<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 6/19/14, 10:10 PM, pratik dand
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAJFa+mTEthRZed3_sF1mLS6ZuEaKPiazdOKUPhY-Qe5udqittw@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>Dear John,<br>
                <br>
              </div>
              Since the pass that I have can transform IR, I was
              thinking to put in an inline assembly code using the
              module asm in llvm.<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    I believe what you want to do is to first create an InlineAsm object
    in your Module that represents the inline assembly code that you
    want to execute.  You then create a CallInst that "calls" the inline
    assembly code with the desired inputs.  See
    <a class="moz-txt-link-freetext" href="http://llvm.org/doxygen/classllvm_1_1InlineAsm.html">http://llvm.org/doxygen/classllvm_1_1InlineAsm.html</a>.<br>
    <br>
    That said, I think "Module asm" is for inline assembly code that
    does not belong in a function, so what you want to create is
    "regular" inline assembly code.<br>
    <br>
    <blockquote
cite="mid:CAJFa+mTEthRZed3_sF1mLS6ZuEaKPiazdOKUPhY-Qe5udqittw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div><br>
            </div>
            <div>Replacing the llvm IR instruction %tmp4 = add nsw i32
              %tmp2, %tmp3 by something like  module asm "ADDenc
              dst,src1,src2" (instruction in the new X86 architecture).<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    Yes, this is (more or less) what you want to do.<br>
    <blockquote
cite="mid:CAJFa+mTEthRZed3_sF1mLS6ZuEaKPiazdOKUPhY-Qe5udqittw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
               <br>
            </div>
            <div>But here I am not sure about the register allocation to
              tmp4,tmp2 and tmp3. Can you comment?<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    I believe you first create an InlineAsm object which acts like an
    LLVM function: you specify a function type (which describes its
    inputs and return values) and then an inline assembly constraint
    string that describes whether the operands need to be pointers to
    memory, register, etc.  You then create a CallInst in which the
    value called is the InlineAsm object and the arguments are the LLVM
    values that you pass into the inline assembly code (in this case,
    %tmp2 and %tmp3).  The CallInst object itself will be the result of
    the inline assembly code.<br>
    <br>
    LLVM's inline assembly is just like GCC's and uses the exact same
    constraints.  First learn how to use GCC inline assembly (if you
    don't know already), and then understanding LLVM's will be
    straightforward.<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote
cite="mid:CAJFa+mTEthRZed3_sF1mLS6ZuEaKPiazdOKUPhY-Qe5udqittw@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <br>
          </div>
          Regards,<br>
        </div>
        Pratik<br>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">On Wed, Jun 18, 2014 at 11:20 PM, John
          Criswell <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:criswell@illinois.edu" target="_blank">criswell@illinois.edu</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000">
              <div class="">
                <div>On 6/18/14, 3:01 AM, pratik dand wrote:<br>
                </div>
                <blockquote type="cite">
                  <div dir="ltr">Dear,
                    <div><br>
                    </div>
                    <div>I am new to llvm and hence have very little
                      idea about a problem that is my university
                      project.</div>
                    <div>I am supposed to assume a X86 CPU supporting an
                      instruction ADDenc that adds two encrypted
                      operands. The original ADD also exists and should
                      operate on unencrypted operands.</div>
                    <div><br>
                    </div>
                    <div>My task is to transform C programs into the new
                      X86 assembly that supports ADDenc. I have very
                      little idea about this.</div>
                    <div><br>
                    </div>
                    <div>I have been suggested the following approaches</div>
                    <div> 1) Adding a new Instruction ADDenc in the
                      current X86 LLVM backend and make the necessary
                      changes.</div>
                    <div>2) Adding a new LLVM IR instruction addenc that
                      recognises the operands at this level instead of
                      general LLVM add, then add an instruction in the
                      target X86 to transform addenc of LLVM to ADDenc
                      of X86.</div>
                  </div>
                </blockquote>
                <br>
              </div>
              There is a third option: if you have an assembler that
              understands the new ADDenc instruction, you can probably
              add inline assembly code that performs the AddEnc
              instruction.  This will only work if you're doing
              ahead-of-time compilation and clang is configured to use
              your new assembler, but if you're transforming C code,
              that is most likely what you're doing.<br>
              <br>
              That said, if you're sufficiently confident with working
              with the LLVM code generator, I think you should add
              support for the AddEnc instruction in the X86 Backend.  As
              to whether you should add an intrinsic or modify the
              backend to just figure out where to use AddEnc, I'm
              guessing that adding an intrinsic would be better, but
              people more familiar with the code generator
              infrastructure should comment.<br>
              <br>
              Regards,<br>
              <br>
              John Criswell<br>
               <br>
              <blockquote type="cite">
                <div class="">
                  <div dir="ltr">
                    <div><br>
                    </div>
                    <div>I have been given an LLVM pass that can run on
                      LLVM IR and decide which are the encrypted
                      operands. </div>
                    <div><br>
                    </div>
                    <div>Any help of any kind will be helpful as I know
                      very little about LLVM. <br>
                    </div>
                    <div>
                      <div><br>
                      </div>
                      -- <br>
                      Pratik
                      <div><br>
                      </div>
                    </div>
                  </div>
                  <br>
                  <fieldset></fieldset>
                  <br>
                </div>
                <pre>_______________________________________________
LLVM Developers mailing list
<a moz-do-not-send="true" href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a moz-do-not-send="true" href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a>
<a moz-do-not-send="true" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
              </blockquote>
              <br>
            </div>
          </blockquote>
        </div>
        <br>
        <br clear="all">
        <br>
        -- <br>
        Pratik
        <div><br>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>