2
0

DAGISelMatcher.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. //===- DAGISelMatcher.h - Representation of DAG pattern matcher -*- C++ -*-===//
  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. #ifndef LLVM_UTILS_TABLEGEN_DAGISELMATCHER_H
  10. #define LLVM_UTILS_TABLEGEN_DAGISELMATCHER_H
  11. #include "llvm/ADT/ArrayRef.h"
  12. #include "llvm/ADT/SmallVector.h"
  13. #include "llvm/ADT/StringRef.h"
  14. #include "llvm/CodeGen/MachineValueType.h"
  15. #include "llvm/Support/Casting.h"
  16. namespace llvm {
  17. struct CodeGenRegister;
  18. class CodeGenDAGPatterns;
  19. class Matcher;
  20. class PatternToMatch;
  21. class raw_ostream;
  22. class ComplexPattern;
  23. class Record;
  24. class SDNodeInfo;
  25. class TreePredicateFn;
  26. class TreePattern;
  27. Matcher *ConvertPatternToMatcher(const PatternToMatch &Pattern,unsigned Variant,
  28. const CodeGenDAGPatterns &CGP);
  29. void OptimizeMatcher(std::unique_ptr<Matcher> &Matcher,
  30. const CodeGenDAGPatterns &CGP);
  31. void EmitMatcherTable(const Matcher *Matcher, const CodeGenDAGPatterns &CGP,
  32. raw_ostream &OS);
  33. /// Matcher - Base class for all the DAG ISel Matcher representation
  34. /// nodes.
  35. class Matcher {
  36. // The next matcher node that is executed after this one. Null if this is the
  37. // last stage of a match.
  38. std::unique_ptr<Matcher> Next;
  39. virtual void anchor();
  40. public:
  41. enum KindTy {
  42. // Matcher state manipulation.
  43. Scope, // Push a checking scope.
  44. RecordNode, // Record the current node.
  45. RecordChild, // Record a child of the current node.
  46. RecordMemRef, // Record the memref in the current node.
  47. CaptureGlueInput, // If the current node has an input glue, save it.
  48. MoveChild, // Move current node to specified child.
  49. MoveParent, // Move current node to parent.
  50. // Predicate checking.
  51. CheckSame, // Fail if not same as prev match.
  52. CheckChildSame, // Fail if child not same as prev match.
  53. CheckPatternPredicate,
  54. CheckPredicate, // Fail if node predicate fails.
  55. CheckOpcode, // Fail if not opcode.
  56. SwitchOpcode, // Dispatch based on opcode.
  57. CheckType, // Fail if not correct type.
  58. SwitchType, // Dispatch based on type.
  59. CheckChildType, // Fail if child has wrong type.
  60. CheckInteger, // Fail if wrong val.
  61. CheckChildInteger, // Fail if child is wrong val.
  62. CheckCondCode, // Fail if not condcode.
  63. CheckValueType,
  64. CheckComplexPat,
  65. CheckAndImm,
  66. CheckOrImm,
  67. CheckFoldableChainNode,
  68. // Node creation/emisssion.
  69. EmitInteger, // Create a TargetConstant
  70. EmitStringInteger, // Create a TargetConstant from a string.
  71. EmitRegister, // Create a register.
  72. EmitConvertToTarget, // Convert a imm/fpimm to target imm/fpimm
  73. EmitMergeInputChains, // Merge together a chains for an input.
  74. EmitCopyToReg, // Emit a copytoreg into a physreg.
  75. EmitNode, // Create a DAG node
  76. EmitNodeXForm, // Run a SDNodeXForm
  77. MarkGlueResults, // Indicate which interior nodes have glue results.
  78. CompleteMatch, // Finish a match and update the results.
  79. MorphNodeTo // Build a node, finish a match and update results.
  80. };
  81. const KindTy Kind;
  82. protected:
  83. Matcher(KindTy K) : Kind(K) {}
  84. public:
  85. virtual ~Matcher() {}
  86. KindTy getKind() const { return Kind; }
  87. Matcher *getNext() { return Next.get(); }
  88. const Matcher *getNext() const { return Next.get(); }
  89. void setNext(Matcher *C) { Next.reset(C); }
  90. Matcher *takeNext() { return Next.release(); }
  91. std::unique_ptr<Matcher> &getNextPtr() { return Next; }
  92. bool isEqual(const Matcher *M) const {
  93. if (getKind() != M->getKind()) return false;
  94. return isEqualImpl(M);
  95. }
  96. unsigned getHash() const {
  97. // Clear the high bit so we don't conflict with tombstones etc.
  98. return ((getHashImpl() << 4) ^ getKind()) & (~0U>>1);
  99. }
  100. /// isSafeToReorderWithPatternPredicate - Return true if it is safe to sink a
  101. /// PatternPredicate node past this one.
  102. virtual bool isSafeToReorderWithPatternPredicate() const {
  103. return false;
  104. }
  105. /// isSimplePredicateNode - Return true if this is a simple predicate that
  106. /// operates on the node or its children without potential side effects or a
  107. /// change of the current node.
  108. bool isSimplePredicateNode() const {
  109. switch (getKind()) {
  110. default: return false;
  111. case CheckSame:
  112. case CheckChildSame:
  113. case CheckPatternPredicate:
  114. case CheckPredicate:
  115. case CheckOpcode:
  116. case CheckType:
  117. case CheckChildType:
  118. case CheckInteger:
  119. case CheckChildInteger:
  120. case CheckCondCode:
  121. case CheckValueType:
  122. case CheckAndImm:
  123. case CheckOrImm:
  124. case CheckFoldableChainNode:
  125. return true;
  126. }
  127. }
  128. /// isSimplePredicateOrRecordNode - Return true if this is a record node or
  129. /// a simple predicate.
  130. bool isSimplePredicateOrRecordNode() const {
  131. return isSimplePredicateNode() ||
  132. getKind() == RecordNode || getKind() == RecordChild;
  133. }
  134. /// unlinkNode - Unlink the specified node from this chain. If Other == this,
  135. /// we unlink the next pointer and return it. Otherwise we unlink Other from
  136. /// the list and return this.
  137. Matcher *unlinkNode(Matcher *Other);
  138. /// canMoveBefore - Return true if this matcher is the same as Other, or if
  139. /// we can move this matcher past all of the nodes in-between Other and this
  140. /// node. Other must be equal to or before this.
  141. bool canMoveBefore(const Matcher *Other) const;
  142. /// canMoveBeforeNode - Return true if it is safe to move the current matcher
  143. /// across the specified one.
  144. bool canMoveBeforeNode(const Matcher *Other) const;
  145. /// isContradictory - Return true of these two matchers could never match on
  146. /// the same node.
  147. bool isContradictory(const Matcher *Other) const {
  148. // Since this predicate is reflexive, we canonicalize the ordering so that
  149. // we always match a node against nodes with kinds that are greater or equal
  150. // to them. For example, we'll pass in a CheckType node as an argument to
  151. // the CheckOpcode method, not the other way around.
  152. if (getKind() < Other->getKind())
  153. return isContradictoryImpl(Other);
  154. return Other->isContradictoryImpl(this);
  155. }
  156. void print(raw_ostream &OS, unsigned indent = 0) const;
  157. void printOne(raw_ostream &OS) const;
  158. void dump() const;
  159. protected:
  160. virtual void printImpl(raw_ostream &OS, unsigned indent) const = 0;
  161. virtual bool isEqualImpl(const Matcher *M) const = 0;
  162. virtual unsigned getHashImpl() const = 0;
  163. virtual bool isContradictoryImpl(const Matcher *M) const { return false; }
  164. };
  165. /// ScopeMatcher - This attempts to match each of its children to find the first
  166. /// one that successfully matches. If one child fails, it tries the next child.
  167. /// If none of the children match then this check fails. It never has a 'next'.
  168. class ScopeMatcher : public Matcher {
  169. SmallVector<Matcher*, 4> Children;
  170. public:
  171. ScopeMatcher(ArrayRef<Matcher *> children)
  172. : Matcher(Scope), Children(children.begin(), children.end()) {
  173. }
  174. ~ScopeMatcher() override;
  175. unsigned getNumChildren() const { return Children.size(); }
  176. Matcher *getChild(unsigned i) { return Children[i]; }
  177. const Matcher *getChild(unsigned i) const { return Children[i]; }
  178. void resetChild(unsigned i, Matcher *N) {
  179. delete Children[i];
  180. Children[i] = N;
  181. }
  182. Matcher *takeChild(unsigned i) {
  183. Matcher *Res = Children[i];
  184. Children[i] = nullptr;
  185. return Res;
  186. }
  187. void setNumChildren(unsigned NC) {
  188. if (NC < Children.size()) {
  189. // delete any children we're about to lose pointers to.
  190. for (unsigned i = NC, e = Children.size(); i != e; ++i)
  191. delete Children[i];
  192. }
  193. Children.resize(NC);
  194. }
  195. static inline bool classof(const Matcher *N) {
  196. return N->getKind() == Scope;
  197. }
  198. private:
  199. void printImpl(raw_ostream &OS, unsigned indent) const override;
  200. bool isEqualImpl(const Matcher *M) const override { return false; }
  201. unsigned getHashImpl() const override { return 12312; }
  202. };
  203. /// RecordMatcher - Save the current node in the operand list.
  204. class RecordMatcher : public Matcher {
  205. /// WhatFor - This is a string indicating why we're recording this. This
  206. /// should only be used for comment generation not anything semantic.
  207. std::string WhatFor;
  208. /// ResultNo - The slot number in the RecordedNodes vector that this will be,
  209. /// just printed as a comment.
  210. unsigned ResultNo;
  211. public:
  212. RecordMatcher(const std::string &whatfor, unsigned resultNo)
  213. : Matcher(RecordNode), WhatFor(whatfor), ResultNo(resultNo) {}
  214. const std::string &getWhatFor() const { return WhatFor; }
  215. unsigned getResultNo() const { return ResultNo; }
  216. static inline bool classof(const Matcher *N) {
  217. return N->getKind() == RecordNode;
  218. }
  219. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  220. private:
  221. void printImpl(raw_ostream &OS, unsigned indent) const override;
  222. bool isEqualImpl(const Matcher *M) const override { return true; }
  223. unsigned getHashImpl() const override { return 0; }
  224. };
  225. /// RecordChildMatcher - Save a numbered child of the current node, or fail
  226. /// the match if it doesn't exist. This is logically equivalent to:
  227. /// MoveChild N + RecordNode + MoveParent.
  228. class RecordChildMatcher : public Matcher {
  229. unsigned ChildNo;
  230. /// WhatFor - This is a string indicating why we're recording this. This
  231. /// should only be used for comment generation not anything semantic.
  232. std::string WhatFor;
  233. /// ResultNo - The slot number in the RecordedNodes vector that this will be,
  234. /// just printed as a comment.
  235. unsigned ResultNo;
  236. public:
  237. RecordChildMatcher(unsigned childno, const std::string &whatfor,
  238. unsigned resultNo)
  239. : Matcher(RecordChild), ChildNo(childno), WhatFor(whatfor),
  240. ResultNo(resultNo) {}
  241. unsigned getChildNo() const { return ChildNo; }
  242. const std::string &getWhatFor() const { return WhatFor; }
  243. unsigned getResultNo() const { return ResultNo; }
  244. static inline bool classof(const Matcher *N) {
  245. return N->getKind() == RecordChild;
  246. }
  247. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  248. private:
  249. void printImpl(raw_ostream &OS, unsigned indent) const override;
  250. bool isEqualImpl(const Matcher *M) const override {
  251. return cast<RecordChildMatcher>(M)->getChildNo() == getChildNo();
  252. }
  253. unsigned getHashImpl() const override { return getChildNo(); }
  254. };
  255. /// RecordMemRefMatcher - Save the current node's memref.
  256. class RecordMemRefMatcher : public Matcher {
  257. public:
  258. RecordMemRefMatcher() : Matcher(RecordMemRef) {}
  259. static inline bool classof(const Matcher *N) {
  260. return N->getKind() == RecordMemRef;
  261. }
  262. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  263. private:
  264. void printImpl(raw_ostream &OS, unsigned indent) const override;
  265. bool isEqualImpl(const Matcher *M) const override { return true; }
  266. unsigned getHashImpl() const override { return 0; }
  267. };
  268. /// CaptureGlueInputMatcher - If the current record has a glue input, record
  269. /// it so that it is used as an input to the generated code.
  270. class CaptureGlueInputMatcher : public Matcher {
  271. public:
  272. CaptureGlueInputMatcher() : Matcher(CaptureGlueInput) {}
  273. static inline bool classof(const Matcher *N) {
  274. return N->getKind() == CaptureGlueInput;
  275. }
  276. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  277. private:
  278. void printImpl(raw_ostream &OS, unsigned indent) const override;
  279. bool isEqualImpl(const Matcher *M) const override { return true; }
  280. unsigned getHashImpl() const override { return 0; }
  281. };
  282. /// MoveChildMatcher - This tells the interpreter to move into the
  283. /// specified child node.
  284. class MoveChildMatcher : public Matcher {
  285. unsigned ChildNo;
  286. public:
  287. MoveChildMatcher(unsigned childNo) : Matcher(MoveChild), ChildNo(childNo) {}
  288. unsigned getChildNo() const { return ChildNo; }
  289. static inline bool classof(const Matcher *N) {
  290. return N->getKind() == MoveChild;
  291. }
  292. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  293. private:
  294. void printImpl(raw_ostream &OS, unsigned indent) const override;
  295. bool isEqualImpl(const Matcher *M) const override {
  296. return cast<MoveChildMatcher>(M)->getChildNo() == getChildNo();
  297. }
  298. unsigned getHashImpl() const override { return getChildNo(); }
  299. };
  300. /// MoveParentMatcher - This tells the interpreter to move to the parent
  301. /// of the current node.
  302. class MoveParentMatcher : public Matcher {
  303. public:
  304. MoveParentMatcher() : Matcher(MoveParent) {}
  305. static inline bool classof(const Matcher *N) {
  306. return N->getKind() == MoveParent;
  307. }
  308. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  309. private:
  310. void printImpl(raw_ostream &OS, unsigned indent) const override;
  311. bool isEqualImpl(const Matcher *M) const override { return true; }
  312. unsigned getHashImpl() const override { return 0; }
  313. };
  314. /// CheckSameMatcher - This checks to see if this node is exactly the same
  315. /// node as the specified match that was recorded with 'Record'. This is used
  316. /// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
  317. class CheckSameMatcher : public Matcher {
  318. unsigned MatchNumber;
  319. public:
  320. CheckSameMatcher(unsigned matchnumber)
  321. : Matcher(CheckSame), MatchNumber(matchnumber) {}
  322. unsigned getMatchNumber() const { return MatchNumber; }
  323. static inline bool classof(const Matcher *N) {
  324. return N->getKind() == CheckSame;
  325. }
  326. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  327. private:
  328. void printImpl(raw_ostream &OS, unsigned indent) const override;
  329. bool isEqualImpl(const Matcher *M) const override {
  330. return cast<CheckSameMatcher>(M)->getMatchNumber() == getMatchNumber();
  331. }
  332. unsigned getHashImpl() const override { return getMatchNumber(); }
  333. };
  334. /// CheckChildSameMatcher - This checks to see if child node is exactly the same
  335. /// node as the specified match that was recorded with 'Record'. This is used
  336. /// when patterns have the same name in them, like '(mul GPR:$in, GPR:$in)'.
  337. class CheckChildSameMatcher : public Matcher {
  338. unsigned ChildNo;
  339. unsigned MatchNumber;
  340. public:
  341. CheckChildSameMatcher(unsigned childno, unsigned matchnumber)
  342. : Matcher(CheckChildSame), ChildNo(childno), MatchNumber(matchnumber) {}
  343. unsigned getChildNo() const { return ChildNo; }
  344. unsigned getMatchNumber() const { return MatchNumber; }
  345. static inline bool classof(const Matcher *N) {
  346. return N->getKind() == CheckChildSame;
  347. }
  348. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  349. private:
  350. void printImpl(raw_ostream &OS, unsigned indent) const override;
  351. bool isEqualImpl(const Matcher *M) const override {
  352. return cast<CheckChildSameMatcher>(M)->ChildNo == ChildNo &&
  353. cast<CheckChildSameMatcher>(M)->MatchNumber == MatchNumber;
  354. }
  355. unsigned getHashImpl() const override { return (MatchNumber << 2) | ChildNo; }
  356. };
  357. /// CheckPatternPredicateMatcher - This checks the target-specific predicate
  358. /// to see if the entire pattern is capable of matching. This predicate does
  359. /// not take a node as input. This is used for subtarget feature checks etc.
  360. class CheckPatternPredicateMatcher : public Matcher {
  361. std::string Predicate;
  362. public:
  363. CheckPatternPredicateMatcher(StringRef predicate)
  364. : Matcher(CheckPatternPredicate), Predicate(predicate) {}
  365. StringRef getPredicate() const { return Predicate; }
  366. static inline bool classof(const Matcher *N) {
  367. return N->getKind() == CheckPatternPredicate;
  368. }
  369. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  370. private:
  371. void printImpl(raw_ostream &OS, unsigned indent) const override;
  372. bool isEqualImpl(const Matcher *M) const override {
  373. return cast<CheckPatternPredicateMatcher>(M)->getPredicate() == Predicate;
  374. }
  375. unsigned getHashImpl() const override;
  376. };
  377. /// CheckPredicateMatcher - This checks the target-specific predicate to
  378. /// see if the node is acceptable.
  379. class CheckPredicateMatcher : public Matcher {
  380. TreePattern *Pred;
  381. public:
  382. CheckPredicateMatcher(const TreePredicateFn &pred);
  383. TreePredicateFn getPredicate() const;
  384. static inline bool classof(const Matcher *N) {
  385. return N->getKind() == CheckPredicate;
  386. }
  387. // TODO: Ok?
  388. //virtual bool isSafeToReorderWithPatternPredicate() const { return true; }
  389. private:
  390. void printImpl(raw_ostream &OS, unsigned indent) const override;
  391. bool isEqualImpl(const Matcher *M) const override {
  392. return cast<CheckPredicateMatcher>(M)->Pred == Pred;
  393. }
  394. unsigned getHashImpl() const override;
  395. };
  396. /// CheckOpcodeMatcher - This checks to see if the current node has the
  397. /// specified opcode, if not it fails to match.
  398. class CheckOpcodeMatcher : public Matcher {
  399. const SDNodeInfo &Opcode;
  400. public:
  401. CheckOpcodeMatcher(const SDNodeInfo &opcode)
  402. : Matcher(CheckOpcode), Opcode(opcode) {}
  403. const SDNodeInfo &getOpcode() const { return Opcode; }
  404. static inline bool classof(const Matcher *N) {
  405. return N->getKind() == CheckOpcode;
  406. }
  407. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  408. private:
  409. void printImpl(raw_ostream &OS, unsigned indent) const override;
  410. bool isEqualImpl(const Matcher *M) const override;
  411. unsigned getHashImpl() const override;
  412. bool isContradictoryImpl(const Matcher *M) const override;
  413. };
  414. /// SwitchOpcodeMatcher - Switch based on the current node's opcode, dispatching
  415. /// to one matcher per opcode. If the opcode doesn't match any of the cases,
  416. /// then the match fails. This is semantically equivalent to a Scope node where
  417. /// every child does a CheckOpcode, but is much faster.
  418. class SwitchOpcodeMatcher : public Matcher {
  419. SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases;
  420. public:
  421. SwitchOpcodeMatcher(ArrayRef<std::pair<const SDNodeInfo*, Matcher*> > cases)
  422. : Matcher(SwitchOpcode), Cases(cases.begin(), cases.end()) {}
  423. ~SwitchOpcodeMatcher() override;
  424. static inline bool classof(const Matcher *N) {
  425. return N->getKind() == SwitchOpcode;
  426. }
  427. unsigned getNumCases() const { return Cases.size(); }
  428. const SDNodeInfo &getCaseOpcode(unsigned i) const { return *Cases[i].first; }
  429. Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
  430. const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
  431. private:
  432. void printImpl(raw_ostream &OS, unsigned indent) const override;
  433. bool isEqualImpl(const Matcher *M) const override { return false; }
  434. unsigned getHashImpl() const override { return 4123; }
  435. };
  436. /// CheckTypeMatcher - This checks to see if the current node has the
  437. /// specified type at the specified result, if not it fails to match.
  438. class CheckTypeMatcher : public Matcher {
  439. MVT::SimpleValueType Type;
  440. unsigned ResNo;
  441. public:
  442. CheckTypeMatcher(MVT::SimpleValueType type, unsigned resno)
  443. : Matcher(CheckType), Type(type), ResNo(resno) {}
  444. MVT::SimpleValueType getType() const { return Type; }
  445. unsigned getResNo() const { return ResNo; }
  446. static inline bool classof(const Matcher *N) {
  447. return N->getKind() == CheckType;
  448. }
  449. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  450. private:
  451. void printImpl(raw_ostream &OS, unsigned indent) const override;
  452. bool isEqualImpl(const Matcher *M) const override {
  453. return cast<CheckTypeMatcher>(M)->Type == Type;
  454. }
  455. unsigned getHashImpl() const override { return Type; }
  456. bool isContradictoryImpl(const Matcher *M) const override;
  457. };
  458. /// SwitchTypeMatcher - Switch based on the current node's type, dispatching
  459. /// to one matcher per case. If the type doesn't match any of the cases,
  460. /// then the match fails. This is semantically equivalent to a Scope node where
  461. /// every child does a CheckType, but is much faster.
  462. class SwitchTypeMatcher : public Matcher {
  463. SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases;
  464. public:
  465. SwitchTypeMatcher(ArrayRef<std::pair<MVT::SimpleValueType, Matcher*> > cases)
  466. : Matcher(SwitchType), Cases(cases.begin(), cases.end()) {}
  467. ~SwitchTypeMatcher() override;
  468. static inline bool classof(const Matcher *N) {
  469. return N->getKind() == SwitchType;
  470. }
  471. unsigned getNumCases() const { return Cases.size(); }
  472. MVT::SimpleValueType getCaseType(unsigned i) const { return Cases[i].first; }
  473. Matcher *getCaseMatcher(unsigned i) { return Cases[i].second; }
  474. const Matcher *getCaseMatcher(unsigned i) const { return Cases[i].second; }
  475. private:
  476. void printImpl(raw_ostream &OS, unsigned indent) const override;
  477. bool isEqualImpl(const Matcher *M) const override { return false; }
  478. unsigned getHashImpl() const override { return 4123; }
  479. };
  480. /// CheckChildTypeMatcher - This checks to see if a child node has the
  481. /// specified type, if not it fails to match.
  482. class CheckChildTypeMatcher : public Matcher {
  483. unsigned ChildNo;
  484. MVT::SimpleValueType Type;
  485. public:
  486. CheckChildTypeMatcher(unsigned childno, MVT::SimpleValueType type)
  487. : Matcher(CheckChildType), ChildNo(childno), Type(type) {}
  488. unsigned getChildNo() const { return ChildNo; }
  489. MVT::SimpleValueType getType() const { return Type; }
  490. static inline bool classof(const Matcher *N) {
  491. return N->getKind() == CheckChildType;
  492. }
  493. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  494. private:
  495. void printImpl(raw_ostream &OS, unsigned indent) const override;
  496. bool isEqualImpl(const Matcher *M) const override {
  497. return cast<CheckChildTypeMatcher>(M)->ChildNo == ChildNo &&
  498. cast<CheckChildTypeMatcher>(M)->Type == Type;
  499. }
  500. unsigned getHashImpl() const override { return (Type << 3) | ChildNo; }
  501. bool isContradictoryImpl(const Matcher *M) const override;
  502. };
  503. /// CheckIntegerMatcher - This checks to see if the current node is a
  504. /// ConstantSDNode with the specified integer value, if not it fails to match.
  505. class CheckIntegerMatcher : public Matcher {
  506. int64_t Value;
  507. public:
  508. CheckIntegerMatcher(int64_t value)
  509. : Matcher(CheckInteger), Value(value) {}
  510. int64_t getValue() const { return Value; }
  511. static inline bool classof(const Matcher *N) {
  512. return N->getKind() == CheckInteger;
  513. }
  514. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  515. private:
  516. void printImpl(raw_ostream &OS, unsigned indent) const override;
  517. bool isEqualImpl(const Matcher *M) const override {
  518. return cast<CheckIntegerMatcher>(M)->Value == Value;
  519. }
  520. unsigned getHashImpl() const override { return Value; }
  521. bool isContradictoryImpl(const Matcher *M) const override;
  522. };
  523. /// CheckChildIntegerMatcher - This checks to see if the child node is a
  524. /// ConstantSDNode with a specified integer value, if not it fails to match.
  525. class CheckChildIntegerMatcher : public Matcher {
  526. unsigned ChildNo;
  527. int64_t Value;
  528. public:
  529. CheckChildIntegerMatcher(unsigned childno, int64_t value)
  530. : Matcher(CheckChildInteger), ChildNo(childno), Value(value) {}
  531. unsigned getChildNo() const { return ChildNo; }
  532. int64_t getValue() const { return Value; }
  533. static inline bool classof(const Matcher *N) {
  534. return N->getKind() == CheckChildInteger;
  535. }
  536. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  537. private:
  538. void printImpl(raw_ostream &OS, unsigned indent) const override;
  539. bool isEqualImpl(const Matcher *M) const override {
  540. return cast<CheckChildIntegerMatcher>(M)->ChildNo == ChildNo &&
  541. cast<CheckChildIntegerMatcher>(M)->Value == Value;
  542. }
  543. unsigned getHashImpl() const override { return (Value << 3) | ChildNo; }
  544. bool isContradictoryImpl(const Matcher *M) const override;
  545. };
  546. /// CheckCondCodeMatcher - This checks to see if the current node is a
  547. /// CondCodeSDNode with the specified condition, if not it fails to match.
  548. class CheckCondCodeMatcher : public Matcher {
  549. StringRef CondCodeName;
  550. public:
  551. CheckCondCodeMatcher(StringRef condcodename)
  552. : Matcher(CheckCondCode), CondCodeName(condcodename) {}
  553. StringRef getCondCodeName() const { return CondCodeName; }
  554. static inline bool classof(const Matcher *N) {
  555. return N->getKind() == CheckCondCode;
  556. }
  557. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  558. private:
  559. void printImpl(raw_ostream &OS, unsigned indent) const override;
  560. bool isEqualImpl(const Matcher *M) const override {
  561. return cast<CheckCondCodeMatcher>(M)->CondCodeName == CondCodeName;
  562. }
  563. unsigned getHashImpl() const override;
  564. };
  565. /// CheckValueTypeMatcher - This checks to see if the current node is a
  566. /// VTSDNode with the specified type, if not it fails to match.
  567. class CheckValueTypeMatcher : public Matcher {
  568. StringRef TypeName;
  569. public:
  570. CheckValueTypeMatcher(StringRef type_name)
  571. : Matcher(CheckValueType), TypeName(type_name) {}
  572. StringRef getTypeName() const { return TypeName; }
  573. static inline bool classof(const Matcher *N) {
  574. return N->getKind() == CheckValueType;
  575. }
  576. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  577. private:
  578. void printImpl(raw_ostream &OS, unsigned indent) const override;
  579. bool isEqualImpl(const Matcher *M) const override {
  580. return cast<CheckValueTypeMatcher>(M)->TypeName == TypeName;
  581. }
  582. unsigned getHashImpl() const override;
  583. bool isContradictoryImpl(const Matcher *M) const override;
  584. };
  585. /// CheckComplexPatMatcher - This node runs the specified ComplexPattern on
  586. /// the current node.
  587. class CheckComplexPatMatcher : public Matcher {
  588. const ComplexPattern &Pattern;
  589. /// MatchNumber - This is the recorded nodes slot that contains the node we
  590. /// want to match against.
  591. unsigned MatchNumber;
  592. /// Name - The name of the node we're matching, for comment emission.
  593. std::string Name;
  594. /// FirstResult - This is the first slot in the RecordedNodes list that the
  595. /// result of the match populates.
  596. unsigned FirstResult;
  597. public:
  598. CheckComplexPatMatcher(const ComplexPattern &pattern, unsigned matchnumber,
  599. const std::string &name, unsigned firstresult)
  600. : Matcher(CheckComplexPat), Pattern(pattern), MatchNumber(matchnumber),
  601. Name(name), FirstResult(firstresult) {}
  602. const ComplexPattern &getPattern() const { return Pattern; }
  603. unsigned getMatchNumber() const { return MatchNumber; }
  604. const std::string getName() const { return Name; }
  605. unsigned getFirstResult() const { return FirstResult; }
  606. static inline bool classof(const Matcher *N) {
  607. return N->getKind() == CheckComplexPat;
  608. }
  609. // Not safe to move a pattern predicate past a complex pattern.
  610. bool isSafeToReorderWithPatternPredicate() const override { return false; }
  611. private:
  612. void printImpl(raw_ostream &OS, unsigned indent) const override;
  613. bool isEqualImpl(const Matcher *M) const override {
  614. return &cast<CheckComplexPatMatcher>(M)->Pattern == &Pattern &&
  615. cast<CheckComplexPatMatcher>(M)->MatchNumber == MatchNumber;
  616. }
  617. unsigned getHashImpl() const override {
  618. return (unsigned)(intptr_t)&Pattern ^ MatchNumber;
  619. }
  620. };
  621. /// CheckAndImmMatcher - This checks to see if the current node is an 'and'
  622. /// with something equivalent to the specified immediate.
  623. class CheckAndImmMatcher : public Matcher {
  624. int64_t Value;
  625. public:
  626. CheckAndImmMatcher(int64_t value)
  627. : Matcher(CheckAndImm), Value(value) {}
  628. int64_t getValue() const { return Value; }
  629. static inline bool classof(const Matcher *N) {
  630. return N->getKind() == CheckAndImm;
  631. }
  632. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  633. private:
  634. void printImpl(raw_ostream &OS, unsigned indent) const override;
  635. bool isEqualImpl(const Matcher *M) const override {
  636. return cast<CheckAndImmMatcher>(M)->Value == Value;
  637. }
  638. unsigned getHashImpl() const override { return Value; }
  639. };
  640. /// CheckOrImmMatcher - This checks to see if the current node is an 'and'
  641. /// with something equivalent to the specified immediate.
  642. class CheckOrImmMatcher : public Matcher {
  643. int64_t Value;
  644. public:
  645. CheckOrImmMatcher(int64_t value)
  646. : Matcher(CheckOrImm), Value(value) {}
  647. int64_t getValue() const { return Value; }
  648. static inline bool classof(const Matcher *N) {
  649. return N->getKind() == CheckOrImm;
  650. }
  651. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  652. private:
  653. void printImpl(raw_ostream &OS, unsigned indent) const override;
  654. bool isEqualImpl(const Matcher *M) const override {
  655. return cast<CheckOrImmMatcher>(M)->Value == Value;
  656. }
  657. unsigned getHashImpl() const override { return Value; }
  658. };
  659. /// CheckFoldableChainNodeMatcher - This checks to see if the current node
  660. /// (which defines a chain operand) is safe to fold into a larger pattern.
  661. class CheckFoldableChainNodeMatcher : public Matcher {
  662. public:
  663. CheckFoldableChainNodeMatcher()
  664. : Matcher(CheckFoldableChainNode) {}
  665. static inline bool classof(const Matcher *N) {
  666. return N->getKind() == CheckFoldableChainNode;
  667. }
  668. bool isSafeToReorderWithPatternPredicate() const override { return true; }
  669. private:
  670. void printImpl(raw_ostream &OS, unsigned indent) const override;
  671. bool isEqualImpl(const Matcher *M) const override { return true; }
  672. unsigned getHashImpl() const override { return 0; }
  673. };
  674. /// EmitIntegerMatcher - This creates a new TargetConstant.
  675. class EmitIntegerMatcher : public Matcher {
  676. int64_t Val;
  677. MVT::SimpleValueType VT;
  678. public:
  679. EmitIntegerMatcher(int64_t val, MVT::SimpleValueType vt)
  680. : Matcher(EmitInteger), Val(val), VT(vt) {}
  681. int64_t getValue() const { return Val; }
  682. MVT::SimpleValueType getVT() const { return VT; }
  683. static inline bool classof(const Matcher *N) {
  684. return N->getKind() == EmitInteger;
  685. }
  686. private:
  687. void printImpl(raw_ostream &OS, unsigned indent) const override;
  688. bool isEqualImpl(const Matcher *M) const override {
  689. return cast<EmitIntegerMatcher>(M)->Val == Val &&
  690. cast<EmitIntegerMatcher>(M)->VT == VT;
  691. }
  692. unsigned getHashImpl() const override { return (Val << 4) | VT; }
  693. };
  694. /// EmitStringIntegerMatcher - A target constant whose value is represented
  695. /// by a string.
  696. class EmitStringIntegerMatcher : public Matcher {
  697. std::string Val;
  698. MVT::SimpleValueType VT;
  699. public:
  700. EmitStringIntegerMatcher(const std::string &val, MVT::SimpleValueType vt)
  701. : Matcher(EmitStringInteger), Val(val), VT(vt) {}
  702. const std::string &getValue() const { return Val; }
  703. MVT::SimpleValueType getVT() const { return VT; }
  704. static inline bool classof(const Matcher *N) {
  705. return N->getKind() == EmitStringInteger;
  706. }
  707. private:
  708. void printImpl(raw_ostream &OS, unsigned indent) const override;
  709. bool isEqualImpl(const Matcher *M) const override {
  710. return cast<EmitStringIntegerMatcher>(M)->Val == Val &&
  711. cast<EmitStringIntegerMatcher>(M)->VT == VT;
  712. }
  713. unsigned getHashImpl() const override;
  714. };
  715. /// EmitRegisterMatcher - This creates a new TargetConstant.
  716. class EmitRegisterMatcher : public Matcher {
  717. /// Reg - The def for the register that we're emitting. If this is null, then
  718. /// this is a reference to zero_reg.
  719. const CodeGenRegister *Reg;
  720. MVT::SimpleValueType VT;
  721. public:
  722. EmitRegisterMatcher(const CodeGenRegister *reg, MVT::SimpleValueType vt)
  723. : Matcher(EmitRegister), Reg(reg), VT(vt) {}
  724. const CodeGenRegister *getReg() const { return Reg; }
  725. MVT::SimpleValueType getVT() const { return VT; }
  726. static inline bool classof(const Matcher *N) {
  727. return N->getKind() == EmitRegister;
  728. }
  729. private:
  730. void printImpl(raw_ostream &OS, unsigned indent) const override;
  731. bool isEqualImpl(const Matcher *M) const override {
  732. return cast<EmitRegisterMatcher>(M)->Reg == Reg &&
  733. cast<EmitRegisterMatcher>(M)->VT == VT;
  734. }
  735. unsigned getHashImpl() const override {
  736. return ((unsigned)(intptr_t)Reg) << 4 | VT;
  737. }
  738. };
  739. /// EmitConvertToTargetMatcher - Emit an operation that reads a specified
  740. /// recorded node and converts it from being a ISD::Constant to
  741. /// ISD::TargetConstant, likewise for ConstantFP.
  742. class EmitConvertToTargetMatcher : public Matcher {
  743. unsigned Slot;
  744. public:
  745. EmitConvertToTargetMatcher(unsigned slot)
  746. : Matcher(EmitConvertToTarget), Slot(slot) {}
  747. unsigned getSlot() const { return Slot; }
  748. static inline bool classof(const Matcher *N) {
  749. return N->getKind() == EmitConvertToTarget;
  750. }
  751. private:
  752. void printImpl(raw_ostream &OS, unsigned indent) const override;
  753. bool isEqualImpl(const Matcher *M) const override {
  754. return cast<EmitConvertToTargetMatcher>(M)->Slot == Slot;
  755. }
  756. unsigned getHashImpl() const override { return Slot; }
  757. };
  758. /// EmitMergeInputChainsMatcher - Emit a node that merges a list of input
  759. /// chains together with a token factor. The list of nodes are the nodes in the
  760. /// matched pattern that have chain input/outputs. This node adds all input
  761. /// chains of these nodes if they are not themselves a node in the pattern.
  762. class EmitMergeInputChainsMatcher : public Matcher {
  763. SmallVector<unsigned, 3> ChainNodes;
  764. public:
  765. EmitMergeInputChainsMatcher(ArrayRef<unsigned> nodes)
  766. : Matcher(EmitMergeInputChains), ChainNodes(nodes.begin(), nodes.end()) {}
  767. unsigned getNumNodes() const { return ChainNodes.size(); }
  768. unsigned getNode(unsigned i) const {
  769. assert(i < ChainNodes.size());
  770. return ChainNodes[i];
  771. }
  772. static inline bool classof(const Matcher *N) {
  773. return N->getKind() == EmitMergeInputChains;
  774. }
  775. private:
  776. void printImpl(raw_ostream &OS, unsigned indent) const override;
  777. bool isEqualImpl(const Matcher *M) const override {
  778. return cast<EmitMergeInputChainsMatcher>(M)->ChainNodes == ChainNodes;
  779. }
  780. unsigned getHashImpl() const override;
  781. };
  782. /// EmitCopyToRegMatcher - Emit a CopyToReg node from a value to a physreg,
  783. /// pushing the chain and glue results.
  784. ///
  785. class EmitCopyToRegMatcher : public Matcher {
  786. unsigned SrcSlot; // Value to copy into the physreg.
  787. Record *DestPhysReg;
  788. public:
  789. EmitCopyToRegMatcher(unsigned srcSlot, Record *destPhysReg)
  790. : Matcher(EmitCopyToReg), SrcSlot(srcSlot), DestPhysReg(destPhysReg) {}
  791. unsigned getSrcSlot() const { return SrcSlot; }
  792. Record *getDestPhysReg() const { return DestPhysReg; }
  793. static inline bool classof(const Matcher *N) {
  794. return N->getKind() == EmitCopyToReg;
  795. }
  796. private:
  797. void printImpl(raw_ostream &OS, unsigned indent) const override;
  798. bool isEqualImpl(const Matcher *M) const override {
  799. return cast<EmitCopyToRegMatcher>(M)->SrcSlot == SrcSlot &&
  800. cast<EmitCopyToRegMatcher>(M)->DestPhysReg == DestPhysReg;
  801. }
  802. unsigned getHashImpl() const override {
  803. return SrcSlot ^ ((unsigned)(intptr_t)DestPhysReg << 4);
  804. }
  805. };
  806. /// EmitNodeXFormMatcher - Emit an operation that runs an SDNodeXForm on a
  807. /// recorded node and records the result.
  808. class EmitNodeXFormMatcher : public Matcher {
  809. unsigned Slot;
  810. Record *NodeXForm;
  811. public:
  812. EmitNodeXFormMatcher(unsigned slot, Record *nodeXForm)
  813. : Matcher(EmitNodeXForm), Slot(slot), NodeXForm(nodeXForm) {}
  814. unsigned getSlot() const { return Slot; }
  815. Record *getNodeXForm() const { return NodeXForm; }
  816. static inline bool classof(const Matcher *N) {
  817. return N->getKind() == EmitNodeXForm;
  818. }
  819. private:
  820. void printImpl(raw_ostream &OS, unsigned indent) const override;
  821. bool isEqualImpl(const Matcher *M) const override {
  822. return cast<EmitNodeXFormMatcher>(M)->Slot == Slot &&
  823. cast<EmitNodeXFormMatcher>(M)->NodeXForm == NodeXForm;
  824. }
  825. unsigned getHashImpl() const override {
  826. return Slot ^ ((unsigned)(intptr_t)NodeXForm << 4);
  827. }
  828. };
  829. /// EmitNodeMatcherCommon - Common class shared between EmitNode and
  830. /// MorphNodeTo.
  831. class EmitNodeMatcherCommon : public Matcher {
  832. std::string OpcodeName;
  833. const SmallVector<MVT::SimpleValueType, 3> VTs;
  834. const SmallVector<unsigned, 6> Operands;
  835. bool HasChain, HasInGlue, HasOutGlue, HasMemRefs;
  836. /// NumFixedArityOperands - If this is a fixed arity node, this is set to -1.
  837. /// If this is a varidic node, this is set to the number of fixed arity
  838. /// operands in the root of the pattern. The rest are appended to this node.
  839. int NumFixedArityOperands;
  840. public:
  841. EmitNodeMatcherCommon(const std::string &opcodeName,
  842. ArrayRef<MVT::SimpleValueType> vts,
  843. ArrayRef<unsigned> operands,
  844. bool hasChain, bool hasInGlue, bool hasOutGlue,
  845. bool hasmemrefs,
  846. int numfixedarityoperands, bool isMorphNodeTo)
  847. : Matcher(isMorphNodeTo ? MorphNodeTo : EmitNode), OpcodeName(opcodeName),
  848. VTs(vts.begin(), vts.end()), Operands(operands.begin(), operands.end()),
  849. HasChain(hasChain), HasInGlue(hasInGlue), HasOutGlue(hasOutGlue),
  850. HasMemRefs(hasmemrefs), NumFixedArityOperands(numfixedarityoperands) {}
  851. const std::string &getOpcodeName() const { return OpcodeName; }
  852. unsigned getNumVTs() const { return VTs.size(); }
  853. MVT::SimpleValueType getVT(unsigned i) const {
  854. assert(i < VTs.size());
  855. return VTs[i];
  856. }
  857. unsigned getNumOperands() const { return Operands.size(); }
  858. unsigned getOperand(unsigned i) const {
  859. assert(i < Operands.size());
  860. return Operands[i];
  861. }
  862. const SmallVectorImpl<MVT::SimpleValueType> &getVTList() const { return VTs; }
  863. const SmallVectorImpl<unsigned> &getOperandList() const { return Operands; }
  864. bool hasChain() const { return HasChain; }
  865. bool hasInFlag() const { return HasInGlue; }
  866. bool hasOutFlag() const { return HasOutGlue; }
  867. bool hasMemRefs() const { return HasMemRefs; }
  868. int getNumFixedArityOperands() const { return NumFixedArityOperands; }
  869. static inline bool classof(const Matcher *N) {
  870. return N->getKind() == EmitNode || N->getKind() == MorphNodeTo;
  871. }
  872. private:
  873. void printImpl(raw_ostream &OS, unsigned indent) const override;
  874. bool isEqualImpl(const Matcher *M) const override;
  875. unsigned getHashImpl() const override;
  876. };
  877. /// EmitNodeMatcher - This signals a successful match and generates a node.
  878. class EmitNodeMatcher : public EmitNodeMatcherCommon {
  879. void anchor() override;
  880. unsigned FirstResultSlot;
  881. public:
  882. EmitNodeMatcher(const std::string &opcodeName,
  883. ArrayRef<MVT::SimpleValueType> vts,
  884. ArrayRef<unsigned> operands,
  885. bool hasChain, bool hasInFlag, bool hasOutFlag,
  886. bool hasmemrefs,
  887. int numfixedarityoperands, unsigned firstresultslot)
  888. : EmitNodeMatcherCommon(opcodeName, vts, operands, hasChain,
  889. hasInFlag, hasOutFlag, hasmemrefs,
  890. numfixedarityoperands, false),
  891. FirstResultSlot(firstresultslot) {}
  892. unsigned getFirstResultSlot() const { return FirstResultSlot; }
  893. static inline bool classof(const Matcher *N) {
  894. return N->getKind() == EmitNode;
  895. }
  896. };
  897. class MorphNodeToMatcher : public EmitNodeMatcherCommon {
  898. void anchor() override;
  899. const PatternToMatch &Pattern;
  900. public:
  901. MorphNodeToMatcher(const std::string &opcodeName,
  902. ArrayRef<MVT::SimpleValueType> vts,
  903. ArrayRef<unsigned> operands,
  904. bool hasChain, bool hasInFlag, bool hasOutFlag,
  905. bool hasmemrefs,
  906. int numfixedarityoperands, const PatternToMatch &pattern)
  907. : EmitNodeMatcherCommon(opcodeName, vts, operands, hasChain,
  908. hasInFlag, hasOutFlag, hasmemrefs,
  909. numfixedarityoperands, true),
  910. Pattern(pattern) {
  911. }
  912. const PatternToMatch &getPattern() const { return Pattern; }
  913. static inline bool classof(const Matcher *N) {
  914. return N->getKind() == MorphNodeTo;
  915. }
  916. };
  917. /// MarkGlueResultsMatcher - This node indicates which non-root nodes in the
  918. /// pattern produce glue. This allows CompleteMatchMatcher to update them
  919. /// with the output glue of the resultant code.
  920. class MarkGlueResultsMatcher : public Matcher {
  921. SmallVector<unsigned, 3> GlueResultNodes;
  922. public:
  923. MarkGlueResultsMatcher(ArrayRef<unsigned> nodes)
  924. : Matcher(MarkGlueResults), GlueResultNodes(nodes.begin(), nodes.end()) {}
  925. unsigned getNumNodes() const { return GlueResultNodes.size(); }
  926. unsigned getNode(unsigned i) const {
  927. assert(i < GlueResultNodes.size());
  928. return GlueResultNodes[i];
  929. }
  930. static inline bool classof(const Matcher *N) {
  931. return N->getKind() == MarkGlueResults;
  932. }
  933. private:
  934. void printImpl(raw_ostream &OS, unsigned indent) const override;
  935. bool isEqualImpl(const Matcher *M) const override {
  936. return cast<MarkGlueResultsMatcher>(M)->GlueResultNodes == GlueResultNodes;
  937. }
  938. unsigned getHashImpl() const override;
  939. };
  940. /// CompleteMatchMatcher - Complete a match by replacing the results of the
  941. /// pattern with the newly generated nodes. This also prints a comment
  942. /// indicating the source and dest patterns.
  943. class CompleteMatchMatcher : public Matcher {
  944. SmallVector<unsigned, 2> Results;
  945. const PatternToMatch &Pattern;
  946. public:
  947. CompleteMatchMatcher(ArrayRef<unsigned> results,
  948. const PatternToMatch &pattern)
  949. : Matcher(CompleteMatch), Results(results.begin(), results.end()),
  950. Pattern(pattern) {}
  951. unsigned getNumResults() const { return Results.size(); }
  952. unsigned getResult(unsigned R) const { return Results[R]; }
  953. const PatternToMatch &getPattern() const { return Pattern; }
  954. static inline bool classof(const Matcher *N) {
  955. return N->getKind() == CompleteMatch;
  956. }
  957. private:
  958. void printImpl(raw_ostream &OS, unsigned indent) const override;
  959. bool isEqualImpl(const Matcher *M) const override {
  960. return cast<CompleteMatchMatcher>(M)->Results == Results &&
  961. &cast<CompleteMatchMatcher>(M)->Pattern == &Pattern;
  962. }
  963. unsigned getHashImpl() const override;
  964. };
  965. } // end namespace llvm
  966. #endif