33 const HexagonMCChecker::PredSense
34 HexagonMCChecker::Unconditional(Hexagon::NoRegister,
false);
36 void HexagonMCChecker::init() {
38 ReadOnly.insert(Hexagon::PC);
39 ReadOnly.insert(Hexagon::C9_8);
43 Defs[Hexagon::SA0].
insert(Unconditional);
44 Defs[Hexagon::LC0].
insert(Unconditional);
47 Defs[Hexagon::SA1].
insert(Unconditional);
48 Defs[Hexagon::LC1].
insert(Unconditional);
54 MCInst const &Inst = *
I.getInst();
65 void HexagonMCChecker::initReg(
MCInst const &MCI,
unsigned R,
unsigned &PredReg,
74 NewPreds.insert(PredReg);
85 void HexagonMCChecker::init(
MCInst const &MCI) {
87 unsigned PredReg = Hexagon::NoRegister;
99 for (; *ImpDef; ++ImpDef) {
100 unsigned R = *ImpDef;
102 if (Hexagon::R31 != R && MCID.
isCall())
106 if (Hexagon::PC == R)
111 if (Hexagon::USR_OVF == R)
118 else if (isPredicateRegister(R) &&
123 Defs[R].
insert(PredSense(PredReg, isTrue));
127 for (
unsigned i = 0; i < MCID.
getNumDefs(); ++i) {
132 if (R == Hexagon::C8)
152 if (Hexagon::P3_0 != R && Hexagon::P3_0 == *SRI)
157 SoftDefs.insert(*SRI);
159 isPredicateRegister(*SRI))
161 LatePreds.insert(*SRI);
169 TmpDefs.insert(*SRI);
175 Defs[*SRI].
insert(PredSense(PredReg, isTrue));
184 compoundRegisterMap(R);
214 if (isPredicateRegister(P))
225 NewUses[N] = NewSense::Jmp(
228 NewUses[
N] = NewSense::Use(
237 : Context(Context), MCB(mcb), RI(ri), MCII(MCII), STI(STI),
238 ReportErrors(ReportErrors) {
243 bool chkB = checkBranches();
244 bool chkP = checkPredicates();
245 bool chkNV = checkNewValues();
246 bool chkR = checkRegisters();
247 bool chkRRO = checkRegistersReadOnly();
248 bool chkELB = checkEndloopBranches();
249 checkRegisterCurDefs();
250 bool chkS = checkSolo();
253 chkSh = checkShuffle();
256 chkSl = checkSlots();
257 bool chkAXOK = checkAXOK();
258 bool chk = chkB && chkP && chkNV && chkR && chkRRO && chkELB && chkS &&
259 chkSh && chkSl && chkAXOK;
264 bool HexagonMCChecker::checkEndloopBranches() {
272 (Inner ?
"0" :
"1") +
"' " +
273 "cannot contain instructions that modify register " +
283 bool isDuplexAGroup(
unsigned Opcode) {
285 case Hexagon::SA1_addi:
286 case Hexagon::SA1_addrx:
287 case Hexagon::SA1_addsp:
288 case Hexagon::SA1_and1:
289 case Hexagon::SA1_clrf:
290 case Hexagon::SA1_clrfnew:
291 case Hexagon::SA1_clrt:
292 case Hexagon::SA1_clrtnew:
293 case Hexagon::SA1_cmpeqi:
294 case Hexagon::SA1_combine0i:
295 case Hexagon::SA1_combine1i:
296 case Hexagon::SA1_combine2i:
297 case Hexagon::SA1_combine3i:
298 case Hexagon::SA1_combinerz:
299 case Hexagon::SA1_combinezr:
300 case Hexagon::SA1_dec:
301 case Hexagon::SA1_inc:
302 case Hexagon::SA1_seti:
303 case Hexagon::SA1_setin1:
304 case Hexagon::SA1_sxtb:
305 case Hexagon::SA1_sxth:
306 case Hexagon::SA1_tfr:
307 case Hexagon::SA1_zxtb:
308 case Hexagon::SA1_zxth:
322 Result += !isDuplexAGroup(subInst0Opcode);
323 Result += !isDuplexAGroup(subInst1Opcode);
334 bool HexagonMCChecker::checkAXOK() {
335 MCInst const *HasSoloAXInst =
nullptr;
344 if (&
I != HasSoloAXInst && isNeitherAnorX(MCII,
I)) {
347 llvm::Twine(
"Instruction can only be in a packet with ALU or "
348 "non-FPU XTYPE instructions"));
350 llvm::Twine(
"Not an ALU or non-FPU XTYPE instruction"));
357 bool HexagonMCChecker::checkSlots() {
358 unsigned slotsUsed = 0;
360 MCInst const &MCI = *HMI.getInst();
370 reportError(
"invalid instruction packet: out of slots");
377 bool HexagonMCChecker::checkBranches() {
379 bool hasConditional =
false;
384 i < MCB.
size(); ++i) {
394 hasConditional =
true;
403 if (!hasConditional || Conditional > Unconditional) {
407 "unconditional branch cannot precede another branch in packet");
416 bool HexagonMCChecker::checkPredicates() {
418 for (
const auto &
I : NewPreds) {
421 if (!Defs.
count(P) || LatePreds.count(P)) {
431 for (
const auto &
I : LatePreds) {
434 if (LatePreds.count(P) > 1 || Defs.
count(P)) {
447 bool HexagonMCChecker::checkNewValues() {
448 for (
auto &
I : NewUses) {
449 unsigned R =
I.first;
450 NewSense &US =
I.second;
452 if (!hasValidNewValueDef(US, NewDefs[R])) {
461 bool HexagonMCChecker::checkRegistersReadOnly() {
463 MCInst const &Inst = *
I.getInst();
465 for (
unsigned j = 0; j < Defs; ++j) {
467 assert(Operand.
isReg() &&
"Def is not a register");
469 if (ReadOnly.find(Register) != ReadOnly.end()) {
479 bool HexagonMCChecker::registerUsed(
unsigned Register) {
482 n =
I.getNumOperands();
491 void HexagonMCChecker::checkRegisterCurDefs() {
495 unsigned Register =
I.getOperand(0).getReg();
496 if (!registerUsed(Register))
498 "' used with `.cur' "
499 "but not used in the same packet");
505 bool HexagonMCChecker::checkRegisters() {
507 for (
const auto &
I : Defs) {
508 unsigned R =
I.first;
510 if (isLoopRegister(R) && Defs.count(R) > 1 &&
514 reportError(
"loop-setup and some branch instructions "
515 "cannot be in the same packet");
518 if (SoftDefs.count(R)) {
521 unsigned UsrR = Hexagon::USR;
522 unsigned BadR = RI.
isSubRegister(Hexagon::USR, R) ? UsrR : R;
526 if (!isPredicateRegister(R) && Defs[R].size() > 1) {
528 PredSet &PM = Defs[R];
531 if (PM.count(Unconditional)) {
534 unsigned UsrR = Hexagon::USR;
535 unsigned BadR = RI.
isSubRegister(Hexagon::USR, R) ? UsrR : R;
540 for (
const auto &J : PM) {
544 if (PM.count(P) > 1) {
551 P.second = !P.second;
552 if (PM.count(P) && PM.size() > 2) {
564 for (
const auto &
I : TmpDefs) {
567 if (!Uses.count(R)) {
569 bool vHistFound =
false;
578 if (vHistFound ==
false) {
580 "' used with `.tmp' "
581 "but not used in the same packet");
591 bool HexagonMCChecker::checkSolo() {
595 reportError(
I.getLoc(),
"Instruction is marked `isSolo' and "
596 "cannot have other instructions in "
605 bool HexagonMCChecker::checkShuffle() {
607 return MCSDX.check();
610 void HexagonMCChecker::compoundRegisterMap(
unsigned &Register) {
615 Register = Hexagon::R23;
618 Register = Hexagon::R22;
621 Register = Hexagon::R21;
624 Register = Hexagon::R20;
627 Register = Hexagon::R19;
630 Register = Hexagon::R18;
633 Register = Hexagon::R17;
636 Register = Hexagon::R16;
641 bool HexagonMCChecker::hasValidNewValueDef(
const NewSense &
Use,
642 const NewSenseList &Defs)
const {
645 for (
unsigned i = 0, n = Defs.size(); i < n; ++i) {
646 const NewSense &
Def = Defs[i];
648 if (Use.IsNVJ && (Def.IsFloat || Def.PredReg != 0))
652 if (Def.PredReg == 0)
657 if (Def.PredReg == Use.PredReg && Def.Cond == Use.Cond)
663 if (Def.PredReg != Use.PredReg || Def.Cond == Use.Cond)
672 "' modified more than once");
677 "' used with `.new' "
678 "but not validly modified in the same packet");
void reportErrorNewValue(unsigned Register)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Describe properties that are true of each instruction in the target description file.
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
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 isSubRegister(unsigned RegA, unsigned RegB) const
Returns true if RegB is a sub-register of RegA.
bool isOuterLoop(MCInst const &MCI)
bool isNewValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn expects newly produced value.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
bool isImmext(MCInst const &MCI)
MCOperand const & getNewValueOperand2(MCInstrInfo const &MCII, MCInst const &MCI)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A Use represents the edge between a Value definition and its users.
#define HEXAGON_PACKET_SIZE
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
bool isCall() const
Return true if the instruction is a call.
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
void reportWarning(llvm::Twine const &Msg)
Context object for machine code objects.
unsigned getReg() const
Returns the register number.
const MCPhysReg * getImplicitDefs() const
Return a list of registers that are potentially written by any instance of this machine instruction...
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)
bool isCompound(MCInstrInfo const &MCII, MCInst const &MCI)
The instances of the Type class are immutable: once they are created, they are never changed...
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.
void reportError(SMLoc L, const Twine &Msg)
const SourceMgr * getSourceManager() const
MCSubRegIterator enumerates all sub-registers of Reg.
size_t const bundleInstructionsOffset
HexagonMCChecker(MCContext &Context, MCInstrInfo const &MCII, MCSubtargetInfo const &STI, MCInst &mcb, const MCRegisterInfo &ri, bool ReportErrors=true)
Promote Memory to Register
bool isCVINew(MCInstrInfo const &MCII, MCInst const &MCI)
void reportErrorRegisters(unsigned Register)
unsigned getOpcode() const
bool isPredicated(MCInstrInfo const &MCII, 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 isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with A and X-type insns.
MCSubtargetInfo - Generic base class for all target subtargets.
const MCInst * getInst() const
#define HEXAGON_PRESHUFFLE_PACKET_SIZE
MCInstrDesc const & getDesc(MCInstrInfo const &MCII, MCInst const &MCI)
const MCPhysReg * getImplicitUses() const
Return a list of registers that are potentially read by any instance of this machine instruction...
INITIALIZE_PASS(HexagonGenMux,"hexagon-gen-mux","Hexagon generate mux instructions", false, false) void HexagonGenMux I isValid()
size_t bundleSize(MCInst const &MCI)
bool check(bool FullCheck=true)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isInnerLoop(MCInst const &MCI)
static bool isBranch(unsigned Opcode)
bool isFloat(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether it is a floating-point insn.
bool isPredicateLate(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
const char * getName(unsigned RegNo) const
Return the human-readable symbolic target-specific name for the specified physical register...
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 reportError(SMLoc Loc, llvm::Twine const &Msg)
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.
Represents a location in source code.
Instances of this class represent operands of the MCInst class.
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI)
const MCOperand & getOperand(unsigned i) const
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)