<div dir="ltr"><div><div><div><div><div><div><div><div>Hi All,<br><br></div>I am new to llvm backend. I am trying out few examples to understand backend codegen. I have ported llvm LEG @ <a href="https://github.com/frasercrmck/llvm-leg">https://github.com/frasercrmck/llvm-leg</a> to llvm 3.9 successfully. <br><br></div>Currently, the LEG instructions are RISC load-store type instruction. I want to generate some instructions for register indirect mode, like following:<br><br></div>IR: <br><br>@a = local_unnamed_addr global i32 0, align 4<br>@b = local_unnamed_addr global i32 0, align 4<br>@c = local_unnamed_addr global i32 0, align 4<br><br>; Function Attrs: norecurse nounwind<br>define void @foo() {<br>entry:<br>  %0 = load i32, i32* @a, align 4<br>  %1 = load i32, i32* @b, align 4<br>  %add = add nsw i32 %1, %0<br>  store i32 %add, i32* @c, align 4<br>  ret void<br>}<br><br><br></div>Expected assembly instructions:<br></div>MOV R0, #A    // R0 pointing to address of A<br></div>MOV R1, #B    // R1 pointing to address of B<br></div>ADD *R0, *R1  // Adding both memory operands<br></div><div><div><div><div><div>MOV #C, *R0  // Moving result to address of C<br><br></div><div>How should i define such mov and add instruction in my .td files? How will ISD::LOAD be seleted in ISelDAGtoDAG in select() function? I want to start with simple .td definitions and would later like to encapsulate them in multiclass once basic example works.<br><br></div><div>Can someone please help how to achieve this?<br><br></div><div>Regards,<br></div><div>Alex <br></div><div><br></div></div></div></div></div></div>