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