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"
18#include "llvm/ADT/STLExtras.h"
20#include "llvm/ADT/StringRef.h"
27#include "llvm/IR/DataLayout.h"
28#include "llvm/IR/GlobalValue.h"
29#include "llvm/IR/IntrinsicsHexagon.h"
33#include <algorithm>
34#include <cassert>
35#include <optional>
36
37using namespace llvm;
38
39#define DEBUG_TYPE "hexagon-subtarget"
40
41#define GET_SUBTARGETINFO_CTOR
42#define GET_SUBTARGETINFO_TARGET_DESC
43#include "HexagonGenSubtargetInfo.inc"
44
45#define OPTIONS_STRUCT_DEFS
46#include "HexagonOptions.inc"
47
49 StringRef FS, const TargetMachine &TM)
50 : HexagonGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
51 CLOpts(static_cast<const HexagonTargetMachine &>(TM).getCLOpts()),
52 OptLevel(TM.getOptLevel()),
53 CPUString(std::string(Hexagon_MC::selectHexagonCPU(CPU))),
54 TargetTriple(TT), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
55 TLInfo(TM, *this), InstrItins(getInstrItineraryForCPU(CPUString)) {
57 // Beware of the default constructor of InstrItineraryData: it will
58 // reset all members to 0.
59 assert(InstrItins.Itineraries != nullptr && "InstrItins not initialized");
60}
61
64 std::optional<Hexagon::ArchEnum> ArchVer = Hexagon::getCpu(CPUString);
65 if (ArchVer)
66 HexagonArchVersion = *ArchVer;
67 else
68 llvm_unreachable("Unrecognized Hexagon processor version");
69
70 UseHVX128BOps = false;
71 UseHVX64BOps = false;
72 UseAudioOps = false;
73 UseLongCalls = false;
74
75 SubtargetFeatures Features(FS);
76
77 // Turn on QFloat if the HVX version is v68+.
78 // The function ParseSubtargetFeatures will set feature bits and initialize
79 // subtarget's variables all in one, so there isn't a good way to preprocess
80 // the feature string, other than by tinkering with it directly.
81 auto IsQFloatFS = [](StringRef F) {
82 return F == "+hvx-qfloat" || F == "-hvx-qfloat";
83 };
84 if (!llvm::count_if(Features.getFeatures(), IsQFloatFS)) {
85 auto getHvxVersion = [&Features](StringRef FS) -> StringRef {
86 for (StringRef F : llvm::reverse(Features.getFeatures())) {
87 if (F.starts_with("+hvxv"))
88 return F;
89 }
90 for (StringRef F : llvm::reverse(Features.getFeatures())) {
91 if (F == "-hvx")
92 return StringRef();
93 if (F.starts_with("+hvx") || F == "-hvx")
94 return F.take_front(4); // Return "+hvx" or "-hvx".
95 }
96 return StringRef();
97 };
98
99 bool AddQFloat = false;
100 StringRef HvxVer = getHvxVersion(FS);
101 if (HvxVer.starts_with("+hvxv")) {
102 int Ver = 0;
103 if (!HvxVer.drop_front(5).consumeInteger(10, Ver) && Ver >= 68)
104 AddQFloat = true;
105 } else if (HvxVer == "+hvx") {
106 if (hasV68Ops())
107 AddQFloat = true;
108 }
109
110 if (AddQFloat)
111 Features.AddFeature("+hvx-qfloat");
112 }
113
114 std::string FeatureString = Features.getString();
115 ParseSubtargetFeatures(CPUString, /*TuneCPU*/ CPUString, FeatureString);
116
117 // Resolve the shadow call stack pointer register. At most one "scs-reg-rN"
118 // feature may be given; R18 is the default. R18 is chosen because it is the
119 // lowest callee-saved register that neither the Hexagon Linux kernel (which
120 // reserves R19 for the thread-info pointer) nor code that reserves the upper
121 // callee-saved range already claims.
122 static_assert(Hexagon::R27 - Hexagon::R16 == 11,
123 "Callee-saved R16-R27 are assumed to be consecutive");
124 SCSPReg = Hexagon::R18;
125 bool SCSRegSelected = false;
126 for (unsigned Reg = Hexagon::R16; Reg <= Hexagon::R27; ++Reg) {
127 if (!SCSPointerRegister[Reg])
128 continue;
129 if (SCSRegSelected)
131 "Only one shadow call stack pointer register may be selected");
132 SCSPReg = Reg;
133 SCSRegSelected = true;
134 }
135
136 if (useHVXV68Ops())
137 UseHVXFloatingPoint = UseHVXIEEEFPOps || UseHVXQFloatOps;
138
139 if (UseHVXQFloatOps && UseHVXIEEEFPOps && UseHVXFloatingPoint)
141 dbgs() << "Behavior is undefined for simultaneous qfloat and ieee hvx codegen...");
142
143 UseLongCalls = valueOr(CLOpts.long_calls, UseLongCalls);
144
145 UseBSBScheduling = hasV60Ops() && valueOr(CLOpts.bsb_sched, true);
146
147 if (isTinyCore()) {
148 // Tiny core has a single thread, so back-to-back scheduling is enabled by
149 // default.
150 if (CLOpts.bsb_sched == BoolOrDefault::Default)
151 UseBSBScheduling = false;
152 }
153
154 FeatureBitset FeatureBits = getFeatureBits();
156 setFeatureBits(FeatureBits.reset(Hexagon::FeatureDuplex));
157 setFeatureBits(Hexagon_MC::completeHVXFeatures(FeatureBits));
158
159 return *this;
160}
161
163 LibcallLoweringInfo &Info) const {
164 // The generic arithmetic/division helper routines (__adddf3, __divsi3, ...)
165 // exist in Hexagon's compiler-rt alongside the preferred __hexagon_*
166 // variants, so both are available. The __hexagon_* variant is the one that
167 // must be used; select it explicitly here.
168 static const struct {
169 const RTLIB::Libcall Op;
170 const RTLIB::LibcallImpl Impl;
171 } LibraryCalls[] = {
172 {RTLIB::SDIV_I32, RTLIB::impl___hexagon_divsi3},
173 {RTLIB::SDIV_I64, RTLIB::impl___hexagon_divdi3},
174 {RTLIB::UDIV_I32, RTLIB::impl___hexagon_udivsi3},
175 {RTLIB::UDIV_I64, RTLIB::impl___hexagon_udivdi3},
176 {RTLIB::SREM_I32, RTLIB::impl___hexagon_modsi3},
177 {RTLIB::SREM_I64, RTLIB::impl___hexagon_moddi3},
178 {RTLIB::UREM_I32, RTLIB::impl___hexagon_umodsi3},
179 {RTLIB::UREM_I64, RTLIB::impl___hexagon_umoddi3},
180 {RTLIB::ADD_F64, RTLIB::impl___hexagon_adddf3},
181 {RTLIB::SUB_F64, RTLIB::impl___hexagon_subdf3},
182 {RTLIB::MUL_F64, RTLIB::impl___hexagon_muldf3},
183 {RTLIB::DIV_F64, RTLIB::impl___hexagon_divdf3},
184 {RTLIB::DIV_F32, RTLIB::impl___hexagon_divsf3},
185 };
186 for (const auto &LC : LibraryCalls)
187 Info.setLibcallImpl(LC.Op, LC.Impl);
188}
189
190bool HexagonSubtarget::isHVXElementType(MVT Ty, bool IncludeBool) const {
191 if (!useHVXOps())
192 return false;
193 if (Ty.isVector())
194 Ty = Ty.getVectorElementType();
195 if (IncludeBool && Ty == MVT::i1)
196 return true;
197 ArrayRef<MVT> ElemTypes = getHVXElementTypes();
198 return llvm::is_contained(ElemTypes, Ty);
199}
200
201bool HexagonSubtarget::isHVXVectorType(EVT VecTy, bool IncludeBool) const {
202 if (!VecTy.isSimple())
203 return false;
204 if (!VecTy.isVector() || !useHVXOps() || VecTy.isScalableVector())
205 return false;
207 if (!IncludeBool && ElemTy == MVT::i1)
208 return false;
209
210 unsigned HwLen = getVectorLength();
211 unsigned NumElems = VecTy.getVectorNumElements();
212 ArrayRef<MVT> ElemTypes = getHVXElementTypes();
213
214 if (IncludeBool && ElemTy == MVT::i1) {
215 // Boolean HVX vector types are formed from regular HVX vector types
216 // by replacing the element type with i1.
217 for (MVT T : ElemTypes)
218 if (NumElems * T.getSizeInBits() == 8 * HwLen)
219 return true;
220 return false;
221 }
222
223 unsigned VecWidth = VecTy.getSizeInBits();
224 if (VecWidth != 8 * HwLen && VecWidth != 16 * HwLen)
225 return false;
226 return llvm::is_contained(ElemTypes, ElemTy);
227}
228
229bool HexagonSubtarget::isTypeForHVX(Type *VecTy, bool IncludeBool) const {
230 if (!VecTy->isVectorTy() || isa<ScalableVectorType>(VecTy))
231 return false;
232 // HLX types have their own legalization path and never go through HVX.
233 if (useHLXOps() && isTypeForHLX(VecTy))
234 return false;
235 // Avoid types like <2 x i32*>.
236 Type *ScalTy = VecTy->getScalarType();
237 if (!ScalTy->isIntegerTy() &&
238 !(ScalTy->isFloatingPointTy() && useHVXFloatingPoint()))
239 return false;
240 // The given type may be something like <17 x i32>, which is not MVT,
241 // but can be represented as (non-simple) EVT.
242 EVT Ty = EVT::getEVT(VecTy, /*HandleUnknown*/false);
243 if (!Ty.getVectorElementType().isSimple())
244 return false;
245
246 auto isHvxTy = [this, IncludeBool](MVT SimpleTy) {
247 if (isHVXVectorType(SimpleTy, IncludeBool))
248 return true;
249 auto Action = getTargetLowering()->getPreferredVectorAction(SimpleTy);
251 };
252
253 // Round up EVT to have power-of-2 elements, and keep checking if it
254 // qualifies for HVX, dividing it in half after each step.
255 MVT ElemTy = Ty.getVectorElementType().getSimpleVT();
256 unsigned VecLen = PowerOf2Ceil(Ty.getVectorNumElements());
257 while (VecLen > 1) {
258 MVT SimpleTy = MVT::getVectorVT(ElemTy, VecLen);
259 if (SimpleTy.isValid() && isHvxTy(SimpleTy))
260 return true;
261 VecLen /= 2;
262 }
263
264 return false;
265}
266
268 if (!useHLXOps())
269 return false;
270 if (Ty.isVector())
271 Ty = Ty.getVectorElementType();
272 ArrayRef<MVT> ElemTypes = getHLXElementTypes();
273 return llvm::is_contained(ElemTypes, Ty);
274}
275
277 if (!VecTy.isSimple())
278 return false;
279 if (!VecTy.isVector() || !useHLXOps() || VecTy.isScalableVector())
280 return false;
282
283 unsigned HwLen = getHLXVectorLength();
284 ArrayRef<MVT> ElemTypes = getHLXElementTypes();
285
286 unsigned VecWidth = VecTy.getSizeInBits();
287 if (VecWidth != 8 * HwLen && VecWidth != 16 * HwLen)
288 return false;
289 return llvm::is_contained(ElemTypes, ElemTy);
290}
291
293 if (!VecTy->isVectorTy() || isa<ScalableVectorType>(VecTy))
294 return false;
295 // Avoid types like <2 x i32*>.
296 Type *ScalTy = VecTy->getScalarType();
297 if (!ScalTy->isIntegerTy() && !ScalTy->isFloatingPointTy())
298 return false;
299 // The given type may be something like <17 x i32>, which is not MVT,
300 // but can be represented as (non-simple) EVT.
301 EVT Ty = EVT::getEVT(VecTy, /*HandleUnknown*/ false);
302 if (!Ty.getVectorElementType().isSimple())
303 return false;
304
305 auto isHLXTy = [this](MVT SimpleTy) {
306 if (isHLXVectorType(SimpleTy))
307 return true;
308 // No widening for now
309 return false;
310 };
311
312 // Round up EVT to have power-of-2 elements, and keep checking if it
313 // qualifies for HLX, dividing it in half after each step.
314 MVT ElemTy = Ty.getVectorElementType().getSimpleVT();
315 unsigned VecLen = PowerOf2Ceil(Ty.getVectorNumElements());
316 while (VecLen > 1) {
317 MVT SimpleTy = MVT::getVectorVT(ElemTy, VecLen);
318 if (SimpleTy.isValid() && isHLXTy(SimpleTy))
319 return true;
320 VecLen /= 2;
321 }
322
323 return false;
324}
325
327 for (SUnit &SU : DAG->SUnits) {
328 if (!SU.isInstr())
329 continue;
331 for (auto &D : SU.Preds)
332 if (D.getKind() == SDep::Output && D.getReg() == Hexagon::USR_OVF)
333 Erase.push_back(D);
334 for (auto &E : Erase)
335 SU.removePred(E);
336 }
337}
338
340 for (SUnit &SU : DAG->SUnits) {
341 // Update the latency of chain edges between v60 vector load or store
342 // instructions to be 1. These instruction cannot be scheduled in the
343 // same packet.
344 MachineInstr &MI1 = *SU.getInstr();
345 auto *QII = static_cast<const HexagonInstrInfo*>(DAG->TII);
346 bool IsStoreMI1 = MI1.mayStore();
347 bool IsLoadMI1 = MI1.mayLoad();
348 if (!QII->isHVXVec(MI1) || !(IsStoreMI1 || IsLoadMI1))
349 continue;
350 for (SDep &SI : SU.Succs) {
351 if (SI.getKind() != SDep::Order || SI.getLatency() != 0)
352 continue;
353 MachineInstr &MI2 = *SI.getSUnit()->getInstr();
354 if (!QII->isHVXVec(MI2))
355 continue;
356 if ((IsStoreMI1 && MI2.mayStore()) || (IsLoadMI1 && MI2.mayLoad())) {
357 SI.setLatency(1);
358 SU.setHeightDirty();
359 // Change the dependence in the opposite direction too.
360 for (SDep &PI : SI.getSUnit()->Preds) {
361 if (PI.getSUnit() != &SU || PI.getKind() != SDep::Order)
362 continue;
363 PI.setLatency(1);
364 SI.getSUnit()->setDepthDirty();
365 }
366 }
367 }
368 }
369}
370
371// Ensure that HMX activate and weight instructions are scheduled together.
372// The main idea is to:
373// 1. Reduce any latency between corresponding A/W to 0.
374// 2. Make the depths of corresponding A/W instructions be the same. (The
375// post-RA scheduler is a top-down list scheduler.)
377 ScheduleDAGInstrs *DAG) {
378 if (DAG->SUnits.empty())
379 return;
380
381 auto &HII = static_cast<const HexagonInstrInfo &>(*DAG->TII);
382 DenseMap<SUnit *, SUnit *> AWMap; // Map: Activation <-> Weight.
383 DenseSet<SUnit *> First; // Which of the two came first.
384 // The SUnits in the DAG follow the order of instructions. The code below
385 // depends on it to pair up activation and weight instructions.
386 SUnit *A = nullptr, *W = nullptr;
387 for (SUnit &SU : DAG->SUnits) {
388 MachineInstr *MI = SU.getInstr();
389 if (HII.isHMXActivateInstr(*MI)) {
390 assert(A == nullptr && "Unexpected activation instruction");
391 A = &SU;
392 if (!W)
393 First.insert(A);
394 } else if (HII.isHMXWeightInstr(*MI)) {
395 assert(W == nullptr && "Unexpected weight instruction");
396 W = &SU;
397 if (!A)
398 First.insert(W);
399 }
400 if (A && W) {
401 AWMap.insert({A, W});
402 AWMap.insert({W, A});
403 A = W = nullptr;
404 }
405 }
406 assert(A == nullptr && "Unmatched activation instruction");
407 assert(W == nullptr && "Unmatched weight instruction");
408
409 // Reset the latency between matching instructions to 0.
410 for (SUnit *FirstSU : First) {
411 SUnit *SecondSU = AWMap.lookup(FirstSU);
412 // Set the successor latency to 0.
413 for (SDep &D : FirstSU->Succs) {
414 if (D.getSUnit() == SecondSU) {
415 D.setLatency(0);
416 FirstSU->setHeightDirty();
417 }
418 }
419 // Set the predecessor latency to 0.
420 for (SDep &D : SecondSU->Preds) {
421 if (D.getSUnit() == FirstSU) {
422 D.setLatency(0);
423 SecondSU->setDepthDirty();
424 }
425 }
426 }
427
428 SUnit *Entry = &DAG->SUnits[0];
429 assert(Entry->getDepth() == 0);
430
431 // For each pair, reset the depth (max distance from the entry) to be the
432 // max of the two. We can't just set the depth directly, because the post-RA
433 // scheduler recalculates it during scheduling. There are also assertions
434 // in it that can fire when the depth on the node is inconsistent with the
435 // calculations.
436 // To avoid this issue, make the depth "real" by adding a fake edge from
437 // the Entry node (which is assumed to have a depth of 0).
438 // Adding a new edge will mark the depths of successors (recursively)
439 // as dirty, potentially including subsequent pairs. The "getDepth" call
440 // will recompute a dirty depth, so it's important to iterate over the nodes
441 // in such a way that predecessors are visited first.
442 //
443 // Skip the first SUnit in case it's an A/W instruction, so that we don't
444 // try to create an edge from that node to itself.
445 for (SUnit &SU : MutableArrayRef<SUnit>(DAG->SUnits).drop_front()) {
446 if (!First.count(&SU))
447 continue;
448 SUnit *FirstSU = &SU;
449 SUnit *SecondSU = AWMap.lookup(FirstSU);
450 unsigned MaxDepth = std::max(FirstSU->getDepth(), SecondSU->getDepth());
451 SDep DepthEdge(Entry, SDep::Artificial);
452 DepthEdge.setLatency(MaxDepth);
453 FirstSU->addPred(DepthEdge);
454 SecondSU->addPred(DepthEdge);
455 }
456}
457
458// Check if a call and subsequent A2_tfrpi instructions should maintain
459// scheduling affinity. We are looking for the TFRI to be consumed in
460// the next instruction. This should help reduce the instances of
461// double register pairs being allocated and scheduled before a call
462// when not used until after the call. This situation is exacerbated
463// by the fact that we allocate the pair from the callee saves list,
464// leading to excess spills and restores.
465bool HexagonSubtarget::CallMutation::shouldTFRICallBind(
466 const HexagonInstrInfo &HII, const SUnit &Inst1,
467 const SUnit &Inst2) const {
468 if (Inst1.getInstr()->getOpcode() != Hexagon::A2_tfrpi)
469 return false;
470
471 // TypeXTYPE are 64 bit operations.
472 unsigned Type = HII.getType(*Inst2.getInstr());
475}
476
478 ScheduleDAGMI *DAG = static_cast<ScheduleDAGMI*>(DAGInstrs);
479 SUnit* LastSequentialCall = nullptr;
480 // Map from virtual register to physical register from the copy.
481 DenseMap<unsigned, unsigned> VRegHoldingReg;
482 // Map from the physical register to the instruction that uses virtual
483 // register. This is used to create the barrier edge.
484 DenseMap<unsigned, SUnit *> LastVRegUse;
485 auto &TRI = *DAG->MF.getSubtarget().getRegisterInfo();
486 auto &HII = *DAG->MF.getSubtarget<HexagonSubtarget>().getInstrInfo();
487 const HexagonOptions &CLOpts =
489
490 // Currently we only catch the situation when compare gets scheduled
491 // before preceding call.
492 for (unsigned su = 0, e = DAG->SUnits.size(); su != e; ++su) {
493 // Remember the call.
494 if (DAG->SUnits[su].getInstr()->isCall())
495 LastSequentialCall = &DAG->SUnits[su];
496 // Look for a compare that defines a predicate.
497 else if (DAG->SUnits[su].getInstr()->isCompare() && LastSequentialCall)
498 DAG->addEdge(&DAG->SUnits[su], SDep(LastSequentialCall, SDep::Barrier));
499 // Look for call and tfri* instructions.
500 else if (CLOpts.sched_preds_closer && LastSequentialCall && su > 1 &&
501 su < e - 1 &&
502 shouldTFRICallBind(HII, DAG->SUnits[su], DAG->SUnits[su + 1]))
503 DAG->addEdge(&DAG->SUnits[su], SDep(&DAG->SUnits[su-1], SDep::Barrier));
504 // Prevent redundant register copies due to reads and writes of physical
505 // registers. The original motivation for this was the code generated
506 // between two calls, which are caused both the return value and the
507 // argument for the next call being in %r0.
508 // Example:
509 // 1: <call1>
510 // 2: %vreg = COPY %r0
511 // 3: <use of %vreg>
512 // 4: %r0 = ...
513 // 5: <call2>
514 // The scheduler would often swap 3 and 4, so an additional register is
515 // needed. This code inserts a Barrier dependence between 3 & 4 to prevent
516 // this.
517 // The code below checks for all the physical registers, not just R0/D0/V0.
518 else if (CLOpts.sched_retval_optimization) {
519 const MachineInstr *MI = DAG->SUnits[su].getInstr();
520 if (MI->isCopy() && MI->getOperand(1).getReg().isPhysical()) {
521 // %vregX = COPY %r0
522 VRegHoldingReg[MI->getOperand(0).getReg()] = MI->getOperand(1).getReg();
523 LastVRegUse.erase(MI->getOperand(1).getReg());
524 } else {
525 for (const MachineOperand &MO : MI->operands()) {
526 if (!MO.isReg())
527 continue;
528 if (MO.isUse() && !MI->isCopy() &&
529 VRegHoldingReg.count(MO.getReg())) {
530 // <use of %vregX>
531 LastVRegUse[VRegHoldingReg[MO.getReg()]] = &DAG->SUnits[su];
532 } else if (MO.isDef() && MO.getReg().isPhysical()) {
533 for (MCRegAliasIterator AI(MO.getReg(), &TRI, true); AI.isValid();
534 ++AI) {
535 if (auto It = LastVRegUse.find(*AI); It != LastVRegUse.end()) {
536 if (It->second != &DAG->SUnits[su])
537 // %r0 = ...
538 DAG->addEdge(&DAG->SUnits[su],
539 SDep(It->second, SDep::Barrier));
540 LastVRegUse.erase(It);
541 }
542 }
543 }
544 }
545 }
546 }
547 }
548}
549
550namespace {
551// Address of a load in the form used by the bank conflict check:
552// (Base << Shift) + Sym + Offset
553// Sym is null when the offset is a plain immediate.
554struct BankAddr {
556 unsigned Shift = 0;
557 const GlobalValue *Sym = nullptr;
558 int64_t Offset = 0;
559 uint64_t Size = 0;
560};
561} // end anonymous namespace
562
563// Decompose a scalar load into a BankAddr. Handles the base + offset form,
564// with either an immediate (memw(Rs+#s11)) or a global address
565// (memw(Rs+##sym)) as the offset, and the shifted-register + global form
566// (memw(Rt<<#u2+##sym)).
567static std::optional<BankAddr> getBankAddr(const MachineInstr &MI,
568 const HexagonInstrInfo &HII) {
569 if (!MI.mayLoad() || MI.mayStore() || HII.isMemOp(MI) ||
570 HII.isPostIncrement(MI) || HII.isHLXVec(MI))
571 return std::nullopt;
572 unsigned AddrMode = HII.getAddrMode(MI);
575 return std::nullopt;
576
577 // Operand 0 is the loaded value; the address operands follow.
578 unsigned BasePos = 1;
579 if (HII.isPredicated(MI))
580 ++BasePos;
581
582 BankAddr A;
583 unsigned OffsetPos = BasePos + 1;
585 // Rt << #u2 + ##u32
586 const MachineOperand &ShiftOp = MI.getOperand(BasePos + 1);
587 if (!ShiftOp.isImm())
588 return std::nullopt;
589 A.Shift = ShiftOp.getImm();
590 ++OffsetPos;
591 }
592
593 const MachineOperand &BaseOp = MI.getOperand(BasePos);
594 if (!BaseOp.isReg() || BaseOp.getSubReg() != 0)
595 return std::nullopt;
596 A.Base = BaseOp.getReg();
597
598 const MachineOperand &OffsetOp = MI.getOperand(OffsetPos);
599 if (OffsetOp.isImm()) {
600 A.Offset = OffsetOp.getImm();
601 } else if (OffsetOp.isGlobal()) {
602 // Only a direct reference to the symbol tells where it is relative to the
603 // bank boundaries; GOT, TLS and other relocations do not.
604 if ((OffsetOp.getTargetFlags() & ~HexagonII::HMOTF_ConstExtended) !=
606 return std::nullopt;
607 A.Sym = OffsetOp.getGlobal();
608 A.Offset = OffsetOp.getOffset();
609 } else {
610 return std::nullopt;
611 }
612
613 A.Size = HII.getMemAccessSize(MI);
614 return A;
615}
616
617// Return true if the offsets of the two loads can be compared to decide
618// whether they map to the same bank, i.e. whether the symbols (if any)
619// contribute the same value to the bank bits of the address.
620static bool haveComparableSyms(const BankAddr &A0, const BankAddr &A1,
621 const DataLayout &DL) {
622 if (A0.Sym == A1.Sym)
623 return true;
624 // Different symbols: the linker places each one independently, so their
625 // low address bits are known only from their alignment. A symbol aligned to
626 // the bank period (32 bytes) does not affect the bank bits, the same as a
627 // plain immediate offset (null Sym).
628 const Align BankPeriod(32);
629 auto HasKnownBankBits = [&](const GlobalValue *Sym) {
630 return !Sym || Sym->getPointerAlignment(DL) >= BankPeriod;
631 };
632 return HasKnownBankBits(A0.Sym) && HasKnownBankBits(A1.Sym);
633}
634
635// Return true if loads MI0 and MI1 likely map to the same cache bank and
636// should not be issued in the same packet. If IgnoreSameLine is true, loads
637// that likely read the same cache line, which cannot conflict, are not
638// reported.
640 const MachineInstr &MI1,
641 const HexagonInstrInfo &HII,
642 bool IgnoreSameLine) const {
643 if (!CLOpts.check_bank_conflict)
644 return false;
645 std::optional<BankAddr> A0 = getBankAddr(MI0, HII);
646 // Skip accesses as large as the L1 cache line.
647 if (!A0 || A0->Size == 0 || A0->Size >= 32)
648 return false;
649 std::optional<BankAddr> A1 = getBankAddr(MI1, HII);
650 if (!A1 || A1->Size == 0 || A1->Size >= 32 || A0->Base != A1->Base ||
651 A0->Shift != A1->Shift ||
652 !haveComparableSyms(*A0, *A1, MI0.getMF()->getDataLayout()))
653 return false;
654 // A bank conflict needs two different cache lines. As the bank check
655 // below does, assume the base is 32-byte aligned: offsets within the same
656 // 32-byte block then read the same line and cannot conflict.
657 if (IgnoreSameLine && A0->Sym == A1->Sym &&
658 (A0->Offset & ~int64_t(31)) == (A1->Offset & ~int64_t(31)))
659 return false;
660 // Compare the bank bits of the two offsets. If any of them differ, the
661 // loads go to different banks and can share a packet.
662 //
663 // Which address bits select the bank depends on the access sizes:
664 //
665 // Load pair Bank bits Mask
666 // ----------------------------------------- --------- ----
667 // double word + any load 4:3 0x18
668 // word/half-word/byte + word/half-word/byte 4:2 0x1C
669 //
670 // Bit 2 only tells two loads apart when neither of them is a double word.
671 // A double word covers both words of its 8-byte slot, so once one is
672 // involved, offsets that differ only in bit 2 still count as a conflict.
673 // Example (same base):
674 // memw(Rs+#0) and memw(Rs+#4) differ in bit 2 -> no conflict
675 // memw(Rs+#0) and memh(Rs+#4) differ in bit 2 -> no conflict
676 // memd(Rs+#0) and memw(Rs+#4) match on 4:3 -> conflict
677 // memd(Rs+#0) and memd(Rs+#8) differ in bit 3 -> no conflict
678 bool HasDoubleWord = A0->Size == 8 || A1->Size == 8;
679 int64_t BankMask = HasDoubleWord ? 0x18 : 0x1C;
680 return ((A0->Offset ^ A1->Offset) & BankMask) == 0;
681}
682
684 const auto &HST = DAG->MF.getSubtarget<HexagonSubtarget>();
685 if (!HST.getCLOpts().check_bank_conflict)
686 return;
687
688 const auto &HII = static_cast<const HexagonInstrInfo&>(*DAG->TII);
689
690 // Create artificial edges between loads that could likely cause a bank
691 // conflict. Since such loads would normally not have any dependency
692 // between them, we cannot rely on existing edges.
693 for (unsigned i = 0, e = DAG->SUnits.size(); i != e; ++i) {
694 SUnit &S0 = DAG->SUnits[i];
695 if (!getBankAddr(*S0.getInstr(), HII))
696 continue;
697 // Scan only up to 32 instructions ahead (to avoid n^2 complexity).
698 for (unsigned j = i+1, m = std::min(i+32, e); j != m; ++j) {
699 SUnit &S1 = DAG->SUnits[j];
700 // Use the conservative check here: the edge only guides the scheduler,
701 // and the packetizer decides whether the loads can share a packet.
702 if (!HST.mayHaveBankConflict(*S0.getInstr(), *S1.getInstr(), HII,
703 /*IgnoreSameLine=*/false))
704 continue;
705 // The loads likely conflict: add an artificial edge and set extra
706 // latency.
707 SDep A(&S0, SDep::Artificial);
708 A.setLatency(1);
709 S1.addPred(A, true);
710 }
711 }
712}
713
715 const auto &HII = static_cast<const HexagonInstrInfo &>(*DAG->TII);
716 const auto &HST = DAG->MF.getSubtarget<HexagonSubtarget>();
717 if (!HST.useHLXOps())
718 return;
719
720 auto setLatency = [](SUnit &From, SUnit &To) {
721 for (SDep &Dep : From.Succs)
722 if (Dep.getSUnit() == &To && Dep.getKind() == SDep::Data)
723 Dep.setLatency(0);
724 for (SDep &Dep : To.Preds)
725 if (Dep.getSUnit() == &From && Dep.getKind() == SDep::Data)
726 Dep.setLatency(0);
727 };
728
729 for (SUnit &SU : DAG->SUnits) {
730 if (!SU.isInstr())
731 continue;
732
733 MachineInstr &MI = *SU.getInstr();
734 if (HII.isTmpLoadPseudo(MI)) {
735 for (SDep &Dep : SU.Succs)
736 if (Dep.getKind() == SDep::Data)
737 setLatency(SU, *Dep.getSUnit());
738 } else if (HII.isNewStorePseudo(MI)) {
739 for (SDep &Dep : SU.Preds)
740 if (Dep.getKind() == SDep::Data)
741 setLatency(*Dep.getSUnit(), SU);
742 }
743 }
744}
745
746/// Enable use of alias analysis during code generation (during MI
747/// scheduling, DAGCombine, etc.).
750 return true;
751 return false;
752}
753
754/// Perform target specific adjustments to the latency of a schedule
755/// dependency.
757 SUnit *Src, int SrcOpIdx, SUnit *Dst, int DstOpIdx, SDep &Dep,
758 const TargetSchedModel *SchedModel) const {
759 if (!Src->isInstr() || !Dst->isInstr())
760 return;
761
762 MachineInstr *SrcInst = Src->getInstr();
763 MachineInstr *DstInst = Dst->getInstr();
764 const HexagonInstrInfo *QII = getInstrInfo();
765
766 // Instructions with .new operands have zero latency.
769 if (QII->canExecuteInBundle(*SrcInst, *DstInst) &&
770 isBestZeroLatency(Src, Dst, QII, ExclSrc, ExclDst)) {
771 Dep.setLatency(0);
772 return;
773 }
774
775 // Set the latency for a copy to zero since we hope that is will get
776 // removed.
777 if (DstInst->isCopy())
778 Dep.setLatency(0);
779
780 // If it's a REG_SEQUENCE/COPY, use its destination instruction to determine
781 // the correct latency.
782 // If there are multiple uses of the def of COPY/REG_SEQUENCE, set the latency
783 // only if the latencies on all the uses are equal, otherwise set it to
784 // default.
785 if ((DstInst->isRegSequence() || DstInst->isCopy())) {
786 Register DReg = DstInst->getOperand(0).getReg();
787 std::optional<unsigned> DLatency;
788 for (const auto &DDep : Dst->Succs) {
789 MachineInstr *DDst = DDep.getSUnit()->getInstr();
790 int UseIdx = -1;
791 for (unsigned OpNum = 0; OpNum < DDst->getNumOperands(); OpNum++) {
792 const MachineOperand &MO = DDst->getOperand(OpNum);
793 if (MO.isReg() && MO.getReg() && MO.isUse() && MO.getReg() == DReg) {
794 UseIdx = OpNum;
795 break;
796 }
797 }
798
799 if (UseIdx == -1)
800 continue;
801
802 std::optional<unsigned> Latency =
803 InstrInfo.getOperandLatency(&InstrItins, *SrcInst, 0, *DDst, UseIdx);
804
805 // Set DLatency for the first time.
806 if (!DLatency)
807 DLatency = Latency;
808
809 // For multiple uses, if the Latency is different across uses, reset
810 // DLatency.
811 if (DLatency != Latency) {
812 DLatency = std::nullopt;
813 break;
814 }
815 }
816 Dep.setLatency(DLatency.value_or(0));
817 }
818
819 // Try to schedule uses near definitions to generate .cur.
820 ExclSrc.clear();
821 ExclDst.clear();
822 if (CLOpts.cur_sched && QII->isToBeScheduledASAP(*SrcInst, *DstInst) &&
823 isBestZeroLatency(Src, Dst, QII, ExclSrc, ExclDst)) {
824 Dep.setLatency(0);
825 return;
826 }
827 int Latency = Dep.getLatency();
828 bool IsArtificial = Dep.isArtificial();
829 Latency = updateLatency(*SrcInst, *DstInst, IsArtificial, Latency);
830 Dep.setLatency(Latency);
831}
832
834 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
835 Mutations.push_back(std::make_unique<UsrOverflowMutation>());
836 Mutations.push_back(std::make_unique<HVXMemLatencyMutation>());
837 Mutations.push_back(std::make_unique<HMXActivateWeightMutation>());
838 Mutations.push_back(std::make_unique<BankConflictMutation>());
839 Mutations.push_back(std::make_unique<HLXPseudoMutation>());
840}
841
843 std::vector<std::unique_ptr<ScheduleDAGMutation>> &Mutations) const {
844 Mutations.push_back(std::make_unique<UsrOverflowMutation>());
845 Mutations.push_back(std::make_unique<HVXMemLatencyMutation>());
846 Mutations.push_back(std::make_unique<HMXActivateWeightMutation>());
847}
848
849// Pin the vtable to this file.
850void HexagonSubtarget::anchor() {}
851
852bool HexagonSubtarget::enableMachineScheduler() const { return CLOpts.misched; }
853
854bool HexagonSubtarget::usePredicatedCalls() const { return CLOpts.pred_calls; }
855
857 MachineInstr &DstInst, bool IsArtificial,
858 int Latency) const {
859 if (IsArtificial)
860 return 1;
861 if (!hasV60Ops())
862 return Latency;
863
864 const HexagonInstrInfo &QII = *getInstrInfo();
865 // BSB scheduling.
866 if (QII.isHVXVec(SrcInst) || useBSBScheduling())
867 Latency = (Latency + 1) >> 1;
868 return Latency;
869}
870
871void HexagonSubtarget::restoreLatency(SUnit *Src, SUnit *Dst) const {
872 MachineInstr *SrcI = Src->getInstr();
873 for (auto &I : Src->Succs) {
874 if (!I.isAssignedRegDep() || I.getSUnit() != Dst)
875 continue;
876 Register DepR = I.getReg();
877 int DefIdx = -1;
878 for (unsigned OpNum = 0; OpNum < SrcI->getNumOperands(); OpNum++) {
879 const MachineOperand &MO = SrcI->getOperand(OpNum);
880 bool IsSameOrSubReg = false;
881 if (MO.isReg()) {
882 Register MOReg = MO.getReg();
883 if (DepR.isVirtual()) {
884 IsSameOrSubReg = (MOReg == DepR);
885 } else {
886 IsSameOrSubReg = getRegisterInfo()->isSubRegisterEq(DepR, MOReg);
887 }
888 if (MO.isDef() && IsSameOrSubReg)
889 DefIdx = OpNum;
890 }
891 }
892 assert(DefIdx >= 0 && "Def Reg not found in Src MI");
893 MachineInstr *DstI = Dst->getInstr();
894 SDep T = I;
895 for (unsigned OpNum = 0; OpNum < DstI->getNumOperands(); OpNum++) {
896 const MachineOperand &MO = DstI->getOperand(OpNum);
897 if (MO.isReg() && MO.isUse() && MO.getReg() == DepR) {
898 std::optional<unsigned> OpLatency = InstrInfo.getOperandLatency(
899 &InstrItins, *SrcI, DefIdx, *DstI, OpNum);
900
901 // For some instructions (ex: COPY), we might end up with < 0 latency
902 // as they don't have any Itinerary class associated with them.
903 bool IsArtificial = I.isArtificial();
904 int Latency =
905 updateLatency(*SrcI, *DstI, IsArtificial, OpLatency.value_or(0));
906 I.setLatency(Latency);
907 }
908 }
909
910 // Update the latency of opposite edge too.
911 T.setSUnit(Src);
912 auto F = find(Dst->Preds, T);
913 assert(F != Dst->Preds.end());
914 F->setLatency(I.getLatency());
915 }
916}
917
918/// Change the latency between the two SUnits.
919void HexagonSubtarget::changeLatency(SUnit *Src, SUnit *Dst, unsigned Lat)
920 const {
921 for (auto &I : Src->Succs) {
922 if (!I.isAssignedRegDep() || I.getSUnit() != Dst)
923 continue;
924 SDep T = I;
925 I.setLatency(Lat);
926
927 // Update the latency of opposite edge too.
928 T.setSUnit(Src);
929 auto F = find(Dst->Preds, T);
930 assert(F != Dst->Preds.end());
931 F->setLatency(Lat);
932 }
933}
934
935/// If the SUnit has a zero latency edge, return the other SUnit.
937 for (auto &I : Deps)
938 if (I.isAssignedRegDep() && I.getLatency() == 0 &&
939 !I.getSUnit()->getInstr()->isPseudo())
940 return I.getSUnit();
941 return nullptr;
942}
943
944// Return true if these are the best two instructions to schedule
945// together with a zero latency. Only one dependence should have a zero
946// latency. If there are multiple choices, choose the best, and change
947// the others, if needed.
948bool HexagonSubtarget::isBestZeroLatency(
949 SUnit *Src, SUnit *Dst, const HexagonInstrInfo *TII,
950 SmallPtrSet<SUnit *, 4> &ExclSrc, SmallPtrSet<SUnit *, 4> &ExclDst) const {
951 MachineInstr &SrcInst = *Src->getInstr();
952 MachineInstr &DstInst = *Dst->getInstr();
953
954 // Ignore Boundary SU nodes as these have null instructions.
955 if (Dst->isBoundaryNode())
956 return false;
957
958 if (SrcInst.isPHI() || DstInst.isPHI())
959 return false;
960
961 if (!TII->isToBeScheduledASAP(SrcInst, DstInst) &&
962 !TII->canExecuteInBundle(SrcInst, DstInst))
963 return false;
964
965 // The architecture doesn't allow three dependent instructions in the same
966 // packet. So, if the destination has a zero latency successor, then it's
967 // not a candidate for a zero latency predecessor.
968 if (getZeroLatency(Dst, Dst->Succs) != nullptr)
969 return false;
970
971 // Check if the Dst instruction is the best candidate first.
972 SUnit *Best = nullptr;
973 SUnit *DstBest = nullptr;
974 SUnit *SrcBest = getZeroLatency(Dst, Dst->Preds);
975 if (SrcBest == nullptr || Src->NodeNum >= SrcBest->NodeNum) {
976 // Check that Src doesn't have a better candidate.
977 DstBest = getZeroLatency(Src, Src->Succs);
978 if (DstBest == nullptr || Dst->NodeNum <= DstBest->NodeNum)
979 Best = Dst;
980 }
981 if (Best != Dst)
982 return false;
983
984 // The caller frequently adds the same dependence twice. If so, then
985 // return true for this case too.
986 if ((Src == SrcBest && Dst == DstBest ) ||
987 (SrcBest == nullptr && Dst == DstBest) ||
988 (Src == SrcBest && Dst == nullptr))
989 return true;
990
991 // Reassign the latency for the previous bests, which requires setting
992 // the dependence edge in both directions.
993 if (SrcBest != nullptr) {
994 if (!hasV60Ops())
995 changeLatency(SrcBest, Dst, 1);
996 else
997 restoreLatency(SrcBest, Dst);
998 }
999 if (DstBest != nullptr) {
1000 if (!hasV60Ops())
1001 changeLatency(Src, DstBest, 1);
1002 else
1003 restoreLatency(Src, DstBest);
1004 }
1005
1006 // Attempt to find another opportunity for zero latency in a different
1007 // dependence.
1008 if (SrcBest && DstBest)
1009 // If there is an edge from SrcBest to DstBst, then try to change that
1010 // to 0 now.
1011 changeLatency(SrcBest, DstBest, 0);
1012 else if (DstBest) {
1013 // Check if the previous best destination instruction has a new zero
1014 // latency dependence opportunity.
1015 ExclSrc.insert(Src);
1016 for (auto &I : DstBest->Preds)
1017 if (ExclSrc.count(I.getSUnit()) == 0 &&
1018 isBestZeroLatency(I.getSUnit(), DstBest, TII, ExclSrc, ExclDst))
1019 changeLatency(I.getSUnit(), DstBest, 0);
1020 } else if (SrcBest) {
1021 // Check if previous best source instruction has a new zero latency
1022 // dependence opportunity.
1023 ExclDst.insert(Dst);
1024 for (auto &I : SrcBest->Succs)
1025 if (ExclDst.count(I.getSUnit()) == 0 &&
1026 isBestZeroLatency(SrcBest, I.getSUnit(), TII, ExclSrc, ExclDst))
1027 changeLatency(SrcBest, I.getSUnit(), 0);
1028 }
1029
1030 return true;
1031}
1032
1034 return 32;
1035}
1036
1038 return 32;
1039}
1040
1041bool HexagonSubtarget::enableSubRegLiveness() const { return true; }
1042
1044 struct Scalar {
1045 unsigned Opcode;
1046 Intrinsic::ID IntId;
1047 };
1048 struct Hvx {
1049 unsigned Opcode;
1050 Intrinsic::ID Int64Id, Int128Id;
1051 };
1052
1053 static Scalar ScalarInts[] = {
1054#define GET_SCALAR_INTRINSICS
1056#undef GET_SCALAR_INTRINSICS
1057 };
1058
1059 static Hvx HvxInts[] = {
1060#define GET_HVX_INTRINSICS
1062#undef GET_HVX_INTRINSICS
1063 };
1064
1065 const auto CmpOpcode = [](auto A, auto B) { return A.Opcode < B.Opcode; };
1066 [[maybe_unused]] static bool SortedScalar =
1067 (llvm::sort(ScalarInts, CmpOpcode), true);
1068 [[maybe_unused]] static bool SortedHvx =
1069 (llvm::sort(HvxInts, CmpOpcode), true);
1070
1071 auto [BS, ES] = std::make_pair(std::begin(ScalarInts), std::end(ScalarInts));
1072 auto [BH, EH] = std::make_pair(std::begin(HvxInts), std::end(HvxInts));
1073
1074 auto FoundScalar = std::lower_bound(BS, ES, Scalar{Opc, 0}, CmpOpcode);
1075 if (FoundScalar != ES && FoundScalar->Opcode == Opc)
1076 return FoundScalar->IntId;
1077
1078 auto FoundHvx = std::lower_bound(BH, EH, Hvx{Opc, 0, 0}, CmpOpcode);
1079 if (FoundHvx != EH && FoundHvx->Opcode == Opc) {
1080 unsigned HwLen = getVectorLength();
1081 if (HwLen == 64)
1082 return FoundHvx->Int64Id;
1083 if (HwLen == 128)
1084 return FoundHvx->Int128Id;
1085 }
1086
1087 std::string error = "Invalid opcode (" + std::to_string(Opc) + ")";
1088 llvm_unreachable(error.c_str());
1089 return 0;
1090}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
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 bool haveComparableSyms(const BankAddr &A0, const BankAddr &A1, const DataLayout &DL)
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.
IRTranslator LLVM IR MI
std::pair< Instruction::BinaryOps, Value * > OffsetOp
Find all possible pairs (BinOp, RHS) that BinOp V, RHS can be simplified.
unsigned Opc
#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:63
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)
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,...
const HexagonOptions & getCLOpts() const
bool mayHaveBankConflict(const MachineInstr &MI0, const MachineInstr &MI1, const HexagonInstrInfo &HII, bool IgnoreSameLine=true) const
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)
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
constexpr bool valueOr(BoolOrDefault X, bool Default)
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