llvm.org GIT mirror llvm / 07fbc5c
Move ownership of GCStrategy objects to LLVMContext Note: This change ended up being slightly more controversial than expected. Chandler has tentatively okayed this for the moment, but I may be revisiting this in the near future after we settle some high level questions. Rather than have the GCStrategy object owned by the GCModuleInfo - which is an immutable analysis pass used mainly by gc.root - have it be owned by the LLVMContext. This simplifies the ownership logic (i.e. can you have two instances of the same strategy at once?), but more importantly, allows us to access the GCStrategy in the middle end optimizer. To this end, I add an accessor through Function which becomes the canonical way to get at a GCStrategy instance. In the near future, this will allows me to move some of the checks from http://reviews.llvm.org/D6808 into the Verifier itself, and to introduce optimization legality predicates for some of the recent additions to InstCombine. (These will follow as separate changes.) Differential Revision: http://reviews.llvm.org/D6811 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226311 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 5 years ago
23 changed file(s) with 296 addition(s) and 260 deletion(s). Raw diff Collapse all Expand all
3535 #include "llvm/ADT/DenseMap.h"
3636 #include "llvm/ADT/StringMap.h"
3737 #include "llvm/IR/DebugLoc.h"
38 #include "llvm/IR/GCStrategy.h"
3839 #include "llvm/Pass.h"
3940 #include
4041
4142 namespace llvm {
4243 class AsmPrinter;
43 class GCStrategy;
4444 class Constant;
4545 class MCSymbol;
46
47 namespace GC {
48 /// PointKind - The type of a collector-safe point.
49 ///
50 enum PointKind {
51 Loop, ///< Instr is a loop (backwards branch).
52 Return, ///< Instr is a return instruction.
53 PreCall, ///< Instr is a call instruction.
54 PostCall ///< Instr is the return address of a call.
55 };
56 }
5746
5847 /// GCPoint - Metadata for a collector-safe point in machine code.
5948 ///
162151 /// Records both the function level information used by GCRoots and a
163152 /// cache of the 'active' gc strategy objects for the current Module.
164153 class GCModuleInfo : public ImmutablePass {
165 typedef StringMap strategy_map_type;
166 typedef std::vector> list_type;
167
168 strategy_map_type StrategyMap;
169 list_type StrategyList;
170
171 GCStrategy *getOrCreateStrategy(const Module *M, const std::string &Name);
172
154 /// A list of GCStrategies which are active in this Module. These are
155 /// not owning pointers.
156 std::vector StrategyList;
173157 public:
174158 /// List of per function info objects. In theory, Each of these
175159 /// may be associated with a different GC.
189173 finfo_map_type FInfoMap;
190174 public:
191175
192 typedef list_type::const_iterator iterator;
176 typedef std::vector::const_iterator iterator;
193177
194178 static char ID;
195179
2020 #define LLVM_CODEGEN_GCMETADATAPRINTER_H
2121
2222 #include "llvm/CodeGen/GCMetadata.h"
23 #include "llvm/CodeGen/GCStrategy.h"
23 #include "llvm/IR/GCStrategy.h"
2424 #include "llvm/Support/Registry.h"
2525
2626 namespace llvm {
+0
-182
include/llvm/CodeGen/GCStrategy.h less more
None //===-- llvm/CodeGen/GCStrategy.h - Garbage collection ----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // GCStrategy coordinates code generation algorithms and implements some itself
10 // in order to generate code compatible with a target code generator as
11 // specified in a function's 'gc' attribute. Algorithms are enabled by setting
12 // flags in a subclass's constructor, and some virtual methods can be
13 // overridden.
14 //
15 // GCStrategy is relevant for implementations using either gc.root or
16 // gc.statepoint based lowering strategies, but is currently focused mostly on
17 // options for gc.root. This will change over time.
18 //
19 // When requested by a subclass of GCStrategy, the gc.root implementation will
20 // populate GCModuleInfo and GCFunctionInfo with that about each Function in
21 // the Module that opts in to garbage collection. Specifically:
22 //
23 // - Safe points
24 // Garbage collection is generally only possible at certain points in code.
25 // GCStrategy can request that the collector insert such points:
26 //
27 // - At and after any call to a subroutine
28 // - Before returning from the current function
29 // - Before backwards branches (loops)
30 //
31 // - Roots
32 // When a reference to a GC-allocated object exists on the stack, it must be
33 // stored in an alloca registered with llvm.gcoot.
34 //
35 // This information can used to emit the metadata tables which are required by
36 // the target garbage collector runtime.
37 //
38 // When used with gc.statepoint, information about safepoint and roots can be
39 // found in the binary StackMap section after code generation. Safepoint
40 // placement is currently the responsibility of the frontend, though late
41 // insertion support is planned. gc.statepoint does not currently support
42 // custom stack map formats; such can be generated by parsing the standard
43 // stack map section if desired.
44 //
45 // The read and write barrier support can be used with either implementation.
46 //
47 //===----------------------------------------------------------------------===//
48
49 #ifndef LLVM_CODEGEN_GCSTRATEGY_H
50 #define LLVM_CODEGEN_GCSTRATEGY_H
51
52 #include "llvm/ADT/Optional.h"
53 #include "llvm/CodeGen/GCMetadata.h"
54 #include "llvm/CodeGen/MachineFunction.h"
55 #include "llvm/Support/Registry.h"
56 #include
57
58 namespace llvm {
59 /// GCStrategy describes a garbage collector algorithm's code generation
60 /// requirements, and provides overridable hooks for those needs which cannot
61 /// be abstractly described. GCStrategy objects currently must be looked up
62 /// through the GCModuleInfo analysis pass. They are owned by the analysis
63 /// pass and recreated every time that pass is invalidated.
64 class GCStrategy {
65 private:
66 std::string Name;
67 friend class GCModuleInfo;
68
69 protected:
70 bool UseStatepoints; /// Uses gc.statepoints as opposed to gc.roots,
71 /// if set, none of the other options can be
72 /// anything but their default values.
73
74 unsigned NeededSafePoints; ///< Bitmask of required safe points.
75 bool CustomReadBarriers; ///< Default is to insert loads.
76 bool CustomWriteBarriers; ///< Default is to insert stores.
77 bool CustomRoots; ///< Default is to pass through to backend.
78 bool InitRoots; ///< If set, roots are nulled during lowering.
79 bool UsesMetadata; ///< If set, backend must emit metadata tables.
80
81 public:
82 GCStrategy();
83 virtual ~GCStrategy() {}
84
85 /// Return the name of the GC strategy. This is the value of the collector
86 /// name string specified on functions which use this strategy.
87 const std::string &getName() const { return Name; }
88
89 /// By default, write barriers are replaced with simple store
90 /// instructions. If true, then performCustomLowering must instead lower
91 /// them.
92 bool customWriteBarrier() const { return CustomWriteBarriers; }
93
94 /// By default, read barriers are replaced with simple load
95 /// instructions. If true, then performCustomLowering must instead lower
96 /// them.
97 bool customReadBarrier() const { return CustomReadBarriers; }
98
99 /// Returns true if this strategy is expecting the use of gc.statepoints,
100 /// and false otherwise.
101 bool useStatepoints() const { return UseStatepoints; }
102
103 /** @name Statepoint Specific Properties */
104 ///@{
105
106 /// If the value specified can be reliably distinguished, returns true for
107 /// pointers to GC managed locations and false for pointers to non-GC
108 /// managed locations. Note a GCStrategy can always return 'None' (i.e. an
109 /// empty optional indicating it can't reliably distinguish.
110 virtual Optional isGCManagedPointer(const Value *V) const {
111 return None;
112 }
113 ///@}
114
115 /** @name GCRoot Specific Properties
116 * These properties and overrides only apply to collector strategies using
117 * GCRoot.
118 */
119 ///@{
120
121 /// True if safe points of any kind are required. By default, none are
122 /// recorded.
123 bool needsSafePoints() const {
124 return NeededSafePoints != 0;
125 }
126
127 /// True if the given kind of safe point is required. By default, none are
128 /// recorded.
129 bool needsSafePoint(GC::PointKind Kind) const {
130 return (NeededSafePoints & 1 << Kind) != 0;
131 }
132
133 /// By default, roots are left for the code generator so it can generate a
134 /// stack map. If true, then performCustomLowering must delete them.
135 bool customRoots() const { return CustomRoots; }
136
137 /// If set, gcroot intrinsics should initialize their allocas to null
138 /// before the first use. This is necessary for most GCs and is enabled by
139 /// default.
140 bool initializeRoots() const { return InitRoots; }
141
142 /// If set, appropriate metadata tables must be emitted by the back-end
143 /// (assembler, JIT, or otherwise). For statepoint, this method is
144 /// currently unsupported. The stackmap information can be found in the
145 /// StackMap section as described in the documentation.
146 bool usesMetadata() const { return UsesMetadata; }
147
148 ///@}
149
150 /// initializeCustomLowering/performCustomLowering - If any of the actions
151 /// are set to custom, performCustomLowering must be overriden to transform
152 /// the corresponding actions to LLVM IR. initializeCustomLowering is
153 /// optional to override. These are the only GCStrategy methods through
154 /// which the LLVM IR can be modified. These methods apply mostly to
155 /// gc.root based implementations, but can be overriden to provide custom
156 /// barrier lowerings with gc.statepoint as well.
157 ///@{
158 virtual bool initializeCustomLowering(Module &F) {
159 // No changes made
160 return false;
161 }
162 virtual bool performCustomLowering(Function &F) {
163 llvm_unreachable("GCStrategy subclass specified a configuration which"
164 "requires a custom lowering without providing one");
165 }
166 };
167
168 /// Subclasses of GCStrategy are made available for use during compilation by
169 /// adding them to the global GCRegistry. This can done either within the
170 /// LLVM source tree or via a loadable plugin. An example registeration
171 /// would be:
172 /// static GCRegistry::Add X("custom-name",
173 /// "my custom supper fancy gc strategy");
174 ///
175 /// Note that to use a custom GCMetadataPrinter w/gc.roots, you must also
176 /// register your GCMetadataPrinter subclass with the
177 /// GCMetadataPrinterRegistery as well.
178 typedef Registry GCRegistry;
179 }
180
181 #endif
2828 namespace llvm {
2929
3030 class FunctionType;
31 class GCStrategy;
3132 class LLVMContext;
3233
3334 // Traits for intrusive list of basic blocks...
224225 void setGC(const char *Str);
225226 void clearGC();
226227
228 /// Returns the GCStrategy associated with the specified garbage collector
229 /// algorithm or nullptr if one is not set.
230 GCStrategy *getGCStrategy() const;
231
227232 /// @brief adds the attribute to the list of attributes.
228233 void addAttribute(unsigned i, Attribute::AttrKind attr);
229234
0 //===-- llvm/IR/GCStrategy.h - Garbage collection ----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // GCStrategy coordinates code generation algorithms and implements some itself
10 // in order to generate code compatible with a target code generator as
11 // specified in a function's 'gc' attribute. Algorithms are enabled by setting
12 // flags in a subclass's constructor, and some virtual methods can be
13 // overridden.
14 //
15 // GCStrategy is relevant for implementations using either gc.root or
16 // gc.statepoint based lowering strategies, but is currently focused mostly on
17 // options for gc.root. This will change over time.
18 //
19 // When requested by a subclass of GCStrategy, the gc.root implementation will
20 // populate GCModuleInfo and GCFunctionInfo with that about each Function in
21 // the Module that opts in to garbage collection. Specifically:
22 //
23 // - Safe points
24 // Garbage collection is generally only possible at certain points in code.
25 // GCStrategy can request that the collector insert such points:
26 //
27 // - At and after any call to a subroutine
28 // - Before returning from the current function
29 // - Before backwards branches (loops)
30 //
31 // - Roots
32 // When a reference to a GC-allocated object exists on the stack, it must be
33 // stored in an alloca registered with llvm.gcoot.
34 //
35 // This information can used to emit the metadata tables which are required by
36 // the target garbage collector runtime.
37 //
38 // When used with gc.statepoint, information about safepoint and roots can be
39 // found in the binary StackMap section after code generation. Safepoint
40 // placement is currently the responsibility of the frontend, though late
41 // insertion support is planned. gc.statepoint does not currently support
42 // custom stack map formats; such can be generated by parsing the standard
43 // stack map section if desired.
44 //
45 // The read and write barrier support can be used with either implementation.
46 //
47 //===----------------------------------------------------------------------===//
48
49 #ifndef LLVM_IR_GCSTRATEGY_H
50 #define LLVM_IR_GCSTRATEGY_H
51
52 #include "llvm/ADT/Optional.h"
53 #include "llvm/IR/Value.h"
54 #include "llvm/IR/Function.h"
55 #include "llvm/IR/Module.h"
56 #include "llvm/Support/ErrorHandling.h"
57 #include "llvm/Support/Registry.h"
58 #include
59
60 namespace llvm {
61 namespace GC {
62 /// PointKind - The type of a collector-safe point.
63 ///
64 enum PointKind {
65 Loop, ///< Instr is a loop (backwards branch).
66 Return, ///< Instr is a return instruction.
67 PreCall, ///< Instr is a call instruction.
68 PostCall ///< Instr is the return address of a call.
69 };
70 }
71
72
73 /// GCStrategy describes a garbage collector algorithm's code generation
74 /// requirements, and provides overridable hooks for those needs which cannot
75 /// be abstractly described. GCStrategy objects must be looked up through
76 /// the Function. The objects themselves are owned by the Context and must
77 /// be immutable.
78 class GCStrategy {
79 private:
80 std::string Name;
81 friend class LLVMContextImpl;
82
83 protected:
84 bool UseStatepoints; /// Uses gc.statepoints as opposed to gc.roots,
85 /// if set, none of the other options can be
86 /// anything but their default values.
87
88 unsigned NeededSafePoints; ///< Bitmask of required safe points.
89 bool CustomReadBarriers; ///< Default is to insert loads.
90 bool CustomWriteBarriers; ///< Default is to insert stores.
91 bool CustomRoots; ///< Default is to pass through to backend.
92 bool InitRoots; ///< If set, roots are nulled during lowering.
93 bool UsesMetadata; ///< If set, backend must emit metadata tables.
94
95 public:
96 GCStrategy();
97 virtual ~GCStrategy() {}
98
99 /// Return the name of the GC strategy. This is the value of the collector
100 /// name string specified on functions which use this strategy.
101 const std::string &getName() const { return Name; }
102
103 /// By default, write barriers are replaced with simple store
104 /// instructions. If true, then performCustomLowering must instead lower
105 /// them.
106 bool customWriteBarrier() const { return CustomWriteBarriers; }
107
108 /// By default, read barriers are replaced with simple load
109 /// instructions. If true, then performCustomLowering must instead lower
110 /// them.
111 bool customReadBarrier() const { return CustomReadBarriers; }
112
113 /// Returns true if this strategy is expecting the use of gc.statepoints,
114 /// and false otherwise.
115 bool useStatepoints() const { return UseStatepoints; }
116
117 /** @name Statepoint Specific Properties */
118 ///@{
119
120 /// If the value specified can be reliably distinguished, returns true for
121 /// pointers to GC managed locations and false for pointers to non-GC
122 /// managed locations. Note a GCStrategy can always return 'None' (i.e. an
123 /// empty optional indicating it can't reliably distinguish.
124 virtual Optional isGCManagedPointer(const Value *V) const {
125 return None;
126 }
127 ///@}
128
129 /** @name GCRoot Specific Properties
130 * These properties and overrides only apply to collector strategies using
131 * GCRoot.
132 */
133 ///@{
134
135 /// True if safe points of any kind are required. By default, none are
136 /// recorded.
137 bool needsSafePoints() const {
138 return NeededSafePoints != 0;
139 }
140
141 /// True if the given kind of safe point is required. By default, none are
142 /// recorded.
143 bool needsSafePoint(GC::PointKind Kind) const {
144 return (NeededSafePoints & 1 << Kind) != 0;
145 }
146
147 /// By default, roots are left for the code generator so it can generate a
148 /// stack map. If true, then performCustomLowering must delete them.
149 bool customRoots() const { return CustomRoots; }
150
151 /// If set, gcroot intrinsics should initialize their allocas to null
152 /// before the first use. This is necessary for most GCs and is enabled by
153 /// default.
154 bool initializeRoots() const { return InitRoots; }
155
156 /// If set, appropriate metadata tables must be emitted by the back-end
157 /// (assembler, JIT, or otherwise). For statepoint, this method is
158 /// currently unsupported. The stackmap information can be found in the
159 /// StackMap section as described in the documentation.
160 bool usesMetadata() const { return UsesMetadata; }
161
162 ///@}
163
164 /// initializeCustomLowering/performCustomLowering - If any of the actions
165 /// are set to custom, performCustomLowering must be overriden to transform
166 /// the corresponding actions to LLVM IR. initializeCustomLowering is
167 /// optional to override. These are the only GCStrategy methods through
168 /// which the LLVM IR can be modified. These methods apply mostly to
169 /// gc.root based implementations, but can be overriden to provide custom
170 /// barrier lowerings with gc.statepoint as well.
171 ///@{
172 virtual bool initializeCustomLowering(Module &F) {
173 // No changes made
174 return false;
175 }
176 virtual bool performCustomLowering(Function &F) {
177 llvm_unreachable("GCStrategy subclass specified a configuration which"
178 "requires a custom lowering without providing one");
179 }
180 };
181
182 /// Subclasses of GCStrategy are made available for use during compilation by
183 /// adding them to the global GCRegistry. This can done either within the
184 /// LLVM source tree or via a loadable plugin. An example registeration
185 /// would be:
186 /// static GCRegistry::Add X("custom-name",
187 /// "my custom supper fancy gc strategy");
188 ///
189 /// Note that to use a custom GCMetadataPrinter w/gc.roots, you must also
190 /// register your GCMetadataPrinter subclass with the
191 /// GCMetadataPrinterRegistery as well.
192 typedef Registry GCRegistry;
193 }
194
195 #endif
119119 static iterator begin() { return iterator(Head); }
120120 static iterator end() { return iterator(nullptr); }
121121
122 static iterator_range entries() {
123 return iterator_range(begin(), end());
124 }
125
122126
123127 /// Abstract base class for registry listeners, which are informed when new
124128 /// entries are added to the registry. Simply subclass and instantiate:
2222 GCMetadata.cpp
2323 GCMetadataPrinter.cpp
2424 GCRootLowering.cpp
25 GCStrategy.cpp
2625 GlobalMerge.cpp
2726 IfConversion.cpp
2827 InlineSpiller.cpp
1414 //===----------------------------------------------------------------------===//
1515
1616 #include "llvm/CodeGen/GCs.h"
17 #include "llvm/CodeGen/GCStrategy.h"
1817 #include "llvm/CodeGen/MachineInstrBuilder.h"
18 #include "llvm/IR/GCStrategy.h"
1919 #include "llvm/MC/MCContext.h"
2020 #include "llvm/MC/MCSymbol.h"
2121 #include "llvm/Target/TargetInstrInfo.h"
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/CodeGen/GCMetadata.h"
14 #include "llvm/CodeGen/GCStrategy.h"
1514 #include "llvm/CodeGen/MachineFrameInfo.h"
1615 #include "llvm/CodeGen/Passes.h"
1716 #include "llvm/IR/Function.h"
17 #include "llvm/IR/GCStrategy.h"
1818 #include "llvm/MC/MCSymbol.h"
1919 #include "llvm/Pass.h"
2020 #include "llvm/Support/Debug.h"
6060 initializeGCModuleInfoPass(*PassRegistry::getPassRegistry());
6161 }
6262
63 GCStrategy *GCModuleInfo::getOrCreateStrategy(const Module *M,
64 const std::string &Name) {
65 strategy_map_type::iterator NMI = StrategyMap.find(Name);
66 if (NMI != StrategyMap.end())
67 return NMI->getValue();
68
69 for (GCRegistry::iterator I = GCRegistry::begin(),
70 E = GCRegistry::end(); I != E; ++I) {
71 if (Name == I->getName()) {
72 std::unique_ptr S = I->instantiate();
73 S->Name = Name;
74 StrategyMap[Name] = S.get();
75 StrategyList.push_back(std::move(S));
76 return StrategyList.back().get();
77 }
78 }
79
80 dbgs() << "unsupported GC: " << Name << "\n";
81 llvm_unreachable(nullptr);
82 }
83
8463 GCFunctionInfo &GCModuleInfo::getFunctionInfo(const Function &F) {
8564 assert(!F.isDeclaration() && "Can only get GCFunctionInfo for a definition!");
8665 assert(F.hasGC());
8968 if (I != FInfoMap.end())
9069 return *I->second;
9170
92 GCStrategy *S = getOrCreateStrategy(F.getParent(), F.getGC());
71 GCStrategy *S = F.getGCStrategy();
72 if (!S) {
73 std::string error = std::string("unsupported GC: ") + F.getGC();
74 report_fatal_error(error);
75 }
76 // Save the fact this strategy is associated with this module. Note that
77 // these are non-owning references, the GCStrategy remains owned by the
78 // Context.
79 StrategyList.push_back(S);
9380 Functions.push_back(make_unique(F, *S));
9481 GCFunctionInfo *GFI = Functions.back().get();
9582 FInfoMap[&F] = GFI;
9986 void GCModuleInfo::clear() {
10087 Functions.clear();
10188 FInfoMap.clear();
102 StrategyMap.clear();
10389 StrategyList.clear();
10490 }
10591
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/CodeGen/GCStrategy.h"
13 #include "llvm/CodeGen/GCMetadata.h"
1414 #include "llvm/CodeGen/MachineFrameInfo.h"
1515 #include "llvm/CodeGen/MachineFunctionPass.h"
1616 #include "llvm/CodeGen/MachineInstrBuilder.h"
1717 #include "llvm/CodeGen/MachineModuleInfo.h"
1818 #include "llvm/CodeGen/Passes.h"
1919 #include "llvm/IR/Dominators.h"
20 #include "llvm/IR/GCStrategy.h"
2021 #include "llvm/IR/IntrinsicInst.h"
2122 #include "llvm/IR/Module.h"
2223 #include "llvm/Support/Debug.h"
+0
-22
lib/CodeGen/GCStrategy.cpp less more
None //===-- GCStrategy.cpp - Garbage Collector Description --------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the policy object GCStrategy which describes the
10 // behavior of a given garbage collector.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/GCStrategy.h"
15
16 using namespace llvm;
17
18 GCStrategy::GCStrategy()
19 : UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
20 CustomWriteBarriers(false), CustomRoots(false),
21 InitRoots(true), UsesMetadata(false) {}
1414 //===----------------------------------------------------------------------===//
1515
1616 #include "llvm/CodeGen/GCs.h"
17 #include "llvm/CodeGen/GCStrategy.h"
17 #include "llvm/IR/GCStrategy.h"
1818
1919 using namespace llvm;
2020
1313
1414 #include "llvm/CodeGen/Passes.h"
1515 #include "llvm/Analysis/Passes.h"
16 #include "llvm/CodeGen/GCStrategy.h"
1716 #include "llvm/CodeGen/MachineFunctionPass.h"
1817 #include "llvm/CodeGen/RegAllocRegistry.h"
1918 #include "llvm/IR/IRPrintingPasses.h"
2525 #include "llvm/CodeGen/FastISel.h"
2626 #include "llvm/CodeGen/FunctionLoweringInfo.h"
2727 #include "llvm/CodeGen/GCMetadata.h"
28 #include "llvm/CodeGen/GCStrategy.h"
2928 #include "llvm/CodeGen/MachineFrameInfo.h"
3029 #include "llvm/CodeGen/MachineFunction.h"
3130 #include "llvm/CodeGen/MachineInstrBuilder.h"
4039 #include "llvm/IR/DebugInfo.h"
4140 #include "llvm/IR/DerivedTypes.h"
4241 #include "llvm/IR/Function.h"
42 #include "llvm/IR/GCStrategy.h"
4343 #include "llvm/IR/GlobalVariable.h"
4444 #include "llvm/IR/InlineAsm.h"
4545 #include "llvm/IR/Instructions.h"
2323 #include "llvm/CodeGen/FastISel.h"
2424 #include "llvm/CodeGen/FunctionLoweringInfo.h"
2525 #include "llvm/CodeGen/GCMetadata.h"
26 #include "llvm/CodeGen/GCStrategy.h"
2726 #include "llvm/CodeGen/MachineFrameInfo.h"
2827 #include "llvm/CodeGen/MachineFunction.h"
2928 #include "llvm/CodeGen/MachineInstrBuilder.h"
3534 #include "llvm/IR/Constants.h"
3635 #include "llvm/IR/DebugInfo.h"
3736 #include "llvm/IR/Function.h"
37 #include "llvm/IR/GCStrategy.h"
3838 #include "llvm/IR/InlineAsm.h"
3939 #include "llvm/IR/Instructions.h"
4040 #include "llvm/IR/IntrinsicInst.h"
1515 #include "SelectionDAGBuilder.h"
1616 #include "llvm/ADT/SmallSet.h"
1717 #include "llvm/ADT/Statistic.h"
18 #include "llvm/CodeGen/GCMetadata.h"
1819 #include "llvm/CodeGen/FunctionLoweringInfo.h"
19 #include "llvm/CodeGen/GCStrategy.h"
2020 #include "llvm/CodeGen/SelectionDAG.h"
2121 #include "llvm/CodeGen/StackMaps.h"
2222 #include "llvm/IR/CallingConv.h"
23 #include "llvm/IR/GCStrategy.h"
2324 #include "llvm/IR/Instructions.h"
2425 #include "llvm/IR/IntrinsicInst.h"
2526 #include "llvm/IR/Intrinsics.h"
2626
2727 #include "llvm/CodeGen/GCs.h"
2828 #include "llvm/ADT/StringExtras.h"
29 #include "llvm/CodeGen/GCStrategy.h"
3029 #include "llvm/IR/CallSite.h"
30 #include "llvm/IR/GCStrategy.h"
3131 #include "llvm/IR/IRBuilder.h"
3232 #include "llvm/IR/IntrinsicInst.h"
3333 #include "llvm/IR/Module.h"
1515 //
1616 //===----------------------------------------------------------------------===//
1717
18 #include "llvm/CodeGen/GCStrategy.h"
18 #include "llvm/IR/GCStrategy.h"
1919 #include "llvm/IR/DerivedTypes.h"
2020 #include "llvm/IR/Value.h"
2121
1616 Dominators.cpp
1717 Function.cpp
1818 GCOV.cpp
19 GCStrategy.cpp
1920 GVMaterializer.cpp
2021 Globals.cpp
2122 IRBuilder.cpp
383383 }
384384 }
385385 }
386 }
387
388 GCStrategy *Function::getGCStrategy() const {
389 // Lookup the GCStrategy (which is owned by the Context), given the name of
390 // the GC in question.
391 return getContext().pImpl->getGCStrategy(getGC());
386392 }
387393
388394 /// copyAttributesFrom - copy all additional attributes (those not needed to
0 //===-- GCStrategy.cpp - Garbage Collector Description --------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the policy object GCStrategy which describes the
10 // behavior of a given garbage collector.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/IR/GCStrategy.h"
15
16 using namespace llvm;
17
18 GCStrategy::GCStrategy()
19 : UseStatepoints(false), NeededSafePoints(0), CustomReadBarriers(false),
20 CustomWriteBarriers(false), CustomRoots(false),
21 InitRoots(true), UsesMetadata(false) {}
1414 #include "llvm/ADT/STLExtras.h"
1515 #include "llvm/IR/Attributes.h"
1616 #include "llvm/IR/DiagnosticInfo.h"
17 #include "llvm/IR/GCStrategy.h"
1718 #include "llvm/IR/Module.h"
1819 #include
1920 using namespace llvm;
181182 void GetElementPtrConstantExpr::anchor() { }
182183
183184 void CompareConstantExpr::anchor() { }
185
186 GCStrategy *LLVMContextImpl::getGCStrategy(const StringRef Name) {
187 // TODO: Arguably, just doing a linear search would be faster for small N
188 auto NMI = GCStrategyMap.find(Name);
189 if (NMI != GCStrategyMap.end())
190 return NMI->getValue();
191
192 for (auto& Entry : GCRegistry::entries()) {
193 if (Name == Entry.getName()) {
194 std::unique_ptr S = Entry.instantiate();
195 S->Name = Name;
196 GCStrategyMap[Name] = S.get();
197 GCStrategyList.push_back(std::move(S));
198 return GCStrategyList.back().get();
199 }
200 }
201
202 // No GCStrategy found for that name, error reporting is the job of our
203 // callers.
204 return nullptr;
205 }
206
207
4040 class DiagnosticInfoOptimizationRemark;
4141 class DiagnosticInfoOptimizationRemarkMissed;
4242 class DiagnosticInfoOptimizationRemarkAnalysis;
43 class GCStrategy;
4344 class LLVMContext;
4445 class Type;
4546 class Value;
388389
389390 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
390391 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
392
393 /// An owning list of all GCStrategies which have been created
394 SmallVector, 1> GCStrategyList;
395 /// A helper map to speedup lookups into the above list
396 StringMap GCStrategyMap;
397
398 /// Lookup the GCStrategy object associated with the given gc name. If one
399 /// can't be found, returns nullptr. The lifetime of the returned objects
400 /// is dictated by the lifetime of the associated context. No caller should
401 /// attempt to delete the returned objects.
402 GCStrategy *getGCStrategy(const StringRef Name);
391403
392404 LLVMContextImpl(LLVMContext &C);
393405 ~LLVMContextImpl();