34 const HexagonMCChecker::PredSense
35 HexagonMCChecker::Unconditional(Hexagon::NoRegister,
false);
37 void HexagonMCChecker::init() {
39 ReadOnly.insert(Hexagon::PC);
40 ReadOnly.insert(Hexagon::C9_8);
44 Defs[Hexagon::SA0].
insert(Unconditional);
45 Defs[Hexagon::LC0].
insert(Unconditional);
48 Defs[Hexagon::SA1].
insert(Unconditional);
49 Defs[Hexagon::LC1].
insert(Unconditional);
55 MCInst const &Inst = *
I.getInst();
66 void HexagonMCChecker::initReg(
MCInst const &MCI,
unsigned R,
unsigned &PredReg,
75 NewPreds.insert(PredReg);
86 void HexagonMCChecker::init(
MCInst const &MCI) {
88 unsigned PredReg = Hexagon::NoRegister;
100 for (; *ImpDef; ++ImpDef) {
101 unsigned R = *ImpDef;
103 if (Hexagon::R31 != R && MCID.
isCall())
107 if (Hexagon::PC == R)
112 if (Hexagon::USR_OVF == R)
119 else if (isPredicateRegister(R) &&
124 Defs[R].
insert(PredSense(PredReg, isTrue));
128 for (
unsigned i = 0; i < MCID.
getNumDefs(); ++i) {
133 if (R == Hexagon::C8)
153 if (Hexagon::P3_0 != R && Hexagon::P3_0 == *SRI)
158 SoftDefs.insert(*SRI);
160 isPredicateRegister(*SRI))
162 LatePreds.insert(*SRI);
170 TmpDefs.insert(*SRI);
176 Defs[*SRI].
insert(PredSense(PredReg, isTrue));
186 if (isPredicateRegister(P))
194 : Context(Context), MCB(mcb), RI(ri), MCII(MCII), STI(STI),
195 ReportErrors(ReportErrors) {
201 bool CopyReportErrors)
202 : Context(Other.Context), MCB(Other.MCB), RI(Other.RI), MCII(Other.MCII),
203 STI(STI), ReportErrors(CopyReportErrors ? Other.ReportErrors :
false) {}
206 bool chkP = checkPredicates();
207 bool chkNV = checkNewValues();
208 bool chkR = checkRegisters();
209 bool chkRRO = checkRegistersReadOnly();
210 checkRegisterCurDefs();
211 bool chkS = checkSolo();
214 chkSh = checkShuffle();
217 chkSl = checkSlots();
218 bool chkAXOK = checkAXOK();
219 bool chkCofMax1 = checkCOFMax1();
220 bool chkHWLoop = checkHWLoop();
221 bool chk = chkP && chkNV && chkR && chkRRO && chkS && chkSh && chkSl &&
222 chkAXOK && chkCofMax1 && chkHWLoop;
229 case Hexagon::SA1_addi:
230 case Hexagon::SA1_addrx:
231 case Hexagon::SA1_addsp:
232 case Hexagon::SA1_and1:
233 case Hexagon::SA1_clrf:
234 case Hexagon::SA1_clrfnew:
235 case Hexagon::SA1_clrt:
236 case Hexagon::SA1_clrtnew:
237 case Hexagon::SA1_cmpeqi:
238 case Hexagon::SA1_combine0i:
239 case Hexagon::SA1_combine1i:
240 case Hexagon::SA1_combine2i:
241 case Hexagon::SA1_combine3i:
242 case Hexagon::SA1_combinerz:
243 case Hexagon::SA1_combinezr:
244 case Hexagon::SA1_dec:
245 case Hexagon::SA1_inc:
246 case Hexagon::SA1_seti:
247 case Hexagon::SA1_setin1:
248 case Hexagon::SA1_sxtb:
249 case Hexagon::SA1_sxth:
250 case Hexagon::SA1_tfr:
251 case Hexagon::SA1_zxtb:
252 case Hexagon::SA1_zxth:
277 bool HexagonMCChecker::checkAXOK() {
278 MCInst const *HasSoloAXInst =
nullptr;
290 Twine(
"Instruction can only be in a packet with ALU or non-FPU XTYPE " 293 Twine(
"Not an ALU or non-FPU XTYPE instruction"));
308 bool HexagonMCChecker::checkHWLoop() {
316 "Branches cannot be in a packet with hardware loops");
324 bool HexagonMCChecker::checkCOFMax1() {
331 for (
unsigned J = 0,
N = BranchLocations.
size(); J <
N; ++J) {
332 MCInst const &
I = *BranchLocations[J];
336 if (N > 1 && !Relax1 && !Relax2) {
338 "Instruction may not be in a packet with other branches");
342 if (N > 1 && J == 0 && !Relax1) {
344 "Instruction may not be the first branch in packet");
348 if (N > 1 && J == 1 && !Relax2) {
350 "Instruction may not be the second branch in packet");
359 bool HexagonMCChecker::checkSlots() {
360 unsigned slotsUsed = 0;
362 MCInst const &MCI = *HMI.getInst();
372 reportError(
"invalid instruction packet: out of slots");
379 bool HexagonMCChecker::checkPredicates() {
381 for (
const auto &
I : NewPreds) {
384 if (!Defs.
count(P) || LatePreds.count(P)) {
394 for (
const auto &
I : LatePreds) {
397 if (LatePreds.count(P) > 1 || Defs.
count(P)) {
410 bool HexagonMCChecker::checkNewValues() {
418 auto Producer = registerProducer(Op.
getReg(), Consumer);
419 if (std::get<0>(Producer) ==
nullptr) {
420 reportError(
I.getLoc(),
"New value register consumer has no producer");
425 if (std::get<2>(Producer).isPredicated() &&
426 (!Consumer.isPredicated() ||
429 std::get<0>(Producer)->getLoc(),
430 "Register producer is predicated and consumer is unconditional");
432 "Instruction does not have a valid new register producer");
435 if (std::get<2>(Producer).Register != Hexagon::NoRegister &&
438 "Register producer does not use the same predicate " 439 "register as the consumer");
441 "Instruction does not have a valid new register producer");
445 if (std::get<2>(Producer).Register == Consumer.Register &&
446 Consumer.PredicatedTrue != std::get<2>(Producer).PredicatedTrue) {
448 std::get<0>(Producer)->getLoc(),
449 "Register producer has the opposite predicate sense as consumer");
451 "Instruction does not have a valid new register producer");
457 Hexagon::DoubleRegsRegClassID) {
459 "Double registers cannot be new-value producers");
461 "Instruction does not have a valid new register producer");
464 if ((Desc.
mayLoad() && std::get<1>(Producer) == 1) ||
465 (Desc.
mayStore() && std::get<1>(Producer) == 0)) {
470 ModeError =
"Absolute-set";
472 ModeError =
"Auto-increment";
473 if (!ModeError.
empty()) {
475 ModeError +
" registers cannot be a new-value " 478 "Instruction does not have a valid new register producer");
484 "FPU instructions cannot be new-value producers for jumps");
486 "Instruction does not have a valid new register producer");
493 bool HexagonMCChecker::checkRegistersReadOnly() {
495 MCInst const &Inst = *
I.getInst();
497 for (
unsigned j = 0; j < Defs; ++j) {
499 assert(Operand.
isReg() &&
"Def is not a register");
501 if (ReadOnly.find(Register) != ReadOnly.end()) {
511 bool HexagonMCChecker::registerUsed(
unsigned Register) {
514 n =
I.getNumOperands();
523 std::tuple<MCInst const *, unsigned, HexagonMCInstrInfo::PredicateInfo>
524 HexagonMCChecker::registerProducer(
526 std::tuple<MCInst const *, unsigned, HexagonMCInstrInfo::PredicateInfo>
534 if (*K == Register) {
536 (ProducerPredicate.Register == ConsumerPredicate.
Register &&
537 (ProducerPredicate.Register == Hexagon::NoRegister ||
538 ProducerPredicate.PredicatedTrue ==
540 return std::make_tuple(&
I, J, ProducerPredicate);
541 std::get<0>(WrongSense) = &
I;
542 std::get<1>(WrongSense) = J;
543 std::get<2>(WrongSense) = ProducerPredicate;
551 void HexagonMCChecker::checkRegisterCurDefs() {
555 unsigned Register =
I.getOperand(0).getReg();
556 if (!registerUsed(Register))
558 "' used with `.cur' " 559 "but not used in the same packet");
565 bool HexagonMCChecker::checkRegisters() {
567 for (
const auto &
I : Defs) {
568 unsigned R =
I.first;
570 if (isLoopRegister(R) && Defs.count(R) > 1 &&
574 reportError(
"loop-setup and some branch instructions " 575 "cannot be in the same packet");
578 if (SoftDefs.count(R)) {
581 unsigned UsrR = Hexagon::USR;
582 unsigned BadR = RI.
isSubRegister(Hexagon::USR, R) ? UsrR : R;
586 if (!isPredicateRegister(R) && Defs[R].
size() > 1) {
588 PredSet &PM = Defs[R];
591 if (PM.count(Unconditional)) {
594 unsigned UsrR = Hexagon::USR;
595 unsigned BadR = RI.
isSubRegister(Hexagon::USR, R) ? UsrR : R;
600 for (
const auto &J : PM) {
604 if (PM.count(P) > 1) {
611 P.second = !P.second;
612 if (PM.count(P) && PM.size() > 2) {
624 for (
const auto &
I : TmpDefs) {
627 if (!Uses.count(R)) {
629 bool vHistFound =
false;
640 "' used with `.tmp' but not used in the same packet");
650 bool HexagonMCChecker::checkSolo() {
654 reportError(
I.getLoc(),
"Instruction is marked `isSolo' and " 655 "cannot have other instructions in " 664 bool HexagonMCChecker::checkShuffle() {
666 return MCSDX.
check();
669 void HexagonMCChecker::compoundRegisterMap(
unsigned &Register) {
674 Register = Hexagon::R23;
677 Register = Hexagon::R22;
680 Register = Hexagon::R21;
683 Register = Hexagon::R20;
686 Register = Hexagon::R19;
689 Register = Hexagon::R18;
692 Register = Hexagon::R17;
695 Register = Hexagon::R16;
702 "' modified more than once");
707 "' used with `.new' " 708 "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)
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)
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
unsigned getReg() const
Returns the register number.
void reportWarning(Twine const &Msg)
Context object for machine code objects.
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...
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)
void reportWarning(SMLoc L, const Twine &Msg)
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
void reportErrorRegisters(unsigned Register)
bool isSubRegister(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a sub-register of RegA.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
const char * getName(MCRegister RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register...
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)
Wrapper class representing virtual and physical registers.
bool check()
Check that the packet is legal and enforce relative insn order.