-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[TableGen] Delete non-const overloads of getAllDerivedDefinitions
#110990
Merged
jurahul
merged 1 commit into
llvm:main
from
jurahul:delete_non_const_get_all_derived_definitions
Oct 3, 2024
Merged
[TableGen] Delete non-const overloads of getAllDerivedDefinitions
#110990
jurahul
merged 1 commit into
llvm:main
from
jurahul:delete_non_const_get_all_derived_definitions
Oct 3, 2024
Conversation
This file contains 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
Now that all TableGen backends have transitioned to const versions of these functions, we do not need the non-const versions anymore.
@llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) ChangesNow that all TableGen backends have transitioned to const versions of these functions, we do not need the non-const versions anymore. Full diff: https://github.com/llvm/llvm-project/pull/110990.diff 2 Files Affected:
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 106fee39cb9f64..fc62b98b841897 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -2058,28 +2058,19 @@ class RecordKeeper {
//===--------------------------------------------------------------------===//
// High-level helper methods, useful for tablegen backends.
- // Non-const methods return std::vector<Record *> by value or reference.
- // Const methods return std::vector<const Record *> by value or
- // ArrayRef<const Record *>.
-
/// Get all the concrete records that inherit from the one specified
/// class. The class must be defined.
ArrayRef<const Record *> getAllDerivedDefinitions(StringRef ClassName) const;
- const std::vector<Record *> &getAllDerivedDefinitions(StringRef ClassName);
/// Get all the concrete records that inherit from all the specified
/// classes. The classes must be defined.
std::vector<const Record *>
getAllDerivedDefinitions(ArrayRef<StringRef> ClassNames) const;
- std::vector<Record *>
- getAllDerivedDefinitions(ArrayRef<StringRef> ClassNames);
/// Get all the concrete records that inherit from specified class, if the
/// class is defined. Returns an empty vector if the class is not defined.
ArrayRef<const Record *>
getAllDerivedDefinitionsIfDefined(StringRef ClassName) const;
- const std::vector<Record *> &
- getAllDerivedDefinitionsIfDefined(StringRef ClassName);
void dump() const;
@@ -2091,24 +2082,9 @@ class RecordKeeper {
RecordKeeper &operator=(RecordKeeper &&) = delete;
RecordKeeper &operator=(const RecordKeeper &) = delete;
- // Helper template functions for backend accessors.
- template <typename VecTy>
- const VecTy &
- getAllDerivedDefinitionsImpl(StringRef ClassName,
- std::map<std::string, VecTy> &Cache) const;
-
- template <typename VecTy>
- VecTy getAllDerivedDefinitionsImpl(ArrayRef<StringRef> ClassNames) const;
-
- template <typename VecTy>
- const VecTy &getAllDerivedDefinitionsIfDefinedImpl(
- StringRef ClassName, std::map<std::string, VecTy> &Cache) const;
-
std::string InputFilename;
RecordMap Classes, Defs;
- mutable std::map<std::string, std::vector<const Record *>>
- ClassRecordsMapConst;
- mutable std::map<std::string, std::vector<Record *>> ClassRecordsMap;
+ mutable std::map<std::string, std::vector<const Record *>> Cache;
GlobalMap ExtraGlobals;
// TODO: Move timing related code out of RecordKeeper.
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index c0c89836171b12..315ea177098efd 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -3275,24 +3275,20 @@ void RecordKeeper::stopBackendTimer() {
}
}
-template <typename VecTy>
-const VecTy &RecordKeeper::getAllDerivedDefinitionsImpl(
- StringRef ClassName, std::map<std::string, VecTy> &Cache) const {
+ArrayRef<const Record *>
+RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const {
// We cache the record vectors for single classes. Many backends request
// the same vectors multiple times.
- auto Pair = Cache.try_emplace(ClassName.str());
- if (Pair.second)
- Pair.first->second =
- getAllDerivedDefinitionsImpl<VecTy>(ArrayRef(ClassName));
-
- return Pair.first->second;
+ auto [Iter, Inserted] = Cache.try_emplace(ClassName.str());
+ if (Inserted)
+ Iter->second = getAllDerivedDefinitions(ArrayRef(ClassName));
+ return Iter->second;
}
-template <typename VecTy>
-VecTy RecordKeeper::getAllDerivedDefinitionsImpl(
- ArrayRef<StringRef> ClassNames) const {
+std::vector<const Record *>
+RecordKeeper::getAllDerivedDefinitions(ArrayRef<StringRef> ClassNames) const {
SmallVector<const Record *, 2> ClassRecs;
- VecTy Defs;
+ std::vector<const Record *> Defs;
assert(ClassNames.size() > 0 && "At least one class must be passed.");
for (const auto &ClassName : ClassNames) {
@@ -3312,46 +3308,11 @@ VecTy RecordKeeper::getAllDerivedDefinitionsImpl(
return Defs;
}
-template <typename VecTy>
-const VecTy &RecordKeeper::getAllDerivedDefinitionsIfDefinedImpl(
- StringRef ClassName, std::map<std::string, VecTy> &Cache) const {
- return getClass(ClassName)
- ? getAllDerivedDefinitionsImpl<VecTy>(ClassName, Cache)
- : Cache[""];
-}
-
-ArrayRef<const Record *>
-RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const {
- return getAllDerivedDefinitionsImpl<std::vector<const Record *>>(
- ClassName, ClassRecordsMapConst);
-}
-
-const std::vector<Record *> &
-RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) {
- return getAllDerivedDefinitionsImpl<std::vector<Record *>>(ClassName,
- ClassRecordsMap);
-}
-
-std::vector<const Record *>
-RecordKeeper::getAllDerivedDefinitions(ArrayRef<StringRef> ClassNames) const {
- return getAllDerivedDefinitionsImpl<std::vector<const Record *>>(ClassNames);
-}
-
-std::vector<Record *>
-RecordKeeper::getAllDerivedDefinitions(ArrayRef<StringRef> ClassNames) {
- return getAllDerivedDefinitionsImpl<std::vector<Record *>>(ClassNames);
-}
-
ArrayRef<const Record *>
RecordKeeper::getAllDerivedDefinitionsIfDefined(StringRef ClassName) const {
- return getAllDerivedDefinitionsIfDefinedImpl<std::vector<const Record *>>(
- ClassName, ClassRecordsMapConst);
-}
-
-const std::vector<Record *> &
-RecordKeeper::getAllDerivedDefinitionsIfDefined(StringRef ClassName) {
- return getAllDerivedDefinitionsIfDefinedImpl<std::vector<Record *>>(
- ClassName, ClassRecordsMap);
+ if (getClass(ClassName))
+ return getAllDerivedDefinitions(ClassName);
+ return Cache[""];
}
void RecordKeeper::dumpAllocationStats(raw_ostream &OS) const {
|
arsenm
approved these changes
Oct 3, 2024
xgupta
pushed a commit
to xgupta/llvm-project
that referenced
this pull request
Oct 4, 2024
…lvm#110990) Now that all TableGen backends have transitioned to const versions of these functions, we do not need the non-const versions anymore. 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
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.
Now that all TableGen backends have transitioned to const versions of these functions, we do not need the non-const versions anymore.
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