summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2017-12-15 23:24:39 +0000
committerQuentin Colombet <qcolombet@apple.com>2017-12-15 23:24:39 +0000
commit02ede688c2c2f9d3bc254d112be98a51df704713 (patch)
tree2ea324bacf6c24b7a34a560091972da84da4157b /utils
parente9ec3f0771bb49d00293f6d9c45de7dd5490a9f3 (diff)
[TableGen][GlobalISel] Make the different Matcher comparable
This opens refactoring opportunities in the match table now that we can check that two predicates are the same. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320890 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/GlobalISelEmitter.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/utils/TableGen/GlobalISelEmitter.cpp b/utils/TableGen/GlobalISelEmitter.cpp
index b8ad1527906..88558894097 100644
--- a/utils/TableGen/GlobalISelEmitter.cpp
+++ b/utils/TableGen/GlobalISelEmitter.cpp
@@ -168,6 +168,8 @@ public:
return Ty.getSizeInBits() < Other.Ty.getSizeInBits();
}
+
+ bool operator==(const LLTCodeGen &B) const { return Ty == B.Ty; }
};
class InstructionMatcher;
@@ -819,6 +821,18 @@ public:
RuleMatcher &Rule) const = 0;
PredicateKind getKind() const { return Kind; }
+
+ virtual bool isIdentical(const PredicateMatcher &B) const {
+ if (InsnVarID != 0 || OpIdx != (unsigned)~0) {
+ // We currently don't hoist the record of instruction properly.
+ // Therefore we can only work on the orig instruction (InsnVarID
+ // == 0).
+ DEBUG(dbgs() << "Non-zero instr ID not supported yet\n");
+ return false;
+ }
+ return B.getKind() == getKind() && InsnVarID == B.InsnVarID &&
+ OpIdx == B.OpIdx;
+ }
};
/// Generates code to check a predicate of an operand.
@@ -890,6 +904,10 @@ public:
static bool classof(const PredicateMatcher *P) {
return P->getKind() == OPM_LLT;
}
+ bool isIdentical(const PredicateMatcher &B) const override {
+ return OperandPredicateMatcher::isIdentical(B) &&
+ Ty == cast<LLTOperandMatcher>(&B)->Ty;
+ }
void emitPredicateOpcodes(MatchTable &Table,
RuleMatcher &Rule) const override {
@@ -946,6 +964,8 @@ protected:
unsigned getAllocatedTemporariesBaseID() const;
public:
+ bool isIdentical(const PredicateMatcher &B) const override { return false; }
+
ComplexPatternOperandMatcher(const OperandMatcher &Operand,
const Record &TheDef, unsigned InsnVarID,
unsigned OpIdx)
@@ -982,6 +1002,11 @@ public:
unsigned OpIdx)
: OperandPredicateMatcher(OPM_RegBank, InsnVarID, OpIdx), RC(RC) {}
+ bool isIdentical(const PredicateMatcher &B) const override {
+ return OperandPredicateMatcher::isIdentical(B) &&
+ RC.getDef() == cast<RegisterBankOperandMatcher>(&B)->RC.getDef();
+ }
+
static bool classof(const PredicateMatcher *P) {
return P->getKind() == OPM_RegBank;
}
@@ -1025,6 +1050,11 @@ public:
ConstantIntOperandMatcher(int64_t Value, unsigned InsnVarID, unsigned OpIdx)
: OperandPredicateMatcher(OPM_Int, InsnVarID, OpIdx), Value(Value) {}
+ bool isIdentical(const PredicateMatcher &B) const override {
+ return OperandPredicateMatcher::isIdentical(B) &&
+ Value == cast<ConstantIntOperandMatcher>(&B)->Value;
+ }
+
static bool classof(const PredicateMatcher *P) {
return P->getKind() == OPM_Int;
}
@@ -1049,6 +1079,11 @@ public:
: OperandPredicateMatcher(OPM_LiteralInt, InsnVarID, OpIdx),
Value(Value) {}
+ bool isIdentical(const PredicateMatcher &B) const override {
+ return OperandPredicateMatcher::isIdentical(B) &&
+ Value == cast<LiteralIntOperandMatcher>(&B)->Value;
+ }
+
static bool classof(const PredicateMatcher *P) {
return P->getKind() == OPM_LiteralInt;
}
@@ -1072,6 +1107,11 @@ public:
unsigned OpIdx)
: OperandPredicateMatcher(OPM_IntrinsicID, InsnVarID, OpIdx), II(II) {}
+ bool isIdentical(const PredicateMatcher &B) const override {
+ return OperandPredicateMatcher::isIdentical(B) &&
+ II == cast<IntrinsicIDOperandMatcher>(&B)->II;
+ }
+
static bool classof(const PredicateMatcher *P) {
return P->getKind() == OPM_IntrinsicID;
}
@@ -1273,6 +1313,11 @@ public:
return P->getKind() == IPM_Opcode;
}
+ bool isIdentical(const PredicateMatcher &B) const override {
+ return InstructionPredicateMatcher::isIdentical(B) &&
+ I == cast<InstructionOpcodeMatcher>(&B)->I;
+ }
+
void emitPredicateOpcodes(MatchTable &Table,
RuleMatcher &Rule) const override {
Table << MatchTable::Opcode("GIM_CheckOpcode") << MatchTable::Comment("MI")
@@ -1342,6 +1387,13 @@ public:
: InstructionPredicateMatcher(IPM_ImmPredicate, InsnVarID),
Predicate(Predicate) {}
+ bool isIdentical(const PredicateMatcher &B) const override {
+ return InstructionPredicateMatcher::isIdentical(B) &&
+ Predicate.getOrigPatFragRecord() ==
+ cast<InstructionImmPredicateMatcher>(&B)
+ ->Predicate.getOrigPatFragRecord();
+ }
+
static bool classof(const PredicateMatcher *P) {
return P->getKind() == IPM_ImmPredicate;
}