1 / 17

Common Subexpression Elimination

Common Subexpression Elimination . Johnathon Jamison CS265 S. Graham. Titanium. Titanium is a compiler. CSE. Given: a = f * i … b = f * i We want to compute f * i only once. CSE. We could do: a = f * i temp = a … b = temp But only if the value of f * i has not changed. Def/Use.

halima
Download Presentation

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. Common Subexpression Elimination Johnathon Jamison CS265 S. Graham

  2. Titanium • Titanium is a compiler

  3. CSE • Given: • a = f * i • … • b = f * i • We want to compute f * i only once

  4. CSE • We could do: • a = f * i • temp = a • … • b = temp • But only if the value of f * i has not changed

  5. Def/Use • Given: • a = … • … • …a… • We want to link the use of a to the definition of a above.

  6. Def/Use • The link should be of every possible definition of a • Thus method calls or pointer indirection could define a

  7. Def/Use • Titanium has def/use information available • Every use of a variable has a list of all possible definitions associated with it • It seems this could be leveraged for CSE

  8. CSE Revisited • a = f * i • … • b = f * i • The second f * i can be eliminated if the definitions of f and i that are used are exactly the same as the first • But checking for that could be onerous

  9. CSE Revisited • So, lets create some fake definitions of f and i immediately before the first f * i • Then, there is one explicit definition that can be traced to for checking the previously mentioned condition

  10. CSE Revisited • f = f • i = i • a = f * i • … • b = f * i • Thus, if f and i have the same definitions in both places, then the second f * i can be eliminated

  11. CSE Revisited • This is fine and dandy for straight line code, but what if you have: • a = f * i b = f * i • … … • --------------------------- • V • c = f * i

  12. CSE Revisited • So, you need to see if f and i have the same definitions in all pairs of places where the common subexpression exists. • I.E., does f or i have any definition that is not associated with a fake def introduced by this analysis? • If not, then an elimination can occur

  13. CSE Revisited • This is complicated by the fact that all CSEs are done simultaneously • So, extra assignments are placed everywhere in the code a CSE could be • Therefore, when tracing defs, those introduced defs must be explicitly ignored

  14. CSE Tidbits • After completion, these assignments are deleted, so as not to interfere with anything else • Any temps introduced are placed after the calculation, so that copy propagation can remove them • Compiler temps are placed at top level, as the live range of CSEs are unknown • Associatively is accounted for • Only binary and unary operations are done

  15. CSE Examples

  16. Timings

  17. Local CSE • Used the standard Muchnik (sp?) algorithm • Used defs to find what was killed • Fully implemented • Except method calls

More Related