Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 1 | //===- DFAPacketizerEmitter.cpp - Packetization DFA for a VLIW machine-----===// |
| 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 class parses the Schedule.td file and produces an API that can be used |
| 11 | // to reason about whether an instruction can be added to a packet on a VLIW |
| 12 | // architecture. The class internally generates a deterministic finite |
| 13 | // automaton (DFA) that models all possible mappings of machine instructions |
| 14 | // to functional units as instructions are added to a packet. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 18 | #define DEBUG_TYPE "dfa-emitter" |
| 19 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 20 | #include "CodeGenTarget.h" |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseSet.h" |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/STLExtras.h" |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringExtras.h" |
| 24 | #include "llvm/CodeGen/DFAPacketizerDefs.h" |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 25 | #include "llvm/TableGen/Record.h" |
| 26 | #include "llvm/TableGen/TableGenBackend.h" |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Debug.h" |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 28 | #include <list> |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 29 | #include <map> |
| 30 | #include <string> |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 31 | #include <queue> |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 32 | using namespace llvm; |
| 33 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 34 | // To enable debugging, run llvm-tblgen with: "-debug-only dfa-emitter". |
| 35 | // |
| 36 | // dbgsInsnClass - When debugging, print instruction class stages. |
| 37 | // |
| 38 | void dbgsInsnClass(const std::vector<unsigned> &InsnClass); |
| 39 | // |
| 40 | // dbgsStateInfo - When debugging, print the set of state info. |
| 41 | // |
| 42 | void dbgsStateInfo(const std::set<unsigned> &stateInfo); |
| 43 | // |
| 44 | // dbgsIndent - When debugging, indent by the specified amount. |
| 45 | // |
| 46 | void dbgsIndent(unsigned indent); |
| 47 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 48 | // |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 49 | // class DFAPacketizerEmitter: class that generates and prints out the DFA |
| 50 | // for resource tracking. |
| 51 | // |
| 52 | namespace { |
| 53 | class DFAPacketizerEmitter { |
| 54 | private: |
| 55 | std::string TargetName; |
| 56 | // |
| 57 | // allInsnClasses is the set of all possible resources consumed by an |
| 58 | // InstrStage. |
| 59 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 60 | std::vector<std::vector<unsigned>> allInsnClasses; |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 61 | RecordKeeper &Records; |
| 62 | |
| 63 | public: |
| 64 | DFAPacketizerEmitter(RecordKeeper &R); |
| 65 | |
| 66 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 67 | // collectAllFuncUnits - Construct a map of function unit names to bits. |
| 68 | // |
| 69 | int collectAllFuncUnits(std::vector<Record*> &ProcItinList, |
| 70 | std::map<std::string, unsigned> &FUNameToBitsMap, |
| 71 | int &maxResources, |
| 72 | raw_ostream &OS); |
| 73 | |
| 74 | // |
| 75 | // collectAllComboFuncs - Construct a map from a combo function unit bit to |
| 76 | // the bits of all included functional units. |
| 77 | // |
| 78 | int collectAllComboFuncs(std::vector<Record*> &ComboFuncList, |
| 79 | std::map<std::string, unsigned> &FUNameToBitsMap, |
| 80 | std::map<unsigned, unsigned> &ComboBitToBitsMap, |
| 81 | raw_ostream &OS); |
| 82 | |
| 83 | // |
| 84 | // collectOneInsnClass - Populate allInsnClasses with one instruction class. |
| 85 | // |
| 86 | int collectOneInsnClass(const std::string &ProcName, |
| 87 | std::vector<Record*> &ProcItinList, |
| 88 | std::map<std::string, unsigned> &FUNameToBitsMap, |
| 89 | Record *ItinData, |
| 90 | raw_ostream &OS); |
| 91 | |
| 92 | // |
| 93 | // collectAllInsnClasses - Populate allInsnClasses which is a set of units |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 94 | // used in each stage. |
| 95 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 96 | int collectAllInsnClasses(const std::string &ProcName, |
| 97 | std::vector<Record*> &ProcItinList, |
| 98 | std::map<std::string, unsigned> &FUNameToBitsMap, |
| 99 | std::vector<Record*> &ItinDataList, |
| 100 | int &maxStages, |
| 101 | raw_ostream &OS); |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 102 | |
| 103 | void run(raw_ostream &OS); |
| 104 | }; |
| 105 | } // End anonymous namespace. |
| 106 | |
| 107 | // |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 108 | // |
| 109 | // State represents the usage of machine resources if the packet contains |
| 110 | // a set of instruction classes. |
| 111 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 112 | // Specifically, currentState is a set of bit-masks. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 113 | // The nth bit in a bit-mask indicates whether the nth resource is being used |
| 114 | // by this state. The set of bit-masks in a state represent the different |
| 115 | // possible outcomes of transitioning to this state. |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 116 | // For example: consider a two resource architecture: resource L and resource M |
| 117 | // with three instruction classes: L, M, and L_or_M. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 118 | // From the initial state (currentState = 0x00), if we add instruction class |
| 119 | // L_or_M we will transition to a state with currentState = [0x01, 0x10]. This |
| 120 | // represents the possible resource states that can result from adding a L_or_M |
| 121 | // instruction |
| 122 | // |
| 123 | // Another way of thinking about this transition is we are mapping a NDFA with |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 124 | // two states [0x01] and [0x10] into a DFA with a single state [0x01, 0x10]. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 125 | // |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 126 | // A State instance also contains a collection of transitions from that state: |
| 127 | // a map from inputs to new states. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 128 | // |
| 129 | namespace { |
| 130 | class State { |
| 131 | public: |
| 132 | static int currentStateNum; |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 133 | // stateNum is the only member used for equality/ordering, all other members |
| 134 | // can be mutated even in const State objects. |
| 135 | const int stateNum; |
| 136 | mutable bool isInitial; |
| 137 | mutable std::set<unsigned> stateInfo; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 138 | typedef std::map<std::vector<unsigned>, const State *> TransitionMap; |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 139 | mutable TransitionMap Transitions; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 140 | |
| 141 | State(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 142 | |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 143 | bool operator<(const State &s) const { |
| 144 | return stateNum < s.stateNum; |
| 145 | } |
| 146 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 147 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 148 | // canMaybeAddInsnClass - Quickly verifies if an instruction of type InsnClass |
| 149 | // may be a valid transition from this state i.e., can an instruction of type |
| 150 | // InsnClass be added to the packet represented by this state. |
Anshuman Dasgupta | 20013f1 | 2012-06-27 19:38:29 +0000 | [diff] [blame] | 151 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 152 | // Note that for multiple stages, this quick check does not take into account |
| 153 | // any possible resource competition between the stages themselves. That is |
| 154 | // enforced in AddInsnClassStages which checks the cross product of all |
| 155 | // stages for resource availability (which is a more involved check). |
Krzysztof Parzyszek | 220a9bc | 2015-11-21 17:23:52 +0000 | [diff] [blame] | 156 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 157 | bool canMaybeAddInsnClass(std::vector<unsigned> &InsnClass, |
| 158 | std::map<unsigned, unsigned> &ComboBitToBitsMap) const; |
Krzysztof Parzyszek | 220a9bc | 2015-11-21 17:23:52 +0000 | [diff] [blame] | 159 | // |
Krzysztof Parzyszek | 4ca21fc | 2015-11-21 17:38:33 +0000 | [diff] [blame] | 160 | // AddInsnClass - Return all combinations of resource reservation |
Krzysztof Parzyszek | 220a9bc | 2015-11-21 17:23:52 +0000 | [diff] [blame] | 161 | // which are possible from this state (PossibleStates). |
| 162 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 163 | // PossibleStates is the set of valid resource states that ensue from valid |
| 164 | // transitions. |
| 165 | // |
| 166 | void AddInsnClass(std::vector<unsigned> &InsnClass, |
| 167 | std::map<unsigned, unsigned> &ComboBitToBitsMap, |
| 168 | std::set<unsigned> &PossibleStates) const; |
| 169 | // |
| 170 | // AddInsnClassStages - Return all combinations of resource reservation |
| 171 | // resulting from the cross product of all stages for this InsnClass |
| 172 | // which are possible from this state (PossibleStates). |
| 173 | // |
| 174 | void AddInsnClassStages(std::vector<unsigned> &InsnClass, |
| 175 | std::map<unsigned, unsigned> &ComboBitToBitsMap, |
| 176 | unsigned chkstage, unsigned numstages, |
| 177 | unsigned prevState, unsigned origState, |
| 178 | DenseSet<unsigned> &VisitedResourceStates, |
| 179 | std::set<unsigned> &PossibleStates) const; |
| 180 | // |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 181 | // addTransition - Add a transition from this state given the input InsnClass |
| 182 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 183 | void addTransition(std::vector<unsigned> InsnClass, const State *To) const; |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 184 | // |
| 185 | // hasTransition - Returns true if there is a transition from this state |
| 186 | // given the input InsnClass |
| 187 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 188 | bool hasTransition(std::vector<unsigned> InsnClass) const; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 189 | }; |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 190 | } // End anonymous namespace. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 191 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 192 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 193 | // class DFA: deterministic finite automaton for processor resource tracking. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 194 | // |
| 195 | namespace { |
| 196 | class DFA { |
| 197 | public: |
| 198 | DFA(); |
| 199 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 200 | // Set of states. Need to keep this sorted to emit the transition table. |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 201 | typedef std::set<State> StateSet; |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 202 | StateSet states; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 203 | |
Sebastian Pop | ac35a4d | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 204 | State *currentState; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 205 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 206 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 207 | // Modify the DFA. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 208 | // |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 209 | const State &newState(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 210 | |
| 211 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 212 | // writeTable: Print out a table representing the DFA. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 213 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 214 | void writeTableAndAPI(raw_ostream &OS, const std::string &ClassName, |
| 215 | int numInsnClasses = 0, |
| 216 | int maxResources = 0, int numCombos = 0, int maxStages = 0); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 217 | }; |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 218 | } // End anonymous namespace. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 219 | |
Krzysztof Parzyszek | 8dd552d | 2015-11-21 22:19:50 +0000 | [diff] [blame^] | 220 | #ifndef NDEBUG |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 221 | // To enable debugging, run llvm-tblgen with: "-debug-only dfa-emitter". |
| 222 | // |
| 223 | // dbgsInsnClass - When debugging, print instruction class stages. |
| 224 | // |
| 225 | void dbgsInsnClass(const std::vector<unsigned> &InsnClass) { |
| 226 | DEBUG(dbgs() << "InsnClass: "); |
| 227 | for (unsigned i = 0; i < InsnClass.size(); ++i) { |
| 228 | if (i > 0) { |
| 229 | DEBUG(dbgs() << ", "); |
| 230 | } |
| 231 | DEBUG(dbgs() << "0x" << utohexstr(InsnClass[i])); |
| 232 | } |
| 233 | DFAInput InsnInput = getDFAInsnInput(InsnClass); |
| 234 | DEBUG(dbgs() << " (input: 0x" << utohexstr(InsnInput) << ")"); |
| 235 | } |
| 236 | |
| 237 | // |
| 238 | // dbgsStateInfo - When debugging, print the set of state info. |
| 239 | // |
| 240 | void dbgsStateInfo(const std::set<unsigned> &stateInfo) { |
| 241 | DEBUG(dbgs() << "StateInfo: "); |
| 242 | unsigned i = 0; |
| 243 | for (std::set<unsigned>::iterator SI = stateInfo.begin(); |
| 244 | SI != stateInfo.end(); ++SI, ++i) { |
| 245 | unsigned thisState = *SI; |
| 246 | if (i > 0) { |
| 247 | DEBUG(dbgs() << ", "); |
| 248 | } |
| 249 | DEBUG(dbgs() << "0x" << utohexstr(thisState)); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // |
| 254 | // dbgsIndent - When debugging, indent by the specified amount. |
| 255 | // |
| 256 | void dbgsIndent(unsigned indent) { |
| 257 | for (unsigned i = 0; i < indent; ++i) { |
| 258 | DEBUG(dbgs() << " "); |
| 259 | } |
| 260 | } |
Krzysztof Parzyszek | 8dd552d | 2015-11-21 22:19:50 +0000 | [diff] [blame^] | 261 | #endif |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 262 | |
| 263 | // |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 264 | // Constructors and destructors for State and DFA |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 265 | // |
| 266 | State::State() : |
| 267 | stateNum(currentStateNum++), isInitial(false) {} |
| 268 | |
Craig Topper | 2406477 | 2014-04-15 07:20:03 +0000 | [diff] [blame] | 269 | DFA::DFA(): currentState(nullptr) {} |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 270 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 271 | // |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 272 | // addTransition - Add a transition from this state given the input InsnClass |
| 273 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 274 | void State::addTransition(std::vector<unsigned> InsnClass, const State *To) |
| 275 | const { |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 276 | assert(!Transitions.count(InsnClass) && |
| 277 | "Cannot have multiple transitions for the same input"); |
| 278 | Transitions[InsnClass] = To; |
| 279 | } |
| 280 | |
| 281 | // |
| 282 | // hasTransition - Returns true if there is a transition from this state |
| 283 | // given the input InsnClass |
| 284 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 285 | bool State::hasTransition(std::vector<unsigned> InsnClass) const { |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 286 | return Transitions.count(InsnClass) > 0; |
Anshuman Dasgupta | 20013f1 | 2012-06-27 19:38:29 +0000 | [diff] [blame] | 287 | } |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 288 | |
| 289 | // |
Anshuman Dasgupta | 20013f1 | 2012-06-27 19:38:29 +0000 | [diff] [blame] | 290 | // AddInsnClass - Return all combinations of resource reservation |
| 291 | // which are possible from this state (PossibleStates). |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 292 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 293 | // PossibleStates is the set of valid resource states that ensue from valid |
| 294 | // transitions. |
| 295 | // |
| 296 | void State::AddInsnClass(std::vector<unsigned> &InsnClass, |
| 297 | std::map<unsigned, unsigned> &ComboBitToBitsMap, |
| 298 | std::set<unsigned> &PossibleStates) const { |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 299 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 300 | // Iterate over all resource states in currentState. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 301 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 302 | unsigned numstages = InsnClass.size(); |
| 303 | assert((numstages > 0) && "InsnClass has no stages"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 304 | |
| 305 | for (std::set<unsigned>::iterator SI = stateInfo.begin(); |
| 306 | SI != stateInfo.end(); ++SI) { |
| 307 | unsigned thisState = *SI; |
| 308 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 309 | DenseSet<unsigned> VisitedResourceStates; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 310 | |
| 311 | DEBUG(dbgs() << " thisState: 0x" << utohexstr(thisState) << "\n"); |
| 312 | AddInsnClassStages(InsnClass, ComboBitToBitsMap, |
| 313 | numstages - 1, numstages, |
| 314 | thisState, thisState, |
| 315 | VisitedResourceStates, PossibleStates); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | void State::AddInsnClassStages(std::vector<unsigned> &InsnClass, |
| 320 | std::map<unsigned, unsigned> &ComboBitToBitsMap, |
| 321 | unsigned chkstage, unsigned numstages, |
| 322 | unsigned prevState, unsigned origState, |
| 323 | DenseSet<unsigned> &VisitedResourceStates, |
| 324 | std::set<unsigned> &PossibleStates) const { |
| 325 | |
| 326 | assert((chkstage < numstages) && "AddInsnClassStages: stage out of range"); |
| 327 | unsigned thisStage = InsnClass[chkstage]; |
| 328 | |
| 329 | dbgsIndent((1 + numstages - chkstage) << 1); |
| 330 | DEBUG(dbgs() << "AddInsnClassStages " << chkstage |
| 331 | << " (0x" << utohexstr(thisStage) << ") from "); |
| 332 | dbgsInsnClass(InsnClass); |
| 333 | DEBUG(dbgs() << "\n"); |
| 334 | |
| 335 | // |
| 336 | // Iterate over all possible resources used in thisStage. |
| 337 | // For ex: for thisStage = 0x11, all resources = {0x01, 0x10}. |
| 338 | // |
| 339 | for (unsigned int j = 0; j < DFA_MAX_RESOURCES; ++j) { |
| 340 | unsigned resourceMask = (0x1 << j); |
| 341 | if (resourceMask & thisStage) { |
| 342 | unsigned combo = ComboBitToBitsMap[resourceMask]; |
| 343 | if (combo && ((~prevState & combo) != combo)) { |
| 344 | DEBUG(dbgs() << "\tSkipped Add 0x" << utohexstr(prevState) |
| 345 | << " - combo op 0x" << utohexstr(resourceMask) |
| 346 | << " (0x" << utohexstr(combo) <<") cannot be scheduled\n"); |
| 347 | continue; |
| 348 | } |
| 349 | // |
| 350 | // For each possible resource used in thisStage, generate the |
| 351 | // resource state if that resource was used. |
| 352 | // |
| 353 | unsigned ResultingResourceState = prevState | resourceMask | combo; |
| 354 | dbgsIndent((2 + numstages - chkstage) << 1); |
| 355 | DEBUG(dbgs() << "0x" << utohexstr(prevState) |
| 356 | << " | 0x" << utohexstr(resourceMask)); |
| 357 | if (combo) { |
| 358 | DEBUG(dbgs() << " | 0x" << utohexstr(combo)); |
| 359 | } |
| 360 | DEBUG(dbgs() << " = 0x" << utohexstr(ResultingResourceState) << " "); |
| 361 | |
| 362 | // |
| 363 | // If this is the final stage for this class |
| 364 | // |
| 365 | if (chkstage == 0) { |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 366 | // |
| 367 | // Check if the resulting resource state can be accommodated in this |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 368 | // packet. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 369 | // We compute resource OR prevState (originally started as origState). |
| 370 | // If the result of the OR is different than origState, it implies |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 371 | // that there is at least one resource that can be used to schedule |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 372 | // thisStage in the current packet. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 373 | // Insert ResultingResourceState into PossibleStates only if we haven't |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 374 | // processed ResultingResourceState before. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 375 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 376 | if (ResultingResourceState != prevState) { |
| 377 | if (VisitedResourceStates.count(ResultingResourceState) == 0) { |
| 378 | VisitedResourceStates.insert(ResultingResourceState); |
| 379 | PossibleStates.insert(ResultingResourceState); |
| 380 | DEBUG(dbgs() << "\tResultingResourceState: 0x" |
| 381 | << utohexstr(ResultingResourceState) << "\n"); |
| 382 | } else { |
| 383 | DEBUG(dbgs() << "\tSkipped Add - state already seen\n"); |
| 384 | } |
| 385 | } else { |
| 386 | DEBUG(dbgs() << "\tSkipped Add - no final resources available\n"); |
| 387 | } |
| 388 | } else { |
| 389 | // |
| 390 | // If the current resource can be accommodated, check the next |
| 391 | // stage in InsnClass for available resources. |
| 392 | // |
| 393 | if (ResultingResourceState != prevState) { |
| 394 | DEBUG(dbgs() << "\n"); |
| 395 | AddInsnClassStages(InsnClass, ComboBitToBitsMap, |
| 396 | chkstage - 1, numstages, |
| 397 | ResultingResourceState, origState, |
| 398 | VisitedResourceStates, PossibleStates); |
| 399 | } else { |
| 400 | DEBUG(dbgs() << "\tSkipped Add - no resources available\n"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |
Anshuman Dasgupta | 20013f1 | 2012-06-27 19:38:29 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | |
| 408 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 409 | // canMaybeAddInsnClass - Quickly verifies if an instruction of type InsnClass |
| 410 | // may be a valid transition from this state i.e., can an instruction of type |
| 411 | // InsnClass be added to the packet represented by this state. |
Anshuman Dasgupta | 20013f1 | 2012-06-27 19:38:29 +0000 | [diff] [blame] | 412 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 413 | // Note that this routine is performing conservative checks that can be |
| 414 | // quickly executed acting as a filter before calling AddInsnClassStages. |
| 415 | // Any cases allowed through here will be caught later in AddInsnClassStages |
| 416 | // which performs the more expensive exact check. |
| 417 | // |
| 418 | bool State::canMaybeAddInsnClass(std::vector<unsigned> &InsnClass, |
| 419 | std::map<unsigned, unsigned> &ComboBitToBitsMap) const { |
Alexey Samsonov | 420a4ed | 2012-06-28 07:47:50 +0000 | [diff] [blame] | 420 | for (std::set<unsigned>::const_iterator SI = stateInfo.begin(); |
Anshuman Dasgupta | 20013f1 | 2012-06-27 19:38:29 +0000 | [diff] [blame] | 421 | SI != stateInfo.end(); ++SI) { |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 422 | |
| 423 | // Check to see if all required resources are available. |
| 424 | bool available = true; |
| 425 | |
| 426 | // Inspect each stage independently. |
| 427 | // note: This is a conservative check as we aren't checking for |
| 428 | // possible resource competition between the stages themselves |
| 429 | // The full cross product is examined later in AddInsnClass. |
| 430 | for (unsigned i = 0; i < InsnClass.size(); ++i) { |
| 431 | unsigned resources = *SI; |
| 432 | if ((~resources & InsnClass[i]) == 0) { |
| 433 | available = false; |
| 434 | break; |
| 435 | } |
| 436 | // Make sure _all_ resources for a combo function are available. |
| 437 | // note: This is a quick conservative check as it won't catch an |
| 438 | // unscheduleable combo if this stage is an OR expression |
| 439 | // containing a combo. |
| 440 | // These cases are caught later in AddInsnClass. |
| 441 | unsigned combo = ComboBitToBitsMap[InsnClass[i]]; |
| 442 | if (combo && ((~resources & combo) != combo)) { |
| 443 | DEBUG(dbgs() << "\tSkipped canMaybeAdd 0x" << utohexstr(resources) |
| 444 | << " - combo op 0x" << utohexstr(InsnClass[i]) |
| 445 | << " (0x" << utohexstr(combo) <<") cannot be scheduled\n"); |
| 446 | available = false; |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | if (available) { |
Anshuman Dasgupta | 20013f1 | 2012-06-27 19:38:29 +0000 | [diff] [blame] | 452 | return true; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 453 | } |
Anshuman Dasgupta | 20013f1 | 2012-06-27 19:38:29 +0000 | [diff] [blame] | 454 | } |
| 455 | return false; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 459 | const State &DFA::newState() { |
David Blaikie | 4bcfcc1 | 2014-04-21 22:46:09 +0000 | [diff] [blame] | 460 | auto IterPair = states.insert(State()); |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 461 | assert(IterPair.second && "State already exists"); |
| 462 | return *IterPair.first; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 463 | } |
| 464 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 465 | int State::currentStateNum = 0; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 466 | |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 467 | DFAPacketizerEmitter::DFAPacketizerEmitter(RecordKeeper &R): |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 468 | TargetName(CodeGenTarget(R).getName()), |
| 469 | allInsnClasses(), Records(R) {} |
| 470 | |
| 471 | |
| 472 | // |
| 473 | // writeTableAndAPI - Print out a table representing the DFA and the |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 474 | // associated API to create a DFA packetizer. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 475 | // |
| 476 | // Format: |
| 477 | // DFAStateInputTable[][2] = pairs of <Input, Transition> for all valid |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 478 | // transitions. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 479 | // DFAStateEntryTable[i] = Index of the first entry in DFAStateInputTable for |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 480 | // the ith state. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 481 | // |
| 482 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 483 | void DFA::writeTableAndAPI(raw_ostream &OS, const std::string &TargetName, |
| 484 | int numInsnClasses, |
| 485 | int maxResources, int numCombos, int maxStages) { |
| 486 | |
| 487 | unsigned numStates = states.size(); |
| 488 | |
| 489 | DEBUG(dbgs() << "-----------------------------------------------------------------------------\n"); |
| 490 | DEBUG(dbgs() << "writeTableAndAPI\n"); |
| 491 | DEBUG(dbgs() << "Total states: " << numStates << "\n"); |
| 492 | |
| 493 | OS << "namespace llvm {\n"; |
| 494 | |
| 495 | OS << "\n// Input format:\n"; |
| 496 | OS << "#define DFA_MAX_RESTERMS " << DFA_MAX_RESTERMS |
| 497 | << "\t// maximum AND'ed resource terms\n"; |
| 498 | OS << "#define DFA_MAX_RESOURCES " << DFA_MAX_RESOURCES |
| 499 | << "\t// maximum resource bits in one term\n"; |
| 500 | |
| 501 | OS << "\n// " << TargetName << "DFAStateInputTable[][2] = " |
| 502 | << "pairs of <Input, NextState> for all valid\n"; |
| 503 | OS << "// transitions.\n"; |
| 504 | OS << "// " << numStates << "\tstates\n"; |
| 505 | OS << "// " << numInsnClasses << "\tinstruction classes\n"; |
| 506 | OS << "// " << maxResources << "\tresources max\n"; |
| 507 | OS << "// " << numCombos << "\tcombo resources\n"; |
| 508 | OS << "// " << maxStages << "\tstages max\n"; |
| 509 | OS << "const " << DFA_TBLTYPE << " " |
| 510 | << TargetName << "DFAStateInputTable[][2] = {\n"; |
| 511 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 512 | // This table provides a map to the beginning of the transitions for State s |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 513 | // in DFAStateInputTable. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 514 | std::vector<int> StateEntry(numStates+1); |
| 515 | static const std::string SentinelEntry = "{-1, -1}"; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 516 | |
| 517 | // Tracks the total valid transitions encountered so far. It is used |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 518 | // to construct the StateEntry table. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 519 | int ValidTransitions = 0; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 520 | DFA::StateSet::iterator SI = states.begin(); |
| 521 | for (unsigned i = 0; i < numStates; ++i, ++SI) { |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 522 | assert ((SI->stateNum == (int) i) && "Mismatch in state numbers"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 523 | StateEntry[i] = ValidTransitions; |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 524 | for (State::TransitionMap::iterator |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 525 | II = SI->Transitions.begin(), IE = SI->Transitions.end(); |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 526 | II != IE; ++II) { |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 527 | OS << "{0x" << utohexstr(getDFAInsnInput(II->first)) << ", " |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 528 | << II->second->stateNum |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 529 | << "},\t"; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 530 | } |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 531 | ValidTransitions += SI->Transitions.size(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 532 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 533 | // If there are no valid transitions from this stage, we need a sentinel |
| 534 | // transition. |
Brendon Cahoon | e9b60aa | 2012-02-03 21:08:25 +0000 | [diff] [blame] | 535 | if (ValidTransitions == StateEntry[i]) { |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 536 | OS << SentinelEntry << ",\t"; |
Brendon Cahoon | e9b60aa | 2012-02-03 21:08:25 +0000 | [diff] [blame] | 537 | ++ValidTransitions; |
| 538 | } |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 539 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 540 | OS << " // state " << i << ": " << StateEntry[i]; |
| 541 | if (StateEntry[i] != (ValidTransitions-1)) { // More than one transition. |
| 542 | OS << "-" << (ValidTransitions-1); |
| 543 | } |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 544 | OS << "\n"; |
| 545 | } |
Anshuman Dasgupta | 3923e28 | 2012-12-10 22:45:57 +0000 | [diff] [blame] | 546 | |
| 547 | // Print out a sentinel entry at the end of the StateInputTable. This is |
| 548 | // needed to iterate over StateInputTable in DFAPacketizer::ReadTable() |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 549 | OS << SentinelEntry << "\t"; |
| 550 | OS << " // state " << numStates << ": " << ValidTransitions; |
| 551 | OS << "\n"; |
| 552 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 553 | OS << "};\n\n"; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 554 | OS << "// " << TargetName << "DFAStateEntryTable[i] = " |
| 555 | << "Index of the first entry in DFAStateInputTable for\n"; |
| 556 | OS << "// " |
| 557 | << "the ith state.\n"; |
| 558 | OS << "// " << numStates << " states\n"; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 559 | OS << "const unsigned int " << TargetName << "DFAStateEntryTable[] = {\n"; |
| 560 | |
| 561 | // Multiply i by 2 since each entry in DFAStateInputTable is a set of |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 562 | // two numbers. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 563 | unsigned lastState = 0; |
| 564 | for (unsigned i = 0; i < numStates; ++i) { |
| 565 | if (i && ((i % 10) == 0)) { |
| 566 | lastState = i-1; |
| 567 | OS << " // states " << (i-10) << ":" << lastState << "\n"; |
| 568 | } |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 569 | OS << StateEntry[i] << ", "; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 570 | } |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 571 | |
Anshuman Dasgupta | 3923e28 | 2012-12-10 22:45:57 +0000 | [diff] [blame] | 572 | // Print out the index to the sentinel entry in StateInputTable |
| 573 | OS << ValidTransitions << ", "; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 574 | OS << " // states " << (lastState+1) << ":" << numStates << "\n"; |
Anshuman Dasgupta | 3923e28 | 2012-12-10 22:45:57 +0000 | [diff] [blame] | 575 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 576 | OS << "};\n"; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 577 | OS << "} // namespace\n"; |
| 578 | |
| 579 | |
| 580 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 581 | // Emit DFA Packetizer tables if the target is a VLIW machine. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 582 | // |
| 583 | std::string SubTargetClassName = TargetName + "GenSubtargetInfo"; |
| 584 | OS << "\n" << "#include \"llvm/CodeGen/DFAPacketizer.h\"\n"; |
| 585 | OS << "namespace llvm {\n"; |
Sebastian Pop | ac35a4d | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 586 | OS << "DFAPacketizer *" << SubTargetClassName << "::" |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 587 | << "createDFAPacketizer(const InstrItineraryData *IID) const {\n" |
| 588 | << " return new DFAPacketizer(IID, " << TargetName |
| 589 | << "DFAStateInputTable, " << TargetName << "DFAStateEntryTable);\n}\n\n"; |
| 590 | OS << "} // End llvm namespace \n"; |
| 591 | } |
| 592 | |
| 593 | |
| 594 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 595 | // collectAllFuncUnits - Construct a map of function unit names to bits. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 596 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 597 | int DFAPacketizerEmitter::collectAllFuncUnits( |
| 598 | std::vector<Record*> &ProcItinList, |
| 599 | std::map<std::string, unsigned> &FUNameToBitsMap, |
| 600 | int &maxFUs, |
| 601 | raw_ostream &OS) { |
| 602 | DEBUG(dbgs() << "-----------------------------------------------------------------------------\n"); |
| 603 | DEBUG(dbgs() << "collectAllFuncUnits"); |
| 604 | DEBUG(dbgs() << " (" << ProcItinList.size() << " itineraries)\n"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 605 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 606 | int totalFUs = 0; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 607 | // Parse functional units for all the itineraries. |
| 608 | for (unsigned i = 0, N = ProcItinList.size(); i < N; ++i) { |
| 609 | Record *Proc = ProcItinList[i]; |
| 610 | std::vector<Record*> FUs = Proc->getValueAsListOfDefs("FU"); |
| 611 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 612 | DEBUG(dbgs() << " FU:" << i |
| 613 | << " (" << FUs.size() << " FUs) " |
Krzysztof Parzyszek | 8dd552d | 2015-11-21 22:19:50 +0000 | [diff] [blame^] | 614 | << Proc->getName()); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 615 | |
| 616 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 617 | // Convert macros to bits for each stage. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 618 | unsigned numFUs = FUs.size(); |
| 619 | for (unsigned j = 0; j < numFUs; ++j) { |
| 620 | assert ((j < DFA_MAX_RESOURCES) && |
| 621 | "Exceeded maximum number of representable resources"); |
| 622 | unsigned FuncResources = (unsigned) (1U << j); |
| 623 | FUNameToBitsMap[FUs[j]->getName()] = FuncResources; |
| 624 | DEBUG(dbgs() << " " << FUs[j]->getName() |
| 625 | << ":0x" << utohexstr(FuncResources)); |
| 626 | } |
| 627 | if (((int) numFUs) > maxFUs) { |
| 628 | maxFUs = numFUs; |
| 629 | } |
| 630 | totalFUs += numFUs; |
| 631 | DEBUG(dbgs() << "\n"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 632 | } |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 633 | return totalFUs; |
| 634 | } |
| 635 | |
| 636 | // |
| 637 | // collectAllComboFuncs - Construct a map from a combo function unit bit to |
| 638 | // the bits of all included functional units. |
| 639 | // |
| 640 | int DFAPacketizerEmitter::collectAllComboFuncs( |
| 641 | std::vector<Record*> &ComboFuncList, |
| 642 | std::map<std::string, unsigned> &FUNameToBitsMap, |
| 643 | std::map<unsigned, unsigned> &ComboBitToBitsMap, |
| 644 | raw_ostream &OS) { |
| 645 | DEBUG(dbgs() << "-----------------------------------------------------------------------------\n"); |
| 646 | DEBUG(dbgs() << "collectAllComboFuncs"); |
| 647 | DEBUG(dbgs() << " (" << ComboFuncList.size() << " sets)\n"); |
| 648 | |
| 649 | int numCombos = 0; |
| 650 | for (unsigned i = 0, N = ComboFuncList.size(); i < N; ++i) { |
| 651 | Record *Func = ComboFuncList[i]; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 652 | std::vector<Record*> FUs = Func->getValueAsListOfDefs("CFD"); |
| 653 | |
| 654 | DEBUG(dbgs() << " CFD:" << i |
| 655 | << " (" << FUs.size() << " combo FUs) " |
Krzysztof Parzyszek | 8dd552d | 2015-11-21 22:19:50 +0000 | [diff] [blame^] | 656 | << Func->getName() << "\n"); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 657 | |
| 658 | // Convert macros to bits for each stage. |
| 659 | for (unsigned j = 0, N = FUs.size(); j < N; ++j) { |
| 660 | assert ((j < DFA_MAX_RESOURCES) && |
| 661 | "Exceeded maximum number of DFA resources"); |
| 662 | Record *FuncData = FUs[j]; |
| 663 | Record *ComboFunc = FuncData->getValueAsDef("TheComboFunc"); |
| 664 | const std::vector<Record*> &FuncList = |
| 665 | FuncData->getValueAsListOfDefs("FuncList"); |
| 666 | std::string ComboFuncName = ComboFunc->getName(); |
| 667 | unsigned ComboBit = FUNameToBitsMap[ComboFuncName]; |
| 668 | unsigned ComboResources = ComboBit; |
| 669 | DEBUG(dbgs() << " combo: " << ComboFuncName |
| 670 | << ":0x" << utohexstr(ComboResources) << "\n"); |
| 671 | for (unsigned k = 0, M = FuncList.size(); k < M; ++k) { |
| 672 | std::string FuncName = FuncList[k]->getName(); |
| 673 | unsigned FuncResources = FUNameToBitsMap[FuncName]; |
| 674 | DEBUG(dbgs() << " " << FuncName |
| 675 | << ":0x" << utohexstr(FuncResources) << "\n"); |
| 676 | ComboResources |= FuncResources; |
| 677 | } |
| 678 | ComboBitToBitsMap[ComboBit] = ComboResources; |
| 679 | numCombos++; |
| 680 | DEBUG(dbgs() << " => combo bits: " << ComboFuncName << ":0x" |
| 681 | << utohexstr(ComboBit) << " = 0x" |
| 682 | << utohexstr(ComboResources) << "\n"); |
| 683 | } |
| 684 | } |
| 685 | return numCombos; |
| 686 | } |
| 687 | |
| 688 | |
| 689 | // |
| 690 | // collectOneInsnClass - Populate allInsnClasses with one instruction class |
| 691 | // |
| 692 | int DFAPacketizerEmitter::collectOneInsnClass(const std::string &ProcName, |
| 693 | std::vector<Record*> &ProcItinList, |
| 694 | std::map<std::string, unsigned> &FUNameToBitsMap, |
| 695 | Record *ItinData, |
| 696 | raw_ostream &OS) { |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 697 | const std::vector<Record*> &StageList = |
| 698 | ItinData->getValueAsListOfDefs("Stages"); |
| 699 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 700 | // The number of stages. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 701 | unsigned NStages = StageList.size(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 702 | |
Krzysztof Parzyszek | 8dd552d | 2015-11-21 22:19:50 +0000 | [diff] [blame^] | 703 | DEBUG(dbgs() << " " << ItinData->getValueAsDef("TheClass")->getName() |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 704 | << "\n"); |
| 705 | |
| 706 | std::vector<unsigned> UnitBits; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 707 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 708 | // Compute the bitwise or of each unit used in this stage. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 709 | for (unsigned i = 0; i < NStages; ++i) { |
| 710 | const Record *Stage = StageList[i]; |
| 711 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 712 | // Get unit list. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 713 | const std::vector<Record*> &UnitList = |
| 714 | Stage->getValueAsListOfDefs("Units"); |
| 715 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 716 | DEBUG(dbgs() << " stage:" << i |
| 717 | << " [" << UnitList.size() << " units]:"); |
| 718 | unsigned dbglen = 26; // cursor after stage dbgs |
| 719 | |
| 720 | // Compute the bitwise or of each unit used in this stage. |
| 721 | unsigned UnitBitValue = 0; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 722 | for (unsigned j = 0, M = UnitList.size(); j < M; ++j) { |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 723 | // Conduct bitwise or. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 724 | std::string UnitName = UnitList[j]->getName(); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 725 | DEBUG(dbgs() << " " << j << ":" << UnitName); |
| 726 | dbglen += 3 + UnitName.length(); |
| 727 | assert(FUNameToBitsMap.count(UnitName)); |
| 728 | UnitBitValue |= FUNameToBitsMap[UnitName]; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | if (UnitBitValue != 0) |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 732 | UnitBits.push_back(UnitBitValue); |
| 733 | |
| 734 | while (dbglen <= 64) { // line up bits dbgs |
| 735 | dbglen += 8; |
| 736 | DEBUG(dbgs() << "\t"); |
| 737 | } |
| 738 | DEBUG(dbgs() << " (bits: 0x" << utohexstr(UnitBitValue) << ")\n"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 739 | } |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 740 | |
| 741 | if (UnitBits.size() > 0) |
| 742 | allInsnClasses.push_back(UnitBits); |
| 743 | |
| 744 | DEBUG(dbgs() << " "); |
| 745 | dbgsInsnClass(UnitBits); |
| 746 | DEBUG(dbgs() << "\n"); |
| 747 | |
| 748 | return NStages; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 751 | // |
| 752 | // collectAllInsnClasses - Populate allInsnClasses which is a set of units |
| 753 | // used in each stage. |
| 754 | // |
| 755 | int DFAPacketizerEmitter::collectAllInsnClasses(const std::string &ProcName, |
| 756 | std::vector<Record*> &ProcItinList, |
| 757 | std::map<std::string, unsigned> &FUNameToBitsMap, |
| 758 | std::vector<Record*> &ItinDataList, |
| 759 | int &maxStages, |
| 760 | raw_ostream &OS) { |
| 761 | // Collect all instruction classes. |
| 762 | unsigned M = ItinDataList.size(); |
| 763 | |
| 764 | int numInsnClasses = 0; |
| 765 | DEBUG(dbgs() << "-----------------------------------------------------------------------------\n" |
| 766 | << "collectAllInsnClasses " |
| 767 | << ProcName |
| 768 | << " (" << M << " classes)\n"); |
| 769 | |
| 770 | // Collect stages for each instruction class for all itinerary data |
| 771 | for (unsigned j = 0; j < M; j++) { |
| 772 | Record *ItinData = ItinDataList[j]; |
| 773 | int NStages = collectOneInsnClass(ProcName, ProcItinList, |
| 774 | FUNameToBitsMap, ItinData, OS); |
| 775 | if (NStages > maxStages) { |
| 776 | maxStages = NStages; |
| 777 | } |
| 778 | numInsnClasses++; |
| 779 | } |
| 780 | return numInsnClasses; |
| 781 | } |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 782 | |
| 783 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 784 | // Run the worklist algorithm to generate the DFA. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 785 | // |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 786 | void DFAPacketizerEmitter::run(raw_ostream &OS) { |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 787 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 788 | // Collect processor iteraries. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 789 | std::vector<Record*> ProcItinList = |
| 790 | Records.getAllDerivedDefinitions("ProcessorItineraries"); |
| 791 | |
| 792 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 793 | // Collect the Functional units. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 794 | // |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 795 | std::map<std::string, unsigned> FUNameToBitsMap; |
| 796 | int maxResources = 0; |
| 797 | collectAllFuncUnits(ProcItinList, |
| 798 | FUNameToBitsMap, maxResources, OS); |
| 799 | |
| 800 | // |
| 801 | // Collect the Combo Functional units. |
| 802 | // |
| 803 | std::map<unsigned, unsigned> ComboBitToBitsMap; |
| 804 | std::vector<Record*> ComboFuncList = |
| 805 | Records.getAllDerivedDefinitions("ComboFuncUnits"); |
| 806 | int numCombos = collectAllComboFuncs(ComboFuncList, |
| 807 | FUNameToBitsMap, ComboBitToBitsMap, OS); |
| 808 | |
| 809 | // |
| 810 | // Collect the itineraries. |
| 811 | // |
| 812 | int maxStages = 0; |
| 813 | int numInsnClasses = 0; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 814 | for (unsigned i = 0, N = ProcItinList.size(); i < N; i++) { |
| 815 | Record *Proc = ProcItinList[i]; |
| 816 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 817 | // Get processor itinerary name. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 818 | const std::string &ProcName = Proc->getName(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 819 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 820 | // Skip default. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 821 | if (ProcName == "NoItineraries") |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 822 | continue; |
| 823 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 824 | // Sanity check for at least one instruction itinerary class. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 825 | unsigned NItinClasses = |
| 826 | Records.getAllDerivedDefinitions("InstrItinClass").size(); |
| 827 | if (NItinClasses == 0) |
| 828 | return; |
| 829 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 830 | // Get itinerary data list. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 831 | std::vector<Record*> ItinDataList = Proc->getValueAsListOfDefs("IID"); |
| 832 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 833 | // Collect all instruction classes |
| 834 | numInsnClasses += collectAllInsnClasses(ProcName, ProcItinList, |
| 835 | FUNameToBitsMap, ItinDataList, maxStages, OS); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 838 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 839 | // Run a worklist algorithm to generate the DFA. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 840 | // |
| 841 | DFA D; |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 842 | const State *Initial = &D.newState(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 843 | Initial->isInitial = true; |
| 844 | Initial->stateInfo.insert(0x0); |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 845 | SmallVector<const State*, 32> WorkList; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 846 | // std::queue<State*> WorkList; |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 847 | std::map<std::set<unsigned>, const State*> Visited; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 848 | |
| 849 | WorkList.push_back(Initial); |
| 850 | |
| 851 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 852 | // Worklist algorithm to create a DFA for processor resource tracking. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 853 | // C = {set of InsnClasses} |
| 854 | // Begin with initial node in worklist. Initial node does not have |
| 855 | // any consumed resources, |
| 856 | // ResourceState = 0x0 |
| 857 | // Visited = {} |
| 858 | // While worklist != empty |
| 859 | // S = first element of worklist |
| 860 | // For every instruction class C |
| 861 | // if we can accommodate C in S: |
| 862 | // S' = state with resource states = {S Union C} |
| 863 | // Add a new transition: S x C -> S' |
| 864 | // If S' is not in Visited: |
| 865 | // Add S' to worklist |
| 866 | // Add S' to Visited |
| 867 | // |
| 868 | while (!WorkList.empty()) { |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 869 | const State *current = WorkList.pop_back_val(); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 870 | DEBUG(dbgs() << "---------------------\n"); |
| 871 | DEBUG(dbgs() << "Processing state: " << current->stateNum << " - "); |
| 872 | dbgsStateInfo(current->stateInfo); |
| 873 | DEBUG(dbgs() << "\n"); |
| 874 | for (unsigned i = 0; i < allInsnClasses.size(); i++) { |
| 875 | std::vector<unsigned> InsnClass = allInsnClasses[i]; |
| 876 | DEBUG(dbgs() << i << " "); |
| 877 | dbgsInsnClass(InsnClass); |
| 878 | DEBUG(dbgs() << "\n"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 879 | |
| 880 | std::set<unsigned> NewStateResources; |
| 881 | // |
| 882 | // If we haven't already created a transition for this input |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 883 | // and the state can accommodate this InsnClass, create a transition. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 884 | // |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 885 | if (!current->hasTransition(InsnClass) && |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 886 | current->canMaybeAddInsnClass(InsnClass, ComboBitToBitsMap)) { |
| 887 | const State *NewState = NULL; |
| 888 | current->AddInsnClass(InsnClass, ComboBitToBitsMap, NewStateResources); |
| 889 | if (NewStateResources.size() == 0) { |
| 890 | DEBUG(dbgs() << " Skipped - no new states generated\n"); |
| 891 | continue; |
| 892 | } |
| 893 | |
| 894 | DEBUG(dbgs() << "\t"); |
| 895 | dbgsStateInfo(NewStateResources); |
| 896 | DEBUG(dbgs() << "\n"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 897 | |
| 898 | // |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 899 | // If we have seen this state before, then do not create a new state. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 900 | // |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 901 | auto VI = Visited.find(NewStateResources); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 902 | if (VI != Visited.end()) { |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 903 | NewState = VI->second; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 904 | DEBUG(dbgs() << "\tFound existing state: " |
| 905 | << NewState->stateNum << " - "); |
| 906 | dbgsStateInfo(NewState->stateInfo); |
| 907 | DEBUG(dbgs() << "\n"); |
| 908 | } else { |
David Blaikie | d43046b | 2014-04-21 22:35:11 +0000 | [diff] [blame] | 909 | NewState = &D.newState(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 910 | NewState->stateInfo = NewStateResources; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 911 | Visited[NewStateResources] = NewState; |
| 912 | WorkList.push_back(NewState); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 913 | DEBUG(dbgs() << "\tAccepted new state: " |
| 914 | << NewState->stateNum << " - "); |
| 915 | dbgsStateInfo(NewState->stateInfo); |
| 916 | DEBUG(dbgs() << "\n"); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 917 | } |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 918 | |
Anshuman Dasgupta | f16a443 | 2012-09-07 21:35:43 +0000 | [diff] [blame] | 919 | current->addTransition(InsnClass, NewState); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 924 | // Print out the table. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 925 | D.writeTableAndAPI(OS, TargetName, |
| 926 | numInsnClasses, maxResources, numCombos, maxStages); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 927 | } |
Jakob Stoklund Olesen | e6aed13 | 2012-06-11 15:37:55 +0000 | [diff] [blame] | 928 | |
| 929 | namespace llvm { |
| 930 | |
| 931 | void EmitDFAPacketizer(RecordKeeper &RK, raw_ostream &OS) { |
| 932 | emitSourceFileHeader("Target DFA Packetizer Tables", OS); |
| 933 | DFAPacketizerEmitter(RK).run(OS); |
| 934 | } |
| 935 | |
| 936 | } // End llvm namespace |