Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / utils / TableGen / DAGISelMatcherEmitter.cpp
blob4a11991036efc1124ed2255a64f59e01192571b1
1 //===- DAGISelMatcherEmitter.cpp - Matcher Emitter ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains code to generate C++ code for a matcher.
11 //===----------------------------------------------------------------------===//
13 #include "CodeGenDAGPatterns.h"
14 #include "CodeGenInstruction.h"
15 #include "CodeGenRegisters.h"
16 #include "CodeGenTarget.h"
17 #include "DAGISelMatcher.h"
18 #include "SDNodeProperties.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/MapVector.h"
21 #include "llvm/ADT/StringMap.h"
22 #include "llvm/ADT/TinyPtrVector.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/Format.h"
25 #include "llvm/Support/SourceMgr.h"
26 #include "llvm/TableGen/Error.h"
27 #include "llvm/TableGen/Record.h"
29 using namespace llvm;
31 enum {
32 IndexWidth = 6,
33 FullIndexWidth = IndexWidth + 4,
34 HistOpcWidth = 40,
37 cl::OptionCategory DAGISelCat("Options for -gen-dag-isel");
39 // To reduce generated source code size.
40 static cl::opt<bool> OmitComments("omit-comments",
41 cl::desc("Do not generate comments"),
42 cl::init(false), cl::cat(DAGISelCat));
44 static cl::opt<bool> InstrumentCoverage(
45 "instrument-coverage",
46 cl::desc("Generates tables to help identify patterns matched"),
47 cl::init(false), cl::cat(DAGISelCat));
49 namespace {
50 class MatcherTableEmitter {
51 const CodeGenDAGPatterns &CGP;
53 SmallVector<unsigned, Matcher::HighestKind+1> OpcodeCounts;
55 DenseMap<TreePattern *, unsigned> NodePredicateMap;
56 std::vector<TreePredicateFn> NodePredicates;
57 std::vector<TreePredicateFn> NodePredicatesWithOperands;
59 // We de-duplicate the predicates by code string, and use this map to track
60 // all the patterns with "identical" predicates.
61 StringMap<TinyPtrVector<TreePattern *>> NodePredicatesByCodeToRun;
63 StringMap<unsigned> PatternPredicateMap;
64 std::vector<std::string> PatternPredicates;
66 DenseMap<const ComplexPattern*, unsigned> ComplexPatternMap;
67 std::vector<const ComplexPattern*> ComplexPatterns;
70 DenseMap<Record*, unsigned> NodeXFormMap;
71 std::vector<Record*> NodeXForms;
73 std::vector<std::string> VecIncludeStrings;
74 MapVector<std::string, unsigned, StringMap<unsigned> > VecPatterns;
76 unsigned getPatternIdxFromTable(std::string &&P, std::string &&include_loc) {
77 const auto It = VecPatterns.find(P);
78 if (It == VecPatterns.end()) {
79 VecPatterns.insert(make_pair(std::move(P), VecPatterns.size()));
80 VecIncludeStrings.push_back(std::move(include_loc));
81 return VecIncludeStrings.size() - 1;
83 return It->second;
86 public:
87 MatcherTableEmitter(const CodeGenDAGPatterns &cgp)
88 : CGP(cgp), OpcodeCounts(Matcher::HighestKind + 1, 0) {}
90 unsigned EmitMatcherList(const Matcher *N, const unsigned Indent,
91 unsigned StartIdx, raw_ostream &OS);
93 unsigned SizeMatcherList(Matcher *N, raw_ostream &OS);
95 void EmitPredicateFunctions(raw_ostream &OS);
97 void EmitHistogram(const Matcher *N, raw_ostream &OS);
99 void EmitPatternMatchTable(raw_ostream &OS);
101 private:
102 void EmitNodePredicatesFunction(const std::vector<TreePredicateFn> &Preds,
103 StringRef Decl, raw_ostream &OS);
105 unsigned SizeMatcher(Matcher *N, raw_ostream &OS);
107 unsigned EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
108 raw_ostream &OS);
110 unsigned getNodePredicate(TreePredicateFn Pred) {
111 TreePattern *TP = Pred.getOrigPatFragRecord();
112 unsigned &Entry = NodePredicateMap[TP];
113 if (Entry == 0) {
114 TinyPtrVector<TreePattern *> &SameCodePreds =
115 NodePredicatesByCodeToRun[Pred.getCodeToRunOnSDNode()];
116 if (SameCodePreds.empty()) {
117 // We've never seen a predicate with the same code: allocate an entry.
118 if (Pred.usesOperands()) {
119 NodePredicatesWithOperands.push_back(Pred);
120 Entry = NodePredicatesWithOperands.size();
121 } else {
122 NodePredicates.push_back(Pred);
123 Entry = NodePredicates.size();
125 } else {
126 // We did see an identical predicate: re-use it.
127 Entry = NodePredicateMap[SameCodePreds.front()];
128 assert(Entry != 0);
129 assert(TreePredicateFn(SameCodePreds.front()).usesOperands() ==
130 Pred.usesOperands() &&
131 "PatFrags with some code must have same usesOperands setting");
133 // In both cases, we've never seen this particular predicate before, so
134 // mark it in the list of predicates sharing the same code.
135 SameCodePreds.push_back(TP);
137 return Entry-1;
140 unsigned getPatternPredicate(StringRef PredName) {
141 unsigned &Entry = PatternPredicateMap[PredName];
142 if (Entry == 0) {
143 PatternPredicates.push_back(PredName.str());
144 Entry = PatternPredicates.size();
146 return Entry-1;
148 unsigned getComplexPat(const ComplexPattern &P) {
149 unsigned &Entry = ComplexPatternMap[&P];
150 if (Entry == 0) {
151 ComplexPatterns.push_back(&P);
152 Entry = ComplexPatterns.size();
154 return Entry-1;
157 unsigned getNodeXFormID(Record *Rec) {
158 unsigned &Entry = NodeXFormMap[Rec];
159 if (Entry == 0) {
160 NodeXForms.push_back(Rec);
161 Entry = NodeXForms.size();
163 return Entry-1;
167 } // end anonymous namespace.
169 static std::string GetPatFromTreePatternNode(const TreePatternNode *N) {
170 std::string str;
171 raw_string_ostream Stream(str);
172 Stream << *N;
173 return str;
176 static unsigned GetVBRSize(unsigned Val) {
177 if (Val <= 127) return 1;
179 unsigned NumBytes = 0;
180 while (Val >= 128) {
181 Val >>= 7;
182 ++NumBytes;
184 return NumBytes+1;
187 /// EmitVBRValue - Emit the specified value as a VBR, returning the number of
188 /// bytes emitted.
189 static unsigned EmitVBRValue(uint64_t Val, raw_ostream &OS) {
190 if (Val <= 127) {
191 OS << Val << ", ";
192 return 1;
195 uint64_t InVal = Val;
196 unsigned NumBytes = 0;
197 while (Val >= 128) {
198 OS << (Val&127) << "|128,";
199 Val >>= 7;
200 ++NumBytes;
202 OS << Val;
203 if (!OmitComments)
204 OS << "/*" << InVal << "*/";
205 OS << ", ";
206 return NumBytes+1;
209 /// Emit the specified signed value as a VBR. To improve compression we encode
210 /// positive numbers shifted left by 1 and negative numbers negated and shifted
211 /// left by 1 with bit 0 set.
212 static unsigned EmitSignedVBRValue(uint64_t Val, raw_ostream &OS) {
213 if ((int64_t)Val >= 0)
214 Val = Val << 1;
215 else
216 Val = (-Val << 1) | 1;
218 return EmitVBRValue(Val, OS);
221 // This is expensive and slow.
222 static std::string getIncludePath(const Record *R) {
223 std::string str;
224 raw_string_ostream Stream(str);
225 auto Locs = R->getLoc();
226 SMLoc L;
227 if (Locs.size() > 1) {
228 // Get where the pattern prototype was instantiated
229 L = Locs[1];
230 } else if (Locs.size() == 1) {
231 L = Locs[0];
233 unsigned CurBuf = SrcMgr.FindBufferContainingLoc(L);
234 assert(CurBuf && "Invalid or unspecified location!");
236 Stream << SrcMgr.getBufferInfo(CurBuf).Buffer->getBufferIdentifier() << ":"
237 << SrcMgr.FindLineNumber(L, CurBuf);
238 return str;
241 /// This function traverses the matcher tree and sizes all the nodes
242 /// that are children of the three kinds of nodes that have them.
243 unsigned MatcherTableEmitter::
244 SizeMatcherList(Matcher *N, raw_ostream &OS) {
245 unsigned Size = 0;
246 while (N) {
247 Size += SizeMatcher(N, OS);
248 N = N->getNext();
250 return Size;
253 /// This function sizes the children of the three kinds of nodes that
254 /// have them. It does so by using special cases for those three
255 /// nodes, but sharing the code in EmitMatcher() for the other kinds.
256 unsigned MatcherTableEmitter::
257 SizeMatcher(Matcher *N, raw_ostream &OS) {
258 unsigned Idx = 0;
260 ++OpcodeCounts[N->getKind()];
261 switch (N->getKind()) {
262 // The Scope matcher has its kind, a series of child size + child,
263 // and a trailing zero.
264 case Matcher::Scope: {
265 ScopeMatcher *SM = cast<ScopeMatcher>(N);
266 assert(SM->getNext() == nullptr && "Scope matcher should not have next");
267 unsigned Size = 1; // Count the kind.
268 for (unsigned i = 0, e = SM->getNumChildren(); i != e; ++i) {
269 const unsigned ChildSize = SizeMatcherList(SM->getChild(i), OS);
270 assert(ChildSize != 0 && "Matcher cannot have child of size 0");
271 SM->getChild(i)->setSize(ChildSize);
272 Size += GetVBRSize(ChildSize) + ChildSize; // Count VBR and child size.
274 ++Size; // Count the zero sentinel.
275 return Size;
278 // SwitchOpcode and SwitchType have their kind, a series of child size +
279 // opcode/type + child, and a trailing zero.
280 case Matcher::SwitchOpcode:
281 case Matcher::SwitchType: {
282 unsigned Size = 1; // Count the kind.
283 unsigned NumCases;
284 if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(N))
285 NumCases = SOM->getNumCases();
286 else
287 NumCases = cast<SwitchTypeMatcher>(N)->getNumCases();
288 for (unsigned i = 0, e = NumCases; i != e; ++i) {
289 Matcher *Child;
290 if (SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(N)) {
291 Child = SOM->getCaseMatcher(i);
292 Size += 2; // Count the child's opcode.
293 } else {
294 Child = cast<SwitchTypeMatcher>(N)->getCaseMatcher(i);
295 ++Size; // Count the child's type.
297 const unsigned ChildSize = SizeMatcherList(Child, OS);
298 assert(ChildSize != 0 && "Matcher cannot have child of size 0");
299 Child->setSize(ChildSize);
300 Size += GetVBRSize(ChildSize) + ChildSize; // Count VBR and child size.
302 ++Size; // Count the zero sentinel.
303 return Size;
306 default:
307 // Employ the matcher emitter to size other matchers.
308 return EmitMatcher(N, 0, Idx, OS);
310 llvm_unreachable("Unreachable");
313 static void BeginEmitFunction(raw_ostream &OS, StringRef RetType,
314 StringRef Decl, bool AddOverride) {
315 OS << "#ifdef GET_DAGISEL_DECL\n";
316 OS << RetType << ' ' << Decl;
317 if (AddOverride)
318 OS << " override";
319 OS << ";\n"
320 "#endif\n"
321 "#if defined(GET_DAGISEL_BODY) || DAGISEL_INLINE\n";
322 OS << RetType << " DAGISEL_CLASS_COLONCOLON " << Decl << "\n";
323 if (AddOverride) {
324 OS << "#if DAGISEL_INLINE\n"
325 " override\n"
326 "#endif\n";
330 static void EndEmitFunction(raw_ostream &OS) {
331 OS << "#endif // GET_DAGISEL_BODY\n\n";
334 void MatcherTableEmitter::EmitPatternMatchTable(raw_ostream &OS) {
336 assert(isUInt<16>(VecPatterns.size()) &&
337 "Using only 16 bits to encode offset into Pattern Table");
338 assert(VecPatterns.size() == VecIncludeStrings.size() &&
339 "The sizes of Pattern and include vectors should be the same");
341 BeginEmitFunction(OS, "StringRef", "getPatternForIndex(unsigned Index)",
342 true/*AddOverride*/);
343 OS << "{\n";
344 OS << "static const char *PATTERN_MATCH_TABLE[] = {\n";
346 for (const auto &It : VecPatterns) {
347 OS << "\"" << It.first << "\",\n";
350 OS << "\n};";
351 OS << "\nreturn StringRef(PATTERN_MATCH_TABLE[Index]);";
352 OS << "\n}\n";
353 EndEmitFunction(OS);
355 BeginEmitFunction(OS, "StringRef", "getIncludePathForIndex(unsigned Index)",
356 true/*AddOverride*/);
357 OS << "{\n";
358 OS << "static const char *INCLUDE_PATH_TABLE[] = {\n";
360 for (const auto &It : VecIncludeStrings) {
361 OS << "\"" << It << "\",\n";
364 OS << "\n};";
365 OS << "\nreturn StringRef(INCLUDE_PATH_TABLE[Index]);";
366 OS << "\n}\n";
367 EndEmitFunction(OS);
370 /// EmitMatcher - Emit bytes for the specified matcher and return
371 /// the number of bytes emitted.
372 unsigned MatcherTableEmitter::
373 EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
374 raw_ostream &OS) {
375 OS.indent(Indent);
377 switch (N->getKind()) {
378 case Matcher::Scope: {
379 const ScopeMatcher *SM = cast<ScopeMatcher>(N);
380 unsigned StartIdx = CurrentIdx;
382 // Emit all of the children.
383 for (unsigned i = 0, e = SM->getNumChildren(); i != e; ++i) {
384 if (i == 0) {
385 OS << "OPC_Scope, ";
386 ++CurrentIdx;
387 } else {
388 if (!OmitComments) {
389 OS << "/*" << format_decimal(CurrentIdx, IndexWidth) << "*/";
390 OS.indent(Indent) << "/*Scope*/ ";
391 } else
392 OS.indent(Indent);
395 unsigned ChildSize = SM->getChild(i)->getSize();
396 unsigned VBRSize = EmitVBRValue(ChildSize, OS);
397 if (!OmitComments) {
398 OS << "/*->" << CurrentIdx + VBRSize + ChildSize << "*/";
399 if (i == 0)
400 OS << " // " << SM->getNumChildren() << " children in Scope";
402 OS << '\n';
404 ChildSize = EmitMatcherList(SM->getChild(i), Indent+1,
405 CurrentIdx + VBRSize, OS);
406 assert(ChildSize == SM->getChild(i)->getSize() &&
407 "Emitted child size does not match calculated size");
408 CurrentIdx += VBRSize + ChildSize;
411 // Emit a zero as a sentinel indicating end of 'Scope'.
412 if (!OmitComments)
413 OS << "/*" << format_decimal(CurrentIdx, IndexWidth) << "*/";
414 OS.indent(Indent) << "0, ";
415 if (!OmitComments)
416 OS << "/*End of Scope*/";
417 OS << '\n';
418 return CurrentIdx - StartIdx + 1;
421 case Matcher::RecordNode:
422 OS << "OPC_RecordNode,";
423 if (!OmitComments)
424 OS << " // #"
425 << cast<RecordMatcher>(N)->getResultNo() << " = "
426 << cast<RecordMatcher>(N)->getWhatFor();
427 OS << '\n';
428 return 1;
430 case Matcher::RecordChild:
431 OS << "OPC_RecordChild" << cast<RecordChildMatcher>(N)->getChildNo()
432 << ',';
433 if (!OmitComments)
434 OS << " // #"
435 << cast<RecordChildMatcher>(N)->getResultNo() << " = "
436 << cast<RecordChildMatcher>(N)->getWhatFor();
437 OS << '\n';
438 return 1;
440 case Matcher::RecordMemRef:
441 OS << "OPC_RecordMemRef,\n";
442 return 1;
444 case Matcher::CaptureGlueInput:
445 OS << "OPC_CaptureGlueInput,\n";
446 return 1;
448 case Matcher::MoveChild: {
449 const auto *MCM = cast<MoveChildMatcher>(N);
451 OS << "OPC_MoveChild";
452 // Handle the specialized forms.
453 if (MCM->getChildNo() >= 8)
454 OS << ", ";
455 OS << MCM->getChildNo() << ",\n";
456 return (MCM->getChildNo() >= 8) ? 2 : 1;
459 case Matcher::MoveParent:
460 OS << "OPC_MoveParent,\n";
461 return 1;
463 case Matcher::CheckSame:
464 OS << "OPC_CheckSame, "
465 << cast<CheckSameMatcher>(N)->getMatchNumber() << ",\n";
466 return 2;
468 case Matcher::CheckChildSame:
469 OS << "OPC_CheckChild"
470 << cast<CheckChildSameMatcher>(N)->getChildNo() << "Same, "
471 << cast<CheckChildSameMatcher>(N)->getMatchNumber() << ",\n";
472 return 2;
474 case Matcher::CheckPatternPredicate: {
475 StringRef Pred = cast<CheckPatternPredicateMatcher>(N)->getPredicate();
476 unsigned PredNo = getPatternPredicate(Pred);
477 if (PredNo > 255)
478 OS << "OPC_CheckPatternPredicate2, TARGET_VAL(" << PredNo << "),";
479 else
480 OS << "OPC_CheckPatternPredicate, " << PredNo << ',';
481 if (!OmitComments)
482 OS << " // " << Pred;
483 OS << '\n';
484 return 2 + (PredNo > 255);
486 case Matcher::CheckPredicate: {
487 TreePredicateFn Pred = cast<CheckPredicateMatcher>(N)->getPredicate();
488 unsigned OperandBytes = 0;
490 if (Pred.usesOperands()) {
491 unsigned NumOps = cast<CheckPredicateMatcher>(N)->getNumOperands();
492 OS << "OPC_CheckPredicateWithOperands, " << NumOps << "/*#Ops*/, ";
493 for (unsigned i = 0; i < NumOps; ++i)
494 OS << cast<CheckPredicateMatcher>(N)->getOperandNo(i) << ", ";
495 OperandBytes = 1 + NumOps;
496 } else {
497 OS << "OPC_CheckPredicate, ";
500 OS << getNodePredicate(Pred) << ',';
501 if (!OmitComments)
502 OS << " // " << Pred.getFnName();
503 OS << '\n';
504 return 2 + OperandBytes;
507 case Matcher::CheckOpcode:
508 OS << "OPC_CheckOpcode, TARGET_VAL("
509 << cast<CheckOpcodeMatcher>(N)->getOpcode().getEnumName() << "),\n";
510 return 3;
512 case Matcher::SwitchOpcode:
513 case Matcher::SwitchType: {
514 unsigned StartIdx = CurrentIdx;
516 unsigned NumCases;
517 if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(N)) {
518 OS << "OPC_SwitchOpcode ";
519 NumCases = SOM->getNumCases();
520 } else {
521 OS << "OPC_SwitchType ";
522 NumCases = cast<SwitchTypeMatcher>(N)->getNumCases();
525 if (!OmitComments)
526 OS << "/*" << NumCases << " cases */";
527 OS << ", ";
528 ++CurrentIdx;
530 // For each case we emit the size, then the opcode, then the matcher.
531 for (unsigned i = 0, e = NumCases; i != e; ++i) {
532 const Matcher *Child;
533 unsigned IdxSize;
534 if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(N)) {
535 Child = SOM->getCaseMatcher(i);
536 IdxSize = 2; // size of opcode in table is 2 bytes.
537 } else {
538 Child = cast<SwitchTypeMatcher>(N)->getCaseMatcher(i);
539 IdxSize = 1; // size of type in table is 1 byte.
542 if (i != 0) {
543 if (!OmitComments)
544 OS << "/*" << format_decimal(CurrentIdx, IndexWidth) << "*/";
545 OS.indent(Indent);
546 if (!OmitComments)
547 OS << (isa<SwitchOpcodeMatcher>(N) ?
548 "/*SwitchOpcode*/ " : "/*SwitchType*/ ");
551 unsigned ChildSize = Child->getSize();
552 CurrentIdx += EmitVBRValue(ChildSize, OS) + IdxSize;
553 if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(N))
554 OS << "TARGET_VAL(" << SOM->getCaseOpcode(i).getEnumName() << "),";
555 else
556 OS << getEnumName(cast<SwitchTypeMatcher>(N)->getCaseType(i)) << ',';
557 if (!OmitComments)
558 OS << "// ->" << CurrentIdx + ChildSize;
559 OS << '\n';
561 ChildSize = EmitMatcherList(Child, Indent+1, CurrentIdx, OS);
562 assert(ChildSize == Child->getSize() &&
563 "Emitted child size does not match calculated size");
564 CurrentIdx += ChildSize;
567 // Emit the final zero to terminate the switch.
568 if (!OmitComments)
569 OS << "/*" << format_decimal(CurrentIdx, IndexWidth) << "*/";
570 OS.indent(Indent) << "0,";
571 if (!OmitComments)
572 OS << (isa<SwitchOpcodeMatcher>(N) ?
573 " // EndSwitchOpcode" : " // EndSwitchType");
575 OS << '\n';
576 return CurrentIdx - StartIdx + 1;
579 case Matcher::CheckType:
580 if (cast<CheckTypeMatcher>(N)->getResNo() == 0) {
581 OS << "OPC_CheckType, "
582 << getEnumName(cast<CheckTypeMatcher>(N)->getType()) << ",\n";
583 return 2;
585 OS << "OPC_CheckTypeRes, " << cast<CheckTypeMatcher>(N)->getResNo()
586 << ", " << getEnumName(cast<CheckTypeMatcher>(N)->getType()) << ",\n";
587 return 3;
589 case Matcher::CheckChildType:
590 OS << "OPC_CheckChild"
591 << cast<CheckChildTypeMatcher>(N)->getChildNo() << "Type, "
592 << getEnumName(cast<CheckChildTypeMatcher>(N)->getType()) << ",\n";
593 return 2;
595 case Matcher::CheckInteger: {
596 OS << "OPC_CheckInteger, ";
597 unsigned Bytes =
598 1 + EmitSignedVBRValue(cast<CheckIntegerMatcher>(N)->getValue(), OS);
599 OS << '\n';
600 return Bytes;
602 case Matcher::CheckChildInteger: {
603 OS << "OPC_CheckChild" << cast<CheckChildIntegerMatcher>(N)->getChildNo()
604 << "Integer, ";
605 unsigned Bytes = 1 + EmitSignedVBRValue(
606 cast<CheckChildIntegerMatcher>(N)->getValue(), OS);
607 OS << '\n';
608 return Bytes;
610 case Matcher::CheckCondCode:
611 OS << "OPC_CheckCondCode, ISD::"
612 << cast<CheckCondCodeMatcher>(N)->getCondCodeName() << ",\n";
613 return 2;
615 case Matcher::CheckChild2CondCode:
616 OS << "OPC_CheckChild2CondCode, ISD::"
617 << cast<CheckChild2CondCodeMatcher>(N)->getCondCodeName() << ",\n";
618 return 2;
620 case Matcher::CheckValueType:
621 OS << "OPC_CheckValueType, MVT::"
622 << cast<CheckValueTypeMatcher>(N)->getTypeName() << ",\n";
623 return 2;
625 case Matcher::CheckComplexPat: {
626 const CheckComplexPatMatcher *CCPM = cast<CheckComplexPatMatcher>(N);
627 const ComplexPattern &Pattern = CCPM->getPattern();
628 OS << "OPC_CheckComplexPat, /*CP*/" << getComplexPat(Pattern) << ", /*#*/"
629 << CCPM->getMatchNumber() << ',';
631 if (!OmitComments) {
632 OS << " // " << Pattern.getSelectFunc();
633 OS << ":$" << CCPM->getName();
634 for (unsigned i = 0, e = Pattern.getNumOperands(); i != e; ++i)
635 OS << " #" << CCPM->getFirstResult()+i;
637 if (Pattern.hasProperty(SDNPHasChain))
638 OS << " + chain result";
640 OS << '\n';
641 return 3;
644 case Matcher::CheckAndImm: {
645 OS << "OPC_CheckAndImm, ";
646 unsigned Bytes=1+EmitVBRValue(cast<CheckAndImmMatcher>(N)->getValue(), OS);
647 OS << '\n';
648 return Bytes;
651 case Matcher::CheckOrImm: {
652 OS << "OPC_CheckOrImm, ";
653 unsigned Bytes = 1+EmitVBRValue(cast<CheckOrImmMatcher>(N)->getValue(), OS);
654 OS << '\n';
655 return Bytes;
658 case Matcher::CheckFoldableChainNode:
659 OS << "OPC_CheckFoldableChainNode,\n";
660 return 1;
662 case Matcher::CheckImmAllOnesV:
663 OS << "OPC_CheckImmAllOnesV,\n";
664 return 1;
666 case Matcher::CheckImmAllZerosV:
667 OS << "OPC_CheckImmAllZerosV,\n";
668 return 1;
670 case Matcher::EmitInteger: {
671 int64_t Val = cast<EmitIntegerMatcher>(N)->getValue();
672 OS << "OPC_EmitInteger, "
673 << getEnumName(cast<EmitIntegerMatcher>(N)->getVT()) << ", ";
674 unsigned Bytes = 2 + EmitSignedVBRValue(Val, OS);
675 OS << '\n';
676 return Bytes;
678 case Matcher::EmitStringInteger: {
679 const std::string &Val = cast<EmitStringIntegerMatcher>(N)->getValue();
680 // These should always fit into 7 bits.
681 OS << "OPC_EmitStringInteger, "
682 << getEnumName(cast<EmitStringIntegerMatcher>(N)->getVT()) << ", " << Val
683 << ",\n";
684 return 3;
687 case Matcher::EmitRegister: {
688 const EmitRegisterMatcher *Matcher = cast<EmitRegisterMatcher>(N);
689 const CodeGenRegister *Reg = Matcher->getReg();
690 // If the enum value of the register is larger than one byte can handle,
691 // use EmitRegister2.
692 if (Reg && Reg->EnumValue > 255) {
693 OS << "OPC_EmitRegister2, " << getEnumName(Matcher->getVT()) << ", ";
694 OS << "TARGET_VAL(" << getQualifiedName(Reg->TheDef) << "),\n";
695 return 4;
696 } else {
697 OS << "OPC_EmitRegister, " << getEnumName(Matcher->getVT()) << ", ";
698 if (Reg) {
699 OS << getQualifiedName(Reg->TheDef) << ",\n";
700 } else {
701 OS << "0 ";
702 if (!OmitComments)
703 OS << "/*zero_reg*/";
704 OS << ",\n";
706 return 3;
710 case Matcher::EmitConvertToTarget:
711 OS << "OPC_EmitConvertToTarget, "
712 << cast<EmitConvertToTargetMatcher>(N)->getSlot() << ",\n";
713 return 2;
715 case Matcher::EmitMergeInputChains: {
716 const EmitMergeInputChainsMatcher *MN =
717 cast<EmitMergeInputChainsMatcher>(N);
719 // Handle the specialized forms OPC_EmitMergeInputChains1_0, 1_1, and 1_2.
720 if (MN->getNumNodes() == 1 && MN->getNode(0) < 3) {
721 OS << "OPC_EmitMergeInputChains1_" << MN->getNode(0) << ",\n";
722 return 1;
725 OS << "OPC_EmitMergeInputChains, " << MN->getNumNodes() << ", ";
726 for (unsigned i = 0, e = MN->getNumNodes(); i != e; ++i)
727 OS << MN->getNode(i) << ", ";
728 OS << '\n';
729 return 2+MN->getNumNodes();
731 case Matcher::EmitCopyToReg: {
732 const auto *C2RMatcher = cast<EmitCopyToRegMatcher>(N);
733 int Bytes = 3;
734 const CodeGenRegister *Reg = C2RMatcher->getDestPhysReg();
735 if (Reg->EnumValue > 255) {
736 assert(isUInt<16>(Reg->EnumValue) && "not handled");
737 OS << "OPC_EmitCopyToReg2, " << C2RMatcher->getSrcSlot() << ", "
738 << "TARGET_VAL(" << getQualifiedName(Reg->TheDef) << "),\n";
739 ++Bytes;
740 } else {
741 OS << "OPC_EmitCopyToReg, " << C2RMatcher->getSrcSlot() << ", "
742 << getQualifiedName(Reg->TheDef) << ",\n";
745 return Bytes;
747 case Matcher::EmitNodeXForm: {
748 const EmitNodeXFormMatcher *XF = cast<EmitNodeXFormMatcher>(N);
749 OS << "OPC_EmitNodeXForm, " << getNodeXFormID(XF->getNodeXForm()) << ", "
750 << XF->getSlot() << ',';
751 if (!OmitComments)
752 OS << " // "<<XF->getNodeXForm()->getName();
753 OS <<'\n';
754 return 3;
757 case Matcher::EmitNode:
758 case Matcher::MorphNodeTo: {
759 auto NumCoveredBytes = 0;
760 if (InstrumentCoverage) {
761 if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(N)) {
762 NumCoveredBytes = 3;
763 OS << "OPC_Coverage, ";
764 std::string src =
765 GetPatFromTreePatternNode(SNT->getPattern().getSrcPattern());
766 std::string dst =
767 GetPatFromTreePatternNode(SNT->getPattern().getDstPattern());
768 Record *PatRecord = SNT->getPattern().getSrcRecord();
769 std::string include_src = getIncludePath(PatRecord);
770 unsigned Offset =
771 getPatternIdxFromTable(src + " -> " + dst, std::move(include_src));
772 OS << "TARGET_VAL(" << Offset << "),\n";
773 OS.indent(FullIndexWidth + Indent);
776 const EmitNodeMatcherCommon *EN = cast<EmitNodeMatcherCommon>(N);
777 OS << (isa<EmitNodeMatcher>(EN) ? "OPC_EmitNode" : "OPC_MorphNodeTo");
778 bool CompressVTs = EN->getNumVTs() < 3;
779 if (CompressVTs)
780 OS << EN->getNumVTs();
782 const CodeGenInstruction &CGI = EN->getInstruction();
783 OS << ", TARGET_VAL(" << CGI.Namespace << "::" << CGI.TheDef->getName()
784 << "), 0";
786 if (EN->hasChain()) OS << "|OPFL_Chain";
787 if (EN->hasInGlue()) OS << "|OPFL_GlueInput";
788 if (EN->hasOutGlue()) OS << "|OPFL_GlueOutput";
789 if (EN->hasMemRefs()) OS << "|OPFL_MemRefs";
790 if (EN->getNumFixedArityOperands() != -1)
791 OS << "|OPFL_Variadic" << EN->getNumFixedArityOperands();
792 OS << ",\n";
794 OS.indent(FullIndexWidth + Indent+4);
795 if (!CompressVTs) {
796 OS << EN->getNumVTs();
797 if (!OmitComments)
798 OS << "/*#VTs*/";
799 OS << ", ";
801 for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i)
802 OS << getEnumName(EN->getVT(i)) << ", ";
804 OS << EN->getNumOperands();
805 if (!OmitComments)
806 OS << "/*#Ops*/";
807 OS << ", ";
808 unsigned NumOperandBytes = 0;
809 for (unsigned i = 0, e = EN->getNumOperands(); i != e; ++i)
810 NumOperandBytes += EmitVBRValue(EN->getOperand(i), OS);
812 if (!OmitComments) {
813 // Print the result #'s for EmitNode.
814 if (const EmitNodeMatcher *E = dyn_cast<EmitNodeMatcher>(EN)) {
815 if (unsigned NumResults = EN->getNumVTs()) {
816 OS << " // Results =";
817 unsigned First = E->getFirstResultSlot();
818 for (unsigned i = 0; i != NumResults; ++i)
819 OS << " #" << First+i;
822 OS << '\n';
824 if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(N)) {
825 OS.indent(FullIndexWidth + Indent) << "// Src: "
826 << *SNT->getPattern().getSrcPattern() << " - Complexity = "
827 << SNT->getPattern().getPatternComplexity(CGP) << '\n';
828 OS.indent(FullIndexWidth + Indent) << "// Dst: "
829 << *SNT->getPattern().getDstPattern() << '\n';
831 } else
832 OS << '\n';
834 return 5 + !CompressVTs + EN->getNumVTs() + NumOperandBytes +
835 NumCoveredBytes;
837 case Matcher::CompleteMatch: {
838 const CompleteMatchMatcher *CM = cast<CompleteMatchMatcher>(N);
839 auto NumCoveredBytes = 0;
840 if (InstrumentCoverage) {
841 NumCoveredBytes = 3;
842 OS << "OPC_Coverage, ";
843 std::string src =
844 GetPatFromTreePatternNode(CM->getPattern().getSrcPattern());
845 std::string dst =
846 GetPatFromTreePatternNode(CM->getPattern().getDstPattern());
847 Record *PatRecord = CM->getPattern().getSrcRecord();
848 std::string include_src = getIncludePath(PatRecord);
849 unsigned Offset =
850 getPatternIdxFromTable(src + " -> " + dst, std::move(include_src));
851 OS << "TARGET_VAL(" << Offset << "),\n";
852 OS.indent(FullIndexWidth + Indent);
854 OS << "OPC_CompleteMatch, " << CM->getNumResults() << ", ";
855 unsigned NumResultBytes = 0;
856 for (unsigned i = 0, e = CM->getNumResults(); i != e; ++i)
857 NumResultBytes += EmitVBRValue(CM->getResult(i), OS);
858 OS << '\n';
859 if (!OmitComments) {
860 OS.indent(FullIndexWidth + Indent) << " // Src: "
861 << *CM->getPattern().getSrcPattern() << " - Complexity = "
862 << CM->getPattern().getPatternComplexity(CGP) << '\n';
863 OS.indent(FullIndexWidth + Indent) << " // Dst: "
864 << *CM->getPattern().getDstPattern();
866 OS << '\n';
867 return 2 + NumResultBytes + NumCoveredBytes;
870 llvm_unreachable("Unreachable");
873 /// This function traverses the matcher tree and emits all the nodes.
874 /// The nodes have already been sized.
875 unsigned MatcherTableEmitter::
876 EmitMatcherList(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,
877 raw_ostream &OS) {
878 unsigned Size = 0;
879 while (N) {
880 if (!OmitComments)
881 OS << "/*" << format_decimal(CurrentIdx, IndexWidth) << "*/";
882 unsigned MatcherSize = EmitMatcher(N, Indent, CurrentIdx, OS);
883 Size += MatcherSize;
884 CurrentIdx += MatcherSize;
886 // If there are other nodes in this list, iterate to them, otherwise we're
887 // done.
888 N = N->getNext();
890 return Size;
893 void MatcherTableEmitter::EmitNodePredicatesFunction(
894 const std::vector<TreePredicateFn> &Preds, StringRef Decl,
895 raw_ostream &OS) {
896 if (Preds.empty())
897 return;
899 BeginEmitFunction(OS, "bool", Decl, true/*AddOverride*/);
900 OS << "{\n";
901 OS << " switch (PredNo) {\n";
902 OS << " default: llvm_unreachable(\"Invalid predicate in table?\");\n";
903 for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
904 // Emit the predicate code corresponding to this pattern.
905 const TreePredicateFn PredFn = Preds[i];
906 assert(!PredFn.isAlwaysTrue() && "No code in this predicate");
907 std::string PredFnCodeStr = PredFn.getCodeToRunOnSDNode();
909 OS << " case " << i << ": {\n";
910 for (auto *SimilarPred : NodePredicatesByCodeToRun[PredFnCodeStr])
911 OS << " // " << TreePredicateFn(SimilarPred).getFnName() << '\n';
912 OS << PredFnCodeStr << "\n }\n";
914 OS << " }\n";
915 OS << "}\n";
916 EndEmitFunction(OS);
919 void MatcherTableEmitter::EmitPredicateFunctions(raw_ostream &OS) {
920 // Emit pattern predicates.
921 if (!PatternPredicates.empty()) {
922 BeginEmitFunction(OS, "bool",
923 "CheckPatternPredicate(unsigned PredNo) const", true/*AddOverride*/);
924 OS << "{\n";
925 OS << " switch (PredNo) {\n";
926 OS << " default: llvm_unreachable(\"Invalid predicate in table?\");\n";
927 for (unsigned i = 0, e = PatternPredicates.size(); i != e; ++i)
928 OS << " case " << i << ": return " << PatternPredicates[i] << ";\n";
929 OS << " }\n";
930 OS << "}\n";
931 EndEmitFunction(OS);
934 // Emit Node predicates.
935 EmitNodePredicatesFunction(
936 NodePredicates, "CheckNodePredicate(SDNode *Node, unsigned PredNo) const",
937 OS);
938 EmitNodePredicatesFunction(
939 NodePredicatesWithOperands,
940 "CheckNodePredicateWithOperands(SDNode *Node, unsigned PredNo, "
941 "const SmallVectorImpl<SDValue> &Operands) const",
942 OS);
944 // Emit CompletePattern matchers.
945 // FIXME: This should be const.
946 if (!ComplexPatterns.empty()) {
947 BeginEmitFunction(OS, "bool",
948 "CheckComplexPattern(SDNode *Root, SDNode *Parent,\n"
949 " SDValue N, unsigned PatternNo,\n"
950 " SmallVectorImpl<std::pair<SDValue, SDNode *>> &Result)",
951 true/*AddOverride*/);
952 OS << "{\n";
953 OS << " unsigned NextRes = Result.size();\n";
954 OS << " switch (PatternNo) {\n";
955 OS << " default: llvm_unreachable(\"Invalid pattern # in table?\");\n";
956 for (unsigned i = 0, e = ComplexPatterns.size(); i != e; ++i) {
957 const ComplexPattern &P = *ComplexPatterns[i];
958 unsigned NumOps = P.getNumOperands();
960 if (P.hasProperty(SDNPHasChain))
961 ++NumOps; // Get the chained node too.
963 OS << " case " << i << ":\n";
964 if (InstrumentCoverage)
965 OS << " {\n";
966 OS << " Result.resize(NextRes+" << NumOps << ");\n";
967 if (InstrumentCoverage)
968 OS << " bool Succeeded = " << P.getSelectFunc();
969 else
970 OS << " return " << P.getSelectFunc();
972 OS << "(";
973 // If the complex pattern wants the root of the match, pass it in as the
974 // first argument.
975 if (P.hasProperty(SDNPWantRoot))
976 OS << "Root, ";
978 // If the complex pattern wants the parent of the operand being matched,
979 // pass it in as the next argument.
980 if (P.hasProperty(SDNPWantParent))
981 OS << "Parent, ";
983 OS << "N";
984 for (unsigned i = 0; i != NumOps; ++i)
985 OS << ", Result[NextRes+" << i << "].first";
986 OS << ");\n";
987 if (InstrumentCoverage) {
988 OS << " if (Succeeded)\n";
989 OS << " dbgs() << \"\\nCOMPLEX_PATTERN: " << P.getSelectFunc()
990 << "\\n\" ;\n";
991 OS << " return Succeeded;\n";
992 OS << " }\n";
995 OS << " }\n";
996 OS << "}\n";
997 EndEmitFunction(OS);
1001 // Emit SDNodeXForm handlers.
1002 // FIXME: This should be const.
1003 if (!NodeXForms.empty()) {
1004 BeginEmitFunction(OS, "SDValue",
1005 "RunSDNodeXForm(SDValue V, unsigned XFormNo)", true/*AddOverride*/);
1006 OS << "{\n";
1007 OS << " switch (XFormNo) {\n";
1008 OS << " default: llvm_unreachable(\"Invalid xform # in table?\");\n";
1010 // FIXME: The node xform could take SDValue's instead of SDNode*'s.
1011 for (unsigned i = 0, e = NodeXForms.size(); i != e; ++i) {
1012 const CodeGenDAGPatterns::NodeXForm &Entry =
1013 CGP.getSDNodeTransform(NodeXForms[i]);
1015 Record *SDNode = Entry.first;
1016 const std::string &Code = Entry.second;
1018 OS << " case " << i << ": { ";
1019 if (!OmitComments)
1020 OS << "// " << NodeXForms[i]->getName();
1021 OS << '\n';
1023 std::string ClassName =
1024 std::string(CGP.getSDNodeInfo(SDNode).getSDClassName());
1025 if (ClassName == "SDNode")
1026 OS << " SDNode *N = V.getNode();\n";
1027 else
1028 OS << " " << ClassName << " *N = cast<" << ClassName
1029 << ">(V.getNode());\n";
1030 OS << Code << "\n }\n";
1032 OS << " }\n";
1033 OS << "}\n";
1034 EndEmitFunction(OS);
1038 static StringRef getOpcodeString(Matcher::KindTy Kind) {
1039 switch (Kind) {
1040 case Matcher::Scope: return "OPC_Scope"; break;
1041 case Matcher::RecordNode: return "OPC_RecordNode"; break;
1042 case Matcher::RecordChild: return "OPC_RecordChild"; break;
1043 case Matcher::RecordMemRef: return "OPC_RecordMemRef"; break;
1044 case Matcher::CaptureGlueInput: return "OPC_CaptureGlueInput"; break;
1045 case Matcher::MoveChild: return "OPC_MoveChild"; break;
1046 case Matcher::MoveParent: return "OPC_MoveParent"; break;
1047 case Matcher::CheckSame: return "OPC_CheckSame"; break;
1048 case Matcher::CheckChildSame: return "OPC_CheckChildSame"; break;
1049 case Matcher::CheckPatternPredicate:
1050 return "OPC_CheckPatternPredicate"; break;
1051 case Matcher::CheckPredicate: return "OPC_CheckPredicate"; break;
1052 case Matcher::CheckOpcode: return "OPC_CheckOpcode"; break;
1053 case Matcher::SwitchOpcode: return "OPC_SwitchOpcode"; break;
1054 case Matcher::CheckType: return "OPC_CheckType"; break;
1055 case Matcher::SwitchType: return "OPC_SwitchType"; break;
1056 case Matcher::CheckChildType: return "OPC_CheckChildType"; break;
1057 case Matcher::CheckInteger: return "OPC_CheckInteger"; break;
1058 case Matcher::CheckChildInteger: return "OPC_CheckChildInteger"; break;
1059 case Matcher::CheckCondCode: return "OPC_CheckCondCode"; break;
1060 case Matcher::CheckChild2CondCode: return "OPC_CheckChild2CondCode"; break;
1061 case Matcher::CheckValueType: return "OPC_CheckValueType"; break;
1062 case Matcher::CheckComplexPat: return "OPC_CheckComplexPat"; break;
1063 case Matcher::CheckAndImm: return "OPC_CheckAndImm"; break;
1064 case Matcher::CheckOrImm: return "OPC_CheckOrImm"; break;
1065 case Matcher::CheckFoldableChainNode:
1066 return "OPC_CheckFoldableChainNode"; break;
1067 case Matcher::CheckImmAllOnesV: return "OPC_CheckImmAllOnesV"; break;
1068 case Matcher::CheckImmAllZerosV: return "OPC_CheckImmAllZerosV"; break;
1069 case Matcher::EmitInteger: return "OPC_EmitInteger"; break;
1070 case Matcher::EmitStringInteger: return "OPC_EmitStringInteger"; break;
1071 case Matcher::EmitRegister: return "OPC_EmitRegister"; break;
1072 case Matcher::EmitConvertToTarget: return "OPC_EmitConvertToTarget"; break;
1073 case Matcher::EmitMergeInputChains: return "OPC_EmitMergeInputChains"; break;
1074 case Matcher::EmitCopyToReg: return "OPC_EmitCopyToReg"; break;
1075 case Matcher::EmitNode: return "OPC_EmitNode"; break;
1076 case Matcher::MorphNodeTo: return "OPC_MorphNodeTo"; break;
1077 case Matcher::EmitNodeXForm: return "OPC_EmitNodeXForm"; break;
1078 case Matcher::CompleteMatch: return "OPC_CompleteMatch"; break;
1081 llvm_unreachable("Unhandled opcode?");
1084 void MatcherTableEmitter::EmitHistogram(const Matcher *M,
1085 raw_ostream &OS) {
1086 if (OmitComments)
1087 return;
1089 OS << " // Opcode Histogram:\n";
1090 for (unsigned i = 0, e = OpcodeCounts.size(); i != e; ++i) {
1091 OS << " // #"
1092 << left_justify(getOpcodeString((Matcher::KindTy)i), HistOpcWidth)
1093 << " = " << OpcodeCounts[i] << '\n';
1095 OS << '\n';
1099 void llvm::EmitMatcherTable(Matcher *TheMatcher,
1100 const CodeGenDAGPatterns &CGP,
1101 raw_ostream &OS) {
1102 OS << "#if defined(GET_DAGISEL_DECL) && defined(GET_DAGISEL_BODY)\n";
1103 OS << "#error GET_DAGISEL_DECL and GET_DAGISEL_BODY cannot be both defined, ";
1104 OS << "undef both for inline definitions\n";
1105 OS << "#endif\n\n";
1107 // Emit a check for omitted class name.
1108 OS << "#ifdef GET_DAGISEL_BODY\n";
1109 OS << "#define LOCAL_DAGISEL_STRINGIZE(X) LOCAL_DAGISEL_STRINGIZE_(X)\n";
1110 OS << "#define LOCAL_DAGISEL_STRINGIZE_(X) #X\n";
1111 OS << "static_assert(sizeof(LOCAL_DAGISEL_STRINGIZE(GET_DAGISEL_BODY)) > 1,"
1112 "\n";
1113 OS << " \"GET_DAGISEL_BODY is empty: it should be defined with the class "
1114 "name\");\n";
1115 OS << "#undef LOCAL_DAGISEL_STRINGIZE_\n";
1116 OS << "#undef LOCAL_DAGISEL_STRINGIZE\n";
1117 OS << "#endif\n\n";
1119 OS << "#if !defined(GET_DAGISEL_DECL) && !defined(GET_DAGISEL_BODY)\n";
1120 OS << "#define DAGISEL_INLINE 1\n";
1121 OS << "#else\n";
1122 OS << "#define DAGISEL_INLINE 0\n";
1123 OS << "#endif\n\n";
1125 OS << "#if !DAGISEL_INLINE\n";
1126 OS << "#define DAGISEL_CLASS_COLONCOLON GET_DAGISEL_BODY ::\n";
1127 OS << "#else\n";
1128 OS << "#define DAGISEL_CLASS_COLONCOLON\n";
1129 OS << "#endif\n\n";
1131 BeginEmitFunction(OS, "void", "SelectCode(SDNode *N)", false/*AddOverride*/);
1132 MatcherTableEmitter MatcherEmitter(CGP);
1134 // First we size all the children of the three kinds of matchers that have
1135 // them. This is done by sharing the code in EmitMatcher(). but we don't
1136 // want to emit anything, so we turn off comments and use a null stream.
1137 bool SaveOmitComments = OmitComments;
1138 OmitComments = true;
1139 raw_null_ostream NullOS;
1140 unsigned TotalSize = MatcherEmitter.SizeMatcherList(TheMatcher, NullOS);
1141 OmitComments = SaveOmitComments;
1143 // Now that the matchers are sized, we can emit the code for them to the
1144 // final stream.
1145 OS << "{\n";
1146 OS << " // Some target values are emitted as 2 bytes, TARGET_VAL handles\n";
1147 OS << " // this.\n";
1148 OS << " #define TARGET_VAL(X) X & 255, unsigned(X) >> 8\n";
1149 OS << " static const unsigned char MatcherTable[] = {\n";
1150 TotalSize = MatcherEmitter.EmitMatcherList(TheMatcher, 1, 0, OS);
1151 OS << " 0\n }; // Total Array size is " << (TotalSize+1) << " bytes\n\n";
1153 MatcherEmitter.EmitHistogram(TheMatcher, OS);
1155 OS << " #undef TARGET_VAL\n";
1156 OS << " SelectCodeCommon(N, MatcherTable,sizeof(MatcherTable));\n";
1157 OS << "}\n";
1158 EndEmitFunction(OS);
1160 // Next up, emit the function for node and pattern predicates:
1161 MatcherEmitter.EmitPredicateFunctions(OS);
1163 if (InstrumentCoverage)
1164 MatcherEmitter.EmitPatternMatchTable(OS);
1166 // Clean up the preprocessor macros.
1167 OS << "\n";
1168 OS << "#ifdef DAGISEL_INLINE\n";
1169 OS << "#undef DAGISEL_INLINE\n";
1170 OS << "#endif\n";
1171 OS << "#ifdef DAGISEL_CLASS_COLONCOLON\n";
1172 OS << "#undef DAGISEL_CLASS_COLONCOLON\n";
1173 OS << "#endif\n";
1174 OS << "#ifdef GET_DAGISEL_DECL\n";
1175 OS << "#undef GET_DAGISEL_DECL\n";
1176 OS << "#endif\n";
1177 OS << "#ifdef GET_DAGISEL_BODY\n";
1178 OS << "#undef GET_DAGISEL_BODY\n";
1179 OS << "#endif\n";