-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[NFC][TableGen] Migrate LLVM RISCVTarget/VT Emitters to const RecordKeeper #107697
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
Member
|
@llvm/pr-subscribers-backend-risc-v Author: Rahul Joshi (jurahul) ChangesFull diff: https://github.com/llvm/llvm-project/pull/107697.diff 2 Files Affected:
diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index ae5ce32d617b47..1fbcba59f964d8 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -25,14 +25,14 @@ static StringRef getExtensionName(const Record *R) {
}
static void printExtensionTable(raw_ostream &OS,
- const std::vector<Record *> &Extensions,
+ ArrayRef<const Record *> Extensions,
bool Experimental) {
OS << "static const RISCVSupportedExtension Supported";
if (Experimental)
OS << "Experimental";
OS << "Extensions[] = {\n";
- for (Record *R : Extensions) {
+ for (const Record *R : Extensions) {
if (R->getValueAsBit("Experimental") != Experimental)
continue;
@@ -44,11 +44,11 @@ static void printExtensionTable(raw_ostream &OS,
OS << "};\n\n";
}
-static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
+static void emitRISCVExtensions(const RecordKeeper &Records, raw_ostream &OS) {
OS << "#ifdef GET_SUPPORTED_EXTENSIONS\n";
OS << "#undef GET_SUPPORTED_EXTENSIONS\n\n";
- std::vector<Record *> Extensions =
+ std::vector<const Record *> Extensions =
Records.getAllDerivedDefinitionsIfDefined("RISCVExtension");
llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
return getExtensionName(Rec1) < getExtensionName(Rec2);
@@ -66,7 +66,7 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
if (!Extensions.empty()) {
OS << "\nstatic constexpr ImpliedExtsEntry ImpliedExts[] = {\n";
- for (Record *Ext : Extensions) {
+ for (const Record *Ext : Extensions) {
auto ImpliesList = Ext->getValueAsListOfDefs("Implies");
if (ImpliesList.empty())
continue;
@@ -94,12 +94,12 @@ static void emitRISCVExtensions(RecordKeeper &Records, raw_ostream &OS) {
//
// This is almost the same as RISCVFeatures::parseFeatureBits, except that we
// get feature name from feature records instead of feature bits.
-static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
+static void printMArch(raw_ostream &OS, ArrayRef<const Record *> Features) {
RISCVISAUtils::OrderedExtensionMap Extensions;
unsigned XLen = 0;
// Convert features to FeatureVector.
- for (auto *Feature : Features) {
+ for (const Record *Feature : Features) {
StringRef FeatureName = getExtensionName(Feature);
if (Feature->isSubClassOf("RISCVExtension")) {
unsigned Major = Feature->getValueAsInt("MajorVersion");
@@ -124,7 +124,7 @@ static void printMArch(raw_ostream &OS, const std::vector<Record *> &Features) {
}
static void printProfileTable(raw_ostream &OS,
- const std::vector<Record *> &Profiles,
+ ArrayRef<const Record *> Profiles,
bool Experimental) {
OS << "static constexpr RISCVProfile Supported";
if (Experimental)
@@ -145,7 +145,7 @@ static void printProfileTable(raw_ostream &OS,
OS << "};\n\n";
}
-static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
+static void emitRISCVProfiles(const RecordKeeper &Records, raw_ostream &OS) {
OS << "#ifdef GET_SUPPORTED_PROFILES\n";
OS << "#undef GET_SUPPORTED_PROFILES\n\n";
@@ -163,7 +163,7 @@ static void emitRISCVProfiles(RecordKeeper &Records, raw_ostream &OS) {
OS << "#endif // GET_SUPPORTED_PROFILES\n\n";
}
-static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
+static void emitRISCVProcs(const RecordKeeper &RK, raw_ostream &OS) {
OS << "#ifndef PROC\n"
<< "#define PROC(ENUM, NAME, DEFAULT_MARCH, FAST_SCALAR_UNALIGN"
<< ", FAST_VECTOR_UNALIGN)\n"
@@ -210,9 +210,8 @@ static void emitRISCVProcs(RecordKeeper &RK, raw_ostream &OS) {
OS << "\n#undef TUNE_PROC\n";
}
-static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
-
- std::vector<Record *> Extensions =
+static void emitRISCVExtensionBitmask(const RecordKeeper &RK, raw_ostream &OS) {
+ std::vector<const Record *> Extensions =
RK.getAllDerivedDefinitionsIfDefined("RISCVExtensionBitmask");
llvm::sort(Extensions, [](const Record *Rec1, const Record *Rec2) {
return getExtensionName(Rec1) < getExtensionName(Rec2);
@@ -245,7 +244,7 @@ static void emitRISCVExtensionBitmask(RecordKeeper &RK, raw_ostream &OS) {
OS << "#endif\n";
}
-static void EmitRISCVTargetDef(RecordKeeper &RK, raw_ostream &OS) {
+static void EmitRISCVTargetDef(const RecordKeeper &RK, raw_ostream &OS) {
emitRISCVExtensions(RK, OS);
emitRISCVProfiles(RK, OS);
emitRISCVProcs(RK, OS);
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 6cfd29e710829f..8f4bcd5fccc73d 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -19,10 +19,10 @@ namespace {
class VTEmitter {
private:
- RecordKeeper &Records;
+ const RecordKeeper &Records;
public:
- VTEmitter(RecordKeeper &R) : Records(R) {}
+ VTEmitter(const RecordKeeper &R) : Records(R) {}
void run(raw_ostream &OS);
};
@@ -91,8 +91,7 @@ void VTEmitter::run(raw_ostream &OS) {
emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);
std::vector<const Record *> VTsByNumber{512};
- auto ValueTypes = Records.getAllDerivedDefinitions("ValueType");
- for (auto *VT : ValueTypes) {
+ for (auto *VT : Records.getAllDerivedDefinitions("ValueType")) {
auto Number = VT->getValueAsInt("Value");
assert(0 <= Number && Number < (int)VTsByNumber.size() &&
"ValueType should be uint16_t");
|
topperc
approved these changes
Sep 8, 2024
Collaborator
topperc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Migrate LLVM RISCVTarget/VT Emitters to const RecordKeeper.