{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

optimization - Machine Independent Code Optimizations...

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

View Full Document Right Arrow Icon
cs5363 1 Machine Independent Code Optimizations Useless Code and Redundant Expression Elimination
Image of page 1

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

View Full Document Right Arrow Icon
cs5363 2 Code Optimization The goal of code optimization is to Discover program run-time behavior at compile time Use the information to improve generated code Speed up runtime execution of compiled code Reduce the size of compiled code Correctness (safety) Optimizations must preserve the meaning of the input code Profitability Optimizations must improve code quality Front end Back end optimizer (Mid end) Source program IR IR Target program compiler
Image of page 2
cs5363 3 Applying Optimizations Most optimizations are separated into two phases Program analysis: discover opportunity and prove safety Program transformation: rewrite code to improve quality The input code may benefit from many optimizations Every optimization acts as a filtering pass that translate one IR into another IR for further optimization Compilers Select a set of optimizations to implement Decide orders of applying implemented optimizations The safety of optimizations depends on results of program analysis Optimizations often interact with each other and need to be combined in specific ways Some optimizations may need to applied multiple times E.g., dead code elimination, redundancy elimination, copy folding Implement predetermined passes of optimizations
Image of page 3

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

View Full Document Right Arrow Icon
cs5363 4 Scalar Compiler Optimizations Machine independent optimizations Enable other transformations Procedure inlining, cloning, loop unrolling Eliminate redundancy Redundant expression elimination Eliminate useless and unreachable code Dead code elimination Specialization and strength reduction Constant propagation, peephole optimization Move operations to less-frequently executed places Loop invariant code motion Machine dependent (scheduling) transformations Take advantage of special hardware features Instruction selection, prefetching Manage or hide latency, introduce parallelism Instruction scheduling, prefetching Manage bounded machine resources Register allocation
Image of page 4
cs5363 5 Scope Of Optimization Local methods Applicable only to basic blocks Superlocal methods Operate on extended basic blocks (EBB) B1,B2,B3,…,Bm, where Bi is the single predecessor of B(i+1) Regional methods Operate beyond EBBs, e.g. loops, conditionals Global (intraprocedural) methods Operate on entire procedure (subroutine) Whole-program (interprocedural) methods Operate on entire program S0: if i< 50 goto s1 goto s2 s1: t1 := b * 2 a := a + t1 goto s0 S2: …… i :=0 EBB
Image of page 5

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

View Full Document Right Arrow Icon
cs5363 6 Loop Unrolling An enabling transformation to expose opportunities for other optimizations Reduce the number of branches by a factor 4 Provide a bigger basic block (loop body) for local optimization Better instruction scheduling and register allocation do i = 1 to n by 1 a(i) = a(i) + b(i) end do i = 1 to 100 by 4 a(i) = a(i) + b(i) a(i+1) = a(i+1) + b(i+1) a(i+2) = a(i+2) + b(i+2) a(i+3) = a(i+3) + b(i+3) end Original loop Unrolled by 4, n = 100
Image of page 6
Image of page 7
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