llvm.org GIT mirror llvm / 355408b
move some code around, no change in the generated code git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25758 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
2 changed file(s) with 53 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
18281828 TreePatternNode *Pattern;
18291829 // Matched instruction.
18301830 TreePatternNode *Instruction;
1831 unsigned PatternNo;
18321831
18331832 // Node to name mapping
18341833 std::map VariableMap;
18571856 public:
18581857 PatternCodeEmitter(DAGISelEmitter &ise, ListInit *preds,
18591858 TreePatternNode *pattern, TreePatternNode *instr,
1860 unsigned PatNum,
18611859 std::vector > &gc)
18621860 : ISE(ise), Predicates(preds), Pattern(pattern), Instruction(instr),
1863 PatternNo(PatNum), GeneratedCode(gc), TmpNo(0) {}
1861 GeneratedCode(gc), TmpNo(0) {}
18641862
18651863 /// EmitMatchCode - Emit a matcher for N, going to the label for PatternNo
18661864 /// if the match fails. At this point, we already know that the opcode for N
25302528
25312529 /// EmitCodeForPattern - Given a pattern to match, emit code to the specified
25322530 /// stream to match the pattern, and generate the code for the match if it
2533 /// succeeds. Returns true if execution may jump to the fail label instead of
2534 /// returning.
2535 bool DAGISelEmitter::EmitCodeForPattern(PatternToMatch &Pattern,
2536 std::ostream &OS) {
2537 static unsigned PatternCount = 0;
2538 unsigned PatternNo = PatternCount++;
2539
2540 std::vector > GeneratedCode;
2531 /// succeeds. Returns true if the pattern is not guaranteed to match.
2532 void DAGISelEmitter::EmitCodeForPattern(PatternToMatch &Pattern,
2533 std::vector > &GeneratedCode) {
25412534 PatternCodeEmitter Emitter(*this, Pattern.getPredicates(),
25422535 Pattern.getSrcPattern(), Pattern.getDstPattern(),
2543 PatternNo, GeneratedCode);
2536 GeneratedCode);
25442537
25452538 // Emit the matcher, capturing named arguments in VariableMap.
25462539 bool FoundChain = false;
25842577 } while (Emitter.InsertOneTypeCheck(Pat, Pattern.getSrcPattern(), "N"));
25852578
25862579 Emitter.EmitResultCode(Pattern.getDstPattern(), true /*the root*/);
2587
25882580 delete Pat;
2589
2590
2591 OS << " { // Pattern #" << PatternNo << ": ";
2592 Pattern.getSrcPattern()->print(OS);
2593 OS << "\n // Emits: ";
2594 Pattern.getDstPattern()->print(OS);
2595 OS << "\n";
2596 OS << " // Pattern complexity = "
2597 << getPatternSize(Pattern.getSrcPattern(), *this)
2598 << " cost = "
2599 << getResultPatternCost(Pattern.getDstPattern()) << "\n";
2600
2601 // Actually output the generated code now.
2602 bool CanFail = false;
2603 unsigned Indent = 4;
2604 for (unsigned i = 0, e = GeneratedCode.size(); i != e; ++i) {
2605 if (!GeneratedCode[i].first) {
2606 // Normal code.
2607 OS << std::string(Indent, ' ') << GeneratedCode[i].second << "\n";
2608 } else {
2609 CanFail = true;
2610 OS << std::string(Indent, ' ')
2611 << "if (" << GeneratedCode[i].second << ") {\n";
2612 Indent += 2;
2613 }
2614 }
2615 for (; Indent != 4; Indent -= 2)
2616 OS << std::string(Indent-2, ' ') << "}\n";
2617
2618 OS << " }\n";
2619 return CanFail;
26202581 }
26212582
26222583
26772638
26782639 const SDNodeInfo &OpcodeInfo = getSDNodeInfo(PBOI->first);
26792640 std::vector &Patterns = PBOI->second;
2641 assert(!Patterns.empty() && "No patterns but map has entry?");
26802642
26812643 // We want to emit all of the matching code now. However, we want to emit
26822644 // the matches in order of minimal cost. Sort the patterns so the least
26842646 std::stable_sort(Patterns.begin(), Patterns.end(),
26852647 PatternSortingPredicate(*this));
26862648
2687 bool mightNotReturn = true;
2649 bool mightNotMatch = true;
26882650 for (unsigned i = 0, e = Patterns.size(); i != e; ++i) {
2689 if (!mightNotReturn) {
2651 PatternToMatch &Pattern = *Patterns[i];
2652 std::vector > GeneratedCode;
2653 EmitCodeForPattern(Pattern, GeneratedCode);
2654
2655 static unsigned PatternCount = 0;
2656 unsigned PatternNo = PatternCount++;
2657
2658 OS << " { // Pattern #" << PatternNo << ": ";
2659 Pattern.getSrcPattern()->print(OS);
2660 OS << "\n // Emits: ";
2661 Pattern.getDstPattern()->print(OS);
2662 OS << "\n";
2663 OS << " // Pattern complexity = "
2664 << getPatternSize(Pattern.getSrcPattern(), *this) << " cost = "
2665 << getResultPatternCost(Pattern.getDstPattern()) << "\n";
2666
2667 // Actually output the generated code now.
2668 mightNotMatch = false;
2669 unsigned Indent = 4;
2670 for (unsigned j = 0, e = GeneratedCode.size(); j != e; ++j) {
2671 if (!GeneratedCode[j].first) {
2672 // Normal code.
2673 OS << std::string(Indent, ' ') << GeneratedCode[j].second << "\n";
2674 } else {
2675 mightNotMatch = true;
2676 OS << std::string(Indent, ' ')
2677 << "if (" << GeneratedCode[j].second << ") {\n";
2678 Indent += 2;
2679 }
2680 }
2681 for (; Indent != 4; Indent -= 2)
2682 OS << std::string(Indent-2, ' ') << "}\n";
2683
2684 OS << " }\n";
2685
2686 if (!mightNotMatch && i != Patterns.size()-1) {
26902687 std::cerr << "Pattern "
2691 << Patterns[i]->getDstPattern()->getOperator()->getName()
2692 << " is impossible to select!\n";
2688 << Patterns[i+1]->getDstPattern()->getOperator()->getName()
2689 << " is impossible to select!\n";
26932690 exit(1);
26942691 }
2695 mightNotReturn = EmitCodeForPattern(*Patterns[i], OS);
2696 }
2697
2698 if (mightNotReturn)
2692 }
2693
2694 if (mightNotMatch)
26992695 OS << " std::cerr << \"Cannot yet select: \";\n"
27002696 << " N.Val->dump(CurDAG);\n"
27012697 << " std::cerr << '\\n';\n"
154154 : Types(), Operator(Op), Val(0), TransformFn(0),
155155 Children(Ch) { Types.push_back(MVT::isUnknown); }
156156 TreePatternNode(Init *val) // leaf ctor
157 : Types(), Operator(0), Val(val), TransformFn(0) { Types.push_back(MVT::isUnknown); }
157 : Types(), Operator(0), Val(val), TransformFn(0) {
158 Types.push_back(MVT::isUnknown);
159 }
158160 ~TreePatternNode();
159161
160162 const std::string &getName() const { return Name; }
467469 std::map &InstResults,
468470 std::vector &InstImpInputs,
469471 std::vector &InstImpResults);
470 bool EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS);
472 void EmitCodeForPattern(PatternToMatch &Pattern,
473 std::vector > &GeneratedCode);
471474 void EmitInstructionSelector(std::ostream &OS);
472475 };
473476