LLVM 24.0.0git
HexagonSubtarget.cpp
Go to the documentation of this file.
1//===- HexagonSubtarget.cpp - Hexagon Subtarget Information ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Hexagon specific subclass of TargetSubtarget.
10//
11//===----------------------------------------------------------------------===//
12
13#include "HexagonSubtarget.h"
14#include "HexagonInstrInfo.h"
15#include "HexagonRegisterInfo.h"
17#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/StringRef.h"
26#include "llvm/IR/DataLayout.h"
27#include "llvm/IR/GlobalValue.h"
28#include "llvm/IR/IntrinsicsHexagon.h"
32#include <algorithm>
33#include <cassert>
34#include <optional>
35
36using namespace llvm;
37
38#define DEBUG_TYPE "hexagon-subtarget"
39
40#define GET_SUBTARGETINFO_CTOR
41#define GET_SUBTARGETINFO_TARGET_DESC
42#include "HexagonGenSubtargetInfo.inc"
43
44static cl::opt<bool> EnableBSBSched("enable-bsb-sched", cl::Hidden,
45 cl::init(true));
46
47static cl::opt<bool> EnableTCLatencySched("enable-tc-latency-sched", cl::Hidden,
48 cl::init(false));
49
50static cl::opt<bool>
51 EnableDotCurSched("enable-cur-sched", cl::Hidden, cl::init(true),
52 cl::desc("Enable the scheduler to generate .cur"));
53
54static cl::opt<bool>
55 DisableHexagonMISched("disable-hexagon-misched", cl::Hidden,
56 cl::desc("Disable Hexagon MI Scheduling"));
57
59 "hexagon-long-calls", cl::Hidden,
60 cl::desc("If present, forces/disables the use of long calls"));
61
62static cl::opt<bool>
63 EnablePredicatedCalls("hexagon-pred-calls", cl::Hidden,
64 cl::desc("Consider calls to be predicable"));
65
66static cl::opt<bool> SchedPredsCloser("sched-preds-closer", cl::Hidden,
67 cl::init(true));
68
69static cl::opt<bool> SchedRetvalOptimization("sched-retval-optimization",
70 cl::Hidden, cl::init(true));
71
73 "hexagon-check-bank-conflict", cl::Hidden, cl::init(true),
74 cl::desc("Enable checking for cache bank conflicts"));
75
77 StringRef FS, const TargetMachine &TM)
78 : HexagonGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
79 OptLevel(TM.getOptLevel()),
80 CPUString(std::string(Hexagon_MC::selectHexagonCPU(CPU))),
81 TargetTriple(TT), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
82 TLInfo(TM, *this), InstrItins(getInstrItineraryForCPU(CPUString)) {
84 // Beware of the default constructor of InstrItineraryData: it will
85 // reset all members to 0.
86 assert(InstrItins.Itineraries != nullptr && "InstrItins not initialized");
87}
88
91 std::optional<Hexagon::ArchEnum> ArchVer = Hexagon::getCpu(CPUString);
92 if (ArchVer)
93 HexagonArchVersion = *ArchVer;
94 else
95 llvm_unreachable("Unrecognized Hexagon processor version");
96
97 UseHVX128BOps = false;
98 UseHVX64BOps = false;
99 UseAudioOps = false;
100 UseLongCalls = false;
101
102 SubtargetFeatures Features(FS);
103
104 // Turn on QFloat if the HVX version is v68+.
105 // The function ParseSubtargetFeatures will set feature bits and initialize
106 // subtarget's variables all in one, so there isn't a good way to preprocess
107 // the feature string, other than by tinkering with it directly.
108 auto IsQFloatFS = [](StringRef F) {
109 return F == "+hvx-qfloat" || F == "-hvx-qfloat";
110 };
111 if (!llvm::count_if(Features.getFeatures(), IsQFloatFS)) {
112 auto getHvxVersion = [&Features](StringRef FS) -> StringRef {
113 for (StringRef F : llvm::reverse(Features.getFeatures())) {
114 if (F.starts_with("+hvxv"))
115 return F;
116 }
117 for (StringRef F : llvm::reverse(Features.getFeatures())) {
118 if (F == "-hvx")
119 return StringRef();
120 if (F.starts_with("+hvx") || F == "-hvx")
121 return F.take_front(4); // Return "+hvx" or "-hvx".
122 }
123 return StringRef();
124 };
125
126 bool AddQFloat = false;
127 StringRef HvxVer = getHvxVersion(FS);
128 if (HvxVer.starts_with("+hvxv")) {
129 int Ver = 0;
130 if (!HvxVer.drop_front(5).consumeInteger(10, Ver) && Ver >= 68)
131 AddQFloat = true;
132 } else if (HvxVer == "+hvx") {
133 if (hasV68Ops())
134 AddQFloat = true;
135 }
136
137 if (AddQFloat)
138 Features.AddFeature("+hvx-qfloat");
139 }
140
141 std::string FeatureString = Features.getString();
142 ParseSubtargetFeatures(CPUString, /*TuneCPU*/ CPUString, FeatureString);
143
144 // Resolve the shadow call stack pointer register. At most one "scs-reg-rN"
145 // feature may be given; R18 is the default. R18 is chosen because it is the
146 // lowest callee-saved register that neither the Hexagon Linux kernel (which
147 // reserves R19 for the thread-info pointer) nor code that reserves the upper
148 // callee-saved range already claims.
149 static_assert(Hexagon::R27 - Hexagon::R16 == 11,
150 "Callee-saved R16-R27 are assumed to be consecutive");
151 SCSPReg = Hexagon::R18;
152 bool SCSRegSelected = false;
153 for (unsigned Reg = Hexagon::R16; Reg <= Hexagon::R27; ++Reg) {
154 if (!SCSPointerRegister[Reg])
155 continue;
156 if (SCSRegSelected)
158 "Only one shadow call stack pointer register may be selected");
159 SCSPReg = Reg;
160 SCSRegSelected = true;
161 }
162
163 if (useHVXV68Ops())
164 UseHVXFloatingPoint = UseHVXIEEEFPOps || UseHVXQFloatOps;
165
166 if (UseHVXQFloatOps && UseHVXIEEEFPOps && UseHVXFloatingPoint)
168 dbgs() << "Behavior is undefined for simultaneous qfloat and ieee hvx codegen...");
169
170 if (OverrideLongCalls.getPosition())
171 UseLongCalls = OverrideLongCalls;
172
174
175 if (isTinyCore()) {
176 // Tiny core has a single thread, so back-to-back scheduling is enabled by
177 // default.
178 if (!EnableBSBSched.getPosition())
179 UseBSBScheduling = false;
180 }
181
182 FeatureBitset FeatureBits = getFeatureBits();
184 setFeatureBits(FeatureBits.reset(Hexagon::FeatureDuplex));
185 setFeatureBits(Hexagon_MC::completeHVXFeatures(FeatureBits));
186
187 return *this;
188}
189
191 LibcallLoweringInfo &Info) const {
192 // The generic arithmetic/division helper routines (__adddf3, __divsi3, ...)
193 // exist in Hexagon's compiler-rt alongside the preferred __hexagon_*
194 // variants, so both are available. The __hexagon_* variant is the one that
195 // must be used; select it explicitly here.
196 static const struct {
197 const RTLIB::Libcall Op;
198 const RTLIB::LibcallImpl Impl;
199 } LibraryCalls[] = {
200 {RTLIB::SDIV_I32, RTLIB::impl___hexagon_divsi3},
201 {RTLIB::SDIV_I64, RTLIB::impl___hexagon_divdi3},
202 {RTLIB::UDIV_I32, RTLIB::impl___hexagon_udivsi3},
203 {RTLIB::UDIV_I64, RTLIB::impl___hexagon_udivdi3},
204 {RTLIB::SREM_I32, RTLIB::impl___hexagon_modsi3},
205 {RTLIB::SREM_I64, RTLIB::impl___hexagon_moddi3},
206 {RTLIB::UREM_I32, RTLIB::impl___hexagon_umodsi3},
207 {RTLIB::UREM_I64, RTLIB::impl___hexagon_umoddi3},
208 {RTLIB::ADD_F64, RTLIB::impl___hexagon_adddf3},
209 {RTLIB::SUB_F64, RTLIB::impl___hexagon_subdf3},
210 {RTLIB::MUL_F64, RTLIB::impl___hexagon_muldf3},
211 {RTLIB::DIV_F64, RTLIB::impl___hexagon_divdf3},
212 {RTLIB::DIV_F32, RTLIB::impl___hexagon_divsf3},
213 };
214 for (const auto &LC : LibraryCalls)
215 Info.setLibcallImpl(LC.Op, LC.Impl);
216}
217
218bool HexagonSubtarget::isHVXElementType(MVT Ty, bool IncludeBool) const {
219 if (!useHVXOps())
220 return false;
221 if (Ty.isVector())
222 Ty = Ty.getVectorElementType();
223 if (IncludeBool && Ty == MVT::i1)
224 return true;
225 ArrayRef<MVT> ElemTypes = getHVXElementTypes();
226 return llvm::is_contained(ElemTypes, Ty);
227}
228
229bool HexagonSubtarget::isHVXVectorType(EVT VecTy, bool IncludeBool) const {
230 if (!VecTy.isSimple())
231 return false;
232 if (!VecTy.isVector() || !useHVXOps() || VecTy.isScalableVector())
233 return false;
235 if (!IncludeBool && ElemTy == MVT::i1)
236 return false;
237
238 unsigned HwLen = getVectorLength();
239 unsigned NumElems = VecTy.getVectorNumElements();
240 ArrayRef<MVT> ElemTypes = getHVXElementTypes();
241
242 if (IncludeBool && ElemTy == MVT::i1) {
243 // Boolean HVX vector types are formed from regular HVX vector types
244 // by replacing the element type with i1.
245 for (MVT T : ElemTypes)
246 if (NumElems * T.getSizeInBits() == 8 * HwLen)
247 return true;
248 return false;
249 }
250
251 unsigned VecWidth = VecTy.getSizeInBits();
252 if (VecWidth != 8 * HwLen && VecWidth != 16 * HwLen)
253 return false;
254 return llvm::is_contained(ElemTypes, ElemTy);
255}
256
257bool HexagonSubtarget::isTypeForHVX(Type *VecTy, bool IncludeBool) const {
258 if (!VecTy->isVectorTy() || isa<ScalableVectorType>(VecTy))
259 return false;
260 // HLX types have their own legalization path and never go through HVX.
261 if (useHLXOps() && isTypeForHLX(VecTy))
262 return false;
263 // Avoid types like <2 x i32*>.
264 Type *ScalTy = VecTy->getScalarType();
265 if (!ScalTy->isIntegerTy() &&
266 !(ScalTy->isFloatingPointTy() && useHVXFloatingPoint()))
267 return false;
268 // The given type may be something like <17 x i32>, which is not MVT,
269 // but can be represented as (non-simple) EVT.
270 EVT Ty = EVT::getEVT(VecTy, /*HandleUnknown*/false);
271 if (!Ty.getVectorElementType().isSimple())
272 return false;
273
274 auto isHvxTy = [this, IncludeBool](MVT SimpleTy) {
275 if (isHVXVectorType(SimpleTy, IncludeBool))
276 return true;
277 auto Action = getTargetLowering()->getPreferredVectorAction(SimpleTy);
279 };
280
281 // Round up EVT to have power-of-2 elements, and keep checking if it
282 // qualifies for HVX, dividing it in half after each step.
283 MVT ElemTy = Ty.getVectorElementType().getSimpleVT();
284 unsigned VecLen = PowerOf2Ceil(Ty.getVectorNumElements());
285 while (VecLen > 1) {
286 MVT SimpleTy = MVT::getVectorVT(ElemTy, VecLen);
287 if (SimpleTy.isValid() && isHvxTy(SimpleTy))
288 return true;
289 VecLen /= 2;
290 }
291
292 return false;
293}
294
296 if (!useHLXOps())
297 return false;
298 if (Ty.isVector())
299 Ty = Ty.getVectorElementType();
300 ArrayRef<MVT> ElemTypes = getHLXElementTypes();
301 return llvm::is_contained(ElemTypes, Ty);
302}
303
305 if (!VecTy.isSimple())
306 return false;
307 if (!VecTy.isVector() || !useHLXOps() || VecTy.isScalableVector())
308 return false;
310
311 unsigned HwLen = getHLXVectorLength();
312 ArrayRef<MVT> ElemTypes = getHLXElementTypes();
313
314 unsigned VecWidth = VecTy.getSizeInBits();
315 if (VecWidth != 8 * HwLen && VecWidth != 16 * HwLen)
316 return false;
317 return llvm::is_contained(ElemTypes, ElemTy);
318}
319
321 if (!VecTy->isVectorTy() || isa<ScalableVectorType>(VecTy))
322 return false;
323 // Avoid types like <2 x i32*>.
324 Type *ScalTy = VecTy->getScalarType();
325 if (!ScalTy->isIntegerTy() && !ScalTy->isFloatingPointTy())
326 return false;
327 // The given type may be something like <17 x i32>, which is not MVT,
328 // but can be represented as (non-simple) EVT.
329 EVT Ty = EVT::getEVT(VecTy, /*HandleUnknown*/ false);
330 if (!Ty.getVectorElementType().isSimple())
331 return false;
332
333 auto isHLXTy = [this](MVT SimpleTy) {
334 if (isHLXVectorType(SimpleTy))
335 return true;
336 // No widening for now
337 return false;
338 };
339
340 // Round up EVT to have power-of-2 elements, and keep checking if it
341 // qualifies for HLX, dividing it in half after each step.
342 MVT ElemTy = Ty.getVectorElementType().getSimpleVT();
343 unsigned VecLen = PowerOf2Ceil(Ty.getVectorNumElements());
344 while (VecLen > 1) {
345 MVT SimpleTy = MVT::getVectorVT(ElemTy, VecLen);
346 if (SimpleTy.isValid() && isHLXTy(SimpleTy))
347 return true;
348 VecLen /= 2;
349 }
350
351 return false;
352}
353
355 for (SUnit &SU : DAG->SUnits) {
356 if (!SU.isInstr())
357 continue;
359 for (auto &D : SU.Preds)
360 if (D.getKind() == SDep::Output && D.getReg() == Hexagon::USR_OVF)
361 Erase.push_back(D);
362 for (auto &E : Erase)
363 SU.removePred(E);
364 }
365}
366
368 for (SUnit &SU : DAG->SUnits) {
369 // Update the latency of chain edges between v60 vector load or store
370 // instructions to be 1. These instruction cannot be scheduled in the
371 // same packet.
372 MachineInstr &MI1 = *SU.getInstr();
373 auto *QII = static_cast<const HexagonInstrInfo*>(DAG->TII);
374 bool IsStoreMI1 = MI1.mayStore();
375 bool IsLoadMI1 = MI1.mayLoad();
376 if (!QII->isHVXVec(MI1) || !(IsStoreMI1 || IsLoadMI1))
377 continue;
378 for (SDep &SI : SU.Succs) {
379 if (SI.getKind() != SDep::Order || SI.getLatency() != 0)
380 continue;
381 MachineInstr &MI2 = *SI.getSUnit()->getInstr();
382 if (!QII->isHVXVec(MI2))
383 continue;
384 if ((IsStoreMI1 && MI2.mayStore()) || (IsLoadMI1 && MI2.mayLoad())) {
385 SI.setLatency(1);
386 SU.setHeightDirty();
387 // Change the dependence in the opposite direction too.
388 for (SDep &PI : SI.getSUnit()->Preds) {
389 if (PI.getSUnit() != &SU || PI.getKind() != SDep::Order)
390 continue;
391 PI.setLatency(1);
392 SI.getSUnit()->setDepthDirty();
393 }
394 }
395 }
396 }
397}
398
399// Ensure that HMX activate and weight instructions are scheduled together.
400// The main idea is to:
401// 1. Reduce any latency between corresponding A/W to 0.
402// 2. Make the depths of corresponding A/W instructions be the same. (The
403// post-RA scheduler is a top-down list scheduler.)
405 ScheduleDAGInstrs *DAG) {
406 if (DAG->SUnits.empty())
407 return;
408
409 auto &HII = static_cast<const HexagonInstrInfo &>(*DAG->TII);
410 DenseMap<SUnit *, SUnit *> AWMap; // Map: Activation <-> Weight.
411 DenseSet<SUnit *> First; // Which of the two came first.
412 // The SUnits in the DAG follow the order of instructions. The code below
413 // depends on it to pair up activation and weight instructions.
414 SUnit *A = nullptr, *W = nullptr;
415 for (SUnit &SU : DAG->SUnits) {
416 MachineInstr *MI = SU.getInstr();
417 if (HII.isHMXActivateInstr(*MI)) {
418 assert(A == nullptr && "Unexpected activation instruction");
419 A = &SU;
420 if (!W)
421 First.insert(A);
422 } else if (HII.isHMXWeightInstr(*MI)) {
423 assert(W == nullptr && "Unexpected weight instruction");
424 W = &SU;
425 if (!A)
426 First.insert(W);
427 }
428 if (A && W) {
429 AWMap.insert({A, W});
430 AWMap.insert({W, A});
431 A = W = nullptr;
432 }
433 }
434 assert(A == nullptr && "Unmatched activation instruction");
435 assert(W == nullptr && "Unmatched weight instruction");
436
437 // Reset the latency between matching instructions to 0.
438 for (SUnit *FirstSU : First) {
439 SUnit *SecondSU = AWMap.lookup(FirstSU);
440 // Set the successor latency to 0.
441 for (SDep &D : FirstSU->Succs) {
442 if (D.getSUnit() == SecondSU) {
443 D.setLatency(0);
444 FirstSU->setHeightDirty();
445 }
446 }
447 // Set the predecessor latency to 0.
448 for (SDep &D : SecondSU->Preds) {
449 if (D.getSUnit() == FirstSU) {
450 D.setLatency(0);
451 SecondSU->setDepthDirty();
452 }
453 }
454 }
455
456 SUnit *Entry = &DAG->SUnits[0];
457 assert(Entry->getDepth() == 0);
458
459 // For each pair, reset the depth (max distance from the entry) to be the
460 // max of the two. We can't just set the depth directly, because the post-RA
461 // scheduler recalculates it during scheduling. There are also assertions
462 // in it that can fire when the depth on the node is inconsistent with the
463 // calculations.
464 // To avoid this issue, make the depth "real" by adding a fake edge from
465 // the Entry node (which is assumed to have a depth of 0).
466 // Adding a new edge will mark the depths of successors (recursively)
467 // as dirty, potentially including subsequent pairs. The "getDepth" call
468 // will recompute a dirty depth, so it's important to iterate over the nodes
469 // in such a way that predecessors are visited first.
470 //
471 // Skip the first SUnit in case it's an A/W instruction, so that we don't
472 // try to create an edge from that node to itself.
473 for (SUnit &SU : MutableArrayRef<SUnit>(DAG->SUnits).drop_front()) {
474 if (!First.count(&SU))
475 continue;
476 SUnit *FirstSU = &SU;
477 SUnit *SecondSU = AWMap.lookup(FirstSU);
478 unsigned MaxDepth = std::max(FirstSU->getDepth(), SecondSU->getDepth());
479 SDep DepthEdge(Entry, SDep::Artificial);
480 DepthEdge.setLatency(MaxDepth);
481 FirstSU->addPred(DepthEdge);
482 SecondSU->addPred(DepthEdge);
483 }
484}
485
486// Check if a call and subsequent A2_tfrpi instructions should maintain
487// scheduling affinity. We are looking for the TFRI to be consumed in
488// the next instruction. This should help reduce the instances of
489// double register pairs being allocated and scheduled before a call
490// when not used until after the call. This situation is exacerbated
491// by the fact that we allocate the pair from the callee saves list,
492// leading to excess spills and restores.
493bool HexagonSubtarget::CallMutation::shouldTFRICallBind(
494 const HexagonInstrInfo &HII, const SUnit &Inst1,
495 const SUnit &Inst2) const {
496 if (Inst1.getInstr()->getOpcode() != Hexagon::A2_tfrpi)
497 return false;
498
499 // TypeXTYPE are 64 bit operations.
500 unsigned Type = HII.getType(*Inst2.getInstr());
503}
504
506 ScheduleDAGMI *DAG = static_cast<ScheduleDAGMI*>(DAGInstrs);
507 SUnit* LastSequentialCall = nullptr;
508 // Map from virtual register to physical register from the copy.
509 DenseMap<unsigned, unsigned> VRegHoldingReg;
510 // Map from the physical register to the instruction that uses virtual
511 // register. This is used to create the barrier edge.
512 DenseMap<unsigned, SUnit *> LastVRegUse;
513 auto &TRI = *DAG->MF.getSubtarget().getRegisterInfo();
514 auto &HII = *DAG->MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
515
516 // Currently we only catch the situation when compare gets scheduled
517 // before preceding call.
518 for (unsigned su = 0, e = DAG->SUnits.size(); su != e; ++su) {
519 // Remember the call.
520 if (DAG->SUnits[su].getInstr()->isCall())
521 LastSequentialCall = &DAG->SUnits[su];
522 // Look for a compare that defines a predicate.
523 else if (DAG->SUnits[su].getInstr()->isCompare() && LastSequentialCall)
524 DAG->addEdge(&DAG->SUnits[su], SDep(LastSequentialCall, SDep::Barrier));
525 // Look for call and tfri* instructions.
526 else if (SchedPredsCloser && LastSequentialCall && su > 1 && su < e-1 &&
527 shouldTFRICallBind(HII, DAG->SUnits[su], DAG->SUnits[su+1]))
528 DAG->addEdge(&DAG->SUnits[su], SDep(&DAG->SUnits[su-1], SDep::Barrier));
529 // Prevent redundant register copies due to reads and writes of physical
530 // registers. The original motivation for this was the code generated
531 // between two calls, which are caused both the return value and the
532 // argument for the next call being in %r0.
533 // Example:
534 // 1: <call1>
535 // 2: %vreg = COPY %r0
536 // 3: <use of %vreg>
537 // 4: %r0 = ...
538 // 5: <call2>
539 // The scheduler would often swap 3 and 4, so an additional register is
540 // needed. This code inserts a Barrier dependence between 3 & 4 to prevent
541 // this.
542 // The code below checks for all the physical registers, not just R0/D0/V0.
543 else if (SchedRetvalOptimization) {
544 const MachineInstr *MI = DAG->SUnits[su].getInstr();
545 if (MI->isCopy() && MI->getOperand(1).getReg().isPhysical()) {
546 // %vregX = COPY %r0
547 VRegHoldingReg[MI->getOperand(0).getReg()] = MI->getOperand(1).getReg();
548 LastVRegUse.erase(MI->getOperand(1).getReg());
549 } else {
550 for (const MachineOperand &MO : MI->operands()) {
551 if (!MO.isReg())
552 continue;
553 if (MO.isUse() && !MI->isCopy() &&
554 VRegHoldingReg.count(MO.getReg())) {
555 // <use of %vregX>
556 LastVRegUse[VRegHoldingReg[MO.getReg()]] = &DAG->SUnits[su];
557 } else if (MO.isDef() && MO.getReg().isPhysical()) {
558 for (MCRegAliasIterator AI(MO.getReg(), &TRI, true); AI.isValid();
559 ++AI) {
560 if (auto It = LastVRegUse.find(*AI); It != LastVRegUse.end()) {
561 if (It->second != &DAG->SUnits[su])
562 // %r0 = ...
563 DAG->addEdge(&DAG->SUnits[su],
564 SDep(It->second, SDep::Barrier));
565 LastVRegUse.erase(It);
566 }
567 }
568 }
569 }
570 }
571 }
572 }
573}
574
575namespace {
576// Address of a load in the form used by the bank conflict check:
577// (Base << Shift) + Sym + Offset
578// Sym is null when the offset is a plain immediate.
579struct BankAddr {
581 unsigned Shift = 0;
582 const GlobalValue *Sym = nullptr;
583 int64_t Offset = 0;
584 uint64_t Size = 0;
585};
586} // end anonymous namespace
587
588// Decompose a scalar load into a BankAddr. Handles the base + offset form,
589// with either an immediate (memw(Rs+#s11)) or a global address
590// (memw(Rs+##sym)) as the offset, and the shifted-register + global form
591// (memw(Rt<<#u2+##sym)).
592static std::optional<BankAddr> getBankAddr(const MachineInstr &MI,
593 const HexagonInstrInfo &HII) {
594 if (!MI.mayLoad() || MI.mayStore() || HII.isMemOp(MI) ||
595 HII.isPostIncrement(MI) || HII.isHLXVec(MI))
596 return std::nullopt;
597 unsigned AddrMode = HII.getAddrMode(MI);
600 return std::nullopt;
601
602 // Operand 0 is the loaded value; the address operands follow.
603 unsigned BasePos = 1;
604 if (HII.isPredicated(MI))
605 ++BasePos;
606
607 BankAddr A;
608 unsigned OffsetPos = BasePos + 1;
610 // Rt << #u2 + ##u32
611 const MachineOperand &ShiftOp = MI.getOperand(BasePos + 1);
612 if (!ShiftOp.isImm())
613 return std::nullopt;
614 A.Shift = ShiftOp.getImm();
615 ++OffsetPos;
616 }
617
618 const MachineOperand &BaseOp = MI.getOperand(BasePos);
619 if (!BaseOp.isReg() || BaseOp.getSubReg() != 0)
620 return std::nullopt;
621 A.Base = BaseOp.getReg();
622
623 const MachineOperand &OffsetOp = MI.getOperand(OffsetPos);
624 if (OffsetOp.isImm()) {
625 A.Offset = OffsetOp.getImm();
626 } else if (OffsetOp.isGlobal()) {
627 // Only a direct reference to the symbol tells where it is relative to the
628 // bank boundaries; GOT, TLS and other relocations do not.
629 if ((OffsetOp.getTargetFlags() & ~HexagonII::HMOTF_ConstExtended) !=
631 return std::nullopt;
632 A.Sym = OffsetOp.getGlobal();
633 A.Offset = OffsetOp.getOffset();
634 } else {
635 return std::nullopt;
636 }
637
638 A.Size = HII.getMemAccessSize(MI);
639 return A;
640}
641
642// Return true if the offsets of the two loads can be compared to decide
643// whether they map to the same bank, i.e. whether the symbols (if any)
644// contribute the same value to the bank bits of the address.
645static bool haveComparableSyms(const BankAddr &A0, const BankAddr &A1,
646 const DataLayout &DL) {
647 if (A0.Sym == A1.Sym)
648 return true;
649 // Different symbols: the linker places each one independently, so their
650 // low address bits are known only from their alignment. A symbol aligned to
651 // the bank period (32 bytes) does not affect the bank bits, the same as a
652 // plain immediate offset (null Sym).
653 const Align BankPeriod(32);
654 auto HasKnownBankBits = [&](const GlobalValue *Sym) {
655 return !Sym || Sym->getPointerAlignment(DL) >= BankPeriod;
656 };
657 return HasKnownBankBits(A0.Sym) && HasKnownBankBits(A1.Sym);
658}
659
660// Return true if loads MI0 and MI1 likely map to the same cache bank and
661// should not be issued in the same packet. If IgnoreSameLine is true, loads
662// that likely read the same cache line, which cannot conflict, are not
663// reported.
665 const MachineInstr &MI1,
666 const HexagonInstrInfo &HII,
667 bool IgnoreSameLine) {
669 return false;
670 std::optional<BankAddr> A0 = getBankAddr(MI0, HII);
671 // Skip accesses as large as the L1 cache line.
672 if (!A0 || A0->Size == 0 || A0->Size >= 32)
673 return false;
674 std::optional<BankAddr> A1 = getBankAddr(MI1, HII);
675 if (!A1 || A1->Size == 0 || A1->Size >= 32 || A0->Base != A1->Base ||
676 A0->Shift != A1->Shift ||
677 !haveComparableSyms(*A0, *A1, MI0.getMF()->getDataLayout()))
678 return false;
679 // A bank conflict needs two different cache lines. As the bank check
680 // below does, assume the base is 32-byte aligned: offsets within the same
681 // 32-byte block then read the same line and cannot conflict.
682 if (IgnoreSameLine && A0->Sym == A1->Sym &&
683 (A0->Offset & ~int64_t(31)) == (A1->Offset & ~int64_t(31)))
684 return false;
685 // Compare the bank bits of the two offsets. If any of them differ, the
686 // loads go to different banks and can share a packet.
687 //
688 // Which address bits select the bank depends on the access sizes:
689 //
690 // Load pair Bank bits Mask
691 // ----------------------------------------- --------- ----
692 // double word + any load 4:3 0x18
693 // word/half-word/byte + word/half-word/byte 4:2 0x1C
694 //
695 // Bit 2 only tells two loads apart when neither of them is a double word.
696 // A double word covers both words of its 8-byte slot, so once one is
697 // involved, offsets that differ only in bit 2 still count as a conflict.
698 // Example (same base):
699 // memw(Rs+#0) and memw(Rs+#4) differ in bit 2 -> no conflict
700 // memw(Rs+#0) and memh(Rs+#4) differ in bit 2 -> no conflict
701 // memd(Rs+#0) and memw(Rs+#4) match on 4:3 -> conflict
702 // memd(Rs+#0) and memd(Rs+#8) differ in bit 3 -> no conflict
703 bool HasDoubleWord = A0->Size == 8 || A1->Size == 8;
704 int64_t BankMask = HasDoubleWord ? 0x18 : 0x1C;
705 return ((A0->Offset ^ A1->Offset) & BankMask) == 0;
706}
707
710 return;
711
712 const auto &HII = static_cast<const HexagonInstrInfo&>(*DAG->TII);
713
714 // Create artificial edges between loads that could likely cause a bank
715 // conflict. Since such loads would normally not have any dependency
716 // between them, we cannot rely on existing edges.
717 for (unsigned i = 0, e = DAG->SUnits.size(); i != e; ++i) {
718 SUnit &S0 = DAG->SUnits[i];
719 if (!getBankAddr(*S0.getInstr(), HII))
720 continue;
721 // Scan only up to 32 instructions ahead (to avoid n^2 complexity).
722 for (unsigned j = i+1, m = std::min(i+32, e); j != m; ++j) {
723 SUnit &S1 = DAG->SUnits[j];
724 // Use the conservative check here: the edge only guides the scheduler,
725 // and the packetizer decides whether the loads can share a packet.
726 if (!mayHaveBankConflict(*S0.getInstr(), *S1.getInstr(), HII,
727 /*IgnoreSameLine=*/false))
728 continue;
729 // The loads likely conflict: add an artificial edge and set extra
730 // latency.
731 SDep A(&S0, SDep::Artificial);
732 A.setLatency(1);
733 S1.addPred(A, true);
734 }
735 }
736}
737
739 const auto &HII = static_cast<const HexagonInstrInfo &>(*DAG->TII);
740 const auto &HST = DAG->MF.getSubtarget<HexagonSubtarget>();
741 if (!HST.useHLXOps())
742 return;
743
744 auto setLatency = [](SUnit &From, SUnit &To) {
745 for (SDep &Dep : From.Succs)
746 if (Dep.getSUnit() == &To && Dep.getKind() == SDep::Data)
747 Dep.setLatency(0);
748 for (SDep &Dep : To.Preds)
749 if (Dep.getSUnit() == &From && Dep.getKind() == SDep::Data)
750 Dep.setLatency(0);
751 };
752
753 for (SUnit &SU : DAG->SUnits) {
754 if (!SU.isInstr())
755 continue;
756
757 MachineInstr &MI = *SU.getInstr();
758 if (HII.isTmpLoadPseudo(MI)) {
759 for (SDep &Dep : SU.Succs)
760 if (Dep.getKind() == SDep::Data)
761 setLatency(SU, *Dep.getSUnit());
762 } else if (HII.isNewStorePseudo(MI)) {
763 for (SDep &Dep : SU.Preds)
764 if (Dep.getKind() == SDep::Data)
765 setLatency(*Dep.getSUnit(), SU);
766 }
767 }
768}
769
770/// Enable use of alias analysis during code generation (during MI
771/// scheduling, DAGCombine, etc.).
774 return true;
775 return false;
776}
777
778/// Perform target specific adjustments to the latency of a schedule
779/// dependency.
781 SUnit *Src, int SrcOpIdx, SUnit *Dst, int DstOpIdx, SDep &Dep,
782 const TargetSchedModel *SchedModel) const {
783 if (!Src->isInstr() || !Dst->isInstr())
784 return;
785
786 MachineInstr *SrcInst = Src->getInstr();
787 MachineInstr *DstInst = Dst->getInstr();
788 const HexagonInstrInfo *QII = getInstrInfo();
789
790 // Instructions with .new operands have zero latency.
793 if (QII->canExecuteInBundle(*SrcInst, *DstInst) &&
794 isBestZeroLatency(Src, Dst, QII, ExclSrc, ExclDst)) {
795 Dep.setLatency(0);
796 return;
797 }
798
799 // Set the latency for a copy to zero since we hope that is will get
800 // removed.
801 if (DstInst->isCopy())
802 Dep.setLatency(0);
803
804 // If it's a REG_SEQUENCE/COPY, use its destination instruction to determine
805 // the correct latency.
806 // If there are multiple uses of the def of COPY/REG_SEQUENCE, set the latency
807 // only if the latencies on all the uses are equal, otherwise set it to
808 // default.
809 if ((DstInst->isRegSequence() || DstInst->isCopy())) {
810 Register DReg = DstInst->getOperand(0).getReg();
811 std::optional<unsigned> DLatency;
812 for (const auto &DDep : Dst->Succs) {
813 MachineInstr *DDst = DDep.getSUnit()->getInstr();
814 int UseIdx = -1;
815 for (unsigned OpNum = 0; OpNum < DDst->getNumOperands(); OpNum++) {
816 const MachineOperand &MO = DDst->getOperand(OpNum);
817 if (MO.isReg() && MO.getReg() && MO.isUse() && MO.getReg() == DReg) {
818 UseIdx = OpNum;
819 break;
820 }
821 }
822
823 if (UseIdx == -1)
824 continue;
825
826 std::optional<unsigned> Latency =
827 InstrInfo.getOperandLatency(&InstrItins, *SrcInst, 0, *DDst, UseIdx);
828
829 // Set DLatency for the first time.
830 if (!DLatency)
831 DLatency = Latency;
832
833 // For multiple uses, if the Latency is different across uses, reset
834 // DLatency.
835 if (DLatency != Latency) {
836 DLatency = std::nullopt;
837 break;
838 }
839 }
840 Dep.setLatency(DLatency.value_or(0));
841 }
842
843 // Try to schedule uses near definitions to generate .cur.
844 ExclSrc.clear();
845 ExclDst.clear();
846 if (EnableDotCurSched && QII->isToBeScheduledASAP(*SrcInst, *DstInst) &&
847 isBestZeroLatency(Src, Dst, QII, ExclSrc, ExclDst)) {
848 Dep.setLatency(0);
849 return;
850 }
851 int Latency = Dep.getLatency();
852 bool IsArtificial = Dep.isArtificial();
853 Latency = updateLatency(*SrcInst, *DstInst, IsArtificial, Latency);
854 Dep.setLatency(Latency);
855}
856
858 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
859 Mutations.push_back(std::make_unique<UsrOverflowMutation>());
860 Mutations.push_back(std::make_unique<HVXMemLatencyMutation>());
861 Mutations.push_back(std::make_unique<HMXActivateWeightMutation>());
862 Mutations.push_back(std::make_unique<BankConflictMutation>());
863 Mutations.push_back(std::make_unique<HLXPseudoMutation>());
864}
865
867 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
868 Mutations.push_back(std::make_unique<UsrOverflowMutation>());
869 Mutations.push_back(std::make_unique<HVXMemLatencyMutation>());
870 Mutations.push_back(std::make_unique<HMXActivateWeightMutation>());
871}
872
873// Pin the vtable to this file.
874void HexagonSubtarget::anchor() {}
875
877 if (DisableHexagonMISched.getNumOccurrences())
878 return !DisableHexagonMISched;
879 return true;
880}
881
885
887 MachineInstr &DstInst, bool IsArtificial,
888 int Latency) const {
889 if (IsArtificial)
890 return 1;
891 if (!hasV60Ops())
892 return Latency;
893
894 const HexagonInstrInfo &QII = *getInstrInfo();
895 // BSB scheduling.
896 if (QII.isHVXVec(SrcInst) || useBSBScheduling())
897 Latency = (Latency + 1) >> 1;
898 return Latency;
899}
900
901void HexagonSubtarget::restoreLatency(SUnit *Src, SUnit *Dst) const {
902 MachineInstr *SrcI = Src->getInstr();
903 for (auto &I : Src->Succs) {
904 if (!I.isAssignedRegDep() || I.getSUnit() != Dst)
905 continue;
906 Register DepR = I.getReg();
907 int DefIdx = -1;
908 for (unsigned OpNum = 0; OpNum < SrcI->getNumOperands(); OpNum++) {
909 const MachineOperand &MO = SrcI->getOperand(OpNum);
910 bool IsSameOrSubReg = false;
911 if (MO.isReg()) {
912 Register MOReg = MO.getReg();
913 if (DepR.isVirtual()) {
914 IsSameOrSubReg = (MOReg == DepR);
915 } else {
916 IsSameOrSubReg = getRegisterInfo()->isSubRegisterEq(DepR, MOReg);
917 }
918 if (MO.isDef() && IsSameOrSubReg)
919 DefIdx = OpNum;
920 }
921 }
922 assert(DefIdx >= 0 && "Def Reg not found in Src MI");
923 MachineInstr *DstI = Dst->getInstr();
924 SDep T = I;
925 for (unsigned OpNum = 0; OpNum < DstI->getNumOperands(); OpNum++) {
926 const MachineOperand &MO = DstI->getOperand(OpNum);
927 if (MO.isReg() && MO.isUse() && MO.getReg() == DepR) {
928 std::optional<unsigned> Latency = InstrInfo.getOperandLatency(
929 &InstrItins, *SrcI, DefIdx, *DstI, OpNum);
930
931 // For some instructions (ex: COPY), we might end up with < 0 latency
932 // as they don't have any Itinerary class associated with them.
933 if (!Latency)
934 Latency = 0;
935 bool IsArtificial = I.isArtificial();
936 Latency = updateLatency(*SrcI, *DstI, IsArtificial, *Latency);
937 I.setLatency(*Latency);
938 }
939 }
940
941 // Update the latency of opposite edge too.
942 T.setSUnit(Src);
943 auto F = find(Dst->Preds, T);
944 assert(F != Dst->Preds.end());
945 F->setLatency(I.getLatency());
946 }
947}
948
949/// Change the latency between the two SUnits.
950void HexagonSubtarget::changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat)
951 const {
952 for (auto &I : Src->Succs) {
953 if (!I.isAssignedRegDep() || I.getSUnit() != Dst)
954 continue;
955 SDep T = I;
956 I.setLatency(Lat);
957
958 // Update the latency of opposite edge too.
959 T.setSUnit(Src);
960 auto F = find(Dst->Preds, T);
961 assert(F != Dst->Preds.end());
962 F->setLatency(Lat);
963 }
964}
965
966/// If the SUnit has a zero latency edge, return the other SUnit.
968 for (auto &I : Deps)
969 if (I.isAssignedRegDep() && I.getLatency() == 0 &&
970 !I.getSUnit()->getInstr()->isPseudo())
971 return I.getSUnit();
972 return nullptr;
973}
974
975// Return true if these are the best two instructions to schedule
976// together with a zero latency. Only one dependence should have a zero
977// latency. If there are multiple choices, choose the best, and change
978// the others, if needed.
979bool HexagonSubtarget::isBestZeroLatency(
980 SUnit *Src, SUnit *Dst, const HexagonInstrInfo *TII,
981 SmallPtrSet<SUnit *, 4> &ExclSrc, SmallPtrSet<SUnit *, 4> &ExclDst) const {
982 MachineInstr &SrcInst = *Src->getInstr();
983 MachineInstr &DstInst = *Dst->getInstr();
984
985 // Ignore Boundary SU nodes as these have null instructions.
986 if (Dst->isBoundaryNode())
987 return false;
988
989 if (SrcInst.isPHI() || DstInst.isPHI())
990 return false;
991
992 if (!TII->isToBeScheduledASAP(SrcInst, DstInst) &&
993 !TII->canExecuteInBundle(SrcInst, DstInst))
994 return false;
995
996 // The architecture doesn't allow three dependent instructions in the same
997 // packet. So, if the destination has a zero latency successor, then it's
998 // not a candidate for a zero latency predecessor.
999 if (getZeroLatency(Dst, Dst->Succs) != nullptr)
1000 return false;
1001
1002 // Check if the Dst instruction is the best candidate first.
1003 SUnit *Best = nullptr;
1004 SUnit *DstBest = nullptr;
1005 SUnit *SrcBest = getZeroLatency(Dst, Dst->Preds);
1006 if (SrcBest == nullptr || Src->NodeNum >= SrcBest->NodeNum) {
1007 // Check that Src doesn't have a better candidate.
1008 DstBest = getZeroLatency(Src, Src->Succs);
1009 if (DstBest == nullptr || Dst->NodeNum <= DstBest->NodeNum)
1010 Best = Dst;
1011 }
1012 if (Best != Dst)
1013 return false;
1014
1015 // The caller frequently adds the same dependence twice. If so, then
1016 // return true for this case too.
1017 if ((Src == SrcBest && Dst == DstBest ) ||
1018 (SrcBest == nullptr && Dst == DstBest) ||
1019 (Src == SrcBest && Dst == nullptr))
1020 return true;
1021
1022 // Reassign the latency for the previous bests, which requires setting
1023 // the dependence edge in both directions.
1024 if (SrcBest != nullptr) {
1025 if (!hasV60Ops())
1026 changeLatency(SrcBest, Dst, 1);
1027 else
1028 restoreLatency(SrcBest, Dst);
1029 }
1030 if (DstBest != nullptr) {
1031 if (!hasV60Ops())
1032 changeLatency(Src, DstBest, 1);
1033 else
1034 restoreLatency(Src, DstBest);
1035 }
1036
1037 // Attempt to find another opportunity for zero latency in a different
1038 // dependence.
1039 if (SrcBest && DstBest)
1040 // If there is an edge from SrcBest to DstBst, then try to change that
1041 // to 0 now.
1042 changeLatency(SrcBest, DstBest, 0);
1043 else if (DstBest) {
1044 // Check if the previous best destination instruction has a new zero
1045 // latency dependence opportunity.
1046 ExclSrc.insert(Src);
1047 for (auto &I : DstBest->Preds)
1048 if (ExclSrc.count(I.getSUnit()) == 0 &&
1049 isBestZeroLatency(I.getSUnit(), DstBest, TII, ExclSrc, ExclDst))
1050 changeLatency(I.getSUnit(), DstBest, 0);
1051 } else if (SrcBest) {
1052 // Check if previous best source instruction has a new zero latency
1053 // dependence opportunity.
1054 ExclDst.insert(Dst);
1055 for (auto &I : SrcBest->Succs)
1056 if (ExclDst.count(I.getSUnit()) == 0 &&
1057 isBestZeroLatency(SrcBest, I.getSUnit(), TII, ExclSrc, ExclDst))
1058 changeLatency(SrcBest, I.getSUnit(), 0);
1059 }
1060
1061 return true;
1062}
1063
1065 return 32;
1066}
1067
1069 return 32;
1070}
1071
1072bool HexagonSubtarget::enableSubRegLiveness() const { return true; }
1073
1075 struct Scalar {
1076 unsigned Opcode;
1077 Intrinsic::ID IntId;
1078 };
1079 struct Hvx {
1080 unsigned Opcode;
1081 Intrinsic::ID Int64Id, Int128Id;
1082 };
1083
1084 static Scalar ScalarInts[] = {
1085#define GET_SCALAR_INTRINSICS
1087#undef GET_SCALAR_INTRINSICS
1088 };
1089
1090 static Hvx HvxInts[] = {
1091#define GET_HVX_INTRINSICS
1093#undef GET_HVX_INTRINSICS
1094 };
1095
1096 const auto CmpOpcode = [](auto A, auto B) { return A.Opcode < B.Opcode; };
1097 [[maybe_unused]] static bool SortedScalar =
1098 (llvm::sort(ScalarInts, CmpOpcode), true);
1099 [[maybe_unused]] static bool SortedHvx =
1100 (llvm::sort(HvxInts, CmpOpcode), true);
1101
1102 auto [BS, ES] = std::make_pair(std::begin(ScalarInts), std::end(ScalarInts));
1103 auto [BH, EH] = std::make_pair(std::begin(HvxInts), std::end(HvxInts));
1104
1105 auto FoundScalar = std::lower_bound(BS, ES, Scalar{Opc, 0}, CmpOpcode);
1106 if (FoundScalar != ES && FoundScalar->Opcode == Opc)
1107 return FoundScalar->IntId;
1108
1109 auto FoundHvx = std::lower_bound(BH, EH, Hvx{Opc, 0, 0}, CmpOpcode);
1110 if (FoundHvx != EH && FoundHvx->Opcode == Opc) {
1111 unsigned HwLen = getVectorLength();
1112 if (HwLen == 64)
1113 return FoundHvx->Int64Id;
1114 if (HwLen == 128)
1115 return FoundHvx->Int128Id;
1116 }
1117
1118 std::string error = "Invalid opcode (" + std::to_string(Opc) + ")";
1119 llvm_unreachable(error.c_str());
1120 return 0;
1121}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
constexpr LLT S1
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static cl::opt< bool > DisableHexagonMISched("disable-hexagon-misched", cl::Hidden, cl::desc("Disable Hexagon MI Scheduling"))
static cl::opt< bool > EnableDotCurSched("enable-cur-sched", cl::Hidden, cl::init(true), cl::desc("Enable the scheduler to generate .cur"))
static cl::opt< bool > EnableCheckBankConflict("hexagon-check-bank-conflict", cl::Hidden, cl::init(true), cl::desc("Enable checking for cache bank conflicts"))
static cl::opt< bool > OverrideLongCalls("hexagon-long-calls", cl::Hidden, cl::desc("If present, forces/disables the use of long calls"))
static cl::opt< bool > SchedPredsCloser("sched-preds-closer", cl::Hidden, cl::init(true))
static cl::opt< bool > SchedRetvalOptimization("sched-retval-optimization", cl::Hidden, cl::init(true))
static cl::opt< bool > EnableTCLatencySched("enable-tc-latency-sched", cl::Hidden, cl::init(false))
static bool haveComparableSyms(const BankAddr &A0, const BankAddr &A1, const DataLayout &DL)
static cl::opt< bool > EnableBSBSched("enable-bsb-sched", cl::Hidden, cl::init(true))
static std::optional< BankAddr > getBankAddr(const MachineInstr &MI, const HexagonInstrInfo &HII)
static SUnit * getZeroLatency(SUnit *N, SmallVector< SDep, 4 > &Deps)
If the SUnit has a zero latency edge, return the other SUnit.
static cl::opt< bool > EnablePredicatedCalls("hexagon-pred-calls", cl::Hidden, cl::desc("Consider calls to be predicable"))
IRTranslator LLVM IR MI
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register const TargetRegisterInfo * TRI
#define T
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallVector class.
#define LLVM_DEBUG(...)
Definition Debug.h:119
#define error(X)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition DenseMap.h:762
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:766
iterator end()
Definition DenseMap.h:686
bool erase(const KeyT &Val)
Definition DenseMap.h:930
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
Definition DenseMap.h:793
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:827
Implements a dense probed hash-table based set.
Definition DenseSet.h:283
Container class for subtarget features.
constexpr FeatureBitset & reset(unsigned I)
bool isTmpLoadPseudo(const MachineInstr &MI) const
bool isHLXVec(const MachineInstr &MI) const
bool isPredicated(const MachineInstr &MI) const override
Returns true if the instruction is already predicated.
unsigned getAddrMode(const MachineInstr &MI) const
bool canExecuteInBundle(const MachineInstr &First, const MachineInstr &Second) const
Can these instructions execute at the same time in a bundle.
unsigned getMemAccessSize(const MachineInstr &MI) const
bool isPostIncrement(const MachineInstr &MI) const override
Return true for post-incremented instructions.
bool isMemOp(const MachineInstr &MI) const
bool isNewStorePseudo(const MachineInstr &MI) const
bool isHVXVec(const MachineInstr &MI) const
bool isToBeScheduledASAP(const MachineInstr &MI1, const MachineInstr &MI2) const
uint64_t getType(const MachineInstr &MI) const
Hexagon::ArchEnum HexagonArchVersion
void adjustSchedDependency(SUnit *Def, int DefOpIdx, SUnit *Use, int UseOpIdx, SDep &Dep, const TargetSchedModel *SchedModel) const override
Perform target specific adjustments to the latency of a schedule dependency.
bool isTypeForHLX(Type *VecTy) const
const HexagonInstrInfo * getInstrInfo() const override
unsigned getHLXVectorLength() const
const HexagonRegisterInfo * getRegisterInfo() const override
void getSMSMutations(std::vector< std::unique_ptr< ScheduleDAGMutation > > &Mutations) const override
HexagonSubtarget(const Triple &TT, StringRef CPU, StringRef FS, const TargetMachine &TM)
bool isHVXVectorType(EVT VecTy, bool IncludeBool=false) const
ArrayRef< MVT > getHLXElementTypes() const
void getPostRAMutations(std::vector< std::unique_ptr< ScheduleDAGMutation > > &Mutations) const override
const HexagonTargetLowering * getTargetLowering() const override
bool UseBSBScheduling
True if the target should use Back-Skip-Back scheduling.
unsigned getL1PrefetchDistance() const
ArrayRef< MVT > getHVXElementTypes() const
bool enableSubRegLiveness() const override
unsigned getVectorLength() const
void initLibcallLoweringInfo(LibcallLoweringInfo &Info) const override
bool isHLXElementType(MVT Ty) const
int updateLatency(MachineInstr &SrcInst, MachineInstr &DstInst, bool IsArtificial, int Latency) const
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
ParseSubtargetFeatures - Parses features string setting specified subtarget options.
unsigned getL1CacheLineSize() const
bool isTypeForHVX(Type *VecTy, bool IncludeBool=false) const
Intrinsic::ID getIntrinsicId(unsigned Opc) const
HexagonSubtarget & initializeSubtargetDependencies(StringRef CPU, StringRef FS)
static bool mayHaveBankConflict(const MachineInstr &MI0, const MachineInstr &MI1, const HexagonInstrInfo &HII, bool IgnoreSameLine=true)
bool enableMachineScheduler() const override
bool isHLXVectorType(EVT VecTy) const
bool isHVXElementType(MVT Ty, bool IncludeBool=false) const
bool useAA() const override
Enable use of alias analysis during code generation (during MI scheduling, DAGCombine,...
LegalizeTypeAction getPreferredVectorAction(MVT VT) const override
Return the preferred vector type legalization action.
Tracks which library functions to use for a particular subtarget or function.
MCRegAliasIterator enumerates all registers aliasing Reg.
Machine Value Type.
static MVT getVectorVT(MVT VT, unsigned NumElements)
MVT getVectorElementType() const
bool isValid() const
Return true if this is a valid simple valuetype.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool isCopy() const
unsigned getNumOperands() const
Retuns the total number of operands.
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
bool isRegSequence() const
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
int64_t getImm() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
Register getReg() const
getReg - Returns the register number.
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
MutableArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition ArrayRef.h:383
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
Scheduling dependency.
Definition ScheduleDAG.h:54
SUnit * getSUnit() const
Kind getKind() const
Returns an enum value representing the kind of the dependence.
@ Output
A register output-dependence (aka WAW).
Definition ScheduleDAG.h:60
@ Order
Any other ordering dependency.
Definition ScheduleDAG.h:61
@ Data
Regular data dependence (aka true-dependence).
Definition ScheduleDAG.h:58
void setLatency(unsigned Lat)
Sets the latency for this edge.
@ Barrier
An unknown scheduling barrier.
Definition ScheduleDAG.h:74
@ Artificial
Arbitrary strong DAG edge (no real dependence).
Definition ScheduleDAG.h:77
unsigned getLatency() const
Returns the latency value for this edge, which roughly means the minimum number of cycles that must e...
bool isArtificial() const
Tests if this is an Order dependence that is marked as "artificial", meaning it isn't necessary for c...
Scheduling unit. This is a node in the scheduling DAG.
bool isInstr() const
Returns true if this SUnit refers to a machine instruction as opposed to an SDNode.
unsigned NodeNum
Entry # of node in the node vector.
LLVM_ABI void setHeightDirty()
Sets a flag in this node to indicate that its stored Height value will require recomputation the next...
LLVM_ABI void removePred(const SDep &D)
Removes the specified edge as a pred of the current node if it exists.
unsigned getDepth() const
Returns the depth of this node, which is the length of the maximum path up to any node which has no p...
SmallVector< SDep, 4 > Succs
All sunit successors.
LLVM_ABI void setDepthDirty()
Sets a flag in this node to indicate that its stored Depth value will require recomputation the next ...
SmallVector< SDep, 4 > Preds
All sunit predecessors.
LLVM_ABI bool addPred(const SDep &D, bool Required=true)
Adds the specified edge as a pred of the current node if not already.
MachineInstr * getInstr() const
Returns the representative MachineInstr for this SUnit.
A ScheduleDAG for scheduling lists of MachineInstr.
bool addEdge(SUnit *SuccSU, const SDep &PredDep)
Add a DAG edge to the given SU with the given predecessor dependence data.
ScheduleDAGMI is an implementation of ScheduleDAGInstrs that simply schedules machine instructions ac...
const TargetInstrInfo * TII
Target instruction information.
std::vector< SUnit > SUnits
The scheduling units.
MachineFunction & MF
Machine function.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
bool consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
Definition StringRef.h:511
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
Definition StringRef.h:627
Manages the enabling and disabling of subtarget specific features.
const std::vector< std::string > & getFeatures() const
Returns the vector of individual subtarget features.
LLVM_ABI std::string getString() const
Returns features as a string.
LLVM_ABI void AddFeature(StringRef String, bool Enable=true)
Adds Features.
Primary interface to the complete machine description for the target machine.
Provide an instruction scheduling machine model to CodeGen passes.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isVectorTy() const
True if this is an instance of VectorType.
Definition Type.h:283
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition Type.h:370
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition Type.h:186
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:252
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void addArchSubtarget(MCSubtargetInfo const *STI, StringRef FS)
FeatureBitset completeHVXFeatures(const FeatureBitset &FB)
std::optional< Hexagon::ArchEnum > getCpu(StringRef CPU)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1781
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition MathExtras.h:380
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1652
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
DWARFExpression::Operation Op
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition STLExtras.h:2035
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
cl::opt< bool > HexagonDisableDuplex
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
Extended Value Type.
Definition ValueTypes.h:35
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition ValueTypes.h:160
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
Definition ValueTypes.h:411
static LLVM_ABI EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition ValueTypes.h:354
bool isVector() const
Return true if this is a vector value type.
Definition ValueTypes.h:191
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
Definition ValueTypes.h:202
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition ValueTypes.h:374
void apply(ScheduleDAGInstrs *DAG) override
void apply(ScheduleDAGInstrs *DAG) override
void apply(ScheduleDAGInstrs *DAG) override
void apply(ScheduleDAGInstrs *DAG) override
void apply(ScheduleDAGInstrs *DAG) override
void apply(ScheduleDAGInstrs *DAG) override