Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 1 | //===- GlobalISelEmitter.cpp - Generate an instruction selector -----------===// |
| 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 | /// \file |
| 11 | /// This tablegen backend emits code for use by the GlobalISel instruction |
| 12 | /// selector. See include/llvm/CodeGen/TargetGlobalISel.td. |
| 13 | /// |
| 14 | /// This file analyzes the patterns recognized by the SelectionDAGISel tablegen |
| 15 | /// backend, filters out the ones that are unsupported, maps |
| 16 | /// SelectionDAG-specific constructs to their GlobalISel counterpart |
| 17 | /// (when applicable: MVT to LLT; SDNode to generic Instruction). |
| 18 | /// |
| 19 | /// Not all patterns are supported: pass the tablegen invocation |
| 20 | /// "-warn-on-skipped-patterns" to emit a warning when a pattern is skipped, |
| 21 | /// as well as why. |
| 22 | /// |
| 23 | /// The generated file defines a single method: |
| 24 | /// bool <Target>InstructionSelector::selectImpl(MachineInstr &I) const; |
| 25 | /// intended to be used in InstructionSelector::select as the first-step |
| 26 | /// selector for the patterns that don't require complex C++. |
| 27 | /// |
| 28 | /// FIXME: We'll probably want to eventually define a base |
| 29 | /// "TargetGenInstructionSelector" class. |
| 30 | /// |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | |
| 33 | #include "CodeGenDAGPatterns.h" |
| 34 | #include "llvm/ADT/Optional.h" |
| 35 | #include "llvm/ADT/Statistic.h" |
| 36 | #include "llvm/CodeGen/MachineValueType.h" |
| 37 | #include "llvm/Support/CommandLine.h" |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Error.h" |
Daniel Sanders | 52b4ce7 | 2017-03-07 23:20:35 +0000 | [diff] [blame^] | 39 | #include "llvm/Support/LowLevelTypeImpl.h" |
Pavel Labath | 52a82e2 | 2017-02-21 09:19:41 +0000 | [diff] [blame] | 40 | #include "llvm/Support/ScopedPrinter.h" |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 41 | #include "llvm/TableGen/Error.h" |
| 42 | #include "llvm/TableGen/Record.h" |
| 43 | #include "llvm/TableGen/TableGenBackend.h" |
| 44 | #include <string> |
| 45 | using namespace llvm; |
| 46 | |
| 47 | #define DEBUG_TYPE "gisel-emitter" |
| 48 | |
| 49 | STATISTIC(NumPatternTotal, "Total number of patterns"); |
Daniel Sanders | b41ce2b | 2017-02-20 14:31:27 +0000 | [diff] [blame] | 50 | STATISTIC(NumPatternImported, "Number of patterns imported from SelectionDAG"); |
| 51 | STATISTIC(NumPatternImportsSkipped, "Number of SelectionDAG imports skipped"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 52 | STATISTIC(NumPatternEmitted, "Number of patterns emitted"); |
| 53 | |
| 54 | static cl::opt<bool> WarnOnSkippedPatterns( |
| 55 | "warn-on-skipped-patterns", |
| 56 | cl::desc("Explain why a pattern was skipped for inclusion " |
| 57 | "in the GlobalISel selector"), |
| 58 | cl::init(false)); |
| 59 | |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 60 | //===- Helper functions ---------------------------------------------------===// |
| 61 | |
Daniel Sanders | 52b4ce7 | 2017-03-07 23:20:35 +0000 | [diff] [blame^] | 62 | /// This class stands in for LLT wherever we want to tablegen-erate an |
| 63 | /// equivalent at compiler run-time. |
| 64 | class LLTCodeGen { |
| 65 | private: |
| 66 | LLT Ty; |
| 67 | |
| 68 | public: |
| 69 | LLTCodeGen(const LLT &Ty) : Ty(Ty) {} |
| 70 | |
| 71 | void emitCxxConstructorCall(raw_ostream &OS) const { |
| 72 | if (Ty.isScalar()) { |
| 73 | OS << "LLT::scalar(" << Ty.getSizeInBits() << ")"; |
| 74 | return; |
| 75 | } |
| 76 | if (Ty.isVector()) { |
| 77 | OS << "LLT::vector(" << Ty.getNumElements() << ", " << Ty.getSizeInBits() |
| 78 | << ")"; |
| 79 | return; |
| 80 | } |
| 81 | llvm_unreachable("Unhandled LLT"); |
| 82 | } |
| 83 | }; |
| 84 | |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 85 | /// Convert an MVT to an equivalent LLT if possible, or the invalid LLT() for |
| 86 | /// MVTs that don't map cleanly to an LLT (e.g., iPTR, *any, ...). |
Daniel Sanders | 52b4ce7 | 2017-03-07 23:20:35 +0000 | [diff] [blame^] | 87 | static Optional<LLTCodeGen> MVTToLLT(MVT::SimpleValueType SVT) { |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 88 | MVT VT(SVT); |
Daniel Sanders | 52b4ce7 | 2017-03-07 23:20:35 +0000 | [diff] [blame^] | 89 | if (VT.isVector() && VT.getVectorNumElements() != 1) |
| 90 | return LLTCodeGen(LLT::vector(VT.getVectorNumElements(), VT.getScalarSizeInBits())); |
| 91 | if (VT.isInteger() || VT.isFloatingPoint()) |
| 92 | return LLTCodeGen(LLT::scalar(VT.getSizeInBits())); |
| 93 | return None; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static bool isTrivialOperatorNode(const TreePatternNode *N) { |
| 97 | return !N->isLeaf() && !N->hasAnyPredicate() && !N->getTransformFn(); |
| 98 | } |
| 99 | |
| 100 | //===- Matchers -----------------------------------------------------------===// |
| 101 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 102 | template <class PredicateTy> class PredicateListMatcher { |
| 103 | private: |
| 104 | typedef std::vector<std::unique_ptr<PredicateTy>> PredicateVec; |
| 105 | PredicateVec Predicates; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 106 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 107 | public: |
| 108 | /// Construct a new operand predicate and add it to the matcher. |
| 109 | template <class Kind, class... Args> |
| 110 | Kind &addPredicate(Args&&... args) { |
Ahmed Bougacha | b67a3ce | 2017-01-26 22:07:37 +0000 | [diff] [blame] | 111 | Predicates.emplace_back( |
| 112 | llvm::make_unique<Kind>(std::forward<Args>(args)...)); |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 113 | return *static_cast<Kind *>(Predicates.back().get()); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 114 | } |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 115 | |
| 116 | typename PredicateVec::const_iterator predicates_begin() const { return Predicates.begin(); } |
| 117 | typename PredicateVec::const_iterator predicates_end() const { return Predicates.end(); } |
| 118 | iterator_range<typename PredicateVec::const_iterator> predicates() const { |
| 119 | return make_range(predicates_begin(), predicates_end()); |
| 120 | } |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 121 | typename PredicateVec::size_type predicates_size() const { return Predicates.size(); } |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 122 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 123 | /// Emit a C++ expression that tests whether all the predicates are met. |
Ahmed Bougacha | b67a3ce | 2017-01-26 22:07:37 +0000 | [diff] [blame] | 124 | template <class... Args> |
Daniel Sanders | f8c804f | 2017-01-28 11:10:42 +0000 | [diff] [blame] | 125 | void emitCxxPredicateListExpr(raw_ostream &OS, Args &&... args) const { |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 126 | if (Predicates.empty()) { |
| 127 | OS << "true"; |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | StringRef Separator = ""; |
| 132 | for (const auto &Predicate : predicates()) { |
| 133 | OS << Separator << "("; |
Ahmed Bougacha | b67a3ce | 2017-01-26 22:07:37 +0000 | [diff] [blame] | 134 | Predicate->emitCxxPredicateExpr(OS, std::forward<Args>(args)...); |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 135 | OS << ")"; |
Ahmed Bougacha | 905af9f | 2017-02-04 00:47:02 +0000 | [diff] [blame] | 136 | Separator = " &&\n"; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 137 | } |
| 138 | } |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 141 | /// Generates code to check a predicate of an operand. |
| 142 | /// |
| 143 | /// Typical predicates include: |
| 144 | /// * Operand is a particular register. |
| 145 | /// * Operand is assigned a particular register bank. |
| 146 | /// * Operand is an MBB. |
| 147 | class OperandPredicateMatcher { |
| 148 | public: |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 149 | /// This enum is used for RTTI and also defines the priority that is given to |
| 150 | /// the predicate when generating the matcher code. Kinds with higher priority |
| 151 | /// must be tested first. |
| 152 | /// |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 153 | /// The relative priority of OPM_LLT, OPM_RegBank, and OPM_MBB do not matter |
| 154 | /// but OPM_Int must have priority over OPM_RegBank since constant integers |
| 155 | /// are represented by a virtual register defined by a G_CONSTANT instruction. |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 156 | enum PredicateKind { |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 157 | OPM_Int, |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 158 | OPM_LLT, |
| 159 | OPM_RegBank, |
| 160 | OPM_MBB, |
| 161 | }; |
| 162 | |
| 163 | protected: |
| 164 | PredicateKind Kind; |
| 165 | |
| 166 | public: |
| 167 | OperandPredicateMatcher(PredicateKind Kind) : Kind(Kind) {} |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 168 | virtual ~OperandPredicateMatcher() {} |
| 169 | |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 170 | PredicateKind getKind() const { return Kind; } |
| 171 | |
Daniel Sanders | e604ef5 | 2017-02-20 15:30:43 +0000 | [diff] [blame] | 172 | /// Emit a C++ expression that checks the predicate for the given operand. |
| 173 | virtual void emitCxxPredicateExpr(raw_ostream &OS, |
| 174 | StringRef OperandExpr) const = 0; |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 175 | |
| 176 | /// Compare the priority of this object and B. |
| 177 | /// |
| 178 | /// Returns true if this object is more important than B. |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 179 | virtual bool isHigherPriorityThan(const OperandPredicateMatcher &B) const { |
| 180 | return Kind < B.Kind; |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 181 | }; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | /// Generates code to check that an operand is a particular LLT. |
| 185 | class LLTOperandMatcher : public OperandPredicateMatcher { |
| 186 | protected: |
Daniel Sanders | 52b4ce7 | 2017-03-07 23:20:35 +0000 | [diff] [blame^] | 187 | LLTCodeGen Ty; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 188 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 189 | public: |
Daniel Sanders | 52b4ce7 | 2017-03-07 23:20:35 +0000 | [diff] [blame^] | 190 | LLTOperandMatcher(const LLTCodeGen &Ty) |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 191 | : OperandPredicateMatcher(OPM_LLT), Ty(Ty) {} |
| 192 | |
| 193 | static bool classof(const OperandPredicateMatcher *P) { |
| 194 | return P->getKind() == OPM_LLT; |
| 195 | } |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 196 | |
Daniel Sanders | e604ef5 | 2017-02-20 15:30:43 +0000 | [diff] [blame] | 197 | void emitCxxPredicateExpr(raw_ostream &OS, |
| 198 | StringRef OperandExpr) const override { |
Daniel Sanders | 52b4ce7 | 2017-03-07 23:20:35 +0000 | [diff] [blame^] | 199 | OS << "MRI.getType(" << OperandExpr << ".getReg()) == ("; |
| 200 | Ty.emitCxxConstructorCall(OS); |
| 201 | OS << ")"; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 202 | } |
| 203 | }; |
| 204 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 205 | /// Generates code to check that an operand is in a particular register bank. |
| 206 | class RegisterBankOperandMatcher : public OperandPredicateMatcher { |
| 207 | protected: |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 208 | const CodeGenRegisterClass &RC; |
| 209 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 210 | public: |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 211 | RegisterBankOperandMatcher(const CodeGenRegisterClass &RC) |
| 212 | : OperandPredicateMatcher(OPM_RegBank), RC(RC) {} |
| 213 | |
| 214 | static bool classof(const OperandPredicateMatcher *P) { |
| 215 | return P->getKind() == OPM_RegBank; |
| 216 | } |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 217 | |
Daniel Sanders | e604ef5 | 2017-02-20 15:30:43 +0000 | [diff] [blame] | 218 | void emitCxxPredicateExpr(raw_ostream &OS, |
| 219 | StringRef OperandExpr) const override { |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 220 | OS << "(&RBI.getRegBankFromRegClass(" << RC.getQualifiedName() |
Daniel Sanders | e604ef5 | 2017-02-20 15:30:43 +0000 | [diff] [blame] | 221 | << "RegClass) == RBI.getRegBank(" << OperandExpr |
| 222 | << ".getReg(), MRI, TRI))"; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 223 | } |
| 224 | }; |
| 225 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 226 | /// Generates code to check that an operand is a basic block. |
| 227 | class MBBOperandMatcher : public OperandPredicateMatcher { |
| 228 | public: |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 229 | MBBOperandMatcher() : OperandPredicateMatcher(OPM_MBB) {} |
| 230 | |
| 231 | static bool classof(const OperandPredicateMatcher *P) { |
| 232 | return P->getKind() == OPM_MBB; |
| 233 | } |
| 234 | |
Daniel Sanders | e604ef5 | 2017-02-20 15:30:43 +0000 | [diff] [blame] | 235 | void emitCxxPredicateExpr(raw_ostream &OS, |
| 236 | StringRef OperandExpr) const override { |
| 237 | OS << OperandExpr << ".isMBB()"; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 238 | } |
| 239 | }; |
| 240 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 241 | /// Generates code to check that an operand is a particular int. |
| 242 | class IntOperandMatcher : public OperandPredicateMatcher { |
| 243 | protected: |
| 244 | int64_t Value; |
| 245 | |
| 246 | public: |
| 247 | IntOperandMatcher(int64_t Value) |
| 248 | : OperandPredicateMatcher(OPM_Int), Value(Value) {} |
| 249 | |
| 250 | static bool classof(const OperandPredicateMatcher *P) { |
| 251 | return P->getKind() == OPM_Int; |
| 252 | } |
| 253 | |
| 254 | void emitCxxPredicateExpr(raw_ostream &OS, |
Simon Pilgrim | d030291 | 2017-02-24 17:20:27 +0000 | [diff] [blame] | 255 | StringRef OperandExpr) const override { |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 256 | OS << "isOperandImmEqual(" << OperandExpr << ", " << Value << ", MRI)"; |
| 257 | } |
| 258 | }; |
| 259 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 260 | /// Generates code to check that a set of predicates match for a particular |
| 261 | /// operand. |
| 262 | class OperandMatcher : public PredicateListMatcher<OperandPredicateMatcher> { |
| 263 | protected: |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 264 | unsigned OpIdx; |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 265 | std::string SymbolicName; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 266 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 267 | public: |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 268 | OperandMatcher(unsigned OpIdx, const std::string &SymbolicName) |
| 269 | : OpIdx(OpIdx), SymbolicName(SymbolicName) {} |
| 270 | |
| 271 | bool hasSymbolicName() const { return !SymbolicName.empty(); } |
| 272 | const StringRef getSymbolicName() const { return SymbolicName; } |
| 273 | unsigned getOperandIndex() const { return OpIdx; } |
| 274 | |
| 275 | std::string getOperandExpr(const StringRef InsnVarName) const { |
Pavel Labath | 52a82e2 | 2017-02-21 09:19:41 +0000 | [diff] [blame] | 276 | return (InsnVarName + ".getOperand(" + llvm::to_string(OpIdx) + ")").str(); |
Daniel Sanders | e604ef5 | 2017-02-20 15:30:43 +0000 | [diff] [blame] | 277 | } |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 278 | |
| 279 | /// Emit a C++ expression that tests whether the instruction named in |
| 280 | /// InsnVarName matches all the predicate and all the operands. |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 281 | void emitCxxPredicateExpr(raw_ostream &OS, const StringRef InsnVarName) const { |
| 282 | OS << "(/* "; |
| 283 | if (SymbolicName.empty()) |
| 284 | OS << "Operand " << OpIdx; |
| 285 | else |
| 286 | OS << SymbolicName; |
| 287 | OS << " */ "; |
Daniel Sanders | e604ef5 | 2017-02-20 15:30:43 +0000 | [diff] [blame] | 288 | emitCxxPredicateListExpr(OS, getOperandExpr(InsnVarName)); |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 289 | OS << ")"; |
| 290 | } |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 291 | |
| 292 | /// Compare the priority of this object and B. |
| 293 | /// |
| 294 | /// Returns true if this object is more important than B. |
| 295 | bool isHigherPriorityThan(const OperandMatcher &B) const { |
| 296 | // Operand matchers involving more predicates have higher priority. |
| 297 | if (predicates_size() > B.predicates_size()) |
| 298 | return true; |
| 299 | if (predicates_size() < B.predicates_size()) |
| 300 | return false; |
| 301 | |
| 302 | // This assumes that predicates are added in a consistent order. |
| 303 | for (const auto &Predicate : zip(predicates(), B.predicates())) { |
| 304 | if (std::get<0>(Predicate)->isHigherPriorityThan(*std::get<1>(Predicate))) |
| 305 | return true; |
| 306 | if (std::get<1>(Predicate)->isHigherPriorityThan(*std::get<0>(Predicate))) |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | return false; |
| 311 | }; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | /// Generates code to check a predicate on an instruction. |
| 315 | /// |
| 316 | /// Typical predicates include: |
| 317 | /// * The opcode of the instruction is a particular value. |
| 318 | /// * The nsw/nuw flag is/isn't set. |
| 319 | class InstructionPredicateMatcher { |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 320 | protected: |
| 321 | /// This enum is used for RTTI and also defines the priority that is given to |
| 322 | /// the predicate when generating the matcher code. Kinds with higher priority |
| 323 | /// must be tested first. |
| 324 | enum PredicateKind { |
| 325 | IPM_Opcode, |
| 326 | }; |
| 327 | |
| 328 | PredicateKind Kind; |
| 329 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 330 | public: |
Daniel Sanders | 8d4d72f | 2017-02-24 14:53:35 +0000 | [diff] [blame] | 331 | InstructionPredicateMatcher(PredicateKind Kind) : Kind(Kind) {} |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 332 | virtual ~InstructionPredicateMatcher() {} |
| 333 | |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 334 | PredicateKind getKind() const { return Kind; } |
| 335 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 336 | /// Emit a C++ expression that tests whether the instruction named in |
| 337 | /// InsnVarName matches the predicate. |
| 338 | virtual void emitCxxPredicateExpr(raw_ostream &OS, |
Ahmed Bougacha | 6a1ac5a | 2017-02-09 02:50:01 +0000 | [diff] [blame] | 339 | StringRef InsnVarName) const = 0; |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 340 | |
| 341 | /// Compare the priority of this object and B. |
| 342 | /// |
| 343 | /// Returns true if this object is more important than B. |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 344 | virtual bool isHigherPriorityThan(const InstructionPredicateMatcher &B) const { |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 345 | return Kind < B.Kind; |
| 346 | }; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | /// Generates code to check the opcode of an instruction. |
| 350 | class InstructionOpcodeMatcher : public InstructionPredicateMatcher { |
| 351 | protected: |
| 352 | const CodeGenInstruction *I; |
| 353 | |
| 354 | public: |
Daniel Sanders | 8d4d72f | 2017-02-24 14:53:35 +0000 | [diff] [blame] | 355 | InstructionOpcodeMatcher(const CodeGenInstruction *I) |
| 356 | : InstructionPredicateMatcher(IPM_Opcode), I(I) {} |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 357 | |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 358 | static bool classof(const InstructionPredicateMatcher *P) { |
| 359 | return P->getKind() == IPM_Opcode; |
| 360 | } |
| 361 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 362 | void emitCxxPredicateExpr(raw_ostream &OS, |
Ahmed Bougacha | 6a1ac5a | 2017-02-09 02:50:01 +0000 | [diff] [blame] | 363 | StringRef InsnVarName) const override { |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 364 | OS << InsnVarName << ".getOpcode() == " << I->Namespace |
| 365 | << "::" << I->TheDef->getName(); |
| 366 | } |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 367 | |
| 368 | /// Compare the priority of this object and B. |
| 369 | /// |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 370 | /// Returns true if this object is more important than B. |
| 371 | bool isHigherPriorityThan(const InstructionPredicateMatcher &B) const override { |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 372 | if (InstructionPredicateMatcher::isHigherPriorityThan(B)) |
| 373 | return true; |
| 374 | if (B.InstructionPredicateMatcher::isHigherPriorityThan(*this)) |
| 375 | return false; |
| 376 | |
| 377 | // Prioritize opcodes for cosmetic reasons in the generated source. Although |
| 378 | // this is cosmetic at the moment, we may want to drive a similar ordering |
| 379 | // using instruction frequency information to improve compile time. |
| 380 | if (const InstructionOpcodeMatcher *BO = |
| 381 | dyn_cast<InstructionOpcodeMatcher>(&B)) |
| 382 | return I->TheDef->getName() < BO->I->TheDef->getName(); |
| 383 | |
| 384 | return false; |
| 385 | }; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | /// Generates code to check that a set of predicates and operands match for a |
| 389 | /// particular instruction. |
| 390 | /// |
| 391 | /// Typical predicates include: |
| 392 | /// * Has a specific opcode. |
| 393 | /// * Has an nsw/nuw flag or doesn't. |
| 394 | class InstructionMatcher |
| 395 | : public PredicateListMatcher<InstructionPredicateMatcher> { |
| 396 | protected: |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 397 | typedef std::vector<OperandMatcher> OperandVec; |
| 398 | |
| 399 | /// The operands to match. All rendered operands must be present even if the |
| 400 | /// condition is always true. |
| 401 | OperandVec Operands; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 402 | |
| 403 | public: |
| 404 | /// Add an operand to the matcher. |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 405 | OperandMatcher &addOperand(unsigned OpIdx, const std::string &SymbolicName) { |
| 406 | Operands.emplace_back(OpIdx, SymbolicName); |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 407 | return Operands.back(); |
| 408 | } |
| 409 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 410 | const OperandMatcher &getOperand(const StringRef SymbolicName) const { |
| 411 | assert(!SymbolicName.empty() && "Cannot lookup unnamed operand"); |
| 412 | const auto &I = std::find_if(Operands.begin(), Operands.end(), |
| 413 | [&SymbolicName](const OperandMatcher &X) { |
| 414 | return X.getSymbolicName() == SymbolicName; |
| 415 | }); |
| 416 | if (I != Operands.end()) |
| 417 | return *I; |
| 418 | llvm_unreachable("Failed to lookup operand"); |
| 419 | } |
| 420 | |
| 421 | unsigned getNumOperands() const { return Operands.size(); } |
| 422 | OperandVec::const_iterator operands_begin() const { |
| 423 | return Operands.begin(); |
| 424 | } |
| 425 | OperandVec::const_iterator operands_end() const { |
| 426 | return Operands.end(); |
| 427 | } |
| 428 | iterator_range<OperandVec::const_iterator> operands() const { |
| 429 | return make_range(operands_begin(), operands_end()); |
| 430 | } |
| 431 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 432 | /// Emit a C++ expression that tests whether the instruction named in |
| 433 | /// InsnVarName matches all the predicates and all the operands. |
Ahmed Bougacha | 6a1ac5a | 2017-02-09 02:50:01 +0000 | [diff] [blame] | 434 | void emitCxxPredicateExpr(raw_ostream &OS, StringRef InsnVarName) const { |
Daniel Sanders | f8c804f | 2017-01-28 11:10:42 +0000 | [diff] [blame] | 435 | emitCxxPredicateListExpr(OS, InsnVarName); |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 436 | for (const auto &Operand : Operands) { |
Ahmed Bougacha | 905af9f | 2017-02-04 00:47:02 +0000 | [diff] [blame] | 437 | OS << " &&\n("; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 438 | Operand.emitCxxPredicateExpr(OS, InsnVarName); |
| 439 | OS << ")"; |
| 440 | } |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 441 | } |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 442 | |
| 443 | /// Compare the priority of this object and B. |
| 444 | /// |
| 445 | /// Returns true if this object is more important than B. |
| 446 | bool isHigherPriorityThan(const InstructionMatcher &B) const { |
| 447 | // Instruction matchers involving more operands have higher priority. |
| 448 | if (Operands.size() > B.Operands.size()) |
| 449 | return true; |
| 450 | if (Operands.size() < B.Operands.size()) |
| 451 | return false; |
| 452 | |
| 453 | for (const auto &Predicate : zip(predicates(), B.predicates())) { |
| 454 | if (std::get<0>(Predicate)->isHigherPriorityThan(*std::get<1>(Predicate))) |
| 455 | return true; |
| 456 | if (std::get<1>(Predicate)->isHigherPriorityThan(*std::get<0>(Predicate))) |
| 457 | return false; |
| 458 | } |
| 459 | |
| 460 | for (const auto &Operand : zip(Operands, B.Operands)) { |
| 461 | if (std::get<0>(Operand).isHigherPriorityThan(std::get<1>(Operand))) |
| 462 | return true; |
| 463 | if (std::get<1>(Operand).isHigherPriorityThan(std::get<0>(Operand))) |
| 464 | return false; |
| 465 | } |
| 466 | |
| 467 | return false; |
| 468 | }; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 469 | }; |
| 470 | |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 471 | //===- Actions ------------------------------------------------------------===// |
| 472 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 473 | namespace { |
| 474 | class OperandRenderer { |
| 475 | public: |
| 476 | enum RendererKind { OR_Copy, OR_Register }; |
| 477 | |
| 478 | protected: |
| 479 | RendererKind Kind; |
| 480 | |
| 481 | public: |
| 482 | OperandRenderer(RendererKind Kind) : Kind(Kind) {} |
| 483 | virtual ~OperandRenderer() {} |
| 484 | |
| 485 | RendererKind getKind() const { return Kind; } |
| 486 | |
| 487 | virtual void emitCxxRenderStmts(raw_ostream &OS) const = 0; |
| 488 | }; |
| 489 | |
| 490 | /// A CopyRenderer emits code to copy a single operand from an existing |
| 491 | /// instruction to the one being built. |
| 492 | class CopyRenderer : public OperandRenderer { |
| 493 | protected: |
| 494 | /// The matcher for the instruction that this operand is copied from. |
| 495 | /// This provides the facility for looking up an a operand by it's name so |
| 496 | /// that it can be used as a source for the instruction being built. |
| 497 | const InstructionMatcher &Matched; |
| 498 | /// The name of the instruction to copy from. |
| 499 | const StringRef InsnVarName; |
| 500 | /// The name of the operand. |
| 501 | const StringRef SymbolicName; |
| 502 | |
| 503 | public: |
| 504 | CopyRenderer(const InstructionMatcher &Matched, const StringRef InsnVarName, |
| 505 | const StringRef SymbolicName) |
| 506 | : OperandRenderer(OR_Copy), Matched(Matched), InsnVarName(InsnVarName), |
| 507 | SymbolicName(SymbolicName) {} |
| 508 | |
| 509 | static bool classof(const OperandRenderer *R) { |
| 510 | return R->getKind() == OR_Copy; |
| 511 | } |
| 512 | |
| 513 | const StringRef getSymbolicName() const { return SymbolicName; } |
| 514 | |
| 515 | void emitCxxRenderStmts(raw_ostream &OS) const override { |
| 516 | std::string OperandExpr = |
| 517 | Matched.getOperand(SymbolicName).getOperandExpr(InsnVarName); |
| 518 | OS << " MIB.add(" << OperandExpr << "/*" << SymbolicName << "*/);\n"; |
| 519 | } |
| 520 | }; |
| 521 | |
| 522 | /// Adds a specific physical register to the instruction being built. |
| 523 | /// This is typically useful for WZR/XZR on AArch64. |
| 524 | class AddRegisterRenderer : public OperandRenderer { |
| 525 | protected: |
| 526 | const Record *RegisterDef; |
| 527 | |
| 528 | public: |
| 529 | AddRegisterRenderer(const Record *RegisterDef) |
| 530 | : OperandRenderer(OR_Register), RegisterDef(RegisterDef) {} |
| 531 | |
| 532 | static bool classof(const OperandRenderer *R) { |
| 533 | return R->getKind() == OR_Register; |
| 534 | } |
| 535 | |
| 536 | void emitCxxRenderStmts(raw_ostream &OS) const override { |
| 537 | OS << " MIB.addReg(" << RegisterDef->getValueAsString("Namespace") |
| 538 | << "::" << RegisterDef->getName() << ");\n"; |
| 539 | } |
| 540 | }; |
| 541 | |
Ahmed Bougacha | 56ca3a9 | 2017-02-04 00:47:10 +0000 | [diff] [blame] | 542 | /// An action taken when all Matcher predicates succeeded for a parent rule. |
| 543 | /// |
| 544 | /// Typical actions include: |
| 545 | /// * Changing the opcode of an instruction. |
| 546 | /// * Adding an operand to an instruction. |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 547 | class MatchAction { |
| 548 | public: |
| 549 | virtual ~MatchAction() {} |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 550 | |
| 551 | /// Emit the C++ statements to implement the action. |
| 552 | /// |
| 553 | /// \param InsnVarName If given, it's an instruction to recycle. The |
| 554 | /// requirements on the instruction vary from action to |
| 555 | /// action. |
| 556 | virtual void emitCxxActionStmts(raw_ostream &OS, |
| 557 | const StringRef InsnVarName) const = 0; |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 558 | }; |
| 559 | |
Ahmed Bougacha | 9aa4c10 | 2017-02-04 00:47:08 +0000 | [diff] [blame] | 560 | /// Generates a comment describing the matched rule being acted upon. |
| 561 | class DebugCommentAction : public MatchAction { |
| 562 | private: |
| 563 | const PatternToMatch &P; |
| 564 | |
| 565 | public: |
| 566 | DebugCommentAction(const PatternToMatch &P) : P(P) {} |
| 567 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 568 | void emitCxxActionStmts(raw_ostream &OS, |
| 569 | const StringRef InsnVarName) const override { |
Ahmed Bougacha | 9aa4c10 | 2017-02-04 00:47:08 +0000 | [diff] [blame] | 570 | OS << "// " << *P.getSrcPattern() << " => " << *P.getDstPattern(); |
| 571 | } |
| 572 | }; |
| 573 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 574 | /// Generates code to build an instruction or mutate an existing instruction |
| 575 | /// into the desired instruction when this is possible. |
| 576 | class BuildMIAction : public MatchAction { |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 577 | private: |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 578 | const CodeGenInstruction *I; |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 579 | const InstructionMatcher &Matched; |
| 580 | std::vector<std::unique_ptr<OperandRenderer>> OperandRenderers; |
| 581 | |
| 582 | /// True if the instruction can be built solely by mutating the opcode. |
| 583 | bool canMutate() const { |
| 584 | for (const auto &Renderer : enumerate(OperandRenderers)) { |
| 585 | if (const auto *Copy = dyn_cast<CopyRenderer>(&*Renderer.Value)) { |
| 586 | if (Matched.getOperand(Copy->getSymbolicName()).getOperandIndex() != |
| 587 | Renderer.Index) |
| 588 | return false; |
| 589 | } else |
| 590 | return false; |
| 591 | } |
| 592 | |
| 593 | return true; |
| 594 | } |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 595 | |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 596 | public: |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 597 | BuildMIAction(const CodeGenInstruction *I, const InstructionMatcher &Matched) |
| 598 | : I(I), Matched(Matched) {} |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 599 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 600 | template <class Kind, class... Args> |
| 601 | Kind &addRenderer(Args&&... args) { |
| 602 | OperandRenderers.emplace_back( |
| 603 | llvm::make_unique<Kind>(std::forward<Args>(args)...)); |
| 604 | return *static_cast<Kind *>(OperandRenderers.back().get()); |
| 605 | } |
| 606 | |
| 607 | virtual void emitCxxActionStmts(raw_ostream &OS, |
| 608 | const StringRef InsnVarName) const { |
| 609 | if (canMutate()) { |
| 610 | OS << "I.setDesc(TII.get(" << I->Namespace << "::" << I->TheDef->getName() |
| 611 | << "));\n"; |
| 612 | OS << " MachineInstr &NewI = I;\n"; |
| 613 | return; |
| 614 | } |
| 615 | |
| 616 | // TODO: Simple permutation looks like it could be almost as common as |
| 617 | // mutation due to commutative operations. |
| 618 | |
| 619 | OS << "MachineInstrBuilder MIB = BuildMI(*I.getParent(), I, " |
| 620 | "I.getDebugLoc(), TII.get(" |
| 621 | << I->Namespace << "::" << I->TheDef->getName() << "));\n"; |
| 622 | for (const auto &Renderer : OperandRenderers) |
| 623 | Renderer->emitCxxRenderStmts(OS); |
| 624 | OS << " MIB.setMemRefs(I.memoperands_begin(), I.memoperands_end());\n"; |
| 625 | OS << " " << InsnVarName << ".eraseFromParent();\n"; |
| 626 | OS << " MachineInstr &NewI = *MIB;\n"; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 627 | } |
| 628 | }; |
| 629 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 630 | /// Generates code to check that a match rule matches. |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 631 | class RuleMatcher { |
Ahmed Bougacha | 56ca3a9 | 2017-02-04 00:47:10 +0000 | [diff] [blame] | 632 | /// A list of matchers that all need to succeed for the current rule to match. |
| 633 | /// FIXME: This currently supports a single match position but could be |
| 634 | /// extended to support multiple positions to support div/rem fusion or |
| 635 | /// load-multiple instructions. |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 636 | std::vector<std::unique_ptr<InstructionMatcher>> Matchers; |
Ahmed Bougacha | 56ca3a9 | 2017-02-04 00:47:10 +0000 | [diff] [blame] | 637 | |
| 638 | /// A list of actions that need to be taken when all predicates in this rule |
| 639 | /// have succeeded. |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 640 | std::vector<std::unique_ptr<MatchAction>> Actions; |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 641 | |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 642 | public: |
Ahmed Bougacha | 9aa4c10 | 2017-02-04 00:47:08 +0000 | [diff] [blame] | 643 | RuleMatcher() {} |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 644 | |
| 645 | InstructionMatcher &addInstructionMatcher() { |
| 646 | Matchers.emplace_back(new InstructionMatcher()); |
| 647 | return *Matchers.back(); |
| 648 | } |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 649 | |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 650 | template <class Kind, class... Args> |
| 651 | Kind &addAction(Args&&... args) { |
| 652 | Actions.emplace_back(llvm::make_unique<Kind>(std::forward<Args>(args)...)); |
| 653 | return *static_cast<Kind *>(Actions.back().get()); |
| 654 | } |
| 655 | |
Daniel Sanders | b41ce2b | 2017-02-20 14:31:27 +0000 | [diff] [blame] | 656 | void emit(raw_ostream &OS) const { |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 657 | if (Matchers.empty()) |
| 658 | llvm_unreachable("Unexpected empty matcher!"); |
| 659 | |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 660 | // The representation supports rules that require multiple roots such as: |
| 661 | // %ptr(p0) = ... |
| 662 | // %elt0(s32) = G_LOAD %ptr |
| 663 | // %1(p0) = G_ADD %ptr, 4 |
| 664 | // %elt1(s32) = G_LOAD p0 %1 |
| 665 | // which could be usefully folded into: |
| 666 | // %ptr(p0) = ... |
| 667 | // %elt0(s32), %elt1(s32) = TGT_LOAD_PAIR %ptr |
| 668 | // on some targets but we don't need to make use of that yet. |
| 669 | assert(Matchers.size() == 1 && "Cannot handle multi-root matchers yet"); |
| 670 | OS << " if ("; |
| 671 | Matchers.front()->emitCxxPredicateExpr(OS, "I"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 672 | OS << ") {\n"; |
| 673 | |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 674 | for (const auto &MA : Actions) { |
| 675 | OS << " "; |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 676 | MA->emitCxxActionStmts(OS, "I"); |
Daniel Sanders | 43c882c | 2017-02-01 10:53:10 +0000 | [diff] [blame] | 677 | OS << "\n"; |
| 678 | } |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 679 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 680 | OS << " constrainSelectedInstRegOperands(NewI, TII, TRI, RBI);\n"; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 681 | OS << " return true;\n"; |
Ahmed Bougacha | 905af9f | 2017-02-04 00:47:02 +0000 | [diff] [blame] | 682 | OS << " }\n\n"; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 683 | } |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 684 | |
| 685 | /// Compare the priority of this object and B. |
| 686 | /// |
| 687 | /// Returns true if this object is more important than B. |
| 688 | bool isHigherPriorityThan(const RuleMatcher &B) const { |
| 689 | // Rules involving more match roots have higher priority. |
| 690 | if (Matchers.size() > B.Matchers.size()) |
| 691 | return true; |
| 692 | if (Matchers.size() < B.Matchers.size()) |
| 693 | return false; |
| 694 | |
| 695 | for (const auto &Matcher : zip(Matchers, B.Matchers)) { |
| 696 | if (std::get<0>(Matcher)->isHigherPriorityThan(*std::get<1>(Matcher))) |
| 697 | return true; |
| 698 | if (std::get<1>(Matcher)->isHigherPriorityThan(*std::get<0>(Matcher))) |
| 699 | return false; |
| 700 | } |
| 701 | |
| 702 | return false; |
| 703 | }; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 704 | }; |
| 705 | |
| 706 | //===- GlobalISelEmitter class --------------------------------------------===// |
| 707 | |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 708 | class GlobalISelEmitter { |
| 709 | public: |
| 710 | explicit GlobalISelEmitter(RecordKeeper &RK); |
| 711 | void run(raw_ostream &OS); |
| 712 | |
| 713 | private: |
| 714 | const RecordKeeper &RK; |
| 715 | const CodeGenDAGPatterns CGP; |
| 716 | const CodeGenTarget &Target; |
| 717 | |
| 718 | /// Keep track of the equivalence between SDNodes and Instruction. |
| 719 | /// This is defined using 'GINodeEquiv' in the target description. |
| 720 | DenseMap<Record *, const CodeGenInstruction *> NodeEquivs; |
| 721 | |
| 722 | void gatherNodeEquivs(); |
| 723 | const CodeGenInstruction *findNodeEquiv(Record *N); |
| 724 | |
| 725 | /// Analyze pattern \p P, returning a matcher for it if possible. |
| 726 | /// Otherwise, return an Error explaining why we don't support it. |
| 727 | Expected<RuleMatcher> runOnPattern(const PatternToMatch &P); |
| 728 | }; |
| 729 | |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 730 | void GlobalISelEmitter::gatherNodeEquivs() { |
| 731 | assert(NodeEquivs.empty()); |
| 732 | for (Record *Equiv : RK.getAllDerivedDefinitions("GINodeEquiv")) |
| 733 | NodeEquivs[Equiv->getValueAsDef("Node")] = |
| 734 | &Target.getInstruction(Equiv->getValueAsDef("I")); |
| 735 | } |
| 736 | |
| 737 | const CodeGenInstruction *GlobalISelEmitter::findNodeEquiv(Record *N) { |
| 738 | return NodeEquivs.lookup(N); |
| 739 | } |
| 740 | |
| 741 | GlobalISelEmitter::GlobalISelEmitter(RecordKeeper &RK) |
| 742 | : RK(RK), CGP(RK), Target(CGP.getTargetInfo()) {} |
| 743 | |
| 744 | //===- Emitter ------------------------------------------------------------===// |
| 745 | |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 746 | /// Helper function to let the emitter report skip reason error messages. |
| 747 | static Error failedImport(const Twine &Reason) { |
| 748 | return make_error<StringError>(Reason, inconvertibleErrorCode()); |
| 749 | } |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 750 | |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 751 | Expected<RuleMatcher> GlobalISelEmitter::runOnPattern(const PatternToMatch &P) { |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 752 | // Keep track of the matchers and actions to emit. |
Ahmed Bougacha | 9aa4c10 | 2017-02-04 00:47:08 +0000 | [diff] [blame] | 753 | RuleMatcher M; |
| 754 | M.addAction<DebugCommentAction>(P); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 755 | |
| 756 | // First, analyze the whole pattern. |
| 757 | // If the entire pattern has a predicate (e.g., target features), ignore it. |
| 758 | if (!P.getPredicates()->getValues().empty()) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 759 | return failedImport("Pattern has a predicate"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 760 | |
| 761 | // Physreg imp-defs require additional logic. Ignore the pattern. |
| 762 | if (!P.getDstRegs().empty()) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 763 | return failedImport("Pattern defines a physical register"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 764 | |
| 765 | // Next, analyze the pattern operators. |
| 766 | TreePatternNode *Src = P.getSrcPattern(); |
| 767 | TreePatternNode *Dst = P.getDstPattern(); |
| 768 | |
| 769 | // If the root of either pattern isn't a simple operator, ignore it. |
| 770 | if (!isTrivialOperatorNode(Dst)) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 771 | return failedImport("Dst pattern root isn't a trivial operator"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 772 | if (!isTrivialOperatorNode(Src)) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 773 | return failedImport("Src pattern root isn't a trivial operator"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 774 | |
| 775 | Record *DstOp = Dst->getOperator(); |
| 776 | if (!DstOp->isSubClassOf("Instruction")) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 777 | return failedImport("Pattern operator isn't an instruction"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 778 | |
| 779 | auto &DstI = Target.getInstruction(DstOp); |
| 780 | |
| 781 | auto SrcGIOrNull = findNodeEquiv(Src->getOperator()); |
| 782 | if (!SrcGIOrNull) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 783 | return failedImport("Pattern operator lacks an equivalent Instruction"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 784 | auto &SrcGI = *SrcGIOrNull; |
| 785 | |
| 786 | // The operators look good: match the opcode and mutate it to the new one. |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 787 | InstructionMatcher &InsnMatcher = M.addInstructionMatcher(); |
| 788 | InsnMatcher.addPredicate<InstructionOpcodeMatcher>(&SrcGI); |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 789 | auto &DstMIBuilder = M.addAction<BuildMIAction>(&DstI, InsnMatcher); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 790 | |
| 791 | // Next, analyze the children, only accepting patterns that don't require |
| 792 | // any change to operands. |
| 793 | if (Src->getNumChildren() != Dst->getNumChildren()) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 794 | return failedImport("Src/dst patterns have a different # of children"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 795 | |
| 796 | unsigned OpIdx = 0; |
| 797 | |
| 798 | // Start with the defined operands (i.e., the results of the root operator). |
| 799 | if (DstI.Operands.NumDefs != Src->getExtTypes().size()) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 800 | return failedImport("Src pattern results and dst MI defs are different"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 801 | |
| 802 | for (const EEVT::TypeSet &Ty : Src->getExtTypes()) { |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 803 | const auto &DstIOperand = DstI.Operands[OpIdx]; |
| 804 | Record *DstIOpRec = DstIOperand.Rec; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 805 | if (!DstIOpRec->isSubClassOf("RegisterClass")) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 806 | return failedImport("Dst MI def isn't a register class"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 807 | |
| 808 | auto OpTyOrNone = MVTToLLT(Ty.getConcrete()); |
| 809 | if (!OpTyOrNone) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 810 | return failedImport("Dst operand has an unsupported type"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 811 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 812 | OperandMatcher &OM = InsnMatcher.addOperand(OpIdx, DstIOperand.Name); |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 813 | OM.addPredicate<LLTOperandMatcher>(*OpTyOrNone); |
| 814 | OM.addPredicate<RegisterBankOperandMatcher>( |
| 815 | Target.getRegisterClass(DstIOpRec)); |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 816 | DstMIBuilder.addRenderer<CopyRenderer>(InsnMatcher, "I", DstIOperand.Name); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 817 | ++OpIdx; |
| 818 | } |
| 819 | |
| 820 | // Finally match the used operands (i.e., the children of the root operator). |
| 821 | for (unsigned i = 0, e = Src->getNumChildren(); i != e; ++i) { |
| 822 | auto *SrcChild = Src->getChild(i); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 823 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 824 | OperandMatcher &OM = InsnMatcher.addOperand(OpIdx++, SrcChild->getName()); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 825 | |
| 826 | // The only non-leaf child we accept is 'bb': it's an operator because |
| 827 | // BasicBlockSDNode isn't inline, but in MI it's just another operand. |
| 828 | if (!SrcChild->isLeaf()) { |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 829 | if (SrcChild->getOperator()->isSubClassOf("SDNode")) { |
| 830 | auto &ChildSDNI = CGP.getSDNodeInfo(SrcChild->getOperator()); |
| 831 | if (ChildSDNI.getSDClassName() == "BasicBlockSDNode") { |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 832 | OM.addPredicate<MBBOperandMatcher>(); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 833 | continue; |
| 834 | } |
| 835 | } |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 836 | return failedImport("Src pattern child isn't a leaf node or an MBB"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 837 | } |
| 838 | |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 839 | if (SrcChild->hasAnyPredicate()) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 840 | return failedImport("Src pattern child has predicate"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 841 | |
| 842 | ArrayRef<EEVT::TypeSet> ChildTypes = SrcChild->getExtTypes(); |
| 843 | if (ChildTypes.size() != 1) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 844 | return failedImport("Src pattern child has multiple results"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 845 | |
| 846 | auto OpTyOrNone = MVTToLLT(ChildTypes.front().getConcrete()); |
| 847 | if (!OpTyOrNone) |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 848 | return failedImport("Src operand has an unsupported type"); |
Daniel Sanders | dc662ff | 2017-01-26 11:10:14 +0000 | [diff] [blame] | 849 | OM.addPredicate<LLTOperandMatcher>(*OpTyOrNone); |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 850 | |
| 851 | if (auto *ChildInt = dyn_cast<IntInit>(SrcChild->getLeafValue())) { |
| 852 | OM.addPredicate<IntOperandMatcher>(ChildInt->getValue()); |
| 853 | continue; |
| 854 | } |
| 855 | |
| 856 | if (auto *ChildDefInit = dyn_cast<DefInit>(SrcChild->getLeafValue())) { |
| 857 | auto *ChildRec = ChildDefInit->getDef(); |
| 858 | |
| 859 | // Otherwise, we're looking for a bog-standard RegisterClass operand. |
| 860 | if (!ChildRec->isSubClassOf("RegisterClass")) |
| 861 | return failedImport("Src pattern child isn't a RegisterClass"); |
| 862 | |
| 863 | OM.addPredicate<RegisterBankOperandMatcher>( |
| 864 | Target.getRegisterClass(ChildRec)); |
| 865 | continue; |
| 866 | } |
| 867 | |
| 868 | return failedImport("Src pattern child is an unsupported kind"); |
| 869 | } |
| 870 | |
| 871 | // Finally render the used operands (i.e., the children of the root operator). |
| 872 | for (unsigned i = 0, e = Dst->getNumChildren(); i != e; ++i) { |
| 873 | auto *DstChild = Dst->getChild(i); |
| 874 | |
| 875 | // The only non-leaf child we accept is 'bb': it's an operator because |
| 876 | // BasicBlockSDNode isn't inline, but in MI it's just another operand. |
| 877 | if (!DstChild->isLeaf()) { |
| 878 | if (DstChild->getOperator()->isSubClassOf("SDNode")) { |
| 879 | auto &ChildSDNI = CGP.getSDNodeInfo(DstChild->getOperator()); |
| 880 | if (ChildSDNI.getSDClassName() == "BasicBlockSDNode") { |
| 881 | DstMIBuilder.addRenderer<CopyRenderer>(InsnMatcher, "I", |
| 882 | DstChild->getName()); |
| 883 | continue; |
| 884 | } |
| 885 | } |
| 886 | return failedImport("Dst pattern child isn't a leaf node or an MBB"); |
| 887 | } |
| 888 | |
| 889 | // Otherwise, we're looking for a bog-standard RegisterClass operand. |
| 890 | if (DstChild->hasAnyPredicate()) |
| 891 | return failedImport("Dst pattern child has predicate"); |
| 892 | |
| 893 | if (auto *ChildDefInit = dyn_cast<DefInit>(DstChild->getLeafValue())) { |
| 894 | auto *ChildRec = ChildDefInit->getDef(); |
| 895 | |
| 896 | ArrayRef<EEVT::TypeSet> ChildTypes = DstChild->getExtTypes(); |
| 897 | if (ChildTypes.size() != 1) |
| 898 | return failedImport("Dst pattern child has multiple results"); |
| 899 | |
| 900 | auto OpTyOrNone = MVTToLLT(ChildTypes.front().getConcrete()); |
| 901 | if (!OpTyOrNone) |
| 902 | return failedImport("Dst operand has an unsupported type"); |
| 903 | |
| 904 | if (ChildRec->isSubClassOf("Register")) { |
| 905 | DstMIBuilder.addRenderer<AddRegisterRenderer>(ChildRec); |
| 906 | continue; |
| 907 | } |
| 908 | |
| 909 | if (ChildRec->isSubClassOf("RegisterClass")) { |
| 910 | DstMIBuilder.addRenderer<CopyRenderer>(InsnMatcher, "I", |
| 911 | DstChild->getName()); |
| 912 | continue; |
| 913 | } |
| 914 | |
| 915 | return failedImport( |
| 916 | "Dst pattern child def is an unsupported tablegen class"); |
| 917 | } |
| 918 | |
| 919 | return failedImport("Src pattern child is an unsupported kind"); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 922 | // We're done with this pattern! It's eligible for GISel emission; return it. |
Daniel Sanders | b41ce2b | 2017-02-20 14:31:27 +0000 | [diff] [blame] | 923 | ++NumPatternImported; |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 924 | return std::move(M); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | void GlobalISelEmitter::run(raw_ostream &OS) { |
| 928 | // Track the GINodeEquiv definitions. |
| 929 | gatherNodeEquivs(); |
| 930 | |
| 931 | emitSourceFileHeader(("Global Instruction Selector for the " + |
| 932 | Target.getName() + " target").str(), OS); |
| 933 | OS << "bool " << Target.getName() |
| 934 | << "InstructionSelector::selectImpl" |
| 935 | "(MachineInstr &I) const {\n const MachineRegisterInfo &MRI = " |
Ahmed Bougacha | 905af9f | 2017-02-04 00:47:02 +0000 | [diff] [blame] | 936 | "I.getParent()->getParent()->getRegInfo();\n\n"; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 937 | |
Daniel Sanders | b41ce2b | 2017-02-20 14:31:27 +0000 | [diff] [blame] | 938 | std::vector<RuleMatcher> Rules; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 939 | // Look through the SelectionDAG patterns we found, possibly emitting some. |
| 940 | for (const PatternToMatch &Pat : CGP.ptms()) { |
| 941 | ++NumPatternTotal; |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 942 | auto MatcherOrErr = runOnPattern(Pat); |
| 943 | |
| 944 | // The pattern analysis can fail, indicating an unsupported pattern. |
| 945 | // Report that if we've been asked to do so. |
| 946 | if (auto Err = MatcherOrErr.takeError()) { |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 947 | if (WarnOnSkippedPatterns) { |
| 948 | PrintWarning(Pat.getSrcRecord()->getLoc(), |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 949 | "Skipped pattern: " + toString(std::move(Err))); |
| 950 | } else { |
| 951 | consumeError(std::move(Err)); |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 952 | } |
Daniel Sanders | b41ce2b | 2017-02-20 14:31:27 +0000 | [diff] [blame] | 953 | ++NumPatternImportsSkipped; |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 954 | continue; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 955 | } |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 956 | |
Daniel Sanders | b41ce2b | 2017-02-20 14:31:27 +0000 | [diff] [blame] | 957 | Rules.push_back(std::move(MatcherOrErr.get())); |
| 958 | } |
| 959 | |
Daniel Sanders | 066ebbf | 2017-02-24 15:43:30 +0000 | [diff] [blame] | 960 | std::stable_sort(Rules.begin(), Rules.end(), |
| 961 | [&](const RuleMatcher &A, const RuleMatcher &B) { |
Daniel Sanders | 759ff41 | 2017-02-24 13:58:11 +0000 | [diff] [blame] | 962 | if (A.isHigherPriorityThan(B)) { |
| 963 | assert(!B.isHigherPriorityThan(A) && "Cannot be more important " |
| 964 | "and less important at " |
| 965 | "the same time"); |
| 966 | return true; |
| 967 | } |
| 968 | return false; |
| 969 | }); |
| 970 | |
Daniel Sanders | b41ce2b | 2017-02-20 14:31:27 +0000 | [diff] [blame] | 971 | for (const auto &Rule : Rules) { |
| 972 | Rule.emit(OS); |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 973 | ++NumPatternEmitted; |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | OS << " return false;\n}\n"; |
| 977 | } |
| 978 | |
Ahmed Bougacha | 982c5eb | 2017-02-10 04:00:17 +0000 | [diff] [blame] | 979 | } // end anonymous namespace |
| 980 | |
Ahmed Bougacha | 36f7035 | 2016-12-21 23:26:20 +0000 | [diff] [blame] | 981 | //===----------------------------------------------------------------------===// |
| 982 | |
| 983 | namespace llvm { |
| 984 | void EmitGlobalISel(RecordKeeper &RK, raw_ostream &OS) { |
| 985 | GlobalISelEmitter(RK).run(OS); |
| 986 | } |
| 987 | } // End llvm namespace |