llvm.org GIT mirror llvm / 2b43fff
TableGen: Refactor DAG patterns to enable parsing one pattern at a time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193526 91177308-0d34-0410-b5e6-96231b3b80d8 Ahmed Bougacha 7 years ago
2 changed file(s) with 66 addition(s) and 52 deletion(s). Raw diff Collapse all Expand all
26742674 return false;
26752675 }
26762676
2677 /// ParseInstructions - Parse all of the instructions, inlining and resolving
2678 /// any fragments involved. This populates the Instructions list with fully
2679 /// resolved instructions.
2680 void CodeGenDAGPatterns::ParseInstructions() {
2681 std::vector Instrs = Records.getAllDerivedDefinitions("Instruction");
2682
2683 for (unsigned i = 0, e = Instrs.size(); i != e; ++i) {
2684 ListInit *LI = 0;
2685
2686 if (isa(Instrs[i]->getValueInit("Pattern")))
2687 LI = Instrs[i]->getValueAsListInit("Pattern");
2688
2689 // If there is no pattern, only collect minimal information about the
2690 // instruction for its operand list. We have to assume that there is one
2691 // result, as we have no detailed info. A pattern which references the
2692 // null_frag operator is as-if no pattern were specified. Normally this
2693 // is from a multiclass expansion w/ a SDPatternOperator passed in as
2694 // null_frag.
2695 if (!LI || LI->getSize() == 0 || hasNullFragReference(LI)) {
2696 std::vector Results;
2697 std::vector Operands;
2698
2699 CodeGenInstruction &InstInfo = Target.getInstruction(Instrs[i]);
2700
2701 if (InstInfo.Operands.size() != 0) {
2702 if (InstInfo.Operands.NumDefs == 0) {
2703 // These produce no results
2704 for (unsigned j = 0, e = InstInfo.Operands.size(); j < e; ++j)
2705 Operands.push_back(InstInfo.Operands[j].Rec);
2706 } else {
2707 // Assume the first operand is the result.
2708 Results.push_back(InstInfo.Operands[0].Rec);
2709
2710 // The rest are inputs.
2711 for (unsigned j = 1, e = InstInfo.Operands.size(); j < e; ++j)
2712 Operands.push_back(InstInfo.Operands[j].Rec);
2713 }
2714 }
2715
2716 // Create and insert the instruction.
2717 std::vector ImpResults;
2718 Instructions.insert(std::make_pair(Instrs[i],
2719 DAGInstruction(0, Results, Operands, ImpResults)));
2720 continue; // no pattern.
2721 }
2677 const DAGInstruction &CodeGenDAGPatterns::parseInstructionPattern(
2678 CodeGenInstruction &CGI, ListInit *Pat, DAGInstMap &DAGInsts) {
2679
2680 assert(!DAGInsts.count(CGI.TheDef) && "Instruction already parsed!");
27222681
27232682 // Parse the instruction.
2724 TreePattern *I = new TreePattern(Instrs[i], LI, true, *this);
2683 TreePattern *I = new TreePattern(CGI.TheDef, Pat, true, *this);
27252684 // Inline pattern fragments into it.
27262685 I->InlinePatternFragments();
27272686
27602719
27612720 // Parse the operands list from the (ops) list, validating it.
27622721 assert(I->getArgList().empty() && "Args list should still be empty here!");
2763 CodeGenInstruction &CGI = Target.getInstruction(Instrs[i]);
27642722
27652723 // Check that all of the results occur first in the list.
27662724 std::vector Results;
28592817 // Create and insert the instruction.
28602818 // FIXME: InstImpResults should not be part of DAGInstruction.
28612819 DAGInstruction TheInst(I, Results, Operands, InstImpResults);
2862 Instructions.insert(std::make_pair(I->getRecord(), TheInst));
2820 DAGInsts.insert(std::make_pair(I->getRecord(), TheInst));
28632821
28642822 // Use a temporary tree pattern to infer all types and make sure that the
28652823 // constructed result is correct. This depends on the instruction already
2866 // being inserted into the Instructions map.
2824 // being inserted into the DAGInsts map.
28672825 TreePattern Temp(I->getRecord(), ResultPattern, false, *this);
28682826 Temp.InferAllTypes(&I->getNamedNodesMap());
28692827
2870 DAGInstruction &TheInsertedInst = Instructions.find(I->getRecord())->second;
2828 DAGInstruction &TheInsertedInst = DAGInsts.find(I->getRecord())->second;
28712829 TheInsertedInst.setResultPattern(Temp.getOnlyTree());
28722830
2873 DEBUG(I->dump());
2831 return TheInsertedInst;
2832 }
2833
2834 /// ParseInstructions - Parse all of the instructions, inlining and resolving
2835 /// any fragments involved. This populates the Instructions list with fully
2836 /// resolved instructions.
2837 void CodeGenDAGPatterns::ParseInstructions() {
2838 std::vector Instrs = Records.getAllDerivedDefinitions("Instruction");
2839
2840 for (unsigned i = 0, e = Instrs.size(); i != e; ++i) {
2841 ListInit *LI = 0;
2842
2843 if (isa(Instrs[i]->getValueInit("Pattern")))
2844 LI = Instrs[i]->getValueAsListInit("Pattern");
2845
2846 // If there is no pattern, only collect minimal information about the
2847 // instruction for its operand list. We have to assume that there is one
2848 // result, as we have no detailed info. A pattern which references the
2849 // null_frag operator is as-if no pattern were specified. Normally this
2850 // is from a multiclass expansion w/ a SDPatternOperator passed in as
2851 // null_frag.
2852 if (!LI || LI->getSize() == 0 || hasNullFragReference(LI)) {
2853 std::vector Results;
2854 std::vector Operands;
2855
2856 CodeGenInstruction &InstInfo = Target.getInstruction(Instrs[i]);
2857
2858 if (InstInfo.Operands.size() != 0) {
2859 if (InstInfo.Operands.NumDefs == 0) {
2860 // These produce no results
2861 for (unsigned j = 0, e = InstInfo.Operands.size(); j < e; ++j)
2862 Operands.push_back(InstInfo.Operands[j].Rec);
2863 } else {
2864 // Assume the first operand is the result.
2865 Results.push_back(InstInfo.Operands[0].Rec);
2866
2867 // The rest are inputs.
2868 for (unsigned j = 1, e = InstInfo.Operands.size(); j < e; ++j)
2869 Operands.push_back(InstInfo.Operands[j].Rec);
2870 }
2871 }
2872
2873 // Create and insert the instruction.
2874 std::vector ImpResults;
2875 Instructions.insert(std::make_pair(Instrs[i],
2876 DAGInstruction(0, Results, Operands, ImpResults)));
2877 continue; // no pattern.
2878 }
2879
2880 CodeGenInstruction &CGI = Target.getInstruction(Instrs[i]);
2881 const DAGInstruction &DI = parseInstructionPattern(CGI, LI, Instructions);
2882
2883 DEBUG(DI.getPattern()->dump());
28742884 }
28752885
28762886 // If we can, convert the instructions to be patterns that are matched!
777777 ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
778778 ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
779779
780
780 /// Parse the Pattern for an instruction, and insert the result in DAGInsts.
781 typedef std::map DAGInstMap;
782 const DAGInstruction &parseInstructionPattern(
783 CodeGenInstruction &CGI, ListInit *Pattern,
784 DAGInstMap &DAGInsts);
781785
782786 const DAGInstruction &getInstruction(Record *R) const {
783787 assert(Instructions.count(R) && "Unknown instruction!");