Index: llvm/include/llvm/IR/GCStrategy.h =================================================================== --- llvm/include/llvm/IR/GCStrategy.h +++ llvm/include/llvm/IR/GCStrategy.h @@ -131,6 +131,9 @@ /// GCMetadataPrinterRegistery as well. using GCRegistry = Registry; +/// Lookup the GCStrategy object associated with the given gc name. +std::unique_ptr getGCStrategy(const StringRef Name); + } // end namespace llvm #endif // LLVM_IR_GCSTRATEGY_H Index: llvm/lib/CodeGen/GCMetadata.cpp =================================================================== --- llvm/lib/CodeGen/GCMetadata.cpp +++ llvm/lib/CodeGen/GCMetadata.cpp @@ -145,24 +145,9 @@ if (NMI != GCStrategyMap.end()) return NMI->getValue(); - for (auto& Entry : GCRegistry::entries()) { - if (Name == Entry.getName()) { - std::unique_ptr S = Entry.instantiate(); - S->Name = std::string(Name); - GCStrategyMap[Name] = S.get(); - GCStrategyList.push_back(std::move(S)); - return GCStrategyList.back().get(); - } - } - - if (GCRegistry::begin() == GCRegistry::end()) { - // In normal operation, the registry should not be empty. There should - // be the builtin GCs if nothing else. The most likely scenario here is - // that we got here without running the initializers used by the Registry - // itself and it's registration mechanism. - const std::string error = ("unsupported GC: " + Name).str() + - " (did you remember to link and initialize the CodeGen library?)"; - report_fatal_error(error); - } else - report_fatal_error(std::string("unsupported GC: ") + Name); + std::unique_ptr S = llvm::getGCStrategy(Name); + S->Name = std::string(Name); + GCStrategyMap[Name] = S.get(); + GCStrategyList.push_back(std::move(S)); + return GCStrategyList.back().get(); } Index: llvm/lib/IR/GCStrategy.cpp =================================================================== --- llvm/lib/IR/GCStrategy.cpp +++ llvm/lib/IR/GCStrategy.cpp @@ -18,3 +18,21 @@ LLVM_INSTANTIATE_REGISTRY(GCRegistry) GCStrategy::GCStrategy() = default; + +std::unique_ptr llvm::getGCStrategy(const StringRef Name) { + for (auto &S : GCRegistry::entries()) + if (S.getName() == Name) + return S.instantiate(); + + if (GCRegistry::begin() == GCRegistry::end()) { + // In normal operation, the registry should not be empty. There should + // be the builtin GCs if nothing else. The most likely scenario here is + // that we got here without running the initializers used by the Registry + // itself and it's registration mechanism. + const std::string error = + std::string("unsupported GC: ") + Name.str() + + " (did you remember to link and initialize the library?)"; + report_fatal_error(error); + } else + report_fatal_error(std::string("unsupported GC: ") + Name.str()); +}