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

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 10 08:02:06 PST 2017


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.


More information about the llvm-dev mailing list