04-05globalOptimizations - Administrivia Code generation...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSE 450: Compilers K. Stirewalt Code generation Survey of global optimizations Topics: – Administrivia and project questions – Peephole optimization – Global optimizations CSE 450: Compilers K. Stirewalt Administrivia Final exam: Friday, May 2 nd from 10:00-12:00 noon in this room Graduating seniors may take the exam Wednesday, April 30th, from 9am - 11am in room 3105 Engineering CSE 450: Compilers K. Stirewalt Project #6 Involves a hand translation of 3-address code generated by your compiler into target code Subject program: test27.adb You must use your compiler to generate the IR from this program; then show how each statement translated into target code Deliverable will be a written document and may include any explanatory text you deem appropriate Due Friday, April 25 th CSE 450: Compilers K. Stirewalt Project 6 Q&A Questions??? CSE 450: Compilers K. Stirewalt Classification of optimizations High-level languages allow 3 optimization types: 1. Local optimizations : Apply to a basic block in isolation 2. Global optimizations : Apply to a control-flow graph (method body) in isolation 3. Inter-procedural optimizations : Apply across method boundaries Most compilers do (1), …many do (2) …and very few do (3) CSE 450: Compilers K. Stirewalt Local Optimizations The simplest form of optimizations are local to a basic block Examples: – Algebraic simplification – Constant folding – Common sub-expression elimination – Dead code elimination
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 CSE 450: Compilers K. Stirewalt Peephole optimization An alternative to careful instruction selection and register allocation Idea: – Generate naïve target code – Then iterate over the generated code, optimizing sequences of instructions within a sliding window or “peephole” Can also be applied to intermediate code prior to target instruction selection CSE 450: Compilers K. Stirewalt Peephole transformations Sliding window comprises small number of (usually contiguous) instructions Typical transformations: – Elimination of redundant loads/stores – Elimination of unreachable code – Flow of control optimizations – Algebraic simplification – Use of machine idioms CSE 450: Compilers K. Stirewalt Elimination of redundancy Naïve code-generation strategies may produce a store followed immediately by a load of the same address E.g.: ST a, R0 LD R0, a Here, the LD is clearly redundant and may be removed CSE 450: Compilers K. Stirewalt Eliminating unreachable code An unlabeled instruction that follows an unconditional jump may be removed E.g.: BR L50 LD R0, a L100: LD R1, z may be replaced with: BR L50 L100: LD R1, z CSE 450: Compilers K. Stirewalt Eliminating jumps over jumps Suppose program has code fragments executed only when a variable debug has value 1 Then might see the code: if debug == 1 goto L1 goto L2 L1: print debugging info L2: Could transform to: if debug != 1 goto L2 L1: print debugging info L2: CSE 450: Compilers K. Stirewalt Furthermore… Suppose we could determine debug == 0: if debug != 1 goto L2 L1: print debugging info L2: Then above code would reduce to: if 0 != 1 goto L2 L1: print debugging info L2: Which could be transformed to: goto L2 L1: print debugging info L2:
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern