aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/CodeGen/GCMetadata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/GCMetadata.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/CodeGen/GCMetadata.cpp113
1 files changed, 46 insertions, 67 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/GCMetadata.cpp b/contrib/llvm-project/llvm/lib/CodeGen/GCMetadata.cpp
index 4d27143c5298..cad7d1f1137b 100644
--- a/contrib/llvm-project/llvm/lib/CodeGen/GCMetadata.cpp
+++ b/contrib/llvm-project/llvm/lib/CodeGen/GCMetadata.cpp
@@ -24,24 +24,49 @@
using namespace llvm;
-namespace {
-
-class Printer : public FunctionPass {
- static char ID;
-
- raw_ostream &OS;
-
-public:
- explicit Printer(raw_ostream &OS) : FunctionPass(ID), OS(OS) {}
+bool GCStrategyMap::invalidate(Module &M, const PreservedAnalyses &PA,
+ ModuleAnalysisManager::Invalidator &) {
+ for (const auto &F : M) {
+ if (F.isDeclaration() || !F.hasGC())
+ continue;
+ if (!StrategyMap.contains(F.getGC()))
+ return true;
+ }
+ return false;
+}
- StringRef getPassName() const override;
- void getAnalysisUsage(AnalysisUsage &AU) const override;
+AnalysisKey CollectorMetadataAnalysis::Key;
+
+CollectorMetadataAnalysis::Result
+CollectorMetadataAnalysis::run(Module &M, ModuleAnalysisManager &MAM) {
+ Result R;
+ auto &Map = R.StrategyMap;
+ for (auto &F : M) {
+ if (F.isDeclaration() || !F.hasGC())
+ continue;
+ if (auto GCName = F.getGC(); !Map.contains(GCName))
+ Map[GCName] = getGCStrategy(GCName);
+ }
+ return R;
+}
- bool runOnFunction(Function &F) override;
- bool doFinalization(Module &M) override;
-};
+AnalysisKey GCFunctionAnalysis::Key;
-} // end anonymous namespace
+GCFunctionAnalysis::Result
+GCFunctionAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
+ assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
+ assert(F.hasGC() && "Function doesn't have GC!");
+
+ auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
+ assert(
+ MAMProxy.cachedResultExists<CollectorMetadataAnalysis>(*F.getParent()) &&
+ "This pass need module analysis `collector-metadata`!");
+ auto &Map =
+ MAMProxy.getCachedResult<CollectorMetadataAnalysis>(*F.getParent())
+ ->StrategyMap;
+ GCFunctionInfo Info(F, *Map[F.getGC()]);
+ return Info;
+}
INITIALIZE_PASS(GCModuleInfo, "collector-metadata",
"Create Garbage Collector Module Metadata", false, false)
@@ -53,6 +78,12 @@ GCFunctionInfo::GCFunctionInfo(const Function &F, GCStrategy &S)
GCFunctionInfo::~GCFunctionInfo() = default;
+bool GCFunctionInfo::invalidate(Function &F, const PreservedAnalyses &PA,
+ FunctionAnalysisManager::Invalidator &) {
+ auto PAC = PA.getChecker<GCFunctionAnalysis>();
+ return !PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Function>>();
+}
+
// -----------------------------------------------------------------------------
char GCModuleInfo::ID = 0;
@@ -84,58 +115,6 @@ void GCModuleInfo::clear() {
// -----------------------------------------------------------------------------
-char Printer::ID = 0;
-
-FunctionPass *llvm::createGCInfoPrinter(raw_ostream &OS) {
- return new Printer(OS);
-}
-
-StringRef Printer::getPassName() const {
- return "Print Garbage Collector Information";
-}
-
-void Printer::getAnalysisUsage(AnalysisUsage &AU) const {
- FunctionPass::getAnalysisUsage(AU);
- AU.setPreservesAll();
- AU.addRequired<GCModuleInfo>();
-}
-
-bool Printer::runOnFunction(Function &F) {
- if (F.hasGC())
- return false;
-
- GCFunctionInfo *FD = &getAnalysis<GCModuleInfo>().getFunctionInfo(F);
-
- OS << "GC roots for " << FD->getFunction().getName() << ":\n";
- for (GCFunctionInfo::roots_iterator RI = FD->roots_begin(),
- RE = FD->roots_end();
- RI != RE; ++RI)
- OS << "\t" << RI->Num << "\t" << RI->StackOffset << "[sp]\n";
-
- OS << "GC safe points for " << FD->getFunction().getName() << ":\n";
- for (GCFunctionInfo::iterator PI = FD->begin(), PE = FD->end(); PI != PE;
- ++PI) {
-
- OS << "\t" << PI->Label->getName() << ": " << "post-call"
- << ", live = {";
-
- ListSeparator LS(",");
- for (const GCRoot &R : make_range(FD->live_begin(PI), FD->live_end(PI)))
- OS << LS << " " << R.Num;
-
- OS << " }\n";
- }
-
- return false;
-}
-
-bool Printer::doFinalization(Module &M) {
- GCModuleInfo *GMI = getAnalysisIfAvailable<GCModuleInfo>();
- assert(GMI && "Printer didn't require GCModuleInfo?!");
- GMI->clear();
- return false;
-}
-
GCStrategy *GCModuleInfo::getGCStrategy(const StringRef Name) {
// TODO: Arguably, just doing a linear search would be faster for small N
auto NMI = GCStrategyMap.find(Name);