Does the back() of a Function guarantee to return the terminator basic block of CFG 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.
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).
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.
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...
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With