16
16
#include " Common/CodeGenTarget.h"
17
17
#include " Common/InfoByHwMode.h"
18
18
#include " Common/InstructionEncoding.h"
19
+ #include " Common/SubtargetFeatureInfo.h"
19
20
#include " Common/VarLenCodeEmitterGen.h"
20
21
#include " TableGenBackends.h"
21
22
#include " llvm/ADT/APInt.h"
@@ -519,8 +520,6 @@ class DecoderTableBuilder {
519
520
520
521
bool emitPredicateMatch (raw_ostream &OS, unsigned EncodingID) const ;
521
522
522
- bool doesOpcodeNeedPredicate (unsigned EncodingID) const ;
523
-
524
523
void emitPredicateTableEntry (unsigned EncodingID) const ;
525
524
526
525
void emitSoftFailTableEntry (unsigned EncodingID) const ;
@@ -839,12 +838,12 @@ void DecoderEmitter::emitPredicateFunction(formatted_raw_ostream &OS,
839
838
// The predicate function is just a big switch statement based on the
840
839
// input predicate index.
841
840
OS << " static bool checkDecoderPredicate(unsigned Idx, const FeatureBitset "
842
- " &Bits ) {\n " ;
841
+ " &FB ) {\n " ;
843
842
OS << " switch (Idx) {\n " ;
844
843
OS << " default: llvm_unreachable(\" Invalid index!\" );\n " ;
845
844
for (const auto &[Index, Predicate] : enumerate(Predicates)) {
846
845
OS << " case " << Index << " :\n " ;
847
- OS << " return ( " << Predicate << " ) ;\n " ;
846
+ OS << " return " << Predicate << " ;\n " ;
848
847
}
849
848
OS << " }\n " ;
850
849
OS << " }\n\n " ;
@@ -1134,41 +1133,19 @@ bool DecoderTableBuilder::emitPredicateMatchAux(const Init &Val,
1134
1133
return true ;
1135
1134
}
1136
1135
1136
+ // Returns true if there was any predicate emitted.
1137
1137
bool DecoderTableBuilder::emitPredicateMatch (raw_ostream &OS,
1138
1138
unsigned EncodingID) const {
1139
- const ListInit *Predicates =
1140
- Encodings[EncodingID].getRecord ()->getValueAsListInit (" Predicates" );
1141
- bool IsFirstEmission = true ;
1142
- for (unsigned i = 0 ; i < Predicates->size (); ++i) {
1143
- const Record *Pred = Predicates->getElementAsRecord (i);
1144
- if (!Pred->getValue (" AssemblerMatcherPredicate" ))
1145
- continue ;
1146
-
1147
- if (!isa<DagInit>(Pred->getValue (" AssemblerCondDag" )->getValue ()))
1148
- continue ;
1149
-
1150
- if (!IsFirstEmission)
1151
- OS << " && " ;
1152
- if (emitPredicateMatchAux (*Pred->getValueAsDag (" AssemblerCondDag" ),
1153
- Predicates->size () > 1 , OS))
1154
- PrintFatalError (Pred->getLoc (), " Invalid AssemblerCondDag!" );
1155
- IsFirstEmission = false ;
1156
- }
1157
- return !Predicates->empty ();
1158
- }
1159
-
1160
- bool DecoderTableBuilder::doesOpcodeNeedPredicate (unsigned EncodingID) const {
1161
- const ListInit *Predicates =
1162
- Encodings[EncodingID].getRecord ()->getValueAsListInit (" Predicates" );
1163
- for (unsigned i = 0 ; i < Predicates->size (); ++i) {
1164
- const Record *Pred = Predicates->getElementAsRecord (i);
1165
- if (!Pred->getValue (" AssemblerMatcherPredicate" ))
1166
- continue ;
1167
-
1168
- if (isa<DagInit>(Pred->getValue (" AssemblerCondDag" )->getValue ()))
1169
- return true ;
1170
- }
1171
- return false ;
1139
+ std::vector<const Record *> Predicates =
1140
+ Encodings[EncodingID].getRecord ()->getValueAsListOfDefs (" Predicates" );
1141
+ auto It = llvm::find_if (Predicates, [](const Record *R) {
1142
+ return R->getValueAsBit (" AssemblerMatcherPredicate" );
1143
+ });
1144
+ bool AnyAsmPredicate = It != Predicates.end ();
1145
+ if (!AnyAsmPredicate)
1146
+ return false ;
1147
+ SubtargetFeatureInfo::emitMCPredicateCheck (OS, Target.getName (), Predicates);
1148
+ return true ;
1172
1149
}
1173
1150
1174
1151
unsigned DecoderTableBuilder::getPredicateIndex (StringRef Predicate) const {
@@ -1186,15 +1163,11 @@ unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
1186
1163
}
1187
1164
1188
1165
void DecoderTableBuilder::emitPredicateTableEntry (unsigned EncodingID) const {
1189
- if (!doesOpcodeNeedPredicate (EncodingID))
1190
- return ;
1191
-
1192
1166
// Build up the predicate string.
1193
1167
SmallString<256 > Predicate;
1194
- // FIXME: emitPredicateMatch() functions can take a buffer directly rather
1195
- // than a stream.
1196
1168
raw_svector_ostream PS (Predicate);
1197
- emitPredicateMatch (PS, EncodingID);
1169
+ if (!emitPredicateMatch (PS, EncodingID))
1170
+ return ;
1198
1171
1199
1172
// Figure out the index into the predicate table for the predicate just
1200
1173
// computed.
0 commit comments