llvm.org GIT mirror llvm / 36d15d6
[GlobalISel][InstructionSelect] Refactoring out a getMatchTable virtual method + other small NFC's The main goal is to share getMatchTable between the Instruction Selector and the Testgen. The commit also contains some NFC only loosely related to refactoring out the getMatchTable, but strongly related to the initial Testgen patch (see https://reviews.llvm.org/D43962) Reviewers: dsanders, aemerson Reviewed By: dsanders Subscribers: rovka, kristof.beyls, llvm-commits, dsanders Differential Revision: https://reviews.llvm.org/D46096 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331395 91177308-0d34-0410-b5e6-96231b3b80d8 Roman Tereshin 1 year, 5 months ago
3 changed file(s) with 47 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
220220 /// Add a temporary register to the specified instruction
221221 /// - InsnID - Instruction ID to modify
222222 /// - TempRegID - The temporary register ID to add
223 /// - TempRegFlags - The register flags to set
223224 GIR_AddTempRegister,
224225 /// Add an immediate to the specified instruction
225226 /// - InsnID - Instruction ID to modify
275276 /// Increment the rule coverage counter.
276277 /// - RuleID - The ID of the rule that was covered.
277278 GIR_Coverage,
279
280 GIU_NumOpcodes,
278281 };
279282
280283 enum {
340343 const RegisterBankInfo &RBI, const PredicateBitset &AvailableFeatures,
341344 CodeGenCoverage &CoverageInfo) const;
342345
346 virtual const int64_t *getMatchTable() const {
347 llvm_unreachable("Should have been overridden by tablegen if used");
348 }
349
343350 virtual bool testImmPredicate_I64(unsigned, int64_t) const {
344351 llvm_unreachable("Subclasses must override this to use tablegen");
345352 }
7777 // CHECK-NEXT: bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const override;
7878 // CHECK-NEXT: bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) const override;
7979 // CHECK-NEXT: bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat &Imm) const override;
80 // CHECK-NEXT: const int64_t *getMatchTable() const override;
8081 // CHECK-NEXT: #endif // ifdef GET_GLOBALISEL_TEMPORARIES_DECL
8182
8283 // CHECK-LABEL: #ifdef GET_GLOBALISEL_TEMPORARIES_INIT
220221 // CHECK-NEXT: State.MIs.clear();
221222 // CHECK-NEXT: State.MIs.push_back(&I);
222223
224 // CHECK: if (executeMatchTable(*this, OutMIs, State, ISelInfo, getMatchTable(), TII, MRI, TRI, RBI, AvailableFeatures, CoverageInfo)) {
225 // CHECK-NEXT: return true;
226 // CHECK-NEXT: }
227
223228 //===- Test a pattern with multiple ComplexPatterns in multiple instrs ----===//
224229 //
225230
226 // CHECK-LABEL: MatchTable0[] = {
231 // CHECK: const int64_t *
232 // CHECK-LABEL: MyTargetInstructionSelector::getMatchTable() const {
233 // CHECK: MatchTable0[] = {
227234 // OPT-NEXT: GIM_Try, /*On fail goto*//*Label [[GRP_LABEL_NUM:[0-9]+]]*/ [[GRP_LABEL:[0-9]+]],
228235 // OPT-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_SELECT,
229236 // CHECK-NEXT: GIM_Try, /*On fail goto*//*Label [[LABEL_NUM:[0-9]+]]*/ [[LABEL:[0-9]+]],
10991106
11001107 // CHECK-NEXT: GIM_Reject,
11011108 // CHECK-NEXT: };
1102 // CHECK-NEXT: if (executeMatchTable(*this, OutMIs, State, ISelInfo, MatchTable0, TII, MRI, TRI, RBI, AvailableFeatures, CoverageInfo)) {
1103 // CHECK-NEXT: return true;
1104 // CHECK-NEXT: }
1109 // CHECK-NEXT: return MatchTable0;
37663766 << "InstructionSelector::ComplexMatcherMemFn ComplexPredicateFns[];\n"
37673767 << " static " << Target.getName()
37683768 << "InstructionSelector::CustomRendererFn CustomRenderers[];\n"
3769 << "bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const "
3769 << " bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const "
37703770 "override;\n"
3771 << "bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) "
3771 << " bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) "
37723772 "const override;\n"
3773 << "bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat "
3773 << " bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat "
37743774 "&Imm) const override;\n"
3775 << " const int64_t *getMatchTable() const override;\n"
37753776 << "#endif // ifdef GET_GLOBALISEL_TEMPORARIES_DECL\n\n";
37763777
37773778 OS << "#ifdef GET_GLOBALISEL_TEMPORARIES_INIT\n"
39233924 << ", // " << Record->getName() << "\n";
39243925 OS << "};\n\n";
39253926
3926 OS << "bool " << Target.getName()
3927 << "InstructionSelector::selectImpl(MachineInstr &I, CodeGenCoverage "
3928 "&CoverageInfo) const {\n"
3929 << " MachineFunction &MF = *I.getParent()->getParent();\n"
3930 << " MachineRegisterInfo &MRI = MF.getRegInfo();\n"
3931 << " // FIXME: This should be computed on a per-function basis rather "
3932 "than per-insn.\n"
3933 << " AvailableFunctionFeatures = computeAvailableFunctionFeatures(&STI, "
3934 "&MF);\n"
3935 << " const PredicateBitset AvailableFeatures = getAvailableFeatures();\n"
3936 << " NewMIVector OutMIs;\n"
3937 << " State.MIs.clear();\n"
3938 << " State.MIs.push_back(&I);\n\n";
3939
39403927 std::stable_sort(Rules.begin(), Rules.end(), [&](const RuleMatcher &A,
39413928 const RuleMatcher &B) {
39423929 int ScoreA = RuleMatcherScores[A.getRuleID()];
39683955 Rule->emit(Table);
39693956
39703957 Table << MatchTable::Opcode("GIM_Reject") << MatchTable::LineBreak;
3958
3959 OS << "bool " << Target.getName()
3960 << "InstructionSelector::selectImpl(MachineInstr &I, CodeGenCoverage "
3961 "&CoverageInfo) const {\n"
3962 << " MachineFunction &MF = *I.getParent()->getParent();\n"
3963 << " MachineRegisterInfo &MRI = MF.getRegInfo();\n"
3964 << " // FIXME: This should be computed on a per-function basis rather "
3965 "than per-insn.\n"
3966 << " AvailableFunctionFeatures = computeAvailableFunctionFeatures(&STI, "
3967 "&MF);\n"
3968 << " const PredicateBitset AvailableFeatures = getAvailableFeatures();\n"
3969 << " NewMIVector OutMIs;\n"
3970 << " State.MIs.clear();\n"
3971 << " State.MIs.push_back(&I);\n\n"
3972 << " if (executeMatchTable(*this, OutMIs, State, ISelInfo"
3973 << ", getMatchTable(), TII, MRI, TRI, RBI, AvailableFeatures"
3974 << ", CoverageInfo)) {\n"
3975 << " return true;\n"
3976 << " }\n\n"
3977 << " return false;\n"
3978 << "}\n\n";
3979
3980 OS << "const int64_t *" << Target.getName()
3981 << "InstructionSelector::getMatchTable() const {\n";
39713982 Table.emitDeclaration(OS);
3972 OS << " if (executeMatchTable(*this, OutMIs, State, ISelInfo, ";
3983 OS << " return ";
39733984 Table.emitUse(OS);
3974 OS << ", TII, MRI, TRI, RBI, AvailableFeatures, CoverageInfo)) {\n"
3975 << " return true;\n"
3976 << " }\n\n";
3977
3978 OS << " return false;\n"
3979 << "}\n"
3980 << "#endif // ifdef GET_GLOBALISEL_IMPL\n";
3985 OS << ";\n}\n";
3986 OS << "#endif // ifdef GET_GLOBALISEL_IMPL\n";
39813987
39823988 OS << "#ifdef GET_GLOBALISEL_PREDICATES_DECL\n"
39833989 << "PredicateBitset AvailableModuleFeatures;\n"