Limitations of Optimizing Compilers behavior that may be obvious to the programmer can be obfuscated by languages and coding styles e.g., data ranges may be more limited than variable types sugges e.g., using an"int"in C for what could be an enumerated type obfuscated:混乱 16
16 Limitations of Optimizing Compilers • Behavior that may be obvious to the programmer can be obfuscated by languages and coding styles – e.g., data ranges may be more limited than variable types suggest • e.g., using an “int” in C for what could be an enumerated type obfuscated:混乱
Limitations of Optimizing Compilers Most analysis is performed only within procedures whole-program analysis is too expensive in most cases Most analysis is based only on static information compiler has difficulty anticipating run-time inputs When in doubt the compiler must be conservative
17 Limitations of Optimizing Compilers • Most analysis is performed only within procedures – whole-program analysis is too expensive in most cases • Most analysis is based only on static information – compiler has difficulty anticipating run-time inputs • When in doubt, the compiler must be conservative
Optimization Blockers P380 Memory aliasing oid twiddle (int *xp, int *yp) *xp + *yp Y void twiddle(int *xp, int *yp) *x+=2**yp 18
18 Optimization Blockers P380 • Memory aliasing void twiddle1(int *xp, int *yp) { *xp += *yp ; *xp += *yp ; } void twiddle2(int *xp, int *yp) { *xp += 2* *yp ; }
Optimization Blockers P381 Function call and side effect int f(int); int funcl(x) return f(x)+f(x)+f(x)+f(x)i int func2(x) return 4*f(x)
19 Optimization Blockers P381 • Function call and side effect int f(int) ; int func1(x) { return f(x)+f(x)+f(x)+f(x) ; } int func2(x) { return 4*f(x) ; }
Optimization Blockers P381 Function call and side effect int counter 0 int f(int x) xe七 urn counter++
20 Optimization Blockers P381 • Function call and side effect int counter = 0 ; int f(int x) { return counter++ ; }