LLVM 20.0.0git
GCMetadata.cpp
Go to the documentation of this file.
1//===-- GCMetadata.cpp - Garbage collector metadata -----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the GCFunctionInfo class and GCModuleInfo pass.
10//
11//===----------------------------------------------------------------------===//
12
15#include "llvm/CodeGen/Passes.h"
16#include "llvm/IR/Function.h"
17#include "llvm/IR/Module.h"
19#include "llvm/MC/MCSymbol.h"
20#include "llvm/Pass.h"
22#include <cassert>
23#include <memory>
24#include <string>
25
26using namespace llvm;
27
30 for (const auto &F : M) {
31 if (F.isDeclaration() || !F.hasGC())
32 continue;
33 if (!StrategyMap.contains(F.getGC()))
34 return true;
35 }
36 return false;
37}
38
39AnalysisKey CollectorMetadataAnalysis::Key;
40
43 Result R;
44 auto &Map = R.StrategyMap;
45 for (auto &F : M) {
46 if (F.isDeclaration() || !F.hasGC())
47 continue;
48 if (auto GCName = F.getGC(); !Map.contains(GCName))
49 Map[GCName] = getGCStrategy(GCName);
50 }
51 return R;
52}
53
54AnalysisKey GCFunctionAnalysis::Key;
55
58 assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
59 assert(F.hasGC() && "Function doesn't have GC!");
60
62 assert(
63 MAMProxy.cachedResultExists<CollectorMetadataAnalysis>(*F.getParent()) &&
64 "This pass need module analysis `collector-metadata`!");
65 auto &Map =
66 MAMProxy.getCachedResult<CollectorMetadataAnalysis>(*F.getParent())
67 ->StrategyMap;
68 GCFunctionInfo Info(F, *Map[F.getGC()]);
69 return Info;
70}
71
72INITIALIZE_PASS(GCModuleInfo, "collector-metadata",
73 "Create Garbage Collector Module Metadata", false, false)
74
75// -----------------------------------------------------------------------------
76
78 : F(F), S(S), FrameSize(~0LL) {}
79
81
84 auto PAC = PA.getChecker<GCFunctionAnalysis>();
85 return !PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Function>>();
86}
87
88// -----------------------------------------------------------------------------
89
90char GCModuleInfo::ID = 0;
91
94}
95
97 assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
98 assert(F.hasGC());
99
100 finfo_map_type::iterator I = FInfoMap.find(&F);
101 if (I != FInfoMap.end())
102 return *I->second;
103
104 GCStrategy *S = getGCStrategy(F.getGC());
105 Functions.push_back(std::make_unique<GCFunctionInfo>(F, *S));
106 GCFunctionInfo *GFI = Functions.back().get();
107 FInfoMap[&F] = GFI;
108 return *GFI;
109}
110
112 Functions.clear();
113 FInfoMap.clear();
114 GCStrategyList.clear();
115}
116
117// -----------------------------------------------------------------------------
118
120 // TODO: Arguably, just doing a linear search would be faster for small N
121 auto NMI = GCStrategyMap.find(Name);
122 if (NMI != GCStrategyMap.end())
123 return NMI->getValue();
124
125 std::unique_ptr<GCStrategy> S = llvm::getGCStrategy(Name);
126 S->Name = std::string(Name);
127 GCStrategyMap[Name] = S.get();
128 GCStrategyList.push_back(std::move(S));
129 return GCStrategyList.back().get();
130}
aarch64 promote const
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
std::string Name
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some functions that are useful when dealing with strings.
This templated class represents "all analyses that operate over <a particular IR unit>" (e....
Definition: Analysis.h:49
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:292
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:405
An analysis pass which caches information about the entire Module.
Definition: GCMetadata.h:168
Result run(Module &M, ModuleAnalysisManager &MAM)
Definition: GCMetadata.cpp:42
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
iterator end()
Definition: DenseMap.h:84
An analysis pass which caches information about the Function.
Definition: GCMetadata.h:180
Result run(Function &F, FunctionAnalysisManager &FAM)
Definition: GCMetadata.cpp:57
Garbage collection metadata for a single function.
Definition: GCMetadata.h:78
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation explicitly.
Definition: GCMetadata.cpp:82
An analysis pass which caches information about the entire Module.
Definition: GCMetadata.h:203
GCFunctionInfo & getFunctionInfo(const Function &F)
get - Look up function metadata.
Definition: GCMetadata.cpp:96
static char ID
Definition: GCMetadata.h:234
void clear()
clear - Resets the pass.
Definition: GCMetadata.cpp:111
GCStrategy * getGCStrategy(const StringRef Name)
Lookup the GCStrategy object associated with the given gc name.
Definition: GCMetadata.cpp:119
GCStrategy describes a garbage collector algorithm's code generation requirements,...
Definition: GCStrategy.h:63
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:281
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
An analysis over an "inner" IR unit that provides access to an analysis manager over a "outer" IR uni...
Definition: PassManager.h:688
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: Analysis.h:264
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeGCModuleInfoPass(PassRegistry &)
std::unique_ptr< GCStrategy > getGCStrategy(const StringRef Name)
Lookup the GCStrategy object associated with the given gc name.
Definition: GCStrategy.cpp:24
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &Inv)
Handle invalidation explicitly.
Definition: GCMetadata.cpp:28
StringMap< std::unique_ptr< GCStrategy > > StrategyMap
Definition: GCMetadata.h:155