llvm.org GIT mirror llvm / d1ff35a
Emit code that matches the incoming DAG pattern and checks predicates. This does not check that types match yet, but PPC only has one integer type ;-). This also doesn't have the code to build the resultant dag. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23414 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 14 years ago
2 changed file(s) with 66 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
984984 });
985985 }
986986
987 /// EmitMatchForPattern - Emit a matcher for N, going to the label for PatternNo
988 /// if the match fails. At this point, we already know that the opcode for N
989 /// matches, and the SDNode for the result has the RootName specified name.
990 void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
991 const std::string &RootName,
992 unsigned PatternNo, std::ostream &OS) {
993 assert(!N->isLeaf() && "Cannot match against a leaf!");
994 // Emit code to load the child nodes and match their contents recursively.
995 for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
996 OS << " SDNode *" << RootName << i <<" = " << RootName
997 << "->getOperand(" << i << ").Val;\n";
998 TreePatternNode *Child = N->getChild(i);
999 if (!Child->isLeaf()) {
1000 // If it's not a leaf, recursively match.
1001 const SDNodeInfo &CInfo = getSDNodeInfo(Child->getOperator());
1002 OS << " if (" << RootName << i << "->getOpcode() != "
1003 << CInfo.getEnumName() << ") goto P" << PatternNo << "Fail;\n";
1004 EmitMatchForPattern(Child, RootName + utostr(i), PatternNo, OS);
1005 } else {
1006 // Handle leaves of various types.
1007 Init *LeafVal = Child->getLeafValue();
1008 Record *LeafRec = dynamic_cast(LeafVal)->getDef();
1009 if (LeafRec->isSubClassOf("RegisterClass")) {
1010 // Handle register references. Nothing to do here.
1011 } else if (LeafRec->isSubClassOf("ValueType")) {
1012 // Make sure this is the specified value type.
1013 OS << " if (cast(" << RootName << i << ")->getVT() != "
1014 << "MVT::" << LeafRec->getName() << ") goto P" << PatternNo
1015 << "Fail;\n";
1016 } else {
1017 Child->dump();
1018 assert(0 && "Unknown leaf type!");
1019 }
1020 }
1021
1022 // If this child has a name associated with it, capture it as a variable.
1023 if (!Child->getName().empty())
1024 OS << " SDOperand op" << Child->getName() << "(" << RootName
1025 << i << ", 0 /*FIXME*/);\n";
1026 }
1027
1028 // If there is a node predicate for this, emit the call.
1029 if (!N->getPredicateFn().empty())
1030 OS << " if (!" << N->getPredicateFn() << "(" << RootName
1031 << ")) goto P" << PatternNo << "Fail;\n";
1032 }
1033
1034 /// EmitCodeForPattern - Given a pattern to match, emit code to the specified
1035 /// stream to match the pattern, and generate the code for the match if it
1036 /// succeeds.
9871037 void DAGISelEmitter::EmitCodeForPattern(PatternToMatch &Pattern,
9881038 std::ostream &OS) {
989 OS << " // ";
1039 static unsigned PatternCount = 0;
1040 unsigned PatternNo = PatternCount++;
1041 OS << " { // Pattern #" << PatternNo << ": ";
9901042 Pattern.first->print(OS);
9911043 OS << "\n";
992
993
994
1044
1045 EmitMatchForPattern(Pattern.first, "N", PatternNo, OS);
1046
1047 OS << " // Emit: ";
1048 Pattern.second->print(OS);
1049 OS << "\n";
1050
1051 OS << " }\n P" << PatternNo << "Fail:\n";
9951052 }
9961053
9971054 /// getPatternSize - Return the 'size' of this pattern. We want to match large
10631120 // We want to emit all of the matching code now. However, we want to emit
10641121 // the matches in order of minimal cost. Sort the patterns so the least
10651122 // cost one is at the start.
1066 std::sort(Patterns.begin(), Patterns.end(), PatternSortingPredicate());
1123 std::stable_sort(Patterns.begin(), Patterns.end(),
1124 PatternSortingPredicate());
10671125
10681126 for (unsigned i = 0, e = Patterns.size(); i != e; ++i)
10691127 EmitCodeForPattern(*Patterns[i], OS);
1070 OS << " break;\n";
1128 OS << " break;\n\n";
10711129 }
10721130
10731131
364364 std::map
365365 TreePatternNode*> &InstInputs,
366366 std::map &InstResults);
367 void EmitMatchForPattern(TreePatternNode *N, const std::string &RootName,
368 unsigned PatternNo, std::ostream &OS);
367369 void EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS);
368370 void EmitInstructionSelector(std::ostream &OS);
369371 };