Mohammad Norouzi via llvm-dev
2017-Mar-10 16:06 UTC
[llvm-dev] get function parameters (not arguments)
what about the memory address of e and f? can i get them? Thank you and best, Mo On Fri, Mar 10, 2017 at 5:02 PM, Tim Northover <t.p.northover at gmail.com> wrote:> On 10 March 2017 at 15:49, Mohammad Norouzi <mnmomn at gmail.com> wrote: > > for (auto& A : cast<CallInst>(BI)->arg_operands()) > > errs() << "--- " << A->getName() << "\n"; > > Ah, I see. You actually want "e" as a name. Unforuntately this isn't > possible in general for a few reasons. > > First, release builds of LLVM drop most Value names for efficiency > reasons. Without optimization your IR would just have numbers in the > arg position: "call void @foo(i32 %3, i32 %4)". Even those numbers > don't exist in memory, but are constructed as needed. > > Another confounding factor is that optimization will turn even that > into a plain "call void @foo(i32 10, i32 22)" with no record of what > the original arguments were. > > It gets even worse at the C level. If you saw "foo(a + b)", that > argument doesn't really have a natural name. It's a temporary > expression. > > So in general you shouldn't be relying on the name for any actual > transformation you do. > > For debugging there are usually alternatives that might not be quite > so convenient but do the job: Just dumping the argument is usually > sufficient; with heroic effort you might be able to use any debug info > that's present. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170310/d6cb6973/attachment.html>
Tim Northover via llvm-dev
2017-Mar-10 16:09 UTC
[llvm-dev] get function parameters (not arguments)
On 10 March 2017 at 08:06, Mohammad Norouzi <mnmomn at gmail.com> wrote:> what about the memory address of e and f? can i get them?Not in general, again. After optimizations they probably won't even have a fixed memory address. For example on AArch64 that code might become something like: main: mov w0, #10 mov w1, #22 bl foo ret Where e and f only ever exist in registers. In some cases you might get lucky and see that the Value used in the call came from a load instruction, and then you could get its address from that. But it's not something you can rely on for correctness. Cheers. Tim.
Mohammad Norouzi via llvm-dev
2017-Mar-10 16:12 UTC
[llvm-dev] get function parameters (not arguments)
What if I use -O0? In this case, there should be a load for each parameter before the function call, yes? Thank you and best, Mo On Fri, Mar 10, 2017 at 5:09 PM, Tim Northover <t.p.northover at gmail.com> wrote:> On 10 March 2017 at 08:06, Mohammad Norouzi <mnmomn at gmail.com> wrote: > > what about the memory address of e and f? can i get them? > > Not in general, again. After optimizations they probably won't even > have a fixed memory address. For example on AArch64 that code might > become something like: > > main: > mov w0, #10 > mov w1, #22 > bl foo > ret > > Where e and f only ever exist in registers. > > In some cases you might get lucky and see that the Value used in the > call came from a load instruction, and then you could get its address > from that. But it's not something you can rely on for correctness. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170310/dfa1ee12/attachment-0001.html>