@@ -46,8 +46,12 @@ class X86CompressEVEXTablesEmitter {
46
46
47
47
typedef std::pair<const CodeGenInstruction *, const CodeGenInstruction *>
48
48
Entry;
49
+ typedef std::map<const Record *, std::vector<const CodeGenInstruction *>>
50
+ PredicateInstMap;
49
51
50
52
std::vector<Entry> Table;
53
+ // Hold all compressed instructions that need to check predicate
54
+ PredicateInstMap PredicateInsts;
51
55
52
56
public:
53
57
X86CompressEVEXTablesEmitter (RecordKeeper &R) : Records(R), Target(R) {}
@@ -58,12 +62,15 @@ class X86CompressEVEXTablesEmitter {
58
62
private:
59
63
// Prints the given table as a C++ array of type X86CompressEVEXTableEntry
60
64
void printTable (const std::vector<Entry> &Table, raw_ostream &OS);
65
+ // Prints function which checks target feature for compressed instructions.
66
+ void printCheckPredicate (const PredicateInstMap &PredicateInsts,
67
+ raw_ostream &OS);
61
68
};
62
69
63
70
void X86CompressEVEXTablesEmitter::printTable (const std::vector<Entry> &Table,
64
71
raw_ostream &OS) {
65
72
66
- OS << " static const X86CompressEVEXTableEntry X86CompressEVEXTable[] = { \n " ;
73
+ OS << " static const X86CompressEVEXTableEntry X86CompressEVEXTable[] = {\n " ;
67
74
68
75
// Print all entries added to the table
69
76
for (const auto &Pair : Table)
@@ -73,6 +80,22 @@ void X86CompressEVEXTablesEmitter::printTable(const std::vector<Entry> &Table,
73
80
OS << " };\n\n " ;
74
81
}
75
82
83
+ void X86CompressEVEXTablesEmitter::printCheckPredicate (
84
+ const PredicateInstMap &PredicateInsts, raw_ostream &OS) {
85
+
86
+ OS << " static bool checkPredicate(unsigned Opc, const X86Subtarget *Subtarget) {\n "
87
+ << " switch (Opc) {\n "
88
+ << " default: return true;\n " ;
89
+ for (const auto &[Key, Val] : PredicateInsts) {
90
+ for (const auto &Inst : Val)
91
+ OS << " case X86::" << Inst->TheDef ->getName () << " :\n " ;
92
+ OS << " return " << Key->getValueAsString (" CondString" ) << " ;\n " ;
93
+ }
94
+
95
+ OS << " }\n " ;
96
+ OS << " };\n\n " ;
97
+ }
98
+
76
99
static uint8_t byteFromBitsInit (const BitsInit *B) {
77
100
unsigned N = B->getNumBits ();
78
101
assert (N <= 8 && " Field is too large for uint8_t!" );
@@ -196,9 +219,18 @@ void X86CompressEVEXTablesEmitter::run(raw_ostream &OS) {
196
219
continue ;
197
220
198
221
Table.push_back (std::make_pair (Inst, NewInst));
222
+ auto Predicates = NewInst->TheDef ->getValueAsListOfDefs (" Predicates" );
223
+ auto It = llvm::find_if (Predicates, [](const Record *R) {
224
+ StringRef Name = R->getName ();
225
+ return Name == " HasAVXNECONVERT" || Name == " HasAVXVNNI" ||
226
+ Name == " HasAVXIFMA" ;
227
+ });
228
+ if (It!= Predicates.end ())
229
+ PredicateInsts[*It].push_back (NewInst);
199
230
}
200
231
201
232
printTable (Table, OS);
233
+ printCheckPredicate (PredicateInsts, OS);
202
234
}
203
235
} // namespace
204
236
0 commit comments