Brian Gaeke | 3ca4fcc | 2004-04-25 07:04:49 +0000 | [diff] [blame] | 1 | //===-- SparcV9TargetMachine.cpp - SparcV9 Target Machine Implementation --===// |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | d71295a | 2003-12-17 22:04:00 +0000 | [diff] [blame] | 9 | // |
| 10 | // Primary interface to machine description for the UltraSPARC. Primarily just |
| 11 | // initializes machine-dependent parameters in class TargetMachine, and creates |
| 12 | // machine-dependent subclasses for classes such as TargetInstrInfo. |
| 13 | // |
Chris Lattner | 1d21f3e | 2002-04-09 05:21:26 +0000 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 15 | |
Chris Lattner | 2fbfdcf | 2002-04-07 20:49:59 +0000 | [diff] [blame] | 16 | #include "llvm/Function.h" |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 17 | #include "llvm/PassManager.h" |
Chris Lattner | 48e6079 | 2003-08-13 02:38:16 +0000 | [diff] [blame] | 18 | #include "llvm/Assembly/PrintModulePass.h" |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/InstrScheduling.h" |
Chris Lattner | 3048373 | 2004-06-20 07:49:54 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Misha Brukman | d71295a | 2003-12-17 22:04:00 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 56d2251 | 2003-09-30 22:24:00 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/Passes.h" |
Chris Lattner | 0cf0c37 | 2004-07-11 04:17:10 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetOptions.h" |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetMachineRegistry.h" |
Misha Brukman | d71295a | 2003-12-17 22:04:00 +0000 | [diff] [blame] | 25 | #include "llvm/Transforms/Scalar.h" |
| 26 | #include "MappingInfo.h" |
Chris Lattner | 85015a0 | 2004-08-16 21:55:02 +0000 | [diff] [blame] | 27 | #include "MachineFunctionInfo.h" |
| 28 | #include "MachineCodeForInstruction.h" |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 29 | #include "SparcV9Internals.h" |
| 30 | #include "SparcV9TargetMachine.h" |
Brian Gaeke | aceb7d8 | 2004-08-04 07:30:04 +0000 | [diff] [blame] | 31 | #include "SparcV9BurgISel.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 32 | #include "llvm/Support/CommandLine.h" |
Misha Brukman | d71295a | 2003-12-17 22:04:00 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
Chris Lattner | 6af2040 | 2002-12-03 05:41:54 +0000 | [diff] [blame] | 35 | static const unsigned ImplicitRegUseList[] = { 0 }; /* not used yet */ |
Chris Lattner | 9a3d63b | 2001-09-19 15:56:23 +0000 | [diff] [blame] | 36 | // Build the MachineInstruction Description Array... |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 37 | const TargetInstrDescriptor llvm::SparcV9MachineInstrDesc[] = { |
Chris Lattner | 9a3d63b | 2001-09-19 15:56:23 +0000 | [diff] [blame] | 38 | #define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \ |
| 39 | NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \ |
| 40 | { OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \ |
Chris Lattner | 6af2040 | 2002-12-03 05:41:54 +0000 | [diff] [blame] | 41 | NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS, 0, \ |
| 42 | ImplicitRegUseList, ImplicitRegUseList }, |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 43 | #include "SparcV9Instr.def" |
Chris Lattner | 9a3d63b | 2001-09-19 15:56:23 +0000 | [diff] [blame] | 44 | }; |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 45 | |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 46 | //--------------------------------------------------------------------------- |
| 47 | // Command line options to control choice of code generation passes. |
| 48 | //--------------------------------------------------------------------------- |
| 49 | |
Brian Gaeke | 828c68a | 2004-09-30 20:20:01 +0000 | [diff] [blame] | 50 | namespace llvm { |
| 51 | bool EmitMappingInfo = false; |
| 52 | } |
| 53 | |
Misha Brukman | 1be1a23 | 2003-11-13 00:16:28 +0000 | [diff] [blame] | 54 | namespace { |
| 55 | cl::opt<bool> DisableSched("disable-sched", |
| 56 | cl::desc("Disable local scheduling pass")); |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 57 | |
Misha Brukman | 1be1a23 | 2003-11-13 00:16:28 +0000 | [diff] [blame] | 58 | cl::opt<bool> DisablePeephole("disable-peephole", |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 59 | cl::desc("Disable peephole optimization pass")); |
| 60 | |
Brian Gaeke | 828c68a | 2004-09-30 20:20:01 +0000 | [diff] [blame] | 61 | cl::opt<bool, true> EmitMappingInfoOpt("enable-maps", |
| 62 | cl::location(EmitMappingInfo), |
| 63 | cl::init(false), |
Misha Brukman | 1be1a23 | 2003-11-13 00:16:28 +0000 | [diff] [blame] | 64 | cl::desc("Emit LLVM-to-MachineCode mapping info to assembly")); |
Brian Gaeke | 2e2f2dc | 2003-06-18 21:14:23 +0000 | [diff] [blame] | 65 | |
Tanya Lattner | def5745 | 2004-11-19 23:34:33 +0000 | [diff] [blame] | 66 | cl::opt<bool> EnableModSched("enable-modsched", |
| 67 | cl::desc("Enable modulo scheduling pass instead of local scheduling"), cl::Hidden); |
Tanya Lattner | 75e8419 | 2004-11-18 18:38:01 +0000 | [diff] [blame] | 68 | |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 69 | // Register the target. |
Chris Lattner | 71d24aa | 2004-07-11 03:27:42 +0000 | [diff] [blame] | 70 | RegisterTarget<SparcV9TargetMachine> X("sparcv9", " SPARC V9"); |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | unsigned SparcV9TargetMachine::getJITMatchQuality() { |
Misha Brukman | 1155d31 | 2004-09-29 23:01:17 +0000 | [diff] [blame] | 74 | #if defined(__sparcv9) |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 75 | return 10; |
| 76 | #else |
| 77 | return 0; |
| 78 | #endif |
| 79 | } |
| 80 | |
| 81 | unsigned SparcV9TargetMachine::getModuleMatchQuality(const Module &M) { |
| 82 | if (M.getEndianness() == Module::BigEndian && |
| 83 | M.getPointerSize() == Module::Pointer64) |
| 84 | return 10; // Direct match |
| 85 | else if (M.getEndianness() != Module::AnyEndianness || |
| 86 | M.getPointerSize() != Module::AnyPointerSize) |
| 87 | return 0; // Match for some other target |
| 88 | |
| 89 | return getJITMatchQuality()/2; |
Misha Brukman | 1be1a23 | 2003-11-13 00:16:28 +0000 | [diff] [blame] | 90 | } |
Brian Gaeke | 2e2f2dc | 2003-06-18 21:14:23 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 583b9d8 | 2003-12-20 09:17:40 +0000 | [diff] [blame] | 92 | //===---------------------------------------------------------------------===// |
| 93 | // Code generation/destruction passes |
| 94 | //===---------------------------------------------------------------------===// |
| 95 | |
| 96 | namespace { |
| 97 | class ConstructMachineFunction : public FunctionPass { |
| 98 | TargetMachine &Target; |
| 99 | public: |
| 100 | ConstructMachineFunction(TargetMachine &T) : Target(T) {} |
| 101 | |
| 102 | const char *getPassName() const { |
| 103 | return "ConstructMachineFunction"; |
| 104 | } |
| 105 | |
| 106 | bool runOnFunction(Function &F) { |
Chris Lattner | a1e51ff | 2004-08-18 18:13:37 +0000 | [diff] [blame] | 107 | MachineFunction::construct(&F, Target).getInfo<SparcV9FunctionInfo>()->CalculateArgSize(); |
Chris Lattner | 583b9d8 | 2003-12-20 09:17:40 +0000 | [diff] [blame] | 108 | return false; |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | struct DestroyMachineFunction : public FunctionPass { |
Brian Gaeke | 3d1fdee | 2004-02-27 21:01:14 +0000 | [diff] [blame] | 113 | const char *getPassName() const { return "DestroyMachineFunction"; } |
Chris Lattner | 583b9d8 | 2003-12-20 09:17:40 +0000 | [diff] [blame] | 114 | |
| 115 | static void freeMachineCode(Instruction &I) { |
| 116 | MachineCodeForInstruction::destroy(&I); |
| 117 | } |
| 118 | |
| 119 | bool runOnFunction(Function &F) { |
| 120 | for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) |
| 121 | for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E; ++I) |
| 122 | MachineCodeForInstruction::get(I).dropAllReferences(); |
| 123 | |
| 124 | for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ++FI) |
| 125 | for_each(FI->begin(), FI->end(), freeMachineCode); |
| 126 | |
Misha Brukman | 3615845 | 2003-12-22 03:47:58 +0000 | [diff] [blame] | 127 | MachineFunction::destruct(&F); |
Chris Lattner | 583b9d8 | 2003-12-20 09:17:40 +0000 | [diff] [blame] | 128 | return false; |
| 129 | } |
| 130 | }; |
| 131 | |
| 132 | FunctionPass *createMachineCodeConstructionPass(TargetMachine &Target) { |
| 133 | return new ConstructMachineFunction(Target); |
| 134 | } |
| 135 | } |
| 136 | |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 137 | FunctionPass *llvm::createSparcV9MachineCodeDestructionPass() { |
Chris Lattner | 583b9d8 | 2003-12-20 09:17:40 +0000 | [diff] [blame] | 138 | return new DestroyMachineFunction(); |
| 139 | } |
| 140 | |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 141 | |
Chris Lattner | d36c970 | 2004-07-11 02:48:49 +0000 | [diff] [blame] | 142 | SparcV9TargetMachine::SparcV9TargetMachine(const Module &M, |
| 143 | IntrinsicLowering *il) |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 144 | : TargetMachine("UltraSparcV9-Native", il, false), |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 145 | schedInfo(*this), |
| 146 | regInfo(*this), |
Vikram S. Adve | b704840 | 2001-11-09 02:16:04 +0000 | [diff] [blame] | 147 | frameInfo(*this), |
Chris Lattner | f70e0c2 | 2003-12-28 21:23:38 +0000 | [diff] [blame] | 148 | jitInfo(*this) { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Misha Brukman | 2647c39 | 2004-02-09 23:18:42 +0000 | [diff] [blame] | 151 | /// addPassesToEmitAssembly - This method controls the entire code generation |
| 152 | /// process for the ultra sparc. |
| 153 | /// |
Misha Brukman | d71295a | 2003-12-17 22:04:00 +0000 | [diff] [blame] | 154 | bool |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 155 | SparcV9TargetMachine::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 156 | { |
Chris Lattner | 99c59e8 | 2004-05-23 21:23:35 +0000 | [diff] [blame] | 157 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 158 | PM.add(createLowerGCPass()); |
| 159 | |
Brian Gaeke | 2e2f2dc | 2003-06-18 21:14:23 +0000 | [diff] [blame] | 160 | // Replace malloc and free instructions with library calls. |
| 161 | PM.add(createLowerAllocationsPass()); |
| 162 | |
Chris Lattner | 155e68f | 2003-04-23 16:24:55 +0000 | [diff] [blame] | 163 | // FIXME: implement the switch instruction in the instruction selector. |
| 164 | PM.add(createLowerSwitchPass()); |
Chris Lattner | d324e25 | 2003-10-05 19:16:09 +0000 | [diff] [blame] | 165 | |
| 166 | // FIXME: implement the invoke/unwind instructions! |
| 167 | PM.add(createLowerInvokePass()); |
Brian Gaeke | 2e2f2dc | 2003-06-18 21:14:23 +0000 | [diff] [blame] | 168 | |
Vikram S. Adve | 248932b | 2003-08-01 15:53:24 +0000 | [diff] [blame] | 169 | // decompose multi-dimensional array references into single-dim refs |
| 170 | PM.add(createDecomposeMultiDimRefsPass()); |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 171 | |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 172 | // Lower LLVM code to the form expected by the SPARCv9 instruction selector. |
Misha Brukman | 3518817 | 2003-11-07 20:33:25 +0000 | [diff] [blame] | 173 | PM.add(createPreSelectionPass(*this)); |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 174 | PM.add(createLowerSelectPass()); |
| 175 | |
| 176 | // Run basic LLVM dataflow optimizations, to clean up after pre-selection. |
Misha Brukman | 3518817 | 2003-11-07 20:33:25 +0000 | [diff] [blame] | 177 | PM.add(createReassociatePass()); |
| 178 | PM.add(createLICMPass()); |
| 179 | PM.add(createGCSEPass()); |
| 180 | |
Brian Gaeke | b985158 | 2004-05-28 19:33:59 +0000 | [diff] [blame] | 181 | // If the user's trying to read the generated code, they'll need to see the |
| 182 | // transformed input. |
| 183 | if (PrintMachineCode) |
| 184 | PM.add(new PrintModulePass()); |
| 185 | |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 186 | // Construct and initialize the MachineFunction object for this fn. |
| 187 | PM.add(createMachineCodeConstructionPass(*this)); |
| 188 | |
| 189 | // Insert empty stackslots in the stack frame of each function |
| 190 | // so %fp+offset-8 and %fp+offset-16 are empty slots now! |
| 191 | PM.add(createStackSlotsPass(*this)); |
| 192 | |
Brian Gaeke | aceb7d8 | 2004-08-04 07:30:04 +0000 | [diff] [blame] | 193 | PM.add(createSparcV9BurgInstSelector(*this)); |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 194 | |
Tanya Lattner | 75e8419 | 2004-11-18 18:38:01 +0000 | [diff] [blame] | 195 | if(PrintMachineCode) |
| 196 | PM.add(createMachineFunctionPrinterPass(&std::cerr, "Before modulo scheduling:\n")); |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 197 | |
Tanya Lattner | 75e8419 | 2004-11-18 18:38:01 +0000 | [diff] [blame] | 198 | //Use ModuloScheduling if enabled, otherwise use local scheduling if not disabled. |
| 199 | if(EnableModSched) |
| 200 | PM.add(createModuloSchedulingPass(*this)); |
| 201 | else { |
| 202 | if (!DisableSched) |
| 203 | PM.add(createInstructionSchedulingWithSSAPass(*this)); |
| 204 | } |
| 205 | |
Brian Gaeke | 215fb76 | 2004-03-12 21:19:08 +0000 | [diff] [blame] | 206 | if (PrintMachineCode) |
| 207 | PM.add(createMachineFunctionPrinterPass(&std::cerr, "Before reg alloc:\n")); |
| 208 | |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 209 | PM.add(getRegisterAllocator(*this)); |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 210 | |
| 211 | if (PrintMachineCode) |
Brian Gaeke | 215fb76 | 2004-03-12 21:19:08 +0000 | [diff] [blame] | 212 | PM.add(createMachineFunctionPrinterPass(&std::cerr, "After reg alloc:\n")); |
Brian Gaeke | 323819e | 2004-03-04 19:16:23 +0000 | [diff] [blame] | 213 | |
Misha Brukman | 1be1a23 | 2003-11-13 00:16:28 +0000 | [diff] [blame] | 214 | PM.add(createPrologEpilogInsertionPass()); |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 215 | |
| 216 | if (!DisablePeephole) |
| 217 | PM.add(createPeepholeOptsPass(*this)); |
| 218 | |
Brian Gaeke | f3210d2 | 2004-06-14 05:05:45 +0000 | [diff] [blame] | 219 | if (PrintMachineCode) |
| 220 | PM.add(createMachineFunctionPrinterPass(&std::cerr, "Final code:\n")); |
| 221 | |
Brian Gaeke | 5821595 | 2004-06-03 05:03:01 +0000 | [diff] [blame] | 222 | if (EmitMappingInfo) { |
| 223 | PM.add(createInternalGlobalMapperPass()); |
| 224 | PM.add(getMappingInfoAsmPrinterPass(Out)); |
| 225 | } |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 226 | |
| 227 | // Output assembly language to the .s file. Assembly emission is split into |
| 228 | // two parts: Function output and Global value output. This is because |
| 229 | // function output is pipelined with all of the rest of code generation stuff, |
| 230 | // allowing machine code representations for functions to be free'd after the |
| 231 | // function has been emitted. |
Misha Brukman | 1be1a23 | 2003-11-13 00:16:28 +0000 | [diff] [blame] | 232 | PM.add(createAsmPrinterPass(Out, *this)); |
Brian Gaeke | 9f78bf2 | 2004-02-27 21:15:40 +0000 | [diff] [blame] | 233 | |
Brian Gaeke | 9f78bf2 | 2004-02-27 21:15:40 +0000 | [diff] [blame] | 234 | // Free machine-code IR which is no longer needed: |
Chris Lattner | ec726a1 | 2004-03-01 15:28:27 +0000 | [diff] [blame] | 235 | PM.add(createSparcV9MachineCodeDestructionPass()); |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 236 | |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 237 | // Emit bytecode to the assembly file into its special section next |
Chris Lattner | ad79198 | 2004-12-02 21:05:01 +0000 | [diff] [blame] | 238 | if (EmitMappingInfo) |
Misha Brukman | 1be1a23 | 2003-11-13 00:16:28 +0000 | [diff] [blame] | 239 | PM.add(createBytecodeAsmPrinterPass(Out)); |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 240 | |
Chris Lattner | 6334205 | 2002-10-29 21:12:46 +0000 | [diff] [blame] | 241 | return false; |
Chris Lattner | 4f94637 | 2002-10-28 01:03:43 +0000 | [diff] [blame] | 242 | } |
Misha Brukman | 86172ab | 2003-05-27 22:24:48 +0000 | [diff] [blame] | 243 | |
Misha Brukman | 2647c39 | 2004-02-09 23:18:42 +0000 | [diff] [blame] | 244 | /// addPassesToJITCompile - This method controls the JIT method of code |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 245 | /// generation for the UltraSparcV9. |
Misha Brukman | 2647c39 | 2004-02-09 23:18:42 +0000 | [diff] [blame] | 246 | /// |
Brian Gaeke | e3d6807 | 2004-02-25 18:44:15 +0000 | [diff] [blame] | 247 | void SparcV9JITInfo::addPassesToJITCompile(FunctionPassManager &PM) { |
Chris Lattner | 99c59e8 | 2004-05-23 21:23:35 +0000 | [diff] [blame] | 248 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 249 | PM.add(createLowerGCPass()); |
| 250 | |
Misha Brukman | a512450 | 2003-06-06 07:11:16 +0000 | [diff] [blame] | 251 | // Replace malloc and free instructions with library calls. |
Misha Brukman | a512450 | 2003-06-06 07:11:16 +0000 | [diff] [blame] | 252 | PM.add(createLowerAllocationsPass()); |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 253 | |
Misha Brukman | 86172ab | 2003-05-27 22:24:48 +0000 | [diff] [blame] | 254 | // FIXME: implement the switch instruction in the instruction selector. |
| 255 | PM.add(createLowerSwitchPass()); |
| 256 | |
Chris Lattner | d324e25 | 2003-10-05 19:16:09 +0000 | [diff] [blame] | 257 | // FIXME: implement the invoke/unwind instructions! |
| 258 | PM.add(createLowerInvokePass()); |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 259 | |
Misha Brukman | 58ba50f | 2003-08-06 23:06:21 +0000 | [diff] [blame] | 260 | // decompose multi-dimensional array references into single-dim refs |
| 261 | PM.add(createDecomposeMultiDimRefsPass()); |
Misha Brukman | 86172ab | 2003-05-27 22:24:48 +0000 | [diff] [blame] | 262 | |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 263 | // Lower LLVM code to the form expected by the SPARCv9 instruction selector. |
Chris Lattner | 1e60a91 | 2003-12-20 01:22:19 +0000 | [diff] [blame] | 264 | PM.add(createPreSelectionPass(TM)); |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 265 | PM.add(createLowerSelectPass()); |
| 266 | |
| 267 | // Run basic LLVM dataflow optimizations, to clean up after pre-selection. |
Misha Brukman | 3518817 | 2003-11-07 20:33:25 +0000 | [diff] [blame] | 268 | PM.add(createReassociatePass()); |
Misha Brukman | 6d2670d | 2003-11-08 00:01:39 +0000 | [diff] [blame] | 269 | // FIXME: these passes crash the FunctionPassManager when being added... |
| 270 | //PM.add(createLICMPass()); |
| 271 | //PM.add(createGCSEPass()); |
Misha Brukman | 3518817 | 2003-11-07 20:33:25 +0000 | [diff] [blame] | 272 | |
Brian Gaeke | f3210d2 | 2004-06-14 05:05:45 +0000 | [diff] [blame] | 273 | // If the user's trying to read the generated code, they'll need to see the |
| 274 | // transformed input. |
| 275 | if (PrintMachineCode) |
| 276 | PM.add(new PrintFunctionPass()); |
| 277 | |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 278 | // Construct and initialize the MachineFunction object for this fn. |
| 279 | PM.add(createMachineCodeConstructionPass(TM)); |
| 280 | |
Brian Gaeke | aceb7d8 | 2004-08-04 07:30:04 +0000 | [diff] [blame] | 281 | PM.add(createSparcV9BurgInstSelector(TM)); |
Misha Brukman | 86172ab | 2003-05-27 22:24:48 +0000 | [diff] [blame] | 282 | |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 283 | if (PrintMachineCode) |
| 284 | PM.add(createMachineFunctionPrinterPass(&std::cerr, "Before reg alloc:\n")); |
| 285 | |
Chris Lattner | 1e60a91 | 2003-12-20 01:22:19 +0000 | [diff] [blame] | 286 | PM.add(getRegisterAllocator(TM)); |
Brian Gaeke | 79ee87b | 2004-04-02 17:52:40 +0000 | [diff] [blame] | 287 | |
| 288 | if (PrintMachineCode) |
| 289 | PM.add(createMachineFunctionPrinterPass(&std::cerr, "After reg alloc:\n")); |
| 290 | |
Misha Brukman | 1be1a23 | 2003-11-13 00:16:28 +0000 | [diff] [blame] | 291 | PM.add(createPrologEpilogInsertionPass()); |
Misha Brukman | 86172ab | 2003-05-27 22:24:48 +0000 | [diff] [blame] | 292 | |
Misha Brukman | d1ef7a8 | 2003-05-30 20:00:13 +0000 | [diff] [blame] | 293 | if (!DisablePeephole) |
Chris Lattner | 1e60a91 | 2003-12-20 01:22:19 +0000 | [diff] [blame] | 294 | PM.add(createPeepholeOptsPass(TM)); |
Brian Gaeke | f3210d2 | 2004-06-14 05:05:45 +0000 | [diff] [blame] | 295 | |
| 296 | if (PrintMachineCode) |
| 297 | PM.add(createMachineFunctionPrinterPass(&std::cerr, "Final code:\n")); |
Misha Brukman | 86172ab | 2003-05-27 22:24:48 +0000 | [diff] [blame] | 298 | } |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 299 | |