1 / 7

Global Common Subexpression Elimination

Global Common Subexpression Elimination. Available Expression Analysis Eliminating CSEs Dragon : pp. 627- 631, 633 - 636. add t1 = x, y add t2 = c, d. ldc t3 = 0 cpy x = t3 add t4 = x, y cpy m = t4. sub t5 = a, b ldc t6 = -1 cpy c = t6. sub t7 = a, b cpy m = t7 add t8 = x, y

isaura
Télécharger la présentation

Global Common Subexpression Elimination

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Global Common Subexpression Elimination Available Expression Analysis Eliminating CSEs Dragon : pp. 627- 631, 633 - 636

  2. add t1 = x, y add t2 = c, d ldc t3 = 0 cpy x = t3 add t4 = x, y cpy m = t4 sub t5 = a, b ldc t6 = -1 cpy c = t6 sub t7 = a, b cpy m = t7 add t8 = x, y add t9 = c, d Global Common Subexpression

  3. Availability of an expression E at point P • Definition : Along every path to P in the flow graph : • E must be evaluated at least once • No variables in E redefined after the last evaluation • Observations : E may have different values on different paths : variables holding value may have been overwritten

  4. Formulating the Problem • Domain : A bit vector, a bit for each lexically unique expression in the program • Forward or Backward ? • Lattice elements ? • Meet operator ? (check commutative, idempotent, associative) • Partial ordering • Top ? Bottom ? • Initialization for iterative algorithm

  5. Transfer Functions • Can use the same equation as reaching definitions • out[b] = gen[b] ∪(in[b] - kill[b]) • Start with the transfer function for a single instruction • When does the instruction generate an expression ? • When does it kill an expression ? • Calculate transfer function for complete basic blocks • Compose individual instruction transfer functions

  6. in1 out1 = gen1 ∪ (in1 - kill1) out2 = gen2 ∪ (in2 - kill2) Composing Transfer Functions Derive the transfer function for an entire block • Since out1 = in2, we can simplify : • out2 = gen2 ∪ ((gen1 ∪ (in1 - kill1)) - kill2) out2 = gen2 ∪ (gen1 - kill2) ∪ (in1 - (kill1 ∪ kill2)) • Result • gen = gen2 ∪ (gen1 - kill2) • kill = kill1 ∪ kill2

  7. Eliminating CSEs • Available expressions (across basic blocks) • Provide the set of expressions available at the start of a block • Value numbering (within basic block) • Initialize Value table with available expressions • If CSE is an “available expression”, transform the code • Original target register may be : • a temporary register • overwritten • different from the variables on other paths • A solution : Copy the expression to a new variable at each evaluation reaching the redundant use

More Related