Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 357
dalibocai Avatar asked Mar 14 '12 14:03

dalibocai


People also ask

What is a basic block in LLVM?

This represents a single basic block in LLVM. A basic block is simply a container of instructions that execute sequentially. Basic blocks are Values because they are referenced by instructions such as branches and switch tables. The type of a BasicBlock is "Type::LabelTy" because the basic block represents a label to which a branch can jump.

How to use llvmgetfirstbasicblock() function?

The returned basic block can be used as an iterator. You will likely eventually call into LLVMGetNextBasicBlock () with it. So call LLVMGetFirstBasicBlock once per function, and then LLVMGetNextBasicBlock repeatedly until you've gone through all the basic blocks of that function (juding by the source you'll get a nullptr when that happens).

What is a function pass in LLVM?

Traces through the program are generated using a function pass in LLVM. The pass takes as input the profiling data generated in the trace detection pass. The pass modifies a function by merging the entry block with other basic blocks along the function's path.

What is the use of return instruction in LLVM?

Returns the terminator instruction if the block is well formed or null if the block is not well formed. More... Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return instruction of this basic block, if such a call is present. More...


2 Answers

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.

like image 96
CAFxX Avatar answered Oct 04 '22 00:10

CAFxX


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
}
like image 43
Shehbaz Jaffer Avatar answered Oct 04 '22 01:10

Shehbaz Jaffer