<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:14px"><div id="yui_3_16_0_ym19_1_1477511507733_20775">Hello,</div><div id="yui_3_16_0_ym19_1_1477511507733_20868"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21271"> I wish to reduce a function CFG to its entry block. I wrote the following code using</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21293"> lib/IR/Function.cpp/Function::dropAllReferences() (from llvm-3.6) as reference:<br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21103"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21017"> Function *F; // Suitably initialized.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21074"> BasicBlock *FEntryBlock = &F->getEntryBlock();</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21090"> FEntryBlock->getTerminator()->eraseFromParent();</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21089"> FEntryBlock->removeFromParent();</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21019"> for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I)</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21018"> I->dropAllReferences();</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21028"> while (!F->getBasicBlockList().empty())</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21122"> F->getBasicBlockList().begin()->eraseFromParent();</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21053"> FEntryBlock->insertInto(F);</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21091"> // ...subsequent provision of a terminator, etc.<br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21030"> <br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21173"> This does have the desired effect, but since I have no prior experience modifying LLVM,</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21176"> I am not sure if this is safe/legitimate or if my approach is flawed.</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21734"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21392"> [ I am also able to achieve this by substituting the original terminator to the entry block by a:</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21401"> br i1 true, label %__RELEVANT, %__DISCARD_REST_OF_OLD_BODY <br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21441"> and have the code-gen prepare step eliminate the (made) unreachable rest of the old body</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21526"> so that only the original entry block with an unconditional branch to other relevant code that</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21566"> I add, remains; as intended. However, I want to not rely on the change happening further</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21596"> downstream; I'd prefer that the intended transformation be self-contained. ]<br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21442"><br></div> Kindly comment.<br><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21259"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21257">Thank you,</div><div dir="ltr" id="yui_3_16_0_ym19_1_1477511507733_21258">Anmol P. Paralkar<br></div></div></body></html>