230 likes | 242 Views
This research paper explores a dynamic programming approach for optimal integrated code generation, including instruction scheduling and register allocation. Implementation, results, related work, and future work are discussed.
E N D
A Dynamic Programming Approach to Optimal Integrated Code Generation Christoph Keßler Andrzej Bednarski Linköping University (Sweden)
Outline • Code generation • Our integrated approach • Implementation and results • Current and future work • Conclusion
Code Generation IR-level Instruction scheduling IR-level Reg. Alloc IR-level Reg. Alloc IR IR-level Instruction scheduling Instruction selection Instruction selection Instruction selection Instruction selection Target code Target-level Instruction scheduling Target-level Reg. Alloc Target-level Reg. Alloc Target-level Instruction scheduling
Related Work • Heuristics • Optimal approaches • ILP • Dynamic programming • Branch-and-bound • Enumeration • Constraint logic programming
Integrated Code Generation IR-level Instruction scheduling IR-level Reg. Alloc IR-level Reg. Alloc IR IR-level Instruction scheduling Instruction selection Instruction selection Integrated Code generation Instruction selection Instruction selection Target code Target-level Instruction scheduling Target-level Reg. Alloc Target-level Reg. Alloc Target-level Instruction scheduling
Integrated Approach • Christoph Keßler’s previous work • Scheduling by topological sorting • Dynamic programming • Selection DAG • Time profile • Extended selection DAG Basic block scope of code generation
z z’ v v u u scheduled(z) scheduled(z’) Topological Sorting
{a,b,c} a c b {b,c} {a,c} {a,b} b c a c a b {c,d} {b} {c,d} {a,e} {b} {a,e} h … … … … … … f g d e a b c Selection Tree
Selection DAG • Merge multiple instances of same zero indegree set z in one selection node • Selection DAG • Selection DAG is leveled in n+1 levels • Each schedule S corresponds to one path in the selection DAG
{a,b,c} a c b {b,c} {a,c} {a,b} a a b c c b {c,d} {b} {a,e} h … … … f g d e a b c Selection DAG
Towards Time Optimization • Machine model • Generic superscalar/VLIW architecture • Single/Multiple issue • From IR level to target level • Instruction selection • Register allocation (homogenous) • Imitate instruction dispatcher behaviour
time Time Profile • Window of the instructions scheduled last for each unit that may still influence future scheduling decisions t e f - - c d b - - a - - u1 u2 u3
time Extended Selection Node • An extended selection node (z, t, P), summarizes all schedules of scheduled(z) that end with the time profile (t, P). • Pruning (formal proof in the paper) t e f - t’ t’ - c d e f - a f - b - - a c d e c d a - - b - - b - - u1 u2 u3 u1 u2 u3 u1 u2 u3
Extended Selection DAG Level 0 Level 1 Level 2 ...
Solution Space • Group the extended selection nodes in each level according to execution time • Construct solution space in order of increasing time • Postpones the combinatorial explosion
Implementation • C++ • LEDA • XML based architecture description language • LCC as C–front-end
Current and Future Work • Time-space profile for irregular register sets • Speculative instruction selection • Extensions of architecture description language • Beyond basic block level • Time-space profiles as connector descriptions
Conclusion • Goal: fully integrated code generation • Dynamic programming approach • Time profiles to compressthe solution space • Improved order of solution space construction • Feasible for medium sized basic blocks • Potential for extensions • Alternative to ILP • Home page: www.ida.liu.se/~chrke/optimist