dalibocai
dalibocai

Reputation: 2347

Last basic block of a function in LLVM

Does the back() of a Function guarantee to return the terminator basic block of CFG in LLVM?

Upvotes: 9

Views: 4109

Answers (2)

Shehbaz Jaffer
Shehbaz Jaffer

Reputation: 2004

No. There could be multiple terminator basic blocks of a function, for instance a function containing multiple return statements. each basic block that contains a return statement from the function will then be called a terminator block or terminator basic block. To detect all basic blocks that are terminator basic blocks (i.e. contain a return statement) do the following:

runOnFunction {
   for BB in F:
      for I in BB:
          if (ReturnInst *RI = dyn_cast<ReturnInst> I)
             BB is terminator Basic Block
          endif
      endfor
   endfor
}

Upvotes: 1

CAFxX
CAFxX

Reputation: 30281

I don't think, since there's no such a thing as a "terminator BB": there very well may be multiple BBs terminated by a return.

Upvotes: 6

Related Questions