[llvm] 2b452b4 - [TableGen] Change SubtargetFeatureInfo to use const Record pointers (#108013)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 08:53:24 PDT 2024
Author: Rahul Joshi
Date: 2024-09-11T08:53:21-07:00
New Revision: 2b452b455eefa0d91f59fefb8caf063983a72a02
URL: https://github.com/llvm/llvm-project/commit/2b452b455eefa0d91f59fefb8caf063983a72a02
DIFF: https://github.com/llvm/llvm-project/commit/2b452b455eefa0d91f59fefb8caf063983a72a02.diff
LOG: [TableGen] Change SubtargetFeatureInfo to use const Record pointers (#108013)
Change SubtargetFeatureInfo to use const Record pointers.
This is a part of effort to have better const correctness in TableGen
backends:
https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
Added:
Modified:
llvm/utils/TableGen/AsmMatcherEmitter.cpp
llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp
llvm/utils/TableGen/Common/SubtargetFeatureInfo.h
llvm/utils/TableGen/InstrInfoEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 4a1bf7ea5ef201..e4ce0f89fd8da1 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -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;
@@ -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
@@ -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;
}
@@ -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;
@@ -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())
diff --git a/llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp b/llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp
index a4d6d8d21b3562..738ddf77602475 100644
--- a/llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp
+++ b/llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp
@@ -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
diff --git a/llvm/utils/TableGen/Common/SubtargetFeatureInfo.h b/llvm/utils/TableGen/Common/SubtargetFeatureInfo.h
index fee2c0263c4960..d75a9a41636de3 100644
--- a/llvm/utils/TableGen/Common/SubtargetFeatureInfo.h
+++ b/llvm/utils/TableGen/Common/SubtargetFeatureInfo.h
@@ -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 {
@@ -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.
///
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index 5fd59141cd1e56..4e2138d15fde50 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -721,9 +721,9 @@ 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;
}
@@ -731,7 +731,7 @@ getNameForFeatureBitset(const std::vector<Record *> &FeatureBitset) {
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)) "
@@ -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())
@@ -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();
@@ -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;
More information about the llvm-commits
mailing list