LLVM 19.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"
18#include "llvm/MC/MCSymbol.h"
19#include "llvm/Pass.h"
21#include <cassert>
22#include <memory>
23#include <string>
24
25using namespace llvm;
26
29 for (const auto &F : M) {
30 if (F.isDeclaration() || !F.hasGC())
31 continue;
32 if (!StrategyMap.contains(F.getGC()))
33 return true;
34 }
35 return false;
36}
37
38AnalysisKey CollectorMetadataAnalysis::Key;
39
42 Result R;
43 auto &Map = R.StrategyMap;
44 for (auto &F : M) {
45 if (F.isDeclaration() || !F.hasGC())
46 continue;
47 if (auto GCName = F.getGC(); !Map.contains(GCName))
48 Map[GCName] = getGCStrategy(GCName);
49 }
50 return R;
51}
52
53AnalysisKey GCFunctionAnalysis::Key;
54
57 assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
58 assert(F.hasGC() && "Function doesn't have GC!");
59
61 assert(
62 MAMProxy.cachedResultExists<CollectorMetadataAnalysis>(*F.getParent()) &&
63 "This pass need module analysis `collector-metadata`!");
64 auto &Map =
65 MAMProxy.getCachedResult<CollectorMetadataAnalysis>(*F.getParent())
66 ->StrategyMap;
67 GCFunctionInfo Info(F, *Map[F.getGC()]);
68 return Info;
69}
70
71INITIALIZE_PASS(GCModuleInfo, "collector-metadata",
72 "Create Garbage Collector Module Metadata", false, false)
73
74// -----------------------------------------------------------------------------
75
77 : F(F), S(S), FrameSize(~0LL) {}
78
80
83 auto PAC = PA.getChecker<GCFunctionAnalysis>();
84 return !PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Function>>();
85}
86
87// -----------------------------------------------------------------------------
88
89char GCModuleInfo::ID = 0;
90
93}
94
96 assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
97 assert(F.hasGC());
98
99 finfo_map_type::iterator I = FInfoMap.find(&F);
100 if (I != FInfoMap.end())
101 return *I->second;
102
103 GCStrategy *S = getGCStrategy(F.getGC());
104 Functions.push_back(std::make_unique<GCFunctionInfo>(F, *S));
105 GCFunctionInfo *GFI = Functions.back().get();
106 FInfoMap[&F] = GFI;
107 return *GFI;
108}
109
111 Functions.clear();
112 FInfoMap.clear();
113 GCStrategyList.clear();
114}
115
116// -----------------------------------------------------------------------------
117
119 // TODO: Arguably, just doing a linear search would be faster for small N
120 auto NMI = GCStrategyMap.find(Name);
121 if (NMI != GCStrategyMap.end())
122 return NMI->getValue();
123
124 std::unique_ptr<GCStrategy> S = llvm::getGCStrategy(Name);
125 S->Name = std::string(Name);
126 GCStrategyMap[Name] = S.get();
127 GCStrategyList.push_back(std::move(S));
128 return GCStrategyList.back().get();
129}
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
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:47
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:281
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:242
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Definition: PassManager.h:394
An analysis pass which caches information about the entire Module.
Definition: GCMetadata.h:168
Result run(Module &M, ModuleAnalysisManager &MAM)
Definition: GCMetadata.cpp:41
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:56
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:81
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:95
static char ID
Definition: GCMetadata.h:234
void clear()
clear - Resets the pass.
Definition: GCMetadata.cpp:110
GCStrategy * getGCStrategy(const StringRef Name)
Lookup the GCStrategy object associated with the given gc name.
Definition: GCMetadata.cpp:118
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:282
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:677
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:109
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:26
bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &Inv)
Handle invalidation explicitly.
Definition: GCMetadata.cpp:27
StringMap< std::unique_ptr< GCStrategy > > StrategyMap
Definition: GCMetadata.h:155