Advanced Compilers CMPSCI 710 Spring 2003 Partial Redundancy EliminationTopicsPartial RedundancyPRE ExamplePRE: ProblemPRE: SolutionBig Example: Critical EdgesBig Example: Critical Edges RemovedPRE Dataflow EquationsStep 1: Local TransparencyLocal TransparencyStep 2: Locally AnticipatableLocally AnticipatableStep 3: Globally AnticipatableGlobally Anticipatable Expressions: Dataflow EquationsGlobally AnticipatableStep 4: Earliest ExpressionsEarly ExpressionsPRE TransformationOPT, REDN, PREConclusionUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer ScienceEmery BergerUniversity of Massachusetts, AmherstAdvanced CompilersCMPSCI 710Spring 2003Partial Redundancy EliminationUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science2TopicsLast timeCommon subexpression eliminationValue numberingGlobal CSEThis timePartial redundancy eliminationUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science3Partial RedundancyPartial redundancy:Expression computed more than onceon so me path through control-flow graphPartial-redundancy elimination (PRE):Minimizes partial redundanciesInserts and deletes computations (adds temps)Each path contains no more (usually fewer) occurrences of any computation than beforeDominates global CSE & loop-invariant code motionUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science4PRE ExampleUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science5PRE: ProblemCritical edge prevents redundancy eliminationConnects node with two or more successors to one with two or more predecessorsWhy is it a problem?UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science6PRE: SolutionSplit critical edges!Insert empty basic blocksAllows PRE to continueUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science7Big Example:Critical EdgesUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science8Big Example:Critical Edges RemovedUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science9PRE Dataflow EquationsFirst formulation [Morel & Renvoise 79]bidirectional dataflow analysisUglyThis version [Knoop et al. 92]Based on “lazy code motion”Places computations as late as possibleSame reductions as classic algorithmMinimizes register pressureMost complex dataflow problem we’ve ever seen…UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science10Step 1: Local TransparencyExpression’s value is locally transparent in a basic block ifNo assignments to variables that occur in expressionSet of locally transparent expressions:TRANSloc(i)Note: Ignore expressions in branchesUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science11Local TransparencyTransLoc – no assignmentsto variables in expressionUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science12Step 2: Locally AnticipatableExpression is locally anticipatable in basic block ifThere is computation of expression in blockMoving to beginning of block has no effectNo uses of expression nor assignments of variable in block ahead of computationSet of locally anticipatable expressions:ANTloc(i)UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science13Locally AnticipatableANTloc – computes expr,can move to frontUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science14Step 3: Globally AnticipatableExpression’s value globally anticipatable on entry to basic block ifEvery path from that point includes computation of expressionExpression yields same value all along pathSet of globally anticipatable expressions:ANTin(i)UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science15Globally Anticipatable Expressions:Dataflow EquationsANTout(exit) = ANTin(i) = ANTloc(i) [ (TRANSloc(i) Å ANTout(i))ANTout(i) = Åj 2 Succ(i) ANTin(j)What’s the analysis direction?UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science16Globally AnticipatableANTout(exit) = ANTin(i) =ANTloc(i) [ (TRANSloc(i) Å ANTout(i))ANTout(i) = Åj 2 Succ(i) ANTin(j)UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science17Step 4: Earliest ExpressionsExpression is earliest at entrance to block ifNo block from entry to block both:Evaluates expression andProduces same value as at entrance to blockDefined in terms of local transparency and globally anticipatable expressionsEARLin(i) = [j 2 Pred(i) EARLout(j)EARLout(i) = inv(TRANSloc(i)) [ (inv(ANTin(i)) Å EARLin(i))Initialize EARLin(entry) = UexpUUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science18Early ExpressionsEARLin(i) = [j 2 Pred(i) EARLout(j)EARLout(i) = inv(TRANSloc(i)) [ (inv(ANTin(i) Å EARLin(i))UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science19PRE TransformationWe’ll cut to the chase:Latest, Isolated expressionsUse earliest, globally anticipatableOPT(i) =
View Full Document