linrongbin
linrongbin

Reputation: 3371

Is variable inside of llvm BasicBlock visible for others?

Suppose we have a Function named hello.world, which contains two BasicBlock bb.1 and bb.2, for example:

i32 @hello.world(i32 %x)
bb.1:
  %a = i32 %x
bb.2:
  %b = i32 %a
  ret i32 %b

Is variable %a in bb.1 visible for %b in bb.2 ?

Upvotes: 0

Views: 52

Answers (1)

arrowd
arrowd

Reputation: 34421

Your code is invalid, because bb.1 doesn't end with a terminator instruction. Have it end with br label %bb.2 and the answer would be yes.

Strictly speaking, variables defined in the given BB are visible from all BBs that are dominated by the given one.

Upvotes: 1

Related Questions