[LLVMdev] get ref to parent instruction

Eli Friedman eli.friedman at gmail.com
Tue Jan 8 15:34:53 PST 2013

On Tue, Jan 8, 2013 at 3:06 PM, Eduardo <erocha.ssa at gmail.com> wrote:
> Hi all,
> How can I get a reference to an instruction if I have a reference to
> an operand? For example, let suppose I have a reference to the
> ConstantExpr "getelementptr inbounds" in the following instruction:
>   %4 = getelementptr i32* getelementptr inbounds ([8 x i32]*
> @__mem_grid_MOD_nnyp, i32 0, i32 0), i32 %3
> then, how can I get a reference to the GetElementPtrInst object?
> The reason I need that is because I want to change every instruction
> that uses certain variables (in the example above the
> __mem_grid_MOD_nnyp variable). The problem is that for the example I
> showed the actual user of the variable is a ConstantExpr object and
> not the GetElementPtrInst object.

You can use Value::use_begin()/use_end() recursively.

That said, have you looked at Value::replaceAllUsesWith()?


More information about the llvm-dev mailing list