LLVM: lib/CodeGen/GCRootLowering.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
27
28using namespace llvm;
29
30
31
32
33
34
35
36
38
39namespace {
40
41
42
43
44
46public:
47 static char ID;
48
49 LowerIntrinsics();
50 StringRef getPassName() const override;
51 void getAnalysisUsage(AnalysisUsage &AU) const override;
52
53 bool doInitialization(Module &M) override;
55};
56
57
58
59
60
62 GCFunctionInfo *FI = nullptr;
63 const TargetInstrInfo *TII = nullptr;
64
65 void FindSafePoints(MachineFunction &MF);
69
70 void FindStackOffsets(MachineFunction &MF);
71
72public:
73 static char ID;
74
75 GCMachineCodeAnalysis();
76 void getAnalysisUsage(AnalysisUsage &AU) const override;
77
78 bool runOnMachineFunction(MachineFunction &MF) override;
79};
80}
81
84 if (.hasGC())
86
88
90
95 return PA;
96}
97
98
99
106
107char LowerIntrinsics::ID = 0;
109
110LowerIntrinsics::LowerIntrinsics() : FunctionPass(ID) {
112}
113
114StringRef LowerIntrinsics::getPassName() const {
115 return "Lower Garbage Collection Instructions";
116}
117
118void LowerIntrinsics::getAnalysisUsage(AnalysisUsage &AU) const {
119 FunctionPass::getAnalysisUsage(AU);
122}
123
124
125bool LowerIntrinsics::doInitialization(Module &M) {
126 GCModuleInfo *MI = getAnalysisIfAvailable();
127 assert(MI && "LowerIntrinsics didn't require GCModuleInfo!?");
128 for (Function &F : M)
129 if (.isDeclaration() && F.hasGC())
131
132 return false;
133}
134
135
136
138
139
140
141
142
143
144
145
146
147
148
151 return false;
152
153
155 if (Function *F = CI->getCalledFunction())
157 if (IID == Intrinsic::gcroot)
158 return false;
159
160 return true;
161}
162
164
167 ++IP;
168
169
175 InitedRoots.insert(AI);
176
177
178 bool MadeChange = false;
179
181 if (!InitedRoots.count(Root)) {
184 Root, std::next(Root->getIterator()));
185 MadeChange = true;
186 }
187
188 return MadeChange;
189}
190
191
192
193bool LowerIntrinsics::runOnFunction(Function &F) {
194
195 if (.hasGC())
196 return false;
197
198 GCFunctionInfo &FI = getAnalysis().getFunctionInfo(F);
200
202}
203
206
207 bool MadeChange = false;
211 if (!CI)
212 continue;
213
215 switch (F->getIntrinsicID()) {
216 default: break;
217 case Intrinsic::gcwrite: {
218
223 MadeChange = true;
224 break;
225 }
226 case Intrinsic::gcread: {
227
233 MadeChange = true;
234 break;
235 }
236 case Intrinsic::gcroot: {
237
238
241 break;
242 }
243 }
244 }
245
246 if (Roots.size())
248
249 return MadeChange;
250}
251
252
253
254char GCMachineCodeAnalysis::ID = 0;
256
258 "Analyze Machine Code For Garbage Collection", false, false)
259
261
262void GCMachineCodeAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
266}
267
268MCSymbol *GCMachineCodeAnalysis::InsertLabel(MachineBasicBlock &MBB,
274}
275
277
278
280 ++RAI;
281
282 MCSymbol *Label = InsertLabel(*CI->getParent(), RAI, CI->getDebugLoc());
284}
285
286void GCMachineCodeAnalysis::FindSafePoints(MachineFunction &MF) {
287 for (MachineBasicBlock &MBB : MF)
288 for (MachineInstr &MI : MBB)
289 if (MI.isCall()) {
290
291
292
293
294 if (MI.isTerminator())
295 continue;
296 VisitCallPoint(&MI);
297 }
298}
299
300void GCMachineCodeAnalysis::FindStackOffsets(MachineFunction &MF) {
302 assert(TFI && "TargetRegisterInfo not available!");
303
306
309 } else {
310 Register FrameReg;
311
313 assert(!FrameOffset.getScalable() &&
314 "Frame offsets with a scalable component are not supported");
315 RI->StackOffset = FrameOffset.getFixed();
316 ++RI;
317 }
318 }
319}
320
321bool GCMachineCodeAnalysis::runOnMachineFunction(MachineFunction &MF) {
322
324 return false;
325
326 FI = &getAnalysis().getFunctionInfo(MF.getFunction());
328
329
330
331 const MachineFrameInfo &MFI = MF.getFrameInfo();
333 const bool DynamicFrameSize =
336
337
339 FindSafePoints(MF);
340
341
342 FindStackOffsets(MF);
343
344 return false;
345}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const TargetInstrInfo & TII
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static bool runOnFunction(Function &F, bool PostInlining)
static bool InsertRootInitializers(Function &F, ArrayRef< AllocaInst * > Roots)
Definition GCRootLowering.cpp:163
static bool CouldBecomeSafePoint(Instruction *I)
CouldBecomeSafePoint - Predicate to conservatively determine whether the instruction could introduce ...
Definition GCRootLowering.cpp:137
static bool DoLowering(Function &F, GCStrategy &S)
Lower barriers out of existence (if the associated GCStrategy hasn't already done so....
Definition GCRootLowering.cpp:204
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
Promote Memory to Register
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
an instruction to allocate memory on the stack
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
InstListType::iterator iterator
Instruction iterators...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Value * getArgOperand(unsigned i) const
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Analysis pass which computes a DominatorTree.
FunctionPass class - This class is used to implement most global optimizations.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
An analysis pass which caches information about the Function.
void setFrameSize(uint64_t S)
void addSafePoint(MCSymbol *Label, const DebugLoc &DL)
addSafePoint - Notes the existence of a safe point.
std::vector< GCRoot >::iterator roots_iterator
roots_iterator removeStackRoot(roots_iterator position)
removeStackRoot - Removes a root.
GCStrategy & getStrategy()
getStrategy - Return the GC strategy for the function.
roots_iterator roots_end()
roots_iterator roots_begin()
roots_begin/roots_end - Iterators for all roots in the function.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
Definition GCRootLowering.cpp:82
An analysis pass which caches information about the entire Module.
GCStrategy describes a garbage collector algorithm's code generation requirements,...
bool needsSafePoints() const
True if safe points need to be inferred on call sites.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
A wrapper class for inspecting calls to intrinsic functions.
An instruction for reading from memory.
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
bool isDeadObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a dead object.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineInstrBuilder & addSym(MCSymbol *Sym, unsigned char TargetFlags=0) const
static LLVM_ABI 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.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
virtual StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
self_iterator getIterator()
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI char & GCMachineCodeAnalysisID
GCMachineCodeAnalysis - Target-independent pass to mark safe points in machine code.
Definition GCRootLowering.cpp:255
LLVM_ABI void initializeLowerIntrinsicsPass(PassRegistry &)
LLVM_ABI char & GCLoweringID
GCLowering Pass - Used by gc.root to perform its default lowering operations.
Definition GCRootLowering.cpp:108
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
LLVM_ABI FunctionPass * createGCLoweringPass()
GCLowering Pass - Used by gc.root to perform its default lowering operations.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.