Title: A Dynamic Programming Approach to Optimal Integrated Code Generation
1A Dynamic Programming Approach to Optimal
Integrated Code Generation
- Christoph Keßler
- Andrzej Bednarski
- Linköping University (Sweden)
2Outline
- Code generation
- Our integrated approach
- Implementation and results
- Current and future work
- Conclusion
3Code 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
4 Related Work
- Heuristics
- Optimal approaches
- ILP
- Dynamic programming
- Branch-and-bound
- Enumeration
- Constraint logic programming
5Integrated 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
6Integrated Approach
- Christoph Keßlers previous work
- Scheduling by topological sorting
- Dynamic programming
- Selection DAG
- Time profile
- Extended selection DAG
- Basic block scope of code generation
7Topological Sorting
8Selection Tree
9Selection DAG
- Merge multiple instances of same zero indegree
set z in one selection node - Selection DAG
- Selection DAG is leveled in n1 levels
- Each schedule S corresponds to one path in the
selection DAG
10Selection DAG
11Towards 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
12Time Profile
- Window of the instructions scheduled last for
each unit that may still influence future
scheduling decisions
t
e
f
-
c
d
-
-
-
b
-
-
a
u3
u2
u1
13Extended 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
c
d
a
c
d
e
-
-
a
-
-
b
-
-
b
u3
u2
u1
u3
u2
u1
u3
u2
u1
14Extended Selection DAG
Level 0
Level 1
Level 2
...
15Solution 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
16Implementation
- C
- LEDA
- XML based architecture description language
- LCC as Cfront-end
17Results Random DAGs
18Results Random DAGs
19Results FIR Filter
Basic Block DAG nodes Time archi. 1 Time archi. 2
BB1 16 3.5s 4.0s
BB2 16 8.0s 9.5s
BB3 30 32150.2s 44044.9s
20Results Matrix Multiplication
Basic Block DAG nodes Time archi. 1 Time archi. 2
BB2 30 105.0s 141.8s
BB2 (unrolled) 40 608.5s 947.2s
21Results Jacobi Grid Relax.
Basic Block DAG nodes Time archi. 1 Time archi. 2
Loop body (5) 40 115.8s 131.8s
Loop body (9) 53 13613.2s 20051.5s
22Current 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
23Conclusion
- Goal fully integrated code generation
- Dynamic programming approach
- Time profiles to compress the 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