LLVM  5.0.0
HexagonMCChecker.h
Go to the documentation of this file.
1 //===----- HexagonMCChecker.h - 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 #ifndef HEXAGONMCCHECKER_H
16 #define HEXAGONMCCHECKER_H
17 
19 #include <queue>
20 #include <set>
21 
22 using namespace llvm;
23 
24 namespace llvm {
25 class MCOperandInfo;
26 
27 /// Check for a valid bundle.
29  MCContext &Context;
30  MCInst &MCB;
31  const MCRegisterInfo &RI;
32  MCInstrInfo const &MCII;
33  MCSubtargetInfo const &STI;
34  bool ReportErrors;
35 
36  /// Set of definitions: register #, if predicated, if predicated true.
37  typedef std::pair<unsigned, bool> PredSense;
38  static const PredSense Unconditional;
39  typedef std::multiset<PredSense> PredSet;
40  typedef std::multiset<PredSense>::iterator PredSetIterator;
41 
44 
45  /// Information about how a new-value register is defined or used:
46  /// PredReg = predicate register, 0 if use/def not predicated,
47  /// Cond = true/false for if(PredReg)/if(!PredReg) respectively,
48  /// IsFloat = true if definition produces a floating point value
49  /// (not valid for uses),
50  /// IsNVJ = true if the use is a new-value branch (not valid for
51  /// definitions).
52  struct NewSense {
53  unsigned PredReg;
54  bool IsFloat, IsNVJ, Cond;
55  // The special-case "constructors":
56  static NewSense Jmp(bool isNVJ) {
57  NewSense NS = {/*PredReg=*/0, /*IsFloat=*/false, /*IsNVJ=*/isNVJ,
58  /*Cond=*/false};
59  return NS;
60  }
61  static NewSense Use(unsigned PR, bool True) {
62  NewSense NS = {/*PredReg=*/PR, /*IsFloat=*/false, /*IsNVJ=*/false,
63  /*Cond=*/True};
64  return NS;
65  }
66  static NewSense Def(unsigned PR, bool True, bool Float) {
67  NewSense NS = {/*PredReg=*/PR, /*IsFloat=*/Float, /*IsNVJ=*/false,
68  /*Cond=*/True};
69  return NS;
70  }
71  };
72  /// Set of definitions that produce new register:
76 
77  /// Set of weak definitions whose clashes should be enforced selectively.
78  typedef std::set<unsigned>::iterator SoftDefsIterator;
79  std::set<unsigned> SoftDefs;
80 
81  /// Set of temporary definitions not committed to the register file.
82  typedef std::set<unsigned>::iterator TmpDefsIterator;
83  std::set<unsigned> TmpDefs;
84 
85  /// Set of new predicates used.
86  typedef std::set<unsigned>::iterator NewPredsIterator;
87  std::set<unsigned> NewPreds;
88 
89  /// Set of predicates defined late.
90  typedef std::multiset<unsigned>::iterator LatePredsIterator;
91  std::multiset<unsigned> LatePreds;
92 
93  /// Set of uses.
94  typedef std::set<unsigned>::iterator UsesIterator;
95  std::set<unsigned> Uses;
96 
97  /// Set of new values used: new register, if new-value jump.
100 
101  /// Pre-defined set of read-only registers.
102  typedef std::set<unsigned>::iterator ReadOnlyIterator;
103  std::set<unsigned> ReadOnly;
104 
105  void init();
106  void init(MCInst const &);
107  void initReg(MCInst const &, unsigned, unsigned &PredReg, bool &isTrue);
108 
109  bool registerUsed(unsigned Register);
110 
111  // Checks performed.
112  bool checkBranches();
113  bool checkPredicates();
114  bool checkNewValues();
115  bool checkRegisters();
116  bool checkRegistersReadOnly();
117  bool checkEndloopBranches();
118  void checkRegisterCurDefs();
119  bool checkSolo();
120  bool checkShuffle();
121  bool checkSlots();
122  bool checkAXOK();
123 
124  static void compoundRegisterMap(unsigned &);
125 
126  bool isPredicateRegister(unsigned R) const {
127  return (Hexagon::P0 == R || Hexagon::P1 == R || Hexagon::P2 == R ||
128  Hexagon::P3 == R);
129  };
130  bool isLoopRegister(unsigned R) const {
131  return (Hexagon::SA0 == R || Hexagon::LC0 == R || Hexagon::SA1 == R ||
132  Hexagon::LC1 == R);
133  };
134 
135  bool hasValidNewValueDef(const NewSense &Use, const NewSenseList &Defs) const;
136 
137 public:
138  explicit HexagonMCChecker(MCContext &Context, MCInstrInfo const &MCII,
139  MCSubtargetInfo const &STI, MCInst &mcb,
140  const MCRegisterInfo &ri, bool ReportErrors = true);
141 
142  bool check(bool FullCheck = true);
143  void reportErrorRegisters(unsigned Register);
144  void reportErrorNewValue(unsigned Register);
145  void reportError(SMLoc Loc, llvm::Twine const &Msg);
146  void reportError(llvm::Twine const &Msg);
147  void reportWarning(llvm::Twine const &Msg);
148 };
149 
150 } // namespace llvm
151 
152 #endif // HEXAGONMCCHECKER_H
void reportErrorNewValue(unsigned Register)
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
void reportWarning(llvm::Twine const &Msg)
Context object for machine code objects.
Definition: MCContext.h:59
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
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
void reportErrorRegisters(unsigned Register)
MCSubtargetInfo - Generic base class for all target subtargets.
bool check(bool FullCheck=true)
Check for a valid bundle.
void reportError(SMLoc Loc, llvm::Twine const &Msg)
Represents a location in source code.
Definition: SMLoc.h:24
This holds information about one operand of a machine instruction, indicating the register class for ...
Definition: MCInstrDesc.h:70