Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLVM getBasicBlockIndex() or equivalent

Tags:

llvm

I have some problems of getting the index of a basic block.

for (Function::iterator II = F.begin(), EE = F.end(); II != EE; ++II, ++ii) 
{  BasicBlock* BB=II;

I have segfaults or cannot use complex structures of several methods that I found in LLVM. Do you know how to use as simply as possible the methods found at :

http://llvm.org/doxygen/Instructions_8h_source.html#l02136

http://llvm.org/doxygen/EdgeBundles_8cpp_source.html#l00078

Or something equivalent? I just want to get an ID of the basic blocks.

Thank you !

like image 697
Alex Avatar asked Feb 05 '26 08:02

Alex


1 Answers

As Eli Bendersky pointed out in the comment above, it depends on your interpretation of index. If you are just interested in unique identifier for the basic block, basic block's name is unique in a Function. You can get that using

BB->getName()

There are other types of IDs associated with basic blocks that are dependent on the nature of your algorithm. For example, if you are writing a dominator tree construction algorithm using the iterative finger algorithm by Keith Cooper, you will associate each basic block with an incremental ID in inverse depth first order. This ID is not a part of the BasicBlock struct and should be maintained by you.

like image 113
Chethan Ravindranath Avatar answered Feb 12 '26 09:02

Chethan Ravindranath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!