<div dir="ltr"><span style="font-family: courier new,monospace;">Is there a simple way to require a pass, e.g., Reg2Mem/Mem2Reg, to run before/after my transformation pass? Or do I do something like:</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">struct myOpt {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> myOpt() {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> mBefore = createDemoteRegisterToMemoryPass();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> mAfter = createPromoteMemoryToRegisterPass();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> getAnalysisUsage(AU) {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> AU.addRequired(my stuff);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> mBefore.getAnalysisUsage(AU);</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> mAfter.getAnalysisUsage(AU);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> runOnFunction(aF) {<br> changed = mBefore(F);<br> do my stuff;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> changed |= mAfter(F);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">I'm trying to transform a CFG where A flows into B and C, and I'm making a copy of A, A_copy, which will also flow into B and C. Right now I'm making a merge point mergeB where both A and A_copy flow into it, and it then flows into B. Same for C.</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> A</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> / \</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">B C</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> A A_copy</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> | / \ |</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">mergeB mergeC</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> | |</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> B C</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">For any values %v deffed in A and A_copy, mergeB has the phis %v.phi.B, and I replace the original uses of %v in B with %v.phi.B. However, if both B and C use %v, I need to make sure B gets updated to use %v.phi.B and C gets %v.phi.C (and not %v.phi.B).</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">I figured I could maybe make the code cleaner by pushing values into alloca slots then doing my transformation and converting back to registers with Reg2Mem then Mem2Reg.</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Ed</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"></div>