Skip to content

[TableGen] Change SubtargetFeatureInfo to use const Record pointers #108013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions llvm/utils/TableGen/AsmMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ class AsmMatcherInfo {
RegisterClassesTy RegisterClasses;

/// Map of Predicate records to their subtarget information.
std::map<Record *, SubtargetFeatureInfo, LessRecordByID> SubtargetFeatures;
SubtargetFeatureInfoMap SubtargetFeatures;

/// Map of AsmOperandClass records to their class information.
std::map<const Record *, ClassInfo *> AsmOperandClasses;
Expand Down Expand Up @@ -1513,8 +1513,8 @@ void AsmMatcherInfo::buildOperandMatchInfo() {

void AsmMatcherInfo::buildInfo() {
// Build information about all of the AssemblerPredicates.
const std::vector<std::pair<Record *, SubtargetFeatureInfo>>
&SubtargetFeaturePairs = SubtargetFeatureInfo::getAll(Records);
SubtargetFeaturesInfoVec SubtargetFeaturePairs =
SubtargetFeatureInfo::getAll(Records);
SubtargetFeatures.insert(SubtargetFeaturePairs.begin(),
SubtargetFeaturePairs.end());
#ifndef NDEBUG
Expand Down Expand Up @@ -3226,9 +3226,9 @@ static void emitMatchClassKindNames(std::forward_list<ClassInfo> &Infos,
}

static std::string
getNameForFeatureBitset(const std::vector<Record *> &FeatureBitset) {
getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset) {
std::string Name = "AMFBS";
for (const auto &Feature : FeatureBitset)
for (const Record *Feature : FeatureBitset)
Name += ("_" + Feature->getName()).str();
return Name;
}
Expand Down Expand Up @@ -3451,7 +3451,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
StringTable.EmitString(OS);
OS << ";\n\n";

std::vector<std::vector<Record *>> FeatureBitsets;
std::vector<std::vector<const Record *>> FeatureBitsets;
for (const auto &MI : Info.Matchables) {
if (MI->RequiredFeatures.empty())
continue;
Expand All @@ -3460,8 +3460,8 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
FeatureBitsets.back().push_back(MI->RequiredFeatures[I]->TheDef);
}

llvm::sort(FeatureBitsets, [&](const std::vector<Record *> &A,
const std::vector<Record *> &B) {
llvm::sort(FeatureBitsets, [&](const std::vector<const Record *> &A,
const std::vector<const Record *> &B) {
if (A.size() < B.size())
return true;
if (A.size() > B.size())
Expand Down
10 changes: 4 additions & 6 deletions llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ LLVM_DUMP_METHOD void SubtargetFeatureInfo::dump() const {
}
#endif

std::vector<std::pair<Record *, SubtargetFeatureInfo>>
SubtargetFeatureInfo::getAll(RecordKeeper &Records) {
std::vector<std::pair<Record *, SubtargetFeatureInfo>> SubtargetFeatures;
std::vector<Record *> AllPredicates =
Records.getAllDerivedDefinitions("Predicate");
for (Record *Pred : AllPredicates) {
SubtargetFeaturesInfoVec
SubtargetFeatureInfo::getAll(const RecordKeeper &Records) {
SubtargetFeaturesInfoVec SubtargetFeatures;
for (const Record *Pred : Records.getAllDerivedDefinitions("Predicate")) {
// Ignore predicates that are not intended for the assembler.
//
// The "AssemblerMatcherPredicate" string should be promoted to an argument
Expand Down
12 changes: 7 additions & 5 deletions llvm/utils/TableGen/Common/SubtargetFeatureInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
namespace llvm {
struct SubtargetFeatureInfo;
using SubtargetFeatureInfoMap =
std::map<Record *, SubtargetFeatureInfo, LessRecordByID>;
std::map<const Record *, SubtargetFeatureInfo, LessRecordByID>;
using SubtargetFeaturesInfoVec =
std::vector<std::pair<const Record *, SubtargetFeatureInfo>>;

/// Helper class for storing information on a subtarget feature which
/// participates in instruction matching.
struct SubtargetFeatureInfo {
/// The predicate record for this feature.
Record *TheDef;
const Record *TheDef;

/// An unique index assigned to represent this feature.
uint64_t Index;

SubtargetFeatureInfo(Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}
SubtargetFeatureInfo(const Record *D, uint64_t Idx) : TheDef(D), Index(Idx) {}

/// The name of the enumerated constant identifying this feature.
std::string getEnumName() const {
Expand All @@ -48,8 +50,8 @@ struct SubtargetFeatureInfo {
}

void dump() const;
static std::vector<std::pair<Record *, SubtargetFeatureInfo>>
getAll(RecordKeeper &Records);

static SubtargetFeaturesInfoVec getAll(const RecordKeeper &Records);

/// Emit the subtarget feature flag definitions.
///
Expand Down
21 changes: 12 additions & 9 deletions llvm/utils/TableGen/InstrInfoEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,17 +721,17 @@ void InstrInfoEmitter::emitMCIIHelperMethods(raw_ostream &OS,
}

static std::string
getNameForFeatureBitset(const std::vector<Record *> &FeatureBitset) {
getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset) {
std::string Name = "CEFBS";
for (const auto &Feature : FeatureBitset)
for (const Record *Feature : FeatureBitset)
Name += ("_" + Feature->getName()).str();
return Name;
}

void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
const CodeGenTarget &Target) {
const auto &All = SubtargetFeatureInfo::getAll(Records);
std::map<Record *, SubtargetFeatureInfo, LessRecordByID> SubtargetFeatures;
SubtargetFeatureInfoMap SubtargetFeatures;
SubtargetFeatures.insert(All.begin(), All.end());

OS << "#if (defined(ENABLE_INSTR_PREDICATE_VERIFIER) && !defined(NDEBUG)) "
Expand All @@ -752,18 +752,19 @@ void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
SubtargetFeatureInfo::emitComputeAssemblerAvailableFeatures(
Target.getName(), "", "computeAvailableFeatures", SubtargetFeatures, OS);

std::vector<std::vector<Record *>> FeatureBitsets;
std::vector<std::vector<const Record *>> FeatureBitsets;
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
FeatureBitsets.emplace_back();
for (Record *Predicate : Inst->TheDef->getValueAsListOfDefs("Predicates")) {
for (const Record *Predicate :
Inst->TheDef->getValueAsListOfDefs("Predicates")) {
const auto &I = SubtargetFeatures.find(Predicate);
if (I != SubtargetFeatures.end())
FeatureBitsets.back().push_back(I->second.TheDef);
}
}

llvm::sort(FeatureBitsets, [&](const std::vector<Record *> &A,
const std::vector<Record *> &B) {
llvm::sort(FeatureBitsets, [&](const std::vector<const Record *> &A,
const std::vector<const Record *> &B) {
if (A.size() < B.size())
return true;
if (A.size() > B.size())
Expand Down Expand Up @@ -806,7 +807,8 @@ void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue()) {
OS << " CEFBS";
unsigned NumPredicates = 0;
for (Record *Predicate : Inst->TheDef->getValueAsListOfDefs("Predicates")) {
for (const Record *Predicate :
Inst->TheDef->getValueAsListOfDefs("Predicates")) {
const auto &I = SubtargetFeatures.find(Predicate);
if (I != SubtargetFeatures.end()) {
OS << '_' << I->second.TheDef->getName();
Expand Down Expand Up @@ -890,7 +892,8 @@ void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
void InstrInfoEmitter::emitTIIHelperMethods(raw_ostream &OS,
StringRef TargetName,
bool ExpandDefinition) {
RecVec TIIPredicates = Records.getAllDerivedDefinitions("TIIPredicate");
ArrayRef<const Record *> TIIPredicates =
Records.getAllDerivedDefinitions("TIIPredicate");
if (TIIPredicates.empty())
return;

Expand Down
Loading