34 cl::desc(
"Relax checks of new-value validity"));
36const HexagonMCChecker::PredSense
37 HexagonMCChecker::Unconditional(Hexagon::NoRegister,
false);
39void HexagonMCChecker::init() {
58 Defs[Hexagon::SA0].insert(Unconditional);
59 Defs[Hexagon::LC0].insert(Unconditional);
62 Defs[Hexagon::SA1].insert(Unconditional);
63 Defs[Hexagon::LC1].insert(Unconditional);
69 MCInst
const &Inst = *
I.getInst();
90 NewPreds.insert(PredReg);
94 for (MCRegAliasIterator SRI(R, &RI, RI.subregs(R).empty()); SRI.isValid();
96 if (RI.subregs(*SRI).empty())
101 ReversePairs.insert(R);
104void HexagonMCChecker::init(
MCInst const &MCI) {
114 initReg(MCI, ImpUse, PredReg, isTrue);
118 STI.hasFeature(Hexagon::ArchV69);
122 if (Hexagon::R31 != R && MCID.
isCall())
126 if (Hexagon::PC == R)
131 if (Hexagon::USR_OVF == R)
142 else if (!IgnoreTmpDst)
143 Defs[
R].insert(PredSense(PredReg, isTrue));
147 for (
unsigned i = 0; i < MCID.
getNumDefs(); ++i) {
152 if (R == Hexagon::C8)
156 ReversePairs.insert(R);
160 for (MCRegAliasIterator SRI(R, &RI, RI.subregs(R).empty()); SRI.isValid();
162 if (!RI.subregs(*SRI).empty())
175 if (Hexagon::P3_0 != R && Hexagon::P3_0 == *SRI)
180 SoftDefs.insert(*SRI);
184 LatePreds.insert(*SRI);
192 TmpDefs.insert(*SRI);
193 else if (!IgnoreTmpDst)
194 Defs[*SRI].insert(PredSense(PredReg, isTrue));
212 : Context(Context), MCB(mcb), RI(ri), MCII(MCII), STI(STI),
213 ReportErrors(ReportErrors) {
219 bool CopyReportErrors)
221 STI(STI), ReportErrors(CopyReportErrors ?
Other.ReportErrors :
false) {
226 bool chkP = checkPredicates();
227 bool chkNV = checkNewValues();
228 bool chkR = checkRegisters();
229 bool chkRRO = checkRegistersReadOnly();
230 checkRegisterCurDefs();
231 bool chkS = checkSolo();
234 chkSh = checkShuffle();
237 chkSl = checkSlots();
238 bool chkAXOK = checkAXOK();
239 bool chkCofMax1 = checkCOFMax1();
240 bool chkHWLoop = checkHWLoop();
241 bool chkHMX = checkValidHMX();
242 bool chkValidTmpDst = FullCheck ? checkValidTmpDst() :
true;
243 bool chkLegalVecRegPair = checkLegalVecRegPair();
244 bool ChkHVXAccum = checkHVXAccum();
245 bool ChkHVXRestrictions = checkHVXRestrictions();
246 bool ChkHLX64BitRegUse = checkHLX64BitRegUse();
247 bool chk = chkP && chkNV && chkR && chkRRO && chkS && chkSh && chkSl &&
248 chkAXOK && chkCofMax1 && chkHWLoop && chkHMX && chkValidTmpDst &&
249 chkLegalVecRegPair && ChkHVXAccum && ChkHVXRestrictions &&
257 case Hexagon::SA1_addi:
258 case Hexagon::SA1_addrx:
259 case Hexagon::SA1_addsp:
260 case Hexagon::SA1_and1:
261 case Hexagon::SA1_clrf:
262 case Hexagon::SA1_clrfnew:
263 case Hexagon::SA1_clrt:
264 case Hexagon::SA1_clrtnew:
265 case Hexagon::SA1_cmpeqi:
266 case Hexagon::SA1_combine0i:
267 case Hexagon::SA1_combine1i:
268 case Hexagon::SA1_combine2i:
269 case Hexagon::SA1_combine3i:
270 case Hexagon::SA1_combinerz:
271 case Hexagon::SA1_combinezr:
272 case Hexagon::SA1_dec:
273 case Hexagon::SA1_inc:
274 case Hexagon::SA1_seti:
275 case Hexagon::SA1_setin1:
276 case Hexagon::SA1_sxtb:
277 case Hexagon::SA1_sxth:
278 case Hexagon::SA1_tfr:
279 case Hexagon::SA1_zxtb:
280 case Hexagon::SA1_zxth:
312bool HexagonMCChecker::checkAXOK() {
313 MCInst
const *HasSoloAXInst =
nullptr;
325 Twine(
"Instruction can only be in a packet with ALU or non-FPU XTYPE "
328 Twine(
"Not an ALU or non-FPU XTYPE instruction"));
342bool HexagonMCChecker::checkHWLoop() {
349 "Branches cannot be in a packet with hardware loops");
357bool HexagonMCChecker::checkCOFMax1() {
363 for (
unsigned J = 0,
N = BranchLocations.
size(); J <
N; ++J) {
364 MCInst
const &
I = *BranchLocations[J];
368 if (
N > 1 && !Relax1 && !Relax2) {
370 "Instruction may not be in a packet with other branches");
374 if (
N > 1 && J == 0 && !Relax1) {
376 "Instruction may not be the first branch in packet");
380 if (
N > 1 && J == 1 && !Relax2) {
382 "Instruction may not be the second branch in packet");
391bool HexagonMCChecker::checkSlots() {
394 reportError(
"invalid instruction packet: out of slots");
401bool HexagonMCChecker::checkPredicates() {
403 for (
const auto &
I : NewPreds) {
406 if (!Defs.count(
P) || LatePreds.count(
P) || Defs.count(Hexagon::P3_0)) {
416 for (
const auto &
I : LatePreds) {
419 if (LatePreds.count(
P) > 1 || Defs.count(
P)) {
432bool HexagonMCChecker::checkNewValues() {
433 for (
auto const &ConsumerInst :
438 const HexagonMCInstrInfo::PredicateInfo ConsumerPredInfo =
442 MCOperand
const &
Op =
446 auto Producer = registerProducer(
Op.getReg(), ConsumerPredInfo);
447 const MCInst *
const ProducerInst = std::get<0>(Producer);
448 const HexagonMCInstrInfo::PredicateInfo ProducerPredInfo =
449 std::get<2>(Producer);
451 if (ProducerInst ==
nullptr) {
453 "New value register consumer has no producer");
464 "Register producer is predicated and consumer is unconditional");
466 "Instruction does not have a valid new register producer");
469 if (ProducerPredInfo.
Register != Hexagon::NoRegister &&
472 "Register producer does not use the same predicate "
473 "register as the consumer");
475 "Instruction does not have a valid new register producer");
483 "Register producer has the opposite predicate sense as consumer");
485 "Instruction does not have a valid new register producer");
490 const unsigned ProducerOpIndex = std::get<1>(Producer);
492 if (
Desc.operands()[ProducerOpIndex].RegClass ==
493 Hexagon::DoubleRegsRegClassID) {
495 "Double registers cannot be new-value producers");
497 "Instruction does not have a valid new register producer");
505 const unsigned ProducerOpSearchIndex =
511 const bool ProducerOpIsMemIndex =
512 ((
Desc.mayLoad() && ProducerOpIndex == ProducerOpSearchIndex) ||
513 (
Desc.mayStore() && ProducerOpIndex == 0));
515 if (ProducerOpIsMemIndex) {
520 ModeError =
"Absolute-set";
522 ModeError =
"Auto-increment";
523 if (!ModeError.
empty()) {
525 ModeError +
" registers cannot be a new-value "
528 "Instruction does not have a valid new register producer");
534 "FPU instructions cannot be new-value producers for jumps");
536 "Instruction does not have a valid new register producer");
543bool HexagonMCChecker::checkRegistersReadOnly() {
545 MCInst
const &Inst = *
I.getInst();
547 for (
unsigned j = 0;
j < Defs; ++
j) {
548 MCOperand
const &Operand = Inst.
getOperand(j);
549 assert(Operand.
isReg() &&
"Def is not a register");
551 if (ReadOnly.find(
Register) != ReadOnly.end()) {
566 MCOperand
const &Operand =
I.getOperand(j);
573std::tuple<MCInst const *, unsigned, HexagonMCInstrInfo::PredicateInfo>
574HexagonMCChecker::registerProducer(
576 std::tuple<MCInst const *, unsigned, HexagonMCInstrInfo::PredicateInfo>
583 for (
unsigned J = 0,
N =
Desc.getNumDefs(); J <
N; ++J)
584 for (
auto K = MCRegAliasIterator(
I.getOperand(J).getReg(), &RI,
true);
588 (ProducerPredicate.Register == ConsumerPredicate.
Register &&
589 (ProducerPredicate.Register == Hexagon::NoRegister ||
590 ProducerPredicate.PredicatedTrue ==
592 return std::make_tuple(&
I, J, ProducerPredicate);
593 std::get<0>(WrongSense) = &
I;
594 std::get<1>(WrongSense) = J;
595 std::get<2>(WrongSense) = ProducerPredicate;
598 return std::make_tuple(&
I, 0, HexagonMCInstrInfo::PredicateInfo());
603void HexagonMCChecker::checkRegisterCurDefs() {
607 const MCRegister RegDef =
I.getOperand(0).getReg();
609 bool HasRegDefUse =
false;
610 for (MCRegAliasIterator Alias(RegDef, &RI,
true); Alias.isValid();
612 HasRegDefUse = HasRegDefUse || registerUsed(*Alias);
616 "' used with `.cur' "
617 "but not used in the same packet");
623bool HexagonMCChecker::checkRegisters() {
625 for (
const auto &
I : Defs) {
626 MCRegister
R =
I.first;
628 if (isLoopRegister(R) && Defs.count(R) > 1 &&
632 reportError(
"loop-setup and some branch instructions "
633 "cannot be in the same packet");
636 if (SoftDefs.count(R)) {
639 MCRegister UsrR = Hexagon::USR;
640 MCRegister BadR = RI.isSubRegister(Hexagon::USR, R) ? UsrR :
R;
646 PredSet &PM = Defs[
R];
649 if (PM.count(Unconditional)) {
652 MCRegister UsrR = Hexagon::USR;
653 MCRegister BadR = RI.isSubRegister(Hexagon::USR, R) ? UsrR :
R;
658 for (
const auto &J : PM) {
662 if (PM.count(
P) > 1) {
669 P.second = !
P.second;
670 if (PM.count(
P) && PM.size() > 2) {
682 for (
const auto &
I : TmpDefs) {
685 if (!Uses.count(R)) {
687 bool vHistFound =
false;
698 "' used with `.tmp' but not used in the same packet");
707bool HexagonMCChecker::checkValidHMX() {
708 bool hasWeight =
false;
709 bool hasActivation =
false;
717 const bool ValidWeightActPairing = hasWeight == hasActivation;
718 if (!ValidWeightActPairing) {
719 const std::string ErrMsg = hasWeight ?
"weight without an activation"
720 :
"activation without a weight";
721 reportError(MCB.getLoc(), Twine(
"packet has HMX ") + ErrMsg);
726 reportNote(
I.getLoc(),
"this is an HMX weight instruction");
728 reportNote(
I.getLoc(),
"this is an HMX activation instruction");
731 "this is neither an HMX weight nor activation");
734 return ValidWeightActPairing;
738bool HexagonMCChecker::checkSolo() {
742 reportError(
I.getLoc(),
"Instruction is marked `isSolo' and "
743 "cannot have other instructions in "
752bool HexagonMCChecker::checkShuffle() {
753 HexagonMCShuffler MCSDX(Context, ReportErrors, MCII, STI, MCB);
754 return MCSDX.check();
757bool HexagonMCChecker::checkValidTmpDst() {
758 if (!STI.hasFeature(Hexagon::ArchV69)) {
761 auto HasTmp = [&](MCInst
const &
I) {
766 unsigned HasTmpCount =
769 if (HasTmpCount > 1) {
772 "this packet has more than one HVX vtmp/.tmp destination instruction");
777 "this is an HVX vtmp/.tmp destination instruction");
784void HexagonMCChecker::compoundRegisterMap(
unsigned &
Register) {
817 "' modified more than once");
822 "' used with `.new' "
823 "but not validly modified in the same packet");
832 Context.reportError(
Loc,
Msg);
837 auto SM = Context.getSourceManager();
845 Context.reportWarning(MCB.getLoc(),
Msg);
848bool HexagonMCChecker::checkLegalVecRegPair() {
849 const bool IsPermitted = STI.
hasFeature(Hexagon::ArchV67);
850 const bool HasReversePairs = ReversePairs.size() != 0;
852 if (!IsPermitted && HasReversePairs) {
853 for (
auto R : ReversePairs)
855 "' is not permitted for this architecture");
861bool HexagonMCChecker::checkHVXRestrictions() {
862 const MCInst *VS3SRC =
nullptr;
863 bool PacketHasNonUnaryALU =
false;
864 bool PacketHasVP =
false;
865 bool PacketHasAnotherVS =
false;
872 PacketHasNonUnaryALU =
true;
878 PacketHasAnotherVS =
true;
882 bool ret = !PacketHasNonUnaryALU && !PacketHasVP && !PacketHasAnotherVS;
884 reportError(
"invalid instruction packet: HVX resource use violation");
885 if (PacketHasNonUnaryALU)
887 "This instruction cannot be paired with an HVX "
888 "non-unary instruction");
891 "This instruction cannot be paired with an HVX "
892 "permute instruction");
893 if (PacketHasAnotherVS)
895 "This instruction cannot be paired with another HVX "
896 "shift instruction");
899 reportNote(
I.getLoc(),
"HVX non-unary instruction");
904 reportNote(
I.getLoc(),
"another HVX shift instruction");
911bool HexagonMCChecker::checkHVXAccum()
918 MCRegister
R =
I.getOperand(0).getReg();
919 TmpDefsIterator It = TmpDefs.find(R);
920 if (It != TmpDefs.end()) {
921 reportError(
"register `" + Twine(RI.getName(R)) +
".tmp" +
922 "' is accumulated in this packet");
929bool HexagonMCChecker::checkHLX64BitRegUse() {
930 const MCRegisterClass &DoubleRegs =
931 RI.getRegClass(Hexagon::DoubleRegsRegClassID);
932 const MCRegisterClass &
IntRegs = RI.getRegClass(Hexagon::IntRegsRegClassID);
933 const MCInst *DoubleInst =
nullptr;
934 unsigned NumScalarArg = 0;
939 if (
Desc.mayLoad() ||
Desc.mayStore())
941 bool UsesScalarArg =
false;
942 for (
const auto &
Op :
I) {
943 if (!DoubleInst &&
Op.isReg() && DoubleRegs.
contains(
Op.getReg()))
945 if (
Op.isImm() ||
Op.isExpr() ||
948 UsesScalarArg =
true;
954 if (DoubleInst && NumScalarArg > 1) {
956 "HLX instruction using a 64-bit scalar register cannot be "
957 "in the same packet with another HLX instruction using a "
958 "scalar register or immediate");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > RelaxNVChecks("relax-nv-checks", cl::Hidden, cl::desc("Relax checks of new-value validity"))
static bool isDuplexAGroup(unsigned Opcode)
static bool isNeitherAnorX(MCInstrInfo const &MCII, MCInst const &ID)
Promote Memory to Register
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static const MCPhysReg IntRegs[32]
void reportErrorNewValue(MCRegister Register)
HexagonMCChecker(MCContext &Context, MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst &mcb, const MCRegisterInfo &ri, bool ReportErrors=true)
bool check(bool FullCheck=true)
void reportWarning(Twine const &Msg)
void reportNote(SMLoc Loc, Twine const &Msg)
void reportErrorRegisters(MCRegister Register)
void reportBranchErrors()
void reportError(SMLoc Loc, Twine const &Msg)
bool isPredicated() const
Context object for machine code objects.
Instances of this class represent a single low-level machine instruction.
const MCOperand & getOperand(unsigned i) const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
ArrayRef< MCPhysReg > implicit_defs() const
Return a list of registers that are potentially written by any instance of this machine instruction.
bool isCall() const
Return true if the instruction is a call.
ArrayRef< MCPhysReg > implicit_uses() const
Return a list of registers that are potentially read by any instance of this machine instruction.
Interface to description of machine instruction set.
MCRegister getReg() const
Returns the register number.
const MCInst * getInst() const
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register.
Wrapper class representing physical registers. Should be passed by value.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
Wrapper class representing virtual and physical registers.
Represents a location in source code.
void push_back(const T &Elt)
constexpr bool empty() const
Check if the string is empty.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isTmpWrite(MCInstrInfo const &MCII, MCInst const &MCI)
bool isHMXWeight(MCInstrInfo const &MCII, MCInst const &MCI)
bool isHVXVS3SRC(MCInstrInfo const &MCII, MCInst const &MCI)
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 IsReverseVecRegPair(MCRegister VecReg)
bool isOuterLoop(MCInst const &MCI)
bool isHVXALU2SRC(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getAddrMode(MCInstrInfo const &MCII, MCInst const &MCI)
size_t bundleSize(MCInst const &MCI)
bool IsABranchingInst(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &I)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
bool isPredicateLate(MCInstrInfo const &MCII, MCInst const &MCI)
bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with A and X-type insns.
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
bool isHVX(MCInstrInfo const &MCII, MCInst const &MCI)
bool isHLX(MCInstrInfo const &MCII, MCInst const &MCI)
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
bool isBundle(MCInst const &MCI)
bool isCofRelax1(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI)
Return the Hexagon ISA class for the insn.
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
bool isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI)
bool isInnerLoop(MCInst const &MCI)
PredicateInfo predicateInfo(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned slotsConsumed(MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst const &MCI)
bool hasTmpDst(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned packetSizeSlots(MCSubtargetInfo const &STI)
bool isPredReg(MCRegisterInfo const &MRI, MCRegister Reg)
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI)
bool isAccumulator(MCInstrInfo const &MCII, MCInst const &MCI)
Return where the instruction is an accumulator.
bool isHMXActivation(MCInstrInfo const &MCII, MCInst const &MCI)
bool isCVINew(MCInstrInfo const &MCII, MCInst const &MCI)
bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether it is a floating-point insn.
bool isCofRelax2(MCInstrInfo const &MCII, MCInst const &MCI)
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
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...