1 //===- DAGISelMatcherEmitter.cpp - Matcher Emitter ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains code to generate C++ code a matcher.
12 //===----------------------------------------------------------------------===//
14 #include "DAGISelMatcher.h"
15 #include "CodeGenDAGPatterns.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/FormattedStream.h"
28 // To reduce generated source code size.
30 OmitComments("omit-comments", cl::desc("Do not generate comments"),
34 class MatcherTableEmitter {
35 StringMap<unsigned> NodePredicateMap, PatternPredicateMap;
36 std::vector<std::string> NodePredicates, PatternPredicates;
38 DenseMap<const ComplexPattern*, unsigned> ComplexPatternMap;
39 std::vector<const ComplexPattern*> ComplexPatterns;
42 DenseMap<Record*, unsigned> NodeXFormMap;
43 std::vector<Record*> NodeXForms;
45 // Per opcode frequence count.
46 std::vector<unsigned> Histogram;
48 MatcherTableEmitter() {}
50 unsigned EmitMatcherList(const Matcher *N, unsigned Indent,
51 unsigned StartIdx, formatted_raw_ostream &OS);
53 void EmitPredicateFunctions(const CodeGenDAGPatterns &CGP,
54 formatted_raw_ostream &OS);
56 void EmitHistogram(formatted_raw_ostream &OS);
58 unsigned EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
59 formatted_raw_ostream &OS);
61 unsigned getNodePredicate(StringRef PredName) {
62 unsigned &Entry = NodePredicateMap[PredName];
64 NodePredicates.push_back(PredName.str());
65 Entry = NodePredicates.size();
69 unsigned getPatternPredicate(StringRef PredName) {
70 unsigned &Entry = PatternPredicateMap[PredName];
72 PatternPredicates.push_back(PredName.str());
73 Entry = PatternPredicates.size();
78 unsigned getComplexPat(const ComplexPattern &P) {
79 unsigned &Entry = ComplexPatternMap[&P];
81 ComplexPatterns.push_back(&P);
82 Entry = ComplexPatterns.size();
87 unsigned getNodeXFormID(Record *Rec) {
88 unsigned &Entry = NodeXFormMap[Rec];
90 NodeXForms.push_back(Rec);
91 Entry = NodeXForms.size();
97 } // end anonymous namespace.
99 static unsigned GetVBRSize(unsigned Val) {
100 if (Val <= 127) return 1;
102 unsigned NumBytes = 0;
110 /// EmitVBRValue - Emit the specified value as a VBR, returning the number of
112 static uint64_t EmitVBRValue(uint64_t Val, raw_ostream &OS) {
118 uint64_t InVal = Val;
119 unsigned NumBytes = 0;
121 OS << (Val&127) << "|128,";
127 OS << "/*" << InVal << "*/";
132 /// EmitMatcherOpcodes - Emit bytes for the specified matcher and return
133 /// the number of bytes emitted.
134 unsigned MatcherTableEmitter::
135 EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
136 formatted_raw_ostream &OS) {
137 OS.PadToColumn(Indent*2);
139 switch (N->getKind()) {
140 case Matcher::Scope: {
141 const ScopeMatcher *SM = cast<ScopeMatcher>(N);
142 assert(SM->getNext() == 0 && "Shouldn't have next after scope");
144 unsigned StartIdx = CurrentIdx;
146 // Emit all of the children.
147 for (unsigned i = 0, e = SM->getNumChildren(); i != e; ++i) {
153 OS << "/*" << CurrentIdx << "*/";
154 OS.PadToColumn(Indent*2) << "/*Scope*/ ";
156 OS.PadToColumn(Indent*2);
159 // We need to encode the child and the offset of the failure code before
160 // emitting either of them. Handle this by buffering the output into a
161 // string while we get the size. Unfortunately, the offset of the
162 // children depends on the VBR size of the child, so for large children we
163 // have to iterate a bit.
164 SmallString<128> TmpBuf;
165 unsigned ChildSize = 0;
166 unsigned VBRSize = 0;
168 VBRSize = GetVBRSize(ChildSize);
171 raw_svector_ostream OS(TmpBuf);
172 formatted_raw_ostream FOS(OS);
173 ChildSize = EmitMatcherList(SM->getChild(i), Indent+1,
174 CurrentIdx+VBRSize, FOS);
175 } while (GetVBRSize(ChildSize) != VBRSize);
177 assert(ChildSize != 0 && "Should not have a zero-sized child!");
179 CurrentIdx += EmitVBRValue(ChildSize, OS);
181 OS << "/*->" << CurrentIdx+ChildSize << "*/";
184 OS.PadToColumn(CommentIndent) << "// " << SM->getNumChildren()
185 << " children in Scope";
188 OS << '\n' << TmpBuf.str();
189 CurrentIdx += ChildSize;
192 // Emit a zero as a sentinel indicating end of 'Scope'.
194 OS << "/*" << CurrentIdx << "*/";
195 OS.PadToColumn(Indent*2) << "0, ";
197 OS << "/*End of Scope*/";
199 return CurrentIdx - StartIdx + 1;
202 case Matcher::RecordNode:
203 OS << "OPC_RecordNode,";
205 OS.PadToColumn(CommentIndent) << "// #"
206 << cast<RecordMatcher>(N)->getResultNo() << " = "
207 << cast<RecordMatcher>(N)->getWhatFor();
211 case Matcher::RecordChild:
212 OS << "OPC_RecordChild" << cast<RecordChildMatcher>(N)->getChildNo()
215 OS.PadToColumn(CommentIndent) << "// #"
216 << cast<RecordChildMatcher>(N)->getResultNo() << " = "
217 << cast<RecordChildMatcher>(N)->getWhatFor();
221 case Matcher::RecordMemRef:
222 OS << "OPC_RecordMemRef,\n";
225 case Matcher::CaptureFlagInput:
226 OS << "OPC_CaptureFlagInput,\n";
229 case Matcher::MoveChild:
230 OS << "OPC_MoveChild, " << cast<MoveChildMatcher>(N)->getChildNo() << ",\n";
233 case Matcher::MoveParent:
234 OS << "OPC_MoveParent,\n";
237 case Matcher::CheckSame:
238 OS << "OPC_CheckSame, "
239 << cast<CheckSameMatcher>(N)->getMatchNumber() << ",\n";
242 case Matcher::CheckPatternPredicate: {
243 StringRef Pred = cast<CheckPatternPredicateMatcher>(N)->getPredicate();
244 OS << "OPC_CheckPatternPredicate, " << getPatternPredicate(Pred) << ',';
246 OS.PadToColumn(CommentIndent) << "// " << Pred;
250 case Matcher::CheckPredicate: {
251 StringRef Pred = cast<CheckPredicateMatcher>(N)->getPredicateName();
252 OS << "OPC_CheckPredicate, " << getNodePredicate(Pred) << ',';
254 OS.PadToColumn(CommentIndent) << "// " << Pred;
259 case Matcher::CheckOpcode:
260 OS << "OPC_CheckOpcode, "
261 << cast<CheckOpcodeMatcher>(N)->getOpcode().getEnumName() << ",\n";
264 case Matcher::SwitchOpcode: {
265 unsigned StartIdx = CurrentIdx;
266 const SwitchOpcodeMatcher *SOM = cast<SwitchOpcodeMatcher>(N);
267 OS << "OPC_SwitchOpcode ";
269 OS << "/*" << SOM->getNumCases() << " cases */";
273 // For each case we emit the size, then the opcode, then the matcher.
274 for (unsigned i = 0, e = SOM->getNumCases(); i != e; ++i) {
275 // We need to encode the opcode and the offset of the case code before
276 // emitting the case code. Handle this by buffering the output into a
277 // string while we get the size. Unfortunately, the offset of the
278 // children depends on the VBR size of the child, so for large children we
279 // have to iterate a bit.
280 SmallString<128> TmpBuf;
281 unsigned ChildSize = 0;
282 unsigned VBRSize = 0;
284 VBRSize = GetVBRSize(ChildSize);
287 raw_svector_ostream OS(TmpBuf);
288 formatted_raw_ostream FOS(OS);
289 ChildSize = EmitMatcherList(SOM->getCaseMatcher(i),
290 Indent+1, CurrentIdx+VBRSize+1, FOS);
291 } while (GetVBRSize(ChildSize) != VBRSize);
293 assert(ChildSize != 0 && "Should not have a zero-sized child!");
296 OS.PadToColumn(Indent*2);
298 OS << "/*SwitchOpcode*/ ";
302 CurrentIdx += EmitVBRValue(ChildSize, OS);
304 OS << " " << SOM->getCaseOpcode(i).getEnumName() << ",";
306 OS << "// ->" << CurrentIdx+ChildSize+1;
310 CurrentIdx += ChildSize;
313 // Emit the final zero to terminate the switch.
314 OS.PadToColumn(Indent*2) << "0, ";
316 OS << "// EndSwitchOpcode";
319 return CurrentIdx-StartIdx;
322 case Matcher::CheckType:
323 OS << "OPC_CheckType, "
324 << getEnumName(cast<CheckTypeMatcher>(N)->getType()) << ",\n";
326 case Matcher::CheckChildType:
327 OS << "OPC_CheckChild"
328 << cast<CheckChildTypeMatcher>(N)->getChildNo() << "Type, "
329 << getEnumName(cast<CheckChildTypeMatcher>(N)->getType()) << ",\n";
332 case Matcher::CheckInteger: {
333 OS << "OPC_CheckInteger, ";
334 unsigned Bytes=1+EmitVBRValue(cast<CheckIntegerMatcher>(N)->getValue(), OS);
338 case Matcher::CheckCondCode:
339 OS << "OPC_CheckCondCode, ISD::"
340 << cast<CheckCondCodeMatcher>(N)->getCondCodeName() << ",\n";
343 case Matcher::CheckValueType:
344 OS << "OPC_CheckValueType, MVT::"
345 << cast<CheckValueTypeMatcher>(N)->getTypeName() << ",\n";
348 case Matcher::CheckComplexPat: {
349 const ComplexPattern &Pattern =
350 cast<CheckComplexPatMatcher>(N)->getPattern();
351 OS << "OPC_CheckComplexPat, " << getComplexPat(Pattern) << ',';
353 OS.PadToColumn(CommentIndent) << "// " << Pattern.getSelectFunc();
354 OS << ": " << Pattern.getNumOperands() << " operands";
355 if (Pattern.hasProperty(SDNPHasChain))
356 OS << " + chain result and input";
362 case Matcher::CheckAndImm: {
363 OS << "OPC_CheckAndImm, ";
364 unsigned Bytes=1+EmitVBRValue(cast<CheckAndImmMatcher>(N)->getValue(), OS);
369 case Matcher::CheckOrImm: {
370 OS << "OPC_CheckOrImm, ";
371 unsigned Bytes = 1+EmitVBRValue(cast<CheckOrImmMatcher>(N)->getValue(), OS);
376 case Matcher::CheckFoldableChainNode:
377 OS << "OPC_CheckFoldableChainNode,\n";
380 case Matcher::EmitInteger: {
381 int64_t Val = cast<EmitIntegerMatcher>(N)->getValue();
382 OS << "OPC_EmitInteger, "
383 << getEnumName(cast<EmitIntegerMatcher>(N)->getVT()) << ", ";
384 unsigned Bytes = 2+EmitVBRValue(Val, OS);
388 case Matcher::EmitStringInteger: {
389 const std::string &Val = cast<EmitStringIntegerMatcher>(N)->getValue();
390 // These should always fit into one byte.
391 OS << "OPC_EmitInteger, "
392 << getEnumName(cast<EmitStringIntegerMatcher>(N)->getVT()) << ", "
397 case Matcher::EmitRegister:
398 OS << "OPC_EmitRegister, "
399 << getEnumName(cast<EmitRegisterMatcher>(N)->getVT()) << ", ";
400 if (Record *R = cast<EmitRegisterMatcher>(N)->getReg())
401 OS << getQualifiedName(R) << ",\n";
405 OS << "/*zero_reg*/";
410 case Matcher::EmitConvertToTarget:
411 OS << "OPC_EmitConvertToTarget, "
412 << cast<EmitConvertToTargetMatcher>(N)->getSlot() << ",\n";
415 case Matcher::EmitMergeInputChains: {
416 const EmitMergeInputChainsMatcher *MN =
417 cast<EmitMergeInputChainsMatcher>(N);
418 OS << "OPC_EmitMergeInputChains, " << MN->getNumNodes() << ", ";
419 for (unsigned i = 0, e = MN->getNumNodes(); i != e; ++i)
420 OS << MN->getNode(i) << ", ";
422 return 2+MN->getNumNodes();
424 case Matcher::EmitCopyToReg:
425 OS << "OPC_EmitCopyToReg, "
426 << cast<EmitCopyToRegMatcher>(N)->getSrcSlot() << ", "
427 << getQualifiedName(cast<EmitCopyToRegMatcher>(N)->getDestPhysReg())
430 case Matcher::EmitNodeXForm: {
431 const EmitNodeXFormMatcher *XF = cast<EmitNodeXFormMatcher>(N);
432 OS << "OPC_EmitNodeXForm, " << getNodeXFormID(XF->getNodeXForm()) << ", "
433 << XF->getSlot() << ',';
435 OS.PadToColumn(CommentIndent) << "// "<<XF->getNodeXForm()->getName();
440 case Matcher::EmitNode:
441 case Matcher::MorphNodeTo: {
442 const EmitNodeMatcherCommon *EN = cast<EmitNodeMatcherCommon>(N);
443 OS << (isa<EmitNodeMatcher>(EN) ? "OPC_EmitNode" : "OPC_MorphNodeTo");
444 OS << ", TARGET_OPCODE(" << EN->getOpcodeName() << "), 0";
446 if (EN->hasChain()) OS << "|OPFL_Chain";
447 if (EN->hasInFlag()) OS << "|OPFL_FlagInput";
448 if (EN->hasOutFlag()) OS << "|OPFL_FlagOutput";
449 if (EN->hasMemRefs()) OS << "|OPFL_MemRefs";
450 if (EN->getNumFixedArityOperands() != -1)
451 OS << "|OPFL_Variadic" << EN->getNumFixedArityOperands();
454 OS.PadToColumn(Indent*2+4) << EN->getNumVTs();
458 for (unsigned i = 0, e = EN->getNumVTs(); i != e; ++i)
459 OS << getEnumName(EN->getVT(i)) << ", ";
461 OS << EN->getNumOperands();
465 unsigned NumOperandBytes = 0;
466 for (unsigned i = 0, e = EN->getNumOperands(); i != e; ++i)
467 NumOperandBytes += EmitVBRValue(EN->getOperand(i), OS);
470 // Print the result #'s for EmitNode.
471 if (const EmitNodeMatcher *E = dyn_cast<EmitNodeMatcher>(EN)) {
472 if (unsigned NumResults = EN->getNumVTs()) {
473 OS.PadToColumn(CommentIndent) << "// Results = ";
474 unsigned First = E->getFirstResultSlot();
475 for (unsigned i = 0; i != NumResults; ++i)
476 OS << "#" << First+i << " ";
481 if (const MorphNodeToMatcher *SNT = dyn_cast<MorphNodeToMatcher>(N)) {
482 OS.PadToColumn(Indent*2) << "// Src: "
483 << *SNT->getPattern().getSrcPattern() << '\n';
484 OS.PadToColumn(Indent*2) << "// Dst: "
485 << *SNT->getPattern().getDstPattern() << '\n';
490 return 6+EN->getNumVTs()+NumOperandBytes;
492 case Matcher::MarkFlagResults: {
493 const MarkFlagResultsMatcher *CFR = cast<MarkFlagResultsMatcher>(N);
494 OS << "OPC_MarkFlagResults, " << CFR->getNumNodes() << ", ";
495 unsigned NumOperandBytes = 0;
496 for (unsigned i = 0, e = CFR->getNumNodes(); i != e; ++i)
497 NumOperandBytes += EmitVBRValue(CFR->getNode(i), OS);
499 return 2+NumOperandBytes;
501 case Matcher::CompleteMatch: {
502 const CompleteMatchMatcher *CM = cast<CompleteMatchMatcher>(N);
503 OS << "OPC_CompleteMatch, " << CM->getNumResults() << ", ";
504 unsigned NumResultBytes = 0;
505 for (unsigned i = 0, e = CM->getNumResults(); i != e; ++i)
506 NumResultBytes += EmitVBRValue(CM->getResult(i), OS);
509 OS.PadToColumn(Indent*2) << "// Src: "
510 << *CM->getPattern().getSrcPattern() << '\n';
511 OS.PadToColumn(Indent*2) << "// Dst: "
512 << *CM->getPattern().getDstPattern();
515 return 2 + NumResultBytes;
518 assert(0 && "Unreachable");
522 /// EmitMatcherList - Emit the bytes for the specified matcher subtree.
523 unsigned MatcherTableEmitter::
524 EmitMatcherList(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
525 formatted_raw_ostream &OS) {
528 if (unsigned(N->getKind()) >= Histogram.size())
529 Histogram.resize(N->getKind()+1);
530 Histogram[N->getKind()]++;
532 OS << "/*" << CurrentIdx << "*/";
533 unsigned MatcherSize = EmitMatcher(N, Indent, CurrentIdx, OS);
535 CurrentIdx += MatcherSize;
537 // If there are other nodes in this list, iterate to them, otherwise we're
544 void MatcherTableEmitter::EmitPredicateFunctions(const CodeGenDAGPatterns &CGP,
545 formatted_raw_ostream &OS) {
546 // Emit pattern predicates.
547 if (!PatternPredicates.empty()) {
548 OS << "bool CheckPatternPredicate(unsigned PredNo) const {\n";
549 OS << " switch (PredNo) {\n";
550 OS << " default: assert(0 && \"Invalid predicate in table?\");\n";
551 for (unsigned i = 0, e = PatternPredicates.size(); i != e; ++i)
552 OS << " case " << i << ": return " << PatternPredicates[i] << ";\n";
557 // Emit Node predicates.
558 // FIXME: Annoyingly, these are stored by name, which we never even emit. Yay?
559 StringMap<TreePattern*> PFsByName;
561 for (CodeGenDAGPatterns::pf_iterator I = CGP.pf_begin(), E = CGP.pf_end();
563 PFsByName[I->first->getName()] = I->second;
565 if (!NodePredicates.empty()) {
566 OS << "bool CheckNodePredicate(SDNode *Node, unsigned PredNo) const {\n";
567 OS << " switch (PredNo) {\n";
568 OS << " default: assert(0 && \"Invalid predicate in table?\");\n";
569 for (unsigned i = 0, e = NodePredicates.size(); i != e; ++i) {
570 // FIXME: Storing this by name is horrible.
571 TreePattern *P =PFsByName[NodePredicates[i].substr(strlen("Predicate_"))];
572 assert(P && "Unknown name?");
574 // Emit the predicate code corresponding to this pattern.
575 std::string Code = P->getRecord()->getValueAsCode("Predicate");
576 assert(!Code.empty() && "No code in this predicate");
577 OS << " case " << i << ": { // " << NodePredicates[i] << '\n';
578 std::string ClassName;
579 if (P->getOnlyTree()->isLeaf())
580 ClassName = "SDNode";
583 CGP.getSDNodeInfo(P->getOnlyTree()->getOperator()).getSDClassName();
584 if (ClassName == "SDNode")
585 OS << " SDNode *N = Node;\n";
587 OS << " " << ClassName << "*N = cast<" << ClassName << ">(Node);\n";
588 OS << Code << "\n }\n";
594 // Emit CompletePattern matchers.
595 // FIXME: This should be const.
596 if (!ComplexPatterns.empty()) {
597 OS << "bool CheckComplexPattern(SDNode *Root, SDValue N,\n";
598 OS << " unsigned PatternNo, SmallVectorImpl<SDValue> &Result) {\n";
599 OS << " switch (PatternNo) {\n";
600 OS << " default: assert(0 && \"Invalid pattern # in table?\");\n";
601 for (unsigned i = 0, e = ComplexPatterns.size(); i != e; ++i) {
602 const ComplexPattern &P = *ComplexPatterns[i];
603 unsigned NumOps = P.getNumOperands();
605 if (P.hasProperty(SDNPHasChain))
606 ++NumOps; // Get the chained node too.
608 OS << " case " << i << ":\n";
609 OS << " Result.resize(Result.size()+" << NumOps << ");\n";
610 OS << " return " << P.getSelectFunc();
613 for (unsigned i = 0; i != NumOps; ++i)
614 OS << ", Result[Result.size()-" << (NumOps-i) << ']';
622 // Emit SDNodeXForm handlers.
623 // FIXME: This should be const.
624 if (!NodeXForms.empty()) {
625 OS << "SDValue RunSDNodeXForm(SDValue V, unsigned XFormNo) {\n";
626 OS << " switch (XFormNo) {\n";
627 OS << " default: assert(0 && \"Invalid xform # in table?\");\n";
629 // FIXME: The node xform could take SDValue's instead of SDNode*'s.
630 for (unsigned i = 0, e = NodeXForms.size(); i != e; ++i) {
631 const CodeGenDAGPatterns::NodeXForm &Entry =
632 CGP.getSDNodeTransform(NodeXForms[i]);
634 Record *SDNode = Entry.first;
635 const std::string &Code = Entry.second;
637 OS << " case " << i << ": { ";
639 OS << "// " << NodeXForms[i]->getName();
642 std::string ClassName = CGP.getSDNodeInfo(SDNode).getSDClassName();
643 if (ClassName == "SDNode")
644 OS << " SDNode *N = V.getNode();\n";
646 OS << " " << ClassName << " *N = cast<" << ClassName
647 << ">(V.getNode());\n";
648 OS << Code << "\n }\n";
655 void MatcherTableEmitter::EmitHistogram(formatted_raw_ostream &OS) {
658 OS << " // Opcode Histogram:\n";
659 for (unsigned i = 0, e = Histogram.size(); i != e; ++i) {
661 switch ((Matcher::KindTy)i) {
662 case Matcher::Scope: OS << "OPC_Scope"; break;
663 case Matcher::RecordNode: OS << "OPC_RecordNode"; break;
664 case Matcher::RecordChild: OS << "OPC_RecordChild"; break;
665 case Matcher::RecordMemRef: OS << "OPC_RecordMemRef"; break;
666 case Matcher::CaptureFlagInput: OS << "OPC_CaptureFlagInput"; break;
667 case Matcher::MoveChild: OS << "OPC_MoveChild"; break;
668 case Matcher::MoveParent: OS << "OPC_MoveParent"; break;
669 case Matcher::CheckSame: OS << "OPC_CheckSame"; break;
670 case Matcher::CheckPatternPredicate:
671 OS << "OPC_CheckPatternPredicate"; break;
672 case Matcher::CheckPredicate: OS << "OPC_CheckPredicate"; break;
673 case Matcher::CheckOpcode: OS << "OPC_CheckOpcode"; break;
674 case Matcher::SwitchOpcode: OS << "OPC_SwitchOpcode"; break;
675 case Matcher::CheckType: OS << "OPC_CheckType"; break;
676 case Matcher::CheckChildType: OS << "OPC_CheckChildType"; break;
677 case Matcher::CheckInteger: OS << "OPC_CheckInteger"; break;
678 case Matcher::CheckCondCode: OS << "OPC_CheckCondCode"; break;
679 case Matcher::CheckValueType: OS << "OPC_CheckValueType"; break;
680 case Matcher::CheckComplexPat: OS << "OPC_CheckComplexPat"; break;
681 case Matcher::CheckAndImm: OS << "OPC_CheckAndImm"; break;
682 case Matcher::CheckOrImm: OS << "OPC_CheckOrImm"; break;
683 case Matcher::CheckFoldableChainNode:
684 OS << "OPC_CheckFoldableChainNode"; break;
685 case Matcher::EmitInteger: OS << "OPC_EmitInteger"; break;
686 case Matcher::EmitStringInteger: OS << "OPC_EmitStringInteger"; break;
687 case Matcher::EmitRegister: OS << "OPC_EmitRegister"; break;
688 case Matcher::EmitConvertToTarget: OS << "OPC_EmitConvertToTarget"; break;
689 case Matcher::EmitMergeInputChains: OS << "OPC_EmitMergeInputChains"; break;
690 case Matcher::EmitCopyToReg: OS << "OPC_EmitCopyToReg"; break;
691 case Matcher::EmitNode: OS << "OPC_EmitNode"; break;
692 case Matcher::MorphNodeTo: OS << "OPC_MorphNodeTo"; break;
693 case Matcher::EmitNodeXForm: OS << "OPC_EmitNodeXForm"; break;
694 case Matcher::MarkFlagResults: OS << "OPC_MarkFlagResults"; break;
695 case Matcher::CompleteMatch: OS << "OPC_CompleteMatch"; break;
698 OS.PadToColumn(40) << " = " << Histogram[i] << '\n';
704 void llvm::EmitMatcherTable(const Matcher *TheMatcher,
705 const CodeGenDAGPatterns &CGP, raw_ostream &O) {
706 formatted_raw_ostream OS(O);
708 OS << "// The main instruction selector code.\n";
709 OS << "SDNode *SelectCode(SDNode *N) {\n";
711 MatcherTableEmitter MatcherEmitter;
713 OS << " // Opcodes are emitted as 2 bytes, TARGET_OPCODE handles this.\n";
714 OS << " #define TARGET_OPCODE(X) X & 255, unsigned(X) >> 8\n";
715 OS << " static const unsigned char MatcherTable[] = {\n";
716 unsigned TotalSize = MatcherEmitter.EmitMatcherList(TheMatcher, 5, 0, OS);
717 OS << " 0\n }; // Total Array size is " << (TotalSize+1) << " bytes\n\n";
719 MatcherEmitter.EmitHistogram(OS);
721 OS << " #undef TARGET_OPCODE\n";
722 OS << " return SelectCodeCommon(N, MatcherTable,sizeof(MatcherTable));\n}\n";
725 // Next up, emit the function for node and pattern predicates:
726 MatcherEmitter.EmitPredicateFunctions(CGP, OS);