llvm instruction use 的用法
Instruction *instr = WorkListLoad->pop_back_val();
for (Value::user_iterator UI = instr->user_begin(), E = instr->user_end(); UI!= E; ++UI) {
User *U = *UI;
assert (isa<Instruction> (U));
Instruction* CI = dyn_cast<Instruction> (U);
assert(CI->getOpcode() == llvm::Instruction::GetElementPtr);
if (CI->getNumOperands() >= 3) {
llvm::Value* val_op = CI->getOperand(0);
llvm::Value* val_op_2 = CI->getOperand(2);
string variable_name = getLabel(val_op_2);
outs() << "variable name " << variable_name << "\n";
if (alloca_keymap_.count(variable_name) > 0) {
Value* new_var = alloca_keymap_[variable_name];
vector<Value *> IdxList = valueInstr(CI);
ArrayRef<Value*> list(IdxList);
GetElementPtrInst* ptrInst_new = GetElementPtrInst::CreateInBounds(
dyn_cast<PointerType> (new_var->getType())->getElementType(),
new_var, list, "");
ReplaceInstWithInst(CI, ptrInst_new);
}
}
}
}