从module中的globalvariable list中获取全局变量的信息
void RemoveStruct::createGlobalVarible() {
// This are the list of load to delete
//SmallVector<Instruction*,128> *WorkListLoad=new SmallVector<Instruction*,128>();
for (auto gv_iter = module_->global_begin(); gv_iter!= module_->global_end(); gv_iter++) {
/* GLOBAL DATA INFO*/
GlobalVariable *gv = &*gv_iter;
Constant *const_gv = gv->getInitializer();
if (!const_gv->isNullValue()) {
//when variable's Type is ConstantStruct
if (llvm::isa<llvm::ConstantStruct>(const_gv)) {
ConstantStruct * global_elememt = llvm::dyn_cast<llvm::ConstantStruct>(const_gv);
// global_type->getTypeForElements();
int global_nums = global_elememt->getNumOperands();
for (int i = 0; i < global_nums; ++i) {
llvm::Value* vir_op = global_elememt->getOperand(i);
llvm::StringRef vir_name = vir_op->getName();
//outs() << i + 1 << " number is " << *global_elememt->getOperand(i) << "\n";
outs() << i + 1 << " Type is " << *vir_op->getType()<< "\n";
outs() << i + 1 << " Value is " << getLabel(vir_op) << "\n";
//outs() << i + 1 << " StringRef is " << vir_name.str() << "\n"; without name
if (llvm::isa<llvm::Constant>(vir_op)) {
Constant* init = NULL;
init = dyn_cast<llvm::Constant> (vir_op);
GlobalVariable * gvar_new = new GlobalVariable(*module_, vir_op->getType(), false,
GlobalValue::InternalLinkage, init, "i", gv);
outs() << "getNumOperands "<< gvar_new->getNumOperands() << "\n";
//llvm::Value* test = gvar_new->getOperand(0);
//BasicBlock* firstBB = returnBasicBlock();
//GetElementPtrInst * ptrInst_new = GetElementPtrInst::Create(vir_op->getType(),vir_op, ArrayRef<Value *>(vir_op), "q", firstBB);
}
}
}
}
}
}