[llvm] r331395 - [GlobalISel][InstructionSelect] Refactoring out a getMatchTable virtual method + other small NFC's
Roman Tereshin via llvm-commits
llvm-commits at lists.llvm.org
Wed May 2 13:07:15 PDT 2018
Author: rtereshin
Date: Wed May 2 13:07:15 2018
New Revision: 331395
URL: http://llvm.org/viewvc/llvm-project?rev=331395&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelector.h
llvm/trunk/test/TableGen/GlobalISelEmitter.td
llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelector.h?rev=331395&r1=331394&r2=331395&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelector.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/InstructionSelector.h Wed May 2 13:07:15 2018
@@ -221,6 +221,7 @@ enum {
/// Add a temporary register to the specified instruction
/// - InsnID - Instruction ID to modify
/// - TempRegID - The temporary register ID to add
+ /// - TempRegFlags - The register flags to set
GIR_AddTempRegister,
/// Add an immediate to the specified instruction
/// - InsnID - Instruction ID to modify
@@ -276,6 +277,8 @@ enum {
/// Increment the rule coverage counter.
/// - RuleID - The ID of the rule that was covered.
GIR_Coverage,
+
+ GIU_NumOpcodes,
};
enum {
@@ -341,6 +344,10 @@ protected:
const RegisterBankInfo &RBI, const PredicateBitset &AvailableFeatures,
CodeGenCoverage &CoverageInfo) const;
+ virtual const int64_t *getMatchTable() const {
+ llvm_unreachable("Should have been overridden by tablegen if used");
+ }
+
virtual bool testImmPredicate_I64(unsigned, int64_t) const {
llvm_unreachable("Subclasses must override this to use tablegen");
}
Modified: llvm/trunk/test/TableGen/GlobalISelEmitter.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/GlobalISelEmitter.td?rev=331395&r1=331394&r2=331395&view=diff
==============================================================================
--- llvm/trunk/test/TableGen/GlobalISelEmitter.td (original)
+++ llvm/trunk/test/TableGen/GlobalISelEmitter.td Wed May 2 13:07:15 2018
@@ -78,6 +78,7 @@ def HasC : Predicate<"Subtarget->hasC()"
// CHECK-NEXT: bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const override;
// CHECK-NEXT: bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) const override;
// CHECK-NEXT: bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat &Imm) const override;
+// CHECK-NEXT: const int64_t *getMatchTable() const override;
// CHECK-NEXT: #endif // ifdef GET_GLOBALISEL_TEMPORARIES_DECL
// CHECK-LABEL: #ifdef GET_GLOBALISEL_TEMPORARIES_INIT
@@ -221,10 +222,16 @@ def HasC : Predicate<"Subtarget->hasC()"
// CHECK-NEXT: State.MIs.clear();
// CHECK-NEXT: State.MIs.push_back(&I);
+// CHECK: if (executeMatchTable(*this, OutMIs, State, ISelInfo, getMatchTable(), TII, MRI, TRI, RBI, AvailableFeatures, CoverageInfo)) {
+// CHECK-NEXT: return true;
+// CHECK-NEXT: }
+
//===- Test a pattern with multiple ComplexPatterns in multiple instrs ----===//
//
-// CHECK-LABEL: MatchTable0[] = {
+// CHECK: const int64_t *
+// CHECK-LABEL: MyTargetInstructionSelector::getMatchTable() const {
+// CHECK: MatchTable0[] = {
// OPT-NEXT: GIM_Try, /*On fail goto*//*Label [[GRP_LABEL_NUM:[0-9]+]]*/ [[GRP_LABEL:[0-9]+]],
// OPT-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_SELECT,
// CHECK-NEXT: GIM_Try, /*On fail goto*//*Label [[LABEL_NUM:[0-9]+]]*/ [[LABEL:[0-9]+]],
@@ -1100,6 +1107,4 @@ def BR : I<(outs), (ins unknown:$target)
// CHECK-NEXT: GIM_Reject,
// CHECK-NEXT: };
-// CHECK-NEXT: if (executeMatchTable(*this, OutMIs, State, ISelInfo, MatchTable0, TII, MRI, TRI, RBI, AvailableFeatures, CoverageInfo)) {
-// CHECK-NEXT: return true;
-// CHECK-NEXT: }
+// CHECK-NEXT: return MatchTable0;
Modified: llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp?rev=331395&r1=331394&r2=331395&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/GlobalISelEmitter.cpp Wed May 2 13:07:15 2018
@@ -3767,12 +3767,13 @@ void GlobalISelEmitter::run(raw_ostream
<< "InstructionSelector::ComplexMatcherMemFn ComplexPredicateFns[];\n"
<< " static " << Target.getName()
<< "InstructionSelector::CustomRendererFn CustomRenderers[];\n"
- << "bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const "
+ << " bool testImmPredicate_I64(unsigned PredicateID, int64_t Imm) const "
"override;\n"
- << "bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) "
+ << " bool testImmPredicate_APInt(unsigned PredicateID, const APInt &Imm) "
"const override;\n"
- << "bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat "
+ << " bool testImmPredicate_APFloat(unsigned PredicateID, const APFloat "
"&Imm) const override;\n"
+ << " const int64_t *getMatchTable() const override;\n"
<< "#endif // ifdef GET_GLOBALISEL_TEMPORARIES_DECL\n\n";
OS << "#ifdef GET_GLOBALISEL_TEMPORARIES_INIT\n"
@@ -3924,20 +3925,6 @@ void GlobalISelEmitter::run(raw_ostream
<< ", // " << Record->getName() << "\n";
OS << "};\n\n";
- OS << "bool " << Target.getName()
- << "InstructionSelector::selectImpl(MachineInstr &I, CodeGenCoverage "
- "&CoverageInfo) const {\n"
- << " MachineFunction &MF = *I.getParent()->getParent();\n"
- << " MachineRegisterInfo &MRI = MF.getRegInfo();\n"
- << " // FIXME: This should be computed on a per-function basis rather "
- "than per-insn.\n"
- << " AvailableFunctionFeatures = computeAvailableFunctionFeatures(&STI, "
- "&MF);\n"
- << " const PredicateBitset AvailableFeatures = getAvailableFeatures();\n"
- << " NewMIVector OutMIs;\n"
- << " State.MIs.clear();\n"
- << " State.MIs.push_back(&I);\n\n";
-
std::stable_sort(Rules.begin(), Rules.end(), [&](const RuleMatcher &A,
const RuleMatcher &B) {
int ScoreA = RuleMatcherScores[A.getRuleID()];
@@ -3969,16 +3956,35 @@ void GlobalISelEmitter::run(raw_ostream
Rule->emit(Table);
Table << MatchTable::Opcode("GIM_Reject") << MatchTable::LineBreak;
- Table.emitDeclaration(OS);
- OS << " if (executeMatchTable(*this, OutMIs, State, ISelInfo, ";
- Table.emitUse(OS);
- OS << ", TII, MRI, TRI, RBI, AvailableFeatures, CoverageInfo)) {\n"
+
+ OS << "bool " << Target.getName()
+ << "InstructionSelector::selectImpl(MachineInstr &I, CodeGenCoverage "
+ "&CoverageInfo) const {\n"
+ << " MachineFunction &MF = *I.getParent()->getParent();\n"
+ << " MachineRegisterInfo &MRI = MF.getRegInfo();\n"
+ << " // FIXME: This should be computed on a per-function basis rather "
+ "than per-insn.\n"
+ << " AvailableFunctionFeatures = computeAvailableFunctionFeatures(&STI, "
+ "&MF);\n"
+ << " const PredicateBitset AvailableFeatures = getAvailableFeatures();\n"
+ << " NewMIVector OutMIs;\n"
+ << " State.MIs.clear();\n"
+ << " State.MIs.push_back(&I);\n\n"
+ << " if (executeMatchTable(*this, OutMIs, State, ISelInfo"
+ << ", getMatchTable(), TII, MRI, TRI, RBI, AvailableFeatures"
+ << ", CoverageInfo)) {\n"
<< " return true;\n"
- << " }\n\n";
+ << " }\n\n"
+ << " return false;\n"
+ << "}\n\n";
- OS << " return false;\n"
- << "}\n"
- << "#endif // ifdef GET_GLOBALISEL_IMPL\n";
+ OS << "const int64_t *" << Target.getName()
+ << "InstructionSelector::getMatchTable() const {\n";
+ Table.emitDeclaration(OS);
+ OS << " return ";
+ Table.emitUse(OS);
+ OS << ";\n}\n";
+ OS << "#endif // ifdef GET_GLOBALISEL_IMPL\n";
OS << "#ifdef GET_GLOBALISEL_PREDICATES_DECL\n"
<< "PredicateBitset AvailableModuleFeatures;\n"
More information about the llvm-commits
mailing list