370 likes | 512 Views
Exhaustive Optimization Phase Order Space Exploration. Prasad A. Kulkarni David B. Whalley Gary S. Tyson Jack W. Davidson. Optimization Phase Ordering. Optimizing compilers apply several optimization phases to improve the performance of applications.
E N D
Exhaustive Optimization Phase Order Space Exploration Prasad A. Kulkarni David B. Whalley Gary S. Tyson Jack W. Davidson Symposium on Code Generation and Optimization - 2006
Optimization Phase Ordering • Optimizing compilers apply several optimization phases to improve the performance of applications. • Optimization phases interact with each other. • Determining the best order of applying optimization phases has been a long standing problem in compilers. Symposium on Code Generation and Optimization - 2006
Exhaustive Phase Order Enumeration... is it Feasible ? • A obvious approach to address the phase ordering problem is to exhaustively evaluate all combinations of optimization phases. • Exhaustive enumeration is difficult • compilers typically contain several different optimization phases • optimizations may be successful multiple times for each function / program Symposium on Code Generation and Optimization - 2006
Optimization Space Properties • Phase ordering problem can be made more manageable by exploiting certain properties of the optimization search space • optimization phases might not be successful when attempted • many optimization phases are independent • Thus, many different orderings of optimization phases produce the same code. Symposium on Code Generation and Optimization - 2006
Re-stating the Phase Ordering Problem • Rather than considering all attempted phase sequences, the phase ordering problem can be addressed by enumerating all distinct function instances that can be produced by combination of optimization phases. • We were able to exhaustively enumerate 109 out of 111 functions, in a few minutes for most. Symposium on Code Generation and Optimization - 2006
Outline • Experimental framework • Algorithm for exhaustive enumeration of the phase order space • Search space enumeration results • Optimization phase interaction analysis • Making conventional compilation faster • Future work and conclusions Symposium on Code Generation and Optimization - 2006
Experimental Framework • We used the VPO compilation system. • VPO performs all transformations on a single representation (RTLs), so it is possible to perform most phases in an arbitrary order. • Experiments use all the 15 available optimization phases in VPO. • Target architecture was the StrongARM SA-100 processor. Symposium on Code Generation and Optimization - 2006
VPO Optimization Phases (cont...) • Register assignment (assigning pseudo registers to hardware registers) is implicitly performed before the first phase that requires it. • Some phases are applied after the sequence • fixing the entry and exit of the function to manage the run-time stack • exploiting predication on the ARM • performing instruction scheduling Symposium on Code Generation and Optimization - 2006
Disclaimers • Did not include optimization phases normally associated with compiler front ends • no memory hierarchy optimizations • no inlining or other interprocedural optimizations • Did not vary how phases are applied. • Did not include optimizations that require profile data. Symposium on Code Generation and Optimization - 2006
Benchmarks • Used one program from each of the six MiBench categories. • Total of 111 functions. Symposium on Code Generation and Optimization - 2006
Outline • Experimental framework • Exhaustive enumeration of the phase order space. • Search space enumeration results • Optimization phase interaction analysis • Making conventional compilation faster • Future work and conclusions Symposium on Code Generation and Optimization - 2006
Naïve Optimization Phase Order Space Exploration • All combinations of optimization phase sequences are attempted. L0 d a c b L1 d a d a d a d a b c b c b c b c L2 Symposium on Code Generation and Optimization - 2006
Eliminating Consecutively Applied Phases • A phase just applied in our compiler cannot be immediately active again. L0 d a c b L1 d a d a d a b c c b b c L2 Symposium on Code Generation and Optimization - 2006
Eliminating Dormant Phases • Get feedback from the compiler indicating if any transformations were successfully applied in a phase. L0 d a c b L1 d a d a d b c c b L2 Symposium on Code Generation and Optimization - 2006
Detecting Identical Function Instances • Some optimization phases are independent • example: branch chaining & register allocation • Different phase sequences can produce the same code • r[2] = 1; • r[3] = r[4] + r[2]; • instruction selection r[3] = r[4] + 1; • r[2] = 1; • r[3] = r[4] + r[2]; • constant propagation r[2] = 1; r[3] = r[4] + 1; • dead assignment elimination r[3] = r[4] + 1; Symposium on Code Generation and Optimization - 2006
Detecting Equivalent Function Instances sum = 0; for (i = 0; i < 1000; i++ ) sum += a [ i ]; Source Code r[10]=0; r[12]=HI[a]; r[12]=r[12]+LO[a]; r[1]=r[12]; r[9]=4000+r[12]; L3 r[8]=M[r[1]]; r[10]=r[10]+r[8]; r[1]=r[1]+4; IC=r[1]?r[9]; PC=IC<0,L3; Register Allocation before Code Motion r[11]=0; r[10]=HI[a]; r[10]=r[10]+LO[a]; r[1]=r[10]; r[9]=4000+r[10]; L5 r[8]=M[r[1]]; r[11]=r[11]+r[8]; r[1]=r[1]+4; IC=r[1]?r[9]; PC=IC<0,L5; Code Motion before Register Allocation r[32]=0; r[33]=HI[a]; r[33]=r[33]+LO[a]; r[34]=r[33]; r[35]=4000+r[33]; L01 r[36]=M[r[34]]; r[32]=r[32]+r[36]; r[34]=r[34]+4; IC=r[34]?r[35]; PC=IC<0,L01; After Mapping Registers Symposium on Code Generation and Optimization - 2006
Resulting Search Space • Merging equivalent function instances transforms the tree to a DAG. L0 a c b L1 a d a d d c L2 Symposium on Code Generation and Optimization - 2006
Techniques to Make Searches Faster • Kept a copy of the program representation of the unoptimized function instance in memory to avoid repeated disk accesses. • Also kept the program representation after each active phase in memory to reduce the number of phases applied for each sequence. • Reduced search time by at least a factor of 5 to 10. • Able to completely enumerate 109 out of 111 functions in our benchmark suite. Symposium on Code Generation and Optimization - 2006
Outline • Experimental framework • Exhaustive enumeration of the phase order space. • Search space enumeration results • Optimization phase interaction analysis • Making conventional compilation faster • Future work and conclusions Symposium on Code Generation and Optimization - 2006
Search Space Statistics Symposium on Code Generation and Optimization - 2006
Outline • Experimental framework • Exhaustive enumeration of the phase order space. • Search space enumeration results • Optimization phase interaction analysis • Making conventional compilation faster • Future work and conclusions Symposium on Code Generation and Optimization - 2006
5 [abc] a c b 2 1 2 [c] [ab] [bc] b c c a b 1 1 1 [d] [a] a d 1 1 Weighted Function Instance DAG • Each node is weighted by the number of paths to a leaf node. Symposium on Code Generation and Optimization - 2006
Enabling Interaction Between Phases • b enables a along the path a-b-a. 5 [abc] a c b 2 1 2 [c] [ab] [bc] b c c a b 1 1 1 [d] [a] a d 1 1 Symposium on Code Generation and Optimization - 2006
Enabling Probabilities Symposium on Code Generation and Optimization - 2006
Disabling Interaction Between Phases • b disables a along the path b-c-d. 5 [abc] a c b 2 1 2 [c] [ab] [bc] b c c a b 1 1 1 [d] [a] a d 1 1 Symposium on Code Generation and Optimization - 2006
Disabling Probabilities Symposium on Code Generation and Optimization - 2006
Disabling Probabilities Symposium on Code Generation and Optimization - 2006
Outline • Experimental framework • Exhaustive enumeration of the phase order space. • Search space enumeration results • Optimization phase interaction analysis • Making conventional compilation faster • Future work and conclusions Symposium on Code Generation and Optimization - 2006
Faster Conventional Compiler • We modified the VPO compiler to use enabling and disabling probabilities to decrease compilation time. # p[i] - current probability of phase i being active # e[i][j] - probability of phase j enabling phase i # d[i][j] - probability of phase j disabling phase i Foreach phase i do p[i] = e[i][st]; While (any p[i] > 0) do Select j as the current phase with highest probability of being active Apply phase j If phase j was active thenFor each phase i, where i != j do p[i] += ((1-p[i]) * e[i][j]) - (p[i] * d[i][j]) p[j] = 0 Symposium on Code Generation and Optimization - 2006
Probabilistic Compilation Results Symposium on Code Generation and Optimization - 2006
Outline • Experimental framework • Exhaustive enumeration of the phase order space. • Search space enumeration results • Optimization phase interaction analysis • Making conventional compilation faster • Future work and conclusions Symposium on Code Generation and Optimization - 2006
Future Work • Study methods to find more equivalent performing function instances to further reduce the optimization phase order space. • Evaluate approaches to find the dynamically optimal function instance. • Improve non-exhaustive searches of the phase order space. • Study additional methods to improve conventional compilers. Symposium on Code Generation and Optimization - 2006
Conclusions • First work to show that the optimization phase order space can often be completely enumerated (at least for the phases in our compiler). • First analysis of the entire phase order space to capture various phase probabilities. • Used phase interaction information to achieve a much faster compiler that still generates comparable code. Symposium on Code Generation and Optimization - 2006
Optimization Phase Independence • a-c and c-a are independent. 5 [abc] a c b 2 1 2 [c] [ab] [bc] b c c a b 1 1 1 [d] [a] a d 1 1 Symposium on Code Generation and Optimization - 2006
Optimization Phase Independence • b-c and c-b are not independent. 5 [abc] a c b 2 1 2 [c] [ab] [bc] b c c a b 1 1 1 [d] [a] a d 1 1 Symposium on Code Generation and Optimization - 2006
Independence Probabilities Symposium on Code Generation and Optimization - 2006
Independence Probabilities Symposium on Code Generation and Optimization - 2006