Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame^] | 1 | //===- HexagonSubtarget.cpp - Hexagon Subtarget Information ---------------===// |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +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 file implements the Hexagon specific subclass of TargetSubtarget. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 14 | #include "Hexagon.h" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame^] | 15 | #include "HexagonInstrInfo.h" |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 16 | #include "HexagonRegisterInfo.h" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame^] | 17 | #include "HexagonSubtarget.h" |
| 18 | #include "llvm/ADT/STLExtras.h" |
| 19 | #include "llvm/ADT/SmallSet.h" |
| 20 | #include "llvm/ADT/SmallVector.h" |
| 21 | #include "llvm/ADT/StringRef.h" |
| 22 | #include "MCTargetDesc/HexagonMCTargetDesc.h" |
| 23 | #include "llvm/CodeGen/MachineInstr.h" |
| 24 | #include "llvm/CodeGen/MachineOperand.h" |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/ScheduleDAG.h" |
| 26 | #include "llvm/CodeGen/ScheduleDAGInstrs.h" |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 27 | #include "llvm/Support/CommandLine.h" |
| 28 | #include "llvm/Support/ErrorHandling.h" |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame^] | 29 | #include <algorithm> |
| 30 | #include <cassert> |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 31 | #include <map> |
| 32 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 33 | using namespace llvm; |
| 34 | |
Chandler Carruth | e96dd89 | 2014-04-21 22:55:11 +0000 | [diff] [blame] | 35 | #define DEBUG_TYPE "hexagon-subtarget" |
| 36 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 37 | #define GET_SUBTARGETINFO_CTOR |
| 38 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 39 | #include "HexagonGenSubtargetInfo.inc" |
| 40 | |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 41 | static cl::opt<bool> EnableMemOps("enable-hexagon-memops", |
| 42 | cl::Hidden, cl::ZeroOrMore, cl::ValueDisallowed, cl::init(true), |
| 43 | cl::desc("Generate V4 MEMOP in code generation for Hexagon target")); |
Jyotsna Verma | fdc660b | 2013-03-22 18:41:34 +0000 | [diff] [blame] | 44 | |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 45 | static cl::opt<bool> DisableMemOps("disable-hexagon-memops", |
| 46 | cl::Hidden, cl::ZeroOrMore, cl::ValueDisallowed, cl::init(false), |
| 47 | cl::desc("Do not generate V4 MEMOP in code generation for Hexagon target")); |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 48 | |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 49 | static cl::opt<bool> EnableIEEERndNear("enable-hexagon-ieee-rnd-near", |
| 50 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 51 | cl::desc("Generate non-chopped conversion from fp to int.")); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 52 | |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 53 | static cl::opt<bool> EnableBSBSched("enable-bsb-sched", |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 54 | cl::Hidden, cl::ZeroOrMore, cl::init(true)); |
| 55 | |
| 56 | static cl::opt<bool> EnableHexagonHVXDouble("enable-hexagon-hvx-double", |
| 57 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 58 | cl::desc("Enable Hexagon Double Vector eXtensions")); |
| 59 | |
| 60 | static cl::opt<bool> EnableHexagonHVX("enable-hexagon-hvx", |
| 61 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 62 | cl::desc("Enable Hexagon Vector eXtensions")); |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 63 | |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 64 | static cl::opt<bool> EnableTCLatencySched("enable-tc-latency-sched", |
| 65 | cl::Hidden, cl::ZeroOrMore, cl::init(false)); |
| 66 | |
| 67 | static cl::opt<bool> EnableDotCurSched("enable-cur-sched", |
| 68 | cl::Hidden, cl::ZeroOrMore, cl::init(true), |
| 69 | cl::desc("Enable the scheduler to generate .cur")); |
| 70 | |
| 71 | static cl::opt<bool> EnableVecFrwdSched("enable-evec-frwd-sched", |
| 72 | cl::Hidden, cl::ZeroOrMore, cl::init(true)); |
| 73 | |
Eric Christopher | 5f141b0 | 2015-03-11 22:56:10 +0000 | [diff] [blame] | 74 | static cl::opt<bool> DisableHexagonMISched("disable-hexagon-misched", |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 75 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 76 | cl::desc("Disable Hexagon MI Scheduling")); |
| 77 | |
Krzysztof Parzyszek | 07d7518 | 2016-05-28 02:02:51 +0000 | [diff] [blame] | 78 | static cl::opt<bool> EnableSubregLiveness("hexagon-subreg-liveness", |
Krzysztof Parzyszek | b5ec487 | 2016-08-24 17:17:39 +0000 | [diff] [blame] | 79 | cl::Hidden, cl::ZeroOrMore, cl::init(true), |
Krzysztof Parzyszek | 07d7518 | 2016-05-28 02:02:51 +0000 | [diff] [blame] | 80 | cl::desc("Enable subregister liveness tracking for Hexagon")); |
| 81 | |
Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 82 | static cl::opt<bool> OverrideLongCalls("hexagon-long-calls", |
| 83 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 84 | cl::desc("If present, forces/disables the use of long calls")); |
| 85 | |
Krzysztof Parzyszek | ee93e00 | 2017-05-05 22:13:57 +0000 | [diff] [blame] | 86 | static cl::opt<bool> EnablePredicatedCalls("hexagon-pred-calls", |
| 87 | cl::Hidden, cl::ZeroOrMore, cl::init(false), |
| 88 | cl::desc("Consider calls to be predicable")); |
| 89 | |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 90 | void HexagonSubtarget::initializeEnvironment() { |
| 91 | UseMemOps = false; |
| 92 | ModeIEEERndNear = false; |
| 93 | UseBSBScheduling = false; |
| 94 | } |
Eric Christopher | 5f141b0 | 2015-03-11 22:56:10 +0000 | [diff] [blame] | 95 | |
Eric Christopher | c4c63ae | 2014-06-27 00:27:40 +0000 | [diff] [blame] | 96 | HexagonSubtarget & |
| 97 | HexagonSubtarget::initializeSubtargetDependencies(StringRef CPU, StringRef FS) { |
Krzysztof Parzyszek | 75e74ee | 2016-08-19 14:09:47 +0000 | [diff] [blame] | 98 | CPUString = Hexagon_MC::selectHexagonCPU(getTargetTriple(), CPU); |
Sebastian Pop | 1a0bef6 | 2012-08-20 19:56:47 +0000 | [diff] [blame] | 99 | |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 100 | static std::map<StringRef, HexagonArchEnum> CpuTable { |
| 101 | { "hexagonv4", V4 }, |
| 102 | { "hexagonv5", V5 }, |
| 103 | { "hexagonv55", V55 }, |
| 104 | { "hexagonv60", V60 }, |
Krzysztof Parzyszek | f9015e6 | 2017-02-10 23:46:45 +0000 | [diff] [blame] | 105 | { "hexagonv62", V62 }, |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | auto foundIt = CpuTable.find(CPUString); |
| 109 | if (foundIt != CpuTable.end()) |
| 110 | HexagonArchVersion = foundIt->second; |
| 111 | else |
Sebastian Pop | 1a0bef6 | 2012-08-20 19:56:47 +0000 | [diff] [blame] | 112 | llvm_unreachable("Unrecognized Hexagon processor version"); |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 113 | |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 114 | UseHVXOps = false; |
| 115 | UseHVXDblOps = false; |
Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 116 | UseLongCalls = false; |
Sebastian Pop | 1a0bef6 | 2012-08-20 19:56:47 +0000 | [diff] [blame] | 117 | ParseSubtargetFeatures(CPUString, FS); |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 118 | |
| 119 | if (EnableHexagonHVX.getPosition()) |
| 120 | UseHVXOps = EnableHexagonHVX; |
| 121 | if (EnableHexagonHVXDouble.getPosition()) |
| 122 | UseHVXDblOps = EnableHexagonHVXDouble; |
Krzysztof Parzyszek | 080bebd | 2016-07-25 14:42:11 +0000 | [diff] [blame] | 123 | if (OverrideLongCalls.getPosition()) |
| 124 | UseLongCalls = OverrideLongCalls; |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 125 | |
Eric Christopher | c4c63ae | 2014-06-27 00:27:40 +0000 | [diff] [blame] | 126 | return *this; |
| 127 | } |
| 128 | |
Daniel Sanders | a73f1fd | 2015-06-10 12:11:26 +0000 | [diff] [blame] | 129 | HexagonSubtarget::HexagonSubtarget(const Triple &TT, StringRef CPU, |
| 130 | StringRef FS, const TargetMachine &TM) |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 131 | : HexagonGenSubtargetInfo(TT, CPU, FS), CPUString(CPU), |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame^] | 132 | InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this) { |
Krzysztof Parzyszek | 207c13f | 2015-11-25 20:30:59 +0000 | [diff] [blame] | 133 | initializeEnvironment(); |
| 134 | |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 135 | // Initialize scheduling itinerary for the specified CPU. |
| 136 | InstrItins = getInstrItineraryForCPU(CPUString); |
| 137 | |
Jyotsna Verma | fdc660b | 2013-03-22 18:41:34 +0000 | [diff] [blame] | 138 | // UseMemOps on by default unless disabled explicitly |
| 139 | if (DisableMemOps) |
| 140 | UseMemOps = false; |
| 141 | else if (EnableMemOps) |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 142 | UseMemOps = true; |
| 143 | else |
| 144 | UseMemOps = false; |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 145 | |
| 146 | if (EnableIEEERndNear) |
| 147 | ModeIEEERndNear = true; |
| 148 | else |
| 149 | ModeIEEERndNear = false; |
Krzysztof Parzyszek | b9a1c3a | 2015-11-24 14:55:26 +0000 | [diff] [blame] | 150 | |
| 151 | UseBSBScheduling = hasV60TOps() && EnableBSBSched; |
Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 152 | } |
Sirish Pande | 69295b8 | 2012-05-10 20:20:25 +0000 | [diff] [blame] | 153 | |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 154 | /// \brief Perform target specific adjustments to the latency of a schedule |
| 155 | /// dependency. |
| 156 | void HexagonSubtarget::adjustSchedDependency(SUnit *Src, SUnit *Dst, |
| 157 | SDep &Dep) const { |
| 158 | MachineInstr *SrcInst = Src->getInstr(); |
| 159 | MachineInstr *DstInst = Dst->getInstr(); |
| 160 | if (!Src->isInstr() || !Dst->isInstr()) |
| 161 | return; |
| 162 | |
| 163 | const HexagonInstrInfo *QII = getInstrInfo(); |
| 164 | |
| 165 | // Instructions with .new operands have zero latency. |
| 166 | SmallSet<SUnit *, 4> ExclSrc; |
| 167 | SmallSet<SUnit *, 4> ExclDst; |
| 168 | if (QII->canExecuteInBundle(*SrcInst, *DstInst) && |
| 169 | isBestZeroLatency(Src, Dst, QII, ExclSrc, ExclDst)) { |
| 170 | Dep.setLatency(0); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | if (!hasV60TOps()) |
| 175 | return; |
| 176 | |
| 177 | // If it's a REG_SEQUENCE, use its destination instruction to determine |
| 178 | // the correct latency. |
| 179 | if (DstInst->isRegSequence() && Dst->NumSuccs == 1) { |
| 180 | unsigned RSeqReg = DstInst->getOperand(0).getReg(); |
| 181 | MachineInstr *RSeqDst = Dst->Succs[0].getSUnit()->getInstr(); |
| 182 | unsigned UseIdx = -1; |
| 183 | for (unsigned OpNum = 0; OpNum < RSeqDst->getNumOperands(); OpNum++) { |
| 184 | const MachineOperand &MO = RSeqDst->getOperand(OpNum); |
| 185 | if (MO.isReg() && MO.getReg() && MO.isUse() && MO.getReg() == RSeqReg) { |
| 186 | UseIdx = OpNum; |
| 187 | break; |
| 188 | } |
| 189 | } |
| 190 | unsigned RSeqLatency = (InstrInfo.getOperandLatency(&InstrItins, *SrcInst, |
| 191 | 0, *RSeqDst, UseIdx)); |
| 192 | Dep.setLatency(RSeqLatency); |
| 193 | } |
| 194 | |
| 195 | // Try to schedule uses near definitions to generate .cur. |
| 196 | ExclSrc.clear(); |
| 197 | ExclDst.clear(); |
| 198 | if (EnableDotCurSched && QII->isToBeScheduledASAP(*SrcInst, *DstInst) && |
| 199 | isBestZeroLatency(Src, Dst, QII, ExclSrc, ExclDst)) { |
| 200 | Dep.setLatency(0); |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | updateLatency(*SrcInst, *DstInst, Dep); |
| 205 | } |
| 206 | |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 207 | void HexagonSubtarget::HexagonDAGMutation::apply(ScheduleDAGInstrs *DAG) { |
| 208 | for (auto &SU : DAG->SUnits) { |
| 209 | if (!SU.isInstr()) |
| 210 | continue; |
| 211 | SmallVector<SDep, 4> Erase; |
| 212 | for (auto &D : SU.Preds) |
| 213 | if (D.getKind() == SDep::Output && D.getReg() == Hexagon::USR_OVF) |
| 214 | Erase.push_back(D); |
| 215 | for (auto &E : Erase) |
| 216 | SU.removePred(E); |
| 217 | } |
| 218 | |
| 219 | for (auto &SU : DAG->SUnits) { |
| 220 | // Update the latency of chain edges between v60 vector load or store |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 221 | // instructions to be 1. These instruction cannot be scheduled in the |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 222 | // same packet. |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 223 | MachineInstr &MI1 = *SU.getInstr(); |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 224 | auto *QII = static_cast<const HexagonInstrInfo*>(DAG->TII); |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 225 | bool IsStoreMI1 = MI1.mayStore(); |
| 226 | bool IsLoadMI1 = MI1.mayLoad(); |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 227 | if (!QII->isHVXVec(MI1) || !(IsStoreMI1 || IsLoadMI1)) |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 228 | continue; |
| 229 | for (auto &SI : SU.Succs) { |
| 230 | if (SI.getKind() != SDep::Order || SI.getLatency() != 0) |
| 231 | continue; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 232 | MachineInstr &MI2 = *SI.getSUnit()->getInstr(); |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 233 | if (!QII->isHVXVec(MI2)) |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 234 | continue; |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 235 | if ((IsStoreMI1 && MI2.mayStore()) || (IsLoadMI1 && MI2.mayLoad())) { |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 236 | SI.setLatency(1); |
| 237 | SU.setHeightDirty(); |
| 238 | // Change the dependence in the opposite direction too. |
| 239 | for (auto &PI : SI.getSUnit()->Preds) { |
| 240 | if (PI.getSUnit() != &SU || PI.getKind() != SDep::Order) |
| 241 | continue; |
| 242 | PI.setLatency(1); |
| 243 | SI.getSUnit()->setDepthDirty(); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 250 | void HexagonSubtarget::getPostRAMutations( |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame^] | 251 | std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const { |
| 252 | Mutations.push_back( |
| 253 | llvm::make_unique<HexagonSubtarget::HexagonDAGMutation>()); |
Krzysztof Parzyszek | 9be6673 | 2016-07-15 17:48:09 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Krzysztof Parzyszek | 3885d87 | 2016-12-22 19:44:55 +0000 | [diff] [blame] | 256 | void HexagonSubtarget::getSMSMutations( |
Eugene Zelenko | 8361b0a | 2017-06-19 22:43:19 +0000 | [diff] [blame^] | 257 | std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const { |
| 258 | Mutations.push_back( |
| 259 | llvm::make_unique<HexagonSubtarget::HexagonDAGMutation>()); |
Krzysztof Parzyszek | 3885d87 | 2016-12-22 19:44:55 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 262 | // Pin the vtable to this file. |
| 263 | void HexagonSubtarget::anchor() {} |
Eric Christopher | 5f141b0 | 2015-03-11 22:56:10 +0000 | [diff] [blame] | 264 | |
| 265 | bool HexagonSubtarget::enableMachineScheduler() const { |
| 266 | if (DisableHexagonMISched.getNumOccurrences()) |
| 267 | return !DisableHexagonMISched; |
| 268 | return true; |
| 269 | } |
Krzysztof Parzyszek | 07d7518 | 2016-05-28 02:02:51 +0000 | [diff] [blame] | 270 | |
Krzysztof Parzyszek | ee93e00 | 2017-05-05 22:13:57 +0000 | [diff] [blame] | 271 | bool HexagonSubtarget::usePredicatedCalls() const { |
| 272 | return EnablePredicatedCalls; |
| 273 | } |
| 274 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 275 | void HexagonSubtarget::updateLatency(MachineInstr &SrcInst, |
| 276 | MachineInstr &DstInst, SDep &Dep) const { |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 277 | if (Dep.isArtificial()) { |
| 278 | Dep.setLatency(1); |
| 279 | return; |
| 280 | } |
| 281 | |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 282 | if (!hasV60TOps()) |
| 283 | return; |
| 284 | |
| 285 | auto &QII = static_cast<const HexagonInstrInfo&>(*getInstrInfo()); |
| 286 | |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 287 | // BSB scheduling. |
| 288 | if (QII.isHVXVec(SrcInst) || useBSBScheduling()) |
| 289 | Dep.setLatency((Dep.getLatency() + 1) >> 1); |
| 290 | } |
| 291 | |
| 292 | void HexagonSubtarget::restoreLatency(SUnit *Src, SUnit *Dst) const { |
| 293 | MachineInstr *SrcI = Src->getInstr(); |
| 294 | for (auto &I : Src->Succs) { |
| 295 | if (!I.isAssignedRegDep() || I.getSUnit() != Dst) |
| 296 | continue; |
| 297 | unsigned DepR = I.getReg(); |
| 298 | int DefIdx = -1; |
| 299 | for (unsigned OpNum = 0; OpNum < SrcI->getNumOperands(); OpNum++) { |
| 300 | const MachineOperand &MO = SrcI->getOperand(OpNum); |
| 301 | if (MO.isReg() && MO.isDef() && MO.getReg() == DepR) |
| 302 | DefIdx = OpNum; |
| 303 | } |
| 304 | assert(DefIdx >= 0 && "Def Reg not found in Src MI"); |
| 305 | MachineInstr *DstI = Dst->getInstr(); |
| 306 | for (unsigned OpNum = 0; OpNum < DstI->getNumOperands(); OpNum++) { |
| 307 | const MachineOperand &MO = DstI->getOperand(OpNum); |
| 308 | if (MO.isReg() && MO.isUse() && MO.getReg() == DepR) { |
| 309 | int Latency = (InstrInfo.getOperandLatency(&InstrItins, *SrcI, |
| 310 | DefIdx, *DstI, OpNum)); |
| 311 | |
| 312 | // For some instructions (ex: COPY), we might end up with < 0 latency |
| 313 | // as they don't have any Itinerary class associated with them. |
| 314 | if (Latency <= 0) |
| 315 | Latency = 1; |
| 316 | |
| 317 | I.setLatency(Latency); |
| 318 | updateLatency(*SrcI, *DstI, I); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // Update the latency of opposite edge too. |
| 323 | for (auto &J : Dst->Preds) { |
| 324 | if (J.getSUnit() != Src) |
| 325 | continue; |
| 326 | J.setLatency(I.getLatency()); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /// Change the latency between the two SUnits. |
| 332 | void HexagonSubtarget::changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat) |
| 333 | const { |
| 334 | for (auto &I : Src->Succs) { |
| 335 | if (I.getSUnit() != Dst) |
| 336 | continue; |
| 337 | SDep T = I; |
| 338 | I.setLatency(Lat); |
| 339 | |
| 340 | // Update the latency of opposite edge too. |
| 341 | T.setSUnit(Src); |
| 342 | auto F = std::find(Dst->Preds.begin(), Dst->Preds.end(), T); |
| 343 | assert(F != Dst->Preds.end()); |
| 344 | F->setLatency(I.getLatency()); |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
Krzysztof Parzyszek | 748d3ef | 2016-07-18 14:23:10 +0000 | [diff] [blame] | 348 | /// If the SUnit has a zero latency edge, return the other SUnit. |
| 349 | static SUnit *getZeroLatency(SUnit *N, SmallVector<SDep, 4> &Deps) { |
| 350 | for (auto &I : Deps) |
| 351 | if (I.isAssignedRegDep() && I.getLatency() == 0 && |
| 352 | !I.getSUnit()->getInstr()->isPseudo()) |
| 353 | return I.getSUnit(); |
| 354 | return nullptr; |
| 355 | } |
| 356 | |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 357 | // Return true if these are the best two instructions to schedule |
| 358 | // together with a zero latency. Only one dependence should have a zero |
| 359 | // latency. If there are multiple choices, choose the best, and change |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 360 | // the others, if needed. |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 361 | bool HexagonSubtarget::isBestZeroLatency(SUnit *Src, SUnit *Dst, |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 362 | const HexagonInstrInfo *TII, SmallSet<SUnit*, 4> &ExclSrc, |
| 363 | SmallSet<SUnit*, 4> &ExclDst) const { |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 364 | MachineInstr &SrcInst = *Src->getInstr(); |
| 365 | MachineInstr &DstInst = *Dst->getInstr(); |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 366 | |
Ron Lieberman | da5df7c | 2016-09-17 16:21:09 +0000 | [diff] [blame] | 367 | // Ignore Boundary SU nodes as these have null instructions. |
| 368 | if (Dst->isBoundaryNode()) |
| 369 | return false; |
| 370 | |
Krzysztof Parzyszek | f0b34a5 | 2016-07-29 21:49:42 +0000 | [diff] [blame] | 371 | if (SrcInst.isPHI() || DstInst.isPHI()) |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 372 | return false; |
| 373 | |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 374 | if (!TII->isToBeScheduledASAP(SrcInst, DstInst) && |
| 375 | !TII->canExecuteInBundle(SrcInst, DstInst)) |
| 376 | return false; |
| 377 | |
| 378 | // The architecture doesn't allow three dependent instructions in the same |
| 379 | // packet. So, if the destination has a zero latency successor, then it's |
| 380 | // not a candidate for a zero latency predecessor. |
| 381 | if (getZeroLatency(Dst, Dst->Succs) != nullptr) |
| 382 | return false; |
| 383 | |
Krzysztof Parzyszek | 748d3ef | 2016-07-18 14:23:10 +0000 | [diff] [blame] | 384 | // Check if the Dst instruction is the best candidate first. |
| 385 | SUnit *Best = nullptr; |
| 386 | SUnit *DstBest = nullptr; |
| 387 | SUnit *SrcBest = getZeroLatency(Dst, Dst->Preds); |
| 388 | if (SrcBest == nullptr || Src->NodeNum >= SrcBest->NodeNum) { |
| 389 | // Check that Src doesn't have a better candidate. |
| 390 | DstBest = getZeroLatency(Src, Src->Succs); |
| 391 | if (DstBest == nullptr || Dst->NodeNum <= DstBest->NodeNum) |
| 392 | Best = Dst; |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 393 | } |
Krzysztof Parzyszek | 748d3ef | 2016-07-18 14:23:10 +0000 | [diff] [blame] | 394 | if (Best != Dst) |
| 395 | return false; |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 396 | |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 397 | // The caller frequently adds the same dependence twice. If so, then |
Krzysztof Parzyszek | 748d3ef | 2016-07-18 14:23:10 +0000 | [diff] [blame] | 398 | // return true for this case too. |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 399 | if ((Src == SrcBest && Dst == DstBest ) || |
| 400 | (SrcBest == nullptr && Dst == DstBest) || |
| 401 | (Src == SrcBest && Dst == nullptr)) |
Krzysztof Parzyszek | 748d3ef | 2016-07-18 14:23:10 +0000 | [diff] [blame] | 402 | return true; |
| 403 | |
| 404 | // Reassign the latency for the previous bests, which requires setting |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 405 | // the dependence edge in both directions. |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 406 | if (SrcBest != nullptr) { |
| 407 | if (!hasV60TOps()) |
| 408 | changeLatency(SrcBest, Dst, 1); |
| 409 | else |
| 410 | restoreLatency(SrcBest, Dst); |
| 411 | } |
| 412 | if (DstBest != nullptr) { |
| 413 | if (!hasV60TOps()) |
| 414 | changeLatency(Src, DstBest, 1); |
| 415 | else |
| 416 | restoreLatency(Src, DstBest); |
| 417 | } |
| 418 | |
| 419 | // Attempt to find another opprotunity for zero latency in a different |
| 420 | // dependence. |
Krzysztof Parzyszek | 748d3ef | 2016-07-18 14:23:10 +0000 | [diff] [blame] | 421 | if (SrcBest && DstBest) |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 422 | // If there is an edge from SrcBest to DstBst, then try to change that |
| 423 | // to 0 now. |
| 424 | changeLatency(SrcBest, DstBest, 0); |
| 425 | else if (DstBest) { |
| 426 | // Check if the previous best destination instruction has a new zero |
| 427 | // latency dependence opportunity. |
| 428 | ExclSrc.insert(Src); |
| 429 | for (auto &I : DstBest->Preds) |
| 430 | if (ExclSrc.count(I.getSUnit()) == 0 && |
| 431 | isBestZeroLatency(I.getSUnit(), DstBest, TII, ExclSrc, ExclDst)) |
| 432 | changeLatency(I.getSUnit(), DstBest, 0); |
| 433 | } else if (SrcBest) { |
| 434 | // Check if previous best source instruction has a new zero latency |
| 435 | // dependence opportunity. |
| 436 | ExclDst.insert(Dst); |
| 437 | for (auto &I : SrcBest->Succs) |
| 438 | if (ExclDst.count(I.getSUnit()) == 0 && |
| 439 | isBestZeroLatency(SrcBest, I.getSUnit(), TII, ExclSrc, ExclDst)) |
| 440 | changeLatency(SrcBest, I.getSUnit(), 0); |
| 441 | } |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 442 | |
Krzysztof Parzyszek | 748d3ef | 2016-07-18 14:23:10 +0000 | [diff] [blame] | 443 | return true; |
Krzysztof Parzyszek | 408e300 | 2016-07-15 21:34:02 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Krzysztof Parzyszek | d3d0a4b | 2016-07-22 14:22:43 +0000 | [diff] [blame] | 446 | unsigned HexagonSubtarget::getL1CacheLineSize() const { |
| 447 | return 32; |
| 448 | } |
| 449 | |
| 450 | unsigned HexagonSubtarget::getL1PrefetchDistance() const { |
| 451 | return 32; |
| 452 | } |
| 453 | |
Krzysztof Parzyszek | 2af5037 | 2017-05-03 20:10:36 +0000 | [diff] [blame] | 454 | bool HexagonSubtarget::enableSubRegLiveness() const { |
| 455 | return EnableSubregLiveness; |
| 456 | } |