[LLVMdev] Accessing Return Variable Names

Joey Gouly joel.gouly at gmail.com
Thu Jul 5 15:04:17 PDT 2012


There is also the Instruction Namer pass that gives all anon registers
names.
On Jul 5, 2012 10:35 PM, "Igor Merkulow" <igor.merkulow at gmail.com> wrote:

> Hi John,
>
> %4 is not returned, because it's a temp register value and not a named
> variable.
> But you can implement something like the code below to get this value.
> (Not the most elegant, but more or less working solution).
>
> static std::string getName(Instruction* i)
> {
>             if(i->getOpcode() == Instruction::Store)
>             {
>                 return
> getName((dyn_cast<StoreInst>(&*i))->getPointerOperand());
>             }
>             else if(i->getOpcode() == Instruction::Ret)
>             {
>                 return "Return";
>             }
>
>             std::string name;
>             raw_string_ostream s(name);
>
>             s << *i; // string representation of an instruction
>
>             size_t var_start = name.find('%'); // var starts with a %
>             size_t var_end = name.find(" ", var_start+1); // till space
>             size_t var_comma = name.find(",", var_start+1); // or comma
>
>             return var_comma<var_end?
>                         name.substr(var_start,var_comma-var_start) :
>                         name.substr(var_start, var_end-var_start);
> }
>
> Have fun
> Igor
>
> On Thu, Jul 5, 2012 at 11:15 PM, John Backes <back0145 at umn.edu> wrote:
>
>> Hello,
>>
>> I'm new to llvm development and I have a question which I think should
>> be straight forward, but I am having trouble figuring it out.  I want to
>> be able to access the return variable name for an instruction.  For some
>> instructions I can get this value through the "getName" method.  For
>> example, with the instruction:
>>
>>  > %arg11 = bitcast i32* %arg1 to i8*, !dbg !42, !id !43
>>
>> calling the "getName" method returns:
>>
>>  > arg11
>>
>> However, for the instruction:
>>
>>  > %4 = load i32* %arg1, align 4, !dbg !57, !id !59
>>
>> the "getName" method returns the empty string.  How would I find the
>> value "4" for this load instruction?  Thanks in advance.
>>
>> - John
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120705/21d67c1e/attachment.html>


More information about the llvm-dev mailing list