[llvm] c5b6371 - [GC][NFC] Make getGCStrategy by name available in IR
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 2 00:26:23 PDT 2021
Author: Max Kazantsev
Date: 2021-08-02T14:26:04+07:00
New Revision: c5b63714b520a2b271809d5f1257e5b3737b12ac
URL: https://github.com/llvm/llvm-project/commit/c5b63714b520a2b271809d5f1257e5b3737b12ac
DIFF: https://github.com/llvm/llvm-project/commit/c5b63714b520a2b271809d5f1257e5b3737b12ac.diff
LOG: [GC][NFC] Make getGCStrategy by name available in IR
We might want to use info from GC strategy in middle end analysis.
The motivation for this is provided in D99135: we may want to ask
a GC if it's going to work with a given pointer (currently this code
makes naive check by the method name).
Differetial Revision: https://reviews.llvm.org/D100559
Reviewed By: reames
Added:
Modified:
llvm/include/llvm/IR/GCStrategy.h
llvm/lib/CodeGen/GCMetadata.cpp
llvm/lib/IR/GCStrategy.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/GCStrategy.h b/llvm/include/llvm/IR/GCStrategy.h
index a69958d596c67..4fa8e3a8dcf4f 100644
--- a/llvm/include/llvm/IR/GCStrategy.h
+++ b/llvm/include/llvm/IR/GCStrategy.h
@@ -131,6 +131,9 @@ class GCStrategy {
/// GCMetadataPrinterRegistery as well.
using GCRegistry = Registry<GCStrategy>;
+/// Lookup the GCStrategy object associated with the given gc name.
+std::unique_ptr<GCStrategy> getGCStrategy(const StringRef Name);
+
} // end namespace llvm
#endif // LLVM_IR_GCSTRATEGY_H
diff --git a/llvm/lib/CodeGen/GCMetadata.cpp b/llvm/lib/CodeGen/GCMetadata.cpp
index 8fae798b31d9a..af5515cc6bfd4 100644
--- a/llvm/lib/CodeGen/GCMetadata.cpp
+++ b/llvm/lib/CodeGen/GCMetadata.cpp
@@ -145,24 +145,9 @@ GCStrategy *GCModuleInfo::getGCStrategy(const StringRef Name) {
if (NMI != GCStrategyMap.end())
return NMI->getValue();
- for (auto& Entry : GCRegistry::entries()) {
- if (Name == Entry.getName()) {
- std::unique_ptr<GCStrategy> 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<GCStrategy> S = llvm::getGCStrategy(Name);
+ S->Name = std::string(Name);
+ GCStrategyMap[Name] = S.get();
+ GCStrategyList.push_back(std::move(S));
+ return GCStrategyList.back().get();
}
diff --git a/llvm/lib/IR/GCStrategy.cpp b/llvm/lib/IR/GCStrategy.cpp
index 25dad5bec9ef3..f3bc5b74f8fd3 100644
--- a/llvm/lib/IR/GCStrategy.cpp
+++ b/llvm/lib/IR/GCStrategy.cpp
@@ -18,3 +18,21 @@ using namespace llvm;
LLVM_INSTANTIATE_REGISTRY(GCRegistry)
GCStrategy::GCStrategy() = default;
+
+std::unique_ptr<GCStrategy> 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());
+}
More information about the llvm-commits
mailing list