Mohammad Norouzi via llvm-dev
2017-Mar-10 15:49 UTC
[llvm-dev] get function parameters (not arguments)
I tried the original posted code again: for (auto& A : cast<CallInst>(BI)->arg_operands()) errs() << "--- " << A->getName() << "\n"; but it prints empty (only ---)! Thank you and best, Mo On Fri, Mar 10, 2017 at 4:44 PM, Tim Northover <t.p.northover at gmail.com> wrote:> On 10 March 2017 at 15:41, Mohammad Norouzi <mnmomn at gmail.com> wrote: > > Sorry i'm using the following code: > > > > F = (cast<CallInst>(BI))->getCalledFunction(); > > for (auto& A : F->getArgumentList()) { > > errs() << "------- " << A.getName() << " " << "11" << > > "\n"; > > } > > > > But how can I get the parameters (as e and f in the example)? > > The code you originally posted (using > cast<CallInst>(BI)->arg_operands()) should iterate through the > arguments to the call. > > Cheers. > > Tim. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170310/3dd4861b/attachment.html>
Tim Northover via llvm-dev
2017-Mar-10 16:02 UTC
[llvm-dev] get function parameters (not arguments)
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.
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>