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