On Jan 28, 2008, at 7:55 PM, David A. Greene wrote:
> On Monday 28 January 2008 09:31:11 pm Owen Anderson wrote:
>> From experience, an important point that is often forgotten is that
>> the order of declaration of dependencies matter. If you declare that
>> you require pass A, and then pass B, and B doesn't preserve A,
you'll
>> get an error like this.
>>
>> Just some advice from having had similar problems in the past.
>
> I'll have to double-check my code, but I don't think I have this
> particular
> problem.
>
> But in any case, isn't the whole point of PassManager that it can
> handle
> situations like this? Why wouldn't it just run Pass A twice, or run
> it
> in the correct order (after Pass B)?
If you realize that function level analysis pass only preserves and
servers analysis info for one function at a time then current pass
manager behavior is obvious. If you insert a module level pass between
two function level passes then these two function level passes can not
share analysis information.
Let's develop one example step by step to understand this.
----------------------------------------------------------------
- PM (Pass Manager) is asked to run function level pass F1.
1) F1 requires function level analysis info A1.
PM will arrange a function level pass manager to handle this request.
FPManager
- execute A1 on function foo()
- execute F1 on function foo()
- execute A1 on function bar()
- execute F1 on function bar()
...
----------------------------------------------------------------
- PM is asked to run function level pass F1.
1) F1 requires function level analysis info A1.
A1 requires and preserves Module level analysis info M1.
PM will arrange a module level pass manager to handle this request.
MPManager
- execute M1 on function foo(), bar()
FPManager
- execute A1 on function foo()
- execute F1 on function foo()
- execute A1 on function bar()
- execute F1 on function bar()
----------------------------------------------------------------
Now if PM is asked to run function level pass F1.
1) F1 requires function level analysis info A1.
A1 requires Module level analysis info M1. A1 does not preserve M1.
2) F1 requires function level analysis info A2.
A2 does not preserve A1.
PM will try to arrange module level pass manager to handle this request.
MPManager
- execute M1 on function foo(), bar()
FPManager
- execute A1 on function foo()
- execute A2 on function foo()
- execute F1 on function foo() /* oops, can not run F1, because A1
for foo() is destroyed */
As you suggested, If after executing A2 function pass manager reorder
A1 then following will happen
MPManager
- execute M1 on function foo(), bar()
FPManager
- execute A1 on function foo()
- execute A2 on function foo()
/* Here, PM can not reorder A1 again for M1 for foo() is destroyed
by previous A1 run*/
/* This means can not order F1 here because A1 is missing */
- execute A1 on function bar()
- execute A2 on function bar()
/*And now, run reordered A1 before running F1 */
MPManager
- execute M1 on function foo(), bar()
FPManager
- execute A1 on function foo()
- execute F1 on function foo() /* oops, A2 for foo() is not
available. */
If A2 is reordered again then A1 will have to be re-reordered and
now you are running in an infinite loop. PM does not have ways to
preserve analysis A1 for foo() and restore it back.
So the solution is to change order of required analysis.
- PM is asked to run function level pass F1.
1) F1 requires function level analysis info A2.
A2 does not preserve A1.
2) F1 requires function level analysis info A1.
A1 requires Module level analysis info M1. A1 does not preserve M1.
This will allow PM to order
MPManager
- execute M1 on function foo(), bar()
FPManager
- execute A2 on function foo()
- execute A1 on function foo()
- execute F1 on function foo() <-- we can do this !
- execute A2 on function bar()
- execute A1 on function bar()
- execute F1 on function bar() <-- we can do this !
... and now world is a better place to live!
As always, I welcome patches to improve diagnosis in this area. IIRC,
Owen added patches to dump PM state to clarify what is going on.
-
Devang