@@ -143,10 +143,11 @@ class X86FoldTablesEmitter {
143143 typedef std::map<const CodeGenInstruction *, X86FoldTableEntry,
144144 CompareInstrsByEnum>
145145 FoldTable;
146- // std::vector for each folding table.
147- // Table2Addr - Holds instructions which their memory form performs load+store
148- // Table#i - Holds instructions which the their memory form perform a load OR
149- // a store, and their #i'th operand is folded.
146+ // Table2Addr - Holds instructions which their memory form performs
147+ // load+store.
148+ //
149+ // Table#i - Holds instructions which the their memory form
150+ // performs a load OR a store, and their #i'th operand is folded.
150151 FoldTable Table2Addr;
151152 FoldTable Table0;
152153 FoldTable Table1;
@@ -168,7 +169,7 @@ class X86FoldTablesEmitter {
168169 bool IsManual = false );
169170
170171 // Generates X86FoldTableEntry with the given instructions and fill it with
171- // the appropriate flags - then adds it to Table .
172+ // the appropriate flags, then adds it to a memory fold table .
172173 void addEntryWithFlags (FoldTable &Table, const CodeGenInstruction *RegInst,
173174 const CodeGenInstruction *MemInst, uint16_t S,
174175 unsigned FoldedIdx, bool IsManual);
@@ -300,6 +301,8 @@ class IsMatch {
300301 const Record *MemRec = MemInst->TheDef ;
301302
302303 // EVEX_B means different things for memory and register forms.
304+ // register form: rounding control or SAE
305+ // memory form: broadcast
303306 if (RegRI.HasEVEX_B || MemRI.HasEVEX_B )
304307 return false ;
305308
@@ -582,6 +585,13 @@ void X86FoldTablesEmitter::run(raw_ostream &O) {
582585
583586 Record *AsmWriter = Target.getAsmWriter ();
584587 unsigned Variant = AsmWriter->getValueAsInt (" Variant" );
588+ auto FixUp = [&](const CodeGenInstruction *RegInst) {
589+ StringRef RegInstName = RegInst->TheDef ->getName ();
590+ if (RegInstName.ends_with (" _REV" ) || RegInstName.ends_with (" _alt" ))
591+ if (auto *RegAltRec = Records.getDef (RegInstName.drop_back (4 )))
592+ RegInst = &Target.getInstruction (RegAltRec);
593+ return RegInst;
594+ };
585595 // For each memory form instruction, try to find its register form
586596 // instruction.
587597 for (const CodeGenInstruction *MemInst : MemInsts) {
@@ -598,13 +608,7 @@ void X86FoldTablesEmitter::run(raw_ostream &O) {
598608
599609 auto Match = find_if (OpcRegInsts, IsMatch (MemInst, Variant));
600610 if (Match != OpcRegInsts.end ()) {
601- const CodeGenInstruction *RegInst = *Match;
602- StringRef RegInstName = RegInst->TheDef ->getName ();
603- if (RegInstName.ends_with (" _REV" ) || RegInstName.ends_with (" _alt" ))
604- if (auto *RegAltRec = Records.getDef (RegInstName.drop_back (4 )))
605- RegInst = &Target.getInstruction (RegAltRec);
606-
607- updateTables (RegInst, MemInst);
611+ updateTables (FixUp (*Match), MemInst);
608612 OpcRegInsts.erase (Match);
609613 }
610614 }
0 commit comments