10b57cec5SDimitry Andric //===-- GCRootLowering.cpp - Garbage collection infrastructure ------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements the lowering for the gc.root mechanism.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric #include "llvm/CodeGen/GCMetadata.h"
140b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h"
150b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunctionPass.h"
160b57cec5SDimitry Andric #include "llvm/CodeGen/MachineInstrBuilder.h"
170b57cec5SDimitry Andric #include "llvm/CodeGen/Passes.h"
180b57cec5SDimitry Andric #include "llvm/CodeGen/TargetFrameLowering.h"
190b57cec5SDimitry Andric #include "llvm/CodeGen/TargetInstrInfo.h"
200b57cec5SDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h"
210b57cec5SDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h"
220b57cec5SDimitry Andric #include "llvm/IR/Dominators.h"
230b57cec5SDimitry Andric #include "llvm/IR/IntrinsicInst.h"
240b57cec5SDimitry Andric #include "llvm/IR/Module.h"
25480093f4SDimitry Andric #include "llvm/InitializePasses.h"
2681ad6265SDimitry Andric #include "llvm/MC/MCContext.h"
270b57cec5SDimitry Andric
280b57cec5SDimitry Andric using namespace llvm;
290b57cec5SDimitry Andric
301db9f3b2SDimitry Andric /// Lower barriers out of existence (if the associated GCStrategy hasn't
311db9f3b2SDimitry Andric /// already done so...), and insert initializing stores to roots as a defensive
321db9f3b2SDimitry Andric /// measure. Given we're going to report all roots live at all safepoints, we
331db9f3b2SDimitry Andric /// need to be able to ensure each root has been initialized by the point the
341db9f3b2SDimitry Andric /// first safepoint is reached. This really should have been done by the
351db9f3b2SDimitry Andric /// frontend, but the old API made this non-obvious, so we do a potentially
361db9f3b2SDimitry Andric /// redundant store just in case.
371db9f3b2SDimitry Andric static bool DoLowering(Function &F, GCStrategy &S);
381db9f3b2SDimitry Andric
390b57cec5SDimitry Andric namespace {
400b57cec5SDimitry Andric
410b57cec5SDimitry Andric /// LowerIntrinsics - This pass rewrites calls to the llvm.gcread or
420b57cec5SDimitry Andric /// llvm.gcwrite intrinsics, replacing them with simple loads and stores as
430b57cec5SDimitry Andric /// directed by the GCStrategy. It also performs automatic root initialization
440b57cec5SDimitry Andric /// and custom intrinsic lowering.
450b57cec5SDimitry Andric class LowerIntrinsics : public FunctionPass {
460b57cec5SDimitry Andric public:
470b57cec5SDimitry Andric static char ID;
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric LowerIntrinsics();
500b57cec5SDimitry Andric StringRef getPassName() const override;
510b57cec5SDimitry Andric void getAnalysisUsage(AnalysisUsage &AU) const override;
520b57cec5SDimitry Andric
530b57cec5SDimitry Andric bool doInitialization(Module &M) override;
540b57cec5SDimitry Andric bool runOnFunction(Function &F) override;
550b57cec5SDimitry Andric };
560b57cec5SDimitry Andric
570b57cec5SDimitry Andric /// GCMachineCodeAnalysis - This is a target-independent pass over the machine
580b57cec5SDimitry Andric /// function representation to identify safe points for the garbage collector
590b57cec5SDimitry Andric /// in the machine code. It inserts labels at safe points and populates a
600b57cec5SDimitry Andric /// GCMetadata record for each function.
610b57cec5SDimitry Andric class GCMachineCodeAnalysis : public MachineFunctionPass {
6206c3fb27SDimitry Andric GCFunctionInfo *FI = nullptr;
6306c3fb27SDimitry Andric const TargetInstrInfo *TII = nullptr;
640b57cec5SDimitry Andric
650b57cec5SDimitry Andric void FindSafePoints(MachineFunction &MF);
660b57cec5SDimitry Andric void VisitCallPoint(MachineBasicBlock::iterator CI);
670b57cec5SDimitry Andric MCSymbol *InsertLabel(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
680b57cec5SDimitry Andric const DebugLoc &DL) const;
690b57cec5SDimitry Andric
700b57cec5SDimitry Andric void FindStackOffsets(MachineFunction &MF);
710b57cec5SDimitry Andric
720b57cec5SDimitry Andric public:
730b57cec5SDimitry Andric static char ID;
740b57cec5SDimitry Andric
750b57cec5SDimitry Andric GCMachineCodeAnalysis();
760b57cec5SDimitry Andric void getAnalysisUsage(AnalysisUsage &AU) const override;
770b57cec5SDimitry Andric
780b57cec5SDimitry Andric bool runOnMachineFunction(MachineFunction &MF) override;
790b57cec5SDimitry Andric };
800b57cec5SDimitry Andric }
810b57cec5SDimitry Andric
run(Function & F,FunctionAnalysisManager & FAM)821db9f3b2SDimitry Andric PreservedAnalyses GCLoweringPass::run(Function &F,
831db9f3b2SDimitry Andric FunctionAnalysisManager &FAM) {
84*0fca6ea1SDimitry Andric if (!F.hasGC())
85*0fca6ea1SDimitry Andric return PreservedAnalyses::all();
86*0fca6ea1SDimitry Andric
871db9f3b2SDimitry Andric auto &Info = FAM.getResult<GCFunctionAnalysis>(F);
881db9f3b2SDimitry Andric
891db9f3b2SDimitry Andric bool Changed = DoLowering(F, Info.getStrategy());
901db9f3b2SDimitry Andric
911db9f3b2SDimitry Andric if (!Changed)
921db9f3b2SDimitry Andric return PreservedAnalyses::all();
931db9f3b2SDimitry Andric PreservedAnalyses PA;
941db9f3b2SDimitry Andric PA.preserve<DominatorTreeAnalysis>();
951db9f3b2SDimitry Andric return PA;
961db9f3b2SDimitry Andric }
971db9f3b2SDimitry Andric
980b57cec5SDimitry Andric // -----------------------------------------------------------------------------
990b57cec5SDimitry Andric
1000b57cec5SDimitry Andric INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering", false,
1010b57cec5SDimitry Andric false)
INITIALIZE_PASS_DEPENDENCY(GCModuleInfo)1020b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(GCModuleInfo)
1030b57cec5SDimitry Andric INITIALIZE_PASS_END(LowerIntrinsics, "gc-lowering", "GC Lowering", false, false)
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andric FunctionPass *llvm::createGCLoweringPass() { return new LowerIntrinsics(); }
1060b57cec5SDimitry Andric
1070b57cec5SDimitry Andric char LowerIntrinsics::ID = 0;
108fe6060f1SDimitry Andric char &llvm::GCLoweringID = LowerIntrinsics::ID;
1090b57cec5SDimitry Andric
LowerIntrinsics()1100b57cec5SDimitry Andric LowerIntrinsics::LowerIntrinsics() : FunctionPass(ID) {
1110b57cec5SDimitry Andric initializeLowerIntrinsicsPass(*PassRegistry::getPassRegistry());
1120b57cec5SDimitry Andric }
1130b57cec5SDimitry Andric
getPassName() const1140b57cec5SDimitry Andric StringRef LowerIntrinsics::getPassName() const {
1150b57cec5SDimitry Andric return "Lower Garbage Collection Instructions";
1160b57cec5SDimitry Andric }
1170b57cec5SDimitry Andric
getAnalysisUsage(AnalysisUsage & AU) const1180b57cec5SDimitry Andric void LowerIntrinsics::getAnalysisUsage(AnalysisUsage &AU) const {
1190b57cec5SDimitry Andric FunctionPass::getAnalysisUsage(AU);
1200b57cec5SDimitry Andric AU.addRequired<GCModuleInfo>();
1210b57cec5SDimitry Andric AU.addPreserved<DominatorTreeWrapperPass>();
1220b57cec5SDimitry Andric }
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andric /// doInitialization - If this module uses the GC intrinsics, find them now.
doInitialization(Module & M)1250b57cec5SDimitry Andric bool LowerIntrinsics::doInitialization(Module &M) {
1260b57cec5SDimitry Andric GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
1270b57cec5SDimitry Andric assert(MI && "LowerIntrinsics didn't require GCModuleInfo!?");
128fe6060f1SDimitry Andric for (Function &F : M)
129fe6060f1SDimitry Andric if (!F.isDeclaration() && F.hasGC())
130fe6060f1SDimitry Andric MI->getFunctionInfo(F); // Instantiate the GC strategy.
1310b57cec5SDimitry Andric
1320b57cec5SDimitry Andric return false;
1330b57cec5SDimitry Andric }
1340b57cec5SDimitry Andric
1350b57cec5SDimitry Andric /// CouldBecomeSafePoint - Predicate to conservatively determine whether the
1360b57cec5SDimitry Andric /// instruction could introduce a safe point.
CouldBecomeSafePoint(Instruction * I)1370b57cec5SDimitry Andric static bool CouldBecomeSafePoint(Instruction *I) {
1380b57cec5SDimitry Andric // The natural definition of instructions which could introduce safe points
1390b57cec5SDimitry Andric // are:
1400b57cec5SDimitry Andric //
1410b57cec5SDimitry Andric // - call, invoke (AfterCall, BeforeCall)
1420b57cec5SDimitry Andric // - phis (Loops)
1430b57cec5SDimitry Andric // - invoke, ret, unwind (Exit)
1440b57cec5SDimitry Andric //
1450b57cec5SDimitry Andric // However, instructions as seemingly inoccuous as arithmetic can become
1460b57cec5SDimitry Andric // libcalls upon lowering (e.g., div i64 on a 32-bit platform), so instead
1470b57cec5SDimitry Andric // it is necessary to take a conservative approach.
1480b57cec5SDimitry Andric
1490b57cec5SDimitry Andric if (isa<AllocaInst>(I) || isa<GetElementPtrInst>(I) || isa<StoreInst>(I) ||
1500b57cec5SDimitry Andric isa<LoadInst>(I))
1510b57cec5SDimitry Andric return false;
1520b57cec5SDimitry Andric
1530b57cec5SDimitry Andric // llvm.gcroot is safe because it doesn't do anything at runtime.
1540b57cec5SDimitry Andric if (CallInst *CI = dyn_cast<CallInst>(I))
1550b57cec5SDimitry Andric if (Function *F = CI->getCalledFunction())
1560b57cec5SDimitry Andric if (Intrinsic::ID IID = F->getIntrinsicID())
1570b57cec5SDimitry Andric if (IID == Intrinsic::gcroot)
1580b57cec5SDimitry Andric return false;
1590b57cec5SDimitry Andric
1600b57cec5SDimitry Andric return true;
1610b57cec5SDimitry Andric }
1620b57cec5SDimitry Andric
InsertRootInitializers(Function & F,ArrayRef<AllocaInst * > Roots)1630b57cec5SDimitry Andric static bool InsertRootInitializers(Function &F, ArrayRef<AllocaInst *> Roots) {
1640b57cec5SDimitry Andric // Scroll past alloca instructions.
1650b57cec5SDimitry Andric BasicBlock::iterator IP = F.getEntryBlock().begin();
1660b57cec5SDimitry Andric while (isa<AllocaInst>(IP))
1670b57cec5SDimitry Andric ++IP;
1680b57cec5SDimitry Andric
1690b57cec5SDimitry Andric // Search for initializers in the initial BB.
1700b57cec5SDimitry Andric SmallPtrSet<AllocaInst *, 16> InitedRoots;
1710b57cec5SDimitry Andric for (; !CouldBecomeSafePoint(&*IP); ++IP)
1720b57cec5SDimitry Andric if (StoreInst *SI = dyn_cast<StoreInst>(IP))
1730b57cec5SDimitry Andric if (AllocaInst *AI =
1740b57cec5SDimitry Andric dyn_cast<AllocaInst>(SI->getOperand(1)->stripPointerCasts()))
1750b57cec5SDimitry Andric InitedRoots.insert(AI);
1760b57cec5SDimitry Andric
1770b57cec5SDimitry Andric // Add root initializers.
1780b57cec5SDimitry Andric bool MadeChange = false;
1790b57cec5SDimitry Andric
1800b57cec5SDimitry Andric for (AllocaInst *Root : Roots)
1810b57cec5SDimitry Andric if (!InitedRoots.count(Root)) {
1825ffd83dbSDimitry Andric new StoreInst(
1830b57cec5SDimitry Andric ConstantPointerNull::get(cast<PointerType>(Root->getAllocatedType())),
184*0fca6ea1SDimitry Andric Root, std::next(Root->getIterator()));
1850b57cec5SDimitry Andric MadeChange = true;
1860b57cec5SDimitry Andric }
1870b57cec5SDimitry Andric
1880b57cec5SDimitry Andric return MadeChange;
1890b57cec5SDimitry Andric }
1900b57cec5SDimitry Andric
1910b57cec5SDimitry Andric /// runOnFunction - Replace gcread/gcwrite intrinsics with loads and stores.
1920b57cec5SDimitry Andric /// Leave gcroot intrinsics; the code generator needs to see those.
runOnFunction(Function & F)1930b57cec5SDimitry Andric bool LowerIntrinsics::runOnFunction(Function &F) {
1940b57cec5SDimitry Andric // Quick exit for functions that do not use GC.
1950b57cec5SDimitry Andric if (!F.hasGC())
1960b57cec5SDimitry Andric return false;
1970b57cec5SDimitry Andric
1980b57cec5SDimitry Andric GCFunctionInfo &FI = getAnalysis<GCModuleInfo>().getFunctionInfo(F);
1990b57cec5SDimitry Andric GCStrategy &S = FI.getStrategy();
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andric return DoLowering(F, S);
2020b57cec5SDimitry Andric }
2030b57cec5SDimitry Andric
DoLowering(Function & F,GCStrategy & S)2041db9f3b2SDimitry Andric bool DoLowering(Function &F, GCStrategy &S) {
2050b57cec5SDimitry Andric SmallVector<AllocaInst *, 32> Roots;
2060b57cec5SDimitry Andric
2070b57cec5SDimitry Andric bool MadeChange = false;
2080b57cec5SDimitry Andric for (BasicBlock &BB : F)
209349cc55cSDimitry Andric for (Instruction &I : llvm::make_early_inc_range(BB)) {
210349cc55cSDimitry Andric IntrinsicInst *CI = dyn_cast<IntrinsicInst>(&I);
2110b57cec5SDimitry Andric if (!CI)
2120b57cec5SDimitry Andric continue;
2130b57cec5SDimitry Andric
2140b57cec5SDimitry Andric Function *F = CI->getCalledFunction();
2150b57cec5SDimitry Andric switch (F->getIntrinsicID()) {
2160b57cec5SDimitry Andric default: break;
2170b57cec5SDimitry Andric case Intrinsic::gcwrite: {
2180b57cec5SDimitry Andric // Replace a write barrier with a simple store.
219*0fca6ea1SDimitry Andric Value *St = new StoreInst(CI->getArgOperand(0), CI->getArgOperand(2),
220*0fca6ea1SDimitry Andric CI->getIterator());
2210b57cec5SDimitry Andric CI->replaceAllUsesWith(St);
2220b57cec5SDimitry Andric CI->eraseFromParent();
2230b57cec5SDimitry Andric MadeChange = true;
2240b57cec5SDimitry Andric break;
2250b57cec5SDimitry Andric }
2260b57cec5SDimitry Andric case Intrinsic::gcread: {
2270b57cec5SDimitry Andric // Replace a read barrier with a simple load.
228*0fca6ea1SDimitry Andric Value *Ld = new LoadInst(CI->getType(), CI->getArgOperand(1), "",
229*0fca6ea1SDimitry Andric CI->getIterator());
2300b57cec5SDimitry Andric Ld->takeName(CI);
2310b57cec5SDimitry Andric CI->replaceAllUsesWith(Ld);
2320b57cec5SDimitry Andric CI->eraseFromParent();
2330b57cec5SDimitry Andric MadeChange = true;
2340b57cec5SDimitry Andric break;
2350b57cec5SDimitry Andric }
2360b57cec5SDimitry Andric case Intrinsic::gcroot: {
2370b57cec5SDimitry Andric // Initialize the GC root, but do not delete the intrinsic. The
2380b57cec5SDimitry Andric // backend needs the intrinsic to flag the stack slot.
2390b57cec5SDimitry Andric Roots.push_back(
2400b57cec5SDimitry Andric cast<AllocaInst>(CI->getArgOperand(0)->stripPointerCasts()));
2410b57cec5SDimitry Andric break;
2420b57cec5SDimitry Andric }
2430b57cec5SDimitry Andric }
2440b57cec5SDimitry Andric }
2450b57cec5SDimitry Andric
2460b57cec5SDimitry Andric if (Roots.size())
2470b57cec5SDimitry Andric MadeChange |= InsertRootInitializers(F, Roots);
2480b57cec5SDimitry Andric
2490b57cec5SDimitry Andric return MadeChange;
2500b57cec5SDimitry Andric }
2510b57cec5SDimitry Andric
2520b57cec5SDimitry Andric // -----------------------------------------------------------------------------
2530b57cec5SDimitry Andric
2540b57cec5SDimitry Andric char GCMachineCodeAnalysis::ID = 0;
2550b57cec5SDimitry Andric char &llvm::GCMachineCodeAnalysisID = GCMachineCodeAnalysis::ID;
2560b57cec5SDimitry Andric
2570b57cec5SDimitry Andric INITIALIZE_PASS(GCMachineCodeAnalysis, "gc-analysis",
2580b57cec5SDimitry Andric "Analyze Machine Code For Garbage Collection", false, false)
2590b57cec5SDimitry Andric
GCMachineCodeAnalysis()2600b57cec5SDimitry Andric GCMachineCodeAnalysis::GCMachineCodeAnalysis() : MachineFunctionPass(ID) {}
2610b57cec5SDimitry Andric
getAnalysisUsage(AnalysisUsage & AU) const2620b57cec5SDimitry Andric void GCMachineCodeAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
2630b57cec5SDimitry Andric MachineFunctionPass::getAnalysisUsage(AU);
2640b57cec5SDimitry Andric AU.setPreservesAll();
2650b57cec5SDimitry Andric AU.addRequired<GCModuleInfo>();
2660b57cec5SDimitry Andric }
2670b57cec5SDimitry Andric
InsertLabel(MachineBasicBlock & MBB,MachineBasicBlock::iterator MI,const DebugLoc & DL) const2680b57cec5SDimitry Andric MCSymbol *GCMachineCodeAnalysis::InsertLabel(MachineBasicBlock &MBB,
2690b57cec5SDimitry Andric MachineBasicBlock::iterator MI,
2700b57cec5SDimitry Andric const DebugLoc &DL) const {
2710b57cec5SDimitry Andric MCSymbol *Label = MBB.getParent()->getContext().createTempSymbol();
2720b57cec5SDimitry Andric BuildMI(MBB, MI, DL, TII->get(TargetOpcode::GC_LABEL)).addSym(Label);
2730b57cec5SDimitry Andric return Label;
2740b57cec5SDimitry Andric }
2750b57cec5SDimitry Andric
VisitCallPoint(MachineBasicBlock::iterator CI)2760b57cec5SDimitry Andric void GCMachineCodeAnalysis::VisitCallPoint(MachineBasicBlock::iterator CI) {
2770b57cec5SDimitry Andric // Find the return address (next instruction), since that's what will be on
2780b57cec5SDimitry Andric // the stack when the call is suspended and we need to inspect the stack.
2790b57cec5SDimitry Andric MachineBasicBlock::iterator RAI = CI;
2800b57cec5SDimitry Andric ++RAI;
2810b57cec5SDimitry Andric
2820b57cec5SDimitry Andric MCSymbol *Label = InsertLabel(*CI->getParent(), RAI, CI->getDebugLoc());
2830b57cec5SDimitry Andric FI->addSafePoint(Label, CI->getDebugLoc());
2840b57cec5SDimitry Andric }
2850b57cec5SDimitry Andric
FindSafePoints(MachineFunction & MF)2860b57cec5SDimitry Andric void GCMachineCodeAnalysis::FindSafePoints(MachineFunction &MF) {
2870b57cec5SDimitry Andric for (MachineBasicBlock &MBB : MF)
288349cc55cSDimitry Andric for (MachineInstr &MI : MBB)
289349cc55cSDimitry Andric if (MI.isCall()) {
2900b57cec5SDimitry Andric // Do not treat tail or sibling call sites as safe points. This is
2910b57cec5SDimitry Andric // legal since any arguments passed to the callee which live in the
2920b57cec5SDimitry Andric // remnants of the callers frame will be owned and updated by the
2930b57cec5SDimitry Andric // callee if required.
294349cc55cSDimitry Andric if (MI.isTerminator())
2950b57cec5SDimitry Andric continue;
296349cc55cSDimitry Andric VisitCallPoint(&MI);
2970b57cec5SDimitry Andric }
2980b57cec5SDimitry Andric }
2990b57cec5SDimitry Andric
FindStackOffsets(MachineFunction & MF)3000b57cec5SDimitry Andric void GCMachineCodeAnalysis::FindStackOffsets(MachineFunction &MF) {
3010b57cec5SDimitry Andric const TargetFrameLowering *TFI = MF.getSubtarget().getFrameLowering();
3020b57cec5SDimitry Andric assert(TFI && "TargetRegisterInfo not available!");
3030b57cec5SDimitry Andric
3040b57cec5SDimitry Andric for (GCFunctionInfo::roots_iterator RI = FI->roots_begin();
3050b57cec5SDimitry Andric RI != FI->roots_end();) {
3060b57cec5SDimitry Andric // If the root references a dead object, no need to keep it.
3070b57cec5SDimitry Andric if (MF.getFrameInfo().isDeadObjectIndex(RI->Num)) {
3080b57cec5SDimitry Andric RI = FI->removeStackRoot(RI);
3090b57cec5SDimitry Andric } else {
3105ffd83dbSDimitry Andric Register FrameReg; // FIXME: surely GCRoot ought to store the
3110b57cec5SDimitry Andric // register that the offset is from?
312e8d8bef9SDimitry Andric auto FrameOffset = TFI->getFrameIndexReference(MF, RI->Num, FrameReg);
313e8d8bef9SDimitry Andric assert(!FrameOffset.getScalable() &&
314e8d8bef9SDimitry Andric "Frame offsets with a scalable component are not supported");
315e8d8bef9SDimitry Andric RI->StackOffset = FrameOffset.getFixed();
3160b57cec5SDimitry Andric ++RI;
3170b57cec5SDimitry Andric }
3180b57cec5SDimitry Andric }
3190b57cec5SDimitry Andric }
3200b57cec5SDimitry Andric
runOnMachineFunction(MachineFunction & MF)3210b57cec5SDimitry Andric bool GCMachineCodeAnalysis::runOnMachineFunction(MachineFunction &MF) {
3220b57cec5SDimitry Andric // Quick exit for functions that do not use GC.
3230b57cec5SDimitry Andric if (!MF.getFunction().hasGC())
3240b57cec5SDimitry Andric return false;
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andric FI = &getAnalysis<GCModuleInfo>().getFunctionInfo(MF.getFunction());
3270b57cec5SDimitry Andric TII = MF.getSubtarget().getInstrInfo();
3280b57cec5SDimitry Andric
3290b57cec5SDimitry Andric // Find the size of the stack frame. There may be no correct static frame
3300b57cec5SDimitry Andric // size, we use UINT64_MAX to represent this.
3310b57cec5SDimitry Andric const MachineFrameInfo &MFI = MF.getFrameInfo();
3320b57cec5SDimitry Andric const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
333fe6060f1SDimitry Andric const bool DynamicFrameSize =
334fe6060f1SDimitry Andric MFI.hasVarSizedObjects() || RegInfo->hasStackRealignment(MF);
3350b57cec5SDimitry Andric FI->setFrameSize(DynamicFrameSize ? UINT64_MAX : MFI.getStackSize());
3360b57cec5SDimitry Andric
3370b57cec5SDimitry Andric // Find all safe points.
3380b57cec5SDimitry Andric if (FI->getStrategy().needsSafePoints())
3390b57cec5SDimitry Andric FindSafePoints(MF);
3400b57cec5SDimitry Andric
3410b57cec5SDimitry Andric // Find the concrete stack offsets for all roots (stack slots)
3420b57cec5SDimitry Andric FindStackOffsets(MF);
3430b57cec5SDimitry Andric
3440b57cec5SDimitry Andric return false;
3450b57cec5SDimitry Andric }
346