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
14#include "llvm/IR/Function.h"
15#include "llvm/IR/Module.h"
17#include "llvm/Pass.h"
18#include <cassert>
19#include <memory>
20#include <string>
21
22using namespace llvm;
23
26 for (const auto &F : M) {
27 if (F.isDeclaration() || !F.hasGC())
28 continue;
29 if (!StrategyMap.contains(F.getGC()))
30 return true;
31 }
32 return false;
33}
34
35AnalysisKey CollectorMetadataAnalysis::Key;
36
39 Result R;
40 auto &Map = R.StrategyMap;
41 for (auto &F : M) {
42 if (F.isDeclaration() || !F.hasGC())
43 continue;
44 if (auto GCName = F.getGC(); !Map.contains(GCName))
45 Map[GCName] = getGCStrategy(GCName);
46 }
47 return R;
48}
49
50AnalysisKey GCFunctionAnalysis::Key;
51
54 assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
55 assert(F.hasGC() && "Function doesn't have GC!");
56
58 assert(
59 MAMProxy.cachedResultExists<CollectorMetadataAnalysis>(*F.getParent()) &&
60 "This pass need module analysis `collector-metadata`!");
61 auto &Map =
62 MAMProxy.getCachedResult<CollectorMetadataAnalysis>(*F.getParent())
63 ->StrategyMap;
64 GCFunctionInfo Info(F, *Map[F.getGC()]);
65 return Info;
66}
67
68INITIALIZE_PASS(GCModuleInfo, "collector-metadata",
69 "Create Garbage Collector Module Metadata", false, true)
70
71// -----------------------------------------------------------------------------
72
74 : F(F), S(S), FrameSize(~0LL) {}
75
77
80 auto PAC = PA.getChecker<GCFunctionAnalysis>();
81 return !PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Function>>();
82}
83
84// -----------------------------------------------------------------------------
85
86char GCModuleInfo::ID = 0;
87
90}
91
93 assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
94 assert(F.hasGC());
95
96 finfo_map_type::iterator I = FInfoMap.find(&F);
97 if (I != FInfoMap.end())
98 return *I->second;
99
100 GCStrategy *S = getGCStrategy(F.getGC());
101 Functions.push_back(std::make_unique<GCFunctionInfo>(F, *S));
102 GCFunctionInfo *GFI = Functions.back().get();
103 FInfoMap[&F] = GFI;
104 return *GFI;
105}
106
108 Functions.clear();
109 FInfoMap.clear();
110 GCStrategyList.clear();
111}
112
113// -----------------------------------------------------------------------------
114
116 // TODO: Arguably, just doing a linear search would be faster for small N
117 auto NMI = GCStrategyMap.find(Name);
118 if (NMI != GCStrategyMap.end())
119 return NMI->getValue();
120
121 std::unique_ptr<GCStrategy> S = llvm::getGCStrategy(Name);
122 S->Name = std::string(Name);
123 GCStrategyMap[Name] = S.get();
124 GCStrategyList.push_back(std::move(S));
125 return GCStrategyList.back().get();
126}
aarch64 promote const
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
std::string Name
Module.h This file contains the declarations for the Module class.
#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 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:410
An analysis pass which caches information about the entire Module.
Definition: GCMetadata.h:168
Result run(Module &M, ModuleAnalysisManager &MAM)
Definition: GCMetadata.cpp:38
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:156
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:53
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:78
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:92
static char ID
Definition: GCMetadata.h:234
void clear()
clear - Resets the pass.
Definition: GCMetadata.cpp:107
GCStrategy * getGCStrategy(const StringRef Name)
Lookup the GCStrategy object associated with the given gc name.
Definition: GCMetadata.cpp:115
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:692
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:51
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:24
StringMap< std::unique_ptr< GCStrategy > > StrategyMap
Definition: GCMetadata.h:155