[llvm-dev] get function parameters (not arguments)

Mohammad Norouzi via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 10 08:06:27 PST 2017


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>


More information about the llvm-dev mailing list