Ch9c - 1 ! Code Generation" Part III! Chapter 8"...

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

View Full Document Right Arrow Icon
1 Code Generation Part III Chapter 8 (1 st ed. Ch.9) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Classic Examples of Local and Global Code Optimizations Local – Constant folding – Constant combining – Strength reduction – Constant propagation – Common subexpression elimination – Backward copy propagation Global – Dead code elimination – Constant propagation – Forward copy propagation – Common subexpression elimination – Code motion – Loop strength reduction – Induction variable elimination
Background image of page 2
3 Local: Constant Folding r7 = 4 + 1 r5 = 2 * r4 r6 = r5 * 2 src1(X) = 4 src2(X) = 1 Goal: eliminate unnecessary operations Rules: 1. X is an arithmetic operation 2. If src1(X) and src2(X) are constant, then change X by applying the operation
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Local: Constant Combining r7 = 5 r5 = 2 * r4 r6 = r5 * 2 r6 = r4 * 4 Goal: eliminate unnecessary operations First operation often becomes dead after constant combining Rules: 1. Operations X and Y in same basic block 2. X and Y have at least one literal src 3. Y uses dest(X) 4. None of the srcs of X have defs between X and Y (excluding Y)
Background image of page 4
5 Local: Strength Reduction r7 = 5 r5 = 2 * r4 r6 = r4 * 4 r6 = r4 << 2 r5 = r4 + r4 Goal: replace expensive operations with cheaper ones Rules (common): 1. X is an multiplication operation where src1(X) or src2(X) is a const 2 k integer literal 2. Change X by using shift operation 3. For k =1 can use add
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Local: Constant Propagation r1 = 5
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

Ch9c - 1 ! Code Generation&quot; Part III! Chapter 8&quot;...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online