How does one reduce a function CFG to its entry block?

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