Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 1 | //===- CodeGenSchedule.h - Scheduling Machine Models ------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines structures to encapsulate the machine model as decribed in |
| 11 | // the target description. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef CODEGEN_SCHEDULE_H |
| 16 | #define CODEGEN_SCHEDULE_H |
| 17 | |
Andrew Trick | 1374526 | 2012-10-03 23:06:32 +0000 | [diff] [blame] | 18 | #include "SetTheory.h" |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/DenseMap.h" |
| 20 | #include "llvm/ADT/StringMap.h" |
Chandler Carruth | 4ffd89f | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ErrorHandling.h" |
| 22 | #include "llvm/TableGen/Record.h" |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
| 25 | |
| 26 | class CodeGenTarget; |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 27 | class CodeGenSchedModels; |
| 28 | class CodeGenInstruction; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 29 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 30 | typedef std::vector<Record*> RecVec; |
| 31 | typedef std::vector<Record*>::const_iterator RecIter; |
| 32 | |
| 33 | typedef std::vector<unsigned> IdxVec; |
| 34 | typedef std::vector<unsigned>::const_iterator IdxIter; |
| 35 | |
| 36 | void splitSchedReadWrites(const RecVec &RWDefs, |
| 37 | RecVec &WriteDefs, RecVec &ReadDefs); |
| 38 | |
| 39 | /// We have two kinds of SchedReadWrites. Explicitly defined and inferred |
| 40 | /// sequences. TheDef is nonnull for explicit SchedWrites, but Sequence may or |
| 41 | /// may not be empty. TheDef is null for inferred sequences, and Sequence must |
| 42 | /// be nonempty. |
| 43 | /// |
| 44 | /// IsVariadic controls whether the variants are expanded into multiple operands |
| 45 | /// or a sequence of writes on one operand. |
| 46 | struct CodeGenSchedRW { |
Andrew Trick | 2062b12 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 47 | unsigned Index; |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 48 | std::string Name; |
| 49 | Record *TheDef; |
Andrew Trick | 2062b12 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 50 | bool IsRead; |
Andrew Trick | 9264988 | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 51 | bool IsAlias; |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 52 | bool HasVariants; |
| 53 | bool IsVariadic; |
| 54 | bool IsSequence; |
| 55 | IdxVec Sequence; |
Andrew Trick | 9264988 | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 56 | RecVec Aliases; |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 57 | |
Richard Smith | 8efd0f0 | 2012-12-20 01:05:39 +0000 | [diff] [blame] | 58 | CodeGenSchedRW() |
| 59 | : Index(0), TheDef(0), IsRead(false), IsAlias(false), |
| 60 | HasVariants(false), IsVariadic(false), IsSequence(false) {} |
| 61 | CodeGenSchedRW(unsigned Idx, Record *Def) |
| 62 | : Index(Idx), TheDef(Def), IsAlias(false), IsVariadic(false) { |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 63 | Name = Def->getName(); |
Andrew Trick | 2062b12 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 64 | IsRead = Def->isSubClassOf("SchedRead"); |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 65 | HasVariants = Def->isSubClassOf("SchedVariant"); |
| 66 | if (HasVariants) |
| 67 | IsVariadic = Def->getValueAsBit("Variadic"); |
| 68 | |
| 69 | // Read records don't currently have sequences, but it can be easily |
| 70 | // added. Note that implicit Reads (from ReadVariant) may have a Sequence |
| 71 | // (but no record). |
| 72 | IsSequence = Def->isSubClassOf("WriteSequence"); |
| 73 | } |
| 74 | |
Andrew Trick | 2062b12 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 75 | CodeGenSchedRW(unsigned Idx, bool Read, const IdxVec &Seq, |
Richard Smith | 8efd0f0 | 2012-12-20 01:05:39 +0000 | [diff] [blame] | 76 | const std::string &Name) |
| 77 | : Index(Idx), Name(Name), TheDef(0), IsRead(Read), IsAlias(false), |
| 78 | HasVariants(false), IsVariadic(false), IsSequence(true), Sequence(Seq) { |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 79 | assert(Sequence.size() > 1 && "implied sequence needs >1 RWs"); |
| 80 | } |
| 81 | |
| 82 | bool isValid() const { |
| 83 | assert((!HasVariants || TheDef) && "Variant write needs record def"); |
| 84 | assert((!IsVariadic || HasVariants) && "Variadic write needs variants"); |
| 85 | assert((!IsSequence || !HasVariants) && "Sequence can't have variant"); |
| 86 | assert((!IsSequence || !Sequence.empty()) && "Sequence should be nonempty"); |
Andrew Trick | 9264988 | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 87 | assert((!IsAlias || Aliases.empty()) && "Alias cannot have aliases"); |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 88 | return TheDef || !Sequence.empty(); |
| 89 | } |
| 90 | |
| 91 | #ifndef NDEBUG |
| 92 | void dump() const; |
| 93 | #endif |
| 94 | }; |
| 95 | |
Andrew Trick | e076bb1 | 2012-09-18 04:03:30 +0000 | [diff] [blame] | 96 | /// Represent a transition between SchedClasses induced by SchedVariant. |
Andrew Trick | 5e613c2 | 2012-09-15 00:19:59 +0000 | [diff] [blame] | 97 | struct CodeGenSchedTransition { |
| 98 | unsigned ToClassIdx; |
| 99 | IdxVec ProcIndices; |
| 100 | RecVec PredTerm; |
| 101 | }; |
| 102 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 103 | /// Scheduling class. |
| 104 | /// |
| 105 | /// Each instruction description will be mapped to a scheduling class. There are |
| 106 | /// four types of classes: |
| 107 | /// |
| 108 | /// 1) An explicitly defined itinerary class with ItinClassDef set. |
| 109 | /// Writes and ReadDefs are empty. ProcIndices contains 0 for any processor. |
| 110 | /// |
| 111 | /// 2) An implied class with a list of SchedWrites and SchedReads that are |
| 112 | /// defined in an instruction definition and which are common across all |
| 113 | /// subtargets. ProcIndices contains 0 for any processor. |
| 114 | /// |
| 115 | /// 3) An implied class with a list of InstRW records that map instructions to |
| 116 | /// SchedWrites and SchedReads per-processor. InstrClassMap should map the same |
| 117 | /// instructions to this class. ProcIndices contains all the processors that |
| 118 | /// provided InstrRW records for this class. ItinClassDef or Writes/Reads may |
| 119 | /// still be defined for processors with no InstRW entry. |
| 120 | /// |
| 121 | /// 4) An inferred class represents a variant of another class that may be |
| 122 | /// resolved at runtime. ProcIndices contains the set of processors that may |
| 123 | /// require the class. ProcIndices are propagated through SchedClasses as |
| 124 | /// variants are expanded. Multiple SchedClasses may be inferred from an |
| 125 | /// itinerary class. Each inherits the processor index from the ItinRW record |
| 126 | /// that mapped the itinerary class to the variant Writes or Reads. |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 127 | struct CodeGenSchedClass { |
| 128 | std::string Name; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 129 | Record *ItinClassDef; |
| 130 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 131 | IdxVec Writes; |
| 132 | IdxVec Reads; |
| 133 | // Sorted list of ProcIdx, where ProcIdx==0 implies any processor. |
| 134 | IdxVec ProcIndices; |
| 135 | |
Andrew Trick | 5e613c2 | 2012-09-15 00:19:59 +0000 | [diff] [blame] | 136 | std::vector<CodeGenSchedTransition> Transitions; |
| 137 | |
Andrew Trick | 9264988 | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 138 | // InstRW records associated with this class. These records may refer to an |
| 139 | // Instruction no longer mapped to this class by InstrClassMap. These |
| 140 | // Instructions should be ignored by this class because they have been split |
| 141 | // off to join another inferred class. |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 142 | RecVec InstRWs; |
| 143 | |
| 144 | CodeGenSchedClass(): ItinClassDef(0) {} |
| 145 | CodeGenSchedClass(Record *rec): ItinClassDef(rec) { |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 146 | Name = rec->getName(); |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 147 | ProcIndices.push_back(0); |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 148 | } |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 149 | |
| 150 | #ifndef NDEBUG |
| 151 | void dump(const CodeGenSchedModels *SchedModels) const; |
| 152 | #endif |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
| 155 | // Processor model. |
| 156 | // |
| 157 | // ModelName is a unique name used to name an instantiation of MCSchedModel. |
| 158 | // |
| 159 | // ModelDef is NULL for inferred Models. This happens when a processor defines |
| 160 | // an itinerary but no machine model. If the processer defines neither a machine |
| 161 | // model nor itinerary, then ModelDef remains pointing to NoModel. NoModel has |
| 162 | // the special "NoModel" field set to true. |
| 163 | // |
| 164 | // ItinsDef always points to a valid record definition, but may point to the |
| 165 | // default NoItineraries. NoItineraries has an empty list of InstrItinData |
| 166 | // records. |
| 167 | // |
| 168 | // ItinDefList orders this processor's InstrItinData records by SchedClass idx. |
| 169 | struct CodeGenProcModel { |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 170 | unsigned Index; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 171 | std::string ModelName; |
| 172 | Record *ModelDef; |
| 173 | Record *ItinsDef; |
| 174 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 175 | // Derived members... |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 176 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 177 | // Array of InstrItinData records indexed by a CodeGenSchedClass index. |
| 178 | // This list is empty if the Processor has no value for Itineraries. |
| 179 | // Initialized by collectProcItins(). |
| 180 | RecVec ItinDefList; |
| 181 | |
| 182 | // Map itinerary classes to per-operand resources. |
| 183 | // This list is empty if no ItinRW refers to this Processor. |
| 184 | RecVec ItinRWDefs; |
| 185 | |
Andrew Trick | 3cbd178 | 2012-09-15 00:20:02 +0000 | [diff] [blame] | 186 | // All read/write resources associated with this processor. |
| 187 | RecVec WriteResDefs; |
| 188 | RecVec ReadAdvanceDefs; |
| 189 | |
| 190 | // Per-operand machine model resources associated with this processor. |
| 191 | RecVec ProcResourceDefs; |
| 192 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 193 | CodeGenProcModel(unsigned Idx, const std::string &Name, Record *MDef, |
| 194 | Record *IDef) : |
| 195 | Index(Idx), ModelName(Name), ModelDef(MDef), ItinsDef(IDef) {} |
| 196 | |
Andrew Trick | 3cbd178 | 2012-09-15 00:20:02 +0000 | [diff] [blame] | 197 | bool hasInstrSchedModel() const { |
| 198 | return !WriteResDefs.empty() || !ItinRWDefs.empty(); |
| 199 | } |
| 200 | |
| 201 | unsigned getProcResourceIdx(Record *PRDef) const; |
| 202 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 203 | #ifndef NDEBUG |
| 204 | void dump() const; |
| 205 | #endif |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 208 | /// Top level container for machine model data. |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 209 | class CodeGenSchedModels { |
| 210 | RecordKeeper &Records; |
| 211 | const CodeGenTarget &Target; |
| 212 | |
Andrew Trick | 1374526 | 2012-10-03 23:06:32 +0000 | [diff] [blame] | 213 | // Map dag expressions to Instruction lists. |
| 214 | SetTheory Sets; |
| 215 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 216 | // List of unique processor models. |
| 217 | std::vector<CodeGenProcModel> ProcModels; |
| 218 | |
| 219 | // Map Processor's MachineModel or ProcItin to a CodeGenProcModel index. |
| 220 | typedef DenseMap<Record*, unsigned> ProcModelMapTy; |
| 221 | ProcModelMapTy ProcModelMap; |
| 222 | |
| 223 | // Per-operand SchedReadWrite types. |
| 224 | std::vector<CodeGenSchedRW> SchedWrites; |
| 225 | std::vector<CodeGenSchedRW> SchedReads; |
| 226 | |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 227 | // List of unique SchedClasses. |
| 228 | std::vector<CodeGenSchedClass> SchedClasses; |
| 229 | |
| 230 | // Map SchedClass name to itinerary index. |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 231 | // These are either explicit itinerary classes or classes implied by |
| 232 | // instruction definitions with SchedReadWrite lists. |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 233 | StringMap<unsigned> SchedClassIdxMap; |
| 234 | |
| 235 | // SchedClass indices 1 up to and including NumItineraryClasses identify |
| 236 | // itinerary classes that are explicitly used for this target's instruction |
| 237 | // definitions. NoItinerary always has index 0 regardless of whether it is |
| 238 | // explicitly referenced. |
| 239 | // |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 240 | // Any implied SchedClass has an index greater than NumItineraryClasses. |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 241 | unsigned NumItineraryClasses; |
| 242 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 243 | // Any inferred SchedClass has an index greater than NumInstrSchedClassses. |
| 244 | unsigned NumInstrSchedClasses; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 245 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 246 | // Map Instruction to SchedClass index. Only for Instructions mentioned in |
Andrew Trick | 9264988 | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 247 | // InstRW records. |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 248 | typedef DenseMap<Record*, unsigned> InstClassMapTy; |
| 249 | InstClassMapTy InstrClassMap; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 250 | |
| 251 | public: |
| 252 | CodeGenSchedModels(RecordKeeper& RK, const CodeGenTarget &TGT); |
| 253 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 254 | Record *getModelOrItinDef(Record *ProcDef) const { |
| 255 | Record *ModelDef = ProcDef->getValueAsDef("SchedModel"); |
| 256 | Record *ItinsDef = ProcDef->getValueAsDef("ProcItin"); |
| 257 | if (!ItinsDef->getValueAsListOfDefs("IID").empty()) { |
| 258 | assert(ModelDef->getValueAsBit("NoModel") |
| 259 | && "Itineraries must be defined within SchedMachineModel"); |
| 260 | return ItinsDef; |
| 261 | } |
| 262 | return ModelDef; |
| 263 | } |
| 264 | |
| 265 | const CodeGenProcModel &getModelForProc(Record *ProcDef) const { |
| 266 | Record *ModelDef = getModelOrItinDef(ProcDef); |
| 267 | ProcModelMapTy::const_iterator I = ProcModelMap.find(ModelDef); |
| 268 | assert(I != ProcModelMap.end() && "missing machine model"); |
| 269 | return ProcModels[I->second]; |
| 270 | } |
| 271 | |
| 272 | const CodeGenProcModel &getProcModel(Record *ModelDef) const { |
| 273 | ProcModelMapTy::const_iterator I = ProcModelMap.find(ModelDef); |
| 274 | assert(I != ProcModelMap.end() && "missing machine model"); |
| 275 | return ProcModels[I->second]; |
| 276 | } |
| 277 | |
| 278 | // Iterate over the unique processor models. |
| 279 | typedef std::vector<CodeGenProcModel>::const_iterator ProcIter; |
| 280 | ProcIter procModelBegin() const { return ProcModels.begin(); } |
| 281 | ProcIter procModelEnd() const { return ProcModels.end(); } |
| 282 | |
| 283 | // Get a SchedWrite from its index. |
| 284 | const CodeGenSchedRW &getSchedWrite(unsigned Idx) const { |
| 285 | assert(Idx < SchedWrites.size() && "bad SchedWrite index"); |
| 286 | assert(SchedWrites[Idx].isValid() && "invalid SchedWrite"); |
| 287 | return SchedWrites[Idx]; |
| 288 | } |
| 289 | // Get a SchedWrite from its index. |
| 290 | const CodeGenSchedRW &getSchedRead(unsigned Idx) const { |
| 291 | assert(Idx < SchedReads.size() && "bad SchedRead index"); |
| 292 | assert(SchedReads[Idx].isValid() && "invalid SchedRead"); |
| 293 | return SchedReads[Idx]; |
| 294 | } |
| 295 | |
| 296 | const CodeGenSchedRW &getSchedRW(unsigned Idx, bool IsRead) const { |
| 297 | return IsRead ? getSchedRead(Idx) : getSchedWrite(Idx); |
| 298 | } |
Andrew Trick | 2062b12 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 299 | CodeGenSchedRW &getSchedRW(Record *Def) { |
Andrew Trick | 9264988 | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 300 | bool IsRead = Def->isSubClassOf("SchedRead"); |
Andrew Trick | 2062b12 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 301 | unsigned Idx = getSchedRWIdx(Def, IsRead); |
Andrew Trick | 9264988 | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 302 | return const_cast<CodeGenSchedRW&>( |
| 303 | IsRead ? getSchedRead(Idx) : getSchedWrite(Idx)); |
| 304 | } |
Andrew Trick | 2062b12 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 305 | const CodeGenSchedRW &getSchedRW(Record*Def) const { |
| 306 | return const_cast<CodeGenSchedModels&>(*this).getSchedRW(Def); |
Andrew Trick | 9264988 | 2012-09-22 02:24:21 +0000 | [diff] [blame] | 307 | } |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 308 | |
| 309 | unsigned getSchedRWIdx(Record *Def, bool IsRead, unsigned After = 0) const; |
| 310 | |
Andrew Trick | 3b8fb64 | 2012-09-19 04:43:19 +0000 | [diff] [blame] | 311 | // Return true if the given write record is referenced by a ReadAdvance. |
| 312 | bool hasReadOfWrite(Record *WriteDef) const; |
| 313 | |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 314 | // Check if any instructions are assigned to an explicit itinerary class other |
| 315 | // than NoItinerary. |
| 316 | bool hasItineraryClasses() const { return NumItineraryClasses > 0; } |
| 317 | |
| 318 | // Return the number of itinerary classes in use by this target's instruction |
| 319 | // descriptions, not including "NoItinerary". |
| 320 | unsigned numItineraryClasses() const { |
| 321 | return NumItineraryClasses; |
| 322 | } |
| 323 | |
| 324 | // Get a SchedClass from its index. |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 325 | CodeGenSchedClass &getSchedClass(unsigned Idx) { |
| 326 | assert(Idx < SchedClasses.size() && "bad SchedClass index"); |
| 327 | return SchedClasses[Idx]; |
| 328 | } |
| 329 | const CodeGenSchedClass &getSchedClass(unsigned Idx) const { |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 330 | assert(Idx < SchedClasses.size() && "bad SchedClass index"); |
| 331 | return SchedClasses[Idx]; |
| 332 | } |
| 333 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 334 | // Get the SchedClass index for an instruction. Instructions with no |
| 335 | // itinerary, no SchedReadWrites, and no InstrReadWrites references return 0 |
| 336 | // for NoItinerary. |
| 337 | unsigned getSchedClassIdx(const CodeGenInstruction &Inst) const; |
| 338 | |
| 339 | unsigned getSchedClassIdx(const RecVec &RWDefs) const; |
| 340 | |
| 341 | unsigned getSchedClassIdxForItin(const Record *ItinDef) { |
| 342 | return SchedClassIdxMap[ItinDef->getName()]; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 345 | typedef std::vector<CodeGenSchedClass>::const_iterator SchedClassIter; |
| 346 | SchedClassIter schedClassBegin() const { return SchedClasses.begin(); } |
| 347 | SchedClassIter schedClassEnd() const { return SchedClasses.end(); } |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 348 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 349 | void findRWs(const RecVec &RWDefs, IdxVec &Writes, IdxVec &Reads) const; |
| 350 | void findRWs(const RecVec &RWDefs, IdxVec &RWs, bool IsRead) const; |
Andrew Trick | 5e613c2 | 2012-09-15 00:19:59 +0000 | [diff] [blame] | 351 | void expandRWSequence(unsigned RWIdx, IdxVec &RWSeq, bool IsRead) const; |
Andrew Trick | 2062b12 | 2012-10-03 23:06:28 +0000 | [diff] [blame] | 352 | void expandRWSeqForProc(unsigned RWIdx, IdxVec &RWSeq, bool IsRead, |
| 353 | const CodeGenProcModel &ProcModel) const; |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 354 | |
| 355 | unsigned addSchedClass(const IdxVec &OperWrites, const IdxVec &OperReads, |
| 356 | const IdxVec &ProcIndices); |
| 357 | |
| 358 | unsigned findOrInsertRW(ArrayRef<unsigned> Seq, bool IsRead); |
| 359 | |
| 360 | unsigned findSchedClassIdx(const IdxVec &Writes, const IdxVec &Reads) const; |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 361 | |
Andrew Trick | 3cbd178 | 2012-09-15 00:20:02 +0000 | [diff] [blame] | 362 | Record *findProcResUnits(Record *ProcResKind, |
| 363 | const CodeGenProcModel &PM) const; |
| 364 | |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 365 | private: |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 366 | void collectProcModels(); |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 367 | |
| 368 | // Initialize a new processor model if it is unique. |
| 369 | void addProcModel(Record *ProcDef); |
| 370 | |
Andrew Trick | 48605c3 | 2012-09-15 00:19:57 +0000 | [diff] [blame] | 371 | void collectSchedRW(); |
| 372 | |
| 373 | std::string genRWName(const IdxVec& Seq, bool IsRead); |
| 374 | unsigned findRWForSequence(const IdxVec &Seq, bool IsRead); |
| 375 | |
| 376 | void collectSchedClasses(); |
| 377 | |
| 378 | std::string createSchedClassName(const IdxVec &OperWrites, |
| 379 | const IdxVec &OperReads); |
| 380 | std::string createSchedClassName(const RecVec &InstDefs); |
| 381 | void createInstRWClass(Record *InstRWDef); |
| 382 | |
| 383 | void collectProcItins(); |
| 384 | |
| 385 | void collectProcItinRW(); |
Andrew Trick | 5e613c2 | 2012-09-15 00:19:59 +0000 | [diff] [blame] | 386 | |
| 387 | void inferSchedClasses(); |
| 388 | |
| 389 | void inferFromRW(const IdxVec &OperWrites, const IdxVec &OperReads, |
| 390 | unsigned FromClassIdx, const IdxVec &ProcIndices); |
| 391 | void inferFromItinClass(Record *ItinClassDef, unsigned FromClassIdx); |
| 392 | void inferFromInstRWs(unsigned SCIdx); |
Andrew Trick | 3cbd178 | 2012-09-15 00:20:02 +0000 | [diff] [blame] | 393 | |
| 394 | void collectProcResources(); |
| 395 | |
| 396 | void collectItinProcResources(Record *ItinClassDef); |
| 397 | |
Andrew Trick | dbe6d43 | 2012-10-10 05:43:13 +0000 | [diff] [blame] | 398 | void collectRWResources(unsigned RWIdx, bool IsRead, |
| 399 | const IdxVec &ProcIndices); |
| 400 | |
Andrew Trick | 3cbd178 | 2012-09-15 00:20:02 +0000 | [diff] [blame] | 401 | void collectRWResources(const IdxVec &Writes, const IdxVec &Reads, |
| 402 | const IdxVec &ProcIndices); |
| 403 | |
| 404 | void addProcResource(Record *ProcResourceKind, CodeGenProcModel &PM); |
| 405 | |
| 406 | void addWriteRes(Record *ProcWriteResDef, unsigned PIdx); |
| 407 | |
| 408 | void addReadAdvance(Record *ProcReadAdvanceDef, unsigned PIdx); |
Andrew Trick | 2661b41 | 2012-07-07 04:00:00 +0000 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | } // namespace llvm |
| 412 | |
| 413 | #endif |