blob: 824cac84d58be6cbb19fec90e6bbf84b366b6e50 [file] [log] [blame]
Gordon Henriksen5eca0752008-08-17 18:44:35 +00001//===-- GCStrategy.cpp - Garbage collection infrastructure -----------------===//
Gordon Henriksen364caf02007-09-29 02:13:43 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Gordon Henriksen364caf02007-09-29 02:13:43 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements target- and collector-independent garbage collection
11// infrastructure.
12//
Gordon Henriksen5eca0752008-08-17 18:44:35 +000013// MachineCodeAnalysis identifies the GC safe points in the machine code. Roots
14// are identified in SelectionDAGISel.
15//
Gordon Henriksen364caf02007-09-29 02:13:43 +000016//===----------------------------------------------------------------------===//
17
Gordon Henriksen5a29c9e2008-08-17 12:56:54 +000018#include "llvm/CodeGen/GCStrategy.h"
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000019#include "llvm/CodeGen/Passes.h"
Gordon Henriksen364caf02007-09-29 02:13:43 +000020#include "llvm/IntrinsicInst.h"
21#include "llvm/Module.h"
Gordon Henriksen364caf02007-09-29 02:13:43 +000022#include "llvm/CodeGen/MachineFrameInfo.h"
23#include "llvm/CodeGen/MachineFunctionPass.h"
24#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner84bc5422007-12-31 04:13:23 +000025#include "llvm/CodeGen/MachineModuleInfo.h"
Gordon Henriksen364caf02007-09-29 02:13:43 +000026#include "llvm/Target/TargetFrameInfo.h"
27#include "llvm/Target/TargetInstrInfo.h"
28#include "llvm/Target/TargetMachine.h"
Gordon Henriksenfcbcfaa2008-08-19 17:06:35 +000029#include "llvm/Target/TargetRegisterInfo.h"
David Greenecc54c7c2010-01-04 21:48:34 +000030#include "llvm/Support/Debug.h"
Torok Edwin7d696d82009-07-11 13:10:19 +000031#include "llvm/Support/ErrorHandling.h"
Chris Lattner45cfe542009-08-23 06:03:38 +000032#include "llvm/Support/raw_ostream.h"
Gordon Henriksen364caf02007-09-29 02:13:43 +000033
34using namespace llvm;
35
36namespace {
37
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000038 /// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
39 /// llvm.gcwrite intrinsics, replacing them with simple loads and stores as
Gordon Henriksen5eca0752008-08-17 18:44:35 +000040 /// directed by the GCStrategy. It also performs automatic root initialization
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000041 /// and custom intrinsic lowering.
Nick Lewycky6726b6d2009-10-25 06:33:48 +000042 class LowerIntrinsics : public FunctionPass {
Gordon Henriksen5eca0752008-08-17 18:44:35 +000043 static bool NeedsDefaultLoweringPass(const GCStrategy &C);
44 static bool NeedsCustomLoweringPass(const GCStrategy &C);
Gordon Henriksen364caf02007-09-29 02:13:43 +000045 static bool CouldBecomeSafePoint(Instruction *I);
Gordon Henriksen5eca0752008-08-17 18:44:35 +000046 bool PerformDefaultLowering(Function &F, GCStrategy &Coll);
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000047 static bool InsertRootInitializers(Function &F,
Gordon Henriksen364caf02007-09-29 02:13:43 +000048 AllocaInst **Roots, unsigned Count);
49
50 public:
51 static char ID;
52
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000053 LowerIntrinsics();
Gordon Henriksen364caf02007-09-29 02:13:43 +000054 const char *getPassName() const;
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000055 void getAnalysisUsage(AnalysisUsage &AU) const;
Gordon Henriksen364caf02007-09-29 02:13:43 +000056
57 bool doInitialization(Module &M);
58 bool runOnFunction(Function &F);
59 };
60
61
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000062 /// MachineCodeAnalysis - This is a target-independent pass over the machine
63 /// function representation to identify safe points for the garbage collector
64 /// in the machine code. It inserts labels at safe points and populates a
Gordon Henriksen5eca0752008-08-17 18:44:35 +000065 /// GCMetadata record for each function.
Nick Lewycky6726b6d2009-10-25 06:33:48 +000066 class MachineCodeAnalysis : public MachineFunctionPass {
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000067 const TargetMachine *TM;
Gordon Henriksen5eca0752008-08-17 18:44:35 +000068 GCFunctionInfo *FI;
Gordon Henriksen364caf02007-09-29 02:13:43 +000069 MachineModuleInfo *MMI;
70 const TargetInstrInfo *TII;
Gordon Henriksen364caf02007-09-29 02:13:43 +000071
72 void FindSafePoints(MachineFunction &MF);
73 void VisitCallPoint(MachineBasicBlock::iterator MI);
Chris Lattneraba9bcb2010-03-14 07:27:07 +000074 MCSymbol *InsertLabel(MachineBasicBlock &MBB,
75 MachineBasicBlock::iterator MI,
76 DebugLoc DL) const;
Gordon Henriksen364caf02007-09-29 02:13:43 +000077
78 void FindStackOffsets(MachineFunction &MF);
79
80 public:
81 static char ID;
82
Gordon Henriksenad93c4f2007-12-11 00:30:17 +000083 MachineCodeAnalysis();
Gordon Henriksen364caf02007-09-29 02:13:43 +000084 const char *getPassName() const;
85 void getAnalysisUsage(AnalysisUsage &AU) const;
86
87 bool runOnMachineFunction(MachineFunction &MF);
88 };
89
90}
91
92// -----------------------------------------------------------------------------
93
Gordon Henriksen5eca0752008-08-17 18:44:35 +000094GCStrategy::GCStrategy() :
Gordon Henriksen364caf02007-09-29 02:13:43 +000095 NeededSafePoints(0),
96 CustomReadBarriers(false),
97 CustomWriteBarriers(false),
98 CustomRoots(false),
Gordon Henriksenc317a602008-08-17 12:08:44 +000099 InitRoots(true),
100 UsesMetadata(false)
Gordon Henriksen364caf02007-09-29 02:13:43 +0000101{}
102
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000103GCStrategy::~GCStrategy() {
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000104 for (iterator I = begin(), E = end(); I != E; ++I)
105 delete *I;
106
107 Functions.clear();
Gordon Henriksen364caf02007-09-29 02:13:43 +0000108}
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000109
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000110bool GCStrategy::initializeCustomLowering(Module &M) { return false; }
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000111
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000112bool GCStrategy::performCustomLowering(Function &F) {
David Greenecc54c7c2010-01-04 21:48:34 +0000113 dbgs() << "gc " << getName() << " must override performCustomLowering.\n";
Torok Edwinc23197a2009-07-14 16:55:14 +0000114 llvm_unreachable(0);
Gordon Henriksen364caf02007-09-29 02:13:43 +0000115 return 0;
116}
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000117
118GCFunctionInfo *GCStrategy::insertFunctionInfo(const Function &F) {
119 GCFunctionInfo *FI = new GCFunctionInfo(F, *this);
120 Functions.push_back(FI);
121 return FI;
122}
Gordon Henriksen364caf02007-09-29 02:13:43 +0000123
124// -----------------------------------------------------------------------------
125
Owen Anderson081c34b2010-10-19 17:21:58 +0000126INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering",
127 false, false)
128INITIALIZE_PASS_DEPENDENCY(GCModuleInfo)
129INITIALIZE_PASS_END(LowerIntrinsics, "gc-lowering", "GC Lowering", false, false)
130
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000131FunctionPass *llvm::createGCLoweringPass() {
132 return new LowerIntrinsics();
133}
134
Gordon Henriksen364caf02007-09-29 02:13:43 +0000135char LowerIntrinsics::ID = 0;
136
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000137LowerIntrinsics::LowerIntrinsics()
Owen Anderson081c34b2010-10-19 17:21:58 +0000138 : FunctionPass(ID) {
139 initializeLowerIntrinsicsPass(*PassRegistry::getPassRegistry());
140 }
Gordon Henriksen364caf02007-09-29 02:13:43 +0000141
142const char *LowerIntrinsics::getPassName() const {
143 return "Lower Garbage Collection Instructions";
144}
145
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000146void LowerIntrinsics::getAnalysisUsage(AnalysisUsage &AU) const {
147 FunctionPass::getAnalysisUsage(AU);
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000148 AU.addRequired<GCModuleInfo>();
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000149}
150
151/// doInitialization - If this module uses the GC intrinsics, find them now.
Gordon Henriksen364caf02007-09-29 02:13:43 +0000152bool LowerIntrinsics::doInitialization(Module &M) {
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000153 // FIXME: This is rather antisocial in the context of a JIT since it performs
154 // work against the entire module. But this cannot be done at
155 // runFunction time (initializeCustomLowering likely needs to change
156 // the module).
Duncan Sands1465d612009-01-28 13:14:17 +0000157 GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000158 assert(MI && "LowerIntrinsics didn't require GCModuleInfo!?");
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000159 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000160 if (!I->isDeclaration() && I->hasGC())
161 MI->getFunctionInfo(*I); // Instantiate the GC strategy.
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000162
163 bool MadeChange = false;
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000164 for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000165 if (NeedsCustomLoweringPass(**I))
166 if ((*I)->initializeCustomLowering(M))
167 MadeChange = true;
168
169 return MadeChange;
Gordon Henriksen364caf02007-09-29 02:13:43 +0000170}
171
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000172bool LowerIntrinsics::InsertRootInitializers(Function &F, AllocaInst **Roots,
Gordon Henriksen364caf02007-09-29 02:13:43 +0000173 unsigned Count) {
174 // Scroll past alloca instructions.
175 BasicBlock::iterator IP = F.getEntryBlock().begin();
176 while (isa<AllocaInst>(IP)) ++IP;
177
178 // Search for initializers in the initial BB.
179 SmallPtrSet<AllocaInst*,16> InitedRoots;
180 for (; !CouldBecomeSafePoint(IP); ++IP)
181 if (StoreInst *SI = dyn_cast<StoreInst>(IP))
Anton Korobeynikovb04addd2008-05-06 22:52:30 +0000182 if (AllocaInst *AI =
Anton Korobeynikov0b12ecf2008-05-07 22:54:15 +0000183 dyn_cast<AllocaInst>(SI->getOperand(1)->stripPointerCasts()))
Gordon Henriksen364caf02007-09-29 02:13:43 +0000184 InitedRoots.insert(AI);
185
186 // Add root initializers.
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000187 bool MadeChange = false;
188
Gordon Henriksen364caf02007-09-29 02:13:43 +0000189 for (AllocaInst **I = Roots, **E = Roots + Count; I != E; ++I)
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000190 if (!InitedRoots.count(*I)) {
Nicolas Geoffray8538f042010-04-15 19:53:35 +0000191 StoreInst* SI = new StoreInst(ConstantPointerNull::get(cast<PointerType>(
192 cast<PointerType>((*I)->getType())->getElementType())),
193 *I);
194 SI->insertAfter(*I);
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000195 MadeChange = true;
196 }
197
198 return MadeChange;
199}
200
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000201bool LowerIntrinsics::NeedsDefaultLoweringPass(const GCStrategy &C) {
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000202 // Default lowering is necessary only if read or write barriers have a default
203 // action. The default for roots is no action.
204 return !C.customWriteBarrier()
205 || !C.customReadBarrier()
206 || C.initializeRoots();
207}
208
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000209bool LowerIntrinsics::NeedsCustomLoweringPass(const GCStrategy &C) {
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000210 // Custom lowering is only necessary if enabled for some action.
211 return C.customWriteBarrier()
212 || C.customReadBarrier()
213 || C.customRoots();
Gordon Henriksen364caf02007-09-29 02:13:43 +0000214}
215
216/// CouldBecomeSafePoint - Predicate to conservatively determine whether the
217/// instruction could introduce a safe point.
218bool LowerIntrinsics::CouldBecomeSafePoint(Instruction *I) {
219 // The natural definition of instructions which could introduce safe points
220 // are:
221 //
222 // - call, invoke (AfterCall, BeforeCall)
223 // - phis (Loops)
224 // - invoke, ret, unwind (Exit)
225 //
226 // However, instructions as seemingly inoccuous as arithmetic can become
227 // libcalls upon lowering (e.g., div i64 on a 32-bit platform), so instead
228 // it is necessary to take a conservative approach.
229
230 if (isa<AllocaInst>(I) || isa<GetElementPtrInst>(I) ||
231 isa<StoreInst>(I) || isa<LoadInst>(I))
232 return false;
233
234 // llvm.gcroot is safe because it doesn't do anything at runtime.
235 if (CallInst *CI = dyn_cast<CallInst>(I))
236 if (Function *F = CI->getCalledFunction())
237 if (unsigned IID = F->getIntrinsicID())
238 if (IID == Intrinsic::gcroot)
239 return false;
240
241 return true;
242}
243
244/// runOnFunction - Replace gcread/gcwrite intrinsics with loads and stores.
245/// Leave gcroot intrinsics; the code generator needs to see those.
246bool LowerIntrinsics::runOnFunction(Function &F) {
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000247 // Quick exit for functions that do not use GC.
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000248 if (!F.hasGC())
249 return false;
Gordon Henriksen364caf02007-09-29 02:13:43 +0000250
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000251 GCFunctionInfo &FI = getAnalysis<GCModuleInfo>().getFunctionInfo(F);
252 GCStrategy &S = FI.getStrategy();
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000253
254 bool MadeChange = false;
255
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000256 if (NeedsDefaultLoweringPass(S))
257 MadeChange |= PerformDefaultLowering(F, S);
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000258
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000259 if (NeedsCustomLoweringPass(S))
260 MadeChange |= S.performCustomLowering(F);
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000261
262 return MadeChange;
263}
264
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000265bool LowerIntrinsics::PerformDefaultLowering(Function &F, GCStrategy &S) {
266 bool LowerWr = !S.customWriteBarrier();
267 bool LowerRd = !S.customReadBarrier();
268 bool InitRoots = S.initializeRoots();
Gordon Henriksen364caf02007-09-29 02:13:43 +0000269
Gabor Greifa3997812010-07-22 10:37:47 +0000270 SmallVector<AllocaInst*, 32> Roots;
Gordon Henriksen364caf02007-09-29 02:13:43 +0000271
272 bool MadeChange = false;
273 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
274 for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E;) {
Gordon Henriksena6c99252007-12-22 17:27:01 +0000275 if (IntrinsicInst *CI = dyn_cast<IntrinsicInst>(II++)) {
Gordon Henriksen364caf02007-09-29 02:13:43 +0000276 Function *F = CI->getCalledFunction();
Gordon Henriksena6c99252007-12-22 17:27:01 +0000277 switch (F->getIntrinsicID()) {
278 case Intrinsic::gcwrite:
279 if (LowerWr) {
280 // Replace a write barrier with a simple store.
Gabor Greifa3997812010-07-22 10:37:47 +0000281 Value *St = new StoreInst(CI->getArgOperand(0),
282 CI->getArgOperand(2), CI);
Gordon Henriksena6c99252007-12-22 17:27:01 +0000283 CI->replaceAllUsesWith(St);
284 CI->eraseFromParent();
285 }
286 break;
287 case Intrinsic::gcread:
288 if (LowerRd) {
289 // Replace a read barrier with a simple load.
Gabor Greif89c4cea2010-06-25 08:48:19 +0000290 Value *Ld = new LoadInst(CI->getArgOperand(1), "", CI);
Gordon Henriksena6c99252007-12-22 17:27:01 +0000291 Ld->takeName(CI);
292 CI->replaceAllUsesWith(Ld);
293 CI->eraseFromParent();
294 }
295 break;
296 case Intrinsic::gcroot:
297 if (InitRoots) {
298 // Initialize the GC root, but do not delete the intrinsic. The
299 // backend needs the intrinsic to flag the stack slot.
300 Roots.push_back(cast<AllocaInst>(
Gabor Greif89c4cea2010-06-25 08:48:19 +0000301 CI->getArgOperand(0)->stripPointerCasts()));
Gordon Henriksena6c99252007-12-22 17:27:01 +0000302 }
303 break;
304 default:
Gordon Henriksen364caf02007-09-29 02:13:43 +0000305 continue;
306 }
307
308 MadeChange = true;
309 }
310 }
311 }
312
313 if (Roots.size())
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000314 MadeChange |= InsertRootInitializers(F, Roots.begin(), Roots.size());
Gordon Henriksen364caf02007-09-29 02:13:43 +0000315
316 return MadeChange;
317}
318
319// -----------------------------------------------------------------------------
320
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000321FunctionPass *llvm::createGCMachineCodeAnalysisPass() {
322 return new MachineCodeAnalysis();
323}
324
Gordon Henriksen364caf02007-09-29 02:13:43 +0000325char MachineCodeAnalysis::ID = 0;
326
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000327MachineCodeAnalysis::MachineCodeAnalysis()
Owen Anderson90c579d2010-08-06 18:33:48 +0000328 : MachineFunctionPass(ID) {}
Gordon Henriksen364caf02007-09-29 02:13:43 +0000329
330const char *MachineCodeAnalysis::getPassName() const {
331 return "Analyze Machine Code For Garbage Collection";
332}
333
334void MachineCodeAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
335 MachineFunctionPass::getAnalysisUsage(AU);
336 AU.setPreservesAll();
337 AU.addRequired<MachineModuleInfo>();
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000338 AU.addRequired<GCModuleInfo>();
Gordon Henriksen364caf02007-09-29 02:13:43 +0000339}
340
Chris Lattneraba9bcb2010-03-14 07:27:07 +0000341MCSymbol *MachineCodeAnalysis::InsertLabel(MachineBasicBlock &MBB,
342 MachineBasicBlock::iterator MI,
343 DebugLoc DL) const {
Chris Lattner77e76942010-03-17 05:41:18 +0000344 MCSymbol *Label = MBB.getParent()->getContext().CreateTempSymbol();
Chris Lattneraba9bcb2010-03-14 07:27:07 +0000345 BuildMI(MBB, MI, DL, TII->get(TargetOpcode::GC_LABEL)).addSym(Label);
Gordon Henriksen364caf02007-09-29 02:13:43 +0000346 return Label;
347}
348
349void MachineCodeAnalysis::VisitCallPoint(MachineBasicBlock::iterator CI) {
350 // Find the return address (next instruction), too, so as to bracket the call
351 // instruction.
352 MachineBasicBlock::iterator RAI = CI;
353 ++RAI;
354
Nicolas Geoffray946e3c92010-09-24 17:27:50 +0000355 if (FI->getStrategy().needsSafePoint(GC::PreCall)) {
356 MCSymbol* Label = InsertLabel(*CI->getParent(), CI, CI->getDebugLoc());
357 FI->addSafePoint(GC::PreCall, Label, CI->getDebugLoc());
358 }
Gordon Henriksen364caf02007-09-29 02:13:43 +0000359
Nicolas Geoffray946e3c92010-09-24 17:27:50 +0000360 if (FI->getStrategy().needsSafePoint(GC::PostCall)) {
361 MCSymbol* Label = InsertLabel(*CI->getParent(), RAI, CI->getDebugLoc());
362 FI->addSafePoint(GC::PostCall, Label, CI->getDebugLoc());
363 }
Gordon Henriksen364caf02007-09-29 02:13:43 +0000364}
365
366void MachineCodeAnalysis::FindSafePoints(MachineFunction &MF) {
367 for (MachineFunction::iterator BBI = MF.begin(),
368 BBE = MF.end(); BBI != BBE; ++BBI)
369 for (MachineBasicBlock::iterator MI = BBI->begin(),
370 ME = BBI->end(); MI != ME; ++MI)
Chris Lattner749c6f62008-01-07 07:27:27 +0000371 if (MI->getDesc().isCall())
Dan Gohmanfd3ff032008-07-07 20:08:05 +0000372 VisitCallPoint(MI);
Gordon Henriksen364caf02007-09-29 02:13:43 +0000373}
374
375void MachineCodeAnalysis::FindStackOffsets(MachineFunction &MF) {
Anton Korobeynikov82f58742010-11-20 15:59:32 +0000376 const TargetFrameInfo *TFI = TM->getFrameInfo();
377 assert(TFI && "TargetRegisterInfo not available!");
Gordon Henriksen364caf02007-09-29 02:13:43 +0000378
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000379 for (GCFunctionInfo::roots_iterator RI = FI->roots_begin(),
380 RE = FI->roots_end(); RI != RE; ++RI)
Anton Korobeynikov82f58742010-11-20 15:59:32 +0000381 RI->StackOffset = TFI->getFrameIndexOffset(MF, RI->Num);
Gordon Henriksen364caf02007-09-29 02:13:43 +0000382}
383
384bool MachineCodeAnalysis::runOnMachineFunction(MachineFunction &MF) {
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000385 // Quick exit for functions that do not use GC.
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000386 if (!MF.getFunction()->hasGC())
387 return false;
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000388
Gordon Henriksen5eca0752008-08-17 18:44:35 +0000389 FI = &getAnalysis<GCModuleInfo>().getFunctionInfo(*MF.getFunction());
390 if (!FI->getStrategy().needsSafePoints())
Gordon Henriksen364caf02007-09-29 02:13:43 +0000391 return false;
392
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000393 TM = &MF.getTarget();
Gordon Henriksen364caf02007-09-29 02:13:43 +0000394 MMI = &getAnalysis<MachineModuleInfo>();
Gordon Henriksenad93c4f2007-12-11 00:30:17 +0000395 TII = TM->getInstrInfo();
Gordon Henriksen364caf02007-09-29 02:13:43 +0000396
397 // Find the size of the stack frame.
Gordon Henriksenfcbcfaa2008-08-19 17:06:35 +0000398 FI->setFrameSize(MF.getFrameInfo()->getStackSize());
Gordon Henriksen364caf02007-09-29 02:13:43 +0000399
400 // Find all safe points.
401 FindSafePoints(MF);
402
403 // Find the stack offsets for all roots.
404 FindStackOffsets(MF);
405
406 return false;
407}