Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 1 | //=- llvm/CodeGen/DFAPacketizer.cpp - DFA Packetizer for VLIW -*- 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 | // This class implements a deterministic finite automaton (DFA) based |
| 10 | // packetizing mechanism for VLIW architectures. It provides APIs to |
| 11 | // determine whether there exists a legal mapping of instructions to |
| 12 | // functional unit assignments in a packet. The DFA is auto-generated from |
| 13 | // the target's Schedule.td file. |
| 14 | // |
| 15 | // A DFA consists of 3 major elements: states, inputs, and transitions. For |
| 16 | // the packetizing mechanism, the input is the set of instruction classes for |
| 17 | // a target. The state models all possible combinations of functional unit |
| 18 | // consumption for a given set of instructions in a packet. A transition |
| 19 | // models the addition of an instruction to a packet. In the DFA constructed |
| 20 | // by this class, if an instruction can be added to a packet, then a valid |
| 21 | // transition exists from the corresponding state. Invalid transitions |
| 22 | // indicate that the instruction cannot be added to the current packet. |
| 23 | // |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | #include "llvm/CodeGen/DFAPacketizer.h" |
| 27 | #include "llvm/CodeGen/MachineInstr.h" |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineInstrBundle.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/ScheduleDAGInstrs.h" |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 30 | #include "llvm/MC/MCInstrItineraries.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetInstrInfo.h" |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 32 | |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
Krzysztof Parzyszek | 6753f33 | 2015-11-22 15:20:19 +0000 | [diff] [blame] | 35 | // -------------------------------------------------------------------- |
| 36 | // Definitions shared between DFAPacketizer.cpp and DFAPacketizerEmitter.cpp |
| 37 | |
| 38 | namespace { |
| 39 | DFAInput addDFAFuncUnits(DFAInput Inp, unsigned FuncUnits) { |
| 40 | return (Inp << DFA_MAX_RESOURCES) | FuncUnits; |
| 41 | } |
| 42 | |
| 43 | /// Return the DFAInput for an instruction class input vector. |
| 44 | /// This function is used in both DFAPacketizer.cpp and in |
| 45 | /// DFAPacketizerEmitter.cpp. |
| 46 | DFAInput getDFAInsnInput(const std::vector<unsigned> &InsnClass) { |
| 47 | DFAInput InsnInput = 0; |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 48 | assert((InsnClass.size() <= DFA_MAX_RESTERMS) && |
| 49 | "Exceeded maximum number of DFA terms"); |
Krzysztof Parzyszek | 6753f33 | 2015-11-22 15:20:19 +0000 | [diff] [blame] | 50 | for (auto U : InsnClass) |
| 51 | InsnInput = addDFAFuncUnits(InsnInput, U); |
| 52 | return InsnInput; |
| 53 | } |
| 54 | } |
| 55 | // -------------------------------------------------------------------- |
| 56 | |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 57 | DFAPacketizer::DFAPacketizer(const InstrItineraryData *I, |
| 58 | const DFAStateInput (*SIT)[2], |
Sebastian Pop | ac35a4d | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 59 | const unsigned *SET): |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 60 | InstrItins(I), CurrentState(0), DFAStateInputTable(SIT), |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 61 | DFAStateEntryTable(SET) { |
| 62 | // Make sure DFA types are large enough for the number of terms & resources. |
| 63 | assert((DFA_MAX_RESTERMS * DFA_MAX_RESOURCES) <= (8 * sizeof(DFAInput)) |
| 64 | && "(DFA_MAX_RESTERMS * DFA_MAX_RESOURCES) too big for DFAInput"); |
| 65 | assert((DFA_MAX_RESTERMS * DFA_MAX_RESOURCES) <= (8 * sizeof(DFAStateInput)) |
| 66 | && "(DFA_MAX_RESTERMS * DFA_MAX_RESOURCES) too big for DFAStateInput"); |
| 67 | } |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 68 | |
| 69 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 70 | // Read the DFA transition table and update CachedTable. |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 71 | // |
| 72 | // Format of the transition tables: |
| 73 | // DFAStateInputTable[][2] = pairs of <Input, Transition> for all valid |
| 74 | // transitions |
| 75 | // DFAStateEntryTable[i] = Index of the first entry in DFAStateInputTable |
| 76 | // for the ith state |
| 77 | // |
| 78 | void DFAPacketizer::ReadTable(unsigned int state) { |
| 79 | unsigned ThisState = DFAStateEntryTable[state]; |
| 80 | unsigned NextStateInTable = DFAStateEntryTable[state+1]; |
| 81 | // Early exit in case CachedTable has already contains this |
Sebastian Pop | 9aa6137 | 2011-12-06 17:34:11 +0000 | [diff] [blame] | 82 | // state's transitions. |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 83 | if (CachedTable.count(UnsignPair(state, DFAStateInputTable[ThisState][0]))) |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 84 | return; |
| 85 | |
| 86 | for (unsigned i = ThisState; i < NextStateInTable; i++) |
| 87 | CachedTable[UnsignPair(state, DFAStateInputTable[i][0])] = |
| 88 | DFAStateInputTable[i][1]; |
| 89 | } |
| 90 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 91 | |
| 92 | // Return the DFAInput for an instruction class. |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 93 | DFAInput DFAPacketizer::getInsnInput(unsigned InsnClass) { |
| 94 | // Note: this logic must match that in DFAPacketizerDefs.h for input vectors. |
| 95 | DFAInput InsnInput = 0; |
| 96 | unsigned i = 0; |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 97 | (void)i; |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 98 | for (const InstrStage *IS = InstrItins->beginStage(InsnClass), |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 99 | *IE = InstrItins->endStage(InsnClass); IS != IE; ++IS) { |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 100 | InsnInput = addDFAFuncUnits(InsnInput, IS->getUnits()); |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 101 | assert((i++ < DFA_MAX_RESTERMS) && "Exceeded maximum number of DFA inputs"); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 102 | } |
| 103 | return InsnInput; |
| 104 | } |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 105 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 106 | |
| 107 | // Return the DFAInput for an instruction class input vector. |
Krzysztof Parzyszek | 6753f33 | 2015-11-22 15:20:19 +0000 | [diff] [blame] | 108 | DFAInput DFAPacketizer::getInsnInput(const std::vector<unsigned> &InsnClass) { |
| 109 | return getDFAInsnInput(InsnClass); |
| 110 | } |
| 111 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 112 | |
| 113 | // Check if the resources occupied by a MCInstrDesc are available in the |
| 114 | // current state. |
Sebastian Pop | ac35a4d | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 115 | bool DFAPacketizer::canReserveResources(const llvm::MCInstrDesc *MID) { |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 116 | unsigned InsnClass = MID->getSchedClass(); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 117 | DFAInput InsnInput = getInsnInput(InsnClass); |
| 118 | UnsignPair StateTrans = UnsignPair(CurrentState, InsnInput); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 119 | ReadTable(CurrentState); |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 120 | return CachedTable.count(StateTrans) != 0; |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 123 | |
| 124 | // Reserve the resources occupied by a MCInstrDesc and change the current |
| 125 | // state to reflect that change. |
Sebastian Pop | ac35a4d | 2011-12-06 17:34:16 +0000 | [diff] [blame] | 126 | void DFAPacketizer::reserveResources(const llvm::MCInstrDesc *MID) { |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 127 | unsigned InsnClass = MID->getSchedClass(); |
Krzysztof Parzyszek | b465572 | 2015-11-21 20:00:45 +0000 | [diff] [blame] | 128 | DFAInput InsnInput = getInsnInput(InsnClass); |
| 129 | UnsignPair StateTrans = UnsignPair(CurrentState, InsnInput); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 130 | ReadTable(CurrentState); |
| 131 | assert(CachedTable.count(StateTrans) != 0); |
| 132 | CurrentState = CachedTable[StateTrans]; |
| 133 | } |
| 134 | |
| 135 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 136 | // Check if the resources occupied by a machine instruction are available |
| 137 | // in the current state. |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 138 | bool DFAPacketizer::canReserveResources(llvm::MachineInstr &MI) { |
| 139 | const llvm::MCInstrDesc &MID = MI.getDesc(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 140 | return canReserveResources(&MID); |
| 141 | } |
| 142 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 143 | |
| 144 | // Reserve the resources occupied by a machine instruction and change the |
| 145 | // current state to reflect that change. |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 146 | void DFAPacketizer::reserveResources(llvm::MachineInstr &MI) { |
| 147 | const llvm::MCInstrDesc &MID = MI.getDesc(); |
Anshuman Dasgupta | 08ebdc1 | 2011-12-01 21:10:21 +0000 | [diff] [blame] | 148 | reserveResources(&MID); |
| 149 | } |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 150 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 151 | |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 152 | namespace llvm { |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 153 | // This class extends ScheduleDAGInstrs and overrides the schedule method |
| 154 | // to build the dependence graph. |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 155 | class DefaultVLIWScheduler : public ScheduleDAGInstrs { |
Krzysztof Parzyszek | dac7102 | 2015-12-14 20:35:13 +0000 | [diff] [blame] | 156 | private: |
| 157 | AliasAnalysis *AA; |
Krzysztof Parzyszek | 1a1d78b | 2016-03-08 15:33:51 +0000 | [diff] [blame] | 158 | /// Ordered list of DAG postprocessing steps. |
| 159 | std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations; |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 160 | public: |
Krzysztof Parzyszek | dac7102 | 2015-12-14 20:35:13 +0000 | [diff] [blame] | 161 | DefaultVLIWScheduler(MachineFunction &MF, MachineLoopInfo &MLI, |
| 162 | AliasAnalysis *AA); |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 163 | // Actual scheduling work. |
Craig Topper | 4584cd5 | 2014-03-07 09:26:03 +0000 | [diff] [blame] | 164 | void schedule() override; |
Krzysztof Parzyszek | 1a1d78b | 2016-03-08 15:33:51 +0000 | [diff] [blame] | 165 | |
| 166 | /// DefaultVLIWScheduler takes ownership of the Mutation object. |
| 167 | void addMutation(std::unique_ptr<ScheduleDAGMutation> Mutation) { |
| 168 | Mutations.push_back(std::move(Mutation)); |
| 169 | } |
| 170 | protected: |
| 171 | void postprocessDAG(); |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 172 | }; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 173 | } |
Andrew Trick | 20349b8 | 2012-02-15 23:34:15 +0000 | [diff] [blame] | 174 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 175 | |
Alexey Samsonov | ea0aee6 | 2014-08-20 20:57:26 +0000 | [diff] [blame] | 176 | DefaultVLIWScheduler::DefaultVLIWScheduler(MachineFunction &MF, |
Krzysztof Parzyszek | dac7102 | 2015-12-14 20:35:13 +0000 | [diff] [blame] | 177 | MachineLoopInfo &MLI, |
| 178 | AliasAnalysis *AA) |
| 179 | : ScheduleDAGInstrs(MF, &MLI), AA(AA) { |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 180 | CanHandleTerminators = true; |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 183 | |
Krzysztof Parzyszek | 1a1d78b | 2016-03-08 15:33:51 +0000 | [diff] [blame] | 184 | /// Apply each ScheduleDAGMutation step in order. |
| 185 | void DefaultVLIWScheduler::postprocessDAG() { |
| 186 | for (auto &M : Mutations) |
| 187 | M->apply(this); |
| 188 | } |
| 189 | |
| 190 | |
Andrew Trick | 52226d4 | 2012-03-07 23:00:49 +0000 | [diff] [blame] | 191 | void DefaultVLIWScheduler::schedule() { |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 192 | // Build the scheduling graph. |
Krzysztof Parzyszek | dac7102 | 2015-12-14 20:35:13 +0000 | [diff] [blame] | 193 | buildSchedGraph(AA); |
Krzysztof Parzyszek | 1a1d78b | 2016-03-08 15:33:51 +0000 | [diff] [blame] | 194 | postprocessDAG(); |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 197 | |
| 198 | VLIWPacketizerList::VLIWPacketizerList(MachineFunction &mf, |
| 199 | MachineLoopInfo &mli, AliasAnalysis *aa) |
| 200 | : MF(mf), TII(mf.getSubtarget().getInstrInfo()), AA(aa) { |
Eric Christopher | 143f02c | 2014-10-09 01:59:35 +0000 | [diff] [blame] | 201 | ResourceTracker = TII->CreateTargetScheduleState(MF.getSubtarget()); |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 202 | VLIWScheduler = new DefaultVLIWScheduler(MF, mli, AA); |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 205 | |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 206 | VLIWPacketizerList::~VLIWPacketizerList() { |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 207 | if (VLIWScheduler) |
| 208 | delete VLIWScheduler; |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 209 | if (ResourceTracker) |
| 210 | delete ResourceTracker; |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 213 | |
| 214 | // End the current packet, bundle packet instructions and reset DFA state. |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 215 | void VLIWPacketizerList::endPacket(MachineBasicBlock *MBB, |
| 216 | MachineBasicBlock::iterator MI) { |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 217 | if (CurrentPacketMIs.size() > 1) { |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 218 | MachineInstr &MIFirst = *CurrentPacketMIs.front(); |
| 219 | finalizeBundle(*MBB, MIFirst.getIterator(), MI.getInstrIterator()); |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 220 | } |
| 221 | CurrentPacketMIs.clear(); |
| 222 | ResourceTracker->clearResources(); |
| 223 | } |
| 224 | |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 225 | |
| 226 | // Bundle machine instructions into packets. |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 227 | void VLIWPacketizerList::PacketizeMIs(MachineBasicBlock *MBB, |
| 228 | MachineBasicBlock::iterator BeginItr, |
| 229 | MachineBasicBlock::iterator EndItr) { |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 230 | assert(VLIWScheduler && "VLIW Scheduler is not initialized!"); |
| 231 | VLIWScheduler->startBlock(MBB); |
Andrew Trick | a53e101 | 2013-08-23 17:48:33 +0000 | [diff] [blame] | 232 | VLIWScheduler->enterRegion(MBB, BeginItr, EndItr, |
| 233 | std::distance(BeginItr, EndItr)); |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 234 | VLIWScheduler->schedule(); |
Andrew Trick | 69b4204 | 2012-03-07 23:01:09 +0000 | [diff] [blame] | 235 | |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 236 | // Generate MI -> SU map. |
| 237 | MIToSUnit.clear(); |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 238 | for (SUnit &SU : VLIWScheduler->SUnits) |
| 239 | MIToSUnit[SU.getInstr()] = &SU; |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 240 | |
| 241 | // The main packetizer loop. |
| 242 | for (; BeginItr != EndItr; ++BeginItr) { |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 243 | MachineInstr &MI = *BeginItr; |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 244 | initPacketizerState(); |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 245 | |
| 246 | // End the current packet if needed. |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 247 | if (isSoloInstruction(MI)) { |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 248 | endPacket(MBB, MI); |
| 249 | continue; |
| 250 | } |
| 251 | |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 252 | // Ignore pseudo instructions. |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 253 | if (ignorePseudoInstruction(MI, MBB)) |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 254 | continue; |
| 255 | |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 256 | SUnit *SUI = MIToSUnit[&MI]; |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 257 | assert(SUI && "Missing SUnit Info!"); |
| 258 | |
| 259 | // Ask DFA if machine resource is available for MI. |
| 260 | bool ResourceAvail = ResourceTracker->canReserveResources(MI); |
Krzysztof Parzyszek | 2005d7d | 2015-12-16 16:38:16 +0000 | [diff] [blame] | 261 | if (ResourceAvail && shouldAddToPacket(MI)) { |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 262 | // Dependency check for MI with instructions in CurrentPacketMIs. |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 263 | for (auto MJ : CurrentPacketMIs) { |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 264 | SUnit *SUJ = MIToSUnit[MJ]; |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 265 | assert(SUJ && "Missing SUnit Info!"); |
| 266 | |
| 267 | // Is it legal to packetize SUI and SUJ together. |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 268 | if (!isLegalToPacketizeTogether(SUI, SUJ)) { |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 269 | // Allow packetization if dependency can be pruned. |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 270 | if (!isLegalToPruneDependencies(SUI, SUJ)) { |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 271 | // End the packet if dependency cannot be pruned. |
| 272 | endPacket(MBB, MI); |
| 273 | break; |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | } |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 277 | } else { |
Krzysztof Parzyszek | 2005d7d | 2015-12-16 16:38:16 +0000 | [diff] [blame] | 278 | // End the packet if resource is not available, or if the instruction |
| 279 | // shoud not be added to the current packet. |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 280 | endPacket(MBB, MI); |
| 281 | } |
| 282 | |
| 283 | // Add MI to the current packet. |
Krzysztof Parzyszek | c005e20 | 2016-01-14 21:17:04 +0000 | [diff] [blame] | 284 | BeginItr = addToPacket(MI); |
| 285 | } // For all instructions in the packetization range. |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 286 | |
| 287 | // End any packet left behind. |
| 288 | endPacket(MBB, EndItr); |
Sirish Pande | 9421216 | 2012-05-01 21:28:30 +0000 | [diff] [blame] | 289 | VLIWScheduler->exitRegion(); |
| 290 | VLIWScheduler->finishBlock(); |
Andrew Trick | 7a35fae | 2012-02-15 18:55:14 +0000 | [diff] [blame] | 291 | } |
Krzysztof Parzyszek | 1a1d78b | 2016-03-08 15:33:51 +0000 | [diff] [blame] | 292 | |
| 293 | |
| 294 | // Add a DAG mutation object to the ordered list. |
| 295 | void VLIWPacketizerList::addMutation( |
| 296 | std::unique_ptr<ScheduleDAGMutation> Mutation) { |
| 297 | VLIWScheduler->addMutation(std::move(Mutation)); |
| 298 | } |