[llvm-dev] Getting variable names from LLVM Pass
Dean Michael Berris via llvm-dev
llvm-dev at lists.llvm.org
Thu May 24 07:57:09 PDT 2018
> On 25 May 2018, at 00:48, Ridwan Shariffdeen <rshariffdeen at gmail.com> wrote:
>
> Hi Michael,
>
> Thanks for the help, it seems like you said its not going to be easy. But I will have a try at this, thank you for the link to LibTooling.
>
It’s not going to be easy if you’re trying to find the name of a variable from the LLVM IR, unless the debugging information is available in the LLVM IR.
If you have access to the original source that Clang knows about (i.e. if it’s C++, C, Objective-C, Objective-C++) then you can use LibTooling. If you have specific questions about using LibTooling, those are better sent to cfe-dev (the mailing list for Clang).
Cheers
> Best
>
> On Mon, May 21, 2018 at 6:26 PM Dean Michael Berris <dean.berris at gmail.com> wrote:
>
>
> > On 21 May 2018, at 18:38, Ridwan Shariffdeen via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> >
> > Hi,
> >
> > I want to retrieve the variable names used in a statement, I tried the following snippet,
> > but it only gives me the variable named in llvm bitcode. I need the variable name in source code.
> >
> > for (auto op = I.op_begin(); op != I.op_end(); op++) {
> > Value* v = op->get();
> > StringRef name = v->getName();
> > }
> >
> > Is there specific documentation I can refer to implement this?
> >
>
> If the source language is something clang knows about, you may have to implement that on top of libTooling, part of clang. Unfortunately it’s not quite straight-forward to get to the source from the LLVM — you’re going to have to rely on a reverse-mapping from the LLVM IR to the higher-level source location, which *might* be doable if there’s debug information associated with the LLVM IR.
>
> https://clang.llvm.org/docs/LibTooling.html
>
> Cheers
>
> -- Dean
>
> --
> Ridwan Shariffdeen
> Graduate Student | National University of Singapore
-- Dean
More information about the llvm-dev
mailing list