[llvm-dev] Getting variable names from LLVM Pass
Dean Michael Berris via llvm-dev
llvm-dev at lists.llvm.org
Mon May 21 03:26:42 PDT 2018
> 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
More information about the llvm-dev
mailing list