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.
10//
11//===----------------------------------------------------------------------===//
12
13#include "Basic/SDNodeProperties.h"
14#include "Basic/SequenceToOffsetTable.h"
15#include "Common/CodeGenDAGPatterns.h"
16#include "Common/CodeGenInstruction.h"
17#include "Common/CodeGenRegisters.h"
18#include "Common/CodeGenTarget.h"
19#include "DAGISelMatcher.h"
20#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/MapVector.h"
22#include "llvm/ADT/StringMap.h"
23#include "llvm/ADT/TinyPtrVector.h"
24#include "llvm/Support/CommandLine.h"
25#include "llvm/Support/Format.h"
26#include "llvm/Support/LEB128.h"
27#include "llvm/Support/SourceMgr.h"
28#include "llvm/TableGen/Error.h"
29#include "llvm/TableGen/Record.h"
30
31using namespace llvm;
32
33enum {
34 IndexWidth = 7,
35 FullIndexWidth = IndexWidth + 4,
36 HistOpcWidth = 40,
37};
38
39static cl::OptionCategory DAGISelCat("Options for -gen-dag-isel");
40
41// To reduce generated source code size.
42static cl::opt<bool> OmitComments("omit-comments",
43 cl::desc("Do not generate comments"),
44 cl::init(Val: false), cl::cat(DAGISelCat));
45
46static cl::opt<bool> InstrumentCoverage(
47 "instrument-coverage",
48 cl::desc("Generates tables to help identify patterns matched"),
49 cl::init(Val: false), cl::cat(DAGISelCat));
50
51namespace {
52class MatcherTableEmitter {
53 const CodeGenDAGPatterns &CGP;
54
55 SmallVector<unsigned, Matcher::HighestKind + 1> OpcodeCounts;
56
57 std::vector<TreePattern *> NodePredicates;
58 std::vector<TreePattern *> NodePredicatesWithOperands;
59
60 // We de-duplicate the predicates by code string, and use this map to track
61 // all the patterns with "identical" predicates.
62 MapVector<std::string, TinyPtrVector<TreePattern *>, StringMap<unsigned>>
63 NodePredicatesByCodeToRun;
64
65 std::vector<std::string> PatternPredicates;
66
67 std::vector<const ComplexPattern *> ComplexPatterns;
68
69 DenseMap<const Record *, unsigned> NodeXFormMap;
70 std::vector<const Record *> NodeXForms;
71
72 std::vector<std::string> VecIncludeStrings;
73 MapVector<std::string, unsigned, StringMap<unsigned>> VecPatterns;
74
75 // Map from ValueTypeByHwMode to (Index, UsageCount) pair.
76 // Index is 1-based (0 means not yet assigned).
77 std::map<ValueTypeByHwMode, std::pair<unsigned, unsigned>> ValueTypeMap;
78
79 SequenceToOffsetTable<std::vector<uint8_t>> OperandTable;
80
81 unsigned getPatternIdxFromTable(std::string &&P, std::string &&include_loc) {
82 const auto [It, Inserted] =
83 VecPatterns.try_emplace(Key: std::move(P), Args: VecPatterns.size());
84 if (Inserted) {
85 VecIncludeStrings.push_back(x: std::move(include_loc));
86 return VecIncludeStrings.size() - 1;
87 }
88 return It->second;
89 }
90
91public:
92 MatcherTableEmitter(const MatcherList &TheMatcherList,
93 const CodeGenDAGPatterns &cgp)
94 : CGP(cgp), OpcodeCounts(Matcher::HighestKind + 1, 0),
95 OperandTable(std::nullopt) {
96 // Record the usage of ComplexPattern.
97 MapVector<const ComplexPattern *, unsigned> ComplexPatternUsage;
98 // Record the usage of PatternPredicate.
99 MapVector<StringRef, unsigned> PatternPredicateUsage;
100 // Record the usage of Predicate.
101 MapVector<TreePattern *, unsigned> PredicateUsage;
102
103 // Iterate the whole MatcherTable once and do some statistics.
104 std::function<void(const MatcherList &)> Statistic =
105 [&](const MatcherList &ML) {
106 for (const Matcher *N : ML) {
107 if (auto *SM = dyn_cast<ScopeMatcher>(Val: N))
108 for (unsigned I = 0; I < SM->getNumChildren(); I++)
109 Statistic(SM->getChild(i: I));
110 else if (auto *SOM = dyn_cast<SwitchOpcodeMatcher>(Val: N))
111 for (unsigned I = 0; I < SOM->getNumCases(); I++)
112 Statistic(SOM->getCaseMatcher(i: I));
113 else if (auto *STM = dyn_cast<SwitchTypeMatcher>(Val: N))
114 for (unsigned I = 0; I < STM->getNumCases(); I++)
115 Statistic(STM->getCaseMatcher(i: I));
116 else if (auto *CPM = dyn_cast<CheckComplexPatMatcher>(Val: N))
117 ++ComplexPatternUsage[&CPM->getPattern()];
118 else if (auto *CPPM = dyn_cast<CheckPatternPredicateMatcher>(Val: N))
119 ++PatternPredicateUsage[CPPM->getPredicate()];
120 else if (auto *PM = dyn_cast<CheckPredicateMatcher>(Val: N))
121 ++PredicateUsage[PM->getPredicate().getOrigPatFragRecord()];
122
123 // Collect ValueTypeByHwMode usage for remapping.
124 if (auto *CTM = dyn_cast<CheckTypeMatcher>(Val: N)) {
125 if (!CTM->getType().isSimple())
126 getValueTypeID(VT: CTM->getType());
127 } else if (auto *CCTM = dyn_cast<CheckChildTypeMatcher>(Val: N)) {
128 if (!CCTM->getType().isSimple())
129 getValueTypeID(VT: CCTM->getType());
130 } else if (auto *EIM = dyn_cast<EmitIntegerMatcher>(Val: N)) {
131 if (!EIM->getVT().isSimple())
132 getValueTypeID(VT: EIM->getVT());
133 } else if (auto *ERM = dyn_cast<EmitRegisterMatcher>(Val: N)) {
134 if (!ERM->getVT().isSimple())
135 getValueTypeID(VT: ERM->getVT());
136 }
137
138 if (const auto *EN = dyn_cast<EmitNodeMatcherCommon>(Val: N)) {
139 ArrayRef<unsigned> Ops = EN->getOperandList();
140 std::vector<uint8_t> OpBytes;
141 for (unsigned Op : Ops) {
142 uint8_t Buffer[5];
143 unsigned Len = encodeULEB128(Value: Op, p: Buffer);
144 for (unsigned i = 0; i < Len; ++i)
145 OpBytes.push_back(x: Buffer[i]);
146 }
147 OperandTable.add(Seq: OpBytes);
148 }
149 }
150 };
151 Statistic(TheMatcherList);
152
153 sortValueTypeByHwModeByFrequency();
154
155 OperandTable.layout();
156
157 // Sort ComplexPatterns by usage.
158 std::vector<std::pair<const ComplexPattern *, unsigned>> ComplexPatternList(
159 ComplexPatternUsage.begin(), ComplexPatternUsage.end());
160 stable_sort(Range&: ComplexPatternList, C: [](const auto &A, const auto &B) {
161 return A.second > B.second;
162 });
163 for (const auto &ComplexPattern : ComplexPatternList)
164 ComplexPatterns.push_back(x: ComplexPattern.first);
165
166 // Sort PatternPredicates by usage.
167 std::vector<std::pair<std::string, unsigned>> PatternPredicateList(
168 PatternPredicateUsage.begin(), PatternPredicateUsage.end());
169 stable_sort(Range&: PatternPredicateList, C: [](const auto &A, const auto &B) {
170 return A.second > B.second;
171 });
172 for (const auto &PatternPredicate : PatternPredicateList)
173 PatternPredicates.push_back(x: PatternPredicate.first);
174
175 // Sort Predicates by usage.
176 // Merge predicates with same code.
177 for (const auto &Usage : PredicateUsage) {
178 TreePattern *TP = Usage.first;
179 TreePredicateFn Pred(TP);
180 NodePredicatesByCodeToRun[Pred.getCodeToRunOnSDNode()].push_back(NewVal: TP);
181 }
182
183 std::vector<std::pair<TreePattern *, unsigned>> PredicateList;
184 // Sum the usage.
185 for (auto &Predicate : NodePredicatesByCodeToRun) {
186 TinyPtrVector<TreePattern *> &TPs = Predicate.second;
187 stable_sort(Range&: TPs, C: [](const auto *A, const auto *B) {
188 return A->getRecord()->getName() < B->getRecord()->getName();
189 });
190 unsigned Uses = 0;
191 for (TreePattern *TP : TPs)
192 Uses += PredicateUsage[TP];
193
194 // We only add the first predicate here since they are with the same code.
195 PredicateList.emplace_back(args: TPs[0], args&: Uses);
196 }
197
198 stable_sort(Range&: PredicateList, C: [](const auto &A, const auto &B) {
199 return A.second > B.second;
200 });
201 for (const auto &Predicate : PredicateList) {
202 TreePattern *TP = Predicate.first;
203 if (TreePredicateFn(TP).usesOperands())
204 NodePredicatesWithOperands.push_back(x: TP);
205 else
206 NodePredicates.push_back(x: TP);
207 }
208 }
209
210 unsigned EmitMatcherList(const MatcherList &ML, const unsigned Indent,
211 unsigned StartIdx, raw_ostream &OS);
212
213 void EmitOperandLists(raw_ostream &OS);
214
215 unsigned SizeMatcherList(MatcherList &ML, raw_ostream &OS);
216
217 void EmitPredicateFunctions(raw_ostream &OS);
218
219 void EmitValueTypeFunction(raw_ostream &OS);
220
221 void EmitHistogram(raw_ostream &OS);
222
223 void EmitPatternMatchTable(raw_ostream &OS);
224
225private:
226 // Reorder ValueType indices by usage frequency (most common -> index 0).
227 // Updates the indices directly in ValueTypeMap.
228 void sortValueTypeByHwModeByFrequency() {
229 if (ValueTypeMap.empty())
230 return;
231
232 // Collect pointers to map entries with their counts for sorting.
233 using EntryPtr = std::pair<unsigned, unsigned> *;
234 std::vector<EntryPtr> Entries;
235 for (auto &[VT, IdxAndCount] : ValueTypeMap)
236 Entries.push_back(x: &IdxAndCount);
237
238 // Sort by count descending.
239 llvm::sort(C&: Entries,
240 Comp: [](EntryPtr A, EntryPtr B) { return A->second > B->second; });
241
242 // Assign new indices (1-based) in frequency order.
243 for (unsigned NewIdx = 0; NewIdx < Entries.size(); ++NewIdx)
244 Entries[NewIdx]->first = NewIdx + 1;
245 }
246 void EmitNodePredicatesFunction(const std::vector<TreePattern *> &Preds,
247 StringRef Decl, raw_ostream &OS);
248
249 unsigned SizeMatcher(Matcher *N, raw_ostream &OS);
250
251 unsigned EmitMatcher(const Matcher *N, const unsigned Indent,
252 unsigned CurrentIdx, raw_ostream &OS);
253
254 unsigned getNodePredicate(TreePredicateFn Pred) {
255 // We use the first predicate.
256 TreePattern *PredPat =
257 NodePredicatesByCodeToRun[Pred.getCodeToRunOnSDNode()][0];
258 return Pred.usesOperands()
259 ? llvm::find(Range&: NodePredicatesWithOperands, Val: PredPat) -
260 NodePredicatesWithOperands.begin()
261 : llvm::find(Range&: NodePredicates, Val: PredPat) - NodePredicates.begin();
262 }
263
264 unsigned getPatternPredicate(StringRef PredName) {
265 return llvm::find(Range&: PatternPredicates, Val: PredName) - PatternPredicates.begin();
266 }
267 unsigned getComplexPat(const ComplexPattern &P) {
268 return llvm::find(Range&: ComplexPatterns, Val: &P) - ComplexPatterns.begin();
269 }
270
271 unsigned getNodeXFormID(const Record *Rec) {
272 unsigned &Entry = NodeXFormMap[Rec];
273 if (Entry == 0) {
274 NodeXForms.push_back(x: Rec);
275 Entry = NodeXForms.size();
276 }
277 return Entry - 1;
278 }
279
280 unsigned getValueTypeID(const ValueTypeByHwMode &VT) {
281 auto &[Idx, Count] = ValueTypeMap[VT];
282 if (Idx == 0) {
283 Idx = ValueTypeMap.size();
284 if (Idx > 256)
285 report_fatal_error(
286 reason: "More ValueType by HwMode than fit in a 8-bit index");
287 }
288 ++Count;
289 return Idx - 1;
290 }
291
292 unsigned emitValueTypeByHwMode(const ValueTypeByHwMode &VTBH, unsigned Index,
293 raw_ostream &OS);
294};
295} // end anonymous namespace.
296
297static std::string GetPatFromTreePatternNode(const TreePatternNode &N) {
298 std::string str;
299 raw_string_ostream Stream(str);
300 Stream << N;
301 return str;
302}
303
304static unsigned GetVBRSize(unsigned Val) {
305 if (Val <= 127)
306 return 1;
307
308 unsigned NumBytes = 0;
309 while (Val >= 128) {
310 Val >>= 7;
311 ++NumBytes;
312 }
313 return NumBytes + 1;
314}
315
316/// EmitVBRValue - Emit the specified value as a VBR, returning the number of
317/// bytes emitted.
318static unsigned EmitVBRValue(uint64_t Val, raw_ostream &OS) {
319 if (Val <= 127) {
320 OS << Val << ',';
321 return 1;
322 }
323
324 uint64_t InVal = Val;
325 unsigned NumBytes = 0;
326 while (Val >= 128) {
327 OS << (Val & 127) << "|128,";
328 Val >>= 7;
329 ++NumBytes;
330 }
331 OS << Val;
332 if (!OmitComments)
333 OS << "/*" << InVal << "*/";
334 OS << ',';
335 return NumBytes + 1;
336}
337
338/// Emit the specified signed value as a VBR. To improve compression we encode
339/// positive numbers shifted left by 1 and negative numbers negated and shifted
340/// left by 1 with bit 0 set.
341static unsigned EmitSignedVBRValue(int64_t Val, raw_ostream &OS) {
342 uint8_t Buffer[10];
343 unsigned Len = encodeSLEB128(Value: Val, p: Buffer);
344
345 for (unsigned i = 0; i != Len - 1; ++i)
346 OS << static_cast<unsigned>(Buffer[i] & 127) << "|128,";
347
348 OS << static_cast<unsigned>(Buffer[Len - 1]);
349 if ((Len > 1 || Val < 0) && !OmitComments)
350 OS << "/*" << Val << "*/";
351 OS << ',';
352 return Len;
353}
354
355// This is expensive and slow.
356static std::string getIncludePath(const Record *R) {
357 std::string str;
358 raw_string_ostream Stream(str);
359 auto Locs = R->getLoc();
360 SMLoc L;
361 if (Locs.size() > 1) {
362 // Get where the pattern prototype was instantiated
363 L = Locs[1];
364 } else if (Locs.size() == 1) {
365 L = Locs[0];
366 }
367 unsigned CurBuf = SrcMgr.FindBufferContainingLoc(Loc: L);
368 assert(CurBuf && "Invalid or unspecified location!");
369
370 Stream << SrcMgr.getBufferInfo(i: CurBuf).Buffer->getBufferIdentifier() << ":"
371 << SrcMgr.FindLineNumber(Loc: L, BufferID: CurBuf);
372 return str;
373}
374
375/// This function traverses the matcher tree and sizes all the nodes
376/// that are children of the three kinds of nodes that have them.
377unsigned MatcherTableEmitter::SizeMatcherList(MatcherList &ML,
378 raw_ostream &OS) {
379 unsigned Size = 0;
380 for (Matcher *N : ML)
381 Size += SizeMatcher(N, OS);
382 return Size;
383}
384
385/// This function sizes the children of the three kinds of nodes that
386/// have them. It does so by using special cases for those three
387/// nodes, but sharing the code in EmitMatcher() for the other kinds.
388unsigned MatcherTableEmitter::SizeMatcher(Matcher *N, raw_ostream &OS) {
389 unsigned Idx = 0;
390
391 ++OpcodeCounts[N->getKind()];
392 switch (N->getKind()) {
393 // The Scope matcher has its kind, a series of child size + child,
394 // and a trailing zero.
395 case Matcher::Scope: {
396 ScopeMatcher *SM = cast<ScopeMatcher>(Val: N);
397 unsigned Size = 1; // Count the kind.
398 for (unsigned i = 0, e = SM->getNumChildren(); i != e; ++i) {
399 const unsigned ChildSize = SizeMatcherList(ML&: SM->getChild(i), OS);
400 assert(ChildSize != 0 && "Matcher cannot have child of size 0");
401 SM->getChild(i).setSize(ChildSize);
402 Size += GetVBRSize(Val: ChildSize) + ChildSize; // Count VBR and child size.
403 }
404 ++Size; // Count the zero sentinel.
405 return Size;
406 }
407
408 // SwitchOpcode and SwitchType have their kind, a series of child size +
409 // opcode/type + child, and a trailing zero.
410 case Matcher::SwitchOpcode:
411 case Matcher::SwitchType: {
412 unsigned Size = 1; // Count the kind.
413 unsigned NumCases;
414 if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(Val: N))
415 NumCases = SOM->getNumCases();
416 else
417 NumCases = cast<SwitchTypeMatcher>(Val: N)->getNumCases();
418 for (unsigned i = 0, e = NumCases; i != e; ++i) {
419 MatcherList *Child;
420 if (SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(Val: N)) {
421 Child = &SOM->getCaseMatcher(i);
422 Size += 2; // Count the child's opcode.
423 } else {
424 Child = &cast<SwitchTypeMatcher>(Val: N)->getCaseMatcher(i);
425 Size += GetVBRSize(Val: cast<SwitchTypeMatcher>(Val: N)
426 ->getCaseType(i)
427 .SimpleTy); // Count the child's type.
428 }
429 const unsigned ChildSize = SizeMatcherList(ML&: *Child, OS);
430 assert(ChildSize != 0 && "Matcher cannot have child of size 0");
431 Child->setSize(ChildSize);
432 Size += GetVBRSize(Val: ChildSize) + ChildSize; // Count VBR and child size.
433 }
434 ++Size; // Count the zero sentinel.
435 return Size;
436 }
437
438 default:
439 // Employ the matcher emitter to size other matchers.
440 return EmitMatcher(N, Indent: 0, CurrentIdx: Idx, OS);
441 }
442 llvm_unreachable("Unreachable");
443}
444
445static void BeginEmitFunction(raw_ostream &OS, StringRef RetType,
446 StringRef Decl, bool AddOverride) {
447 OS << "#ifdef GET_DAGISEL_DECL\n";
448 OS << RetType << ' ' << Decl;
449 if (AddOverride)
450 OS << " override";
451 OS << ";\n"
452 "#endif\n"
453 "#if defined(GET_DAGISEL_BODY) || DAGISEL_INLINE\n";
454 OS << RetType << " DAGISEL_CLASS_COLONCOLON " << Decl << "\n";
455 if (AddOverride) {
456 OS << "#if DAGISEL_INLINE\n"
457 " override\n"
458 "#endif\n";
459 }
460}
461
462static void EndEmitFunction(raw_ostream &OS) {
463 OS << "#endif // GET_DAGISEL_BODY\n\n";
464}
465
466void MatcherTableEmitter::EmitPatternMatchTable(raw_ostream &OS) {
467
468 if (!isUInt<32>(x: VecPatterns.size()))
469 report_fatal_error(reason: "More patterns defined that can fit into 32-bit Pattern "
470 "Table index encoding");
471
472 assert(VecPatterns.size() == VecIncludeStrings.size() &&
473 "The sizes of Pattern and include vectors should be the same");
474
475 BeginEmitFunction(OS, RetType: "StringRef", Decl: "getPatternForIndex(unsigned Index)",
476 AddOverride: true /*AddOverride*/);
477 OS << "{\n";
478 OS << "static const char *PATTERN_MATCH_TABLE[] = {\n";
479
480 for (const auto &It : VecPatterns) {
481 OS << "\"" << It.first << "\",\n";
482 }
483
484 OS << "\n};";
485 OS << "\nreturn StringRef(PATTERN_MATCH_TABLE[Index]);";
486 OS << "\n}\n";
487 EndEmitFunction(OS);
488
489 BeginEmitFunction(OS, RetType: "StringRef", Decl: "getIncludePathForIndex(unsigned Index)",
490 AddOverride: true /*AddOverride*/);
491 OS << "{\n";
492 OS << "static const char *INCLUDE_PATH_TABLE[] = {\n";
493
494 for (const auto &It : VecIncludeStrings) {
495 OS << "\"" << It << "\",\n";
496 }
497
498 OS << "\n};";
499 OS << "\nreturn StringRef(INCLUDE_PATH_TABLE[Index]);";
500 OS << "\n}\n";
501 EndEmitFunction(OS);
502}
503
504static unsigned emitMVT(MVT VT, raw_ostream &OS) {
505 // Print the MVT directly if it doesn't require a VBR.
506 if (VT.SimpleTy <= 127) {
507 OS << getEnumName(T: VT) << ',';
508 return 1;
509 }
510
511 if (!OmitComments)
512 OS << "/*" << getEnumName(T: VT) << "*/";
513 return EmitVBRValue(Val: VT.SimpleTy, OS);
514}
515
516unsigned
517MatcherTableEmitter::emitValueTypeByHwMode(const ValueTypeByHwMode &VTBH,
518 unsigned Index, raw_ostream &OS) {
519 if (!OmitComments)
520 OS << "/*" << VTBH << "*/";
521 OS << Index << ',';
522 return 1;
523}
524/// EmitMatcher - Emit bytes for the specified matcher and return
525/// the number of bytes emitted.
526unsigned MatcherTableEmitter::EmitMatcher(const Matcher *N,
527 const unsigned Indent,
528 unsigned CurrentIdx,
529 raw_ostream &OS) {
530 OS.indent(NumSpaces: Indent);
531
532 switch (N->getKind()) {
533 case Matcher::Scope: {
534 const ScopeMatcher *SM = cast<ScopeMatcher>(Val: N);
535 unsigned StartIdx = CurrentIdx;
536
537 OS << "OPC_Scope";
538 if (!OmitComments)
539 OS << " /*" << SM->getNumChildren() << " children */";
540 OS << ", ";
541 ++CurrentIdx;
542
543 // Emit all of the children.
544 for (unsigned i = 0, e = SM->getNumChildren(); i != e; ++i) {
545 if (i != 0) {
546 if (!OmitComments) {
547 OS << "/*" << format_decimal(N: CurrentIdx, Width: IndexWidth) << "*/";
548 OS.indent(NumSpaces: Indent) << "/*Scope*/ ";
549 } else {
550 OS.indent(NumSpaces: Indent);
551 }
552 }
553
554 const MatcherList &Child = SM->getChild(i);
555 unsigned ChildSize = Child.getSize();
556 CurrentIdx += EmitVBRValue(Val: ChildSize, OS);
557 if (!OmitComments)
558 OS << " // ->" << CurrentIdx + ChildSize;
559 OS << '\n';
560
561 ChildSize = EmitMatcherList(ML: Child, Indent: Indent + 1, StartIdx: CurrentIdx, OS);
562 assert(ChildSize == Child.getSize() &&
563 "Emitted child size does not match calculated size");
564 CurrentIdx += ChildSize;
565 }
566
567 // Emit a zero as a sentinel indicating end of 'Scope'.
568 if (!OmitComments)
569 OS << "/*" << format_decimal(N: CurrentIdx, Width: IndexWidth) << "*/";
570 OS.indent(NumSpaces: Indent) << "0,";
571 if (!OmitComments)
572 OS << " // End of Scope";
573 OS << '\n';
574 return CurrentIdx - StartIdx + 1;
575 }
576
577 case Matcher::RecordNode:
578 OS << "OPC_RecordNode,";
579 if (!OmitComments)
580 OS << " // #" << cast<RecordMatcher>(Val: N)->getResultNo() << " = "
581 << cast<RecordMatcher>(Val: N)->getWhatFor();
582 OS << '\n';
583 return 1;
584
585 case Matcher::RecordChild:
586 OS << "OPC_RecordChild" << cast<RecordChildMatcher>(Val: N)->getChildNo() << ',';
587 if (!OmitComments)
588 OS << " // #" << cast<RecordChildMatcher>(Val: N)->getResultNo() << " = "
589 << cast<RecordChildMatcher>(Val: N)->getWhatFor();
590 OS << '\n';
591 return 1;
592
593 case Matcher::RecordMemRef:
594 OS << "OPC_RecordMemRef,\n";
595 return 1;
596
597 case Matcher::CaptureGlueInput:
598 OS << "OPC_CaptureGlueInput,\n";
599 return 1;
600
601 case Matcher::MoveChild: {
602 const auto *MCM = cast<MoveChildMatcher>(Val: N);
603
604 OS << "OPC_MoveChild";
605 // Handle the specialized forms.
606 if (MCM->getChildNo() >= 8)
607 OS << ", ";
608 OS << MCM->getChildNo() << ",\n";
609 return (MCM->getChildNo() >= 8) ? 2 : 1;
610 }
611
612 case Matcher::MoveSibling: {
613 const auto *MSM = cast<MoveSiblingMatcher>(Val: N);
614
615 OS << "OPC_MoveSibling";
616 // Handle the specialized forms.
617 if (MSM->getSiblingNo() >= 8)
618 OS << ", ";
619 OS << MSM->getSiblingNo() << ",\n";
620 return (MSM->getSiblingNo() >= 8) ? 2 : 1;
621 }
622
623 case Matcher::MoveParent:
624 OS << "OPC_MoveParent,\n";
625 return 1;
626
627 case Matcher::CheckSame:
628 OS << "OPC_CheckSame, " << cast<CheckSameMatcher>(Val: N)->getMatchNumber()
629 << ",\n";
630 return 2;
631
632 case Matcher::CheckChildSame:
633 OS << "OPC_CheckChild" << cast<CheckChildSameMatcher>(Val: N)->getChildNo()
634 << "Same, " << cast<CheckChildSameMatcher>(Val: N)->getMatchNumber() << ",\n";
635 return 2;
636
637 case Matcher::CheckPatternPredicate: {
638 StringRef Pred = cast<CheckPatternPredicateMatcher>(Val: N)->getPredicate();
639 unsigned PredNo = getPatternPredicate(PredName: Pred);
640 if (PredNo > 255)
641 OS << "OPC_CheckPatternPredicateTwoByte, TARGET_VAL(" << PredNo << "),";
642 else if (PredNo < 8)
643 OS << "OPC_CheckPatternPredicate" << PredNo << ',';
644 else
645 OS << "OPC_CheckPatternPredicate, " << PredNo << ',';
646 if (!OmitComments)
647 OS << " // " << Pred;
648 OS << '\n';
649 return 2 + (PredNo > 255) - (PredNo < 8);
650 }
651 case Matcher::CheckPredicate: {
652 TreePredicateFn Pred = cast<CheckPredicateMatcher>(Val: N)->getPredicate();
653 unsigned OperandBytes = 0;
654 unsigned PredNo = getNodePredicate(Pred);
655
656 if (Pred.usesOperands()) {
657 unsigned NumOps = cast<CheckPredicateMatcher>(Val: N)->getNumOperands();
658 OS << "OPC_CheckPredicateWithOperands, " << NumOps << "/*#Ops*/, ";
659 for (unsigned i = 0; i < NumOps; ++i)
660 OS << cast<CheckPredicateMatcher>(Val: N)->getOperandNo(i) << ", ";
661 OperandBytes = 1 + NumOps;
662 } else {
663 if (PredNo < 8) {
664 OperandBytes = -1;
665 OS << "OPC_CheckPredicate" << PredNo << ',';
666 } else {
667 OS << "OPC_CheckPredicate, ";
668 }
669 }
670
671 if (PredNo >= 8 || Pred.usesOperands())
672 OS << PredNo << ',';
673 if (!OmitComments)
674 OS << " // " << Pred.getFnName();
675 OS << '\n';
676 return 2 + OperandBytes;
677 }
678
679 case Matcher::CheckOpcode:
680 OS << "OPC_CheckOpcode, TARGET_VAL("
681 << cast<CheckOpcodeMatcher>(Val: N)->getOpcode().getEnumName() << "),\n";
682 return 3;
683
684 case Matcher::SwitchOpcode:
685 case Matcher::SwitchType: {
686 unsigned StartIdx = CurrentIdx;
687
688 unsigned NumCases;
689 if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(Val: N)) {
690 OS << "OPC_SwitchOpcode ";
691 NumCases = SOM->getNumCases();
692 } else {
693 OS << "OPC_SwitchType ";
694 NumCases = cast<SwitchTypeMatcher>(Val: N)->getNumCases();
695 }
696
697 if (!OmitComments)
698 OS << "/*" << NumCases << " cases */";
699 OS << ", ";
700 ++CurrentIdx;
701
702 // For each case we emit the size, then the opcode, then the matcher.
703 for (unsigned i = 0, e = NumCases; i != e; ++i) {
704 const MatcherList *Child;
705 unsigned IdxSize;
706 if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(Val: N)) {
707 Child = &SOM->getCaseMatcher(i);
708 IdxSize = 2; // size of opcode in table is 2 bytes.
709 } else {
710 Child = &cast<SwitchTypeMatcher>(Val: N)->getCaseMatcher(i);
711 IdxSize = GetVBRSize(
712 Val: cast<SwitchTypeMatcher>(Val: N)
713 ->getCaseType(i)
714 .SimpleTy); // size of type in table is sizeof(VBR(MVT)) byte.
715 }
716
717 if (i != 0) {
718 if (!OmitComments)
719 OS << "/*" << format_decimal(N: CurrentIdx, Width: IndexWidth) << "*/";
720 OS.indent(NumSpaces: Indent);
721 if (!OmitComments)
722 OS << (isa<SwitchOpcodeMatcher>(Val: N) ? "/*SwitchOpcode*/ "
723 : "/*SwitchType*/ ");
724 }
725
726 unsigned ChildSize = Child->getSize();
727 CurrentIdx += EmitVBRValue(Val: ChildSize, OS) + IdxSize;
728 OS << ' ';
729 if (const SwitchOpcodeMatcher *SOM = dyn_cast<SwitchOpcodeMatcher>(Val: N))
730 OS << "TARGET_VAL(" << SOM->getCaseOpcode(i).getEnumName() << "),";
731 else
732 emitMVT(VT: cast<SwitchTypeMatcher>(Val: N)->getCaseType(i), OS);
733 if (!OmitComments)
734 OS << " // ->" << CurrentIdx + ChildSize;
735 OS << '\n';
736
737 ChildSize = EmitMatcherList(ML: *Child, Indent: Indent + 1, StartIdx: CurrentIdx, OS);
738 assert(ChildSize == Child->getSize() &&
739 "Emitted child size does not match calculated size");
740 CurrentIdx += ChildSize;
741 }
742
743 // Emit the final zero to terminate the switch.
744 if (!OmitComments)
745 OS << "/*" << format_decimal(N: CurrentIdx, Width: IndexWidth) << "*/";
746 OS.indent(NumSpaces: Indent) << "0,";
747 if (!OmitComments)
748 OS << (isa<SwitchOpcodeMatcher>(Val: N) ? " // EndSwitchOpcode"
749 : " // EndSwitchType");
750
751 OS << '\n';
752 return CurrentIdx - StartIdx + 1;
753 }
754
755 case Matcher::CheckType: {
756 const ValueTypeByHwMode &VTBH = cast<CheckTypeMatcher>(Val: N)->getType();
757 if (VTBH.isSimple()) {
758 MVT VT = VTBH.getSimple();
759 if (cast<CheckTypeMatcher>(Val: N)->getResNo() == 0) {
760 switch (VT.SimpleTy) {
761 case MVT::i32:
762 case MVT::i64:
763 OS << "OPC_CheckTypeI" << MVT(VT).getSizeInBits() << ",\n";
764 return 1;
765 default:
766 OS << "OPC_CheckType, ";
767 unsigned NumBytes = emitMVT(VT, OS);
768 OS << '\n';
769 return NumBytes + 1;
770 }
771 }
772
773 OS << "OPC_CheckTypeRes, " << cast<CheckTypeMatcher>(Val: N)->getResNo()
774 << ", ";
775 unsigned NumBytes =
776 emitMVT(VT: cast<CheckTypeMatcher>(Val: N)->getType().getSimple(), OS);
777 OS << '\n';
778 return NumBytes + 2;
779 }
780
781 unsigned OpSize;
782 if (cast<CheckTypeMatcher>(Val: N)->getResNo() == 0) {
783 unsigned Index = getValueTypeID(VT: VTBH);
784 if (Index == 0) {
785 OS << "OPC_CheckTypeByHwMode0";
786 if (!OmitComments)
787 OS << "/*" << VTBH << "*/";
788 OS << ',';
789 OpSize = 1;
790 } else {
791 OS << "OPC_CheckTypeByHwMode, ";
792 OpSize = 1 + emitValueTypeByHwMode(VTBH, Index, OS);
793 }
794 } else {
795 OS << "OPC_CheckTypeResByHwMode, "
796 << cast<CheckTypeMatcher>(Val: N)->getResNo() << ", ";
797 OpSize = 2 + emitValueTypeByHwMode(VTBH, Index: getValueTypeID(VT: VTBH), OS);
798 }
799 OS << '\n';
800 return OpSize;
801 }
802
803 case Matcher::CheckChildType: {
804 const ValueTypeByHwMode &VTBH = cast<CheckChildTypeMatcher>(Val: N)->getType();
805 if (VTBH.isSimple()) {
806 MVT VT = VTBH.getSimple();
807 switch (VT.SimpleTy) {
808 case MVT::i32:
809 case MVT::i64:
810 OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(Val: N)->getChildNo()
811 << "TypeI" << VT.getSizeInBits() << ",\n";
812 return 1;
813 default:
814 OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(Val: N)->getChildNo()
815 << "Type, ";
816 unsigned NumBytes = emitMVT(VT, OS);
817 OS << '\n';
818 return NumBytes + 1;
819 }
820 } else {
821 unsigned Index = getValueTypeID(VT: VTBH);
822 if (Index == 0) {
823 OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(Val: N)->getChildNo()
824 << "TypeByHwMode0";
825 if (!OmitComments)
826 OS << "/*" << VTBH << "*/";
827 OS << ",\n";
828 return 1;
829 }
830 OS << "OPC_CheckChild" << cast<CheckChildTypeMatcher>(Val: N)->getChildNo()
831 << "TypeByHwMode, ";
832 unsigned NumBytes = emitValueTypeByHwMode(VTBH, Index, OS);
833 OS << '\n';
834 return NumBytes + 1;
835 }
836 }
837
838 case Matcher::CheckInteger: {
839 OS << "OPC_CheckInteger, ";
840 unsigned Bytes =
841 1 + EmitSignedVBRValue(Val: cast<CheckIntegerMatcher>(Val: N)->getValue(), OS);
842 OS << '\n';
843 return Bytes;
844 }
845 case Matcher::CheckChildInteger: {
846 OS << "OPC_CheckChild" << cast<CheckChildIntegerMatcher>(Val: N)->getChildNo()
847 << "Integer, ";
848 unsigned Bytes = 1 + EmitSignedVBRValue(
849 Val: cast<CheckChildIntegerMatcher>(Val: N)->getValue(), OS);
850 OS << '\n';
851 return Bytes;
852 }
853 case Matcher::CheckCondCode:
854 OS << "OPC_CheckCondCode, ISD::"
855 << cast<CheckCondCodeMatcher>(Val: N)->getCondCodeName() << ",\n";
856 return 2;
857
858 case Matcher::CheckChild2CondCode:
859 OS << "OPC_CheckChild2CondCode, ISD::"
860 << cast<CheckChild2CondCodeMatcher>(Val: N)->getCondCodeName() << ",\n";
861 return 2;
862
863 case Matcher::CheckValueType: {
864 OS << "OPC_CheckValueType, ";
865 unsigned NumBytes = emitMVT(VT: cast<CheckValueTypeMatcher>(Val: N)->getVT(), OS);
866 OS << "\n";
867 return NumBytes + 1;
868 }
869
870 case Matcher::CheckComplexPat: {
871 const CheckComplexPatMatcher *CCPM = cast<CheckComplexPatMatcher>(Val: N);
872 const ComplexPattern &Pattern = CCPM->getPattern();
873 unsigned PatternNo = getComplexPat(P: Pattern);
874 if (PatternNo < 8)
875 OS << "OPC_CheckComplexPat" << PatternNo << ", /*#*/"
876 << CCPM->getMatchNumber() << ',';
877 else
878 OS << "OPC_CheckComplexPat, /*CP*/" << PatternNo << ", /*#*/"
879 << CCPM->getMatchNumber() << ',';
880
881 if (!OmitComments) {
882 OS << " // " << Pattern.getSelectFunc();
883 OS << ":$" << CCPM->getName();
884 for (unsigned i = 0, e = Pattern.getNumOperands(); i != e; ++i)
885 OS << " #" << CCPM->getFirstResult() + i;
886
887 if (Pattern.hasProperty(Prop: SDNPHasChain))
888 OS << " + chain result";
889 }
890 OS << '\n';
891 return PatternNo < 8 ? 2 : 3;
892 }
893
894 case Matcher::CheckAndImm: {
895 OS << "OPC_CheckAndImm, ";
896 unsigned Bytes =
897 1 + EmitVBRValue(Val: cast<CheckAndImmMatcher>(Val: N)->getValue(), OS);
898 OS << '\n';
899 return Bytes;
900 }
901
902 case Matcher::CheckOrImm: {
903 OS << "OPC_CheckOrImm, ";
904 unsigned Bytes =
905 1 + EmitVBRValue(Val: cast<CheckOrImmMatcher>(Val: N)->getValue(), OS);
906 OS << '\n';
907 return Bytes;
908 }
909
910 case Matcher::CheckFoldableChainNode:
911 OS << "OPC_CheckFoldableChainNode,\n";
912 return 1;
913
914 case Matcher::CheckImmAllOnesV:
915 OS << "OPC_CheckImmAllOnesV,\n";
916 return 1;
917
918 case Matcher::CheckImmAllZerosV:
919 OS << "OPC_CheckImmAllZerosV,\n";
920 return 1;
921
922 case Matcher::EmitInteger: {
923 const auto *IM = cast<EmitIntegerMatcher>(Val: N);
924 int64_t Val = IM->getValue();
925 const std::string &Str = IM->getString();
926 const ValueTypeByHwMode &VTBH = IM->getVT();
927 unsigned TypeBytes = 0;
928 if (VTBH.isSimple()) {
929 MVT VT = VTBH.getSimple();
930 switch (VT.SimpleTy) {
931 case MVT::i8:
932 case MVT::i16:
933 case MVT::i32:
934 case MVT::i64:
935 OS << "OPC_EmitIntegerI" << VT.getSizeInBits() << ", ";
936 break;
937 default:
938 OS << "OPC_EmitInteger, ";
939 TypeBytes = emitMVT(VT, OS);
940 OS << ' ';
941 break;
942 }
943 } else {
944 unsigned Index = getValueTypeID(VT: VTBH);
945 if (Index == 0) {
946 OS << "OPC_EmitIntegerByHwMode0";
947 if (!OmitComments)
948 OS << "/*" << VTBH << "*/";
949 OS << ", ";
950 TypeBytes = 0;
951 } else {
952 OS << "OPC_EmitIntegerByHwMode, ";
953 TypeBytes = emitValueTypeByHwMode(VTBH, Index, OS);
954 OS << ' ';
955 }
956 }
957 // If the value is 63 or smaller, use the string directly. Otherwise, use
958 // a VBR.
959 unsigned ValBytes = 1;
960 if (!Str.empty() && Val <= 63)
961 OS << Str << ',';
962 else
963 ValBytes = EmitSignedVBRValue(Val, OS);
964 if (!OmitComments) {
965 OS << " // #" << IM->getResultNo() << " = ";
966 if (!Str.empty())
967 OS << Str;
968 else
969 OS << Val;
970 }
971 OS << '\n';
972 return 1 + TypeBytes + ValBytes;
973 }
974
975 case Matcher::EmitRegister: {
976 const EmitRegisterMatcher *Matcher = cast<EmitRegisterMatcher>(Val: N);
977 const CodeGenRegister *Reg = Matcher->getReg();
978 const ValueTypeByHwMode &VTBH = Matcher->getVT();
979 unsigned OpBytes;
980 if (VTBH.isSimple()) {
981 MVT VT = VTBH.getSimple();
982 // If the enum value of the register is larger than one byte can handle,
983 // use EmitRegister2.
984 if (Reg && Reg->EnumValue > 255) {
985 OS << "OPC_EmitRegister2, ";
986 OpBytes = emitMVT(VT, OS);
987 OS << " TARGET_VAL(" << getQualifiedName(R: Reg->TheDef) << "),\n";
988 return OpBytes + 3;
989 }
990 switch (VT.SimpleTy) {
991 case MVT::i32:
992 case MVT::i64:
993 OpBytes = 1;
994 OS << "OPC_EmitRegisterI" << VT.getSizeInBits() << ", ";
995 break;
996 default:
997 OS << "OPC_EmitRegister, ";
998 OpBytes = emitMVT(VT, OS) + 1;
999 OS << ' ';
1000 break;
1001 }
1002 } else {
1003 if (Reg && Reg->EnumValue > 255) {
1004 OS << "OPC_EmitRegisterByHwMode2, ";
1005 OpBytes = emitValueTypeByHwMode(VTBH, Index: getValueTypeID(VT: VTBH), OS);
1006 OS << " TARGET_VAL(" << getQualifiedName(R: Reg->TheDef) << "),\n";
1007 return OpBytes + 3;
1008 }
1009
1010 OS << "OPC_EmitRegisterByHwMode, ";
1011 OpBytes = emitValueTypeByHwMode(VTBH, Index: getValueTypeID(VT: VTBH), OS) + 1;
1012 OS << ' ';
1013 }
1014 if (Reg)
1015 OS << getQualifiedName(R: Reg->TheDef);
1016 else
1017 OS << "MCRegister::NoRegister";
1018
1019 OS << ',';
1020 if (!OmitComments)
1021 OS << " // #" << Matcher->getResultNo();
1022 OS << '\n';
1023 return OpBytes + 1;
1024 }
1025
1026 case Matcher::EmitConvertToTarget: {
1027 const auto *CTTM = cast<EmitConvertToTargetMatcher>(Val: N);
1028 unsigned Slot = CTTM->getSlot();
1029 OS << "OPC_EmitConvertToTarget";
1030 if (Slot >= 8)
1031 OS << ", ";
1032 OS << Slot << ',';
1033 if (!OmitComments)
1034 OS << " // #" << CTTM->getResultNo() << " = ConvertToTarget #" << Slot;
1035 OS << '\n';
1036 return 1 + (Slot >= 8);
1037 }
1038
1039 case Matcher::EmitMergeInputChains: {
1040 const EmitMergeInputChainsMatcher *MN =
1041 cast<EmitMergeInputChainsMatcher>(Val: N);
1042
1043 // Handle the specialized forms OPC_EmitMergeInputChains1_0, 1_1, and 1_2.
1044 if (MN->getNumNodes() == 1 && MN->getNode(i: 0) < 3) {
1045 OS << "OPC_EmitMergeInputChains1_" << MN->getNode(i: 0) << ",\n";
1046 return 1;
1047 }
1048
1049 OS << "OPC_EmitMergeInputChains, " << MN->getNumNodes() << ',';
1050 for (unsigned i = 0, e = MN->getNumNodes(); i != e; ++i)
1051 OS << ' ' << MN->getNode(i) << ",";
1052 OS << '\n';
1053 return 2 + MN->getNumNodes();
1054 }
1055 case Matcher::EmitCopyToReg: {
1056 const auto *C2RMatcher = cast<EmitCopyToRegMatcher>(Val: N);
1057 int Bytes = 3;
1058 const CodeGenRegister *Reg = C2RMatcher->getDestPhysReg();
1059 unsigned Slot = C2RMatcher->getSrcSlot();
1060 if (Reg->EnumValue > 255) {
1061 assert(isUInt<16>(Reg->EnumValue) && "not handled");
1062 OS << "OPC_EmitCopyToRegTwoByte, " << Slot << ", "
1063 << "TARGET_VAL(" << getQualifiedName(R: Reg->TheDef) << "),";
1064 ++Bytes;
1065 } else {
1066 if (Slot < 8) {
1067 OS << "OPC_EmitCopyToReg" << Slot << ", "
1068 << getQualifiedName(R: Reg->TheDef) << ",";
1069 --Bytes;
1070 } else {
1071 OS << "OPC_EmitCopyToReg, " << Slot << ", "
1072 << getQualifiedName(R: Reg->TheDef) << ",";
1073 }
1074 }
1075 if (!OmitComments)
1076 OS << " // = #" << Slot;
1077
1078 OS << '\n';
1079 return Bytes;
1080 }
1081 case Matcher::EmitNodeXForm: {
1082 const EmitNodeXFormMatcher *XF = cast<EmitNodeXFormMatcher>(Val: N);
1083 OS << "OPC_EmitNodeXForm, " << getNodeXFormID(Rec: XF->getNodeXForm()) << ", "
1084 << XF->getSlot() << ',';
1085 if (!OmitComments)
1086 OS << " // #" << XF->getResultNo() << " = "
1087 << XF->getNodeXForm()->getName() << " #" << XF->getSlot();
1088 OS << '\n';
1089 return 3;
1090 }
1091
1092 case Matcher::EmitNode:
1093 case Matcher::MorphNodeTo: {
1094 auto NumCoveredBytes = 0;
1095 if (InstrumentCoverage) {
1096 if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(Val: N)) {
1097 NumCoveredBytes = 3;
1098 OS << "OPC_Coverage, ";
1099 std::string src =
1100 GetPatFromTreePatternNode(N: SNT->getPattern().getSrcPattern());
1101 std::string dst =
1102 GetPatFromTreePatternNode(N: SNT->getPattern().getDstPattern());
1103 const Record *PatRecord = SNT->getPattern().getSrcRecord();
1104 std::string include_src = getIncludePath(R: PatRecord);
1105 unsigned Offset =
1106 getPatternIdxFromTable(P: src + " -> " + dst, include_loc: std::move(include_src));
1107 OS << "COVERAGE_IDX_VAL(" << Offset << "),\n";
1108 OS.indent(NumSpaces: FullIndexWidth + Indent);
1109 }
1110 }
1111 const EmitNodeMatcherCommon *EN = cast<EmitNodeMatcherCommon>(Val: N);
1112 bool SupportsDeactivationSymbol =
1113 EN->getInstruction().TheDef->getValueAsBit(
1114 FieldName: "supportsDeactivationSymbol");
1115 if (SupportsDeactivationSymbol) {
1116 OS << "OPC_CaptureDeactivationSymbol,\n";
1117 OS.indent(NumSpaces: FullIndexWidth + Indent);
1118 }
1119
1120 bool ByHwMode =
1121 llvm::any_of(Range: EN->getVTList(), P: [](const ValueTypeByHwMode &VT) {
1122 return !VT.isSimple();
1123 });
1124
1125 bool IsEmitNode = isa<EmitNodeMatcher>(Val: EN);
1126 OS << (IsEmitNode ? "OPC_EmitNode" : "OPC_MorphNodeTo");
1127 unsigned NumVTs = EN->getNumVTs();
1128 bool CompressVTs = !ByHwMode && EN->getNumVTs() < 3;
1129 bool CompressNodeInfo = false;
1130 if (CompressVTs) {
1131 OS << NumVTs;
1132 // When NumVTs is zero, only consider compressing the chain flag. Any
1133 // zero result node without chain would be deleted and not eligible for
1134 // isel.
1135 if (NumVTs > 0 && !EN->hasChain() && !EN->hasInGlue() &&
1136 !EN->hasOutGlue() && !EN->hasMemRefs() &&
1137 EN->getNumFixedArityOperands() == -1) {
1138 CompressNodeInfo = true;
1139 OS << "None";
1140 } else if (EN->hasChain() && !EN->hasInGlue() && !EN->hasOutGlue() &&
1141 !EN->hasMemRefs() && EN->getNumFixedArityOperands() == -1) {
1142 CompressNodeInfo = true;
1143 OS << "Chain";
1144 } else if (NumVTs > 0 && !IsEmitNode && !EN->hasChain() &&
1145 EN->hasInGlue() && !EN->hasOutGlue() && !EN->hasMemRefs() &&
1146 EN->getNumFixedArityOperands() == -1) {
1147 CompressNodeInfo = true;
1148 OS << "GlueInput";
1149 } else if (NumVTs > 0 && !IsEmitNode && !EN->hasChain() &&
1150 !EN->hasInGlue() && EN->hasOutGlue() && !EN->hasMemRefs() &&
1151 EN->getNumFixedArityOperands() == -1) {
1152 CompressNodeInfo = true;
1153 OS << "GlueOutput";
1154 }
1155 }
1156
1157 if (ByHwMode)
1158 OS << "ByHwMode";
1159
1160 const CodeGenInstruction &CGI = EN->getInstruction();
1161 OS << ", TARGET_VAL(" << CGI.Namespace << "::" << CGI.TheDef->getName()
1162 << ")";
1163
1164 if (!CompressNodeInfo) {
1165 OS << ", 0";
1166 if (EN->hasChain())
1167 OS << "|OPFL_Chain";
1168 if (EN->hasInGlue())
1169 OS << "|OPFL_GlueInput";
1170 if (EN->hasOutGlue())
1171 OS << "|OPFL_GlueOutput";
1172 if (EN->hasMemRefs())
1173 OS << "|OPFL_MemRefs";
1174 if (EN->getNumFixedArityOperands() != -1)
1175 OS << "|OPFL_Variadic" << EN->getNumFixedArityOperands();
1176 }
1177 OS << ",\n";
1178
1179 OS.indent(NumSpaces: FullIndexWidth + Indent + 4);
1180 if (!CompressVTs) {
1181 OS << EN->getNumVTs();
1182 if (!OmitComments)
1183 OS << "/*#VTs*/";
1184 OS << ",";
1185 }
1186 unsigned NumTypeBytes = 0;
1187 if (ByHwMode) {
1188 for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i) {
1189 OS << ' ';
1190 const ValueTypeByHwMode &VTBH = EN->getVT(i);
1191 NumTypeBytes += emitValueTypeByHwMode(VTBH, Index: getValueTypeID(VT: VTBH), OS);
1192 }
1193 } else {
1194 for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i) {
1195 OS << ' ';
1196 NumTypeBytes += emitMVT(VT: EN->getVT(i).getSimple(), OS);
1197 }
1198 }
1199
1200 unsigned NumOps = EN->getNumOperands();
1201 OS << ' ' << NumOps;
1202 if (!OmitComments)
1203 OS << "/*#Ops*/";
1204 OS << ',';
1205
1206 unsigned NumOperandBytes = 0;
1207 if (NumOps != 0) {
1208 std::vector<uint8_t> OpBytes;
1209 for (unsigned i = 0, e = EN->getNumOperands(); i != e; ++i) {
1210 uint8_t Buffer[5];
1211 unsigned Len = encodeULEB128(Value: EN->getOperand(i), p: Buffer);
1212 for (unsigned i = 0; i < Len; ++i)
1213 OpBytes.push_back(x: Buffer[i]);
1214 }
1215 unsigned Index = OperandTable.get(Seq: OpBytes);
1216 OS << ' ';
1217 if (!OmitComments)
1218 OS << "/*OperandList*/";
1219 NumOperandBytes = EmitVBRValue(Val: Index, OS);
1220 }
1221
1222 if (!OmitComments) {
1223 // Print the operand #'s.
1224 ArrayRef<unsigned> Ops = EN->getOperandList();
1225 OS << " // Ops =";
1226 if (Ops.empty())
1227 OS << " None";
1228 else
1229 for (unsigned OpNo : Ops)
1230 OS << " #" << OpNo;
1231
1232 // Print the result #'s for EmitNode.
1233 if (const EmitNodeMatcher *E = dyn_cast<EmitNodeMatcher>(Val: EN)) {
1234 if (unsigned NumResults = EN->getNumVTs()) {
1235 OS << " Results =";
1236 unsigned First = E->getFirstResultSlot();
1237 for (unsigned i = 0; i != NumResults; ++i)
1238 OS << " #" << First + i;
1239 }
1240 }
1241 OS << '\n';
1242
1243 if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(Val: N)) {
1244 OS.indent(NumSpaces: FullIndexWidth + Indent)
1245 << "// Src: " << SNT->getPattern().getSrcPattern()
1246 << " - Complexity = " << SNT->getPattern().getPatternComplexity(CGP)
1247 << '\n';
1248 OS.indent(NumSpaces: FullIndexWidth + Indent)
1249 << "// Dst: " << SNT->getPattern().getDstPattern() << '\n';
1250 }
1251 } else {
1252 OS << '\n';
1253 }
1254
1255 return 4 + SupportsDeactivationSymbol + !CompressVTs + !CompressNodeInfo +
1256 NumTypeBytes + NumOperandBytes + NumCoveredBytes;
1257 }
1258 case Matcher::CompleteMatch: {
1259 const CompleteMatchMatcher *CM = cast<CompleteMatchMatcher>(Val: N);
1260 auto NumCoveredBytes = 0;
1261 if (InstrumentCoverage) {
1262 NumCoveredBytes = 3;
1263 OS << "OPC_Coverage, ";
1264 std::string src =
1265 GetPatFromTreePatternNode(N: CM->getPattern().getSrcPattern());
1266 std::string dst =
1267 GetPatFromTreePatternNode(N: CM->getPattern().getDstPattern());
1268 const Record *PatRecord = CM->getPattern().getSrcRecord();
1269 std::string include_src = getIncludePath(R: PatRecord);
1270 unsigned Offset =
1271 getPatternIdxFromTable(P: src + " -> " + dst, include_loc: std::move(include_src));
1272 OS << "COVERAGE_IDX_VAL(" << Offset << "),\n";
1273 OS.indent(NumSpaces: FullIndexWidth + Indent);
1274 }
1275 OS << "OPC_CompleteMatch, " << CM->getNumResults() << ",";
1276 unsigned NumResultBytes = 0;
1277 for (unsigned i = 0, e = CM->getNumResults(); i != e; ++i) {
1278 OS << ' ';
1279 NumResultBytes += EmitVBRValue(Val: CM->getResult(R: i), OS);
1280 }
1281 OS << '\n';
1282 if (!OmitComments) {
1283 OS.indent(NumSpaces: FullIndexWidth + Indent)
1284 << " // Src: " << CM->getPattern().getSrcPattern()
1285 << " - Complexity = " << CM->getPattern().getPatternComplexity(CGP)
1286 << '\n';
1287 OS.indent(NumSpaces: FullIndexWidth + Indent)
1288 << " // Dst: " << CM->getPattern().getDstPattern();
1289 }
1290 OS << '\n';
1291 return 2 + NumResultBytes + NumCoveredBytes;
1292 }
1293 }
1294 llvm_unreachable("Unreachable");
1295}
1296
1297/// This function traverses the matcher tree and emits all the nodes.
1298/// The nodes have already been sized.
1299unsigned MatcherTableEmitter::EmitMatcherList(const MatcherList &ML,
1300 const unsigned Indent,
1301 unsigned CurrentIdx,
1302 raw_ostream &OS) {
1303 unsigned Size = 0;
1304 for (const Matcher *N : ML) {
1305 if (!OmitComments)
1306 OS << "/*" << format_decimal(N: CurrentIdx, Width: IndexWidth) << "*/";
1307 unsigned MatcherSize = EmitMatcher(N, Indent, CurrentIdx, OS);
1308 Size += MatcherSize;
1309 CurrentIdx += MatcherSize;
1310 }
1311 return Size;
1312}
1313
1314void MatcherTableEmitter::EmitOperandLists(raw_ostream &OS) {
1315 OperandTable.emit(OS, Print: [](raw_ostream &OS, uint8_t O) { OS << (unsigned)O; });
1316}
1317
1318void MatcherTableEmitter::EmitNodePredicatesFunction(
1319 const std::vector<TreePattern *> &Preds, StringRef Decl, raw_ostream &OS) {
1320 if (Preds.empty())
1321 return;
1322
1323 BeginEmitFunction(OS, RetType: "bool", Decl, AddOverride: true /*AddOverride*/);
1324 OS << "{\n";
1325 OS << " switch (PredNo) {\n";
1326 OS << " default: llvm_unreachable(\"Invalid predicate in table?\");\n";
1327 for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
1328 // Emit the predicate code corresponding to this pattern.
1329 TreePredicateFn PredFn(Preds[i]);
1330 assert(!PredFn.isAlwaysTrue() && "No code in this predicate");
1331 std::string PredFnCodeStr = PredFn.getCodeToRunOnSDNode();
1332
1333 OS << " case " << i << ": {\n";
1334 for (auto *SimilarPred : NodePredicatesByCodeToRun[PredFnCodeStr])
1335 OS << " // " << TreePredicateFn(SimilarPred).getFnName() << '\n';
1336 OS << PredFnCodeStr << "\n }\n";
1337 }
1338 OS << " }\n";
1339 OS << "}\n";
1340 EndEmitFunction(OS);
1341}
1342
1343void MatcherTableEmitter::EmitPredicateFunctions(raw_ostream &OS) {
1344 // Emit pattern predicates.
1345 if (!PatternPredicates.empty()) {
1346 BeginEmitFunction(OS, RetType: "bool",
1347 Decl: "CheckPatternPredicate(unsigned PredNo) const",
1348 AddOverride: true /*AddOverride*/);
1349 OS << "{\n";
1350 OS << " switch (PredNo) {\n";
1351 OS << " default: llvm_unreachable(\"Invalid predicate in table?\");\n";
1352 for (unsigned i = 0, e = PatternPredicates.size(); i != e; ++i)
1353 OS << " case " << i << ": return " << PatternPredicates[i] << ";\n";
1354 OS << " }\n";
1355 OS << "}\n";
1356 EndEmitFunction(OS);
1357 }
1358
1359 // Emit Node predicates.
1360 EmitNodePredicatesFunction(
1361 Preds: NodePredicates, Decl: "CheckNodePredicate(SDValue Op, unsigned PredNo) const",
1362 OS);
1363 EmitNodePredicatesFunction(
1364 Preds: NodePredicatesWithOperands,
1365 Decl: "CheckNodePredicateWithOperands(SDValue Op, unsigned PredNo, "
1366 "ArrayRef<SDValue> Operands) const",
1367 OS);
1368
1369 // Emit CompletePattern matchers.
1370 // FIXME: This should be const.
1371 if (!ComplexPatterns.empty()) {
1372 BeginEmitFunction(
1373 OS, RetType: "bool",
1374 Decl: "CheckComplexPattern(SDNode *Root, SDNode *Parent,\n"
1375 " SDValue N, unsigned PatternNo,\n"
1376 " SmallVectorImpl<std::pair<SDValue, SDNode *>> &Result)",
1377 AddOverride: true /*AddOverride*/);
1378 OS << "{\n";
1379 OS << " unsigned NextRes = Result.size();\n";
1380 OS << " switch (PatternNo) {\n";
1381 OS << " default: llvm_unreachable(\"Invalid pattern # in table?\");\n";
1382 for (unsigned i = 0, e = ComplexPatterns.size(); i != e; ++i) {
1383 const ComplexPattern &P = *ComplexPatterns[i];
1384 unsigned NumOps = P.getNumOperands();
1385
1386 if (P.hasProperty(Prop: SDNPHasChain))
1387 ++NumOps; // Get the chained node too.
1388
1389 OS << " case " << i << ":\n";
1390 if (InstrumentCoverage)
1391 OS << " {\n";
1392 OS << " Result.resize(NextRes+" << NumOps << ");\n";
1393 if (InstrumentCoverage)
1394 OS << " bool Succeeded = " << P.getSelectFunc();
1395 else
1396 OS << " return " << P.getSelectFunc();
1397
1398 OS << "(";
1399 // If the complex pattern wants the root of the match, pass it in as the
1400 // first argument.
1401 if (P.wantsRoot())
1402 OS << "Root, ";
1403
1404 // If the complex pattern wants the parent of the operand being matched,
1405 // pass it in as the next argument.
1406 if (P.wantsParent())
1407 OS << "Parent, ";
1408
1409 OS << "N";
1410 for (unsigned i = 0; i != NumOps; ++i)
1411 OS << ", Result[NextRes+" << i << "].first";
1412 OS << ");\n";
1413 if (InstrumentCoverage) {
1414 OS << " if (Succeeded)\n";
1415 OS << " dbgs() << \"\\nCOMPLEX_PATTERN: " << P.getSelectFunc()
1416 << "\\n\" ;\n";
1417 OS << " return Succeeded;\n";
1418 OS << " }\n";
1419 }
1420 }
1421 OS << " }\n";
1422 OS << "}\n";
1423 EndEmitFunction(OS);
1424 }
1425
1426 // Emit SDNodeXForm handlers.
1427 // FIXME: This should be const.
1428 if (!NodeXForms.empty()) {
1429 BeginEmitFunction(OS, RetType: "SDValue",
1430 Decl: "RunSDNodeXForm(SDValue V, unsigned XFormNo)",
1431 AddOverride: true /*AddOverride*/);
1432 OS << "{\n";
1433 OS << " switch (XFormNo) {\n";
1434 OS << " default: llvm_unreachable(\"Invalid xform # in table?\");\n";
1435
1436 // FIXME: The node xform could take SDValue's instead of SDNode*'s.
1437 for (unsigned i = 0, e = NodeXForms.size(); i != e; ++i) {
1438 const CodeGenDAGPatterns::NodeXForm &Entry =
1439 CGP.getSDNodeTransform(R: NodeXForms[i]);
1440
1441 const Record *SDNode = Entry.first;
1442 const std::string &Code = Entry.second;
1443
1444 OS << " case " << i << ": { ";
1445 if (!OmitComments)
1446 OS << "// " << NodeXForms[i]->getName();
1447 OS << '\n';
1448
1449 std::string ClassName = CGP.getSDNodeInfo(R: SDNode).getSDClassName().str();
1450 if (ClassName == "SDNode")
1451 OS << " SDNode *N = V.getNode();\n";
1452 else
1453 OS << " " << ClassName << " *N = cast<" << ClassName
1454 << ">(V.getNode());\n";
1455 OS << Code << "\n }\n";
1456 }
1457 OS << " }\n";
1458 OS << "}\n";
1459 EndEmitFunction(OS);
1460 }
1461}
1462
1463void MatcherTableEmitter::EmitValueTypeFunction(raw_ostream &OS) {
1464 if (ValueTypeMap.empty())
1465 return;
1466
1467 BeginEmitFunction(OS, RetType: "MVT", Decl: "getValueTypeForHwMode(unsigned Index) const",
1468 /*AddOverride=*/true);
1469 OS << "{\n";
1470
1471 OS << " switch (Index) {\n";
1472 OS << " default: llvm_unreachable(\"Unexpected index\");\n";
1473
1474 for (const auto &[VTs, IdxAndCount] : ValueTypeMap) {
1475 const auto &[Idx, Count] = IdxAndCount;
1476 OS << " case " << (Idx - 1) << ":\n";
1477 if (VTs.isSimple()) {
1478 OS << " return " << getEnumName(T: VTs.getSimple()) << ";\n";
1479 } else {
1480 OS << " switch (HwMode) {\n";
1481 if (!VTs.hasDefault())
1482 OS << " default:\n return MVT();\n";
1483 for (const auto [Mode, VT] : VTs) {
1484 if (Mode == DefaultMode)
1485 OS << " default:\n";
1486 else
1487 OS << " case " << Mode << ":\n";
1488 OS << " return " << getEnumName(T: VT) << ";\n";
1489 }
1490
1491 OS << " }\n";
1492 OS << " break;\n";
1493 }
1494 }
1495
1496 OS << " }\n";
1497
1498 OS << "}\n";
1499 EndEmitFunction(OS);
1500}
1501
1502static StringRef getOpcodeString(Matcher::KindTy Kind) {
1503 switch (Kind) {
1504 case Matcher::Scope:
1505 return "OPC_Scope";
1506 case Matcher::RecordNode:
1507 return "OPC_RecordNode";
1508 case Matcher::RecordChild:
1509 return "OPC_RecordChild";
1510 case Matcher::RecordMemRef:
1511 return "OPC_RecordMemRef";
1512 case Matcher::CaptureGlueInput:
1513 return "OPC_CaptureGlueInput";
1514 case Matcher::MoveChild:
1515 return "OPC_MoveChild";
1516 case Matcher::MoveSibling:
1517 return "OPC_MoveSibling";
1518 case Matcher::MoveParent:
1519 return "OPC_MoveParent";
1520 case Matcher::CheckSame:
1521 return "OPC_CheckSame";
1522 case Matcher::CheckChildSame:
1523 return "OPC_CheckChildSame";
1524 case Matcher::CheckPatternPredicate:
1525 return "OPC_CheckPatternPredicate";
1526 case Matcher::CheckPredicate:
1527 return "OPC_CheckPredicate";
1528 case Matcher::CheckOpcode:
1529 return "OPC_CheckOpcode";
1530 case Matcher::SwitchOpcode:
1531 return "OPC_SwitchOpcode";
1532 case Matcher::CheckType:
1533 return "OPC_CheckType";
1534 case Matcher::SwitchType:
1535 return "OPC_SwitchType";
1536 case Matcher::CheckChildType:
1537 return "OPC_CheckChildType";
1538 case Matcher::CheckInteger:
1539 return "OPC_CheckInteger";
1540 case Matcher::CheckChildInteger:
1541 return "OPC_CheckChildInteger";
1542 case Matcher::CheckCondCode:
1543 return "OPC_CheckCondCode";
1544 case Matcher::CheckChild2CondCode:
1545 return "OPC_CheckChild2CondCode";
1546 case Matcher::CheckValueType:
1547 return "OPC_CheckValueType";
1548 case Matcher::CheckComplexPat:
1549 return "OPC_CheckComplexPat";
1550 case Matcher::CheckAndImm:
1551 return "OPC_CheckAndImm";
1552 case Matcher::CheckOrImm:
1553 return "OPC_CheckOrImm";
1554 case Matcher::CheckFoldableChainNode:
1555 return "OPC_CheckFoldableChainNode";
1556 case Matcher::CheckImmAllOnesV:
1557 return "OPC_CheckImmAllOnesV";
1558 case Matcher::CheckImmAllZerosV:
1559 return "OPC_CheckImmAllZerosV";
1560 case Matcher::EmitInteger:
1561 return "OPC_EmitInteger";
1562 case Matcher::EmitRegister:
1563 return "OPC_EmitRegister";
1564 case Matcher::EmitConvertToTarget:
1565 return "OPC_EmitConvertToTarget";
1566 case Matcher::EmitMergeInputChains:
1567 return "OPC_EmitMergeInputChains";
1568 case Matcher::EmitCopyToReg:
1569 return "OPC_EmitCopyToReg";
1570 case Matcher::EmitNode:
1571 return "OPC_EmitNode";
1572 case Matcher::MorphNodeTo:
1573 return "OPC_MorphNodeTo";
1574 case Matcher::EmitNodeXForm:
1575 return "OPC_EmitNodeXForm";
1576 case Matcher::CompleteMatch:
1577 return "OPC_CompleteMatch";
1578 }
1579
1580 llvm_unreachable("Unhandled opcode?");
1581}
1582
1583void MatcherTableEmitter::EmitHistogram(raw_ostream &OS) {
1584 if (OmitComments)
1585 return;
1586
1587 OS << " // Opcode Histogram:\n";
1588 for (unsigned i = 0, e = OpcodeCounts.size(); i != e; ++i) {
1589 OS << " // #"
1590 << left_justify(Str: getOpcodeString(Kind: (Matcher::KindTy)i), Width: HistOpcWidth)
1591 << " = " << OpcodeCounts[i] << '\n';
1592 }
1593 OS << '\n';
1594}
1595
1596void llvm::EmitMatcherTable(MatcherList &TheMatcherList,
1597 const CodeGenDAGPatterns &CGP, raw_ostream &OS) {
1598 OS << "#if defined(GET_DAGISEL_DECL) && defined(GET_DAGISEL_BODY)\n";
1599 OS << "#error GET_DAGISEL_DECL and GET_DAGISEL_BODY cannot be both defined, ";
1600 OS << "undef both for inline definitions\n";
1601 OS << "#endif\n\n";
1602
1603 // Emit a check for omitted class name.
1604 OS << "#ifdef GET_DAGISEL_BODY\n";
1605 OS << "#define LOCAL_DAGISEL_STRINGIZE(X) LOCAL_DAGISEL_STRINGIZE_(X)\n";
1606 OS << "#define LOCAL_DAGISEL_STRINGIZE_(X) #X\n";
1607 OS << "static_assert(sizeof(LOCAL_DAGISEL_STRINGIZE(GET_DAGISEL_BODY)) > 1,"
1608 "\n";
1609 OS << " \"GET_DAGISEL_BODY is empty: it should be defined with the class "
1610 "name\");\n";
1611 OS << "#undef LOCAL_DAGISEL_STRINGIZE_\n";
1612 OS << "#undef LOCAL_DAGISEL_STRINGIZE\n";
1613 OS << "#endif\n\n";
1614
1615 OS << "#if !defined(GET_DAGISEL_DECL) && !defined(GET_DAGISEL_BODY)\n";
1616 OS << "#define DAGISEL_INLINE 1\n";
1617 OS << "#else\n";
1618 OS << "#define DAGISEL_INLINE 0\n";
1619 OS << "#endif\n\n";
1620
1621 OS << "#if !DAGISEL_INLINE\n";
1622 OS << "#define DAGISEL_CLASS_COLONCOLON GET_DAGISEL_BODY ::\n";
1623 OS << "#else\n";
1624 OS << "#define DAGISEL_CLASS_COLONCOLON\n";
1625 OS << "#endif\n\n";
1626
1627 BeginEmitFunction(OS, RetType: "void", Decl: "SelectCode(SDNode *N)", AddOverride: false /*AddOverride*/);
1628 MatcherTableEmitter MatcherEmitter(TheMatcherList, CGP);
1629
1630 // First we size all the children of the three kinds of matchers that have
1631 // them. This is done by sharing the code in EmitMatcher(). but we don't
1632 // want to emit anything, so we turn off comments and use a null stream.
1633 bool SaveOmitComments = OmitComments;
1634 OmitComments = true;
1635 raw_null_ostream NullOS;
1636 unsigned TotalSize = MatcherEmitter.SizeMatcherList(ML&: TheMatcherList, OS&: NullOS);
1637 OmitComments = SaveOmitComments;
1638
1639 // Now that the matchers are sized, we can emit the code for them to the
1640 // final stream.
1641 OS << "{\n";
1642 OS << " // Some target values are emitted as 2 bytes, TARGET_VAL handles\n";
1643 OS << " // this. Coverage indexes are emitted as 4 bytes,\n";
1644 OS << " // COVERAGE_IDX_VAL handles this.\n";
1645 OS << " #define TARGET_VAL(X) X & 255, unsigned(X) >> 8\n";
1646 OS << " #define COVERAGE_IDX_VAL(X) X & 255, (unsigned(X) >> 8) & 255, ";
1647 OS << "(unsigned(X) >> 16) & 255, (unsigned(X) >> 24) & 255\n";
1648 OS << " static const uint8_t MatcherTable[] = {\n";
1649 TotalSize = MatcherEmitter.EmitMatcherList(ML: TheMatcherList, Indent: 1, CurrentIdx: 0, OS);
1650 OS << " }; // Total Array size is " << TotalSize << " bytes\n\n";
1651
1652 MatcherEmitter.EmitHistogram(OS);
1653
1654 OS << " static const uint8_t OperandLists[] = {\n";
1655 MatcherEmitter.EmitOperandLists(OS);
1656 OS << " };\n\n";
1657
1658 OS << " #undef COVERAGE_IDX_VAL\n";
1659 OS << " #undef TARGET_VAL\n";
1660 OS << " SelectCodeCommon(N, MatcherTable, sizeof(MatcherTable),\n";
1661 OS << " OperandLists);\n";
1662 OS << "}\n";
1663 EndEmitFunction(OS);
1664
1665 // Next up, emit the function for node and pattern predicates:
1666 MatcherEmitter.EmitPredicateFunctions(OS);
1667
1668 MatcherEmitter.EmitValueTypeFunction(OS);
1669
1670 if (InstrumentCoverage)
1671 MatcherEmitter.EmitPatternMatchTable(OS);
1672
1673 // Clean up the preprocessor macros.
1674 OS << "\n";
1675 OS << "#ifdef DAGISEL_INLINE\n";
1676 OS << "#undef DAGISEL_INLINE\n";
1677 OS << "#endif\n";
1678 OS << "#ifdef DAGISEL_CLASS_COLONCOLON\n";
1679 OS << "#undef DAGISEL_CLASS_COLONCOLON\n";
1680 OS << "#endif\n";
1681 OS << "#ifdef GET_DAGISEL_DECL\n";
1682 OS << "#undef GET_DAGISEL_DECL\n";
1683 OS << "#endif\n";
1684 OS << "#ifdef GET_DAGISEL_BODY\n";
1685 OS << "#undef GET_DAGISEL_BODY\n";
1686 OS << "#endif\n";
1687}
1688