Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 1 | // $Id$ |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 2 | //*************************************************************************** |
| 3 | // File: |
| 4 | // Sparc.cpp |
| 5 | // |
| 6 | // Purpose: |
| 7 | // |
| 8 | // History: |
| 9 | // 7/15/01 - Vikram Adve - Created |
| 10 | //**************************************************************************/ |
| 11 | |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 12 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 13 | #include "SparcInternals.h" |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 14 | #include "llvm/Target/Sparc.h" |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/InstrScheduling.h" |
| 16 | #include "llvm/CodeGen/InstrSelection.h" |
Chris Lattner | cf4525b | 2002-02-03 07:49:15 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
| 18 | #include "llvm/CodeGen/MachineCodeForMethod.h" |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/PhyRegAlloc.h" |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 20 | #include "llvm/Method.h" |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 21 | #include "llvm/PassManager.h" |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 22 | #include <iostream> |
| 23 | using std::cerr; |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 9a3d63b | 2001-09-19 15:56:23 +0000 | [diff] [blame] | 25 | // Build the MachineInstruction Description Array... |
| 26 | const MachineInstrDescriptor SparcMachineInstrDesc[] = { |
| 27 | #define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \ |
| 28 | NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \ |
| 29 | { OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \ |
| 30 | NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS }, |
| 31 | #include "SparcInstr.def" |
| 32 | }; |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 33 | |
| 34 | //---------------------------------------------------------------------------- |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 35 | // allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine |
| 36 | // that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface) |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 37 | //---------------------------------------------------------------------------- |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 38 | // |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 40 | TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 41 | |
| 42 | |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 43 | //---------------------------------------------------------------------------- |
| 44 | // Entry point for register allocation for a module |
| 45 | //---------------------------------------------------------------------------- |
| 46 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 47 | class RegisterAllocation : public MethodPass { |
| 48 | TargetMachine &Target; |
| 49 | public: |
| 50 | inline RegisterAllocation(TargetMachine &T) : Target(T) {} |
| 51 | bool runOnMethod(Method *M) { |
| 52 | if (DEBUG_RA) |
| 53 | cerr << "\n******************** Method "<< M->getName() |
| 54 | << " ********************\n"; |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 55 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 56 | MethodLiveVarInfo LVI(M ); // Analyze live varaibles |
| 57 | LVI.analyze(); |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 58 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 59 | PhyRegAlloc PRA(M, Target, &LVI); // allocate registers |
| 60 | PRA.allocateRegisters(); |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 61 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 62 | if (DEBUG_RA) cerr << "\nRegister allocation complete!\n"; |
| 63 | return false; |
| 64 | } |
| 65 | }; |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 66 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 67 | static MachineInstr* minstrVec[MAX_INSTR_PER_VMINSTR]; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 68 | |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 69 | //--------------------------------------------------------------------------- |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 70 | // class InsertPrologEpilogCode |
| 71 | // |
| 72 | // Insert SAVE/RESTORE instructions for the method |
| 73 | // |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 74 | // Insert prolog code at the unique method entry point. |
| 75 | // Insert epilog code at each method exit point. |
| 76 | // InsertPrologEpilog invokes these only if the method is not compiled |
| 77 | // with the leaf method optimization. |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 78 | // |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 79 | //--------------------------------------------------------------------------- |
| 80 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 81 | class InsertPrologEpilogCode : public MethodPass { |
| 82 | TargetMachine &Target; |
| 83 | public: |
| 84 | inline InsertPrologEpilogCode(TargetMachine &T) : Target(T) {} |
| 85 | bool runOnMethod(Method *M) { |
| 86 | MachineCodeForMethod &mcodeInfo = MachineCodeForMethod::get(M); |
| 87 | if (!mcodeInfo.isCompiledAsLeafMethod()) { |
| 88 | InsertPrologCode(M); |
| 89 | InsertEpilogCode(M); |
| 90 | } |
| 91 | return false; |
| 92 | } |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 94 | void InsertPrologCode(Method *M); |
| 95 | void InsertEpilogCode(Method *M); |
| 96 | }; |
| 97 | |
| 98 | void InsertPrologEpilogCode::InsertPrologCode(Method* method) |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 99 | { |
| 100 | BasicBlock* entryBB = method->getEntryNode(); |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 101 | unsigned N = GetInstructionsForProlog(entryBB, Target, minstrVec); |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 102 | assert(N <= MAX_INSTR_PER_VMINSTR); |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 103 | MachineCodeForBasicBlock& bbMvec = entryBB->getMachineInstrVec(); |
| 104 | bbMvec.insert(bbMvec.begin(), minstrVec, minstrVec+N); |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 108 | void InsertPrologEpilogCode::InsertEpilogCode(Method* method) |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 109 | { |
| 110 | for (Method::iterator I=method->begin(), E=method->end(); I != E; ++I) |
| 111 | if ((*I)->getTerminator()->getOpcode() == Instruction::Ret) |
| 112 | { |
| 113 | BasicBlock* exitBB = *I; |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 114 | unsigned N = GetInstructionsForEpilog(exitBB, Target, minstrVec); |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 115 | |
| 116 | MachineCodeForBasicBlock& bbMvec = exitBB->getMachineInstrVec(); |
Chris Lattner | cf4525b | 2002-02-03 07:49:15 +0000 | [diff] [blame] | 117 | MachineCodeForInstruction &termMvec = |
| 118 | MachineCodeForInstruction::get(exitBB->getTerminator()); |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 119 | |
| 120 | // Remove the NOPs in the delay slots of the return instruction |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 121 | const MachineInstrInfo &mii = Target.getInstrInfo(); |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 122 | unsigned numNOPs = 0; |
| 123 | while (termMvec.back()->getOpCode() == NOP) |
| 124 | { |
| 125 | assert( termMvec.back() == bbMvec.back()); |
| 126 | termMvec.pop_back(); |
| 127 | bbMvec.pop_back(); |
| 128 | ++numNOPs; |
| 129 | } |
| 130 | assert(termMvec.back() == bbMvec.back()); |
| 131 | |
| 132 | // Check that we found the right number of NOPs and have the right |
| 133 | // number of instructions to replace them. |
| 134 | unsigned ndelays = mii.getNumDelaySlots(termMvec.back()->getOpCode()); |
| 135 | assert(numNOPs == ndelays && "Missing NOPs in delay slots?"); |
| 136 | assert(N == ndelays && "Cannot use epilog code for delay slots?"); |
| 137 | |
| 138 | // Append the epilog code to the end of the basic block. |
| 139 | bbMvec.push_back(minstrVec[0]); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 144 | |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 145 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 146 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 147 | //--------------------------------------------------------------------------- |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 148 | // class UltraSparcSchedInfo |
| 149 | // |
| 150 | // Purpose: |
| 151 | // Scheduling information for the UltraSPARC. |
| 152 | // Primarily just initializes machine-dependent parameters in |
| 153 | // class MachineSchedInfo. |
| 154 | //--------------------------------------------------------------------------- |
| 155 | |
| 156 | /*ctor*/ |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 157 | UltraSparcSchedInfo::UltraSparcSchedInfo(const TargetMachine& tgt) |
| 158 | : MachineSchedInfo(tgt, |
| 159 | (unsigned int) SPARC_NUM_SCHED_CLASSES, |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 160 | SparcRUsageDesc, |
| 161 | SparcInstrUsageDeltas, |
| 162 | SparcInstrIssueDeltas, |
| 163 | sizeof(SparcInstrUsageDeltas)/sizeof(InstrRUsageDelta), |
| 164 | sizeof(SparcInstrIssueDeltas)/sizeof(InstrIssueDelta)) |
| 165 | { |
| 166 | maxNumIssueTotal = 4; |
| 167 | longestIssueConflict = 0; // computed from issuesGaps[] |
| 168 | |
| 169 | branchMispredictPenalty = 4; // 4 for SPARC IIi |
| 170 | branchTargetUnknownPenalty = 2; // 2 for SPARC IIi |
| 171 | l1DCacheMissPenalty = 8; // 7 or 9 for SPARC IIi |
| 172 | l1ICacheMissPenalty = 8; // ? for SPARC IIi |
| 173 | |
| 174 | inOrderLoads = true; // true for SPARC IIi |
| 175 | inOrderIssue = true; // true for SPARC IIi |
| 176 | inOrderExec = false; // false for most architectures |
| 177 | inOrderRetire= true; // true for most architectures |
| 178 | |
| 179 | // must be called after above parameters are initialized. |
| 180 | this->initializeResources(); |
| 181 | } |
| 182 | |
| 183 | void |
| 184 | UltraSparcSchedInfo::initializeResources() |
| 185 | { |
| 186 | // Compute MachineSchedInfo::instrRUsages and MachineSchedInfo::issueGaps |
| 187 | MachineSchedInfo::initializeResources(); |
| 188 | |
| 189 | // Machine-dependent fixups go here. None for now. |
| 190 | } |
| 191 | |
| 192 | |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 193 | //--------------------------------------------------------------------------- |
| 194 | // class UltraSparcFrameInfo |
| 195 | // |
| 196 | // Purpose: |
| 197 | // Interface to stack frame layout info for the UltraSPARC. |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 198 | // Starting offsets for each area of the stack frame are aligned at |
| 199 | // a multiple of getStackFrameSizeAlignment(). |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 200 | //--------------------------------------------------------------------------- |
| 201 | |
| 202 | int |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 203 | UltraSparcFrameInfo::getFirstAutomaticVarOffset(MachineCodeForMethod& , |
| 204 | bool& pos) const |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 205 | { |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 206 | pos = false; // static stack area grows downwards |
| 207 | return StaticAreaOffsetFromFP; |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | int |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 211 | UltraSparcFrameInfo::getRegSpillAreaOffset(MachineCodeForMethod& mcInfo, |
| 212 | bool& pos) const |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 213 | { |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 214 | pos = false; // static stack area grows downwards |
| 215 | unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize(); |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 216 | if (int mod = autoVarsSize % getStackFrameSizeAlignment()) |
| 217 | autoVarsSize += (getStackFrameSizeAlignment() - mod); |
| 218 | return StaticAreaOffsetFromFP - autoVarsSize; |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | int |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 222 | UltraSparcFrameInfo::getTmpAreaOffset(MachineCodeForMethod& mcInfo, |
| 223 | bool& pos) const |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 224 | { |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 225 | pos = false; // static stack area grows downwards |
| 226 | unsigned int autoVarsSize = mcInfo.getAutomaticVarsSize(); |
| 227 | unsigned int spillAreaSize = mcInfo.getRegSpillsSize(); |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 228 | int offset = autoVarsSize + spillAreaSize; |
| 229 | if (int mod = offset % getStackFrameSizeAlignment()) |
| 230 | offset += (getStackFrameSizeAlignment() - mod); |
| 231 | return StaticAreaOffsetFromFP - offset; |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | int |
| 235 | UltraSparcFrameInfo::getDynamicAreaOffset(MachineCodeForMethod& mcInfo, |
| 236 | bool& pos) const |
| 237 | { |
| 238 | // dynamic stack area grows downwards starting at top of opt-args area |
| 239 | unsigned int optArgsSize = mcInfo.getMaxOptionalArgsSize(); |
Vikram S. Adve | 00521d7 | 2001-11-12 23:26:35 +0000 | [diff] [blame] | 240 | int offset = optArgsSize + FirstOptionalOutgoingArgOffsetFromSP; |
| 241 | assert(offset % getStackFrameSizeAlignment() == 0); |
| 242 | return offset; |
Vikram S. Adve | 9db4318 | 2001-10-22 13:44:23 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 245 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 246 | //--------------------------------------------------------------------------- |
| 247 | // class UltraSparcMachine |
| 248 | // |
| 249 | // Purpose: |
| 250 | // Primary interface to machine description for the UltraSPARC. |
| 251 | // Primarily just initializes machine-dependent parameters in |
| 252 | // class TargetMachine, and creates machine-dependent subclasses |
| 253 | // for classes such as MachineInstrInfo. |
| 254 | // |
| 255 | //--------------------------------------------------------------------------- |
| 256 | |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 257 | UltraSparc::UltraSparc() |
| 258 | : TargetMachine("UltraSparc-Native"), |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 259 | instrInfo(*this), |
| 260 | schedInfo(*this), |
| 261 | regInfo(*this), |
Vikram S. Adve | b704840 | 2001-11-09 02:16:04 +0000 | [diff] [blame] | 262 | frameInfo(*this), |
| 263 | cacheInfo(*this) |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 264 | { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 265 | optSizeForSubWordData = 4; |
| 266 | minMemOpWordSize = 8; |
| 267 | maxAtomicMemOpWordSize = 8; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 270 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 271 | |
| 272 | //===---------------------------------------------------------------------===// |
| 273 | // GenerateCodeForTarget Pass |
| 274 | // |
| 275 | // Native code generation for a specified target. |
| 276 | //===---------------------------------------------------------------------===// |
| 277 | |
| 278 | class ConstructMachineCodeForMethod : public MethodPass { |
| 279 | TargetMachine &Target; |
| 280 | public: |
| 281 | inline ConstructMachineCodeForMethod(TargetMachine &T) : Target(T) {} |
| 282 | bool runOnMethod(Method *M) { |
| 283 | MachineCodeForMethod::construct(M, Target); |
| 284 | return false; |
| 285 | } |
| 286 | }; |
| 287 | |
| 288 | class InstructionSelection : public MethodPass { |
| 289 | TargetMachine &Target; |
| 290 | public: |
| 291 | inline InstructionSelection(TargetMachine &T) : Target(T) {} |
| 292 | bool runOnMethod(Method *M) { |
| 293 | if (SelectInstructionsForMethod(M, Target)) |
| 294 | cerr << "Instr selection failed for method " << M->getName() << "\n"; |
| 295 | return false; |
| 296 | } |
| 297 | }; |
| 298 | |
| 299 | class InstructionScheduling : public MethodPass { |
| 300 | TargetMachine &Target; |
| 301 | public: |
| 302 | inline InstructionScheduling(TargetMachine &T) : Target(T) {} |
| 303 | bool runOnMethod(Method *M) { |
| 304 | if (ScheduleInstructionsWithSSA(M, Target)) |
| 305 | cerr << "Instr scheduling failed for method " << M->getName() << "\n\n"; |
| 306 | return false; |
| 307 | } |
| 308 | }; |
| 309 | |
| 310 | struct FreeMachineCodeForMethod : public MethodPass { |
| 311 | static void freeMachineCode(Instruction *I) { |
| 312 | MachineCodeForInstruction::destroy(I); |
| 313 | } |
| 314 | |
| 315 | bool runOnMethod(Method *M) { |
| 316 | for_each(M->inst_begin(), M->inst_end(), freeMachineCode); |
| 317 | // Don't destruct MachineCodeForMethod - The global printer needs it |
| 318 | //MachineCodeForMethod::destruct(M); |
| 319 | return false; |
| 320 | } |
| 321 | }; |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 322 | |
| 323 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 324 | void UltraSparc::addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) { |
Vikram S. Adve | 7f37fe5 | 2001-11-08 04:55:13 +0000 | [diff] [blame] | 325 | // Construct and initialize the MachineCodeForMethod object for this method. |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 326 | PM.add(new ConstructMachineCodeForMethod(*this)); |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 327 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 328 | PM.add(new InstructionSelection(*this)); |
Ruchira Sasanka | d00982a | 2002-01-07 19:20:28 +0000 | [diff] [blame] | 329 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 330 | //PM.add(new InstructionScheduling(*this)); |
Chris Lattner | cf4525b | 2002-02-03 07:49:15 +0000 | [diff] [blame] | 331 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 332 | PM.add(new RegisterAllocation(*this)); |
| 333 | |
| 334 | //PM.add(new OptimizeLeafProcedures()); |
| 335 | //PM.add(new DeleteFallThroughBranches()); |
| 336 | //PM.add(new RemoveChainedBranches()); // should be folded with previous |
| 337 | //PM.add(new RemoveRedundantOps()); // operations with %g0, NOP, etc. |
| 338 | |
| 339 | PM.add(new InsertPrologEpilogCode(*this)); |
| 340 | |
| 341 | // Output assembly language to the .s file. Assembly emission is split into |
| 342 | // two parts: Method output and Global value output. This is because method |
| 343 | // output is pipelined with all of the rest of code generation stuff, |
| 344 | // allowing machine code representations for methods to be free'd after the |
| 345 | // method has been emitted. |
| 346 | // |
| 347 | PM.add(getMethodAsmPrinterPass(PM, Out)); |
| 348 | PM.add(new FreeMachineCodeForMethod()); // Free stuff no longer needed |
Chris Lattner | cf4525b | 2002-02-03 07:49:15 +0000 | [diff] [blame] | 349 | |
Chris Lattner | 0feb358 | 2002-02-03 23:41:51 +0000 | [diff] [blame^] | 350 | // Emit Module level assembly after all of the methods have been processed. |
| 351 | PM.add(getModuleAsmPrinterPass(PM, Out)); |
Chris Lattner | cf4525b | 2002-02-03 07:49:15 +0000 | [diff] [blame] | 352 | } |