[LLVMdev] How to Check whether BasicBlock resides in a conditional branch
Iaroslav Markov
ymarkov at cs.stonybrook.edu
Sat Aug 25 08:00:45 PDT 2012
Can't you do it by performing some analysis on CFG? You can traverse that structure with BFS. And after that for all the BB you have visited more than once, you try to find a parent that has a branch instruction as a terminator. Additionally you ensure that there are no BB with branches as terminators on your way. If such parent exist, you mark that there is exist a direct connection between this parent and BB.
Anyway I think it's impossible to detect all of such BB - you have indirect jumps, you can have a complicated branch structure with implicit flows that are hard to analyse - like this:
a = 0;
b = 1;
if (X == 1)
a = 1;
if (X == 0)
b = 0;
if (a == 0)
Y = 0;
if (b == 1)
Y = 1;
// in the end Y = X
if(X == Y)
BasicBlock C
endif
BasicBlock D
In this example BasicBlock C is *must* executed, however it's hard to detect that it is.
--
Yaroslav Markov
PhD student in Computer Science
Stony Brook University
________________________________________
From: llvmdev-bounces at cs.uiuc.edu [llvmdev-bounces at cs.uiuc.edu] on behalf of Jianfei Hu [hujianfei258 at gmail.com]
Sent: Saturday, August 25, 2012 8:44 AM
To: LLVMdev at cs.uiuc.edu
Subject: [LLVMdev] How to Check whether BasicBlock resides in a conditional branch
Hello All,
I want to dertermine whether a basicblock is in a conditional branch. such as,
//=============================
if a > 2 // BasicBlock A
then
BasicBlock B
endif
BasicBlock C
//=============================
What I want to identify is BasicBlock B, which is in a condtional
block. but C is not.
In other words, I want to distinguish BasicBlocks that * must * be
executed and that *may* be executed.
CFG's iterator may not help, as LLVM IR br would be:
A:
br %cmp, %lable.B, %label.C
B
br C
C
both of the blocks could be operand of br instruction.
code in C *must be executed*, but B is not.
Is there any availiable API in LLVM to distinguish them?
Thanks.
_______________________________________________
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list