Hongxu Chen
2013-Sep-18 09:45 UTC
[LLVMdev] In llvm, how can I delete a whole branch elegantly?
Hi, I am trying to prune some uninteresting llvm ir branches, corresponding to the *if-else* condition in the source code. And here is the procedures: 1. Get the BasicBlock containing the BranchInst which has 2 successors(in order to keep consistent with the source code I am using the llvm ir without any optimizations, so SelectInst/SwitchInst/PHINode is absent), one of which should be pruned; let's name these 2 branches bb1 and bb2 and bb2 is to be pruned. 2. Find their nearest common post dominator, bb_join 3. Create a new branInst bb_new whose successors are bb1 and bb_join; replace the original BranchInst with bb_new 4. For bb2, dropAllReferences && eraseFromParent However since bb2 also has several successors(before bb_join), which are not pruned together with bb2. Is there any existing API to remove them as well? Also, in Step 4, could I just call bb2->eraseFromParent() without dropping any references? I am a bit confused with the function dropAllReferences. Thanks, Hongxu Chen -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130918/b57811be/attachment.html>
Hongxu Chen
2013-Sep-18 11:20 UTC
[LLVMdev] In llvm, how can I delete a whole branch elegantly?
Sorry for the pollute, I later found that DeleteDeadBlock(BasicBlock *B) inside BasicBlockUtils.h might be helpful since it just removes those blocks without any predecessors. Now I am using Function::iterator with this function to remove those dangling basicblock nodes. However I still have no idea whether this can prune ALL the suspicious blocks, in theory(still the presiquite, no optimization and only for if-else like branches). And is there a better way? Thanks, Hongxu Chen On Wed, Sep 18, 2013 at 5:45 PM, Hongxu Chen <leftcopy.chx at gmail.com> wrote:> Hi, > > I am trying to prune some uninteresting llvm ir branches, corresponding > to the *if-else* condition in the source code. And here is the procedures: > > 1. Get the BasicBlock containing the BranchInst which has 2 > successors(in order to keep consistent with the source code I am using the > llvm ir without any optimizations, so SelectInst/SwitchInst/PHINode is > absent), one of which should be pruned; let's name these 2 branches bb1 and > bb2 and bb2 is to be pruned. > 2. Find their nearest common post dominator, bb_join > 3. Create a new branInst bb_new whose successors are bb1 and bb_join; > replace the original BranchInst with bb_new > 4. For bb2, dropAllReferences && eraseFromParent > > However since bb2 also has several successors(before bb_join), which are > not pruned together with bb2. Is there any existing API to remove them as > well? > > Also, in Step 4, could I just call bb2->eraseFromParent() without dropping > any references? I am a bit confused with the function dropAllReferences. > > Thanks, > Hongxu Chen > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130918/3dde3807/attachment.html>
Reasonably Related Threads
- [LLVMdev] Missing libclang_rt.san-x86_64.a file for Compiler-rt
- [PATCH] configure.ac/cipher.c: Check for OpenSSL with EVP_des_ede3_cbc
- [Bug 2608] New: Signed overflow in openbsd-compat/strlcpy.c
- [LLVMdev] internal compiler error when compiling llvm-gcc-4.2-2.9
- [LLVMdev] internal compiler error when compiling llvm-gcc-4.2-2.9