<div dir="ltr">Dear Tim,<div><br></div><div>Just to make myself clear. I am looking for making a tool that can give me machine code only (not execute the program on my CPU).</div><div>I am interested in converting the .c to .s (.o) where .s (.o) has the assembly language instructions (machine code).</div>
<div><br></div><div>With respect to the example you mention, I will be having a CPU that can execute the sign extended addition as an instruction and its decomposition to add and sext won't be required. Since, I will be having a CPU with such capabilities, do i still need to such things?</div>
<div><br></div><div>Regards.</div><div>Pratik</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 11, 2014 at 5:02 PM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Pratik<br>
<div class=""><br>
On 11 June 2014 09:30, pratik dand <<a href="mailto:pratikdand143@gmail.com">pratikdand143@gmail.com</a>> wrote:<br>
> Note: gcd is just an example.<br>
<br>
</div>gcd is very difficult, because an implementation in terms of LLVM<br>
primitive nodes involves control flow. For that one, I'd create an<br>
"@llvm.mytarget.gcd" intrinsic, and spot it earlier somehow (possibly<br>
with an IR-level pass).<br>
<br>
For simpler cases, this is just what PatFrag was created for. For<br>
example, AArch64 has an add that sign extends both its arguments<br>
before doing the addition, so we can write:<br>
<br>
    def extending_add : PatFrag<(ops node:$LHS, node:$RHS), (add (sext<br>
node:$LHS), (sext node:$RHS))>;<br>
<br>
and then use this in the pattern as normal:<br>
<br>
   [(set GPR64:$Rd, (extending_add GPR32:$Rn, GPR32:$Rm))]<br>
<br>
what happens is TableGen pastes the definition of the PatFrag "(add<br>
(sext ...), ...)" into the pattern where we've written extending_add.<br>
It's mostly as if we'd written the "(add (sext ...), ...)" one<br>
ourselves. This only works within a single basic block though, and has<br>
some slight edge-cases around type-inference that can be annoying.<br>
<br>
Cheers.<br>
<span class="HOEnZb"><font color="#888888"><br>
Tim.<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Pratik<div><br></div>
</div>