36 const HexagonMCChecker::PredSense
37 HexagonMCChecker::Unconditional(Hexagon::NoRegister,
false);
39 void HexagonMCChecker::init() {
41 ReadOnly.insert(Hexagon::PC);
42 ReadOnly.insert(Hexagon::C9_8);
46 Defs[Hexagon::SA0].
insert(Unconditional);
47 Defs[Hexagon::LC0].
insert(Unconditional);
50 Defs[Hexagon::SA1].
insert(Unconditional);
51 Defs[Hexagon::LC1].
insert(Unconditional);
57 MCInst const &Inst = *
I.getInst();
68 void HexagonMCChecker::initReg(
MCInst const &MCI,
unsigned R,
unsigned &PredReg,
77 NewPreds.insert(PredReg);
88 void HexagonMCChecker::init(
MCInst const &MCI) {
90 unsigned PredReg = Hexagon::NoRegister;
102 for (; *ImpDef; ++ImpDef) {
103 unsigned R = *ImpDef;
105 if (Hexagon::R31 != R && MCID.
isCall())
109 if (Hexagon::PC == R)
114 if (Hexagon::USR_OVF == R)
121 else if (isPredicateRegister(R) &&
126 Defs[R].
insert(PredSense(PredReg, isTrue));
130 for (
unsigned i = 0; i < MCID.
getNumDefs(); ++i) {
135 if (R == Hexagon::C8)
155 if (Hexagon::P3_0 != R && Hexagon::P3_0 == *SRI)
160 SoftDefs.insert(*SRI);
162 isPredicateRegister(*SRI))
164 LatePreds.insert(*SRI);
172 TmpDefs.insert(*SRI);
178 Defs[*SRI].
insert(PredSense(PredReg, isTrue));
188 if (isPredicateRegister(P))
196 : Context(Context), MCB(mcb), RI(ri), MCII(MCII), STI(STI),
197 ReportErrors(ReportErrors) {
203 bool CopyReportErrors)
204 : Context(Other.Context), MCB(Other.MCB), RI(Other.RI), MCII(Other.MCII),
205 STI(STI), ReportErrors(CopyReportErrors ? Other.ReportErrors :
false) {}
208 bool chkP = checkPredicates();
209 bool chkNV = checkNewValues();
210 bool chkR = checkRegisters();
211 bool chkRRO = checkRegistersReadOnly();
212 checkRegisterCurDefs();
213 bool chkS = checkSolo();
216 chkSh = checkShuffle();
219 chkSl = checkSlots();
220 bool chkAXOK = checkAXOK();
221 bool chkCofMax1 = checkCOFMax1();
222 bool chkHWLoop = checkHWLoop();
223 bool chk = chkP && chkNV && chkR && chkRRO && chkS && chkSh && chkSl &&
224 chkAXOK && chkCofMax1 && chkHWLoop;
231 case Hexagon::SA1_addi:
232 case Hexagon::SA1_addrx:
233 case Hexagon::SA1_addsp:
234 case Hexagon::SA1_and1:
235 case Hexagon::SA1_clrf:
236 case Hexagon::SA1_clrfnew:
237 case Hexagon::SA1_clrt:
238 case Hexagon::SA1_clrtnew:
239 case Hexagon::SA1_cmpeqi:
240 case Hexagon::SA1_combine0i:
241 case Hexagon::SA1_combine1i:
242 case Hexagon::SA1_combine2i:
243 case Hexagon::SA1_combine3i:
244 case Hexagon::SA1_combinerz:
245 case Hexagon::SA1_combinezr:
246 case Hexagon::SA1_dec:
247 case Hexagon::SA1_inc:
248 case Hexagon::SA1_seti:
249 case Hexagon::SA1_setin1:
250 case Hexagon::SA1_sxtb:
251 case Hexagon::SA1_sxth:
252 case Hexagon::SA1_tfr:
253 case Hexagon::SA1_zxtb:
254 case Hexagon::SA1_zxth:
279 bool HexagonMCChecker::checkAXOK() {
280 MCInst const *HasSoloAXInst =
nullptr;
292 Twine(
"Instruction can only be in a packet with ALU or non-FPU XTYPE " 295 Twine(
"Not an ALU or non-FPU XTYPE instruction"));
310 bool HexagonMCChecker::checkHWLoop() {
318 "Branches cannot be in a packet with hardware loops");
326 bool HexagonMCChecker::checkCOFMax1() {
333 for (
unsigned J = 0,
N = BranchLocations.
size(); J <
N; ++J) {
334 MCInst const &
I = *BranchLocations[J];
338 if (N > 1 && !Relax1 && !Relax2) {
340 "Instruction may not be in a packet with other branches");
344 if (N > 1 && J == 0 && !Relax1) {
346 "Instruction may not be the first branch in packet");
350 if (N > 1 && J == 1 && !Relax2) {
352 "Instruction may not be the second branch in packet");
361 bool HexagonMCChecker::checkSlots() {
362 unsigned slotsUsed = 0;
364 MCInst const &MCI = *HMI.getInst();
374 reportError(
"invalid instruction packet: out of slots");
381 bool HexagonMCChecker::checkPredicates() {
383 for (
const auto &
I : NewPreds) {
386 if (!Defs.
count(P) || LatePreds.count(P)) {
396 for (
const auto &
I : LatePreds) {
399 if (LatePreds.count(P) > 1 || Defs.
count(P)) {
412 bool HexagonMCChecker::checkNewValues() {
420 auto Producer = registerProducer(Op.
getReg(), Consumer);
421 if (std::get<0>(Producer) ==
nullptr) {
422 reportError(
I.getLoc(),
"New value register consumer has no producer");
427 if (std::get<2>(Producer).isPredicated() &&
428 (!Consumer.isPredicated() ||
431 std::get<0>(Producer)->getLoc(),
432 "Register producer is predicated and consumer is unconditional");
434 "Instruction does not have a valid new register producer");
437 if (std::get<2>(Producer).Register != Hexagon::NoRegister &&
438 std::get<2>(Producer).
Register != Consumer.Register) {
440 "Register producer does not use the same predicate " 441 "register as the consumer");
443 "Instruction does not have a valid new register producer");
447 if (std::get<2>(Producer).Register == Consumer.Register &&
448 Consumer.PredicatedTrue != std::get<2>(Producer).PredicatedTrue) {
450 std::get<0>(Producer)->getLoc(),
451 "Register producer has the opposite predicate sense as consumer");
453 "Instruction does not have a valid new register producer");
459 Hexagon::DoubleRegsRegClassID) {
461 "Double registers cannot be new-value producers");
463 "Instruction does not have a valid new register producer");
466 if ((Desc.
mayLoad() && std::get<1>(Producer) == 1) ||
467 (Desc.
mayStore() && std::get<1>(Producer) == 0)) {
472 ModeError =
"Absolute-set";
474 ModeError =
"Auto-increment";
475 if (!ModeError.
empty()) {
477 ModeError +
" registers cannot be a new-value " 480 "Instruction does not have a valid new register producer");
486 "FPU instructions cannot be new-value producers for jumps");
488 "Instruction does not have a valid new register producer");
495 bool HexagonMCChecker::checkRegistersReadOnly() {
497 MCInst const &Inst = *
I.getInst();
499 for (
unsigned j = 0; j < Defs; ++j) {
501 assert(Operand.
isReg() &&
"Def is not a register");
503 if (ReadOnly.find(Register) != ReadOnly.end()) {
513 bool HexagonMCChecker::registerUsed(
unsigned Register) {
516 n =
I.getNumOperands();
525 std::tuple<MCInst const *, unsigned, HexagonMCInstrInfo::PredicateInfo>
526 HexagonMCChecker::registerProducer(
528 std::tuple<MCInst const *, unsigned, HexagonMCInstrInfo::PredicateInfo>
536 if (*K == Register) {
538 (ProducerPredicate.Register == ConsumerPredicate.
Register &&
539 (ProducerPredicate.Register == Hexagon::NoRegister ||
540 ProducerPredicate.PredicatedTrue ==
542 return std::make_tuple(&
I, J, ProducerPredicate);
543 std::get<0>(WrongSense) = &
I;
544 std::get<1>(WrongSense) = J;
545 std::get<2>(WrongSense) = ProducerPredicate;
553 void HexagonMCChecker::checkRegisterCurDefs() {
557 unsigned Register =
I.getOperand(0).getReg();
558 if (!registerUsed(Register))
560 "' used with `.cur' " 561 "but not used in the same packet");
567 bool HexagonMCChecker::checkRegisters() {
569 for (
const auto &
I : Defs) {
570 unsigned R =
I.first;
572 if (isLoopRegister(R) && Defs.count(R) > 1 &&
576 reportError(
"loop-setup and some branch instructions " 577 "cannot be in the same packet");
580 if (SoftDefs.count(R)) {
583 unsigned UsrR = Hexagon::USR;
584 unsigned BadR = RI.
isSubRegister(Hexagon::USR, R) ? UsrR : R;
588 if (!isPredicateRegister(R) && Defs[R].
size() > 1) {
590 PredSet &PM = Defs[R];
593 if (PM.count(Unconditional)) {
596 unsigned UsrR = Hexagon::USR;
597 unsigned BadR = RI.
isSubRegister(Hexagon::USR, R) ? UsrR : R;
602 for (
const auto &J : PM) {
606 if (PM.count(P) > 1) {
613 P.second = !P.second;
614 if (PM.count(P) && PM.size() > 2) {
626 for (
const auto &
I : TmpDefs) {
629 if (!Uses.count(R)) {
631 bool vHistFound =
false;
642 "' used with `.tmp' but not used in the same packet");
652 bool HexagonMCChecker::checkSolo() {
656 reportError(
I.getLoc(),
"Instruction is marked `isSolo' and " 657 "cannot have other instructions in " 666 bool HexagonMCChecker::checkShuffle() {
668 return MCSDX.
check();
671 void HexagonMCChecker::compoundRegisterMap(
unsigned &Register) {
676 Register = Hexagon::R23;
679 Register = Hexagon::R22;
682 Register = Hexagon::R21;
685 Register = Hexagon::R20;
688 Register = Hexagon::R19;
691 Register = Hexagon::R18;
694 Register = Hexagon::R17;
697 Register = Hexagon::R16;
704 "' modified more than once");
709 "' used with `.new' " 710 "but not validly modified in the same packet");
void reportErrorNewValue(unsigned Register)
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getAddrMode(MCInstrInfo const &MCII, MCInst const &MCI)
bool hasTmpDst(MCInstrInfo const &MCII, MCInst const &MCI)
return true if instruction has hasTmpDst attribute.
This class represents lattice values for constants.
void push_back(const T &Elt)
const MCPhysReg * getImplicitUses() const
Return a list of registers that are potentially read by any instance of this machine instruction...
Describe properties that are true of each instruction in the target description file.
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)
bool isBundle(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 mayLoad() const
Return true if this instruction could possibly read memory.
bool isOuterLoop(MCInst const &MCI)
bool isReturn() const
Return true if the instruction is a return.
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
bool isCofRelax1(MCInstrInfo const &MCII, MCInst const &MCI)
bool isImmext(MCInst const &MCI)
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
bool isCofMax1(MCInstrInfo const &MCII, MCInst const &MCI)
bool isSubRegister(unsigned RegA, unsigned RegB) const
Returns true if RegB is a sub-register of RegA.
void reportError(SMLoc Loc, Twine const &Msg)
bool isCofRelax2(MCInstrInfo const &MCII, MCInst const &MCI)
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getReg() const
Returns the register number.
void reportWarning(Twine const &Msg)
Context object for machine code objects.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
PredicateInfo predicateInfo(MCInstrInfo const &MCII, MCInst const &MCI)
const MCInst * getInst() const
bool hasNewValue2(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn produces a second value.
Instances of this class represent a single low-level machine instruction.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
const char * getName(unsigned RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
initializer< Ty > init(const Ty &Val)
void reportNote(SMLoc Loc, Twine const &Msg)
const MCPhysReg * getImplicitDefs() const
Return a list of registers that are potentially written by any instance of this machine instruction...
The instances of the Type class are immutable: once they are created, they are never changed...
static bool isDuplexAGroup(unsigned Opcode)
void reportBranchErrors()
Interface to description of machine instruction set.
static cl::opt< bool > RelaxNVChecks("relax-nv-checks", cl::init(false), cl::ZeroOrMore, cl::Hidden, cl::desc("Relax checks of new-value validity"))
MCRegAliasIterator enumerates all registers aliasing Reg.
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
void reportError(SMLoc L, const Twine &Msg)
const SourceMgr * getSourceManager() const
MCSubRegIterator enumerates all sub-registers of Reg.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
HexagonMCChecker(MCContext &Context, MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst &mcb, const MCRegisterInfo &ri, bool ReportErrors=true)
const MCOperand & getOperand(unsigned i) const
Promote Memory to Register
bool isCVINew(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
void reportErrorRegisters(unsigned Register)
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
bool isPredicated(MCInstrInfo const &MCII, MCInst const &MCI)
bool mayStore() const
Return true if this instruction could possibly modify memory.
bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with A and X-type insns.
int16_t RegClass
This specifies the register class enumeration of the operand if the operand is a register.
Generic base class for all target subtargets.
bool isCall() const
Return true if the instruction is a call.
size_t bundleSize(MCInst const &MCI)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool check(bool FullCheck=true)
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.
bool isPredicateLate(MCInstrInfo const &MCII, MCInst const &MCI)
#define HEXAGON_PACKET_SIZE
static bool isNeitherAnorX(MCInstrInfo const &MCII, MCInst const &ID)
const MCOperandInfo * OpInfo
Check for a valid bundle.
StringRef - Represent a constant reference to a string, i.e.
unsigned getType(MCInstrInfo const &MCII, MCInst const &MCI)
Return the Hexagon ISA class for the insn.
Represents a location in source code.
unsigned getOpcode() const
Instances of this class represent operands of the MCInst class.
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI)
bool check()
Check that the packet is legal and enforce relative insn order.