Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1 | //===----- HexagonPacketizer.cpp - vliw packetizer ---------------------===// |
| 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 implements a simple VLIW packetizer using DFA. The packetizer works on |
| 11 | // machine basic blocks. For each instruction I in BB, the packetizer consults |
| 12 | // the DFA to see if machine resources are available to execute I. If so, the |
| 13 | // packetizer checks if I depends on any instruction J in the current packet. |
| 14 | // If no dependency is found, I is added to current packet and machine resource |
| 15 | // is marked as taken. If any dependency is found, a target API call is made to |
| 16 | // prune the dependence. |
| 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
Jyotsna Verma | 8425643 | 2013-03-01 17:37:13 +0000 | [diff] [blame] | 19 | #include "HexagonRegisterInfo.h" |
| 20 | #include "HexagonSubtarget.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 21 | #include "HexagonTargetMachine.h" |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 22 | #include "HexagonVLIWPacketizer.h" |
| 23 | #include "llvm/Analysis/AliasAnalysis.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/MachineDominators.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineLoopInfo.h" |
| 27 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 28 | #include "llvm/CodeGen/Passes.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 29 | #include "llvm/Support/CommandLine.h" |
Chandler Carruth | 8a8cd2b | 2014-01-07 11:48:04 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Debug.h" |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace llvm; |
| 33 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 34 | #define DEBUG_TYPE "packets" |
| 35 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 36 | static cl::opt<bool> DisablePacketizer("disable-packetizer", cl::Hidden, |
| 37 | cl::ZeroOrMore, cl::init(false), |
| 38 | cl::desc("Disable Hexagon packetizer pass")); |
| 39 | |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 40 | static cl::opt<bool> PacketizeVolatiles("hexagon-packetize-volatiles", |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 41 | cl::ZeroOrMore, cl::Hidden, cl::init(true), |
| 42 | cl::desc("Allow non-solo packetization of volatile memory references")); |
| 43 | |
| 44 | static cl::opt<bool> EnableGenAllInsnClass("enable-gen-insn", cl::init(false), |
| 45 | cl::Hidden, cl::ZeroOrMore, cl::desc("Generate all instruction with TC")); |
| 46 | |
| 47 | static cl::opt<bool> DisableVecDblNVStores("disable-vecdbl-nv-stores", |
| 48 | cl::init(false), cl::Hidden, cl::ZeroOrMore, |
| 49 | cl::desc("Disable vector double new-value-stores")); |
| 50 | |
| 51 | extern cl::opt<bool> ScheduleInlineAsm; |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 52 | |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 53 | namespace llvm { |
Colin LeMahieu | 56efafc | 2015-06-15 19:05:35 +0000 | [diff] [blame] | 54 | FunctionPass *createHexagonPacketizer(); |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 55 | void initializeHexagonPacketizerPass(PassRegistry&); |
| 56 | } |
| 57 | |
| 58 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 59 | namespace { |
| 60 | class HexagonPacketizer : public MachineFunctionPass { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 61 | public: |
| 62 | static char ID; |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 63 | HexagonPacketizer() : MachineFunctionPass(ID) { |
| 64 | initializeHexagonPacketizerPass(*PassRegistry::getPassRegistry()); |
| 65 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 66 | |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 67 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 68 | AU.setPreservesCFG(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 69 | AU.addRequired<AAResultsWrapperPass>(); |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 70 | AU.addRequired<MachineBranchProbabilityInfo>(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 71 | AU.addRequired<MachineDominatorTree>(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 72 | AU.addRequired<MachineLoopInfo>(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 73 | AU.addPreserved<MachineDominatorTree>(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 74 | AU.addPreserved<MachineLoopInfo>(); |
| 75 | MachineFunctionPass::getAnalysisUsage(AU); |
| 76 | } |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 77 | const char *getPassName() const override { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 78 | return "Hexagon Packetizer"; |
| 79 | } |
Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 80 | bool runOnMachineFunction(MachineFunction &Fn) override; |
Derek Schuff | 1dbf7a5 | 2016-04-04 17:09:25 +0000 | [diff] [blame] | 81 | MachineFunctionProperties getRequiredProperties() const override { |
| 82 | return MachineFunctionProperties().set( |
Matthias Braun | 1eb4736 | 2016-08-25 01:27:13 +0000 | [diff] [blame] | 83 | MachineFunctionProperties::Property::NoVRegs); |
Derek Schuff | 1dbf7a5 | 2016-04-04 17:09:25 +0000 | [diff] [blame] | 84 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 85 | |
| 86 | private: |
| 87 | const HexagonInstrInfo *HII; |
| 88 | const HexagonRegisterInfo *HRI; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 89 | }; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 90 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 91 | char HexagonPacketizer::ID = 0; |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 92 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 93 | |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 94 | INITIALIZE_PASS_BEGIN(HexagonPacketizer, "packets", "Hexagon Packetizer", |
| 95 | false, false) |
| 96 | INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) |
| 97 | INITIALIZE_PASS_DEPENDENCY(MachineBranchProbabilityInfo) |
| 98 | INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo) |
Chandler Carruth | 7b560d4 | 2015-09-09 17:55:00 +0000 | [diff] [blame] | 99 | INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) |
Jyotsna Verma | 1d29750 | 2013-05-02 15:39:30 +0000 | [diff] [blame] | 100 | INITIALIZE_PASS_END(HexagonPacketizer, "packets", "Hexagon Packetizer", |
| 101 | false, false) |
| 102 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 103 | HexagonPacketizerList::HexagonPacketizerList(MachineFunction &MF, |
| 104 | MachineLoopInfo &MLI, AliasAnalysis *AA, |
| 105 | const MachineBranchProbabilityInfo *MBPI) |
| 106 | : VLIWPacketizerList(MF, MLI, AA), MBPI(MBPI), MLI(&MLI) { |
| 107 | HII = MF.getSubtarget<HexagonSubtarget>().getInstrInfo(); |
| 108 | HRI = MF.getSubtarget<HexagonSubtarget>().getRegisterInfo(); |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 109 | |
| 110 | addMutation(make_unique<HexagonSubtarget::HexagonDAGMutation>()); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 113 | // Check if FirstI modifies a register that SecondI reads. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 114 | static bool hasWriteToReadDep(const MachineInstr &FirstI, |
| 115 | const MachineInstr &SecondI, |
| 116 | const TargetRegisterInfo *TRI) { |
| 117 | for (auto &MO : FirstI.operands()) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 118 | if (!MO.isReg() || !MO.isDef()) |
| 119 | continue; |
| 120 | unsigned R = MO.getReg(); |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 121 | if (SecondI.readsRegister(R, TRI)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 122 | return true; |
| 123 | } |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 128 | static MachineBasicBlock::iterator moveInstrOut(MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 129 | MachineBasicBlock::iterator BundleIt, bool Before) { |
| 130 | MachineBasicBlock::instr_iterator InsertPt; |
| 131 | if (Before) |
Duncan P. N. Exon Smith | d84f600 | 2016-02-22 21:30:15 +0000 | [diff] [blame] | 132 | InsertPt = BundleIt.getInstrIterator(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 133 | else |
Duncan P. N. Exon Smith | d84f600 | 2016-02-22 21:30:15 +0000 | [diff] [blame] | 134 | InsertPt = std::next(BundleIt).getInstrIterator(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 135 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 136 | MachineBasicBlock &B = *MI.getParent(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 137 | // The instruction should at least be bundled with the preceding instruction |
| 138 | // (there will always be one, i.e. BUNDLE, if nothing else). |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 139 | assert(MI.isBundledWithPred()); |
| 140 | if (MI.isBundledWithSucc()) { |
| 141 | MI.clearFlag(MachineInstr::BundledSucc); |
| 142 | MI.clearFlag(MachineInstr::BundledPred); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 143 | } else { |
| 144 | // If it's not bundled with the successor (i.e. it is the last one |
| 145 | // in the bundle), then we can simply unbundle it from the predecessor, |
| 146 | // which will take care of updating the predecessor's flag. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 147 | MI.unbundleFromPred(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 148 | } |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 149 | B.splice(InsertPt, &B, MI.getIterator()); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 150 | |
| 151 | // Get the size of the bundle without asserting. |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 152 | MachineBasicBlock::const_instr_iterator I = BundleIt.getInstrIterator(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 153 | MachineBasicBlock::const_instr_iterator E = B.instr_end(); |
| 154 | unsigned Size = 0; |
| 155 | for (++I; I != E && I->isBundledWithPred(); ++I) |
| 156 | ++Size; |
| 157 | |
| 158 | // If there are still two or more instructions, then there is nothing |
| 159 | // else to be done. |
| 160 | if (Size > 1) |
| 161 | return BundleIt; |
| 162 | |
| 163 | // Otherwise, extract the single instruction out and delete the bundle. |
| 164 | MachineBasicBlock::iterator NextIt = std::next(BundleIt); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 165 | MachineInstr &SingleI = *BundleIt->getNextNode(); |
| 166 | SingleI.unbundleFromPred(); |
| 167 | assert(!SingleI.isBundledWithSucc()); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 168 | BundleIt->eraseFromParent(); |
| 169 | return NextIt; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | bool HexagonPacketizer::runOnMachineFunction(MachineFunction &MF) { |
Andrew Kaylor | 5b444a2 | 2016-04-26 19:46:28 +0000 | [diff] [blame] | 174 | if (DisablePacketizer || skipFunction(*MF.getFunction())) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 175 | return false; |
| 176 | |
| 177 | HII = MF.getSubtarget<HexagonSubtarget>().getInstrInfo(); |
| 178 | HRI = MF.getSubtarget<HexagonSubtarget>().getRegisterInfo(); |
| 179 | auto &MLI = getAnalysis<MachineLoopInfo>(); |
| 180 | auto *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults(); |
| 181 | auto *MBPI = &getAnalysis<MachineBranchProbabilityInfo>(); |
| 182 | |
| 183 | if (EnableGenAllInsnClass) |
| 184 | HII->genAllInsnTimingClasses(MF); |
| 185 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 186 | // Instantiate the packetizer. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 187 | HexagonPacketizerList Packetizer(MF, MLI, AA, MBPI); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 188 | |
| 189 | // DFA state table should not be empty. |
| 190 | assert(Packetizer.getResourceTracker() && "Empty DFA table!"); |
| 191 | |
| 192 | // |
| 193 | // Loop over all basic blocks and remove KILL pseudo-instructions |
| 194 | // These instructions confuse the dependence analysis. Consider: |
| 195 | // D0 = ... (Insn 0) |
| 196 | // R0 = KILL R0, D0 (Insn 1) |
| 197 | // R0 = ... (Insn 2) |
| 198 | // Here, Insn 1 will result in the dependence graph not emitting an output |
| 199 | // dependence between Insn 0 and Insn 2. This can lead to incorrect |
| 200 | // packetization |
| 201 | // |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 202 | for (auto &MB : MF) { |
| 203 | auto End = MB.end(); |
| 204 | auto MI = MB.begin(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 205 | while (MI != End) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 206 | auto NextI = std::next(MI); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 207 | if (MI->isKill()) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 208 | MB.erase(MI); |
| 209 | End = MB.end(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 210 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 211 | MI = NextI; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| 215 | // Loop over all of the basic blocks. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 216 | for (auto &MB : MF) { |
| 217 | auto Begin = MB.begin(), End = MB.end(); |
| 218 | while (Begin != End) { |
| 219 | // First the first non-boundary starting from the end of the last |
| 220 | // scheduling region. |
| 221 | MachineBasicBlock::iterator RB = Begin; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 222 | while (RB != End && HII->isSchedulingBoundary(*RB, &MB, MF)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 223 | ++RB; |
| 224 | // First the first boundary starting from the beginning of the new |
| 225 | // region. |
| 226 | MachineBasicBlock::iterator RE = RB; |
Duncan P. N. Exon Smith | 9cfc75c | 2016-06-30 00:01:54 +0000 | [diff] [blame] | 227 | while (RE != End && !HII->isSchedulingBoundary(*RE, &MB, MF)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 228 | ++RE; |
| 229 | // Add the scheduling boundary if it's not block end. |
| 230 | if (RE != End) |
| 231 | ++RE; |
| 232 | // If RB == End, then RE == End. |
| 233 | if (RB != End) |
| 234 | Packetizer.PacketizeMIs(&MB, RB, RE); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 235 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 236 | Begin = RE; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 240 | Packetizer.unpacketizeSoloInstrs(MF); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 241 | return true; |
| 242 | } |
| 243 | |
| 244 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 245 | // Reserve resources for a constant extender. Trigger an assertion if the |
| 246 | // reservation fails. |
| 247 | void HexagonPacketizerList::reserveResourcesForConstExt() { |
| 248 | if (!tryAllocateResourcesForConstExt(true)) |
| 249 | llvm_unreachable("Resources not available"); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 252 | bool HexagonPacketizerList::canReserveResourcesForConstExt() { |
| 253 | return tryAllocateResourcesForConstExt(false); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 256 | // Allocate resources (i.e. 4 bytes) for constant extender. If succeeded, |
| 257 | // return true, otherwise, return false. |
| 258 | bool HexagonPacketizerList::tryAllocateResourcesForConstExt(bool Reserve) { |
| 259 | auto *ExtMI = MF.CreateMachineInstr(HII->get(Hexagon::A4_ext), DebugLoc()); |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 260 | bool Avail = ResourceTracker->canReserveResources(*ExtMI); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 261 | if (Reserve && Avail) |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 262 | ResourceTracker->reserveResources(*ExtMI); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 263 | MF.DeleteMachineInstr(ExtMI); |
| 264 | return Avail; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 267 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 268 | bool HexagonPacketizerList::isCallDependent(const MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 269 | SDep::Kind DepType, unsigned DepReg) { |
| 270 | // Check for LR dependence. |
| 271 | if (DepReg == HRI->getRARegister()) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 272 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 273 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 274 | if (HII->isDeallocRet(MI)) |
| 275 | if (DepReg == HRI->getFrameRegister() || DepReg == HRI->getStackRegister()) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 276 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 277 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 278 | // Check if this is a predicate dependence. |
| 279 | const TargetRegisterClass* RC = HRI->getMinimalPhysRegClass(DepReg); |
| 280 | if (RC == &Hexagon::PredRegsRegClass) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 281 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 282 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 283 | // Assumes that the first operand of the CALLr is the function address. |
| 284 | if (HII->isIndirectCall(MI) && (DepType == SDep::Data)) { |
Krzysztof Parzyszek | 29a6a2e | 2016-08-19 21:07:35 +0000 | [diff] [blame] | 285 | const MachineOperand MO = MI.getOperand(0); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 286 | if (MO.isReg() && MO.isUse() && (MO.getReg() == DepReg)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 287 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Krzysztof Parzyszek | 29a6a2e | 2016-08-19 21:07:35 +0000 | [diff] [blame] | 290 | if (HII->isJumpR(MI)) { |
| 291 | const MachineOperand &MO = HII->isPredicated(MI) ? MI.getOperand(1) |
| 292 | : MI.getOperand(0); |
| 293 | assert(MO.isReg() && MO.isUse()); |
| 294 | if (MO.getReg() == DepReg) |
| 295 | return true; |
| 296 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 297 | return false; |
| 298 | } |
| 299 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 300 | static bool isRegDependence(const SDep::Kind DepType) { |
| 301 | return DepType == SDep::Data || DepType == SDep::Anti || |
| 302 | DepType == SDep::Output; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 305 | static bool isDirectJump(const MachineInstr &MI) { |
| 306 | return MI.getOpcode() == Hexagon::J2_jump; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 309 | static bool isSchedBarrier(const MachineInstr &MI) { |
| 310 | switch (MI.getOpcode()) { |
Colin LeMahieu | b882f2b | 2015-02-05 18:56:28 +0000 | [diff] [blame] | 311 | case Hexagon::Y2_barrier: |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 312 | return true; |
| 313 | } |
| 314 | return false; |
| 315 | } |
| 316 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 317 | static bool isControlFlow(const MachineInstr &MI) { |
| 318 | return MI.getDesc().isTerminator() || MI.getDesc().isCall(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 321 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 322 | /// Returns true if the instruction modifies a callee-saved register. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 323 | static bool doesModifyCalleeSavedReg(const MachineInstr &MI, |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 324 | const TargetRegisterInfo *TRI) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 325 | const MachineFunction &MF = *MI.getParent()->getParent(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 326 | for (auto *CSR = TRI->getCalleeSavedRegs(&MF); CSR && *CSR; ++CSR) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 327 | if (MI.modifiesRegister(*CSR, TRI)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 328 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 329 | return false; |
| 330 | } |
| 331 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 332 | // Returns true if an instruction can be promoted to .new predicate or |
| 333 | // new-value store. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 334 | bool HexagonPacketizerList::isNewifiable(const MachineInstr &MI, |
Krzysztof Parzyszek | 2a48059 | 2016-07-26 20:30:30 +0000 | [diff] [blame] | 335 | const TargetRegisterClass *NewRC) { |
| 336 | // Vector stores can be predicated, and can be new-value stores, but |
| 337 | // they cannot be predicated on a .new predicate value. |
| 338 | if (NewRC == &Hexagon::PredRegsRegClass) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 339 | if (HII->isV60VectorInstruction(MI) && MI.mayStore()) |
Krzysztof Parzyszek | 2a48059 | 2016-07-26 20:30:30 +0000 | [diff] [blame] | 340 | return false; |
Krzysztof Parzyszek | 38e2ccc | 2016-08-23 16:01:01 +0000 | [diff] [blame] | 341 | return HII->isCondInst(MI) || HII->isJumpR(MI) || MI.isReturn() || |
| 342 | HII->mayBeNewStore(MI); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 345 | // Promote an instructiont to its .cur form. |
| 346 | // At this time, we have already made a call to canPromoteToDotCur and made |
| 347 | // sure that it can *indeed* be promoted. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 348 | bool HexagonPacketizerList::promoteToDotCur(MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 349 | SDep::Kind DepType, MachineBasicBlock::iterator &MII, |
| 350 | const TargetRegisterClass* RC) { |
| 351 | assert(DepType == SDep::Data); |
| 352 | int CurOpcode = HII->getDotCurOp(MI); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 353 | MI.setDesc(HII->get(CurOpcode)); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 354 | return true; |
| 355 | } |
| 356 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 357 | void HexagonPacketizerList::cleanUpDotCur() { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 358 | MachineInstr *MI = nullptr; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 359 | for (auto BI : CurrentPacketMIs) { |
| 360 | DEBUG(dbgs() << "Cleanup packet has "; BI->dump();); |
| 361 | if (BI->getOpcode() == Hexagon::V6_vL32b_cur_ai) { |
| 362 | MI = BI; |
| 363 | continue; |
| 364 | } |
| 365 | if (MI) { |
| 366 | for (auto &MO : BI->operands()) |
| 367 | if (MO.isReg() && MO.getReg() == MI->getOperand(0).getReg()) |
| 368 | return; |
| 369 | } |
| 370 | } |
| 371 | if (!MI) |
| 372 | return; |
| 373 | // We did not find a use of the CUR, so de-cur it. |
| 374 | MI->setDesc(HII->get(Hexagon::V6_vL32b_ai)); |
| 375 | DEBUG(dbgs() << "Demoted CUR "; MI->dump();); |
| 376 | } |
| 377 | |
| 378 | // Check to see if an instruction can be dot cur. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 379 | bool HexagonPacketizerList::canPromoteToDotCur(const MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 380 | const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII, |
| 381 | const TargetRegisterClass *RC) { |
| 382 | if (!HII->isV60VectorInstruction(MI)) |
| 383 | return false; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 384 | if (!HII->isV60VectorInstruction(*MII)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 385 | return false; |
| 386 | |
| 387 | // Already a dot new instruction. |
| 388 | if (HII->isDotCurInst(MI) && !HII->mayBeCurLoad(MI)) |
| 389 | return false; |
| 390 | |
| 391 | if (!HII->mayBeCurLoad(MI)) |
| 392 | return false; |
| 393 | |
| 394 | // The "cur value" cannot come from inline asm. |
| 395 | if (PacketSU->getInstr()->isInlineAsm()) |
| 396 | return false; |
| 397 | |
| 398 | // Make sure candidate instruction uses cur. |
| 399 | DEBUG(dbgs() << "Can we DOT Cur Vector MI\n"; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 400 | MI.dump(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 401 | dbgs() << "in packet\n";); |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 402 | MachineInstr &MJ = *MII; |
| 403 | DEBUG({ |
| 404 | dbgs() << "Checking CUR against "; |
| 405 | MJ.dump(); |
| 406 | }); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 407 | unsigned DestReg = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 408 | bool FoundMatch = false; |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 409 | for (auto &MO : MJ.operands()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 410 | if (MO.isReg() && MO.getReg() == DestReg) |
| 411 | FoundMatch = true; |
| 412 | if (!FoundMatch) |
| 413 | return false; |
| 414 | |
| 415 | // Check for existing uses of a vector register within the packet which |
| 416 | // would be affected by converting a vector load into .cur formt. |
| 417 | for (auto BI : CurrentPacketMIs) { |
| 418 | DEBUG(dbgs() << "packet has "; BI->dump();); |
| 419 | if (BI->readsRegister(DepReg, MF.getSubtarget().getRegisterInfo())) |
| 420 | return false; |
| 421 | } |
| 422 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 423 | DEBUG(dbgs() << "Can Dot CUR MI\n"; MI.dump();); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 424 | // We can convert the opcode into a .cur. |
| 425 | return true; |
| 426 | } |
| 427 | |
| 428 | // Promote an instruction to its .new form. At this time, we have already |
| 429 | // made a call to canPromoteToDotNew and made sure that it can *indeed* be |
| 430 | // promoted. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 431 | bool HexagonPacketizerList::promoteToDotNew(MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 432 | SDep::Kind DepType, MachineBasicBlock::iterator &MII, |
| 433 | const TargetRegisterClass* RC) { |
| 434 | assert (DepType == SDep::Data); |
| 435 | int NewOpcode; |
| 436 | if (RC == &Hexagon::PredRegsRegClass) |
| 437 | NewOpcode = HII->getDotNewPredOp(MI, MBPI); |
| 438 | else |
| 439 | NewOpcode = HII->getDotNewOp(MI); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 440 | MI.setDesc(HII->get(NewOpcode)); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 441 | return true; |
| 442 | } |
| 443 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 444 | bool HexagonPacketizerList::demoteToDotOld(MachineInstr &MI) { |
| 445 | int NewOpcode = HII->getDotOldOp(MI.getOpcode()); |
| 446 | MI.setDesc(HII->get(NewOpcode)); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 447 | return true; |
| 448 | } |
| 449 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 450 | bool HexagonPacketizerList::useCallersSP(MachineInstr &MI) { |
| 451 | unsigned Opc = MI.getOpcode(); |
Krzysztof Parzyszek | 3b4682f | 2016-07-26 14:24:46 +0000 | [diff] [blame] | 452 | switch (Opc) { |
| 453 | case Hexagon::S2_storerd_io: |
| 454 | case Hexagon::S2_storeri_io: |
| 455 | case Hexagon::S2_storerh_io: |
| 456 | case Hexagon::S2_storerb_io: |
| 457 | break; |
| 458 | default: |
| 459 | llvm_unreachable("Unexpected instruction"); |
| 460 | } |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 461 | unsigned FrameSize = MF.getFrameInfo().getStackSize(); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 462 | MachineOperand &Off = MI.getOperand(1); |
Krzysztof Parzyszek | 3b4682f | 2016-07-26 14:24:46 +0000 | [diff] [blame] | 463 | int64_t NewOff = Off.getImm() - (FrameSize + HEXAGON_LRFP_SIZE); |
| 464 | if (HII->isValidOffset(Opc, NewOff)) { |
| 465 | Off.setImm(NewOff); |
| 466 | return true; |
| 467 | } |
| 468 | return false; |
| 469 | } |
| 470 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 471 | void HexagonPacketizerList::useCalleesSP(MachineInstr &MI) { |
| 472 | unsigned Opc = MI.getOpcode(); |
Krzysztof Parzyszek | 3b4682f | 2016-07-26 14:24:46 +0000 | [diff] [blame] | 473 | switch (Opc) { |
| 474 | case Hexagon::S2_storerd_io: |
| 475 | case Hexagon::S2_storeri_io: |
| 476 | case Hexagon::S2_storerh_io: |
| 477 | case Hexagon::S2_storerb_io: |
| 478 | break; |
| 479 | default: |
| 480 | llvm_unreachable("Unexpected instruction"); |
| 481 | } |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 482 | unsigned FrameSize = MF.getFrameInfo().getStackSize(); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 483 | MachineOperand &Off = MI.getOperand(1); |
Krzysztof Parzyszek | 3b4682f | 2016-07-26 14:24:46 +0000 | [diff] [blame] | 484 | Off.setImm(Off.getImm() + FrameSize + HEXAGON_LRFP_SIZE); |
| 485 | } |
| 486 | |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 487 | enum PredicateKind { |
| 488 | PK_False, |
| 489 | PK_True, |
| 490 | PK_Unknown |
| 491 | }; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 492 | |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 493 | /// Returns true if an instruction is predicated on p0 and false if it's |
| 494 | /// predicated on !p0. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 495 | static PredicateKind getPredicateSense(const MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 496 | const HexagonInstrInfo *HII) { |
| 497 | if (!HII->isPredicated(MI)) |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 498 | return PK_Unknown; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 499 | if (HII->isPredicatedTrue(MI)) |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 500 | return PK_True; |
Jyotsna Verma | 300f0b9 | 2013-05-10 20:27:34 +0000 | [diff] [blame] | 501 | return PK_False; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 504 | static const MachineOperand &getPostIncrementOperand(const MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 505 | const HexagonInstrInfo *HII) { |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 506 | assert(HII->isPostIncrement(MI) && "Not a post increment operation."); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 507 | #ifndef NDEBUG |
| 508 | // Post Increment means duplicates. Use dense map to find duplicates in the |
| 509 | // list. Caution: Densemap initializes with the minimum of 64 buckets, |
| 510 | // whereas there are at most 5 operands in the post increment. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 511 | DenseSet<unsigned> DefRegsSet; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 512 | for (auto &MO : MI.operands()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 513 | if (MO.isReg() && MO.isDef()) |
| 514 | DefRegsSet.insert(MO.getReg()); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 515 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 516 | for (auto &MO : MI.operands()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 517 | if (MO.isReg() && MO.isUse() && DefRegsSet.count(MO.getReg())) |
| 518 | return MO; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 519 | #else |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 520 | if (MI.mayLoad()) { |
| 521 | const MachineOperand &Op1 = MI.getOperand(1); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 522 | // The 2nd operand is always the post increment operand in load. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 523 | assert(Op1.isReg() && "Post increment operand has be to a register."); |
| 524 | return Op1; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 525 | } |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 526 | if (MI.getDesc().mayStore()) { |
| 527 | const MachineOperand &Op0 = MI.getOperand(0); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 528 | // The 1st operand is always the post increment operand in store. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 529 | assert(Op0.isReg() && "Post increment operand has be to a register."); |
| 530 | return Op0; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 531 | } |
| 532 | #endif |
| 533 | // we should never come here. |
| 534 | llvm_unreachable("mayLoad or mayStore not set for Post Increment operation"); |
| 535 | } |
| 536 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 537 | // Get the value being stored. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 538 | static const MachineOperand& getStoreValueOperand(const MachineInstr &MI) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 539 | // value being stored is always the last operand. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 540 | return MI.getOperand(MI.getNumOperands()-1); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 543 | static bool isLoadAbsSet(const MachineInstr &MI) { |
| 544 | unsigned Opc = MI.getOpcode(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 545 | switch (Opc) { |
| 546 | case Hexagon::L4_loadrd_ap: |
| 547 | case Hexagon::L4_loadrb_ap: |
| 548 | case Hexagon::L4_loadrh_ap: |
| 549 | case Hexagon::L4_loadrub_ap: |
| 550 | case Hexagon::L4_loadruh_ap: |
| 551 | case Hexagon::L4_loadri_ap: |
| 552 | return true; |
| 553 | } |
| 554 | return false; |
| 555 | } |
| 556 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 557 | static const MachineOperand &getAbsSetOperand(const MachineInstr &MI) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 558 | assert(isLoadAbsSet(MI)); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 559 | return MI.getOperand(1); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | |
| 563 | // Can be new value store? |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 564 | // Following restrictions are to be respected in convert a store into |
| 565 | // a new value store. |
| 566 | // 1. If an instruction uses auto-increment, its address register cannot |
| 567 | // be a new-value register. Arch Spec 5.4.2.1 |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 568 | // 2. If an instruction uses absolute-set addressing mode, its address |
| 569 | // register cannot be a new-value register. Arch Spec 5.4.2.1. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 570 | // 3. If an instruction produces a 64-bit result, its registers cannot be used |
| 571 | // as new-value registers. Arch Spec 5.4.2.2. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 572 | // 4. If the instruction that sets the new-value register is conditional, then |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 573 | // the instruction that uses the new-value register must also be conditional, |
| 574 | // and both must always have their predicates evaluate identically. |
| 575 | // Arch Spec 5.4.2.3. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 576 | // 5. There is an implied restriction that a packet cannot have another store, |
| 577 | // if there is a new value store in the packet. Corollary: if there is |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 578 | // already a store in a packet, there can not be a new value store. |
| 579 | // Arch Spec: 3.4.4.2 |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 580 | bool HexagonPacketizerList::canPromoteToNewValueStore(const MachineInstr &MI, |
| 581 | const MachineInstr &PacketMI, unsigned DepReg) { |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 582 | // Make sure we are looking at the store, that can be promoted. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 583 | if (!HII->mayBeNewStore(MI)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 584 | return false; |
| 585 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 586 | // Make sure there is dependency and can be new value'd. |
| 587 | const MachineOperand &Val = getStoreValueOperand(MI); |
| 588 | if (Val.isReg() && Val.getReg() != DepReg) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 589 | return false; |
| 590 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 591 | const MCInstrDesc& MCID = PacketMI.getDesc(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 592 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 593 | // First operand is always the result. |
| 594 | const TargetRegisterClass *PacketRC = HII->getRegClass(MCID, 0, HRI, MF); |
| 595 | // Double regs can not feed into new value store: PRM section: 5.4.2.2. |
| 596 | if (PacketRC == &Hexagon::DoubleRegsRegClass) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 597 | return false; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 598 | |
| 599 | // New-value stores are of class NV (slot 0), dual stores require class ST |
| 600 | // in slot 0 (PRM 5.5). |
| 601 | for (auto I : CurrentPacketMIs) { |
| 602 | SUnit *PacketSU = MIToSUnit.find(I)->second; |
| 603 | if (PacketSU->getInstr()->mayStore()) |
| 604 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | // Make sure it's NOT the post increment register that we are going to |
| 608 | // new value. |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 609 | if (HII->isPostIncrement(MI) && |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 610 | getPostIncrementOperand(MI, HII).getReg() == DepReg) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 611 | return false; |
| 612 | } |
| 613 | |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 614 | if (HII->isPostIncrement(PacketMI) && PacketMI.mayLoad() && |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 615 | getPostIncrementOperand(PacketMI, HII).getReg() == DepReg) { |
| 616 | // If source is post_inc, or absolute-set addressing, it can not feed |
| 617 | // into new value store |
| 618 | // r3 = memw(r2++#4) |
| 619 | // memw(r30 + #-1404) = r2.new -> can not be new value store |
| 620 | // arch spec section: 5.4.2.1. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 621 | return false; |
| 622 | } |
| 623 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 624 | if (isLoadAbsSet(PacketMI) && getAbsSetOperand(PacketMI).getReg() == DepReg) |
| 625 | return false; |
| 626 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 627 | // If the source that feeds the store is predicated, new value store must |
Jyotsna Verma | 438cec5 | 2013-05-10 20:58:11 +0000 | [diff] [blame] | 628 | // also be predicated. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 629 | if (HII->isPredicated(PacketMI)) { |
| 630 | if (!HII->isPredicated(MI)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 631 | return false; |
| 632 | |
| 633 | // Check to make sure that they both will have their predicates |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 634 | // evaluate identically. |
Sirish Pande | 95d0117 | 2012-05-11 20:00:34 +0000 | [diff] [blame] | 635 | unsigned predRegNumSrc = 0; |
| 636 | unsigned predRegNumDst = 0; |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 637 | const TargetRegisterClass* predRegClass = nullptr; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 638 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 639 | // Get predicate register used in the source instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 640 | for (auto &MO : PacketMI.operands()) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 641 | if (!MO.isReg()) |
| 642 | continue; |
| 643 | predRegNumSrc = MO.getReg(); |
| 644 | predRegClass = HRI->getMinimalPhysRegClass(predRegNumSrc); |
| 645 | if (predRegClass == &Hexagon::PredRegsRegClass) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 646 | break; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 647 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 648 | assert((predRegClass == &Hexagon::PredRegsRegClass) && |
| 649 | "predicate register not found in a predicated PacketMI instruction"); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 650 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 651 | // Get predicate register used in new-value store instruction. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 652 | for (auto &MO : MI.operands()) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 653 | if (!MO.isReg()) |
| 654 | continue; |
| 655 | predRegNumDst = MO.getReg(); |
| 656 | predRegClass = HRI->getMinimalPhysRegClass(predRegNumDst); |
| 657 | if (predRegClass == &Hexagon::PredRegsRegClass) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 658 | break; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 659 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 660 | assert((predRegClass == &Hexagon::PredRegsRegClass) && |
| 661 | "predicate register not found in a predicated MI instruction"); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 662 | |
| 663 | // New-value register producer and user (store) need to satisfy these |
| 664 | // constraints: |
| 665 | // 1) Both instructions should be predicated on the same register. |
| 666 | // 2) If producer of the new-value register is .new predicated then store |
| 667 | // should also be .new predicated and if producer is not .new predicated |
| 668 | // then store should not be .new predicated. |
| 669 | // 3) Both new-value register producer and user should have same predicate |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 670 | // sense, i.e, either both should be negated or both should be non-negated. |
| 671 | if (predRegNumDst != predRegNumSrc || |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 672 | HII->isDotNewInst(PacketMI) != HII->isDotNewInst(MI) || |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 673 | getPredicateSense(MI, HII) != getPredicateSense(PacketMI, HII)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 674 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | // Make sure that other than the new-value register no other store instruction |
| 678 | // register has been modified in the same packet. Predicate registers can be |
| 679 | // modified by they should not be modified between the producer and the store |
| 680 | // instruction as it will make them both conditional on different values. |
| 681 | // We already know this to be true for all the instructions before and |
| 682 | // including PacketMI. Howerver, we need to perform the check for the |
| 683 | // remaining instructions in the packet. |
| 684 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 685 | unsigned StartCheck = 0; |
| 686 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 687 | for (auto I : CurrentPacketMIs) { |
| 688 | SUnit *TempSU = MIToSUnit.find(I)->second; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 689 | MachineInstr &TempMI = *TempSU->getInstr(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 690 | |
| 691 | // Following condition is true for all the instructions until PacketMI is |
| 692 | // reached (StartCheck is set to 0 before the for loop). |
| 693 | // StartCheck flag is 1 for all the instructions after PacketMI. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 694 | if (&TempMI != &PacketMI && !StartCheck) // Start processing only after |
| 695 | continue; // encountering PacketMI. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 696 | |
| 697 | StartCheck = 1; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 698 | if (&TempMI == &PacketMI) // We don't want to check PacketMI for dependence. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 699 | continue; |
| 700 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 701 | for (auto &MO : MI.operands()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 702 | if (MO.isReg() && TempSU->getInstr()->modifiesRegister(MO.getReg(), HRI)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 703 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 704 | } |
| 705 | |
Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 706 | // Make sure that for non-POST_INC stores: |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 707 | // 1. The only use of reg is DepReg and no other registers. |
| 708 | // This handles V4 base+index registers. |
| 709 | // The following store can not be dot new. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 710 | // Eg. r0 = add(r0, #3) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 711 | // memw(r1+r0<<#2) = r0 |
Krzysztof Parzyszek | 8fb181c | 2016-08-01 17:55:48 +0000 | [diff] [blame] | 712 | if (!HII->isPostIncrement(MI)) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 713 | for (unsigned opNum = 0; opNum < MI.getNumOperands()-1; opNum++) { |
| 714 | const MachineOperand &MO = MI.getOperand(opNum); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 715 | if (MO.isReg() && MO.getReg() == DepReg) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 716 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 717 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | // If data definition is because of implicit definition of the register, |
| 721 | // do not newify the store. Eg. |
| 722 | // %R9<def> = ZXTH %R12, %D6<imp-use>, %R12<imp-def> |
| 723 | // S2_storerh_io %R8, 2, %R12<kill>; mem:ST2[%scevgep343] |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 724 | for (auto &MO : PacketMI.operands()) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 725 | if (!MO.isReg() || !MO.isDef() || !MO.isImplicit()) |
| 726 | continue; |
| 727 | unsigned R = MO.getReg(); |
| 728 | if (R == DepReg || HRI->isSuperRegister(DepReg, R)) |
| 729 | return false; |
| 730 | } |
| 731 | |
| 732 | // Handle imp-use of super reg case. There is a target independent side |
| 733 | // change that should prevent this situation but I am handling it for |
| 734 | // just-in-case. For example, we cannot newify R2 in the following case: |
| 735 | // %R3<def> = A2_tfrsi 0; |
| 736 | // S2_storeri_io %R0<kill>, 0, %R2<kill>, %D1<imp-use,kill>; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 737 | for (auto &MO : MI.operands()) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 738 | if (MO.isReg() && MO.isUse() && MO.isImplicit() && MO.getReg() == DepReg) |
| 739 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | // Can be dot new store. |
| 743 | return true; |
| 744 | } |
| 745 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 746 | // Can this MI to promoted to either new value store or new value jump. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 747 | bool HexagonPacketizerList::canPromoteToNewValue(const MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 748 | const SUnit *PacketSU, unsigned DepReg, |
| 749 | MachineBasicBlock::iterator &MII) { |
| 750 | if (!HII->mayBeNewStore(MI)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 751 | return false; |
| 752 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 753 | // Check to see the store can be new value'ed. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 754 | MachineInstr &PacketMI = *PacketSU->getInstr(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 755 | if (canPromoteToNewValueStore(MI, PacketMI, DepReg)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 756 | return true; |
| 757 | |
| 758 | // Check to see the compare/jump can be new value'ed. |
| 759 | // This is done as a pass on its own. Don't need to check it here. |
| 760 | return false; |
| 761 | } |
| 762 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 763 | static bool isImplicitDependency(const MachineInstr &I, unsigned DepReg) { |
| 764 | for (auto &MO : I.operands()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 765 | if (MO.isReg() && MO.isDef() && (MO.getReg() == DepReg) && MO.isImplicit()) |
| 766 | return true; |
| 767 | return false; |
| 768 | } |
| 769 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 770 | // Check to see if an instruction can be dot new |
| 771 | // There are three kinds. |
| 772 | // 1. dot new on predicate - V2/V3/V4 |
| 773 | // 2. dot new on stores NV/ST - V4 |
| 774 | // 3. dot new on jump NV/J - V4 -- This is generated in a pass. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 775 | bool HexagonPacketizerList::canPromoteToDotNew(const MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 776 | const SUnit *PacketSU, unsigned DepReg, MachineBasicBlock::iterator &MII, |
| 777 | const TargetRegisterClass* RC) { |
Jyotsna Verma | a46059b | 2013-03-28 19:44:04 +0000 | [diff] [blame] | 778 | // Already a dot new instruction. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 779 | if (HII->isDotNewInst(MI) && !HII->mayBeNewStore(MI)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 780 | return false; |
| 781 | |
Krzysztof Parzyszek | 2a48059 | 2016-07-26 20:30:30 +0000 | [diff] [blame] | 782 | if (!isNewifiable(MI, RC)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 783 | return false; |
| 784 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 785 | const MachineInstr &PI = *PacketSU->getInstr(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 786 | |
| 787 | // The "new value" cannot come from inline asm. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 788 | if (PI.isInlineAsm()) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 789 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 790 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 791 | // IMPLICIT_DEFs won't materialize as real instructions, so .new makes no |
| 792 | // sense. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 793 | if (PI.isImplicitDef()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 794 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 795 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 796 | // If dependency is trough an implicitly defined register, we should not |
| 797 | // newify the use. |
| 798 | if (isImplicitDependency(PI, DepReg)) |
| 799 | return false; |
| 800 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 801 | const MCInstrDesc& MCID = PI.getDesc(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 802 | const TargetRegisterClass *VecRC = HII->getRegClass(MCID, 0, HRI, MF); |
| 803 | if (DisableVecDblNVStores && VecRC == &Hexagon::VecDblRegsRegClass) |
| 804 | return false; |
| 805 | |
| 806 | // predicate .new |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 807 | if (RC == &Hexagon::PredRegsRegClass) |
Krzysztof Parzyszek | 38e2ccc | 2016-08-23 16:01:01 +0000 | [diff] [blame] | 808 | if (HII->isCondInst(MI) || HII->isJumpR(MI) || MI.isReturn()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 809 | return HII->predCanBeUsedAsDotNew(PI, DepReg); |
| 810 | |
| 811 | if (RC != &Hexagon::PredRegsRegClass && !HII->mayBeNewStore(MI)) |
| 812 | return false; |
| 813 | |
| 814 | // Create a dot new machine instruction to see if resources can be |
| 815 | // allocated. If not, bail out now. |
| 816 | int NewOpcode = HII->getDotNewOp(MI); |
| 817 | const MCInstrDesc &D = HII->get(NewOpcode); |
| 818 | MachineInstr *NewMI = MF.CreateMachineInstr(D, DebugLoc()); |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 819 | bool ResourcesAvailable = ResourceTracker->canReserveResources(*NewMI); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 820 | MF.DeleteMachineInstr(NewMI); |
| 821 | if (!ResourcesAvailable) |
| 822 | return false; |
| 823 | |
| 824 | // New Value Store only. New Value Jump generated as a separate pass. |
| 825 | if (!canPromoteToNewValue(MI, PacketSU, DepReg, MII)) |
| 826 | return false; |
| 827 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 828 | return true; |
| 829 | } |
| 830 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 831 | // Go through the packet instructions and search for an anti dependency between |
| 832 | // them and DepReg from MI. Consider this case: |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 833 | // Trying to add |
| 834 | // a) %R1<def> = TFRI_cdNotPt %P3, 2 |
| 835 | // to this packet: |
| 836 | // { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 837 | // b) %P0<def> = C2_or %P3<kill>, %P0<kill> |
| 838 | // c) %P3<def> = C2_tfrrp %R23 |
| 839 | // d) %R1<def> = C2_cmovenewit %P3, 4 |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 840 | // } |
| 841 | // The P3 from a) and d) will be complements after |
| 842 | // a)'s P3 is converted to .new form |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 843 | // Anti-dep between c) and b) is irrelevant for this case |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 844 | bool HexagonPacketizerList::restrictingDepExistInPacket(MachineInstr &MI, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 845 | unsigned DepReg) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 846 | SUnit *PacketSUDep = MIToSUnit.find(&MI)->second; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 847 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 848 | for (auto I : CurrentPacketMIs) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 849 | // We only care for dependencies to predicated instructions |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 850 | if (!HII->isPredicated(*I)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 851 | continue; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 852 | |
| 853 | // Scheduling Unit for current insn in the packet |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 854 | SUnit *PacketSU = MIToSUnit.find(I)->second; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 855 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 856 | // Look at dependencies between current members of the packet and |
| 857 | // predicate defining instruction MI. Make sure that dependency is |
| 858 | // on the exact register we care about. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 859 | if (PacketSU->isSucc(PacketSUDep)) { |
| 860 | for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 861 | auto &Dep = PacketSU->Succs[i]; |
| 862 | if (Dep.getSUnit() == PacketSUDep && Dep.getKind() == SDep::Anti && |
| 863 | Dep.getReg() == DepReg) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 864 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | return false; |
| 870 | } |
| 871 | |
| 872 | |
Jyotsna Verma | 11bd54a | 2013-05-14 16:36:34 +0000 | [diff] [blame] | 873 | /// Gets the predicate register of a predicated instruction. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 874 | static unsigned getPredicatedRegister(MachineInstr &MI, |
Benjamin Kramer | e79beac | 2013-05-23 15:43:11 +0000 | [diff] [blame] | 875 | const HexagonInstrInfo *QII) { |
Jyotsna Verma | 11bd54a | 2013-05-14 16:36:34 +0000 | [diff] [blame] | 876 | /// We use the following rule: The first predicate register that is a use is |
| 877 | /// the predicate register of a predicated instruction. |
Jyotsna Verma | 11bd54a | 2013-05-14 16:36:34 +0000 | [diff] [blame] | 878 | assert(QII->isPredicated(MI) && "Must be predicated instruction"); |
| 879 | |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 880 | for (auto &Op : MI.operands()) { |
Jyotsna Verma | 11bd54a | 2013-05-14 16:36:34 +0000 | [diff] [blame] | 881 | if (Op.isReg() && Op.getReg() && Op.isUse() && |
| 882 | Hexagon::PredRegsRegClass.contains(Op.getReg())) |
| 883 | return Op.getReg(); |
| 884 | } |
| 885 | |
| 886 | llvm_unreachable("Unknown instruction operand layout"); |
Jyotsna Verma | 11bd54a | 2013-05-14 16:36:34 +0000 | [diff] [blame] | 887 | return 0; |
| 888 | } |
| 889 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 890 | // Given two predicated instructions, this function detects whether |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 891 | // the predicates are complements. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 892 | bool HexagonPacketizerList::arePredicatesComplements(MachineInstr &MI1, |
| 893 | MachineInstr &MI2) { |
Jyotsna Verma | 11bd54a | 2013-05-14 16:36:34 +0000 | [diff] [blame] | 894 | // If we don't know the predicate sense of the instructions bail out early, we |
| 895 | // need it later. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 896 | if (getPredicateSense(MI1, HII) == PK_Unknown || |
| 897 | getPredicateSense(MI2, HII) == PK_Unknown) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 898 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 899 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 900 | // Scheduling unit for candidate. |
Duncan P. N. Exon Smith | 6307eb5 | 2016-02-23 02:46:52 +0000 | [diff] [blame] | 901 | SUnit *SU = MIToSUnit[&MI1]; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 902 | |
| 903 | // One corner case deals with the following scenario: |
| 904 | // Trying to add |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 905 | // a) %R24<def> = A2_tfrt %P0, %R25 |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 906 | // to this packet: |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 907 | // { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 908 | // b) %R25<def> = A2_tfrf %P0, %R24 |
| 909 | // c) %P0<def> = C2_cmpeqi %R26, 1 |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 910 | // } |
| 911 | // |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 912 | // On general check a) and b) are complements, but presence of c) will |
| 913 | // convert a) to .new form, and then it is not a complement. |
| 914 | // We attempt to detect it by analyzing existing dependencies in the packet. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 915 | |
| 916 | // Analyze relationships between all existing members of the packet. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 917 | // Look for Anti dependecy on the same predicate reg as used in the |
| 918 | // candidate. |
| 919 | for (auto I : CurrentPacketMIs) { |
| 920 | // Scheduling Unit for current insn in the packet. |
| 921 | SUnit *PacketSU = MIToSUnit.find(I)->second; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 922 | |
| 923 | // If this instruction in the packet is succeeded by the candidate... |
| 924 | if (PacketSU->isSucc(SU)) { |
| 925 | for (unsigned i = 0; i < PacketSU->Succs.size(); ++i) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 926 | auto Dep = PacketSU->Succs[i]; |
| 927 | // The corner case exist when there is true data dependency between |
| 928 | // candidate and one of current packet members, this dep is on |
| 929 | // predicate reg, and there already exist anti dep on the same pred in |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 930 | // the packet. |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 931 | if (Dep.getSUnit() == SU && Dep.getKind() == SDep::Data && |
| 932 | Hexagon::PredRegsRegClass.contains(Dep.getReg())) { |
| 933 | // Here I know that I is predicate setting instruction with true |
| 934 | // data dep to candidate on the register we care about - c) in the |
| 935 | // above example. Now I need to see if there is an anti dependency |
| 936 | // from c) to any other instruction in the same packet on the pred |
| 937 | // reg of interest. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 938 | if (restrictingDepExistInPacket(*I, Dep.getReg())) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 939 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 940 | } |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 945 | // If the above case does not apply, check regular complement condition. |
| 946 | // Check that the predicate register is the same and that the predicate |
| 947 | // sense is different We also need to differentiate .old vs. .new: !p0 |
| 948 | // is not complementary to p0.new. |
| 949 | unsigned PReg1 = getPredicatedRegister(MI1, HII); |
| 950 | unsigned PReg2 = getPredicatedRegister(MI2, HII); |
| 951 | return PReg1 == PReg2 && |
| 952 | Hexagon::PredRegsRegClass.contains(PReg1) && |
| 953 | Hexagon::PredRegsRegClass.contains(PReg2) && |
| 954 | getPredicateSense(MI1, HII) != getPredicateSense(MI2, HII) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 955 | HII->isDotNewInst(MI1) == HII->isDotNewInst(MI2); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 956 | } |
| 957 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 958 | // Initialize packetizer flags. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 959 | void HexagonPacketizerList::initPacketizerState() { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 960 | Dependence = false; |
| 961 | PromotedToDotNew = false; |
| 962 | GlueToNewValueJump = false; |
| 963 | GlueAllocframeStore = false; |
| 964 | FoundSequentialDependence = false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 965 | } |
| 966 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 967 | // Ignore bundling of pseudo instructions. |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 968 | bool HexagonPacketizerList::ignorePseudoInstruction(const MachineInstr &MI, |
| 969 | const MachineBasicBlock *) { |
| 970 | if (MI.isDebugValue()) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 971 | return true; |
| 972 | |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 973 | if (MI.isCFIInstruction()) |
Krzysztof Parzyszek | 6bbcb31 | 2015-04-22 15:47:35 +0000 | [diff] [blame] | 974 | return false; |
| 975 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 976 | // We must print out inline assembly. |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 977 | if (MI.isInlineAsm()) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 978 | return false; |
| 979 | |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 980 | if (MI.isImplicitDef()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 981 | return false; |
| 982 | |
| 983 | // We check if MI has any functional units mapped to it. If it doesn't, |
| 984 | // we ignore the instruction. |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 985 | const MCInstrDesc& TID = MI.getDesc(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 986 | auto *IS = ResourceTracker->getInstrItins()->beginStage(TID.getSchedClass()); |
Hal Finkel | 8db5547 | 2012-06-22 20:27:13 +0000 | [diff] [blame] | 987 | unsigned FuncUnits = IS->getUnits(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 988 | return !FuncUnits; |
| 989 | } |
| 990 | |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 991 | bool HexagonPacketizerList::isSoloInstruction(const MachineInstr &MI) { |
| 992 | if (MI.isEHLabel() || MI.isCFIInstruction()) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 993 | return true; |
| 994 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 995 | // Consider inline asm to not be a solo instruction by default. |
| 996 | // Inline asm will be put in a packet temporarily, but then it will be |
| 997 | // removed, and placed outside of the packet (before or after, depending |
| 998 | // on dependencies). This is to reduce the impact of inline asm as a |
| 999 | // "packet splitting" instruction. |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1000 | if (MI.isInlineAsm() && !ScheduleInlineAsm) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1001 | return true; |
| 1002 | |
| 1003 | // From Hexagon V4 Programmer's Reference Manual 3.4.4 Grouping constraints: |
| 1004 | // trap, pause, barrier, icinva, isync, and syncht are solo instructions. |
| 1005 | // They must not be grouped with other instructions in a packet. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1006 | if (isSchedBarrier(MI)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1007 | return true; |
| 1008 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1009 | if (HII->isSolo(MI)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1010 | return true; |
| 1011 | |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1012 | if (MI.getOpcode() == Hexagon::A2_nop) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1013 | return true; |
| 1014 | |
| 1015 | return false; |
| 1016 | } |
| 1017 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1018 | |
| 1019 | // Quick check if instructions MI and MJ cannot coexist in the same packet. |
| 1020 | // Limit the tests to be "one-way", e.g. "if MI->isBranch and MJ->isInlineAsm", |
| 1021 | // but not the symmetric case: "if MJ->isBranch and MI->isInlineAsm". |
| 1022 | // For full test call this function twice: |
| 1023 | // cannotCoexistAsymm(MI, MJ) || cannotCoexistAsymm(MJ, MI) |
| 1024 | // Doing the test only one way saves the amount of code in this function, |
| 1025 | // since every test would need to be repeated with the MI and MJ reversed. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1026 | static bool cannotCoexistAsymm(const MachineInstr &MI, const MachineInstr &MJ, |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1027 | const HexagonInstrInfo &HII) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1028 | const MachineFunction *MF = MI.getParent()->getParent(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1029 | if (MF->getSubtarget<HexagonSubtarget>().hasV60TOpsOnly() && |
| 1030 | HII.isHVXMemWithAIndirect(MI, MJ)) |
| 1031 | return true; |
| 1032 | |
| 1033 | // An inline asm cannot be together with a branch, because we may not be |
| 1034 | // able to remove the asm out after packetizing (i.e. if the asm must be |
| 1035 | // moved past the bundle). Similarly, two asms cannot be together to avoid |
| 1036 | // complications when determining their relative order outside of a bundle. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1037 | if (MI.isInlineAsm()) |
| 1038 | return MJ.isInlineAsm() || MJ.isBranch() || MJ.isBarrier() || |
| 1039 | MJ.isCall() || MJ.isTerminator(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1040 | |
Krzysztof Parzyszek | 639545b | 2016-08-19 16:57:05 +0000 | [diff] [blame] | 1041 | switch (MI.getOpcode()) { |
| 1042 | case (Hexagon::S2_storew_locked): |
| 1043 | case (Hexagon::S4_stored_locked): |
| 1044 | case (Hexagon::L2_loadw_locked): |
| 1045 | case (Hexagon::L4_loadd_locked): |
| 1046 | case (Hexagon::Y4_l2fetch): { |
| 1047 | // These instructions can only be grouped with ALU32 or non-floating-point |
| 1048 | // XTYPE instructions. Since there is no convenient way of identifying fp |
| 1049 | // XTYPE instructions, only allow grouping with ALU32 for now. |
| 1050 | unsigned TJ = HII.getType(MJ); |
| 1051 | if (TJ != HexagonII::TypeALU32) |
| 1052 | return true; |
| 1053 | break; |
| 1054 | } |
| 1055 | default: |
| 1056 | break; |
| 1057 | } |
| 1058 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1059 | // "False" really means that the quick check failed to determine if |
| 1060 | // I and J cannot coexist. |
| 1061 | return false; |
| 1062 | } |
| 1063 | |
| 1064 | |
| 1065 | // Full, symmetric check. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1066 | bool HexagonPacketizerList::cannotCoexist(const MachineInstr &MI, |
| 1067 | const MachineInstr &MJ) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1068 | return cannotCoexistAsymm(MI, MJ, *HII) || cannotCoexistAsymm(MJ, MI, *HII); |
| 1069 | } |
| 1070 | |
| 1071 | void HexagonPacketizerList::unpacketizeSoloInstrs(MachineFunction &MF) { |
| 1072 | for (auto &B : MF) { |
| 1073 | MachineBasicBlock::iterator BundleIt; |
| 1074 | MachineBasicBlock::instr_iterator NextI; |
| 1075 | for (auto I = B.instr_begin(), E = B.instr_end(); I != E; I = NextI) { |
| 1076 | NextI = std::next(I); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1077 | MachineInstr &MI = *I; |
| 1078 | if (MI.isBundle()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1079 | BundleIt = I; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1080 | if (!MI.isInsideBundle()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1081 | continue; |
| 1082 | |
| 1083 | // Decide on where to insert the instruction that we are pulling out. |
| 1084 | // Debug instructions always go before the bundle, but the placement of |
| 1085 | // INLINE_ASM depends on potential dependencies. By default, try to |
| 1086 | // put it before the bundle, but if the asm writes to a register that |
| 1087 | // other instructions in the bundle read, then we need to place it |
| 1088 | // after the bundle (to preserve the bundle semantics). |
| 1089 | bool InsertBeforeBundle; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1090 | if (MI.isInlineAsm()) |
| 1091 | InsertBeforeBundle = !hasWriteToReadDep(MI, *BundleIt, HRI); |
| 1092 | else if (MI.isDebugValue()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1093 | InsertBeforeBundle = true; |
| 1094 | else |
| 1095 | continue; |
| 1096 | |
| 1097 | BundleIt = moveInstrOut(MI, BundleIt, InsertBeforeBundle); |
| 1098 | } |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | // Check if a given instruction is of class "system". |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1103 | static bool isSystemInstr(const MachineInstr &MI) { |
| 1104 | unsigned Opc = MI.getOpcode(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1105 | switch (Opc) { |
| 1106 | case Hexagon::Y2_barrier: |
| 1107 | case Hexagon::Y2_dcfetchbo: |
| 1108 | return true; |
| 1109 | } |
| 1110 | return false; |
| 1111 | } |
| 1112 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1113 | bool HexagonPacketizerList::hasDeadDependence(const MachineInstr &I, |
| 1114 | const MachineInstr &J) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1115 | // The dependence graph may not include edges between dead definitions, |
| 1116 | // so without extra checks, we could end up packetizing two instruction |
| 1117 | // defining the same (dead) register. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1118 | if (I.isCall() || J.isCall()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1119 | return false; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1120 | if (HII->isPredicated(I) || HII->isPredicated(J)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1121 | return false; |
| 1122 | |
| 1123 | BitVector DeadDefs(Hexagon::NUM_TARGET_REGS); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1124 | for (auto &MO : I.operands()) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1125 | if (!MO.isReg() || !MO.isDef() || !MO.isDead()) |
| 1126 | continue; |
| 1127 | DeadDefs[MO.getReg()] = true; |
| 1128 | } |
| 1129 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1130 | for (auto &MO : J.operands()) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1131 | if (!MO.isReg() || !MO.isDef() || !MO.isDead()) |
| 1132 | continue; |
| 1133 | unsigned R = MO.getReg(); |
| 1134 | if (R != Hexagon::USR_OVF && DeadDefs[R]) |
| 1135 | return true; |
| 1136 | } |
| 1137 | return false; |
| 1138 | } |
| 1139 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1140 | bool HexagonPacketizerList::hasControlDependence(const MachineInstr &I, |
| 1141 | const MachineInstr &J) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1142 | // A save callee-save register function call can only be in a packet |
| 1143 | // with instructions that don't write to the callee-save registers. |
| 1144 | if ((HII->isSaveCalleeSavedRegsCall(I) && |
| 1145 | doesModifyCalleeSavedReg(J, HRI)) || |
| 1146 | (HII->isSaveCalleeSavedRegsCall(J) && |
| 1147 | doesModifyCalleeSavedReg(I, HRI))) |
| 1148 | return true; |
| 1149 | |
| 1150 | // Two control flow instructions cannot go in the same packet. |
| 1151 | if (isControlFlow(I) && isControlFlow(J)) |
| 1152 | return true; |
| 1153 | |
| 1154 | // \ref-manual (7.3.4) A loop setup packet in loopN or spNloop0 cannot |
| 1155 | // contain a speculative indirect jump, |
| 1156 | // a new-value compare jump or a dealloc_return. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1157 | auto isBadForLoopN = [this] (const MachineInstr &MI) -> bool { |
| 1158 | if (MI.isCall() || HII->isDeallocRet(MI) || HII->isNewValueJump(MI)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1159 | return true; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1160 | if (HII->isPredicated(MI) && HII->isPredicatedNew(MI) && HII->isJumpR(MI)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1161 | return true; |
| 1162 | return false; |
| 1163 | }; |
| 1164 | |
| 1165 | if (HII->isLoopN(I) && isBadForLoopN(J)) |
| 1166 | return true; |
| 1167 | if (HII->isLoopN(J) && isBadForLoopN(I)) |
| 1168 | return true; |
| 1169 | |
| 1170 | // dealloc_return cannot appear in the same packet as a conditional or |
| 1171 | // unconditional jump. |
| 1172 | return HII->isDeallocRet(I) && |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1173 | (J.isBranch() || J.isCall() || J.isBarrier()); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1176 | bool HexagonPacketizerList::hasV4SpecificDependence(const MachineInstr &I, |
| 1177 | const MachineInstr &J) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1178 | bool SysI = isSystemInstr(I), SysJ = isSystemInstr(J); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1179 | bool StoreI = I.mayStore(), StoreJ = J.mayStore(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1180 | if ((SysI && StoreJ) || (SysJ && StoreI)) |
| 1181 | return true; |
| 1182 | |
| 1183 | if (StoreI && StoreJ) { |
| 1184 | if (HII->isNewValueInst(J) || HII->isMemOp(J) || HII->isMemOp(I)) |
| 1185 | return true; |
| 1186 | } else { |
| 1187 | // A memop cannot be in the same packet with another memop or a store. |
| 1188 | // Two stores can be together, but here I and J cannot both be stores. |
| 1189 | bool MopStI = HII->isMemOp(I) || StoreI; |
| 1190 | bool MopStJ = HII->isMemOp(J) || StoreJ; |
| 1191 | if (MopStI && MopStJ) |
| 1192 | return true; |
| 1193 | } |
| 1194 | |
| 1195 | return (StoreJ && HII->isDeallocRet(I)) || (StoreI && HII->isDeallocRet(J)); |
| 1196 | } |
| 1197 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1198 | // SUI is the current instruction that is out side of the current packet. |
| 1199 | // SUJ is the current instruction inside the current packet against which that |
| 1200 | // SUI will be packetized. |
| 1201 | bool HexagonPacketizerList::isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1202 | assert(SUI->getInstr() && SUJ->getInstr()); |
| 1203 | MachineInstr &I = *SUI->getInstr(); |
| 1204 | MachineInstr &J = *SUJ->getInstr(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1205 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1206 | // Clear IgnoreDepMIs when Packet starts. |
| 1207 | if (CurrentPacketMIs.size() == 1) |
| 1208 | IgnoreDepMIs.clear(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1209 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1210 | MachineBasicBlock::iterator II = I.getIterator(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1211 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1212 | // Solo instructions cannot go in the packet. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1213 | assert(!isSoloInstruction(I) && "Unexpected solo instr!"); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1214 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1215 | if (cannotCoexist(I, J)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1216 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1217 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1218 | Dependence = hasDeadDependence(I, J) || hasControlDependence(I, J); |
| 1219 | if (Dependence) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1220 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1221 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1222 | // V4 allows dual stores. It does not allow second store, if the first |
| 1223 | // store is not in SLOT0. New value store, new value jump, dealloc_return |
| 1224 | // and memop always take SLOT0. Arch spec 3.4.4.2. |
| 1225 | Dependence = hasV4SpecificDependence(I, J); |
| 1226 | if (Dependence) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1227 | return false; |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1228 | |
| 1229 | // If an instruction feeds new value jump, glue it. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1230 | MachineBasicBlock::iterator NextMII = I.getIterator(); |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1231 | ++NextMII; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1232 | if (NextMII != I.getParent()->end() && HII->isNewValueJump(*NextMII)) { |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 1233 | MachineInstr &NextMI = *NextMII; |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1234 | |
| 1235 | bool secondRegMatch = false; |
Duncan P. N. Exon Smith | 98226e3 | 2016-07-12 01:55:32 +0000 | [diff] [blame] | 1236 | const MachineOperand &NOp0 = NextMI.getOperand(0); |
| 1237 | const MachineOperand &NOp1 = NextMI.getOperand(1); |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1238 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1239 | if (NOp1.isReg() && I.getOperand(0).getReg() == NOp1.getReg()) |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1240 | secondRegMatch = true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1241 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1242 | for (auto T : CurrentPacketMIs) { |
| 1243 | SUnit *PacketSU = MIToSUnit.find(T)->second; |
| 1244 | MachineInstr &PI = *PacketSU->getInstr(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1245 | // NVJ can not be part of the dual jump - Arch Spec: section 7.8. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1246 | if (PI.isCall()) { |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1247 | Dependence = true; |
| 1248 | break; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1249 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1250 | // Validate: |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1251 | // 1. Packet does not have a store in it. |
| 1252 | // 2. If the first operand of the nvj is newified, and the second |
| 1253 | // operand is also a reg, it (second reg) is not defined in |
| 1254 | // the same packet. |
| 1255 | // 3. If the second operand of the nvj is newified, (which means |
| 1256 | // first operand is also a reg), first reg is not defined in |
| 1257 | // the same packet. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1258 | if (PI.getOpcode() == Hexagon::S2_allocframe || PI.mayStore() || |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1259 | HII->isLoopN(PI)) { |
| 1260 | Dependence = true; |
| 1261 | break; |
| 1262 | } |
| 1263 | // Check #2/#3. |
| 1264 | const MachineOperand &OpR = secondRegMatch ? NOp0 : NOp1; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1265 | if (OpR.isReg() && PI.modifiesRegister(OpR.getReg(), HRI)) { |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1266 | Dependence = true; |
| 1267 | break; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1268 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1269 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1270 | |
| 1271 | if (Dependence) |
Colin LeMahieu | 4fd203d | 2015-02-09 21:56:37 +0000 | [diff] [blame] | 1272 | return false; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1273 | GlueToNewValueJump = true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1276 | // There no dependency between a prolog instruction and its successor. |
| 1277 | if (!SUJ->isSucc(SUI)) |
| 1278 | return true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1279 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1280 | for (unsigned i = 0; i < SUJ->Succs.size(); ++i) { |
| 1281 | if (FoundSequentialDependence) |
| 1282 | break; |
| 1283 | |
| 1284 | if (SUJ->Succs[i].getSUnit() != SUI) |
| 1285 | continue; |
| 1286 | |
| 1287 | SDep::Kind DepType = SUJ->Succs[i].getKind(); |
| 1288 | // For direct calls: |
| 1289 | // Ignore register dependences for call instructions for packetization |
| 1290 | // purposes except for those due to r31 and predicate registers. |
| 1291 | // |
| 1292 | // For indirect calls: |
| 1293 | // Same as direct calls + check for true dependences to the register |
| 1294 | // used in the indirect call. |
| 1295 | // |
| 1296 | // We completely ignore Order dependences for call instructions. |
| 1297 | // |
| 1298 | // For returns: |
| 1299 | // Ignore register dependences for return instructions like jumpr, |
| 1300 | // dealloc return unless we have dependencies on the explicit uses |
| 1301 | // of the registers used by jumpr (like r31) or dealloc return |
| 1302 | // (like r29 or r30). |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1303 | unsigned DepReg = 0; |
| 1304 | const TargetRegisterClass *RC = nullptr; |
| 1305 | if (DepType == SDep::Data) { |
| 1306 | DepReg = SUJ->Succs[i].getReg(); |
| 1307 | RC = HRI->getMinimalPhysRegClass(DepReg); |
| 1308 | } |
| 1309 | |
Krzysztof Parzyszek | 38e2ccc | 2016-08-23 16:01:01 +0000 | [diff] [blame] | 1310 | if (I.isCall() || HII->isJumpR(I) || I.isReturn() || HII->isTailCall(I)) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1311 | if (!isRegDependence(DepType)) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1312 | continue; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1313 | if (!isCallDependent(I, DepType, SUJ->Succs[i].getReg())) |
| 1314 | continue; |
| 1315 | } |
| 1316 | |
| 1317 | if (DepType == SDep::Data) { |
| 1318 | if (canPromoteToDotCur(J, SUJ, DepReg, II, RC)) |
| 1319 | if (promoteToDotCur(J, DepType, II, RC)) |
| 1320 | continue; |
| 1321 | } |
| 1322 | |
| 1323 | // Data dpendence ok if we have load.cur. |
| 1324 | if (DepType == SDep::Data && HII->isDotCurInst(J)) { |
| 1325 | if (HII->isV60VectorInstruction(I)) |
| 1326 | continue; |
| 1327 | } |
| 1328 | |
| 1329 | // For instructions that can be promoted to dot-new, try to promote. |
| 1330 | if (DepType == SDep::Data) { |
| 1331 | if (canPromoteToDotNew(I, SUJ, DepReg, II, RC)) { |
| 1332 | if (promoteToDotNew(I, DepType, II, RC)) { |
| 1333 | PromotedToDotNew = true; |
| 1334 | continue; |
| 1335 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1336 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1337 | if (HII->isNewValueJump(I)) |
| 1338 | continue; |
| 1339 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1340 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1341 | // For predicated instructions, if the predicates are complements then |
| 1342 | // there can be no dependence. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1343 | if (HII->isPredicated(I) && HII->isPredicated(J) && |
| 1344 | arePredicatesComplements(I, J)) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1345 | // Not always safe to do this translation. |
| 1346 | // DAG Builder attempts to reduce dependence edges using transitive |
| 1347 | // nature of dependencies. Here is an example: |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1348 | // |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1349 | // r0 = tfr_pt ... (1) |
| 1350 | // r0 = tfr_pf ... (2) |
| 1351 | // r0 = tfr_pt ... (3) |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1352 | // |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1353 | // There will be an output dependence between (1)->(2) and (2)->(3). |
| 1354 | // However, there is no dependence edge between (1)->(3). This results |
| 1355 | // in all 3 instructions going in the same packet. We ignore dependce |
| 1356 | // only once to avoid this situation. |
David Majnemer | 0d955d0 | 2016-08-11 22:21:41 +0000 | [diff] [blame] | 1357 | auto Itr = find(IgnoreDepMIs, &J); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1358 | if (Itr != IgnoreDepMIs.end()) { |
| 1359 | Dependence = true; |
| 1360 | return false; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1361 | } |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1362 | IgnoreDepMIs.push_back(&I); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1363 | continue; |
| 1364 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1365 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1366 | // Ignore Order dependences between unconditional direct branches |
| 1367 | // and non-control-flow instructions. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1368 | if (isDirectJump(I) && !J.isBranch() && !J.isCall() && |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1369 | DepType == SDep::Order) |
| 1370 | continue; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1371 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1372 | // Ignore all dependences for jumps except for true and output |
| 1373 | // dependences. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1374 | if (I.isConditionalBranch() && DepType != SDep::Data && |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1375 | DepType != SDep::Output) |
| 1376 | continue; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1377 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1378 | // Ignore output dependences due to superregs. We can write to two |
| 1379 | // different subregisters of R1:0 for instance in the same cycle. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1380 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1381 | // If neither I nor J defines DepReg, then this is a superfluous output |
| 1382 | // dependence. The dependence must be of the form: |
| 1383 | // R0 = ... |
| 1384 | // R1 = ... |
| 1385 | // and there is an output dependence between the two instructions with |
| 1386 | // DepReg = D0. |
| 1387 | // We want to ignore these dependences. Ideally, the dependence |
| 1388 | // constructor should annotate such dependences. We can then avoid this |
| 1389 | // relatively expensive check. |
| 1390 | // |
| 1391 | if (DepType == SDep::Output) { |
| 1392 | // DepReg is the register that's responsible for the dependence. |
| 1393 | unsigned DepReg = SUJ->Succs[i].getReg(); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1394 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1395 | // Check if I and J really defines DepReg. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1396 | if (!I.definesRegister(DepReg) && !J.definesRegister(DepReg)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1397 | continue; |
| 1398 | FoundSequentialDependence = true; |
| 1399 | break; |
| 1400 | } |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1401 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1402 | // For Order dependences: |
| 1403 | // 1. On V4 or later, volatile loads/stores can be packetized together, |
| 1404 | // unless other rules prevent is. |
| 1405 | // 2. Store followed by a load is not allowed. |
| 1406 | // 3. Store followed by a store is only valid on V4 or later. |
| 1407 | // 4. Load followed by any memory operation is allowed. |
| 1408 | if (DepType == SDep::Order) { |
| 1409 | if (!PacketizeVolatiles) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1410 | bool OrdRefs = I.hasOrderedMemoryRef() || J.hasOrderedMemoryRef(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1411 | if (OrdRefs) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1412 | FoundSequentialDependence = true; |
| 1413 | break; |
| 1414 | } |
| 1415 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1416 | // J is first, I is second. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1417 | bool LoadJ = J.mayLoad(), StoreJ = J.mayStore(); |
| 1418 | bool LoadI = I.mayLoad(), StoreI = I.mayStore(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1419 | if (StoreJ) { |
| 1420 | // Two stores are only allowed on V4+. Load following store is never |
| 1421 | // allowed. |
| 1422 | if (LoadI) { |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1423 | FoundSequentialDependence = true; |
| 1424 | break; |
| 1425 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1426 | } else if (!LoadJ || (!LoadI && !StoreI)) { |
| 1427 | // If J is neither load nor store, assume a dependency. |
| 1428 | // If J is a load, but I is neither, also assume a dependency. |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1429 | FoundSequentialDependence = true; |
| 1430 | break; |
| 1431 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1432 | // Store followed by store: not OK on V2. |
| 1433 | // Store followed by load: not OK on all. |
| 1434 | // Load followed by store: OK on all. |
| 1435 | // Load followed by load: OK on all. |
| 1436 | continue; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1439 | // For V4, special case ALLOCFRAME. Even though there is dependency |
| 1440 | // between ALLOCFRAME and subsequent store, allow it to be packetized |
| 1441 | // in a same packet. This implies that the store is using the caller's |
| 1442 | // SP. Hence, offset needs to be updated accordingly. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1443 | if (DepType == SDep::Data && J.getOpcode() == Hexagon::S2_allocframe) { |
| 1444 | unsigned Opc = I.getOpcode(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1445 | switch (Opc) { |
| 1446 | case Hexagon::S2_storerd_io: |
| 1447 | case Hexagon::S2_storeri_io: |
| 1448 | case Hexagon::S2_storerh_io: |
| 1449 | case Hexagon::S2_storerb_io: |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1450 | if (I.getOperand(0).getReg() == HRI->getStackRegister()) { |
Krzysztof Parzyszek | 3b4682f | 2016-07-26 14:24:46 +0000 | [diff] [blame] | 1451 | // Since this store is to be glued with allocframe in the same |
| 1452 | // packet, it will use SP of the previous stack frame, i.e. |
| 1453 | // caller's SP. Therefore, we need to recalculate offset |
| 1454 | // according to this change. |
| 1455 | GlueAllocframeStore = useCallersSP(I); |
| 1456 | if (GlueAllocframeStore) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1457 | continue; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1458 | } |
| 1459 | default: |
| 1460 | break; |
| 1461 | } |
| 1462 | } |
| 1463 | |
Krzysztof Parzyszek | adb7ff0 | 2016-05-06 19:13:38 +0000 | [diff] [blame] | 1464 | // There are certain anti-dependencies that cannot be ignored. |
| 1465 | // Specifically: |
| 1466 | // J2_call ... %R0<imp-def> ; SUJ |
| 1467 | // R0 = ... ; SUI |
| 1468 | // Those cannot be packetized together, since the call will observe |
| 1469 | // the effect of the assignment to R0. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1470 | if (DepType == SDep::Anti && J.isCall()) { |
Krzysztof Parzyszek | adb7ff0 | 2016-05-06 19:13:38 +0000 | [diff] [blame] | 1471 | // Check if I defines any volatile register. We should also check |
| 1472 | // registers that the call may read, but these happen to be a |
| 1473 | // subset of the volatile register set. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1474 | for (const MCPhysReg *P = J.getDesc().ImplicitDefs; P && *P; ++P) { |
| 1475 | if (!I.modifiesRegister(*P, HRI)) |
Krzysztof Parzyszek | adb7ff0 | 2016-05-06 19:13:38 +0000 | [diff] [blame] | 1476 | continue; |
| 1477 | FoundSequentialDependence = true; |
| 1478 | break; |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | // Skip over remaining anti-dependences. Two instructions that are |
| 1483 | // anti-dependent can share a packet, since in most such cases all |
| 1484 | // operands are read before any modifications take place. |
| 1485 | // The exceptions are branch and call instructions, since they are |
| 1486 | // executed after all other instructions have completed (at least |
| 1487 | // conceptually). |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1488 | if (DepType != SDep::Anti) { |
| 1489 | FoundSequentialDependence = true; |
| 1490 | break; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1494 | if (FoundSequentialDependence) { |
| 1495 | Dependence = true; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1496 | return false; |
| 1497 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1498 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1499 | return true; |
| 1500 | } |
| 1501 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1502 | bool HexagonPacketizerList::isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1503 | assert(SUI->getInstr() && SUJ->getInstr()); |
| 1504 | MachineInstr &I = *SUI->getInstr(); |
| 1505 | MachineInstr &J = *SUJ->getInstr(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1506 | |
| 1507 | if (cannotCoexist(I, J)) |
| 1508 | return false; |
| 1509 | |
| 1510 | if (!Dependence) |
| 1511 | return true; |
| 1512 | |
| 1513 | // Check if the instruction was promoted to a dot-new. If so, demote it |
| 1514 | // back into a dot-old. |
| 1515 | if (PromotedToDotNew) |
| 1516 | demoteToDotOld(I); |
| 1517 | |
| 1518 | cleanUpDotCur(); |
| 1519 | // Check if the instruction (must be a store) was glued with an allocframe |
| 1520 | // instruction. If so, restore its offset to its original value, i.e. use |
| 1521 | // current SP instead of caller's SP. |
| 1522 | if (GlueAllocframeStore) { |
Krzysztof Parzyszek | 3b4682f | 2016-07-26 14:24:46 +0000 | [diff] [blame] | 1523 | useCalleesSP(I); |
| 1524 | GlueAllocframeStore = false; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1525 | } |
| 1526 | return false; |
| 1527 | } |
| 1528 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1529 | MachineBasicBlock::iterator |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1530 | HexagonPacketizerList::addToPacket(MachineInstr &MI) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1531 | MachineBasicBlock::iterator MII = MI.getIterator(); |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1532 | MachineBasicBlock *MBB = MI.getParent(); |
| 1533 | if (MI.isImplicitDef()) { |
| 1534 | unsigned R = MI.getOperand(0).getReg(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1535 | if (Hexagon::IntRegsRegClass.contains(R)) { |
| 1536 | MCSuperRegIterator S(R, HRI, false); |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1537 | MI.addOperand(MachineOperand::CreateReg(*S, true, true)); |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1538 | } |
| 1539 | return MII; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1540 | } |
| 1541 | assert(ResourceTracker->canReserveResources(MI)); |
| 1542 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1543 | bool ExtMI = HII->isExtended(MI) || HII->isConstExtended(MI); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1544 | bool Good = true; |
| 1545 | |
| 1546 | if (GlueToNewValueJump) { |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1547 | MachineInstr &NvjMI = *++MII; |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1548 | // We need to put both instructions in the same packet: MI and NvjMI. |
| 1549 | // Either of them can require a constant extender. Try to add both to |
| 1550 | // the current packet, and if that fails, end the packet and start a |
| 1551 | // new one. |
| 1552 | ResourceTracker->reserveResources(MI); |
| 1553 | if (ExtMI) |
| 1554 | Good = tryAllocateResourcesForConstExt(true); |
| 1555 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1556 | bool ExtNvjMI = HII->isExtended(NvjMI) || HII->isConstExtended(NvjMI); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1557 | if (Good) { |
| 1558 | if (ResourceTracker->canReserveResources(NvjMI)) |
| 1559 | ResourceTracker->reserveResources(NvjMI); |
| 1560 | else |
| 1561 | Good = false; |
| 1562 | } |
| 1563 | if (Good && ExtNvjMI) |
| 1564 | Good = tryAllocateResourcesForConstExt(true); |
| 1565 | |
| 1566 | if (!Good) { |
| 1567 | endPacket(MBB, MI); |
| 1568 | assert(ResourceTracker->canReserveResources(MI)); |
| 1569 | ResourceTracker->reserveResources(MI); |
| 1570 | if (ExtMI) { |
| 1571 | assert(canReserveResourcesForConstExt()); |
| 1572 | tryAllocateResourcesForConstExt(true); |
| 1573 | } |
| 1574 | assert(ResourceTracker->canReserveResources(NvjMI)); |
| 1575 | ResourceTracker->reserveResources(NvjMI); |
| 1576 | if (ExtNvjMI) { |
| 1577 | assert(canReserveResourcesForConstExt()); |
| 1578 | reserveResourcesForConstExt(); |
| 1579 | } |
| 1580 | } |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1581 | CurrentPacketMIs.push_back(&MI); |
| 1582 | CurrentPacketMIs.push_back(&NvjMI); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1583 | return MII; |
| 1584 | } |
| 1585 | |
| 1586 | ResourceTracker->reserveResources(MI); |
| 1587 | if (ExtMI && !tryAllocateResourcesForConstExt(true)) { |
| 1588 | endPacket(MBB, MI); |
| 1589 | if (PromotedToDotNew) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1590 | demoteToDotOld(MI); |
Krzysztof Parzyszek | 3b4682f | 2016-07-26 14:24:46 +0000 | [diff] [blame] | 1591 | if (GlueAllocframeStore) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1592 | useCalleesSP(MI); |
Krzysztof Parzyszek | 3b4682f | 2016-07-26 14:24:46 +0000 | [diff] [blame] | 1593 | GlueAllocframeStore = false; |
| 1594 | } |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1595 | ResourceTracker->reserveResources(MI); |
| 1596 | reserveResourcesForConstExt(); |
| 1597 | } |
| 1598 | |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1599 | CurrentPacketMIs.push_back(&MI); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1600 | return MII; |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1603 | void HexagonPacketizerList::endPacket(MachineBasicBlock *MBB, |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1604 | MachineBasicBlock::iterator MI) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1605 | OldPacketMIs = CurrentPacketMIs; |
| 1606 | VLIWPacketizerList::endPacket(MBB, MI); |
| 1607 | } |
| 1608 | |
Duncan P. N. Exon Smith | 5702287 | 2016-02-27 19:09:00 +0000 | [diff] [blame] | 1609 | bool HexagonPacketizerList::shouldAddToPacket(const MachineInstr &MI) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1610 | return !producesStall(MI); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | |
| 1614 | // Return true when ConsMI uses a register defined by ProdMI. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1615 | static bool isDependent(const MachineInstr &ProdMI, |
| 1616 | const MachineInstr &ConsMI) { |
| 1617 | if (!ProdMI.getOperand(0).isReg()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1618 | return false; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1619 | unsigned DstReg = ProdMI.getOperand(0).getReg(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1620 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1621 | for (auto &Op : ConsMI.operands()) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1622 | if (Op.isReg() && Op.isUse() && Op.getReg() == DstReg) |
| 1623 | // The MIs depend on each other. |
| 1624 | return true; |
| 1625 | |
| 1626 | return false; |
| 1627 | } |
| 1628 | |
| 1629 | // V60 forward scheduling. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1630 | bool HexagonPacketizerList::producesStall(const MachineInstr &I) { |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1631 | // Check whether the previous packet is in a different loop. If this is the |
| 1632 | // case, there is little point in trying to avoid a stall because that would |
| 1633 | // favor the rare case (loop entry) over the common case (loop iteration). |
| 1634 | // |
| 1635 | // TODO: We should really be able to check all the incoming edges if this is |
| 1636 | // the first packet in a basic block, so we can avoid stalls from the loop |
| 1637 | // backedge. |
| 1638 | if (!OldPacketMIs.empty()) { |
| 1639 | auto *OldBB = OldPacketMIs.front()->getParent(); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1640 | auto *ThisBB = I.getParent(); |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1641 | if (MLI->getLoopFor(OldBB) != MLI->getLoopFor(ThisBB)) |
| 1642 | return false; |
| 1643 | } |
| 1644 | |
| 1645 | // Check for stall between two vector instructions. |
| 1646 | if (HII->isV60VectorInstruction(I)) { |
| 1647 | for (auto J : OldPacketMIs) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1648 | if (!HII->isV60VectorInstruction(*J)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1649 | continue; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1650 | if (isDependent(*J, I) && !HII->isVecUsableNextPacket(*J, I)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1651 | return true; |
| 1652 | } |
| 1653 | return false; |
| 1654 | } |
| 1655 | |
| 1656 | // Check for stall between two scalar instructions. First, check that |
| 1657 | // there is no definition of a use in the current packet, because it |
| 1658 | // may be a candidate for .new. |
| 1659 | for (auto J : CurrentPacketMIs) |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1660 | if (!HII->isV60VectorInstruction(*J) && isDependent(*J, I)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1661 | return false; |
| 1662 | |
| 1663 | // Check for stall between I and instructions in the previous packet. |
| 1664 | if (MF.getSubtarget<HexagonSubtarget>().useBSBScheduling()) { |
| 1665 | for (auto J : OldPacketMIs) { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1666 | if (HII->isV60VectorInstruction(*J)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1667 | continue; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1668 | if (!HII->isLateInstrFeedsEarlyInstr(*J, I)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1669 | continue; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 1670 | if (isDependent(*J, I) && !HII->canExecuteInBundle(*J, I)) |
Krzysztof Parzyszek | 56bbf54 | 2015-12-16 19:36:12 +0000 | [diff] [blame] | 1671 | return true; |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | return false; |
| 1676 | } |
| 1677 | |
| 1678 | |
Sirish Pande | f8e5e3c | 2012-05-03 21:52:53 +0000 | [diff] [blame] | 1679 | //===----------------------------------------------------------------------===// |
| 1680 | // Public Constructor Functions |
| 1681 | //===----------------------------------------------------------------------===// |
| 1682 | |
| 1683 | FunctionPass *llvm::createHexagonPacketizer() { |
| 1684 | return new HexagonPacketizer(); |
| 1685 | } |