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::CheckUndef:
923 OS << "OPC_CheckUndef,\n";
924 return 1;
925
926 case Matcher::EmitInteger: {
927 const auto *IM = cast<EmitIntegerMatcher>(Val: N);
928 int64_t Val = IM->getValue();
929 const std::string &Str = IM->getString();
930 const ValueTypeByHwMode &VTBH = IM->getVT();
931 unsigned TypeBytes = 0;
932 if (VTBH.isSimple()) {
933 MVT VT = VTBH.getSimple();
934 switch (VT.SimpleTy) {
935 case MVT::i8:
936 case MVT::i16:
937 case MVT::i32:
938 case MVT::i64:
939 OS << "OPC_EmitIntegerI" << VT.getSizeInBits() << ", ";
940 break;
941 default:
942 OS << "OPC_EmitInteger, ";
943 TypeBytes = emitMVT(VT, OS);
944 OS << ' ';
945 break;
946 }
947 } else {
948 unsigned Index = getValueTypeID(VT: VTBH);
949 if (Index == 0) {
950 OS << "OPC_EmitIntegerByHwMode0";
951 if (!OmitComments)
952 OS << "/*" << VTBH << "*/";
953 OS << ", ";
954 TypeBytes = 0;
955 } else {
956 OS << "OPC_EmitIntegerByHwMode, ";
957 TypeBytes = emitValueTypeByHwMode(VTBH, Index, OS);
958 OS << ' ';
959 }
960 }
961 // If the value is 63 or smaller, use the string directly. Otherwise, use
962 // a VBR.
963 unsigned ValBytes = 1;
964 if (!Str.empty() && Val <= 63)
965 OS << Str << ',';
966 else
967 ValBytes = EmitSignedVBRValue(Val, OS);
968 if (!OmitComments) {
969 OS << " // #" << IM->getResultNo() << " = ";
970 if (!Str.empty())
971 OS << Str;
972 else
973 OS << Val;
974 }
975 OS << '\n';
976 return 1 + TypeBytes + ValBytes;
977 }
978
979 case Matcher::EmitRegister: {
980 const EmitRegisterMatcher *Matcher = cast<EmitRegisterMatcher>(Val: N);
981 const CodeGenRegister *Reg = Matcher->getReg();
982 const ValueTypeByHwMode &VTBH = Matcher->getVT();
983 unsigned OpBytes;
984 if (VTBH.isSimple()) {
985 MVT VT = VTBH.getSimple();
986 // If the enum value of the register is larger than one byte can handle,
987 // use EmitRegister2.
988 if (Reg && Reg->EnumValue > 255) {
989 OS << "OPC_EmitRegister2, ";
990 OpBytes = emitMVT(VT, OS);
991 OS << " TARGET_VAL(" << getQualifiedName(R: Reg->TheDef) << "),\n";
992 return OpBytes + 3;
993 }
994 switch (VT.SimpleTy) {
995 case MVT::i32:
996 case MVT::i64:
997 OpBytes = 1;
998 OS << "OPC_EmitRegisterI" << VT.getSizeInBits() << ", ";
999 break;
1000 default:
1001 OS << "OPC_EmitRegister, ";
1002 OpBytes = emitMVT(VT, OS) + 1;
1003 OS << ' ';
1004 break;
1005 }
1006 } else {
1007 if (Reg && Reg->EnumValue > 255) {
1008 OS << "OPC_EmitRegisterByHwMode2, ";
1009 OpBytes = emitValueTypeByHwMode(VTBH, Index: getValueTypeID(VT: VTBH), OS);
1010 OS << " TARGET_VAL(" << getQualifiedName(R: Reg->TheDef) << "),\n";
1011 return OpBytes + 3;
1012 }
1013
1014 OS << "OPC_EmitRegisterByHwMode, ";
1015 OpBytes = emitValueTypeByHwMode(VTBH, Index: getValueTypeID(VT: VTBH), OS) + 1;
1016 OS << ' ';
1017 }
1018 if (Reg)
1019 OS << getQualifiedName(R: Reg->TheDef);
1020 else
1021 OS << "MCRegister::NoRegister";
1022
1023 OS << ',';
1024 if (!OmitComments)
1025 OS << " // #" << Matcher->getResultNo();
1026 OS << '\n';
1027 return OpBytes + 1;
1028 }
1029
1030 case Matcher::EmitConvertToTarget: {
1031 const auto *CTTM = cast<EmitConvertToTargetMatcher>(Val: N);
1032 unsigned Slot = CTTM->getSlot();
1033 OS << "OPC_EmitConvertToTarget";
1034 if (Slot >= 8)
1035 OS << ", ";
1036 OS << Slot << ',';
1037 if (!OmitComments)
1038 OS << " // #" << CTTM->getResultNo() << " = ConvertToTarget #" << Slot;
1039 OS << '\n';
1040 return 1 + (Slot >= 8);
1041 }
1042
1043 case Matcher::EmitMergeInputChains: {
1044 const EmitMergeInputChainsMatcher *MN =
1045 cast<EmitMergeInputChainsMatcher>(Val: N);
1046
1047 // Handle the specialized forms OPC_EmitMergeInputChains1_0, 1_1, and 1_2.
1048 if (MN->getNumNodes() == 1 && MN->getNode(i: 0) < 3) {
1049 OS << "OPC_EmitMergeInputChains1_" << MN->getNode(i: 0) << ",\n";
1050 return 1;
1051 }
1052
1053 OS << "OPC_EmitMergeInputChains, " << MN->getNumNodes() << ',';
1054 for (unsigned i = 0, e = MN->getNumNodes(); i != e; ++i)
1055 OS << ' ' << MN->getNode(i) << ",";
1056 OS << '\n';
1057 return 2 + MN->getNumNodes();
1058 }
1059 case Matcher::EmitCopyToReg: {
1060 const auto *C2RMatcher = cast<EmitCopyToRegMatcher>(Val: N);
1061 int Bytes = 3;
1062 const CodeGenRegister *Reg = C2RMatcher->getDestPhysReg();
1063 unsigned Slot = C2RMatcher->getSrcSlot();
1064 if (Reg->EnumValue > 255) {
1065 assert(isUInt<16>(Reg->EnumValue) && "not handled");
1066 OS << "OPC_EmitCopyToRegTwoByte, " << Slot << ", "
1067 << "TARGET_VAL(" << getQualifiedName(R: Reg->TheDef) << "),";
1068 ++Bytes;
1069 } else {
1070 if (Slot < 8) {
1071 OS << "OPC_EmitCopyToReg" << Slot << ", "
1072 << getQualifiedName(R: Reg->TheDef) << ",";
1073 --Bytes;
1074 } else {
1075 OS << "OPC_EmitCopyToReg, " << Slot << ", "
1076 << getQualifiedName(R: Reg->TheDef) << ",";
1077 }
1078 }
1079 if (!OmitComments)
1080 OS << " // = #" << Slot;
1081
1082 OS << '\n';
1083 return Bytes;
1084 }
1085 case Matcher::EmitNodeXForm: {
1086 const EmitNodeXFormMatcher *XF = cast<EmitNodeXFormMatcher>(Val: N);
1087 OS << "OPC_EmitNodeXForm, " << getNodeXFormID(Rec: XF->getNodeXForm()) << ", "
1088 << XF->getSlot() << ',';
1089 if (!OmitComments)
1090 OS << " // #" << XF->getResultNo() << " = "
1091 << XF->getNodeXForm()->getName() << " #" << XF->getSlot();
1092 OS << '\n';
1093 return 3;
1094 }
1095
1096 case Matcher::EmitNode:
1097 case Matcher::MorphNodeTo: {
1098 auto NumCoveredBytes = 0;
1099 if (InstrumentCoverage) {
1100 if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(Val: N)) {
1101 NumCoveredBytes = 3;
1102 OS << "OPC_Coverage, ";
1103 std::string src =
1104 GetPatFromTreePatternNode(N: SNT->getPattern().getSrcPattern());
1105 std::string dst =
1106 GetPatFromTreePatternNode(N: SNT->getPattern().getDstPattern());
1107 const Record *PatRecord = SNT->getPattern().getSrcRecord();
1108 std::string include_src = getIncludePath(R: PatRecord);
1109 unsigned Offset =
1110 getPatternIdxFromTable(P: src + " -> " + dst, include_loc: std::move(include_src));
1111 OS << "COVERAGE_IDX_VAL(" << Offset << "),\n";
1112 OS.indent(NumSpaces: FullIndexWidth + Indent);
1113 }
1114 }
1115 const EmitNodeMatcherCommon *EN = cast<EmitNodeMatcherCommon>(Val: N);
1116 bool SupportsDeactivationSymbol =
1117 EN->getInstruction().TheDef->getValueAsBit(
1118 FieldName: "supportsDeactivationSymbol");
1119 if (SupportsDeactivationSymbol) {
1120 OS << "OPC_CaptureDeactivationSymbol,\n";
1121 OS.indent(NumSpaces: FullIndexWidth + Indent);
1122 }
1123
1124 bool ByHwMode =
1125 llvm::any_of(Range: EN->getVTList(), P: [](const ValueTypeByHwMode &VT) {
1126 return !VT.isSimple();
1127 });
1128
1129 bool IsEmitNode = isa<EmitNodeMatcher>(Val: EN);
1130 OS << (IsEmitNode ? "OPC_EmitNode" : "OPC_MorphNodeTo");
1131 unsigned NumVTs = EN->getNumVTs();
1132 bool CompressVTs = !ByHwMode && EN->getNumVTs() < 3;
1133 bool CompressNodeInfo = false;
1134 if (CompressVTs) {
1135 OS << NumVTs;
1136 // When NumVTs is zero, only consider compressing the chain flag. Any
1137 // zero result node without chain would be deleted and not eligible for
1138 // isel.
1139 if (NumVTs > 0 && !EN->hasChain() && !EN->hasInGlue() &&
1140 !EN->hasOutGlue() && !EN->hasMemRefs() &&
1141 EN->getNumFixedArityOperands() == -1) {
1142 CompressNodeInfo = true;
1143 OS << "None";
1144 } else if (EN->hasChain() && !EN->hasInGlue() && !EN->hasOutGlue() &&
1145 !EN->hasMemRefs() && EN->getNumFixedArityOperands() == -1) {
1146 CompressNodeInfo = true;
1147 OS << "Chain";
1148 } else if (NumVTs > 0 && !IsEmitNode && !EN->hasChain() &&
1149 EN->hasInGlue() && !EN->hasOutGlue() && !EN->hasMemRefs() &&
1150 EN->getNumFixedArityOperands() == -1) {
1151 CompressNodeInfo = true;
1152 OS << "GlueInput";
1153 } else if (NumVTs > 0 && !IsEmitNode && !EN->hasChain() &&
1154 !EN->hasInGlue() && EN->hasOutGlue() && !EN->hasMemRefs() &&
1155 EN->getNumFixedArityOperands() == -1) {
1156 CompressNodeInfo = true;
1157 OS << "GlueOutput";
1158 }
1159 }
1160
1161 if (ByHwMode)
1162 OS << "ByHwMode";
1163
1164 const CodeGenInstruction &CGI = EN->getInstruction();
1165 OS << ", TARGET_VAL(" << CGI.Namespace << "::" << CGI.TheDef->getName()
1166 << ")";
1167
1168 if (!CompressNodeInfo) {
1169 OS << ", 0";
1170 if (EN->hasChain())
1171 OS << "|OPFL_Chain";
1172 if (EN->hasInGlue())
1173 OS << "|OPFL_GlueInput";
1174 if (EN->hasOutGlue())
1175 OS << "|OPFL_GlueOutput";
1176 if (EN->hasMemRefs())
1177 OS << "|OPFL_MemRefs";
1178 if (EN->getNumFixedArityOperands() != -1)
1179 OS << "|OPFL_Variadic" << EN->getNumFixedArityOperands();
1180 }
1181 OS << ",\n";
1182
1183 OS.indent(NumSpaces: FullIndexWidth + Indent + 4);
1184 if (!CompressVTs) {
1185 OS << EN->getNumVTs();
1186 if (!OmitComments)
1187 OS << "/*#VTs*/";
1188 OS << ",";
1189 }
1190 unsigned NumTypeBytes = 0;
1191 if (ByHwMode) {
1192 for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i) {
1193 OS << ' ';
1194 const ValueTypeByHwMode &VTBH = EN->getVT(i);
1195 NumTypeBytes += emitValueTypeByHwMode(VTBH, Index: getValueTypeID(VT: VTBH), OS);
1196 }
1197 } else {
1198 for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i) {
1199 OS << ' ';
1200 NumTypeBytes += emitMVT(VT: EN->getVT(i).getSimple(), OS);
1201 }
1202 }
1203
1204 unsigned NumOps = EN->getNumOperands();
1205 OS << ' ' << NumOps;
1206 if (!OmitComments)
1207 OS << "/*#Ops*/";
1208 OS << ',';
1209
1210 unsigned NumOperandBytes = 0;
1211 if (NumOps != 0) {
1212 std::vector<uint8_t> OpBytes;
1213 for (unsigned i = 0, e = EN->getNumOperands(); i != e; ++i) {
1214 uint8_t Buffer[5];
1215 unsigned Len = encodeULEB128(Value: EN->getOperand(i), p: Buffer);
1216 for (unsigned i = 0; i < Len; ++i)
1217 OpBytes.push_back(x: Buffer[i]);
1218 }
1219 unsigned Index = OperandTable.get(Seq: OpBytes);
1220 OS << ' ';
1221 if (!OmitComments)
1222 OS << "/*OperandList*/";
1223 NumOperandBytes = EmitVBRValue(Val: Index, OS);
1224 }
1225
1226 if (!OmitComments) {
1227 // Print the operand #'s.
1228 ArrayRef<unsigned> Ops = EN->getOperandList();
1229 OS << " // Ops =";
1230 if (Ops.empty())
1231 OS << " None";
1232 else
1233 for (unsigned OpNo : Ops)
1234 OS << " #" << OpNo;
1235
1236 // Print the result #'s for EmitNode.
1237 if (const EmitNodeMatcher *E = dyn_cast<EmitNodeMatcher>(Val: EN)) {
1238 if (unsigned NumResults = EN->getNumVTs()) {
1239 OS << " Results =";
1240 unsigned First = E->getFirstResultSlot();
1241 for (unsigned i = 0; i != NumResults; ++i)
1242 OS << " #" << First + i;
1243 }
1244 }
1245 OS << '\n';
1246
1247 if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(Val: N)) {
1248 OS.indent(NumSpaces: FullIndexWidth + Indent)
1249 << "// Src: " << SNT->getPattern().getSrcPattern()
1250 << " - Complexity = " << SNT->getPattern().getPatternComplexity(CGP)
1251 << '\n';
1252 OS.indent(NumSpaces: FullIndexWidth + Indent)
1253 << "// Dst: " << SNT->getPattern().getDstPattern() << '\n';
1254 }
1255 } else {
1256 OS << '\n';
1257 }
1258
1259 return 4 + SupportsDeactivationSymbol + !CompressVTs + !CompressNodeInfo +
1260 NumTypeBytes + NumOperandBytes + NumCoveredBytes;
1261 }
1262 case Matcher::CompleteMatch: {
1263 const CompleteMatchMatcher *CM = cast<CompleteMatchMatcher>(Val: N);
1264 auto NumCoveredBytes = 0;
1265 if (InstrumentCoverage) {
1266 NumCoveredBytes = 3;
1267 OS << "OPC_Coverage, ";
1268 std::string src =
1269 GetPatFromTreePatternNode(N: CM->getPattern().getSrcPattern());
1270 std::string dst =
1271 GetPatFromTreePatternNode(N: CM->getPattern().getDstPattern());
1272 const Record *PatRecord = CM->getPattern().getSrcRecord();
1273 std::string include_src = getIncludePath(R: PatRecord);
1274 unsigned Offset =
1275 getPatternIdxFromTable(P: src + " -> " + dst, include_loc: std::move(include_src));
1276 OS << "COVERAGE_IDX_VAL(" << Offset << "),\n";
1277 OS.indent(NumSpaces: FullIndexWidth + Indent);
1278 }
1279 OS << "OPC_CompleteMatch, " << CM->getNumResults() << ",";
1280 unsigned NumResultBytes = 0;
1281 for (unsigned i = 0, e = CM->getNumResults(); i != e; ++i) {
1282 OS << ' ';
1283 NumResultBytes += EmitVBRValue(Val: CM->getResult(R: i), OS);
1284 }
1285 OS << '\n';
1286 if (!OmitComments) {
1287 OS.indent(NumSpaces: FullIndexWidth + Indent)
1288 << " // Src: " << CM->getPattern().getSrcPattern()
1289 << " - Complexity = " << CM->getPattern().getPatternComplexity(CGP)
1290 << '\n';
1291 OS.indent(NumSpaces: FullIndexWidth + Indent)
1292 << " // Dst: " << CM->getPattern().getDstPattern();
1293 }
1294 OS << '\n';
1295 return 2 + NumResultBytes + NumCoveredBytes;
1296 }
1297 }
1298 llvm_unreachable("Unreachable");
1299}
1300
1301/// This function traverses the matcher tree and emits all the nodes.
1302/// The nodes have already been sized.
1303unsigned MatcherTableEmitter::EmitMatcherList(const MatcherList &ML,
1304 const unsigned Indent,
1305 unsigned CurrentIdx,
1306 raw_ostream &OS) {
1307 unsigned Size = 0;
1308 for (const Matcher *N : ML) {
1309 if (!OmitComments)
1310 OS << "/*" << format_decimal(N: CurrentIdx, Width: IndexWidth) << "*/";
1311 unsigned MatcherSize = EmitMatcher(N, Indent, CurrentIdx, OS);
1312 Size += MatcherSize;
1313 CurrentIdx += MatcherSize;
1314 }
1315 return Size;
1316}
1317
1318void MatcherTableEmitter::EmitOperandLists(raw_ostream &OS) {
1319 OperandTable.emit(OS, Print: [](raw_ostream &OS, uint8_t O) { OS << (unsigned)O; });
1320}
1321
1322void MatcherTableEmitter::EmitNodePredicatesFunction(
1323 const std::vector<TreePattern *> &Preds, StringRef Decl, raw_ostream &OS) {
1324 if (Preds.empty())
1325 return;
1326
1327 BeginEmitFunction(OS, RetType: "bool", Decl, AddOverride: true /*AddOverride*/);
1328 OS << "{\n";
1329 OS << " switch (PredNo) {\n";
1330 OS << " default: llvm_unreachable(\"Invalid predicate in table?\");\n";
1331 for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
1332 // Emit the predicate code corresponding to this pattern.
1333 TreePredicateFn PredFn(Preds[i]);
1334 assert(!PredFn.isAlwaysTrue() && "No code in this predicate");
1335 std::string PredFnCodeStr = PredFn.getCodeToRunOnSDNode();
1336
1337 OS << " case " << i << ": {\n";
1338 for (auto *SimilarPred : NodePredicatesByCodeToRun[PredFnCodeStr])
1339 OS << " // " << TreePredicateFn(SimilarPred).getFnName() << '\n';
1340 OS << PredFnCodeStr << "\n }\n";
1341 }
1342 OS << " }\n";
1343 OS << "}\n";
1344 EndEmitFunction(OS);
1345}
1346
1347void MatcherTableEmitter::EmitPredicateFunctions(raw_ostream &OS) {
1348 // Emit pattern predicates.
1349 if (!PatternPredicates.empty()) {
1350 BeginEmitFunction(OS, RetType: "bool",
1351 Decl: "CheckPatternPredicate(unsigned PredNo) const",
1352 AddOverride: true /*AddOverride*/);
1353 OS << "{\n";
1354 OS << " switch (PredNo) {\n";
1355 OS << " default: llvm_unreachable(\"Invalid predicate in table?\");\n";
1356 for (unsigned i = 0, e = PatternPredicates.size(); i != e; ++i)
1357 OS << " case " << i << ": return " << PatternPredicates[i] << ";\n";
1358 OS << " }\n";
1359 OS << "}\n";
1360 EndEmitFunction(OS);
1361 }
1362
1363 // Emit Node predicates.
1364 EmitNodePredicatesFunction(
1365 Preds: NodePredicates, Decl: "CheckNodePredicate(SDValue Op, unsigned PredNo) const",
1366 OS);
1367 EmitNodePredicatesFunction(
1368 Preds: NodePredicatesWithOperands,
1369 Decl: "CheckNodePredicateWithOperands(SDValue Op, unsigned PredNo, "
1370 "ArrayRef<SDValue> Operands) const",
1371 OS);
1372
1373 // Emit CompletePattern matchers.
1374 // FIXME: This should be const.
1375 if (!ComplexPatterns.empty()) {
1376 BeginEmitFunction(
1377 OS, RetType: "bool",
1378 Decl: "CheckComplexPattern(SDNode *Root, SDNode *Parent,\n"
1379 " SDValue N, unsigned PatternNo,\n"
1380 " SmallVectorImpl<std::pair<SDValue, SDNode *>> &Result)",
1381 AddOverride: true /*AddOverride*/);
1382 OS << "{\n";
1383 OS << " unsigned NextRes = Result.size();\n";
1384 OS << " switch (PatternNo) {\n";
1385 OS << " default: llvm_unreachable(\"Invalid pattern # in table?\");\n";
1386 for (unsigned i = 0, e = ComplexPatterns.size(); i != e; ++i) {
1387 const ComplexPattern &P = *ComplexPatterns[i];
1388 unsigned NumOps = P.getNumOperands();
1389
1390 if (P.hasProperty(Prop: SDNPHasChain))
1391 ++NumOps; // Get the chained node too.
1392
1393 OS << " case " << i << ":\n";
1394 if (InstrumentCoverage)
1395 OS << " {\n";
1396 OS << " Result.resize(NextRes+" << NumOps << ");\n";
1397 if (InstrumentCoverage)
1398 OS << " bool Succeeded = " << P.getSelectFunc();
1399 else
1400 OS << " return " << P.getSelectFunc();
1401
1402 OS << "(";
1403 // If the complex pattern wants the root of the match, pass it in as the
1404 // first argument.
1405 if (P.wantsRoot())
1406 OS << "Root, ";
1407
1408 // If the complex pattern wants the parent of the operand being matched,
1409 // pass it in as the next argument.
1410 if (P.wantsParent())
1411 OS << "Parent, ";
1412
1413 OS << "N";
1414 for (unsigned i = 0; i != NumOps; ++i)
1415 OS << ", Result[NextRes+" << i << "].first";
1416 OS << ");\n";
1417 if (InstrumentCoverage) {
1418 OS << " if (Succeeded)\n";
1419 OS << " dbgs() << \"\\nCOMPLEX_PATTERN: " << P.getSelectFunc()
1420 << "\\n\" ;\n";
1421 OS << " return Succeeded;\n";
1422 OS << " }\n";
1423 }
1424 }
1425 OS << " }\n";
1426 OS << "}\n";
1427 EndEmitFunction(OS);
1428 }
1429
1430 // Emit SDNodeXForm handlers.
1431 // FIXME: This should be const.
1432 if (!NodeXForms.empty()) {
1433 BeginEmitFunction(OS, RetType: "SDValue",
1434 Decl: "RunSDNodeXForm(SDValue V, unsigned XFormNo)",
1435 AddOverride: true /*AddOverride*/);
1436 OS << "{\n";
1437 OS << " switch (XFormNo) {\n";
1438 OS << " default: llvm_unreachable(\"Invalid xform # in table?\");\n";
1439
1440 // FIXME: The node xform could take SDValue's instead of SDNode*'s.
1441 for (unsigned i = 0, e = NodeXForms.size(); i != e; ++i) {
1442 const CodeGenDAGPatterns::NodeXForm &Entry =
1443 CGP.getSDNodeTransform(R: NodeXForms[i]);
1444
1445 const Record *SDNode = Entry.first;
1446 const std::string &Code = Entry.second;
1447
1448 OS << " case " << i << ": { ";
1449 if (!OmitComments)
1450 OS << "// " << NodeXForms[i]->getName();
1451 OS << '\n';
1452
1453 std::string ClassName = CGP.getSDNodeInfo(R: SDNode).getSDClassName().str();
1454 if (ClassName == "SDNode")
1455 OS << " SDNode *N = V.getNode();\n";
1456 else
1457 OS << " " << ClassName << " *N = cast<" << ClassName
1458 << ">(V.getNode());\n";
1459 OS << Code << "\n }\n";
1460 }
1461 OS << " }\n";
1462 OS << "}\n";
1463 EndEmitFunction(OS);
1464 }
1465}
1466
1467void MatcherTableEmitter::EmitValueTypeFunction(raw_ostream &OS) {
1468 if (ValueTypeMap.empty())
1469 return;
1470
1471 BeginEmitFunction(OS, RetType: "MVT", Decl: "getValueTypeForHwMode(unsigned Index) const",
1472 /*AddOverride=*/true);
1473 OS << "{\n";
1474
1475 OS << " switch (Index) {\n";
1476 OS << " default: llvm_unreachable(\"Unexpected index\");\n";
1477
1478 for (const auto &[VTs, IdxAndCount] : ValueTypeMap) {
1479 const auto &[Idx, Count] = IdxAndCount;
1480 OS << " case " << (Idx - 1) << ":\n";
1481 if (VTs.isSimple()) {
1482 OS << " return " << getEnumName(T: VTs.getSimple()) << ";\n";
1483 } else {
1484 OS << " switch (HwMode) {\n";
1485 if (!VTs.hasDefault())
1486 OS << " default:\n return MVT();\n";
1487 for (const auto [Mode, VT] : VTs) {
1488 if (Mode == DefaultMode)
1489 OS << " default:\n";
1490 else
1491 OS << " case " << Mode << ":\n";
1492 OS << " return " << getEnumName(T: VT) << ";\n";
1493 }
1494
1495 OS << " }\n";
1496 OS << " break;\n";
1497 }
1498 }
1499
1500 OS << " }\n";
1501
1502 OS << "}\n";
1503 EndEmitFunction(OS);
1504}
1505
1506static StringRef getOpcodeString(Matcher::KindTy Kind) {
1507 switch (Kind) {
1508 case Matcher::Scope:
1509 return "OPC_Scope";
1510 case Matcher::RecordNode:
1511 return "OPC_RecordNode";
1512 case Matcher::RecordChild:
1513 return "OPC_RecordChild";
1514 case Matcher::RecordMemRef:
1515 return "OPC_RecordMemRef";
1516 case Matcher::CaptureGlueInput:
1517 return "OPC_CaptureGlueInput";
1518 case Matcher::MoveChild:
1519 return "OPC_MoveChild";
1520 case Matcher::MoveSibling:
1521 return "OPC_MoveSibling";
1522 case Matcher::MoveParent:
1523 return "OPC_MoveParent";
1524 case Matcher::CheckSame:
1525 return "OPC_CheckSame";
1526 case Matcher::CheckChildSame:
1527 return "OPC_CheckChildSame";
1528 case Matcher::CheckPatternPredicate:
1529 return "OPC_CheckPatternPredicate";
1530 case Matcher::CheckPredicate:
1531 return "OPC_CheckPredicate";
1532 case Matcher::CheckOpcode:
1533 return "OPC_CheckOpcode";
1534 case Matcher::SwitchOpcode:
1535 return "OPC_SwitchOpcode";
1536 case Matcher::CheckType:
1537 return "OPC_CheckType";
1538 case Matcher::SwitchType:
1539 return "OPC_SwitchType";
1540 case Matcher::CheckChildType:
1541 return "OPC_CheckChildType";
1542 case Matcher::CheckInteger:
1543 return "OPC_CheckInteger";
1544 case Matcher::CheckChildInteger:
1545 return "OPC_CheckChildInteger";
1546 case Matcher::CheckCondCode:
1547 return "OPC_CheckCondCode";
1548 case Matcher::CheckChild2CondCode:
1549 return "OPC_CheckChild2CondCode";
1550 case Matcher::CheckValueType:
1551 return "OPC_CheckValueType";
1552 case Matcher::CheckComplexPat:
1553 return "OPC_CheckComplexPat";
1554 case Matcher::CheckAndImm:
1555 return "OPC_CheckAndImm";
1556 case Matcher::CheckOrImm:
1557 return "OPC_CheckOrImm";
1558 case Matcher::CheckFoldableChainNode:
1559 return "OPC_CheckFoldableChainNode";
1560 case Matcher::CheckImmAllOnesV:
1561 return "OPC_CheckImmAllOnesV";
1562 case Matcher::CheckImmAllZerosV:
1563 return "OPC_CheckImmAllZerosV";
1564 case Matcher::CheckUndef:
1565 return "OPC_CheckUndef";
1566 case Matcher::EmitInteger:
1567 return "OPC_EmitInteger";
1568 case Matcher::EmitRegister:
1569 return "OPC_EmitRegister";
1570 case Matcher::EmitConvertToTarget:
1571 return "OPC_EmitConvertToTarget";
1572 case Matcher::EmitMergeInputChains:
1573 return "OPC_EmitMergeInputChains";
1574 case Matcher::EmitCopyToReg:
1575 return "OPC_EmitCopyToReg";
1576 case Matcher::EmitNode:
1577 return "OPC_EmitNode";
1578 case Matcher::MorphNodeTo:
1579 return "OPC_MorphNodeTo";
1580 case Matcher::EmitNodeXForm:
1581 return "OPC_EmitNodeXForm";
1582 case Matcher::CompleteMatch:
1583 return "OPC_CompleteMatch";
1584 }
1585
1586 llvm_unreachable("Unhandled opcode?");
1587}
1588
1589void MatcherTableEmitter::EmitHistogram(raw_ostream &OS) {
1590 if (OmitComments)
1591 return;
1592
1593 OS << " // Opcode Histogram:\n";
1594 for (unsigned i = 0, e = OpcodeCounts.size(); i != e; ++i) {
1595 OS << " // #"
1596 << left_justify(Str: getOpcodeString(Kind: (Matcher::KindTy)i), Width: HistOpcWidth)
1597 << " = " << OpcodeCounts[i] << '\n';
1598 }
1599 OS << '\n';
1600}
1601
1602void llvm::EmitMatcherTable(MatcherList &TheMatcherList,
1603 const CodeGenDAGPatterns &CGP, raw_ostream &OS) {
1604 OS << "#if defined(GET_DAGISEL_DECL) && defined(GET_DAGISEL_BODY)\n";
1605 OS << "#error GET_DAGISEL_DECL and GET_DAGISEL_BODY cannot be both defined, ";
1606 OS << "undef both for inline definitions\n";
1607 OS << "#endif\n\n";
1608
1609 // Emit a check for omitted class name.
1610 OS << "#ifdef GET_DAGISEL_BODY\n";
1611 OS << "#define LOCAL_DAGISEL_STRINGIZE(X) LOCAL_DAGISEL_STRINGIZE_(X)\n";
1612 OS << "#define LOCAL_DAGISEL_STRINGIZE_(X) #X\n";
1613 OS << "static_assert(sizeof(LOCAL_DAGISEL_STRINGIZE(GET_DAGISEL_BODY)) > 1,"
1614 "\n";
1615 OS << " \"GET_DAGISEL_BODY is empty: it should be defined with the class "
1616 "name\");\n";
1617 OS << "#undef LOCAL_DAGISEL_STRINGIZE_\n";
1618 OS << "#undef LOCAL_DAGISEL_STRINGIZE\n";
1619 OS << "#endif\n\n";
1620
1621 OS << "#if !defined(GET_DAGISEL_DECL) && !defined(GET_DAGISEL_BODY)\n";
1622 OS << "#define DAGISEL_INLINE 1\n";
1623 OS << "#else\n";
1624 OS << "#define DAGISEL_INLINE 0\n";
1625 OS << "#endif\n\n";
1626
1627 OS << "#if !DAGISEL_INLINE\n";
1628 OS << "#define DAGISEL_CLASS_COLONCOLON GET_DAGISEL_BODY ::\n";
1629 OS << "#else\n";
1630 OS << "#define DAGISEL_CLASS_COLONCOLON\n";
1631 OS << "#endif\n\n";
1632
1633 BeginEmitFunction(OS, RetType: "void", Decl: "SelectCode(SDNode *N)", AddOverride: false /*AddOverride*/);
1634 MatcherTableEmitter MatcherEmitter(TheMatcherList, CGP);
1635
1636 // First we size all the children of the three kinds of matchers that have
1637 // them. This is done by sharing the code in EmitMatcher(). but we don't
1638 // want to emit anything, so we turn off comments and use a null stream.
1639 bool SaveOmitComments = OmitComments;
1640 OmitComments = true;
1641 raw_null_ostream NullOS;
1642 unsigned TotalSize = MatcherEmitter.SizeMatcherList(ML&: TheMatcherList, OS&: NullOS);
1643 OmitComments = SaveOmitComments;
1644
1645 // Now that the matchers are sized, we can emit the code for them to the
1646 // final stream.
1647 OS << "{\n";
1648 OS << " // Some target values are emitted as 2 bytes, TARGET_VAL handles\n";
1649 OS << " // this. Coverage indexes are emitted as 4 bytes,\n";
1650 OS << " // COVERAGE_IDX_VAL handles this.\n";
1651 OS << " #define TARGET_VAL(X) X & 255, unsigned(X) >> 8\n";
1652 OS << " #define COVERAGE_IDX_VAL(X) X & 255, (unsigned(X) >> 8) & 255, ";
1653 OS << "(unsigned(X) >> 16) & 255, (unsigned(X) >> 24) & 255\n";
1654 OS << " static const uint8_t MatcherTable[] = {\n";
1655 TotalSize = MatcherEmitter.EmitMatcherList(ML: TheMatcherList, Indent: 1, CurrentIdx: 0, OS);
1656 OS << " }; // Total Array size is " << TotalSize << " bytes\n\n";
1657
1658 MatcherEmitter.EmitHistogram(OS);
1659
1660 OS << " static const uint8_t OperandLists[] = {\n";
1661 MatcherEmitter.EmitOperandLists(OS);
1662 OS << " };\n\n";
1663
1664 OS << " #undef COVERAGE_IDX_VAL\n";
1665 OS << " #undef TARGET_VAL\n";
1666 OS << " SelectCodeCommon(N, MatcherTable, sizeof(MatcherTable),\n";
1667 OS << " OperandLists);\n";
1668 OS << "}\n";
1669 EndEmitFunction(OS);
1670
1671 // Next up, emit the function for node and pattern predicates:
1672 MatcherEmitter.EmitPredicateFunctions(OS);
1673
1674 MatcherEmitter.EmitValueTypeFunction(OS);
1675
1676 if (InstrumentCoverage)
1677 MatcherEmitter.EmitPatternMatchTable(OS);
1678
1679 // Clean up the preprocessor macros.
1680 OS << "\n";
1681 OS << "#ifdef DAGISEL_INLINE\n";
1682 OS << "#undef DAGISEL_INLINE\n";
1683 OS << "#endif\n";
1684 OS << "#ifdef DAGISEL_CLASS_COLONCOLON\n";
1685 OS << "#undef DAGISEL_CLASS_COLONCOLON\n";
1686 OS << "#endif\n";
1687 OS << "#ifdef GET_DAGISEL_DECL\n";
1688 OS << "#undef GET_DAGISEL_DECL\n";
1689 OS << "#endif\n";
1690 OS << "#ifdef GET_DAGISEL_BODY\n";
1691 OS << "#undef GET_DAGISEL_BODY\n";
1692 OS << "#endif\n";
1693}
1694