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 | |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 12 | #include "llvm/Target/Sparc.h" |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 13 | #include "SparcInternals.h" |
| 14 | #include "llvm/Method.h" |
| 15 | #include "llvm/CodeGen/InstrScheduling.h" |
| 16 | #include "llvm/CodeGen/InstrSelection.h" |
| 17 | |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 18 | #include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h" |
| 19 | #include "llvm/CodeGen/PhyRegAlloc.h" |
| 20 | |
Chris Lattner | 9a3d63b | 2001-09-19 15:56:23 +0000 | [diff] [blame] | 21 | // Build the MachineInstruction Description Array... |
| 22 | const MachineInstrDescriptor SparcMachineInstrDesc[] = { |
| 23 | #define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \ |
| 24 | NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \ |
| 25 | { OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \ |
| 26 | NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS }, |
| 27 | #include "SparcInstr.def" |
| 28 | }; |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 29 | |
| 30 | //---------------------------------------------------------------------------- |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 31 | // allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine |
| 32 | // that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface) |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 33 | //---------------------------------------------------------------------------- |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 34 | // |
Ruchira Sasanka | cc3ccac | 2001-10-15 16:25:28 +0000 | [diff] [blame] | 35 | |
Chris Lattner | 46cbff6 | 2001-09-14 16:56:32 +0000 | [diff] [blame] | 36 | TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 37 | |
| 38 | |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 39 | //---------------------------------------------------------------------------- |
| 40 | // Entry point for register allocation for a module |
| 41 | //---------------------------------------------------------------------------- |
| 42 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 43 | void AllocateRegisters(Method *M, TargetMachine &TM) |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 44 | { |
| 45 | |
| 46 | if ( (M)->isExternal() ) // don't process prototypes |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 47 | return; |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 48 | |
| 49 | if( DEBUG_RA ) { |
| 50 | cout << endl << "******************** Method "<< (M)->getName(); |
| 51 | cout << " ********************" <<endl; |
| 52 | } |
| 53 | |
| 54 | MethodLiveVarInfo LVI(M ); // Analyze live varaibles |
| 55 | LVI.analyze(); |
| 56 | |
| 57 | |
| 58 | PhyRegAlloc PRA(M, TM , &LVI); // allocate registers |
| 59 | PRA.allocateRegisters(); |
| 60 | |
| 61 | |
| 62 | if( DEBUG_RA ) cout << endl << "Register allocation complete!" << endl; |
| 63 | |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 66 | |
| 67 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 68 | //--------------------------------------------------------------------------- |
| 69 | // class UltraSparcInstrInfo |
| 70 | // |
| 71 | // Purpose: |
| 72 | // Information about individual instructions. |
| 73 | // Most information is stored in the SparcMachineInstrDesc array above. |
| 74 | // Other information is computed on demand, and most such functions |
| 75 | // default to member functions in base class MachineInstrInfo. |
| 76 | //--------------------------------------------------------------------------- |
| 77 | |
| 78 | /*ctor*/ |
| 79 | UltraSparcInstrInfo::UltraSparcInstrInfo() |
| 80 | : MachineInstrInfo(SparcMachineInstrDesc, |
| 81 | /*descSize = */ NUM_TOTAL_OPCODES, |
| 82 | /*numRealOpCodes = */ NUM_REAL_OPCODES) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | |
| 87 | //--------------------------------------------------------------------------- |
| 88 | // class UltraSparcSchedInfo |
| 89 | // |
| 90 | // Purpose: |
| 91 | // Scheduling information for the UltraSPARC. |
| 92 | // Primarily just initializes machine-dependent parameters in |
| 93 | // class MachineSchedInfo. |
| 94 | //--------------------------------------------------------------------------- |
| 95 | |
| 96 | /*ctor*/ |
| 97 | UltraSparcSchedInfo::UltraSparcSchedInfo(const MachineInstrInfo* mii) |
| 98 | : MachineSchedInfo((unsigned int) SPARC_NUM_SCHED_CLASSES, |
| 99 | mii, |
| 100 | SparcRUsageDesc, |
| 101 | SparcInstrUsageDeltas, |
| 102 | SparcInstrIssueDeltas, |
| 103 | sizeof(SparcInstrUsageDeltas)/sizeof(InstrRUsageDelta), |
| 104 | sizeof(SparcInstrIssueDeltas)/sizeof(InstrIssueDelta)) |
| 105 | { |
| 106 | maxNumIssueTotal = 4; |
| 107 | longestIssueConflict = 0; // computed from issuesGaps[] |
| 108 | |
| 109 | branchMispredictPenalty = 4; // 4 for SPARC IIi |
| 110 | branchTargetUnknownPenalty = 2; // 2 for SPARC IIi |
| 111 | l1DCacheMissPenalty = 8; // 7 or 9 for SPARC IIi |
| 112 | l1ICacheMissPenalty = 8; // ? for SPARC IIi |
| 113 | |
| 114 | inOrderLoads = true; // true for SPARC IIi |
| 115 | inOrderIssue = true; // true for SPARC IIi |
| 116 | inOrderExec = false; // false for most architectures |
| 117 | inOrderRetire= true; // true for most architectures |
| 118 | |
| 119 | // must be called after above parameters are initialized. |
| 120 | this->initializeResources(); |
| 121 | } |
| 122 | |
| 123 | void |
| 124 | UltraSparcSchedInfo::initializeResources() |
| 125 | { |
| 126 | // Compute MachineSchedInfo::instrRUsages and MachineSchedInfo::issueGaps |
| 127 | MachineSchedInfo::initializeResources(); |
| 128 | |
| 129 | // Machine-dependent fixups go here. None for now. |
| 130 | } |
| 131 | |
| 132 | |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 133 | |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 134 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 135 | //--------------------------------------------------------------------------- |
| 136 | // class UltraSparcMachine |
| 137 | // |
| 138 | // Purpose: |
| 139 | // Primary interface to machine description for the UltraSPARC. |
| 140 | // Primarily just initializes machine-dependent parameters in |
| 141 | // class TargetMachine, and creates machine-dependent subclasses |
| 142 | // for classes such as MachineInstrInfo. |
| 143 | // |
| 144 | //--------------------------------------------------------------------------- |
| 145 | |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 146 | UltraSparc::UltraSparc() |
| 147 | : TargetMachine("UltraSparc-Native"), |
| 148 | instrInfo(), |
| 149 | schedInfo(&instrInfo), |
| 150 | regInfo( this ) |
| 151 | { |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 152 | optSizeForSubWordData = 4; |
| 153 | minMemOpWordSize = 8; |
| 154 | maxAtomicMemOpWordSize = 8; |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 157 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 158 | |
| 159 | |
| 160 | |
| 161 | bool UltraSparc::compileMethod(Method *M) { |
| 162 | |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 163 | if (SelectInstructionsForMethod(M, *this)) |
| 164 | { |
| 165 | cerr << "Instruction selection failed for method " << M->getName() |
| 166 | << "\n\n"; |
| 167 | return true; |
| 168 | } |
Ruchira Sasanka | e38bd533 | 2001-09-15 00:30:44 +0000 | [diff] [blame] | 169 | |
Vikram S. Adve | 0fb4980 | 2001-09-18 13:01:29 +0000 | [diff] [blame] | 170 | if (ScheduleInstructionsWithSSA(M, *this)) |
| 171 | { |
| 172 | cerr << "Instruction scheduling before allocation failed for method " |
| 173 | << M->getName() << "\n\n"; |
| 174 | return true; |
| 175 | } |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 176 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 177 | AllocateRegisters(M, *this); // allocate registers |
| 178 | |
| 179 | |
Chris Lattner | 20b1ea0 | 2001-09-14 03:47:57 +0000 | [diff] [blame] | 180 | return false; |
| 181 | } |
Chris Lattner | f6e0e28 | 2001-09-14 04:32:55 +0000 | [diff] [blame] | 182 | |
Ruchira Sasanka | 89fb46b | 2001-09-18 22:52:44 +0000 | [diff] [blame] | 183 | |
| 184 | |