Hi,<div><br></div><div> I've been experimenting with writing a backend for LLVM (3.2) (having already written a frontend <a href="http://savourysnax.github.com/EDL">http://savourysnax.github.com/EDL</a>), everything was going reasonably ok ( calls/returns, epilogue, prologue, etc are all working), up until I tried to place support for conditional  branches.</div>
<div><br></div><div>Given this simple program :<br><br><div>int test(int c,int d)</div><div>{</div><div>        if (c)</div><div>        {</div><div>                return d;</div><div>        }</div><div>        else</div>
<div>        {</div><div>                return c;</div><div>        }</div><div>}<br><br>with optimisations disabled (opts enabled it generates a select and this works fine) - I get the error  at the bottom of the post.</div>
</div><div><br></div><div><br></div><div> It seems to state, the problem is in the usage of -  %R0 in : JMP <BB#3>, %R0<imp-use>  </div><div><br></div><div>what is confusing me, is the implied R0 on the jump, it only appears at Post SSA, and i`m not sure where to look to discern what i've done to cause it. I've tested the same code with the x86 backend and it never seems to do this implied usage. I realise I've not left you a lot to go on, but I`m really just looking for likely areas to go poke around in. The backend was started by copying the MSP430 backend then commenting out large swathes of things (I may have left something in that causes the below error). I'm not using (or shouldn't be) any custom lowering, all instructions map to DAG concepts (with the exception of select_cc and br_cc which are set to expand). </div>
<div><br></div><div>Any pointers would be much appreciated - I can post code etc, if required.</div><div><br></div><div> Thanks, Lee</div><div><br></div><div><div># Machine code for function test: Post SSA</div><div>Frame Objects:</div>
<div>  fi#0: size=4, align=4, at location [SP]</div><div>  fi#1: size=4, align=4, at location [SP]</div><div>  fi#2: size=4, align=4, at location [SP]</div><div>Function Live Ins: %R0 in %vreg0, %R1 in %vreg1</div><div>Function Live Outs: %R0</div>
<div><br></div><div>BB#0: derived from LLVM BB %entry</div><div>    Live Ins: %R0 %R1</div><div>        %vreg1<def> = COPY %R1<kill>; GR32:%vreg1</div><div>        %vreg0<def> = COPY %R0; GR32:%vreg0</div>
<div>        MOV32mr <fi#1>, 0, %vreg0<kill>; mem:ST4[%c.addr] GR32:%vreg0</div><div>        MOV32mr <fi#2>, 0, %vreg1<kill>; mem:ST4[%d.addr] GR32:%vreg1</div><div>        %vreg2<def> = MOV32rm <fi#1>, 0; mem:LD4[%c.addr] GR32:%vreg2</div>
<div>        %vreg3<def> = CMPfri %vreg2<kill>, 0; SR1:%vreg3 GR32:%vreg2</div><div>        JCC %vreg3<kill>, <BB#2>; SR1:%vreg3</div><div>        JMP <BB#1>, %R0<imp-use></div><div>    Successors according to CFG: BB#1(20) BB#2(12)</div>
<div><br></div><div>BB#1: derived from LLVM BB %if.then</div><div>    Predecessors according to CFG: BB#0</div><div>        %vreg5<def> = MOV32rm <fi#2>, 0; mem:LD4[%d.addr] GR32:%vreg5</div><div>        MOV32mr <fi#0>, 0, %vreg5<kill>; mem:ST4[%retval] GR32:%vreg5</div>
<div>        JMP <BB#3>, %R0<imp-use></div><div>    Successors according to CFG: BB#3</div><div><br></div><div>BB#2: derived from LLVM BB %if.else</div><div>    Predecessors according to CFG: BB#0</div><div>        %vreg4<def> = MOV32rm <fi#1>, 0; mem:LD4[%c.addr] GR32:%vreg4</div>
<div>        MOV32mr <fi#0>, 0, %vreg4<kill>; mem:ST4[%retval] GR32:%vreg4</div><div>    Successors according to CFG: BB#3</div><div><br></div><div>BB#3: derived from LLVM BB %return</div><div>    Predecessors according to CFG: BB#2 BB#1</div>
<div>        %vreg6<def> = MOV32rm <fi#0>, 0; mem:LD4[%retval] GR32:%vreg6</div><div>        %R0<def> = COPY %vreg6<kill>; GR32:%vreg6</div><div>        RET %R0<imp-use,kill></div><div><br></div>
<div># End machine code for function test.</div><div><br></div><div>*** Bad machine code: Using an undefined physical register ***</div><div>- function:    test</div><div>- basic block: BB#1 if.then (0xea46f84)</div><div>
- instruction: JMP <BB#3>, %R0<imp-use></div><div>- operand 1:   %R0<imp-use></div><div>LLVM ERROR: Found 1 machine code errors.</div><div><br></div></div><div><br></div><div><br></div>