



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




CS553 Lecture Dynamic Optimizations 2
Last time
CS553 Lecture Dynamic Optimizations 4 Basic idea
Exploiting runtime constants − Perform constant propagation − Eliminate memory ops − Remove branches − Unroll loops Improves performance by moving computation from runtime to compile time CS553 Lecture Dynamic Optimizations 5
Interpreters: Simulators: Graphics renderers: Scientific simulations: Extensible OS kernels: Examples
CS553 Lecture Dynamic Optimizations 6
Active research area
DyC [Auslander, et al 1996]
System goal
annotated C code (^) static compiler template setup code directives dynamic compiler (stitcher) executable program runtime values static compile time dynamic compile time − Make the static compiler do as much work as possible − Give the dynamic compiler as little work as possible
CS553 Lecture Dynamic Optimizations 14 cacheResult cacheLookup (void *addr, Cache cache) { dynamicRegion (cache) { / cache is a runtime constant */ int blockSize = cache->blockSize; int numLines = cache->numLines; int tag = addr / (blockSize * numLines); int line = (add / blockSize) % numLines; setStructure *setArray = cache->lines[line]->sets; int assoc = cache->associativity; int set; unrolled for (set=0; set<assoc; set++) { if (setArray[set] dynamic ->tag == tag) return CacheHit; } return CacheMiss; } / end of dynamic region */ }
dynamic − Any type of data can be considered constant − In particular, contents of arrays and pointer-based structures are assumed to be runtime constant whenever they are accessed by runtime constant pointers − To ensure that this assumption is correct, users must insert the dynamic annotation to mark pointer refs that are not constant CS553 Lecture Dynamic Optimizations 15 cacheResult cacheLookup (void *addr, Cache cache) { dynamicRegion (cache) { / cache is a runtime constant */ int blockSize = cache->blockSize; int numLines = cache->numLines; int tag = addr / (blockSize * numLines); int line = (add / blockSize) % numLines; setStructure *setArray = cache->lines[line]->sets; int assoc = cache->associativity; int set; unrolled for (set=0; set<assoc; set++) { if (setArray[set] dynamic ->tag == tag) return CacheHit; } return CacheMiss; } / end of dynamic region */ }
unrolled − Directs the compiler to completely unroll a loop − Loop termination must be governed by runtime constants − The static compiler can check whether this annotation is legal − Complete unrolling is a critical optimization − Allows induction variables to become runtime constants CS553 Lecture Dynamic Optimizations 16 cacheResult cacheLookup (void *addr, Cache *cache) { dynamicRegion key (cache, foo) { int blockSize = cache->blockSize; int numLines = cache->numLines; int tag = addr / (blockSize * numLines); int line = (add / blockSize) % numLines; setStructure *setArray = cache->lines[line]->sets; int assoc = cache->associativity; int set; unrolled for (set=0; set<assoc; set++) { if (setArray[set] dynamic ->tag == tag) return CacheHit; } return CacheMiss; } / end of dynamic region */ }
key − Allows the creation of multiple versions of a dynamic region, each using different runtime constants − Separate code is dynamically generated for each distinct combination of values of the runtime constants CS553 Lecture Dynamic Optimizations 17
Annotation errors
CS553 Lecture Dynamic Optimizations 18
Operates on low-level IR
Simple data-flow analysis
Merging control flow
Integrated optimizations
CS553 Lecture Dynamic Optimizations 26
Today’s discussion
Is dynamic compilation worthwhile?
Reading