1 / 8

Optimization

Optimization. CPSC 388 Ellen Walker Hiram College. Areas for Optimization. Register allocation Unnecessary operations Costly operations. Register Allocation. In most architectures, values must be in registers to be operated on In memory: load, act, store

kiara-foley
Download Presentation

Optimization

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. Optimization CPSC 388 Ellen Walker Hiram College

  2. Areas for Optimization • Register allocation • Unnecessary operations • Costly operations

  3. Register Allocation • In most architectures, values must be in registers to be operated on • In memory: load, act, store • Must allocate values (temporary and variable) to a limited # of registers • If both memory & register operations are available, registers are faster

  4. Unnecessary Operations • Common subexpression elimination • Save partial values instead of recomputing them • E.g. t = (a*a / (a*a + b*b)) • Dead code elimination • Don’t generate unreachable code • Jump optimization • Avoid jumping to jump statements • Useless code • Store X ; Load X

  5. Costly Operations : Reduction in Strength • Don’t call a power function if you can multiply • (x*x vs x^2) • Don’t multiply when you can shift • (x<<4 vs. 16*x)

  6. Costly Operations: Constant Folding • Don’t generate operations on constants; do them at compile time • Circ = 2 * PI * r • If a variable will act like a constant for part or all of a program, transform its expressions also (constant propagation)

  7. Costly Operations: Function Calls • Function calls have overhead • Create a new activation frame • Set up parameters & return value • Remove activation frame & jump to return • Avoid by inlining (insert function code directly • Eliminate tail recursion with loop

  8. Recognizing Tail Recursion • Last step of recursive program is the recursive call • No use of local variables after the recursive call • Trace looks like “>” (all the way in, then all the way out)

More Related