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