<div dir="ltr"><div><div>IMHO, don't try to tell llvm about your registers, instead create a mapping between the last Value* assigned to each register for each basic block.<br><br>For example, here's a crude suggestion. <br><br></div><div>First pass, identify all of the branch destinations from your custom IR, where you will need to create an llvm basic block.<br></div><div><br>Second pass, translate IR instructions into llvm IR for each block.<br></div><div> - keep track of the last Value* stored in each register.<br></div><div> - if you need to load a Value* from a register that hasn't been assigned yet in this block, create a phi node and insert it at the start of the block.<br><br></div><div>Third pass, follow branches and link up phi nodes.<br><br><br></div><div>Or you could simply generate code as if each register is on the stack. Generating alloca, load & store. Then run the mem2reg pass to promote everything back to virtual registers for you automatically. That's probably easier to get right.<br><br></div><br><br><br></div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 8, 2016 at 9:30 AM, Paul Peet via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>I am currently trying to translate some custom IR to LLVM-IR and came across and issue.</div><div>The custom IR has several registers and I am basically try to SSAfy it so it can be easily translated/converted to LLVM-IR.</div><div><br></div><div>The problem:</div><div><br></div><div>Since in my custom IR I can reassign every register I have to reassign every new expression with a new llvm Value. But my IR has something like this:</div><div><br></div><div>REG A = VAR C + CONST 2</div><div>REG A = CONST 12</div><div><br></div><div>So my workaround looks like:</div><div><br></div><div>; I am returning the registers in an anonymous struct</div><div><div>define { i32, i32, i32 } @test(i32 %var_c) {</div><div> ; Initializing registers</div><div> %reg_a_0 = select i1 true, i32 0, i32 0</div><div> %reg_b_0 = select i1 true, i32 0, i32 0</div><div> %reg_c_0 = select i1 true, i32 0, i32 0</div><div><br></div><div> ; Translated instructions</div><div> %reg_a_1 = add i32 %var_c, 2</div><div> %reg_a_2 = select i1 true, i32 12, i32 0</div><div><br></div><div> ; Prepare return values</div><div> %ret_0 = insertvalue { i32, i32, i32 } undef, i32 %reg_a_2, 0</div><div> %ret_1 = insertvalue { i32, i32, i32 } %ret_0, i32 %reg_b_0, 1</div><div> %ret_2 = insertvalue { i32, i32, i32 } %ret_1, i32 %reg_c_0, 2</div><div> </div><div> ret { i32, i32, i32 } %ret_2</div><div>}</div></div><div><br></div><div>I am basically using "select i1 true, i32 1, i32 0" so after optimization it gets:</div><div>%val = i32 1</div><div><br></div><div>But as I said this looks like a hack to me and I can't simply use "%val = i32 1".</div><div>So what's the proper way to do this without actually using alloca/load/store.</div><div><br></div><div>Regards,</div><div>Paul</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>