Dear all,
Is there a way to check whether we can go from A to B within a function when I’m writing a pass?
Thanks.
Best,
–Wenbin
Dear all,
Is there a way to check whether we can go from A to B within a function when I’m writing a pass?
Thanks.
Best,
–Wenbin
Wenbin Zhang wrote:
Dear all,
Is there a way to check whether we can go from A to B within a
function when I'm writing a pass?
I assume you are asking whether control flow can pass from BasicBlock A
to BasicBlock B. In that case, yes: all you need to do is look at the
terminator instruction of BasicBlock A and see if it can branch to
BasicBlock B.
There's a new indirect branch instruction; I don't believe it is used
very often. You might have to handle those specially, but I'll let
others comment on that.
-- John T.
basicblock B within the same function?
Wenbin Zhang wrote:
Dear all,
Is there a way to check whether we can go from A to B within a
function when I'm writing a pass?I assume you are asking whether control flow can pass from BasicBlock A
to BasicBlock B. In that case, yes: all you need to do is look at the
terminator instruction of BasicBlock A and see if it can branch to
BasicBlock B.
Yes, also switch and invoke instruction have the similar effects.
So does it mean that I need to recursively traverse all the possible destinations from A (following the terminator instructions) to see whether I can reach B?
Thanks.
There's a new indirect branch instruction; I don't believe it is used
very often. You might have to handle those specially, but I'll let
others comment on that.-- John T.
Thanks.
Best,
--Wenbin
Best,
--Wenbin
Wenbin Zhang wrote:
From: "John Criswell" <criswell@illinois.edu>
To: "Wenbin Zhang" <zhangwen@cse.ohio-state.edu>
Cc: <llvmdev@cs.uiuc.edu>
Sent: Friday, August 27, 2010 5:09 PM
Subject: Re: [LLVMdev] how to check whether from basicblock A we can go to
basicblock B within the same function?Wenbin Zhang wrote:
Dear all,
Is there a way to check whether we can go from A to B within a
function when I'm writing a pass?
I assume you are asking whether control flow can pass from BasicBlock A
to BasicBlock B. In that case, yes: all you need to do is look at the
terminator instruction of BasicBlock A and see if it can branch to
BasicBlock B.
Yes, also switch and invoke instruction have the similar effects.
Every basic block ends with a terminator instruction that indicates
which basic block or basic blocks it should branch to next. Switch,
invoke, and branch are all terminator instructions. There may be more
that I don't remember.
So does it mean that I need to recursively traverse all the possible
destinations from A (following the terminator instructions) to see whether I
can reach B?
Are you wanting to know if B is a successor of A in the control flow
graph, or are you wanting to know if there is a path from A to B in the
control flow graph? The first question only requires that you look at
the terminator instruction of basic block A. The second question
requires that you traverse the control-flow graph, starting at A, and
see if there is a path from A to B.
-- John T.
Every basic block ends with a terminator instruction that indicates
which basic block or basic blocks it should branch to next. Switch,
invoke, and branch are all terminator instructions. There may be more
that I don't remember.
Why not just use the predecessor and successor iterator?
http://llvm.org/docs/ProgrammersManual.html#iterate_preds
Are those iterators enought for this purpose?
I believe so.