LLVM  5.0.0
HexagonMCInstrInfo.cpp
Go to the documentation of this file.
1 //===- HexagonMCInstrInfo.cpp - Hexagon sub-class of MCInst ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class extends MCInstrInfo to allow Hexagon specific MCInstr queries
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "HexagonMCInstrInfo.h"
15 
16 #include "Hexagon.h"
17 #include "HexagonBaseInfo.h"
18 #include "HexagonMCChecker.h"
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCInstrInfo.h"
23 
24 namespace llvm {
25 
27  MCInst const &Inst)
28  : MCII(MCII), BundleCurrent(Inst.begin() +
29  HexagonMCInstrInfo::bundleInstructionsOffset),
30  BundleEnd(Inst.end()), DuplexCurrent(Inst.end()), DuplexEnd(Inst.end()) {}
31 
33  MCInst const &Inst, std::nullptr_t)
34  : MCII(MCII), BundleCurrent(Inst.end()), BundleEnd(Inst.end()),
35  DuplexCurrent(Inst.end()), DuplexEnd(Inst.end()) {}
36 
38  if (DuplexCurrent != DuplexEnd) {
39  ++DuplexCurrent;
40  if (DuplexCurrent == DuplexEnd) {
41  DuplexCurrent = BundleEnd;
42  DuplexEnd = BundleEnd;
43  }
44  return *this;
45  }
46  ++BundleCurrent;
47  if (BundleCurrent != BundleEnd) {
48  MCInst const &Inst = *BundleCurrent->getInst();
49  if (HexagonMCInstrInfo::isDuplex(MCII, Inst)) {
50  DuplexCurrent = Inst.begin();
51  DuplexEnd = Inst.end();
52  }
53  }
54  return *this;
55 }
56 
58  if (DuplexCurrent != DuplexEnd)
59  return *DuplexCurrent->getInst();
60  return *BundleCurrent->getInst();
61 }
62 
64  return BundleCurrent == Other.BundleCurrent && BundleEnd == Other.BundleEnd &&
65  DuplexCurrent == Other.DuplexCurrent && DuplexEnd == Other.DuplexEnd;
66 }
67 
69  MCContext &Context) {
71 }
72 
74  MCInstrInfo const &MCII, MCInst &MCB,
75  MCInst const &MCI) {
77  MCOperand const &exOp =
79 
80  // Create the extender.
81  MCInst *XMCI =
82  new (Context) MCInst(HexagonMCInstrInfo::deriveExtender(MCII, MCI, exOp));
83 
85 }
86 
89  MCInst const &MCI) {
90  assert(isBundle(MCI));
91  return make_range(Hexagon::PacketIterator(MCII, MCI),
92  Hexagon::PacketIterator(MCII, MCI, nullptr));
93 }
94 
97  assert(isBundle(MCI));
98  return make_range(MCI.begin() + bundleInstructionsOffset, MCI.end());
99 }
100 
103  return (MCI.size() - bundleInstructionsOffset);
104  else
105  return (1);
106 }
107 
109  MCSubtargetInfo const &STI,
110  MCContext &Context, MCInst &MCB,
112  // Check the bundle for errors.
113  bool CheckOk = Check ? Check->check(false) : true;
114  if (!CheckOk)
115  return false;
116  // Examine the packet and convert pairs of instructions to compound
117  // instructions when possible.
119  HexagonMCInstrInfo::tryCompound(MCII, STI, Context, MCB);
120  HexagonMCShuffle(Context, false, MCII, STI, MCB);
121  // Examine the packet and convert pairs of instructions to duplex
122  // instructions when possible.
123  MCInst InstBundlePreDuplex = MCInst(MCB);
124  if (!HexagonDisableDuplex) {
125  SmallVector<DuplexCandidate, 8> possibleDuplexes;
126  possibleDuplexes =
128  HexagonMCShuffle(Context, MCII, STI, MCB, possibleDuplexes);
129  }
130  // Examines packet and pad the packet, if needed, when an
131  // end-loop is in the bundle.
132  HexagonMCInstrInfo::padEndloop(MCB, Context);
133  // If compounding and duplexing didn't reduce the size below
134  // 4 or less we have a packet that is too big.
136  return false;
137  // Check the bundle for errors.
138  CheckOk = Check ? Check->check(true) : true;
139  if (!CheckOk)
140  return false;
141  HexagonMCShuffle(Context, true, MCII, STI, MCB);
142  return true;
143 }
144 
146  MCContext &Context, MCInst &MCI) {
148  HexagonMCInstrInfo::isExtended(MCII, MCI));
149  MCOperand &exOp =
151  // If the extended value is a constant, then use it for the extended and
152  // for the extender instructions, masking off the lower 6 bits and
153  // including the assumed bits.
154  int64_t Value;
155  if (exOp.getExpr()->evaluateAsAbsolute(Value)) {
156  unsigned Shift = HexagonMCInstrInfo::getExtentAlignment(MCII, MCI);
158  MCConstantExpr::create((Value & 0x3f) << Shift, Context), Context));
159  }
160 }
161 
163  MCInst Result;
164  Result.setOpcode(Hexagon::BUNDLE);
165  Result.addOperand(MCOperand::createImm(0));
166  return Result;
167 }
168 
170  MCInst const &Inst,
171  MCOperand const &MO) {
173  HexagonMCInstrInfo::isExtended(MCII, Inst));
174 
175  MCInst XMI;
176  XMI.setOpcode(Hexagon::A4_ext);
177  if (MO.isImm())
178  XMI.addOperand(MCOperand::createImm(MO.getImm() & (~0x3f)));
179  else if (MO.isExpr())
181  else
182  llvm_unreachable("invalid extendable operand");
183  return XMI;
184 }
185 
187  MCInst const &inst0,
188  MCInst const &inst1) {
189  assert((iClass <= 0xf) && "iClass must have range of 0 to 0xf");
190  MCInst *duplexInst = new (Context) MCInst;
191  duplexInst->setOpcode(Hexagon::DuplexIClass0 + iClass);
192 
193  MCInst *SubInst0 = new (Context) MCInst(deriveSubInst(inst0));
194  MCInst *SubInst1 = new (Context) MCInst(deriveSubInst(inst1));
195  duplexInst->addOperand(MCOperand::createInst(SubInst0));
196  duplexInst->addOperand(MCOperand::createInst(SubInst1));
197  return duplexInst;
198 }
199 
201  size_t Index) {
202  assert(Index <= bundleSize(MCB));
203  if (Index == 0)
204  return nullptr;
205  MCInst const *Inst =
206  MCB.getOperand(Index + bundleInstructionsOffset - 1).getInst();
207  if (isImmext(*Inst))
208  return Inst;
209  return nullptr;
210 }
211 
213  MCInstrInfo const &MCII, MCInst &MCB,
214  MCInst const &MCI) {
215  if (isConstExtended(MCII, MCI))
216  addConstExtender(Context, MCII, MCB, MCI);
217 }
218 
221  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
222 
225 }
226 
228  MCInst const &MCI) {
229  return MCII.get(MCI.getOpcode());
230 }
231 
233  using namespace Hexagon;
234  switch (Reg) {
235  default:
236  llvm_unreachable("unknown duplex register");
237  // Rs Rss
238  case R0:
239  case D0:
240  return 0;
241  case R1:
242  case D1:
243  return 1;
244  case R2:
245  case D2:
246  return 2;
247  case R3:
248  case D3:
249  return 3;
250  case R4:
251  case D8:
252  return 4;
253  case R5:
254  case D9:
255  return 5;
256  case R6:
257  case D10:
258  return 6;
259  case R7:
260  case D11:
261  return 7;
262  case R16:
263  return 8;
264  case R17:
265  return 9;
266  case R18:
267  return 10;
268  case R19:
269  return 11;
270  case R20:
271  return 12;
272  case R21:
273  return 13;
274  case R22:
275  return 14;
276  case R23:
277  return 15;
278  }
279 }
280 
282  const auto &HExpr = cast<HexagonMCExpr>(Expr);
283  assert(HExpr.getExpr());
284  return *HExpr.getExpr();
285 }
286 
288  MCInst const &MCI) {
289  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
291 }
292 
293 MCOperand const &
295  MCInst const &MCI) {
296  unsigned O = HexagonMCInstrInfo::getExtendableOp(MCII, MCI);
297  MCOperand const &MO = MCI.getOperand(O);
298 
300  HexagonMCInstrInfo::isExtended(MCII, MCI)) &&
301  (MO.isImm() || MO.isExpr()));
302  return (MO);
303 }
304 
306  MCInst const &MCI) {
307  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
309 }
310 
312  MCInst const &MCI) {
313  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
315 }
316 
317 /// Return the maximum value of an extendable operand.
319  MCInst const &MCI) {
320  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
322 
324  HexagonMCInstrInfo::isExtended(MCII, MCI));
325 
326  if (S) // if value is signed
327  return (1 << (HexagonMCInstrInfo::getExtentBits(MCII, MCI) - 1)) - 1;
328  return (1 << HexagonMCInstrInfo::getExtentBits(MCII, MCI)) - 1;
329 }
330 
331 /// Return the minimum value of an extendable operand.
333  MCInst const &MCI) {
334  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
336 
338  HexagonMCInstrInfo::isExtended(MCII, MCI));
339 
340  if (S) // if value is signed
341  return -(1 << (HexagonMCInstrInfo::getExtentBits(MCII, MCI) - 1));
342  return 0;
343 }
344 
346  MCInst const &MCI) {
347  return MCII.getName(MCI.getOpcode());
348 }
349 
351  MCInst const &MCI) {
352  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
354 }
355 
357  MCInst const &MCI) {
358  unsigned O = HexagonMCInstrInfo::getNewValueOp(MCII, MCI);
359  MCOperand const &MCO = MCI.getOperand(O);
360 
362  HexagonMCInstrInfo::hasNewValue(MCII, MCI)) &&
363  MCO.isReg());
364  return (MCO);
365 }
366 
367 /// Return the new value or the newly produced value.
369  MCInst const &MCI) {
370  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
372 }
373 
374 MCOperand const &
376  MCInst const &MCI) {
377  unsigned O = HexagonMCInstrInfo::getNewValueOp2(MCII, MCI);
378  MCOperand const &MCO = MCI.getOperand(O);
379 
381  HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) &&
382  MCO.isReg());
383  return (MCO);
384 }
385 
386 /// Return the Hexagon ISA class for the insn.
388  MCInst const &MCI) {
389  const uint64_t F = MCII.get(MCI.getOpcode()).TSFlags;
390  return ((F >> HexagonII::TypePos) & HexagonII::TypeMask);
391 }
392 
393 /// Return the slots this instruction can execute out of
395  MCSubtargetInfo const &STI,
396  MCInst const &MCI) {
398  int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
399  return ((II[SchedClass].FirstStage + HexagonStages)->getUnits());
400 }
401 
402 /// Return the slots this instruction consumes in addition to
403 /// the slot(s) it can execute out of
404 
406  MCSubtargetInfo const &STI,
407  MCInst const &MCI) {
409  int SchedClass = HexagonMCInstrInfo::getDesc(MCII, MCI).getSchedClass();
410  unsigned Slots = 0;
411 
412  // FirstStage are slots that this instruction can execute in.
413  // FirstStage+1 are slots that are also consumed by this instruction.
414  // For example: vmemu can only execute in slot 0 but also consumes slot 1.
415  for (unsigned Stage = II[SchedClass].FirstStage + 1;
416  Stage < II[SchedClass].LastStage; ++Stage) {
417  unsigned Units = (Stage + HexagonStages)->getUnits();
418  if (Units > HexagonGetLastSlot())
419  break;
420  // fyi: getUnits() will return 0x1, 0x2, 0x4 or 0x8
421  Slots |= Units;
422  }
423 
424  // if 0 is returned, then no additional slots are consumed by this inst.
425  return Slots;
426 }
427 
428 bool HexagonMCInstrInfo::hasDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
430  return false;
431 
432  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCII, MCI)) {
433  if (HexagonMCInstrInfo::isDuplex(MCII, I))
434  return true;
435  }
436 
437  return false;
438 }
439 
440 bool HexagonMCInstrInfo::hasExtenderForIndex(MCInst const &MCB, size_t Index) {
441  return extenderForIndex(MCB, Index) != nullptr;
442 }
443 
446  return false;
447 
448  for (const auto &I : HexagonMCInstrInfo::bundleInstructions(MCI)) {
449  if (isImmext(*I.getInst()))
450  return true;
451  }
452 
453  return false;
454 }
455 
456 /// Return whether the insn produces a value.
458  MCInst const &MCI) {
459  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
461 }
462 
463 /// Return whether the insn produces a second value.
465  MCInst const &MCI) {
466  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
468 }
469 
470 MCInst const &HexagonMCInstrInfo::instruction(MCInst const &MCB, size_t Index) {
471  assert(isBundle(MCB));
472  assert(Index < HEXAGON_PACKET_SIZE);
473  return *MCB.getOperand(bundleInstructionsOffset + Index).getInst();
474 }
475 
476 /// Return where the instruction is an accumulator.
478  MCInst const &MCI) {
479  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
481 }
482 
484  auto Result = Hexagon::BUNDLE == MCI.getOpcode();
485  assert(!Result || (MCI.size() > 0 && MCI.getOperand(0).isImm()));
486  return Result;
487 }
488 
490  MCInst const &MCI) {
491  if (HexagonMCInstrInfo::isExtended(MCII, MCI))
492  return true;
493  if (!HexagonMCInstrInfo::isExtendable(MCII, MCI))
494  return false;
496  if (isa<HexagonMCExpr>(MO.getExpr()) &&
498  return true;
499  // Branch insns are handled as necessary by relaxation.
500  if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeJ) ||
502  HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch()) ||
505  return false;
506  // Otherwise loop instructions and other CR insts are handled by relaxation
507  else if ((HexagonMCInstrInfo::getType(MCII, MCI) == HexagonII::TypeCR) &&
508  (MCI.getOpcode() != Hexagon::C4_addipc))
509  return false;
510 
511  assert(!MO.isImm());
512  if (isa<HexagonMCExpr>(MO.getExpr()) &&
514  return false;
515  int64_t Value;
516  if (!MO.getExpr()->evaluateAsAbsolute(Value))
517  return true;
518  int MinValue = HexagonMCInstrInfo::getMinValue(MCII, MCI);
519  int MaxValue = HexagonMCInstrInfo::getMaxValue(MCII, MCI);
520  return (MinValue > Value || Value > MaxValue);
521 }
522 
523 bool HexagonMCInstrInfo::isCanon(MCInstrInfo const &MCII, MCInst const &MCI) {
524  return !HexagonMCInstrInfo::getDesc(MCII, MCI).isPseudo() &&
525  !HexagonMCInstrInfo::isPrefix(MCII, MCI);
526 }
527 
528 bool HexagonMCInstrInfo::isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI) {
529  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
531 }
532 
534  MCInst const &MCI) {
535  return (getType(MCII, MCI) == HexagonII::TypeCJ);
536 }
537 
538 bool HexagonMCInstrInfo::isCVINew(MCInstrInfo const &MCII, MCInst const &MCI) {
539  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
541 }
542 
544  return ((Reg >= Hexagon::D0 && Reg <= Hexagon::D3) ||
545  (Reg >= Hexagon::D8 && Reg <= Hexagon::D11));
546 }
547 
548 bool HexagonMCInstrInfo::isDuplex(MCInstrInfo const &MCII, MCInst const &MCI) {
550 }
551 
553  MCInst const &MCI) {
554  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
556 }
557 
559  MCInst const &MCI) {
560  uint64_t const F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
562 }
563 
564 bool HexagonMCInstrInfo::isFloat(MCInstrInfo const &MCII, MCInst const &MCI) {
565  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
566  return ((F >> HexagonII::FPPos) & HexagonII::FPMask);
567 }
568 
570  return MCI.getOpcode() == Hexagon::A4_ext;
571 }
572 
574  assert(isBundle(MCI));
575  int64_t Flags = MCI.getOperand(0).getImm();
576  return (Flags & innerLoopMask) != 0;
577 }
578 
580  return (Reg >= Hexagon::R0 && Reg <= Hexagon::R31);
581 }
582 
584  return ((Reg >= Hexagon::R0 && Reg <= Hexagon::R7) ||
585  (Reg >= Hexagon::R16 && Reg <= Hexagon::R23));
586 }
587 
588 /// Return whether the insn expects newly produced value.
590  MCInst const &MCI) {
591  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
593 }
594 
595 /// Return whether the operand is extendable.
597  MCInst const &MCI, unsigned short O) {
598  return (O == HexagonMCInstrInfo::getExtendableOp(MCII, MCI));
599 }
600 
602  assert(isBundle(MCI));
603  int64_t Flags = MCI.getOperand(0).getImm();
604  return (Flags & outerLoopMask) != 0;
605 }
606 
608  MCInst const &MCI) {
609  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
611 }
612 
613 bool HexagonMCInstrInfo::isPrefix(MCInstrInfo const &MCII, MCInst const &MCI) {
615 }
616 
618  MCInst const &MCI) {
619  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
621 }
622 
623 /// Return whether the insn is newly predicated.
625  MCInst const &MCI) {
626  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
628 }
629 
631  MCInst const &MCI) {
632  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
633  return (
635 }
636 
638  return (Reg >= Hexagon::P0 && Reg <= Hexagon::P3_0);
639 }
640 
641 /// Return whether the insn can be packaged only with A and X-type insns.
642 bool HexagonMCInstrInfo::isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI) {
643  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
645 }
646 
647 /// Return whether the insn can be packaged only with an A-type insn in slot #1.
649  MCInst const &MCI) {
650  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
652 }
653 
654 /// Return whether the insn is solo, i.e., cannot be in a packet.
655 bool HexagonMCInstrInfo::isSolo(MCInstrInfo const &MCII, MCInst const &MCI) {
656  const uint64_t F = MCII.get(MCI.getOpcode()).TSFlags;
657  return ((F >> HexagonII::SoloPos) & HexagonII::SoloMask);
658 }
659 
661  assert(isBundle(MCI));
662  auto Flags = MCI.getOperand(0).getImm();
663  return (Flags & memReorderDisabledMask) != 0;
664 }
665 
667  assert(isBundle(MCI));
668  auto Flags = MCI.getOperand(0).getImm();
669  return (Flags & memStoreReorderEnabledMask) != 0;
670 }
671 
673  switch (MCI.getOpcode()) {
674  default:
675  return false;
676  case Hexagon::SA1_addi:
677  case Hexagon::SA1_addrx:
678  case Hexagon::SA1_addsp:
679  case Hexagon::SA1_and1:
680  case Hexagon::SA1_clrf:
681  case Hexagon::SA1_clrfnew:
682  case Hexagon::SA1_clrt:
683  case Hexagon::SA1_clrtnew:
684  case Hexagon::SA1_cmpeqi:
685  case Hexagon::SA1_combine0i:
686  case Hexagon::SA1_combine1i:
687  case Hexagon::SA1_combine2i:
688  case Hexagon::SA1_combine3i:
689  case Hexagon::SA1_combinerz:
690  case Hexagon::SA1_combinezr:
691  case Hexagon::SA1_dec:
692  case Hexagon::SA1_inc:
693  case Hexagon::SA1_seti:
694  case Hexagon::SA1_setin1:
695  case Hexagon::SA1_sxtb:
696  case Hexagon::SA1_sxth:
697  case Hexagon::SA1_tfr:
698  case Hexagon::SA1_zxtb:
699  case Hexagon::SA1_zxth:
700  case Hexagon::SL1_loadri_io:
701  case Hexagon::SL1_loadrub_io:
702  case Hexagon::SL2_deallocframe:
703  case Hexagon::SL2_jumpr31:
704  case Hexagon::SL2_jumpr31_f:
705  case Hexagon::SL2_jumpr31_fnew:
706  case Hexagon::SL2_jumpr31_t:
707  case Hexagon::SL2_jumpr31_tnew:
708  case Hexagon::SL2_loadrb_io:
709  case Hexagon::SL2_loadrd_sp:
710  case Hexagon::SL2_loadrh_io:
711  case Hexagon::SL2_loadri_sp:
712  case Hexagon::SL2_loadruh_io:
713  case Hexagon::SL2_return:
714  case Hexagon::SL2_return_f:
715  case Hexagon::SL2_return_fnew:
716  case Hexagon::SL2_return_t:
717  case Hexagon::SL2_return_tnew:
718  case Hexagon::SS1_storeb_io:
719  case Hexagon::SS1_storew_io:
720  case Hexagon::SS2_allocframe:
721  case Hexagon::SS2_storebi0:
722  case Hexagon::SS2_storebi1:
723  case Hexagon::SS2_stored_sp:
724  case Hexagon::SS2_storeh_io:
725  case Hexagon::SS2_storew_sp:
726  case Hexagon::SS2_storewi0:
727  case Hexagon::SS2_storewi1:
728  return true;
729  }
730 }
731 
732 bool HexagonMCInstrInfo::isVector(MCInstrInfo const &MCII, MCInst const &MCI) {
733  if ((getType(MCII, MCI) <= HexagonII::TypeCVI_LAST) &&
734  (getType(MCII, MCI) >= HexagonII::TypeCVI_FIRST))
735  return true;
736  return false;
737 }
738 
739 int64_t HexagonMCInstrInfo::minConstant(MCInst const &MCI, size_t Index) {
740  auto Sentinal = static_cast<int64_t>(std::numeric_limits<uint32_t>::max())
741  << 8;
742  if (MCI.size() <= Index)
743  return Sentinal;
744  MCOperand const &MCO = MCI.getOperand(Index);
745  if (!MCO.isExpr())
746  return Sentinal;
747  int64_t Value;
748  if (!MCO.getExpr()->evaluateAsAbsolute(Value))
749  return Sentinal;
750  return Value;
751 }
752 
753 void HexagonMCInstrInfo::setMustExtend(MCExpr const &Expr, bool Val) {
754  HexagonMCExpr &HExpr = const_cast<HexagonMCExpr &>(cast<HexagonMCExpr>(Expr));
755  HExpr.setMustExtend(Val);
756 }
757 
759  HexagonMCExpr const &HExpr = cast<HexagonMCExpr>(Expr);
760  return HExpr.mustExtend();
761 }
762 void HexagonMCInstrInfo::setMustNotExtend(MCExpr const &Expr, bool Val) {
763  HexagonMCExpr &HExpr = const_cast<HexagonMCExpr &>(cast<HexagonMCExpr>(Expr));
764  HExpr.setMustNotExtend(Val);
765 }
767  HexagonMCExpr const &HExpr = cast<HexagonMCExpr>(Expr);
768  return HExpr.mustNotExtend();
769 }
770 void HexagonMCInstrInfo::setS27_2_reloc(MCExpr const &Expr, bool Val) {
771  HexagonMCExpr &HExpr =
772  const_cast<HexagonMCExpr &>(*llvm::cast<HexagonMCExpr>(&Expr));
773  HExpr.setS27_2_reloc(Val);
774 }
776  HexagonMCExpr const *HExpr = llvm::dyn_cast<HexagonMCExpr>(&Expr);
777  if (!HExpr)
778  return false;
779  return HExpr->s27_2_reloc();
780 }
781 
783  MCInst Nop;
784  Nop.setOpcode(Hexagon::A2_nop);
785  assert(isBundle(MCB));
786  while ((HexagonMCInstrInfo::isInnerLoop(MCB) &&
790  MCB.addOperand(MCOperand::createInst(new (Context) MCInst(Nop)));
791 }
792 
794  MCInst const &MCI) {
795  const uint64_t F = HexagonMCInstrInfo::getDesc(MCII, MCI).TSFlags;
797 }
798 
800  DuplexCandidate Candidate) {
801  assert(Candidate.packetIndexI < MCB.size());
802  assert(Candidate.packetIndexJ < MCB.size());
803  assert(isBundle(MCB));
804  MCInst *Duplex =
805  deriveDuplex(Context, Candidate.iClass,
806  *MCB.getOperand(Candidate.packetIndexJ).getInst(),
807  *MCB.getOperand(Candidate.packetIndexI).getInst());
808  assert(Duplex != nullptr);
809  MCB.getOperand(Candidate.packetIndexI).setInst(Duplex);
810  MCB.erase(MCB.begin() + Candidate.packetIndexJ);
811 }
812 
814  assert(isBundle(MCI));
815  MCOperand &Operand = MCI.getOperand(0);
816  Operand.setImm(Operand.getImm() | innerLoopMask);
817 }
818 
820  assert(isBundle(MCI));
821  MCOperand &Operand = MCI.getOperand(0);
822  Operand.setImm(Operand.getImm() | memReorderDisabledMask);
824 }
825 
827  assert(isBundle(MCI));
828  MCOperand &Operand = MCI.getOperand(0);
829  Operand.setImm(Operand.getImm() | memStoreReorderEnabledMask);
831 }
832 
834  assert(isBundle(MCI));
835  MCOperand &Operand = MCI.getOperand(0);
836  Operand.setImm(Operand.getImm() | outerLoopMask);
837 }
838 
839 unsigned HexagonMCInstrInfo::SubregisterBit(unsigned Consumer,
840  unsigned Producer,
841  unsigned Producer2) {
842  // If we're a single vector consumer of a double producer, set subreg bit
843  // based on if we're accessing the lower or upper register component
844  if (Producer >= Hexagon::W0 && Producer <= Hexagon::W15)
845  if (Consumer >= Hexagon::V0 && Consumer <= Hexagon::V31)
846  return (Consumer - Hexagon::V0) & 0x1;
847  if (Consumer == Producer2)
848  return 0x1;
849  return 0;
850 }
851 } // namespace llvm
bool isSoloAin1(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with an A-type insn in slot #1.
#define HEXAGON_PACKET_INNER_SIZE
Definition: Hexagon.h:36
void replaceDuplex(MCContext &Context, MCInst &MCI, DuplexCandidate Candidate)
static bool Check(DecodeStatus &Out, DecodeStatus In)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
iterator end()
Definition: MCInst.h:187
iterator begin()
Definition: MCInst.h:185
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:243
void setMustExtend(bool Val=true)
unsigned short getNewValueOp(MCInstrInfo const &MCII, MCInst const &MCI)
#define R4(n)
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:234
MCInst const * extenderForIndex(MCInst const &MCB, size_t Index)
bool isReg() const
Definition: MCInst.h:58
unsigned getOtherReservedSlots(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &MCI)
Return the slots this instruction consumes in addition to the slot(s) it can execute out of...
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:137
void setInst(const MCInst *Val)
Definition: MCInst.h:111
void setMustNotExtend(bool Val=true)
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:163
bool isIntRegForSubInst(unsigned Reg)
bool isBundle(MCInst const &MCI)
unsigned HexagonGetLastSlot()
bool isSolo(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn is solo, i.e., cannot be in a packet.
bool isPredicatedNew(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn is newly predicated.
bool isSubInstruction(MCInst const &MCI)
bool isDblRegForSubInst(unsigned Reg)
#define R2(n)
MCInst deriveExtender(MCInstrInfo const &MCII, MCInst const &Inst, MCOperand const &MO)
bool isOuterLoop(MCInst const &MCI)
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
bool isMemStoreReorderEnabled(MCInst const &MCI)
PacketIterator(MCInstrInfo const &MCII, MCInst const &Inst)
bool isImmext(MCInst const &MCI)
void tryCompound(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCContext &Context, MCInst &MCI)
tryCompound - Given a bundle check for compound insns when one is found update the contents fo the bu...
MCOperand const & getNewValueOperand2(MCInstrInfo const &MCII, MCInst const &MCI)
MCInst const & instruction(MCInst const &MCB, size_t Index)
#define HEXAGON_PACKET_SIZE
Definition: Hexagon.h:33
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
Definition: MCInstrDesc.h:270
bool isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI)
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
Definition: MCInstrInfo.h:51
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
void erase(iterator I)
Definition: MCInst.h:183
Reg
All possible values of the reg field in the ModR/M byte.
const MCSchedModel & getSchedModel() const
Get the machine model for this subtarget's CPU.
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
bool s27_2_reloc(MCExpr const &Expr)
void padEndloop(MCInst &MCI, MCContext &Context)
StringRef getName(MCInstrInfo const &MCII, MCInst const &MCI)
void setMemReorderDisabled(MCInst &MCI)
Context object for machine code objects.
Definition: MCContext.h:59
#define F(x, y, z)
Definition: MD5.cpp:55
int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the maximum value of an extendable operand.
bool canonicalizePacket(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCContext &Context, MCInst &MCB, HexagonMCChecker *Checker)
unsigned short getNewValueOp2(MCInstrInfo const &MCII, MCInst const &MCI)
Return the new value or the newly produced value.
bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a second value.
void extendIfNeeded(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI)
void setMustExtend(MCExpr const &Expr, bool Val=true)
bool isAccumulator(MCInstrInfo const &MCII, MCInst const &MCI)
Return where the instruction is an accumulator.
const InstrItinerary * InstrItineraries
Definition: MCSchedule.h:194
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
void setS27_2_reloc(bool Val=true)
bool isPrefix(MCInstrInfo const &MCII, MCInst const &MCI)
bool isImm() const
Definition: MCInst.h:59
const MCExpr * getExpr() const
Definition: MCInst.h:96
void setMemStoreReorderEnabled(MCInst &MCI)
void setImm(int64_t Val)
Definition: MCInst.h:81
bool isCompound(MCInstrInfo const &MCII, MCInst const &MCI)
int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the minimum value of an extendable operand.
static HexagonMCExpr * create(MCExpr const *Expr, MCContext &Ctx)
bool mustExtend(MCExpr const &Expr)
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
int64_t const memReorderDisabledMask
bool hasDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
cl::opt< bool > HexagonDisableCompound
bool isExpr() const
Definition: MCInst.h:61
bool s27_2_reloc() const
MCExpr const & getExpr(MCExpr const &Expr)
bool isPseudo() const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction...
Definition: MCInstrDesc.h:242
static wasm::ValType getType(const TargetRegisterClass *RC)
unsigned SubregisterBit(unsigned Consumer, unsigned Producer, unsigned Producer2)
void clampExtended(MCInstrInfo const &MCII, MCContext &Context, MCInst &MCI)
bool prefersSlot3(MCInstrInfo const &MCII, MCInst const &MCI)
bool isCanon(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned short getExtendableOp(MCInstrInfo const &MCII, MCInst const &MCI)
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:45
size_t size() const
Definition: MCInst.h:184
int64_t const memStoreReorderEnabledMask
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void setOpcode(unsigned Op)
Definition: MCInst.h:167
size_t const bundleInstructionsOffset
#define R6(n)
bool isExtendable(MCInstrInfo const &MCII, MCInst const &MCI)
MCInst const & operator*() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
unsigned LastStage
Index of last + 1 stage in itinerary.
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
bool isCVINew(MCInstrInfo const &MCII, MCInst const &MCI)
HexagonII::MemAccessSize getAccessSize(MCInstrInfo const &MCII, MCInst const &MCI)
int64_t minConstant(MCInst const &MCI, size_t Index)
bool HexagonMCShuffle(MCContext &Context, bool Fatal, MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst &)
A range adaptor for a pair of iterators.
unsigned getOpcode() const
Definition: MCInst.h:168
unsigned const TypeCVI_FIRST
bool isMemReorderDisabled(MCInst const &MCI)
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned const TypeCVI_LAST
int64_t getImm() const
Definition: MCInst.h:76
bool isExtended(MCInstrInfo const &MCII, MCInst const &MCI)
#define HEXAGON_PACKET_OUTER_SIZE
Definition: Hexagon.h:37
static MCOperand createInst(const MCInst *Val)
Definition: MCInst.h:144
MCInst deriveSubInst(MCInst const &Inst)
llvm_unreachable("Unknown RegBank!")
bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with A and X-type insns.
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
unsigned getSchedClass() const
Return the scheduling class for this instruction.
Definition: MCInstrDesc.h:565
bool hasExtenderForIndex(MCInst const &MCB, size_t Index)
bool mustExtend() const
#define I(x, y, z)
Definition: MD5.cpp:58
MCSubtargetInfo - Generic base class for all target subtargets.
const InstrStage HexagonStages[]
const MCInst * getInst() const
Definition: MCInst.h:106
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
void setMustNotExtend(MCExpr const &Expr, bool Val=true)
size_t bundleSize(MCInst const &MCI)
bool check(bool FullCheck=true)
bool mustNotExtend() const
bool hasImmExt(MCInst const &MCI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInnerLoop(MCInst const &MCI)
bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether it is a floating-point insn.
An itinerary represents the scheduling information for an instruction.
bool isPredicateLate(MCInstrInfo const &MCII, MCInst const &MCI)
LLVM Value Representation.
Definition: Value.h:73
static const unsigned Nop
Instruction opcodes emitted via means other than CodeGen.
SmallVector< DuplexCandidate, 8 > getDuplexPossibilties(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &MCB)
Check for a valid bundle.
void addConstExtender(MCContext &Context, MCInstrInfo const &MCII, MCInst &MCB, MCInst const &MCI)
unsigned getUnits(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &MCI)
Return the slots used by the insn.
bool isConstExtended(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getDuplexRegisterNumbering(unsigned Reg)
IRTranslator LLVM IR MI
bool isOpExtendable(MCInstrInfo const &MCII, MCInst const &MCI, unsigned short)
Return whether the operand is extendable.
void addOperand(const MCOperand &Op)
Definition: MCInst.h:177
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
MCInst * deriveDuplex(MCContext &Context, unsigned iClass, MCInst const &inst0, MCInst const &inst1)
bool hasNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a value.
unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI)
Return the Hexagon ISA class for the insn.
void setS27_2_reloc(MCExpr const &Expr, bool Val=true)
unsigned getExtentAlignment(MCInstrInfo const &MCII, MCInst const &MCI)
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
bool mustNotExtend(MCExpr const &Expr)
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI)
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:123
MCOperand const & getExtendableOperand(MCInstrInfo const &MCII, MCInst const &MCI)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:159
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:173
cl::opt< bool > HexagonDisableDuplex
void addConstant(MCInst &MI, uint64_t Value, MCContext &Context)
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)
void setExpr(const MCExpr *Val)
Definition: MCInst.h:101
bool operator==(PacketIterator const &Other) const
unsigned getExtentBits(MCInstrInfo const &MCII, MCInst const &MCI)