I am attempting to write a pass which would eliminate phi nodes in llvm IR. Although I have converted the llvm IR to CSSA form I am not sure how to actually remove the phi nodes. From a broader perspective, I want to do RA directly from LLVM IR. The only option I can think of is to have the SSA deconstruction pass as an analysis pass and then while doing code generation, use the information from this pass to insert the necessary movs. Is that the only option or is there any other way whereby we can move out of SSA form with IR.
Asked
Active
Viewed 526 times
0
-
Can you please describe what RA is? – coder hacker Nov 23 '14 at 17:54
-
And if you don't use any optimization flags or run a -mem2reg pass its a non SSA form, however variables will be loaded from memory. I am not sure this is what you want – coder hacker Nov 23 '14 at 17:55
-
I meant register allocation. I am doing all the optimization on ssa form so keeping the mem2reg pass is necessary. I just want to go out of ssa translation during the last register allocation phase. But more I think about it, it seems keeping it as an analysis phase makes more sense and inserting the movs during code generation will make it easier. – ssarangi Nov 23 '14 at 22:27
-
I don't understand what you mean exactly by move out of SSA. I don't think thats possible, because otherwise the only other option is to load variable every time. Without SSA how would your represent which variable reaches a particular point? – coder hacker Nov 23 '14 at 22:59
-
So when I say move out of SSA it essentially means removing the phi nodes and then inserting movs as necessary. LLVM's PhiElimination.cpp or an older StrongPhiElimination.cpp do this for you. So if you look at llvm's source, they have sort of 2 IR's. One is the higher level IR and one is the Machine level IR . The Machine Level IR supports out of ssa form. I don't think the higher level IR supports it. So I have to go with maintaining it as an analysis pass. – ssarangi Nov 24 '14 at 13:46
-
2There is a `reg2mem` pass which does exactly what you want. Although it is better to do register allocation with phis, see the greedy heuristics used by LLVM itself. – SK-logic Nov 25 '14 at 17:32