1//===- HexagonMCInstrInfo.cpp - Hexagon sub-class of MCInst ---------------===//
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 class extends MCInstrInfo to allow Hexagon specific MCInstr queries
10//
11//===----------------------------------------------------------------------===//
12
13#include "MCTargetDesc/HexagonMCInstrInfo.h"
14#include "MCTargetDesc/HexagonBaseInfo.h"
15#include "MCTargetDesc/HexagonMCChecker.h"
16#include "MCTargetDesc/HexagonMCExpr.h"
17#include "MCTargetDesc/HexagonMCShuffler.h"
18#include "MCTargetDesc/HexagonMCTargetDesc.h"
19#include "llvm/ADT/SmallVector.h"
20#include "llvm/ADT/StringSwitch.h"
21#include "llvm/MC/MCContext.h"
22#include "llvm/MC/MCExpr.h"
23#include "llvm/MC/MCInst.h"
24#include "llvm/MC/MCInstrInfo.h"
25#include "llvm/MC/MCInstrItineraries.h"
26#include "llvm/MC/MCSubtargetInfo.h"
27#include "llvm/Support/Casting.h"
28#include "llvm/Support/ErrorHandling.h"
29#include <cassert>
30#include <cstdint>
31#include <limits>
32
33using namespace llvm;
34
35bool HexagonMCInstrInfo::PredicateInfo::isPredicated() const {
36 return Register != Hexagon::NoRegister;
37}
38
39Hexagon::PacketIterator::PacketIterator(MCInstrInfo const &MCII,
40 MCInst const &Inst)
41 : MCII(MCII), BundleCurrent(Inst.begin() +
42 HexagonMCInstrInfo::bundleInstructionsOffset),
43 BundleEnd(Inst.end()), DuplexCurrent(Inst.end()), DuplexEnd(Inst.end()) {}
44
45Hexagon::PacketIterator::PacketIterator(MCInstrInfo const &MCII,
46 MCInst const &Inst, std::nullptr_t)
47 : MCII(MCII), BundleCurrent(Inst.end()), BundleEnd(Inst.end()),
48 DuplexCurrent(Inst.end()), DuplexEnd(Inst.end()) {}
49
50Hexagon::PacketIterator &Hexagon::PacketIterator::operator++() {
51 if (DuplexCurrent != DuplexEnd) {
52 ++DuplexCurrent;
53 if (DuplexCurrent == DuplexEnd) {
54 DuplexCurrent = BundleEnd;
55 DuplexEnd = BundleEnd;
56 ++BundleCurrent;
57 }
58 return *this;
59 }
60 ++BundleCurrent;
61 if (BundleCurrent != BundleEnd) {
62 MCInst const &Inst = *BundleCurrent->getInst();
63 if (HexagonMCInstrInfo::isDuplex(MCII, MCI: Inst)) {
64 DuplexCurrent = Inst.begin();
65 DuplexEnd = Inst.end();
66 }
67 }
68 return *this;
69}
70
71MCInst const &Hexagon::PacketIterator::operator*() const {
72 if (DuplexCurrent != DuplexEnd)
73 return *DuplexCurrent->getInst();
74 return *BundleCurrent->getInst();
75}
76
77bool Hexagon::PacketIterator::operator==(PacketIterator const &Other) const {
78 return BundleCurrent == Other.BundleCurrent && BundleEnd == Other.BundleEnd &&
79 DuplexCurrent == Other.DuplexCurrent && DuplexEnd == Other.DuplexEnd;
80}
81
82void HexagonMCInstrInfo::addConstant(MCInst &MI, uint64_t Value,
83 MCContext &Context) {
84 MI.addOperand(Op: MCOperand::createExpr(Val: MCConstantExpr::create(Value, Ctx&: Context)));
85}
86
87void HexagonMCInstrInfo::addConstExtender(MCContext &Context,
88 MCInstrInfo const &MCII, MCInst &MCB,
89 MCInst const &MCI) {
90 assert(HexagonMCInstrInfo::isBundle(MCB));
91 MCOperand const &exOp =
92 MCI.getOperand(i: HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
93
94 // Create the extender.
95 MCInst *XMCI =
96 new (Context) MCInst(HexagonMCInstrInfo::deriveExtender(MCII, Inst: MCI, MO: exOp));
97 XMCI->setLoc(MCI.getLoc());
98
99 MCB.addOperand(Op: MCOperand::createInst(Val: XMCI));
100}
101
102iterator_range<Hexagon::PacketIterator>
103HexagonMCInstrInfo::bundleInstructions(MCInstrInfo const &MCII,
104 MCInst const &MCI) {
105 assert(isBundle(MCI));
106 return make_range(x: Hexagon::PacketIterator(MCII, MCI),
107 y: Hexagon::PacketIterator(MCII, MCI, nullptr));
108}
109
110iterator_range<MCInst::const_iterator>
111HexagonMCInstrInfo::bundleInstructions(MCInst const &MCI) {
112 assert(isBundle(MCI));
113 return drop_begin(RangeOrContainer: MCI, N: bundleInstructionsOffset);
114}
115
116size_t HexagonMCInstrInfo::bundleSize(MCInst const &MCI) {
117 if (HexagonMCInstrInfo::isBundle(MCI))
118 return (MCI.size() - bundleInstructionsOffset);
119 else
120 return (1);
121}
122
123namespace {
124bool canonicalizePacketImpl(MCInstrInfo const &MCII, MCSubtargetInfo const &STI,
125 MCContext &Context, MCInst &MCB,
126 HexagonMCChecker *Check) {
127 // Check the bundle for errors.
128 bool CheckOk = Check ? Check->check(FullCheck: false) : true;
129 if (!CheckOk)
130 return false;
131
132 // Examine the packet and convert pairs of instructions to compound
133 // instructions when possible.
134 if (!HexagonDisableCompound)
135 HexagonMCInstrInfo::tryCompound(MCII, STI, Context, MCI&: MCB);
136 HexagonMCShuffle(Context, ReportErrors: false, MCII, STI, MCB);
137
138 const SmallVector<DuplexCandidate, 8> possibleDuplexes =
139 (STI.hasFeature(Feature: Hexagon::FeatureDuplex))
140 ? HexagonMCInstrInfo::getDuplexPossibilties(MCII, STI, MCB)
141 : SmallVector<DuplexCandidate, 8>();
142
143 // Examine the packet and convert pairs of instructions to duplex
144 // instructions when possible.
145 HexagonMCShuffle(Context, MCII, STI, MCB, possibleDuplexes);
146
147 // Examines packet and pad the packet, if needed, when an
148 // end-loop is in the bundle.
149 HexagonMCInstrInfo::padEndloop(MCI&: MCB, Context);
150
151 // If compounding and duplexing didn't reduce the size below
152 // 4 or less we have a packet that is too big.
153 if (HexagonMCInstrInfo::bundleSize(MCI: MCB) > HEXAGON_PACKET_SIZE) {
154 if (Check)
155 Check->reportError(Msg: "invalid instruction packet: out of slots");
156 return false;
157 }
158 // Check the bundle for errors.
159 CheckOk = Check ? Check->check(FullCheck: true) : true;
160 if (!CheckOk)
161 return false;
162
163 HexagonMCShuffle(Context, ReportErrors: true, MCII, STI, MCB);
164
165 return true;
166}
167} // namespace
168
169bool HexagonMCInstrInfo::canonicalizePacket(MCInstrInfo const &MCII,
170 MCSubtargetInfo const &STI,
171 MCContext &Context, MCInst &MCB,
172 HexagonMCChecker *Check,
173 bool AttemptCompatibility) {
174 auto ArchSTI = Hexagon_MC::getArchSubtarget(STI: &STI);
175 if (!AttemptCompatibility || ArchSTI == nullptr)
176 return canonicalizePacketImpl(MCII, STI, Context, MCB, Check);
177
178 const MCRegisterInfo *RI = Context.getRegisterInfo();
179 HexagonMCChecker DefaultCheck(Context, MCII, STI, MCB, *RI, false);
180 HexagonMCChecker *BaseCheck = (Check == nullptr) ? &DefaultCheck : Check;
181 HexagonMCChecker PerfCheck(*BaseCheck, STI, false);
182 if (canonicalizePacketImpl(MCII, STI, Context, MCB, Check: &PerfCheck))
183 return true;
184
185 HexagonMCChecker ArchCheck(*BaseCheck, *ArchSTI, true);
186 return canonicalizePacketImpl(MCII, STI: *ArchSTI, Context, MCB, Check: &ArchCheck);
187}
188
189MCInst HexagonMCInstrInfo::deriveExtender(MCInstrInfo const &MCII,
190 MCInst const &Inst,
191 MCOperand const &MO) {
192 assert(HexagonMCInstrInfo::isExtendable(MCII, Inst) ||
193 HexagonMCInstrInfo::isExtended(MCII, Inst));
194
195 MCInst XMI;
196 XMI.setOpcode(Hexagon::A4_ext);
197 if (MO.isImm())
198 XMI.addOperand(Op: MCOperand::createImm(Val: MO.getImm() & (~0x3f)));
199 else if (MO.isExpr())
200 XMI.addOperand(Op: MCOperand::createExpr(Val: MO.getExpr()));
201 else
202 llvm_unreachable("invalid extendable operand");
203 return XMI;
204}
205
206MCInst *HexagonMCInstrInfo::deriveDuplex(MCContext &Context, unsigned iClass,
207 MCInst const &inst0,
208 MCInst const &inst1) {
209 assert((iClass <= 0xf) && "iClass must have range of 0 to 0xf");
210 MCInst *duplexInst = new (Context) MCInst;
211 duplexInst->setOpcode(Hexagon::DuplexIClass0 + iClass);
212
213 MCInst *SubInst0 = new (Context) MCInst(deriveSubInst(Inst: inst0));
214 MCInst *SubInst1 = new (Context) MCInst(deriveSubInst(Inst: inst1));
215 duplexInst->addOperand(Op: MCOperand::createInst(Val: SubInst0));
216 duplexInst->addOperand(Op: MCOperand::createInst(Val: SubInst1));
217 return duplexInst;
218}
219
220MCInst const *HexagonMCInstrInfo::extenderForIndex(MCInst const &MCB,
221 size_t Index) {
222 assert(Index <= bundleSize(MCB));
223 if (Index == 0)
224 return nullptr;
225 MCInst const *Inst =
226 MCB.getOperand(i: Index + bundleInstructionsOffset - 1).getInst();
227 if (isImmext(MCI: *Inst))
228 return Inst;
229 return nullptr;
230}
231
232void HexagonMCInstrInfo::extendIfNeeded(MCContext &Context,
233 MCInstrInfo const &MCII, MCInst &MCB,
234 MCInst const &MCI) {
235 if (isConstExtended(MCII, MCI))
236 addConstExtender(Context, MCII, MCB, MCI);
237}
238
239unsigned HexagonMCInstrInfo::getMemAccessSize(MCInstrInfo const &MCII,
240 MCInst const &MCI) {
241 uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
242 unsigned S = (F >> HexagonII::MemAccessSizePos) & HexagonII::MemAccesSizeMask;
243 return HexagonII::getMemAccessSizeInBytes(S: HexagonII::MemAccessSize(S));
244}
245
246unsigned HexagonMCInstrInfo::getAddrMode(MCInstrInfo const &MCII,
247 MCInst const &MCI) {
248 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
249 return static_cast<unsigned>((F >> HexagonII::AddrModePos) &
250 HexagonII::AddrModeMask);
251}
252
253MCInstrDesc const &HexagonMCInstrInfo::getDesc(MCInstrInfo const &MCII,
254 MCInst const &MCI) {
255 return MCII.get(Opcode: MCI.getOpcode());
256}
257
258unsigned HexagonMCInstrInfo::getDuplexRegisterNumbering(MCRegister Reg) {
259 using namespace Hexagon;
260
261 switch (Reg.id()) {
262 default:
263 llvm_unreachable("unknown duplex register");
264 // Rs Rss
265 case R0:
266 case D0:
267 return 0;
268 case R1:
269 case D1:
270 return 1;
271 case R2:
272 case D2:
273 return 2;
274 case R3:
275 case D3:
276 return 3;
277 case R4:
278 case D8:
279 return 4;
280 case R5:
281 case D9:
282 return 5;
283 case R6:
284 case D10:
285 return 6;
286 case R7:
287 case D11:
288 return 7;
289 case R16:
290 return 8;
291 case R17:
292 return 9;
293 case R18:
294 return 10;
295 case R19:
296 return 11;
297 case R20:
298 return 12;
299 case R21:
300 return 13;
301 case R22:
302 return 14;
303 case R23:
304 return 15;
305 }
306}
307
308MCExpr const &HexagonMCInstrInfo::getExpr(MCExpr const &Expr) {
309 const auto &HExpr = cast<HexagonMCExpr>(Val: Expr);
310 assert(HExpr.getExpr());
311 return *HExpr.getExpr();
312}
313
314unsigned short HexagonMCInstrInfo::getExtendableOp(MCInstrInfo const &MCII,
315 MCInst const &MCI) {
316 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
317 return ((F >> HexagonII::ExtendableOpPos) & HexagonII::ExtendableOpMask);
318}
319
320MCOperand const &
321HexagonMCInstrInfo::getExtendableOperand(MCInstrInfo const &MCII,
322 MCInst const &MCI) {
323 unsigned O = HexagonMCInstrInfo::getExtendableOp(MCII, MCI);
324 MCOperand const &MO = MCI.getOperand(i: O);
325
326 assert((HexagonMCInstrInfo::isExtendable(MCII, MCI) ||
327 HexagonMCInstrInfo::isExtended(MCII, MCI)) &&
328 (MO.isImm() || MO.isExpr()));
329 return (MO);
330}
331
332unsigned HexagonMCInstrInfo::getExtentAlignment(MCInstrInfo const &MCII,
333 MCInst const &MCI) {
334 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
335 return ((F >> HexagonII::ExtentAlignPos) & HexagonII::ExtentAlignMask);
336}
337
338unsigned HexagonMCInstrInfo::getExtentBits(MCInstrInfo const &MCII,
339 MCInst const &MCI) {
340 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
341 return ((F >> HexagonII::ExtentBitsPos) & HexagonII::ExtentBitsMask);
342}
343
344bool HexagonMCInstrInfo::isExtentSigned(MCInstrInfo const &MCII,
345 MCInst const &MCI) {
346 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
347 return (F >> HexagonII::ExtentSignedPos) & HexagonII::ExtentSignedMask;
348}
349
350/// Return the maximum value of an extendable operand.
351int HexagonMCInstrInfo::getMaxValue(MCInstrInfo const &MCII,
352 MCInst const &MCI) {
353 assert(HexagonMCInstrInfo::isExtendable(MCII, MCI) ||
354 HexagonMCInstrInfo::isExtended(MCII, MCI));
355
356 if (HexagonMCInstrInfo::isExtentSigned(MCII, MCI)) // if value is signed
357 return (1 << (HexagonMCInstrInfo::getExtentBits(MCII, MCI) - 1)) - 1;
358 return (1 << HexagonMCInstrInfo::getExtentBits(MCII, MCI)) - 1;
359}
360
361/// Return the minimum value of an extendable operand.
362int HexagonMCInstrInfo::getMinValue(MCInstrInfo const &MCII,
363 MCInst const &MCI) {
364 assert(HexagonMCInstrInfo::isExtendable(MCII, MCI) ||
365 HexagonMCInstrInfo::isExtended(MCII, MCI));
366
367 if (HexagonMCInstrInfo::isExtentSigned(MCII, MCI)) // if value is signed
368 return -(1 << (HexagonMCInstrInfo::getExtentBits(MCII, MCI) - 1));
369 return 0;
370}
371
372StringRef HexagonMCInstrInfo::getName(MCInstrInfo const &MCII,
373 MCInst const &MCI) {
374 return MCII.getName(Opcode: MCI.getOpcode());
375}
376
377unsigned short HexagonMCInstrInfo::getNewValueOp(MCInstrInfo const &MCII,
378 MCInst const &MCI) {
379 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
380 return ((F >> HexagonII::NewValueOpPos) & HexagonII::NewValueOpMask);
381}
382
383MCOperand const &HexagonMCInstrInfo::getNewValueOperand(MCInstrInfo const &MCII,
384 MCInst const &MCI) {
385 if (HexagonMCInstrInfo::hasTmpDst(MCII, MCI)) {
386 // VTMP doesn't actually exist in the encodings for these 184
387 // 3 instructions so go ahead and create it here.
388 static MCOperand MCO = MCOperand::createReg(Reg: Hexagon::VTMP);
389 return (MCO);
390 } else {
391 unsigned O = HexagonMCInstrInfo::getNewValueOp(MCII, MCI);
392 MCOperand const &MCO = MCI.getOperand(i: O);
393
394 assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) ||
395 HexagonMCInstrInfo::hasNewValue(MCII, MCI)) &&
396 MCO.isReg());
397 return (MCO);
398 }
399}
400
401/// Return the new value or the newly produced value.
402unsigned short HexagonMCInstrInfo::getNewValueOp2(MCInstrInfo const &MCII,
403 MCInst const &MCI) {
404 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
405 return ((F >> HexagonII::NewValueOpPos2) & HexagonII::NewValueOpMask2);
406}
407
408MCOperand const &
409HexagonMCInstrInfo::getNewValueOperand2(MCInstrInfo const &MCII,
410 MCInst const &MCI) {
411 unsigned O = HexagonMCInstrInfo::getNewValueOp2(MCII, MCI);
412 MCOperand const &MCO = MCI.getOperand(i: O);
413
414 assert((HexagonMCInstrInfo::isNewValue(MCII, MCI) ||
415 HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) &&
416 MCO.isReg());
417 return (MCO);
418}
419
420/// Return the Hexagon ISA class for the insn.
421unsigned HexagonMCInstrInfo::getType(MCInstrInfo const &MCII,
422 MCInst const &MCI) {
423 const uint64_t F = MCII.get(Opcode: MCI.getOpcode()).TSFlags;
424 return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
425}
426
427/// Return the resources used by this instruction
428unsigned HexagonMCInstrInfo::getCVIResources(MCInstrInfo const &MCII,
429 MCSubtargetInfo const &STI,
430 MCInst const &MCI) {
431
432 const InstrItinerary *II = STI.getSchedModel().InstrItineraries;
433 int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
434 int Size = II[SchedClass].LastStage - II[SchedClass].FirstStage;
435
436 // HVX resources used are currently located at the second to last stage.
437 // This could also be done with a linear search of the stages looking for:
438 // CVI_ALL, CVI_MPY01, CVI_XLSHF, CVI_MPY0, CVI_MPY1, CVI_SHIFT, CVI_XLANE,
439 // CVI_ZW
440 unsigned Stage = II[SchedClass].LastStage - 1;
441
442 if (Size < 2)
443 return 0;
444 return ((Stage + HexagonStages)->getUnits());
445}
446
447/// Return the slots this instruction can execute out of
448unsigned HexagonMCInstrInfo::getUnits(MCInstrInfo const &MCII,
449 MCSubtargetInfo const &STI,
450 MCInst const &MCI) {
451 const InstrItinerary *II = STI.getSchedModel().InstrItineraries;
452 int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
453 return ((II[SchedClass].FirstStage + HexagonStages)->getUnits());
454}
455
456/// Return the slots this instruction consumes in addition to
457/// the slot(s) it can execute out of
458
459unsigned HexagonMCInstrInfo::getOtherReservedSlots(MCInstrInfo const &MCII,
460 MCSubtargetInfo const &STI,
461 MCInst const &MCI) {
462 const InstrItinerary *II = STI.getSchedModel().InstrItineraries;
463 int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
464 unsigned Slots = 0;
465
466 // FirstStage are slots that this instruction can execute in.
467 // FirstStage+1 are slots that are also consumed by this instruction.
468 // For example: vmemu can only execute in slot 0 but also consumes slot 1.
469 for (unsigned Stage = II[SchedClass].FirstStage + 1;
470 Stage < II[SchedClass].LastStage; ++Stage) {
471 unsigned Units = (Stage + HexagonStages)->getUnits();
472 if (Units > HexagonGetLastSlot())
473 break;
474 // fyi: getUnits() will return 0x1, 0x2, 0x4 or 0x8
475 Slots |= Units;
476 }
477
478 // if 0 is returned, then no additional slots are consumed by this inst.
479 return Slots;
480}
481
482bool HexagonMCInstrInfo::hasDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
483 if (!HexagonMCInstrInfo::isBundle(MCI))
484 return false;
485
486 for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
487 if (HexagonMCInstrInfo::isDuplex(MCII, MCI: *I.getInst()))
488 return true;
489 }
490
491 return false;
492}
493
494bool HexagonMCInstrInfo::hasExtenderForIndex(MCInst const &MCB, size_t Index) {
495 return extenderForIndex(MCB, Index) != nullptr;
496}
497
498bool HexagonMCInstrInfo::hasImmExt(MCInst const &MCI) {
499 if (!HexagonMCInstrInfo::isBundle(MCI))
500 return false;
501
502 for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
503 if (isImmext(MCI: *I.getInst()))
504 return true;
505 }
506
507 return false;
508}
509
510/// Return whether the insn produces a value.
511bool HexagonMCInstrInfo::hasNewValue(MCInstrInfo const &MCII,
512 MCInst const &MCI) {
513 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
514 return ((F >> HexagonII::hasNewValuePos) & HexagonII::hasNewValueMask);
515}
516
517/// Return whether the insn produces a second value.
518bool HexagonMCInstrInfo::hasNewValue2(MCInstrInfo const &MCII,
519 MCInst const &MCI) {
520 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
521 return ((F >> HexagonII::hasNewValuePos2) & HexagonII::hasNewValueMask2);
522}
523
524MCInst const &HexagonMCInstrInfo::instruction(MCInst const &MCB, size_t Index) {
525 assert(isBundle(MCB));
526 assert(Index < HEXAGON_PRESHUFFLE_PACKET_SIZE);
527 return *MCB.getOperand(i: bundleInstructionsOffset + Index).getInst();
528}
529
530/// Return where the instruction is an accumulator.
531bool HexagonMCInstrInfo::isAccumulator(MCInstrInfo const &MCII,
532 MCInst const &MCI) {
533 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
534 return ((F >> HexagonII::AccumulatorPos) & HexagonII::AccumulatorMask);
535}
536
537bool HexagonMCInstrInfo::isBundle(MCInst const &MCI) {
538 auto Result = Hexagon::BUNDLE == MCI.getOpcode();
539 assert(!Result || (MCI.size() > 0 && MCI.getOperand(0).isImm()));
540 return Result;
541}
542
543bool HexagonMCInstrInfo::isConstExtended(MCInstrInfo const &MCII,
544 MCInst const &MCI) {
545 if (HexagonMCInstrInfo::isExtended(MCII, MCI))
546 return true;
547 if (!HexagonMCInstrInfo::isExtendable(MCII, MCI))
548 return false;
549 MCOperand const &MO = HexagonMCInstrInfo::getExtendableOperand(MCII, MCI);
550 if (isa<HexagonMCExpr>(Val: MO.getExpr()) &&
551 HexagonMCInstrInfo::mustExtend(Expr: *MO.getExpr()))
552 return true;
553 // Branch insns are handled as necessary by relaxation.
554 if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeJ) ||
555 (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCJ &&
556 HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()) ||
557 (HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeNCJ &&
558 HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()))
559 return false;
560 // Otherwise loop instructions and other CR insts are handled by relaxation
561 else if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCR) &&
562 (MCI.getOpcode() != Hexagon::C4_addipc))
563 return false;
564
565 assert(!MO.isImm());
566 if (isa<HexagonMCExpr>(Val: MO.getExpr()) &&
567 HexagonMCInstrInfo::mustNotExtend(Expr: *MO.getExpr()))
568 return false;
569
570 int64_t Value;
571 if (!MO.getExpr()->evaluateAsAbsolute(Res&: Value))
572 return true;
573 if (HexagonMCInstrInfo::isExtentSigned(MCII, MCI)) {
574 int32_t SValue = Value;
575 int32_t MinValue = HexagonMCInstrInfo::getMinValue(MCII, MCI);
576 int32_t MaxValue = HexagonMCInstrInfo::getMaxValue(MCII, MCI);
577 return SValue < MinValue || SValue > MaxValue;
578 }
579 uint32_t UValue = Value;
580 uint32_t MinValue = HexagonMCInstrInfo::getMinValue(MCII, MCI);
581 uint32_t MaxValue = HexagonMCInstrInfo::getMaxValue(MCII, MCI);
582 return UValue < MinValue || UValue > MaxValue;
583}
584
585bool HexagonMCInstrInfo::isCanon(MCInstrInfo const &MCII, MCInst const &MCI) {
586 return !HexagonMCInstrInfo::getDesc(MCII, MCI).isPseudo() &&
587 !HexagonMCInstrInfo::isPrefix(MCII, MCI);
588}
589
590bool HexagonMCInstrInfo::isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI) {
591 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
592 return ((F >> HexagonII::CofMax1Pos) & HexagonII::CofMax1Mask);
593}
594
595bool HexagonMCInstrInfo::isCofRelax1(MCInstrInfo const &MCII,
596 MCInst const &MCI) {
597 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
598 return ((F >> HexagonII::CofRelax1Pos) & HexagonII::CofRelax1Mask);
599}
600
601bool HexagonMCInstrInfo::isCofRelax2(MCInstrInfo const &MCII,
602 MCInst const &MCI) {
603 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
604 return ((F >> HexagonII::CofRelax2Pos) & HexagonII::CofRelax2Mask);
605}
606
607bool HexagonMCInstrInfo::isCompound(MCInstrInfo const &MCII,
608 MCInst const &MCI) {
609 return (getType(MCII, MCI) == HexagonII::TypeCJ);
610}
611
612bool HexagonMCInstrInfo::isCVINew(MCInstrInfo const &MCII, MCInst const &MCI) {
613 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
614 return ((F >> HexagonII::CVINewPos) & HexagonII::CVINewMask);
615}
616
617bool HexagonMCInstrInfo::isDblRegForSubInst(MCRegister Reg) {
618 return ((Reg >= Hexagon::D0 && Reg <= Hexagon::D3) ||
619 (Reg >= Hexagon::D8 && Reg <= Hexagon::D11));
620}
621
622bool HexagonMCInstrInfo::isDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
623 return HexagonII::TypeDUPLEX == HexagonMCInstrInfo::getType(MCII, MCI);
624}
625
626bool HexagonMCInstrInfo::isExtendable(MCInstrInfo const &MCII,
627 MCInst const &MCI) {
628 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
629 return (F >> HexagonII::ExtendablePos) & HexagonII::ExtendableMask;
630}
631
632bool HexagonMCInstrInfo::isExtended(MCInstrInfo const &MCII,
633 MCInst const &MCI) {
634 uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
635 return (F >> HexagonII::ExtendedPos) & HexagonII::ExtendedMask;
636}
637
638bool HexagonMCInstrInfo::isFloat(MCInstrInfo const &MCII, MCInst const &MCI) {
639 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
640 return ((F >> HexagonII::FPPos) & HexagonII::FPMask);
641}
642
643bool HexagonMCInstrInfo::isHVX(MCInstrInfo const &MCII, MCInst const &MCI) {
644 const uint64_t V = getType(MCII, MCI);
645 return HexagonII::TypeCVI_FIRST <= V && V <= HexagonII::TypeCVI_LAST;
646}
647
648bool HexagonMCInstrInfo::isHLX(MCInstrInfo const &MCII, MCInst const &MCI) {
649 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
650 return (F >> HexagonII::isHLXPos) & HexagonII::isHLXMask;
651}
652
653bool HexagonMCInstrInfo::isImmext(MCInst const &MCI) {
654 return MCI.getOpcode() == Hexagon::A4_ext;
655}
656
657bool HexagonMCInstrInfo::isInnerLoop(MCInst const &MCI) {
658 assert(isBundle(MCI));
659 int64_t Flags = MCI.getOperand(i: 0).getImm();
660 return (Flags & innerLoopMask) != 0;
661}
662
663bool HexagonMCInstrInfo::isIntReg(MCRegister Reg) {
664 return (Reg >= Hexagon::R0 && Reg <= Hexagon::R31);
665}
666
667bool HexagonMCInstrInfo::isIntRegForSubInst(MCRegister Reg) {
668 return ((Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
669 (Reg >= Hexagon::R16 && Reg <= Hexagon::R23));
670}
671
672/// Return whether the insn expects newly produced value.
673bool HexagonMCInstrInfo::isNewValue(MCInstrInfo const &MCII,
674 MCInst const &MCI) {
675 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
676 return ((F >> HexagonII::NewValuePos) & HexagonII::NewValueMask);
677}
678
679bool HexagonMCInstrInfo::isNewValueStore(MCInstrInfo const &MCII,
680 MCInst const &MCI) {
681 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
682 return (F >> HexagonII::NVStorePos) & HexagonII::NVStoreMask;
683}
684
685/// Return whether the operand is extendable.
686bool HexagonMCInstrInfo::isOpExtendable(MCInstrInfo const &MCII,
687 MCInst const &MCI, unsigned short O) {
688 return (O == HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
689}
690
691bool HexagonMCInstrInfo::isOuterLoop(MCInst const &MCI) {
692 assert(isBundle(MCI));
693 int64_t Flags = MCI.getOperand(i: 0).getImm();
694 return (Flags & outerLoopMask) != 0;
695}
696
697bool HexagonMCInstrInfo::IsVecRegPair(MCRegister VecReg) {
698 return (VecReg >= Hexagon::W0 && VecReg <= Hexagon::W15) ||
699 (VecReg >= Hexagon::WR0 && VecReg <= Hexagon::WR15);
700}
701
702bool HexagonMCInstrInfo::IsReverseVecRegPair(MCRegister VecReg) {
703 return (VecReg >= Hexagon::WR0 && VecReg <= Hexagon::WR15);
704}
705
706bool HexagonMCInstrInfo::IsVecRegSingle(MCRegister VecReg) {
707 return (VecReg >= Hexagon::V0 && VecReg <= Hexagon::V31);
708}
709
710std::pair<unsigned, unsigned>
711HexagonMCInstrInfo::GetVecRegPairIndices(MCRegister VecRegPair) {
712 assert(IsVecRegPair(VecRegPair) &&
713 "VecRegPair must be a vector register pair");
714
715 const bool IsRev = IsReverseVecRegPair(VecReg: VecRegPair);
716 const unsigned PairIndex =
717 2 * (IsRev ? VecRegPair - Hexagon::WR0 : VecRegPair - Hexagon::W0);
718
719 return IsRev ? std::make_pair(x: PairIndex, y: PairIndex + 1)
720 : std::make_pair(x: PairIndex + 1, y: PairIndex);
721}
722
723bool HexagonMCInstrInfo::IsSingleConsumerRefPairProducer(MCRegister Producer,
724 MCRegister Consumer) {
725 if (IsVecRegPair(VecReg: Producer) && IsVecRegSingle(VecReg: Consumer)) {
726 const unsigned ProdPairIndex = IsReverseVecRegPair(VecReg: Producer)
727 ? Producer - Hexagon::WR0
728 : Producer - Hexagon::W0;
729 const unsigned ConsumerSingleIndex = (Consumer - Hexagon::V0) >> 1;
730
731 return ConsumerSingleIndex == ProdPairIndex;
732 }
733 return false;
734}
735
736bool HexagonMCInstrInfo::isPredicated(MCInstrInfo const &MCII,
737 MCInst const &MCI) {
738 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
739 return ((F >> HexagonII::PredicatedPos) & HexagonII::PredicatedMask);
740}
741
742bool HexagonMCInstrInfo::isPrefix(MCInstrInfo const &MCII, MCInst const &MCI) {
743 return HexagonII::TypeEXTENDER == HexagonMCInstrInfo::getType(MCII, MCI);
744}
745
746bool HexagonMCInstrInfo::isPredicateLate(MCInstrInfo const &MCII,
747 MCInst const &MCI) {
748 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
749 return (F >> HexagonII::PredicateLatePos & HexagonII::PredicateLateMask);
750}
751
752/// Return whether the insn is newly predicated.
753bool HexagonMCInstrInfo::isPredicatedNew(MCInstrInfo const &MCII,
754 MCInst const &MCI) {
755 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
756 return ((F >> HexagonII::PredicatedNewPos) & HexagonII::PredicatedNewMask);
757}
758
759bool HexagonMCInstrInfo::isPredicatedTrue(MCInstrInfo const &MCII,
760 MCInst const &MCI) {
761 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
762 return (
763 !((F >> HexagonII::PredicatedFalsePos) & HexagonII::PredicatedFalseMask));
764}
765
766bool HexagonMCInstrInfo::isPredReg(MCRegisterInfo const &MRI, MCRegister Reg) {
767 auto &PredRegClass = MRI.getRegClass(i: Hexagon::PredRegsRegClassID);
768 return PredRegClass.contains(Reg);
769}
770
771bool HexagonMCInstrInfo::isPredRegister(MCInstrInfo const &MCII,
772 MCInst const &Inst, unsigned I) {
773 MCInstrDesc const &Desc = HexagonMCInstrInfo::getDesc(MCII, MCI: Inst);
774
775 return Inst.getOperand(i: I).isReg() &&
776 Desc.operands()[I].RegClass == Hexagon::PredRegsRegClassID;
777}
778
779/// Return whether the insn can be packaged only with A and X-type insns.
780bool HexagonMCInstrInfo::isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI) {
781 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
782 return ((F >> HexagonII::SoloAXPos) & HexagonII::SoloAXMask);
783}
784
785/// Return whether the insn can be packaged only with an A-type insn in slot #1.
786bool HexagonMCInstrInfo::isRestrictSlot1AOK(MCInstrInfo const &MCII,
787 MCInst const &MCI) {
788 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
789 return ((F >> HexagonII::RestrictSlot1AOKPos) &
790 HexagonII::RestrictSlot1AOKMask);
791}
792
793bool HexagonMCInstrInfo::isRestrictNoSlot1Store(MCInstrInfo const &MCII,
794 MCInst const &MCI) {
795 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
796 return ((F >> HexagonII::RestrictNoSlot1StorePos) &
797 HexagonII::RestrictNoSlot1StoreMask);
798}
799
800/// Return whether the insn is solo, i.e., cannot be in a packet.
801bool HexagonMCInstrInfo::isSolo(MCInstrInfo const &MCII, MCInst const &MCI) {
802 const uint64_t F = MCII.get(Opcode: MCI.getOpcode()).TSFlags;
803 return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask);
804}
805
806bool HexagonMCInstrInfo::isMemReorderDisabled(MCInst const &MCI) {
807 assert(isBundle(MCI));
808 auto Flags = MCI.getOperand(i: 0).getImm();
809 return (Flags & memReorderDisabledMask) != 0;
810}
811
812bool HexagonMCInstrInfo::isSubInstruction(MCInst const &MCI) {
813 switch (MCI.getOpcode()) {
814 default:
815 return false;
816 case Hexagon::SA1_addi:
817 case Hexagon::SA1_addrx:
818 case Hexagon::SA1_addsp:
819 case Hexagon::SA1_and1:
820 case Hexagon::SA1_clrf:
821 case Hexagon::SA1_clrfnew:
822 case Hexagon::SA1_clrt:
823 case Hexagon::SA1_clrtnew:
824 case Hexagon::SA1_cmpeqi:
825 case Hexagon::SA1_combine0i:
826 case Hexagon::SA1_combine1i:
827 case Hexagon::SA1_combine2i:
828 case Hexagon::SA1_combine3i:
829 case Hexagon::SA1_combinerz:
830 case Hexagon::SA1_combinezr:
831 case Hexagon::SA1_dec:
832 case Hexagon::SA1_inc:
833 case Hexagon::SA1_seti:
834 case Hexagon::SA1_setin1:
835 case Hexagon::SA1_sxtb:
836 case Hexagon::SA1_sxth:
837 case Hexagon::SA1_tfr:
838 case Hexagon::SA1_zxtb:
839 case Hexagon::SA1_zxth:
840 case Hexagon::SL1_loadri_io:
841 case Hexagon::SL1_loadrub_io:
842 case Hexagon::SL2_deallocframe:
843 case Hexagon::SL2_jumpr31:
844 case Hexagon::SL2_jumpr31_f:
845 case Hexagon::SL2_jumpr31_fnew:
846 case Hexagon::SL2_jumpr31_t:
847 case Hexagon::SL2_jumpr31_tnew:
848 case Hexagon::SL2_loadrb_io:
849 case Hexagon::SL2_loadrd_sp:
850 case Hexagon::SL2_loadrh_io:
851 case Hexagon::SL2_loadri_sp:
852 case Hexagon::SL2_loadruh_io:
853 case Hexagon::SL2_return:
854 case Hexagon::SL2_return_f:
855 case Hexagon::SL2_return_fnew:
856 case Hexagon::SL2_return_t:
857 case Hexagon::SL2_return_tnew:
858 case Hexagon::SS1_storeb_io:
859 case Hexagon::SS1_storew_io:
860 case Hexagon::SS2_allocframe:
861 case Hexagon::SS2_storebi0:
862 case Hexagon::SS2_storebi1:
863 case Hexagon::SS2_stored_sp:
864 case Hexagon::SS2_storeh_io:
865 case Hexagon::SS2_storew_sp:
866 case Hexagon::SS2_storewi0:
867 case Hexagon::SS2_storewi1:
868 return true;
869 }
870}
871
872bool HexagonMCInstrInfo::isVector(MCInstrInfo const &MCII, MCInst const &MCI) {
873 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
874 return (F >> HexagonII::isCVIPos) & HexagonII::isCVIMask;
875}
876
877int64_t HexagonMCInstrInfo::minConstant(MCInst const &MCI, size_t Index) {
878 auto Sentinel = static_cast<int64_t>(std::numeric_limits<uint32_t>::max())
879 << 8;
880 if (MCI.size() <= Index)
881 return Sentinel;
882 MCOperand const &MCO = MCI.getOperand(i: Index);
883 if (!MCO.isExpr())
884 return Sentinel;
885 int64_t Value;
886 if (!MCO.getExpr()->evaluateAsAbsolute(Res&: Value))
887 return Sentinel;
888 return Value;
889}
890
891void HexagonMCInstrInfo::setMustExtend(MCExpr const &Expr, bool Val) {
892 HexagonMCExpr &HExpr = const_cast<HexagonMCExpr &>(cast<HexagonMCExpr>(Val: Expr));
893 HExpr.setMustExtend(Val);
894}
895
896bool HexagonMCInstrInfo::mustExtend(MCExpr const &Expr) {
897 HexagonMCExpr const &HExpr = cast<HexagonMCExpr>(Val: Expr);
898 return HExpr.mustExtend();
899}
900void HexagonMCInstrInfo::setMustNotExtend(MCExpr const &Expr, bool Val) {
901 HexagonMCExpr &HExpr = const_cast<HexagonMCExpr &>(cast<HexagonMCExpr>(Val: Expr));
902 HExpr.setMustNotExtend(Val);
903}
904bool HexagonMCInstrInfo::mustNotExtend(MCExpr const &Expr) {
905 HexagonMCExpr const &HExpr = cast<HexagonMCExpr>(Val: Expr);
906 return HExpr.mustNotExtend();
907}
908void HexagonMCInstrInfo::setS27_2_reloc(MCExpr const &Expr, bool Val) {
909 HexagonMCExpr &HExpr =
910 const_cast<HexagonMCExpr &>(*cast<HexagonMCExpr>(Val: &Expr));
911 HExpr.setS27_2_reloc(Val);
912}
913bool HexagonMCInstrInfo::s27_2_reloc(MCExpr const &Expr) {
914 HexagonMCExpr const *HExpr = dyn_cast<HexagonMCExpr>(Val: &Expr);
915 if (!HExpr)
916 return false;
917 return HExpr->s27_2_reloc();
918}
919
920unsigned HexagonMCInstrInfo::packetSizeSlots(MCSubtargetInfo const &STI) {
921 const bool IsTiny = STI.hasFeature(Feature: Hexagon::ProcTinyCore);
922
923 return IsTiny ? (HEXAGON_PACKET_SIZE - 1) : HEXAGON_PACKET_SIZE;
924}
925
926unsigned HexagonMCInstrInfo::packetSize(StringRef CPU) {
927 return llvm::StringSwitch<unsigned>(CPU)
928 .Case(S: "hexagonv67t", Value: 3)
929 .Default(Value: 4);
930}
931
932void HexagonMCInstrInfo::padEndloop(MCInst &MCB, MCContext &Context) {
933 MCInst Nop;
934 Nop.setOpcode(Hexagon::A2_nop);
935 assert(isBundle(MCB));
936 while (LoopNeedsPadding(MCB))
937 MCB.addOperand(Op: MCOperand::createInst(Val: new (Context) MCInst(Nop)));
938}
939
940HexagonMCInstrInfo::PredicateInfo
941HexagonMCInstrInfo::predicateInfo(MCInstrInfo const &MCII, MCInst const &MCI) {
942 if (!isPredicated(MCII, MCI))
943 return {0, 0, false};
944 MCInstrDesc const &Desc = getDesc(MCII, MCI);
945 for (auto I = Desc.getNumDefs(), N = Desc.getNumOperands(); I != N; ++I)
946 if (Desc.operands()[I].RegClass == Hexagon::PredRegsRegClassID)
947 return {MCI.getOperand(i: I).getReg(), I, isPredicatedTrue(MCII, MCI)};
948 return {0, 0, false};
949}
950
951bool HexagonMCInstrInfo::prefersSlot3(MCInstrInfo const &MCII,
952 MCInst const &MCI) {
953 const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
954 return (F >> HexagonII::PrefersSlot3Pos) & HexagonII::PrefersSlot3Mask;
955}
956
957bool HexagonMCInstrInfo::hasTmpDst(MCInstrInfo const &MCII, MCInst const &MCI) {
958 switch (MCI.getOpcode()) {
959 default:
960 return false;
961 case Hexagon::V6_vgathermh:
962 case Hexagon::V6_vgathermhq:
963 case Hexagon::V6_vgathermhw:
964 case Hexagon::V6_vgathermhwq:
965 case Hexagon::V6_vgathermw:
966 case Hexagon::V6_vgathermwq:
967 return true;
968 }
969 return false;
970}
971
972bool HexagonMCInstrInfo::isTmpWrite(MCInstrInfo const &MCII,
973 MCInst const &MCI) {
974 const auto &MID = HexagonMCInstrInfo::getDesc(MCII, MCI);
975 return HexagonII::getTSFlag(MID, Pos: HexagonII::isTmpWritePos);
976}
977
978bool HexagonMCInstrInfo::requiresSlot(MCSubtargetInfo const &STI,
979 MCInst const &MCI) {
980 const unsigned OpCode = MCI.getOpcode();
981 const bool IsTiny = STI.getFeatureBits() [Hexagon::ProcTinyCore];
982 const bool NoSlotReqd = Hexagon::A4_ext == OpCode ||
983 (IsTiny && Hexagon::A2_nop == OpCode) ||
984 (IsTiny && Hexagon::J4_hintjumpr == OpCode);
985
986 return !NoSlotReqd;
987}
988
989unsigned HexagonMCInstrInfo::slotsConsumed(MCInstrInfo const &MCII,
990 MCSubtargetInfo const &STI,
991 MCInst const &MCI) {
992 unsigned slotsUsed = 0;
993 for (auto HMI : bundleInstructions(MCI)) {
994 MCInst const &MCI = *HMI.getInst();
995 if (!requiresSlot(STI, MCI))
996 continue;
997 if (isDuplex(MCII, MCI))
998 slotsUsed += 2;
999 else
1000 ++slotsUsed;
1001 }
1002 return slotsUsed;
1003}
1004
1005void HexagonMCInstrInfo::replaceDuplex(MCContext &Context, MCInst &MCB,
1006 DuplexCandidate Candidate) {
1007 assert(Candidate.packetIndexI < MCB.size());
1008 assert(Candidate.packetIndexJ < MCB.size());
1009 assert(isBundle(MCB));
1010 MCInst *Duplex =
1011 deriveDuplex(Context, iClass: Candidate.iClass,
1012 inst0: *MCB.getOperand(i: Candidate.packetIndexJ).getInst(),
1013 inst1: *MCB.getOperand(i: Candidate.packetIndexI).getInst());
1014 assert(Duplex != nullptr);
1015 MCB.getOperand(i: Candidate.packetIndexI).setInst(Duplex);
1016 MCB.erase(I: MCB.begin() + Candidate.packetIndexJ);
1017}
1018
1019void HexagonMCInstrInfo::setInnerLoop(MCInst &MCI) {
1020 assert(isBundle(MCI));
1021 MCOperand &Operand = MCI.getOperand(i: 0);
1022 Operand.setImm(Operand.getImm() | innerLoopMask);
1023}
1024
1025void HexagonMCInstrInfo::setMemReorderDisabled(MCInst &MCI) {
1026 assert(isBundle(MCI));
1027 MCOperand &Operand = MCI.getOperand(i: 0);
1028 Operand.setImm(Operand.getImm() | memReorderDisabledMask);
1029 assert(isMemReorderDisabled(MCI));
1030}
1031
1032void HexagonMCInstrInfo::setOuterLoop(MCInst &MCI) {
1033 assert(isBundle(MCI));
1034 MCOperand &Operand = MCI.getOperand(i: 0);
1035 Operand.setImm(Operand.getImm() | outerLoopMask);
1036}
1037
1038unsigned HexagonMCInstrInfo::SubregisterBit(MCRegister Consumer,
1039 MCRegister Producer,
1040 MCRegister Producer2) {
1041 // If we're a single vector consumer of a double producer, set subreg bit
1042 // based on if we're accessing the lower or upper register component
1043 if (IsVecRegPair(VecReg: Producer) && IsVecRegSingle(VecReg: Consumer)) {
1044 unsigned Rev = IsReverseVecRegPair(VecReg: Producer);
1045 return ((Consumer - Hexagon::V0) & 0x1) ^ Rev;
1046 }
1047 if (Producer2 != Hexagon::NoRegister)
1048 return Consumer == Producer;
1049 return 0;
1050}
1051
1052bool HexagonMCInstrInfo::isHMXWeight(MCInstrInfo const &MCII,
1053 MCInst const &MCI) {
1054 const auto &MID = HexagonMCInstrInfo::getDesc(MCII, MCI);
1055 return HexagonII::getTSFlag(MID, Pos: HexagonII::isHMXWeightPos);
1056}
1057
1058bool HexagonMCInstrInfo::isHMXActivation(MCInstrInfo const &MCII,
1059 MCInst const &MCI) {
1060 const auto &MID = HexagonMCInstrInfo::getDesc(MCII, MCI);
1061 return HexagonII::getTSFlag(MID, Pos: HexagonII::isHMXActivatePos);
1062}
1063
1064bool HexagonMCInstrInfo::LoopNeedsPadding(MCInst const &MCB) {
1065 return (
1066 (HexagonMCInstrInfo::isInnerLoop(MCI: MCB) &&
1067 (HexagonMCInstrInfo::bundleSize(MCI: MCB) < HEXAGON_PACKET_INNER_SIZE)) ||
1068 ((HexagonMCInstrInfo::isOuterLoop(MCI: MCB) &&
1069 (HexagonMCInstrInfo::bundleSize(MCI: MCB) < HEXAGON_PACKET_OUTER_SIZE))));
1070}
1071
1072bool HexagonMCInstrInfo::IsABranchingInst(MCInstrInfo const &MCII,
1073 MCSubtargetInfo const &STI,
1074 MCInst const &I) {
1075 assert(!HexagonMCInstrInfo::isBundle(I));
1076 MCInstrDesc const &Desc = HexagonMCInstrInfo::getDesc(MCII, MCI: I);
1077 return (Desc.isBranch() || Desc.isCall() || Desc.isReturn());
1078}
1079