Algorithm to Detect Loops
stack := empty;
loop := {b};
insert(a);
while stack is not empty do begin
pop m of the stack;
for each predecessor p of m do insert(p)
end;
procedure insert(m);
if m is not in loop then begin
loop := loop ∪ {m};
push m onto stack
end; |
Approaches to Control Flow Analysis
- Approach 1; Use dominators to discover loops use loops in optimization do iterative data flow analysis
- Approach 2: Use interval analysis analyze overall structure of the program decompose it into nested regions
the nesting structure forms a control tree
- Approach 3: Use structural analysis speeds up dataflow analysis also called elimination method
- Most compilers use the first approach
- It is easy to implement and provides most of the information for optimization
- It is inferior to the other two approaches
- Interval based approaches are faster
- Interval based approach can be used in incremental analysis
- Structural analysis makes control flow transformations easy
|