[LLVMdev] The "scope" of passes
ether zhhb
etherzhhb at gmail.com
Mon Apr 19 19:35:53 PDT 2010
hi John,
On Mon, Apr 19, 2010 at 10:27 PM, John Criswell <criswell at uiuc.edu> wrote:
> ether zhhb wrote:
>
>> hi John,
>>
>> sorry for reply so late.
>>
>> On Tue, Apr 13, 2010 at 10:38 PM, John Criswell <criswell at uiuc.edu<mailto:
>> criswell at uiuc.edu>> wrote:
>>
>> Devang Patel wrote:
>>
>> On Mon, Apr 12, 2010 at 6:41 PM, ether zhhb
>> <etherzhhb at gmail.com <mailto:etherzhhb at gmail.com>> wrote:
>>
>>
>> that's because FunctionPass implement the
>> "addLowerLevelRequiredPass"
>> function, but others not.
>>
>> so, is there any special reason that only
>> "addLowerLevelRequiredPass" is
>> allow?
>>
>>
>>
>> There is no reason to not allow it. It is not done because
>> there was
>> not any use. If you need this then pl. prepare a patch!
>>
>>
>> Alternatively, if you wrote the BasicBlock analysis pass, you
>> could easily modify it to be a FunctionPass.
>>
>> yep, if we just concerning use BB pass in Function pass, we can just
>> change it into a Function pass. (In fact, i had do something like this
>> before :) )
>>
>> But the problem is, sometimes, the BB pass PassA use by some Function pass
>> requires others BB pass for analysis result, so we had to rewrite all the
>> passes required by PassA to Function pass, so that PassA can get the
>> analysis :(
>>
>
> Yes, it's inconvenient, but you only have two options: either enhance the
> PassManager to allow a FunctionPass to use a BasicBlockPass, or modify all
> of your BasicBlockPass'es to be FunctionPass'es.
>
> Personally, I would make everything a FunctionPass. When a lower level
> pass is requested by a higher level pass (e.g., ModulePass requests a
> FunctionPass), then the lower-level pass is re-run *even if it was executed
> previously and not invalidated.* So, in your case, if a FunctionPass
> requests the results of BasicBlockPass, that BasicBlockPass will be re-run,
> even if it was run previously and not invalidated.
>
Maybe we could add some "results cache" to the llvm pass manager system, but
this will make things too complex and will not give significant advantage to
llvm, since the we almost do not need to run passes "out of scope".
>
> Plus, you can always write a BasicBlockPass *and* a FunctionPass that reuse
> the same code. For example, you could structure your code this way:
>
> classname::analyzeBasicBlock (BasicBlock & BB) {
> ...
> }
>
> BBClassName::runOnBasicBlock (BasicBlock & BB) {
> analyzeBasicBlock (BB):
> }
>
> FuncClassName::runOnFunction (Function & F) {
> for each basic block in F {
> analyzeBasicBlock (BB)
> }
> }
>
or
BBClassName::runOnBasicBlock (BasicBlock & BB) {
do something
}
FuncClassName::runOnFunction (Function & F) {
BBClassName bbPass;
for each basic block in F {
bbPass.clear();
bbPass.runOnBasicBlock (BB)
}
}
as i mention in the first mail :)
well, thanks very much for your suggestion about this.
--best regards
ether
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100420/53543ea0/attachment.html>
More information about the llvm-dev
mailing list