Dasgupta, Sandeep via llvm-dev
2016-Nov-28 04:04 UTC
[llvm-dev] LLVM Pass for Instructions in Function (error
Oh sorry that was a typo. it's just getOperand (0). This is in order to get the first operand of getelementptr, which is the base address pointer (%A in your listing). Now as I can see that you want to store ptrA in some data structure; you can just store the Inst instead as the virtual register ptrA itself represent the instruction. Sent via the Samsung Galaxy Note® 3, an AT&T 4G LTE smartphone -------- Original message -------- From: Gurunath Kadam <gurunath.kadam at gmail.com> Date: 11/27/2016 8:40 PM (GMT-06:00) To: "Dasgupta, Sandeep" <sdasgup3 at illinois.edu> Cc: llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] LLVM Pass for Instructions in Function (error Hi Sandeep, Thanks. One question about: Value* AddrPointer = Inst->getIperand(0); So this works for LVALUE(S) i.e. in my case pointer on LHS of '='. I cannot find anything online about getloperand online. For reference this is the instruction: %ptrA = getelementptr float, float addrspace(1)* %A, i32 %id I thought if I just get the return value of the instruction then I can get %ptrA. Can you please elaborate on that? Thanks again. -Gurunath On Sun, Nov 27, 2016 at 9:21 PM, Dasgupta, Sandeep <sdasgup3 at illinois.edu<mailto:sdasgup3 at illinois.edu>> wrote: Hi, Sent via the Samsung Galaxy Note® 3, an AT&T 4G LTE smartphone -------- Original message -------- From: Gurunath Kadam via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> Date: 11/27/2016 7:49 PM (GMT-06:00) To: llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> Subject: [llvm-dev] LLVM Pass for Instructions in Function (error Hi, Please find the embedded code. Also you may follow http://llvm.org/docs/ProgrammersManual.html#iterating-over-the-instruction-in-a-function<https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_ProgrammersManual.html-23iterating-2Dover-2Dthe-2Dinstruction-2Din-2Da-2Dfunction&d=DQMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=at_zHdaJ5pMt_A20sKa_JLbvjeXndNos3PveVfgUF0o&m=sgKJsUvkCaaRtnodZerk-FVpqAHHpzk5gPC7VImAiN0&s=E-fekZNyRFShLug4UZybHsL4iibcKy_cmvdRExTT23s&e=> - Sandeep I have following lines in my code, where I need to iterate over the instructions in the function (not BB): for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I){ Instruction *Inst = I; Instruction *Inst = &*I; if (Inst -> getOpcode() == Instruction::GetElementPtr){ Value* AddrPointer = Inst->getIperand(0); .... if (cast<Operator>(Inst) -> getOpcode() == Instruction::GetElementPtr){ Value* AddrPointer = cast<Value>(Inst); Value* threadId = Inst -> getOperand(1); unsigned AddrSpace = Inst -> getAddressSpace() DataStructureForTrace.push_back (std:make_tuple(new Value(threadId), AddrSpace, 0, new Value(AddrPointer))); } } I get following error (there are more, some visible here and some not. for eg, getAddressSpace not being for Instruction class.): error: cannot convert ‘llvm::inst_iterator {aka llvm::InstIterator<llvm::SymbolTableList<llvm::BasicBlock>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::BasicBlock, false, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void>, false, false>, llvm::Instruction>}’ to ‘llvm::Instruction*’ in initialization Instruction *Inst = I; I am not sure about this, as I am following some online code practices. Thank you. Regards, Gurunath -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161128/6f3c529e/attachment.html>