<div class="gmail_quote">[please remember to cc llvmdev]</div><div class="gmail_quote"><br></div><div class="gmail_quote">On 24 October 2011 13:20, Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com">ryta1203@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Nick,<br><br> Thanks, this is not really viable as I'd have to check every single instruction like this, seems like there is a lot of overhead associated with this solution.</blockquote>

<div><br></div><div>I don't know what problem you're solving?</div><div><br></div><div>Nick</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="HOEnZb"><div class="h5"><div class="gmail_quote">On Mon, Oct 24, 2011 at 11:48 AM, Nick Lewycky <span dir="ltr"><<a href="mailto:nlewycky@google.com" target="_blank">nlewycky@google.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div>On 24 October 2011 10:31, Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>></span> wrote:<br>


</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Nick,<br>  <br><div>  Is there a clean way to tell the difference between dst and src operands in operations without assignment "=" (ie, store)?<br></div></blockquote><div><br></div><div>StoreInst has getValueOperand() and getPointerOperand(). See <a href="http://llvm.org/doxygen/de/d9c/classllvm_1_1StoreInst.html" target="_blank">http://llvm.org/doxygen/de/d9c/classllvm_1_1StoreInst.html</a> .</div>





<div><br></div><div>We don't print out a name for instructions that are void typed, since there's no sense trying to refer to them again. You can test for that with Inst->getType()->isVoidTy().</div><div><br>





</div><div>Nick</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>On Mon, Oct 24, 2011 at 9:52 AM, Ryan Taylor <span dir="ltr"><<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>></span> wrote:<br>





<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Nick,<br><br>  I forgot to thank you, thanks!<div><div><div><div></div><div><br><br><div class="gmail_quote">On Sat, Oct 22, 2011 at 2:25 PM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br>







<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>Ryan Taylor wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Nick,<br>
<br>
   Ah, forgot the -o, thanks, silly mistake.<br>
<br>
   So how would you extract "add" from the instruction "%A"?<br>
</blockquote>
<br></div>
I->getOpcodeName().<div><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   Yes, this is sort of what I am trying to do. The instnamer works fine<br>
for the local variables and I already had the constants sorted out.<br>
</blockquote>
<br></div>
Great!<br><font color="#888888">
<br>
Nick<br>
<br>
</font><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<br>
On Sat, Oct 22, 2011 at 1:21 PM, Nick Lewycky <<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a><br></div><div><div></div><div>
<mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>>> wrote:<br>
<br>
    Ryan Taylor wrote:<br>
<br>
        Nick,<br>
<br>
           Also, I forgot to mention I had no luck with instnamer, it<br>
        still left<br>
        the local variables as "%slotNum", it didn't name them, unless I<br>
        used<br>
        -instnamer wrong:<br>
<br>
        opt -instnamer <file.bc> file2.bc<br>
<br>
<br>
    Almost, use -o to specify output: opt -instnamer file.bc -o file2.bc<br>
<br>
<br>
        Those are the ones I am refering to. The description for<br>
        instnamer says that it names unnamed instructions (not<br>
        operands), or am I confused on the terminology here?<br>
<br>
<br>
    Ah, I see. The operand of an instruction is some other Value, but<br>
    it's not a subclass of Value like Instruction is. Allow me to elaborate.<br>
<br>
    Here's some example IR:<br>
<br>
      declare i32 @test(i32 %arg) {<br>
        %A = add i32 %arg, 1<br>
        %B = mul i32 %A, 2<br>
        ret i32 %B<br>
      }<br>
<br>
    The llvm::Value hierarchy contains Instruction, Argument and<br>
    Constant (among others). The operands of %A are "i32 %arg" and "i32<br>
    1" where %arg is an Argument and 1 is a Constant.<br>
<br>
    So, saying that "but it doesn't name operands" is moot, because it<br>
    goes through and names all the arguments and instructions, which<br>
    means that it's going to name all the operands -- except for constants.<br>
<br>
    Firstly, constants (like "i32 1") aren't allowed to have names.<br>
    Secondly, some Constants (GlobalValues which includes functions and<br>
    global variables) are allowed to have names, but the instnamer won't<br>
    touch them.<br>
<br>
<br>
        For example, if I print out I->getName I get "add" not "x" or<br>
        "y", but when I do Value *V = I->getOperands(loop) and then do<br>
        V->getName, then it prints out the name of the operand. Am I<br>
        going about this backwards? It sounds like it from the<br>
        terminology you are using (calling an operand an instruction).<br>
<br>
<br>
    If you have the Instruction* for "%A", then getName() will return<br>
    "A", not "add". It may be the case that you have "%add = add i32<br>
    %arg, 1" in which case it would return "add". :)<br>
<br>
    If you call %A->getOperand(0) then you'll get the Value* whose<br>
    getName() returns "arg", and also you can cast pointer to Argument*.<br>
<br>
<br>
        I don't mean to be contentious (as I really appreciate your time<br>
        and help) but apparently someone does use it, me. When going<br>
        from source to source it's needed to keep track of the<br>
        variables. Or am I missing something here too?<br>
<br>
<br>
    Sure, no problem! I'm happy to explain how LLVM works.<br>
<br>
    I'm not sure what you mean when you say you're going<br>
    source-to-source through LLVM. Are you taking a language (say C++)<br>
    compiling it to LLVM IR, then trying to produce another language<br>
    back out (say Javascript)? I would give up on trying to map the<br>
    output variable names back to the input ones. Think of LLVM IR like<br>
    you would x86 assembly, that information is long gone.<br>
<br>
    If you mean that you're doing LLVM IR -> LLVM IR, then instead of<br>
    names use the Value pointers directly. Like names, they refer to the<br>
    values.<br>
<br>
    Nick<br>
<br>
<br>
        ?<br>
<br>
<br>
        On Sat, Oct 22, 2011 at 12:51 PM, Nick Lewycky <<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a><br>
        <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>><br></div></div><div><div></div><div>
        <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a> <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>>>> wrote:<br>
<br>
            Ryan Taylor wrote:<br>
<br>
                Nick,<br>
<br>
                    Unfortunately this doesn't answer my question I<br>
        don't think. It<br>
                seems that -instnamer, as you mention, names the<br>
        instructions<br>
                but still<br>
                does not name the local variables.<br>
<br>
<br>
            What other local variables are you referring to? When AsmWriter<br>
            prints "%y = add i32 %x, 1", the name of that add<br>
        instruction is "y"<br>
            and "x" is the name of another instruction or argument. If<br>
        it has no<br>
            name, the AsmWriter emits a number ("%0"), by counting from<br>
        the top.<br>
            The only other locals could be function arguments, and instnamer<br>
            names those too.<br>
<br>
<br>
                    So there really is no way to do this shy of creating (or<br>
                basically<br>
                copying) the API from AsmWriter (seems very dedundant to<br>
        me)?<br>
                This seems<br>
                like a large failing?<br>
<br>
<br>
            Correct, you'd have to copy that logic.<br>
<br>
            It's not a large failing because nobody uses names of<br>
        non-globals<br>
            for anything. When we want to refer to a value, we use the<br>
        Value*.<br>
<br>
            Nick<br>
<br>
<br>
                On Fri, Oct 21, 2011 at 7:03 PM, Nick Lewycky<br>
        <<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a> <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>><br>
        <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a> <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>>><br>
        <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a> <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>><br>
        <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a> <mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>>>>> wrote:<br>
<br>
                    Ryan Taylor wrote:<br>
<br>
                        It looks like the AsmWriter is generating the local<br>
                variables<br>
                        (SlotNum)s<br>
                        on the fly in that file (AsmWriter.cpp), so is<br>
        there any<br>
                way at<br>
                        all to<br>
                        get this information from the operation itself, via<br>
                Instruction,<br>
                        Value<br>
                        or Type?<br>
<br>
<br>
                    Nope! As you noticed, they're created on the fly...<br>
<br>
                    ...when the Value or Type is anonymous. If you want<br>
        them to be<br>
                    persistent, values can have names via. the setName()<br>
        call. "opt<br>
                    -instnamer" will name all your instructions, for<br>
        example.<br>
<br>
                    Nick<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div></div></blockquote>
<br>
</blockquote></div><br>
</div></div></div></div></blockquote></div><br>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br>
</blockquote></div><br>
</div></div></blockquote></div><br>