LLVM  5.0.0
HexagonMCChecker.cpp
Go to the documentation of this file.
1 //===----- HexagonMCChecker.cpp - Instruction bundle checking -------------===//
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 implements the checking of insns inside a bundle according to the
11 // packet constraint rules of the Hexagon ISA.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "HexagonMCChecker.h"
16 
17 #include "HexagonBaseInfo.h"
18 
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCInstrDesc.h"
21 #include "llvm/MC/MCInstrInfo.h"
23 #include "llvm/Support/Debug.h"
24 #include "llvm/Support/SourceMgr.h"
26 
27 using namespace llvm;
28 
29 static cl::opt<bool>
30  RelaxNVChecks("relax-nv-checks", cl::init(false), cl::ZeroOrMore,
31  cl::Hidden, cl::desc("Relax checks of new-value validity"));
32 
33 const HexagonMCChecker::PredSense
34  HexagonMCChecker::Unconditional(Hexagon::NoRegister, false);
35 
36 void HexagonMCChecker::init() {
37  // Initialize read-only registers set.
38  ReadOnly.insert(Hexagon::PC);
39  ReadOnly.insert(Hexagon::C9_8);
40 
41  // Figure out the loop-registers definitions.
43  Defs[Hexagon::SA0].insert(Unconditional); // FIXME: define or change SA0?
44  Defs[Hexagon::LC0].insert(Unconditional);
45  }
47  Defs[Hexagon::SA1].insert(Unconditional); // FIXME: define or change SA0?
48  Defs[Hexagon::LC1].insert(Unconditional);
49  }
50 
52  // Unfurl a bundle.
53  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
54  MCInst const &Inst = *I.getInst();
55  if (HexagonMCInstrInfo::isDuplex(MCII, Inst)) {
56  init(*Inst.getOperand(0).getInst());
57  init(*Inst.getOperand(1).getInst());
58  } else
59  init(Inst);
60  }
61  else
62  init(MCB);
63 }
64 
65 void HexagonMCChecker::initReg(MCInst const &MCI, unsigned R, unsigned &PredReg,
66  bool &isTrue) {
67  if (HexagonMCInstrInfo::isPredicated(MCII, MCI) && isPredicateRegister(R)) {
68  // Note an used predicate register.
69  PredReg = R;
70  isTrue = HexagonMCInstrInfo::isPredicatedTrue(MCII, MCI);
71 
72  // Note use of new predicate register.
74  NewPreds.insert(PredReg);
75  } else
76  // Note register use. Super-registers are not tracked directly,
77  // but their components.
78  for (MCRegAliasIterator SRI(R, &RI, !MCSubRegIterator(R, &RI).isValid());
79  SRI.isValid(); ++SRI)
80  if (!MCSubRegIterator(*SRI, &RI).isValid())
81  // Skip super-registers used indirectly.
82  Uses.insert(*SRI);
83 }
84 
85 void HexagonMCChecker::init(MCInst const &MCI) {
86  const MCInstrDesc &MCID = HexagonMCInstrInfo::getDesc(MCII, MCI);
87  unsigned PredReg = Hexagon::NoRegister;
88  bool isTrue = false;
89 
90  // Get used registers.
91  for (unsigned i = MCID.getNumDefs(); i < MCID.getNumOperands(); ++i)
92  if (MCI.getOperand(i).isReg())
93  initReg(MCI, MCI.getOperand(i).getReg(), PredReg, isTrue);
94  for (unsigned i = 0; i < MCID.getNumImplicitUses(); ++i)
95  initReg(MCI, MCID.getImplicitUses()[i], PredReg, isTrue);
96 
97  // Get implicit register definitions.
98  if (const MCPhysReg *ImpDef = MCID.getImplicitDefs())
99  for (; *ImpDef; ++ImpDef) {
100  unsigned R = *ImpDef;
101 
102  if (Hexagon::R31 != R && MCID.isCall())
103  // Any register other than the LR and the PC are actually volatile ones
104  // as defined by the ABI, not modified implicitly by the call insn.
105  continue;
106  if (Hexagon::PC == R)
107  // Branches are the only insns that can change the PC,
108  // otherwise a read-only register.
109  continue;
110 
111  if (Hexagon::USR_OVF == R)
112  // Many insns change the USR implicitly, but only one or another flag.
113  // The instruction table models the USR.OVF flag, which can be
114  // implicitly modified more than once, but cannot be modified in the
115  // same packet with an instruction that modifies is explicitly. Deal
116  // with such situations individually.
117  SoftDefs.insert(R);
118  else if (isPredicateRegister(R) &&
120  // Include implicit late predicates.
121  LatePreds.insert(R);
122  else
123  Defs[R].insert(PredSense(PredReg, isTrue));
124  }
125 
126  // Figure out explicit register definitions.
127  for (unsigned i = 0; i < MCID.getNumDefs(); ++i) {
128  unsigned R = MCI.getOperand(i).getReg(), S = Hexagon::NoRegister;
129  // USR has subregisters (while C8 does not for technical reasons), so
130  // reset R to USR, since we know how to handle multiple defs of USR,
131  // taking into account its subregisters.
132  if (R == Hexagon::C8)
133  R = Hexagon::USR;
134 
135  // Note register definitions, direct ones as well as indirect side-effects.
136  // Super-registers are not tracked directly, but their components.
137  for (MCRegAliasIterator SRI(R, &RI, !MCSubRegIterator(R, &RI).isValid());
138  SRI.isValid(); ++SRI) {
139  if (MCSubRegIterator(*SRI, &RI).isValid())
140  // Skip super-registers defined indirectly.
141  continue;
142 
143  if (R == *SRI) {
144  if (S == R)
145  // Avoid scoring the defined register multiple times.
146  continue;
147  else
148  // Note that the defined register has already been scored.
149  S = R;
150  }
151 
152  if (Hexagon::P3_0 != R && Hexagon::P3_0 == *SRI)
153  // P3:0 is a special case, since multiple predicate register definitions
154  // in a packet is allowed as the equivalent of their logical "and".
155  // Only an explicit definition of P3:0 is noted as such; if a
156  // side-effect, then note as a soft definition.
157  SoftDefs.insert(*SRI);
158  else if (HexagonMCInstrInfo::isPredicateLate(MCII, MCI) &&
159  isPredicateRegister(*SRI))
160  // Some insns produce predicates too late to be used in the same packet.
161  LatePreds.insert(*SRI);
162  else if (i == 0 && llvm::HexagonMCInstrInfo::getType(MCII, MCI) ==
164  // Temporary loads should be used in the same packet, but don't commit
165  // results, so it should be disregarded if another insn changes the same
166  // register.
167  // TODO: relies on the impossibility of a current and a temporary loads
168  // in the same packet.
169  TmpDefs.insert(*SRI);
170  else if (i <= 1 && llvm::HexagonMCInstrInfo::hasNewValue2(MCII, MCI))
171  // vshuff(Vx, Vy, Rx) <- Vx(0) and Vy(1) are both source and
172  // destination registers with this instruction. same for vdeal(Vx,Vy,Rx)
173  Uses.insert(*SRI);
174  else
175  Defs[*SRI].insert(PredSense(PredReg, isTrue));
176  }
177  }
178 
179  // Figure out register definitions that produce new values.
180  if (HexagonMCInstrInfo::hasNewValue(MCII, MCI)) {
181  unsigned R = HexagonMCInstrInfo::getNewValueOperand(MCII, MCI).getReg();
182 
183  if (HexagonMCInstrInfo::isCompound(MCII, MCI))
184  compoundRegisterMap(R); // Compound insns have a limited register range.
185 
186  for (MCRegAliasIterator SRI(R, &RI, !MCSubRegIterator(R, &RI).isValid());
187  SRI.isValid(); ++SRI)
188  if (!MCSubRegIterator(*SRI, &RI).isValid())
189  // No super-registers defined indirectly.
190  NewDefs[*SRI].push_back(NewSense::Def(
191  PredReg, HexagonMCInstrInfo::isPredicatedTrue(MCII, MCI),
192  HexagonMCInstrInfo::isFloat(MCII, MCI)));
193 
194  // For fairly unique 2-dot-new producers, example:
195  // vdeal(V1, V9, R0) V1.new and V9.new can be used by consumers.
196  if (HexagonMCInstrInfo::hasNewValue2(MCII, MCI)) {
197  unsigned R2 = HexagonMCInstrInfo::getNewValueOperand2(MCII, MCI).getReg();
198 
199  bool HasSubRegs = MCSubRegIterator(R2, &RI).isValid();
200  for (MCRegAliasIterator SRI(R2, &RI, !HasSubRegs); SRI.isValid(); ++SRI)
201  if (!MCSubRegIterator(*SRI, &RI).isValid())
202  NewDefs[*SRI].push_back(NewSense::Def(
203  PredReg, HexagonMCInstrInfo::isPredicatedTrue(MCII, MCI),
204  HexagonMCInstrInfo::isFloat(MCII, MCI)));
205  }
206  }
207 
208  // Figure out definitions of new predicate registers.
210  for (unsigned i = MCID.getNumDefs(); i < MCID.getNumOperands(); ++i)
211  if (MCI.getOperand(i).isReg()) {
212  unsigned P = MCI.getOperand(i).getReg();
213 
214  if (isPredicateRegister(P))
215  NewPreds.insert(P);
216  }
217 
218  // Figure out uses of new values.
219  if (HexagonMCInstrInfo::isNewValue(MCII, MCI)) {
220  unsigned N = HexagonMCInstrInfo::getNewValueOperand(MCII, MCI).getReg();
221 
222  if (!MCSubRegIterator(N, &RI).isValid()) {
223  // Super-registers cannot use new values.
224  if (MCID.isBranch())
225  NewUses[N] = NewSense::Jmp(
227  else
228  NewUses[N] = NewSense::Use(
229  PredReg, HexagonMCInstrInfo::isPredicatedTrue(MCII, MCI));
230  }
231  }
232 }
233 
235  MCSubtargetInfo const &STI, MCInst &mcb,
236  MCRegisterInfo const &ri, bool ReportErrors)
237  : Context(Context), MCB(mcb), RI(ri), MCII(MCII), STI(STI),
238  ReportErrors(ReportErrors) {
239  init();
240 }
241 
242 bool HexagonMCChecker::check(bool FullCheck) {
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();
251  bool chkSh = true;
252  if (FullCheck)
253  chkSh = checkShuffle();
254  bool chkSl = true;
255  if (FullCheck)
256  chkSl = checkSlots();
257  bool chkAXOK = checkAXOK();
258  bool chk = chkB && chkP && chkNV && chkR && chkRRO && chkELB && chkS &&
259  chkSh && chkSl && chkAXOK;
260 
261  return chk;
262 }
263 
264 bool HexagonMCChecker::checkEndloopBranches() {
265  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCII, MCB)) {
267  if (Desc.isBranch() || Desc.isCall()) {
268  auto Inner = HexagonMCInstrInfo::isInnerLoop(MCB);
269  if (Inner || HexagonMCInstrInfo::isOuterLoop(MCB)) {
270  reportError(I.getLoc(),
271  llvm::Twine("packet marked with `:endloop") +
272  (Inner ? "0" : "1") + "' " +
273  "cannot contain instructions that modify register " +
274  "`" + llvm::Twine(RI.getName(Hexagon::PC)) + "'");
275  return false;
276  }
277  }
278  }
279  return true;
280 }
281 
282 namespace {
283 bool isDuplexAGroup(unsigned Opcode) {
284  switch (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:
309  return true;
310  break;
311  default:
312  return false;
313  }
314 }
315 
316 bool isNeitherAnorX(MCInstrInfo const &MCII, MCInst const &ID) {
317  unsigned Result = 0;
318  unsigned Type = HexagonMCInstrInfo::getType(MCII, ID);
319  if (Type == HexagonII::TypeDUPLEX) {
320  unsigned subInst0Opcode = ID.getOperand(0).getInst()->getOpcode();
321  unsigned subInst1Opcode = ID.getOperand(1).getInst()->getOpcode();
322  Result += !isDuplexAGroup(subInst0Opcode);
323  Result += !isDuplexAGroup(subInst1Opcode);
324  } else
325  Result +=
327  Type != HexagonII::TypeALU32_ADDI && Type != HexagonII::TypeS_2op &&
328  Type != HexagonII::TypeS_3op &&
329  (Type != HexagonII::TypeALU64 || HexagonMCInstrInfo::isFloat(MCII, ID));
330  return Result != 0;
331 }
332 } // namespace
333 
334 bool HexagonMCChecker::checkAXOK() {
335  MCInst const *HasSoloAXInst = nullptr;
336  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCII, MCB)) {
337  if (HexagonMCInstrInfo::isSoloAX(MCII, I)) {
338  HasSoloAXInst = &I;
339  }
340  }
341  if (!HasSoloAXInst)
342  return true;
343  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCII, MCB)) {
344  if (&I != HasSoloAXInst && isNeitherAnorX(MCII, I)) {
345  reportError(
346  HasSoloAXInst->getLoc(),
347  llvm::Twine("Instruction can only be in a packet with ALU or "
348  "non-FPU XTYPE instructions"));
349  reportError(I.getLoc(),
350  llvm::Twine("Not an ALU or non-FPU XTYPE instruction"));
351  return false;
352  }
353  }
354  return true;
355 }
356 
357 bool HexagonMCChecker::checkSlots() {
358  unsigned slotsUsed = 0;
359  for (auto HMI : HexagonMCInstrInfo::bundleInstructions(MCB)) {
360  MCInst const &MCI = *HMI.getInst();
362  continue;
363  if (HexagonMCInstrInfo::isDuplex(MCII, MCI))
364  slotsUsed += 2;
365  else
366  ++slotsUsed;
367  }
368 
369  if (slotsUsed > HEXAGON_PACKET_SIZE) {
370  reportError("invalid instruction packet: out of slots");
371  return false;
372  }
373  return true;
374 }
375 
376 // Check legal use of branches.
377 bool HexagonMCChecker::checkBranches() {
378  if (HexagonMCInstrInfo::isBundle(MCB)) {
379  bool hasConditional = false;
380  unsigned Branches = 0, Conditional = HEXAGON_PRESHUFFLE_PACKET_SIZE,
381  Unconditional = HEXAGON_PRESHUFFLE_PACKET_SIZE;
382 
384  i < MCB.size(); ++i) {
385  MCInst const &MCI = *MCB.begin()[i].getInst();
386 
388  continue;
389  if (HexagonMCInstrInfo::getDesc(MCII, MCI).isBranch() ||
390  HexagonMCInstrInfo::getDesc(MCII, MCI).isCall()) {
391  ++Branches;
392  if (HexagonMCInstrInfo::isPredicated(MCII, MCI) ||
394  hasConditional = true;
395  Conditional = i; // Record the position of the conditional branch.
396  } else {
397  Unconditional = i; // Record the position of the unconditional branch.
398  }
399  }
400  }
401 
402  if (Branches > 1)
403  if (!hasConditional || Conditional > Unconditional) {
404  // Error out if more than one unconditional branch or
405  // the conditional branch appears after the unconditional one.
406  reportError(
407  "unconditional branch cannot precede another branch in packet");
408  return false;
409  }
410  }
411 
412  return true;
413 }
414 
415 // Check legal use of predicate registers.
416 bool HexagonMCChecker::checkPredicates() {
417  // Check for proper use of new predicate registers.
418  for (const auto &I : NewPreds) {
419  unsigned P = I;
420 
421  if (!Defs.count(P) || LatePreds.count(P)) {
422  // Error out if the new predicate register is not defined,
423  // or defined "late"
424  // (e.g., "{ if (p3.new)... ; p3 = sp1loop0(#r7:2, Rs) }").
426  return false;
427  }
428  }
429 
430  // Check for proper use of auto-anded of predicate registers.
431  for (const auto &I : LatePreds) {
432  unsigned P = I;
433 
434  if (LatePreds.count(P) > 1 || Defs.count(P)) {
435  // Error out if predicate register defined "late" multiple times or
436  // defined late and regularly defined
437  // (e.g., "{ p3 = sp1loop0(...); p3 = cmp.eq(...) }".
439  return false;
440  }
441  }
442 
443  return true;
444 }
445 
446 // Check legal use of new values.
447 bool HexagonMCChecker::checkNewValues() {
448  for (auto &I : NewUses) {
449  unsigned R = I.first;
450  NewSense &US = I.second;
451 
452  if (!hasValidNewValueDef(US, NewDefs[R])) {
454  return false;
455  }
456  }
457 
458  return true;
459 }
460 
461 bool HexagonMCChecker::checkRegistersReadOnly() {
462  for (auto I : HexagonMCInstrInfo::bundleInstructions(MCB)) {
463  MCInst const &Inst = *I.getInst();
464  unsigned Defs = HexagonMCInstrInfo::getDesc(MCII, Inst).getNumDefs();
465  for (unsigned j = 0; j < Defs; ++j) {
466  MCOperand const &Operand = Inst.getOperand(j);
467  assert(Operand.isReg() && "Def is not a register");
468  unsigned Register = Operand.getReg();
469  if (ReadOnly.find(Register) != ReadOnly.end()) {
470  reportError(Inst.getLoc(), "Cannot write to read-only register `" +
471  llvm::Twine(RI.getName(Register)) + "'");
472  return false;
473  }
474  }
475  }
476  return true;
477 }
478 
479 bool HexagonMCChecker::registerUsed(unsigned Register) {
480  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCII, MCB))
481  for (unsigned j = HexagonMCInstrInfo::getDesc(MCII, I).getNumDefs(),
482  n = I.getNumOperands();
483  j < n; ++j) {
484  MCOperand const &Operand = I.getOperand(j);
485  if (Operand.isReg() && Operand.getReg() == Register)
486  return true;
487  }
488  return false;
489 }
490 
491 void HexagonMCChecker::checkRegisterCurDefs() {
492  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCII, MCB)) {
493  if (HexagonMCInstrInfo::isCVINew(MCII, I) &&
494  HexagonMCInstrInfo::getDesc(MCII, I).mayLoad()) {
495  unsigned Register = I.getOperand(0).getReg();
496  if (!registerUsed(Register))
497  reportWarning("Register `" + llvm::Twine(RI.getName(Register)) +
498  "' used with `.cur' "
499  "but not used in the same packet");
500  }
501  }
502 }
503 
504 // Check for legal register uses and definitions.
505 bool HexagonMCChecker::checkRegisters() {
506  // Check for proper register definitions.
507  for (const auto &I : Defs) {
508  unsigned R = I.first;
509 
510  if (isLoopRegister(R) && Defs.count(R) > 1 &&
513  // Error out for definitions of loop registers at the end of a loop.
514  reportError("loop-setup and some branch instructions "
515  "cannot be in the same packet");
516  return false;
517  }
518  if (SoftDefs.count(R)) {
519  // Error out for explicit changes to registers also weakly defined
520  // (e.g., "{ usr = r0; r0 = sfadd(...) }").
521  unsigned UsrR = Hexagon::USR; // Silence warning about mixed types in ?:.
522  unsigned BadR = RI.isSubRegister(Hexagon::USR, R) ? UsrR : R;
523  reportErrorRegisters(BadR);
524  return false;
525  }
526  if (!isPredicateRegister(R) && Defs[R].size() > 1) {
527  // Check for multiple register definitions.
528  PredSet &PM = Defs[R];
529 
530  // Check for multiple unconditional register definitions.
531  if (PM.count(Unconditional)) {
532  // Error out on an unconditional change when there are any other
533  // changes, conditional or not.
534  unsigned UsrR = Hexagon::USR;
535  unsigned BadR = RI.isSubRegister(Hexagon::USR, R) ? UsrR : R;
536  reportErrorRegisters(BadR);
537  return false;
538  }
539  // Check for multiple conditional register definitions.
540  for (const auto &J : PM) {
541  PredSense P = J;
542 
543  // Check for multiple uses of the same condition.
544  if (PM.count(P) > 1) {
545  // Error out on conditional changes based on the same predicate
546  // (e.g., "{ if (!p0) r0 =...; if (!p0) r0 =... }").
548  return false;
549  }
550  // Check for the use of the complementary condition.
551  P.second = !P.second;
552  if (PM.count(P) && PM.size() > 2) {
553  // Error out on conditional changes based on the same predicate
554  // multiple times
555  // (e.g., "if (p0) r0 =...; if (!p0) r0 =... }; if (!p0) r0 =...").
557  return false;
558  }
559  }
560  }
561  }
562 
563  // Check for use of temporary definitions.
564  for (const auto &I : TmpDefs) {
565  unsigned R = I;
566 
567  if (!Uses.count(R)) {
568  // special case for vhist
569  bool vHistFound = false;
570  for (auto const &HMI : HexagonMCInstrInfo::bundleInstructions(MCB)) {
571  if (llvm::HexagonMCInstrInfo::getType(MCII, *HMI.getInst()) ==
573  vHistFound = true; // vhist() implicitly uses ALL REGxx.tmp
574  break;
575  }
576  }
577  // Warn on an unused temporary definition.
578  if (vHistFound == false) {
579  reportWarning("register `" + llvm::Twine(RI.getName(R)) +
580  "' used with `.tmp' "
581  "but not used in the same packet");
582  return true;
583  }
584  }
585  }
586 
587  return true;
588 }
589 
590 // Check for legal use of solo insns.
591 bool HexagonMCChecker::checkSolo() {
592  if (HexagonMCInstrInfo::bundleSize(MCB) > 1)
593  for (auto const &I : HexagonMCInstrInfo::bundleInstructions(MCII, MCB)) {
594  if (llvm::HexagonMCInstrInfo::isSolo(MCII, I)) {
595  reportError(I.getLoc(), "Instruction is marked `isSolo' and "
596  "cannot have other instructions in "
597  "the same packet");
598  return false;
599  }
600  }
601 
602  return true;
603 }
604 
605 bool HexagonMCChecker::checkShuffle() {
606  HexagonMCShuffler MCSDX(Context, ReportErrors, MCII, STI, MCB);
607  return MCSDX.check();
608 }
609 
610 void HexagonMCChecker::compoundRegisterMap(unsigned &Register) {
611  switch (Register) {
612  default:
613  break;
614  case Hexagon::R15:
615  Register = Hexagon::R23;
616  break;
617  case Hexagon::R14:
618  Register = Hexagon::R22;
619  break;
620  case Hexagon::R13:
621  Register = Hexagon::R21;
622  break;
623  case Hexagon::R12:
624  Register = Hexagon::R20;
625  break;
626  case Hexagon::R11:
627  Register = Hexagon::R19;
628  break;
629  case Hexagon::R10:
630  Register = Hexagon::R18;
631  break;
632  case Hexagon::R9:
633  Register = Hexagon::R17;
634  break;
635  case Hexagon::R8:
636  Register = Hexagon::R16;
637  break;
638  }
639 }
640 
641 bool HexagonMCChecker::hasValidNewValueDef(const NewSense &Use,
642  const NewSenseList &Defs) const {
643  bool Strict = !RelaxNVChecks;
644 
645  for (unsigned i = 0, n = Defs.size(); i < n; ++i) {
646  const NewSense &Def = Defs[i];
647  // NVJ cannot use a new FP value [7.6.1]
648  if (Use.IsNVJ && (Def.IsFloat || Def.PredReg != 0))
649  continue;
650  // If the definition was not predicated, then it does not matter if
651  // the use is.
652  if (Def.PredReg == 0)
653  return true;
654  // With the strict checks, both the definition and the use must be
655  // predicated on the same register and condition.
656  if (Strict) {
657  if (Def.PredReg == Use.PredReg && Def.Cond == Use.Cond)
658  return true;
659  } else {
660  // With the relaxed checks, if the definition was predicated, the only
661  // detectable violation is if the use is predicated on the opposing
662  // condition, otherwise, it's ok.
663  if (Def.PredReg != Use.PredReg || Def.Cond == Use.Cond)
664  return true;
665  }
666  }
667  return false;
668 }
669 
670 void HexagonMCChecker::reportErrorRegisters(unsigned Register) {
671  reportError("register `" + llvm::Twine(RI.getName(Register)) +
672  "' modified more than once");
673 }
674 
675 void HexagonMCChecker::reportErrorNewValue(unsigned Register) {
676  reportError("register `" + llvm::Twine(RI.getName(Register)) +
677  "' used with `.new' "
678  "but not validly modified in the same packet");
679 }
680 
682  reportError(MCB.getLoc(), Msg);
683 }
684 
686  if (ReportErrors)
687  Context.reportError(Loc, Msg);
688 }
689 
691  if (ReportErrors) {
692  auto SM = Context.getSourceManager();
693  if (SM)
694  SM->PrintMessage(MCB.getLoc(), SourceMgr::DK_Warning, Msg);
695  }
696 }
void reportErrorNewValue(unsigned Register)
bool isDuplex(MCInstrInfo const &MCII, MCInst const &MCI)
iterator begin()
Definition: MCInst.h:185
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
Definition: MCInstrDesc.h:515
LLVMContext & Context
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
bool isReg() const
Definition: MCInst.h:58
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Definition: MCInstrDesc.h:225
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:163
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.
#define R2(n)
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)
Definition: DenseMap.h:176
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...
Definition: Twine.h:81
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
#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 isCall() const
Return true if the instruction is a call.
Definition: MCInstrDesc.h:251
iterator_range< Hexagon::PacketIterator > bundleInstructions(MCInstrInfo const &MCII, MCInst const &MCI)
void reportWarning(llvm::Twine const &Msg)
Context object for machine code objects.
Definition: MCContext.h:59
unsigned getReg() const
Returns the register number.
Definition: MCInst.h:65
const MCPhysReg * getImplicitDefs() const
Return a list of registers that are potentially written by any instance of this machine instruction...
Definition: MCInstrDesc.h:534
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.
Definition: MCInst.h:159
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...
#define P(N)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:401
bool isCompound(MCInstrInfo const &MCII, MCInst const &MCI)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
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)
Definition: MCContext.cpp:608
SMLoc getLoc() const
Definition: MCInst.h:171
const SourceMgr * getSourceManager() const
Definition: MCContext.h:279
MCSubRegIterator enumerates all sub-registers of Reg.
size_t size() const
Definition: MCInst.h:184
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
Definition: Mem2Reg.cpp:101
const size_t N
bool isCVINew(MCInstrInfo const &MCII, MCInst const &MCI)
void reportErrorRegisters(unsigned Register)
unsigned getOpcode() const
Definition: MCInst.h:168
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.
Definition: DenseMap.h:126
bool isSoloAX(MCInstrInfo const &MCII, MCInst const &MCI)
Return whether the insn can be packaged only with A and X-type insns.
#define I(x, y, z)
Definition: MD5.cpp:58
MCSubtargetInfo - Generic base class for all target subtargets.
const MCInst * getInst() const
Definition: MCInst.h:106
#define HEXAGON_PRESHUFFLE_PACKET_SIZE
Definition: Hexagon.h:40
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...
Definition: MCInstrDesc.h:512
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.
Definition: MCInstrDesc.h:210
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.
Definition: SourceMgr.cpp:225
Represents a location in source code.
Definition: SMLoc.h:24
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
bool isPredicatedTrue(MCInstrInfo const &MCII, MCInst const &MCI)
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:173
MCOperand const & getNewValueOperand(MCInstrInfo const &MCII, MCInst const &MCI)