1*9880d681SAndroid Build Coastguard WorkerDate: Fri, 1 Jun 2001 17:08:44 -0500 (CDT) 2*9880d681SAndroid Build Coastguard WorkerFrom: Chris Lattner <[email protected]> 3*9880d681SAndroid Build Coastguard WorkerTo: Vikram S. Adve <[email protected]> 4*9880d681SAndroid Build Coastguard WorkerSubject: RE: Interesting: GCC passes 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Worker> That is very interesting. I agree that some of these could be done on LLVM 7*9880d681SAndroid Build Coastguard Worker> at link-time, but it is the extra time required that concerns me. Link-time 8*9880d681SAndroid Build Coastguard Worker> optimization is severely time-constrained. 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard WorkerIf we were to reimplement any of these optimizations, I assume that we 11*9880d681SAndroid Build Coastguard Workercould do them a translation unit at a time, just as GCC does now. This 12*9880d681SAndroid Build Coastguard Workerwould lead to a pipeline like this: 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard WorkerStatic optimizations, xlation unit at a time: 15*9880d681SAndroid Build Coastguard Worker.c --GCC--> .llvm --llvmopt--> .llvm 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard WorkerLink time optimizations: 18*9880d681SAndroid Build Coastguard Worker.llvm --llvm-ld--> .llvm --llvm-link-opt--> .llvm 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard WorkerOf course, many optimizations could be shared between llvmopt and 21*9880d681SAndroid Build Coastguard Workerllvm-link-opt, but the wouldn't need to be shared... Thus compile time 22*9880d681SAndroid Build Coastguard Workercould be faster, because we are using a "smarter" IR (SSA based). 23*9880d681SAndroid Build Coastguard Worker 24*9880d681SAndroid Build Coastguard Worker> BTW, about SGI, "borrowing" SSA-based optimizations from one compiler and 25*9880d681SAndroid Build Coastguard Worker> putting it into another is not necessarily easier than re-doing it. 26*9880d681SAndroid Build Coastguard Worker> Optimization code is usually heavily tied in to the specific IR they use. 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard WorkerUnderstood. The only reason that I brought this up is because SGI's IR is 29*9880d681SAndroid Build Coastguard Workermore similar to LLVM than it is different in many respects (SSA based, 30*9880d681SAndroid Build Coastguard Workerrelatively low level, etc), and could be easily adapted. Also their 31*9880d681SAndroid Build Coastguard Workeroptimizations are written in C++ and are actually somewhat 32*9880d681SAndroid Build Coastguard Workerstructured... of course it would be no walk in the park, but it would be 33*9880d681SAndroid Build Coastguard Workermuch less time consuming to adapt, say, SSA-PRE than to rewrite it. 34*9880d681SAndroid Build Coastguard Worker 35*9880d681SAndroid Build Coastguard Worker> But your larger point is valid that adding SSA based optimizations is 36*9880d681SAndroid Build Coastguard Worker> feasible and should be fun. (Again, link time cost is the issue.) 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard WorkerAssuming linktime cost wasn't an issue, the question is: 39*9880d681SAndroid Build Coastguard WorkerDoes using GCC's backend buy us anything? 40*9880d681SAndroid Build Coastguard Worker 41*9880d681SAndroid Build Coastguard Worker> It also occurs to me that GCC is probably doing quite a bit of back-end 42*9880d681SAndroid Build Coastguard Worker> optimization (step 16 in your list). Do you have a breakdown of that? 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard WorkerNot really. The irritating part of GCC is that it mixes it all up and 45*9880d681SAndroid Build Coastguard Workerdoesn't have a clean separation of concerns. A lot of the "back end 46*9880d681SAndroid Build Coastguard Workeroptimization" happens right along with other data optimizations (ie, CSE 47*9880d681SAndroid Build Coastguard Workerof machine specific things). 48*9880d681SAndroid Build Coastguard Worker 49*9880d681SAndroid Build Coastguard WorkerAs far as REAL back end optimizations go, it looks something like this: 50*9880d681SAndroid Build Coastguard Worker 51*9880d681SAndroid Build Coastguard Worker1. Instruction combination: try to make CISCy instructions, if available 52*9880d681SAndroid Build Coastguard Worker2. Register movement: try to get registers in the right places for the 53*9880d681SAndroid Build Coastguard Workerarchitecture to avoid register to register moves. For example, try to get 54*9880d681SAndroid Build Coastguard Workerthe first argument of a function to naturally land in %o0 for sparc. 55*9880d681SAndroid Build Coastguard Worker3. Instruction scheduling: 'nuff said :) 56*9880d681SAndroid Build Coastguard Worker4. Register class preferencing: ?? 57*9880d681SAndroid Build Coastguard Worker5. Local register allocation 58*9880d681SAndroid Build Coastguard Worker6. global register allocation 59*9880d681SAndroid Build Coastguard Worker7. Spilling 60*9880d681SAndroid Build Coastguard Worker8. Local regalloc 61*9880d681SAndroid Build Coastguard Worker9. Jump optimization 62*9880d681SAndroid Build Coastguard Worker10. Delay slot scheduling 63*9880d681SAndroid Build Coastguard Worker11. Branch shorting for CISC machines 64*9880d681SAndroid Build Coastguard Worker12. Instruction selection & peephole optimization 65*9880d681SAndroid Build Coastguard Worker13. Debug info output 66*9880d681SAndroid Build Coastguard Worker 67*9880d681SAndroid Build Coastguard WorkerBut none of this would be usable for LLVM anyways, unless we were using 68*9880d681SAndroid Build Coastguard WorkerGCC as a static compiler. 69*9880d681SAndroid Build Coastguard Worker 70*9880d681SAndroid Build Coastguard Worker-Chris 71*9880d681SAndroid Build Coastguard Worker 72