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. Best regards, Eduardo
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()? -Eli
Eduardo <erocha.ssa at gmail.com> writes:> 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?A given Value instance can be an operand of multiple instructions.> 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 traverse the User's of a Value with the iterators returned by Value::use_begin and Value::use_end methods.
Hi Eli, Thanks for your reply. I once tried to use Value::replaceAllUsesWith() but it'd break my code. Eduardo On Jan 8, 2013 9:34 PM, "Eli Friedman" <eli.friedman at gmail.com> wrote:> 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()? > > -Eli >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130108/9acb4eb9/attachment.html>
Hi Oscar: In instructions like the one I showed can I expect that Value::use_begin and Value::use_end will return only the getelementptr or there is a chance I will get other users of that constant? Thanks a lot, Eduardo On Jan 8, 2013 9:39 PM, "Óscar Fuentes" <ofv at wanadoo.es> wrote:> Eduardo <erocha.ssa at gmail.com> writes: > > > 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? > > A given Value instance can be an operand of multiple instructions. > > > 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 traverse the User's of a Value with the iterators returned by > Value::use_begin and Value::use_end methods. > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130108/56c26b54/attachment.html>