Skip to content

Commit 62a1ea2

Browse files
committed
Review feedback
1 parent ae4f936 commit 62a1ea2

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,9 @@ void SubtargetFeatureInfo::emitMCPredicateCheck(
190190
bool ParenIfBinOp = range_size(MCPredicates) > 1;
191191
for (const Record *R : MCPredicates) {
192192
OS << LS;
193-
emitFeaturesAux(TargetName, *R->getValueAsDag("AssemblerCondDag"),
194-
ParenIfBinOp, OS);
193+
if (emitFeaturesAux(TargetName, *R->getValueAsDag("AssemblerCondDag"),
194+
ParenIfBinOp, OS))
195+
PrintFatalError(R, "Invalid AssemblerCondDag!");
195196
}
196197
}
197198

@@ -206,12 +207,14 @@ void SubtargetFeatureInfo::emitComputeAssemblerAvailableFeatures(
206207
OS << "const ";
207208
OS << "{\n";
208209
OS << " FeatureBitset Features;\n";
209-
for (const auto &SF : SubtargetFeatures) {
210-
const SubtargetFeatureInfo &SFI = SF.second;
210+
for (const SubtargetFeatureInfo &SFI : make_second_range(SubtargetFeatures)) {
211+
const Record *Def = SFI.TheDef;
211212

212213
OS << " if (";
213-
emitFeaturesAux(TargetName, *SFI.TheDef->getValueAsDag("AssemblerCondDag"),
214-
/*ParenIfBinOp=*/false, OS);
214+
if (emitFeaturesAux(TargetName, *Def->getValueAsDag("AssemblerCondDag"),
215+
/*ParenIfBinOp=*/false, OS))
216+
PrintFatalError(Def, "Invalid AssemblerCondDag!");
217+
215218
OS << ")\n";
216219
OS << " Features.set(" << SFI.getEnumBitName() << ");\n";
217220
}

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "Common/InfoByHwMode.h"
1818
#include "Common/InstructionEncoding.h"
1919
#include "Common/VarLenCodeEmitterGen.h"
20+
#include "Common/SubtargetFeatureInfo.h"
2021
#include "TableGenBackends.h"
2122
#include "llvm/ADT/APInt.h"
2223
#include "llvm/ADT/ArrayRef.h"
@@ -517,7 +518,7 @@ class DecoderTableBuilder {
517518
bool emitPredicateMatchAux(const Init &Val, bool ParenIfBinOp,
518519
raw_ostream &OS) const;
519520

520-
bool emitPredicateMatch(raw_ostream &OS, unsigned EncodingID) const;
521+
void emitPredicateMatch(raw_ostream &OS, unsigned EncodingID) const;
521522

522523
void emitPredicateTableEntry(unsigned EncodingID) const;
523524

@@ -837,7 +838,7 @@ void DecoderEmitter::emitPredicateFunction(formatted_raw_ostream &OS,
837838
// The predicate function is just a big switch statement based on the
838839
// input predicate index.
839840
OS << "static bool checkDecoderPredicate(unsigned Idx, const FeatureBitset "
840-
"&Bits) {\n";
841+
"&FB) {\n";
841842
OS << " switch (Idx) {\n";
842843
OS << " default: llvm_unreachable(\"Invalid index!\");\n";
843844
for (const auto &[Index, Predicate] : enumerate(Predicates)) {
@@ -1132,27 +1133,14 @@ bool DecoderTableBuilder::emitPredicateMatchAux(const Init &Val,
11321133
return true;
11331134
}
11341135

1135-
bool DecoderTableBuilder::emitPredicateMatch(raw_ostream &OS,
1136+
void DecoderTableBuilder::emitPredicateMatch(raw_ostream &OS,
11361137
unsigned EncodingID) const {
1137-
const ListInit *Predicates =
1138+
const ListInit *PredicateList =
11381139
Encodings[EncodingID].getRecord()->getValueAsListInit("Predicates");
1139-
ListSeparator LS(" && ");
1140-
bool AnyPredicate = false;
1141-
for (unsigned i = 0; i < Predicates->size(); ++i) {
1142-
const Record *Pred = Predicates->getElementAsRecord(i);
1143-
if (!Pred->getValue("AssemblerMatcherPredicate"))
1144-
continue;
1145-
1146-
if (!isa<DagInit>(Pred->getValue("AssemblerCondDag")->getValue()))
1147-
continue;
1148-
1149-
AnyPredicate = true;
1150-
OS << LS;
1151-
if (emitPredicateMatchAux(*Pred->getValueAsDag("AssemblerCondDag"),
1152-
Predicates->size() > 1, OS))
1153-
PrintFatalError(Pred->getLoc(), "Invalid AssemblerCondDag!");
1154-
}
1155-
return AnyPredicate;
1140+
std::vector<const Record *> Predicates;
1141+
for (unsigned i = 0; i < PredicateList->size(); ++i)
1142+
Predicates.push_back(PredicateList->getElementAsRecord(i));
1143+
SubtargetFeatureInfo::emitMCPredicateCheck(OS, Target.getName(), Predicates);
11561144
}
11571145

11581146
unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
@@ -1172,10 +1160,12 @@ unsigned DecoderTableBuilder::getPredicateIndex(StringRef Predicate) const {
11721160
void DecoderTableBuilder::emitPredicateTableEntry(unsigned EncodingID) const {
11731161
// Build up the predicate string.
11741162
SmallString<256> Predicate;
1175-
// FIXME: emitPredicateMatch() functions can take a buffer directly rather
1176-
// than a stream.
11771163
raw_svector_ostream PS(Predicate);
1178-
if (!emitPredicateMatch(PS, EncodingID))
1164+
emitPredicateMatch(PS, EncodingID);
1165+
// Predicate being empty indicates that there are no predicates.
1166+
// Predicate being "false" indicate that there are predicates but with no
1167+
// AssemblerMatcherPredicate.
1168+
if (Predicate.empty() || Predicate == "false")
11791169
return;
11801170

11811171
// Figure out the index into the predicate table for the predicate just

0 commit comments

Comments
 (0)