Basic Block API

Hi,

Is there an API for getting (within a basic block pass) the number of basic block in the program ?

Thanks.

Rotem Varon wrote:

Hi,

Is there an API for getting (within a basic block pass) the number of basic block in the program ?
  

Not of which I am aware. You will probably need to write code that does
this for you.

One place to put the code would be in the doInitialization() method of
the BasicBlockPass that you're writing. However, I'm not sure if the
count would be accurate; other passes could invalidate the information
before the runOnBasicBlock() method is called by the PassManager.

Another method is to write a separate ModulePass that counts the number
of basic blocks. Your pass could list it as a prerequisite, and the
PassManager would automatically run this separate ModulePass for you.

-- John T.

Hi,

Thank you for your answer.
But let me get it straight, when i compile code with the llvm compiler, and my basic block pass is being processed, other passes are concurrently being processed ?

Thanks.

Rotem Varon wrote:

Hi,

Thank you for your answer.
But let me get it straight, when i compile code with the llvm compiler, and my basic block pass is being processed, other passes are concurrently being processed ?
  

Currently, no. The PassManager does not execute passes concurrently.
However, it might in the future, which is why a BasicBlock pass must not
examine or modify anything outside of the BasicBlock that it is working
on (the doInitialization() and doFinalization() methods are exceptions
to the rule).

The purpose of the PassManager is to schedule the order of prerequisite
passes in order to minimize the number of times that they are executed.

For example, let's say I have three passes: A, B and C. Each pass
requires analysis pass D. Pass A preserves (does not invalidate) the
results of Pass D, but Pass B does invalidate the results of Pass D.

If I tell PassManager to run passes A, B, and C, it will examine all the
dependency and preservation information and run the following passes in
the following order:

D, A, B, D, C

-- John T.