[llvm-dev] How does one reduce a function CFG to its entry block?
Anmol P. Paralkar via llvm-dev
llvm-dev at lists.llvm.org
Wed Oct 26 13:53:19 PDT 2016
Hello,
I wish to reduce a function CFG to its entry block. I wrote the following code using lib/IR/Function.cpp/Function::dropAllReferences() (from llvm-3.6) as reference:
Function *F; // Suitably initialized. BasicBlock *FEntryBlock = &F->getEntryBlock(); FEntryBlock->getTerminator()->eraseFromParent(); FEntryBlock->removeFromParent(); for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) I->dropAllReferences(); while (!F->getBasicBlockList().empty()) F->getBasicBlockList().begin()->eraseFromParent(); FEntryBlock->insertInto(F); // ...subsequent provision of a terminator, etc.
This does have the desired effect, but since I have no prior experience modifying LLVM, I am not sure if this is safe/legitimate or if my approach is flawed.
[ I am also able to achieve this by substituting the original terminator to the entry block by a: br i1 true, label %__RELEVANT, %__DISCARD_REST_OF_OLD_BODY
and have the code-gen prepare step eliminate the (made) unreachable rest of the old body so that only the original entry block with an unconditional branch to other relevant code that I add, remains; as intended. However, I want to not rely on the change happening further downstream; I'd prefer that the intended transformation be self-contained. ]
Kindly comment.
Thank you,Anmol P. Paralkar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161026/8822185f/attachment.html>
More information about the llvm-dev
mailing list