diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index 106fee39cb9f647..fc62b98b8418974 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 by value or reference. - // Const methods return std::vector by value or - // ArrayRef. - /// Get all the concrete records that inherit from the one specified /// class. The class must be defined. ArrayRef getAllDerivedDefinitions(StringRef ClassName) const; - const std::vector &getAllDerivedDefinitions(StringRef ClassName); /// Get all the concrete records that inherit from all the specified /// classes. The classes must be defined. std::vector getAllDerivedDefinitions(ArrayRef ClassNames) const; - std::vector - getAllDerivedDefinitions(ArrayRef 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 getAllDerivedDefinitionsIfDefined(StringRef ClassName) const; - const std::vector & - 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 - const VecTy & - getAllDerivedDefinitionsImpl(StringRef ClassName, - std::map &Cache) const; - - template - VecTy getAllDerivedDefinitionsImpl(ArrayRef ClassNames) const; - - template - const VecTy &getAllDerivedDefinitionsIfDefinedImpl( - StringRef ClassName, std::map &Cache) const; - std::string InputFilename; RecordMap Classes, Defs; - mutable std::map> - ClassRecordsMapConst; - mutable std::map> ClassRecordsMap; + mutable std::map> 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 c0c89836171b12b..315ea177098efde 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -3275,24 +3275,20 @@ void RecordKeeper::stopBackendTimer() { } } -template -const VecTy &RecordKeeper::getAllDerivedDefinitionsImpl( - StringRef ClassName, std::map &Cache) const { +ArrayRef +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(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 -VecTy RecordKeeper::getAllDerivedDefinitionsImpl( - ArrayRef ClassNames) const { +std::vector +RecordKeeper::getAllDerivedDefinitions(ArrayRef ClassNames) const { SmallVector ClassRecs; - VecTy Defs; + std::vector 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 -const VecTy &RecordKeeper::getAllDerivedDefinitionsIfDefinedImpl( - StringRef ClassName, std::map &Cache) const { - return getClass(ClassName) - ? getAllDerivedDefinitionsImpl(ClassName, Cache) - : Cache[""]; -} - -ArrayRef -RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) const { - return getAllDerivedDefinitionsImpl>( - ClassName, ClassRecordsMapConst); -} - -const std::vector & -RecordKeeper::getAllDerivedDefinitions(StringRef ClassName) { - return getAllDerivedDefinitionsImpl>(ClassName, - ClassRecordsMap); -} - -std::vector -RecordKeeper::getAllDerivedDefinitions(ArrayRef ClassNames) const { - return getAllDerivedDefinitionsImpl>(ClassNames); -} - -std::vector -RecordKeeper::getAllDerivedDefinitions(ArrayRef ClassNames) { - return getAllDerivedDefinitionsImpl>(ClassNames); -} - ArrayRef RecordKeeper::getAllDerivedDefinitionsIfDefined(StringRef ClassName) const { - return getAllDerivedDefinitionsIfDefinedImpl>( - ClassName, ClassRecordsMapConst); -} - -const std::vector & -RecordKeeper::getAllDerivedDefinitionsIfDefined(StringRef ClassName) { - return getAllDerivedDefinitionsIfDefinedImpl>( - ClassName, ClassRecordsMap); + if (getClass(ClassName)) + return getAllDerivedDefinitions(ClassName); + return Cache[""]; } void RecordKeeper::dumpAllocationStats(raw_ostream &OS) const {