@@ -997,6 +997,7 @@ class InstructionPredicateMatcher {
997
997
enum PredicateKind {
998
998
IPM_Opcode,
999
999
IPM_ImmPredicate,
1000
+ IPM_NonAtomicMMO,
1000
1001
};
1001
1002
1002
1003
PredicateKind Kind;
@@ -1125,6 +1126,24 @@ class InstructionImmPredicateMatcher : public InstructionPredicateMatcher {
1125
1126
}
1126
1127
};
1127
1128
1129
+ // / Generates code to check that a memory instruction has a non-atomic MachineMemoryOperand.
1130
+ class NonAtomicMMOPredicateMatcher : public InstructionPredicateMatcher {
1131
+ public:
1132
+ NonAtomicMMOPredicateMatcher ()
1133
+ : InstructionPredicateMatcher(IPM_NonAtomicMMO) {}
1134
+
1135
+ static bool classof (const InstructionPredicateMatcher *P) {
1136
+ return P->getKind () == IPM_NonAtomicMMO;
1137
+ }
1138
+
1139
+ void emitPredicateOpcodes (MatchTable &Table, RuleMatcher &Rule,
1140
+ unsigned InsnVarID) const override {
1141
+ Table << MatchTable::Opcode (" GIM_CheckNonAtomic" )
1142
+ << MatchTable::Comment (" MI" ) << MatchTable::IntValue (InsnVarID)
1143
+ << MatchTable::LineBreak;
1144
+ }
1145
+ };
1146
+
1128
1147
// / Generates code to check that a set of predicates and operands match for a
1129
1148
// / particular instruction.
1130
1149
// /
@@ -1991,9 +2010,11 @@ class GlobalISelEmitter {
1991
2010
const CodeGenTarget &Target;
1992
2011
CodeGenRegBank CGRegs;
1993
2012
1994
- // / Keep track of the equivalence between SDNodes and Instruction.
2013
+ // / Keep track of the equivalence between SDNodes and Instruction by mapping
2014
+ // / SDNodes to the GINodeEquiv mapping. We need to map to the GINodeEquiv to
2015
+ // / check for attributes on the relation such as CheckMMOIsNonAtomic.
1995
2016
// / This is defined using 'GINodeEquiv' in the target description.
1996
- DenseMap<Record *, const CodeGenInstruction *> NodeEquivs;
2017
+ DenseMap<Record *, Record *> NodeEquivs;
1997
2018
1998
2019
// / Keep track of the equivalence between ComplexPattern's and
1999
2020
// / GIComplexOperandMatcher. Map entries are specified by subclassing
@@ -2004,7 +2025,7 @@ class GlobalISelEmitter {
2004
2025
SubtargetFeatureInfoMap SubtargetFeatures;
2005
2026
2006
2027
void gatherNodeEquivs ();
2007
- const CodeGenInstruction *findNodeEquiv (Record *N) const ;
2028
+ Record *findNodeEquiv (Record *N) const ;
2008
2029
2009
2030
Error importRulePredicates (RuleMatcher &M, ArrayRef<Predicate> Predicates);
2010
2031
Expected<InstructionMatcher &>
@@ -2041,8 +2062,7 @@ class GlobalISelEmitter {
2041
2062
void GlobalISelEmitter::gatherNodeEquivs () {
2042
2063
assert (NodeEquivs.empty ());
2043
2064
for (Record *Equiv : RK.getAllDerivedDefinitions (" GINodeEquiv" ))
2044
- NodeEquivs[Equiv->getValueAsDef (" Node" )] =
2045
- &Target.getInstruction (Equiv->getValueAsDef (" I" ));
2065
+ NodeEquivs[Equiv->getValueAsDef (" Node" )] = Equiv;
2046
2066
2047
2067
assert (ComplexPatternEquivs.empty ());
2048
2068
for (Record *Equiv : RK.getAllDerivedDefinitions (" GIComplexPatternEquiv" )) {
@@ -2053,7 +2073,7 @@ void GlobalISelEmitter::gatherNodeEquivs() {
2053
2073
}
2054
2074
}
2055
2075
2056
- const CodeGenInstruction *GlobalISelEmitter::findNodeEquiv (Record *N) const {
2076
+ Record *GlobalISelEmitter::findNodeEquiv (Record *N) const {
2057
2077
return NodeEquivs.lookup (N);
2058
2078
}
2059
2079
@@ -2080,6 +2100,7 @@ Expected<InstructionMatcher &>
2080
2100
GlobalISelEmitter::createAndImportSelDAGMatcher (InstructionMatcher &InsnMatcher,
2081
2101
const TreePatternNode *Src,
2082
2102
unsigned &TempOpIdx) const {
2103
+ Record *SrcGIEquivOrNull = nullptr ;
2083
2104
const CodeGenInstruction *SrcGIOrNull = nullptr ;
2084
2105
2085
2106
// Start with the defined operands (i.e., the results of the root operator).
@@ -2095,14 +2116,14 @@ GlobalISelEmitter::createAndImportSelDAGMatcher(InstructionMatcher &InsnMatcher,
2095
2116
return failedImport (
2096
2117
" Unable to deduce gMIR opcode to handle Src (which is a leaf)" );
2097
2118
} else {
2098
- SrcGIOrNull = findNodeEquiv (Src->getOperator ());
2099
- if (!SrcGIOrNull )
2119
+ SrcGIEquivOrNull = findNodeEquiv (Src->getOperator ());
2120
+ if (!SrcGIEquivOrNull )
2100
2121
return failedImport (" Pattern operator lacks an equivalent Instruction" +
2101
2122
explainOperator (Src->getOperator ()));
2102
- auto &SrcGI = *SrcGIOrNull ;
2123
+ SrcGIOrNull = &Target. getInstruction (SrcGIEquivOrNull-> getValueAsDef ( " I " )) ;
2103
2124
2104
2125
// The operators look good: match the opcode
2105
- InsnMatcher.addPredicate <InstructionOpcodeMatcher>(&SrcGI );
2126
+ InsnMatcher.addPredicate <InstructionOpcodeMatcher>(SrcGIOrNull );
2106
2127
}
2107
2128
2108
2129
unsigned OpIdx = 0 ;
@@ -2132,6 +2153,8 @@ GlobalISelEmitter::createAndImportSelDAGMatcher(InstructionMatcher &InsnMatcher,
2132
2153
return failedImport (" Src pattern child has predicate (" +
2133
2154
explainPredicates (Src) + " )" );
2134
2155
}
2156
+ if (SrcGIEquivOrNull && SrcGIEquivOrNull->getValueAsBit (" CheckMMOIsNonAtomic" ))
2157
+ InsnMatcher.addPredicate <NonAtomicMMOPredicateMatcher>();
2135
2158
2136
2159
if (Src->isLeaf ()) {
2137
2160
Init *SrcInit = Src->getLeafValue ();
0 commit comments