Advanced Compilers CMPSCI 710 Spring 2003 Partial Redundancy
- Slides: 21
Advanced Compilers CMPSCI 710 Spring 2003 Partial Redundancy Elimination Emery Berger University of Massachusetts, Amherst UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science
Topics n Last time n n Common subexpression elimination n Value numbering n Global CSE This time n Partial redundancy elimination UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 2
Partial Redundancy n Partial redundancy: n n Expression computed more than once on some path through control-flow graph Partial-redundancy elimination (PRE): n Minimizes partial redundancies n Ø n Inserts and deletes computations (adds temps) Each path contains no more (usually fewer) occurrences of any computation than before Dominates global CSE & loop-invariant code motion UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 3
PRE Example UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 4
PRE: Problem n Critical edge prevents redundancy elimination n n Connects node with two or more successors to one with two or more predecessors Why is it a problem? UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 5
PRE: Solution n Split critical edges! n n Insert empty basic blocks Allows PRE to continue UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 6
Big Example: Critical Edges UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 7
Big Example: Critical Edges Removed UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 8
PRE Dataflow Equations n First formulation [Morel & Renvoise 79] bidirectional dataflow analysis n n Ugly This version [Knoop et al. 92] n Based on “lazy code motion” n n Places computations as late as possible Same reductions as classic algorithm Minimizes register pressure Most complex dataflow problem we’ve ever seen… UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 9
Step 1: Local Transparency n Expression’s value is locally transparent in a basic block if n n n No assignments to variables that occur in expression Set of locally transparent expressions: TRANSloc(i) Note: Ignore expressions in branches UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 10
Local Transparency Trans. Loc – no assignments to variables in expression UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 11
Step 2: Locally Anticipatable n Expression is locally anticipatable in basic block if n n There is computation of expression in block Moving to beginning of block has no effect n n No uses of expression nor assignments of variable in block ahead of computation Set of locally anticipatable expressions: ANTloc(i) UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 12
Locally Anticipatable ANTloc – computes expr, can move to front UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 13
Step 3: Globally Anticipatable n Expression’s value globally anticipatable on entry to basic block if n n n Every path from that point includes computation of expression Expression yields same value all along path Set of globally anticipatable expressions: ANTin(i) UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 14
Globally Anticipatable Expressions: Dataflow Equations n n ANTout(exit) = ANTin(i) = ANTloc(i) [ (TRANSloc(i) Å ANTout(i)) ANTout(i) = Åj 2 Succ(i) ANTin(j) What’s the analysis direction? UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 15
Globally Anticipatable ANTout(exit) = ANTin(i) = ANTloc(i) [ (TRANSloc(i) Å ANTout(i)) ANTout(i) = Åj 2 Succ(i) ANTin(j) UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 16
Step 4: Earliest Expressions n Expression is earliest at entrance to block if n No block from entry to block both: n n n Evaluates expression and Produces same value as at entrance to block Defined in terms of local transparency and globally anticipatable expressions n n n EARLin(i) = [j 2 Pred(i) EARLout(j) EARLout(i) = inv(TRANSloc(i)) [ (inv(ANTin(i)) Å EARLin(i)) Initialize EARLin(entry) = Uexp UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 17
Early Expressions EARLin(i) = [j 2 Pred(i) EARLout(j) EARLout(i) = inv(TRANSloc(i)) [ (inv(ANTin(i) Å EARLin(i)) UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 18
PRE Transformation n We’ll cut to the chase: n Latest, Isolated expressions n n Use earliest, globally anticipatable OPT(i) = latest but not isolated = LATEin(i) Å inv(ISOLout(i)) REDN(i) = used but not optimal = ANTloc(i) Å inv(LATEin(i) [ ISOLout(i)) Insert fresh temporaries for OPT expressions, replace uses in REDN UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 19
OPT, REDN, PRE OPT(B 1) = a+1 OPT(B 2, B 3 a) = x*y REDN(B 1) = a+1 REDN(B 2, B 4, B 7) = x*y UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 20
Conclusion n PRE n n Subsumes global CSE & loop-invariant code motion Complex (but unidirectional) dataflow analysis problem Can only reduce number of computations and register pressure Next time n Register allocation: ACDI ch. 16, pp. 481 -524 UNIVERSITY OF MASSACHUSETTS, AMHERST • Department of Computer Science 21
- Spring, summer, fall, winter... and spring (2003)
- Bhavish
- Partial redundancy elimination
- Inanticipable
- Yacc symbol table
- Binarymove c++
- Compilers book
- Introduction to compiler and interpreter
- Cross compilers
- Basic compiler functions in system software
- Cs 421 programming languages and compilers
- Pros and cons of compilers and interpreters
- Depict structure of front end of a compiler
- Elsa gunter uiuc
- Finding and understanding bugs in c compilers
- Summer spring winter fall
- Qic 710
- Qic 710
- Euperlan pk 3000 am
- A gas has a pressure of 710 kpa at 227
- Qic710
- Din vde 0100 teil 710