diff --git a/include/llvm/CodeGen/MachineFunction.h b/include/llvm/CodeGen/MachineFunction.h index c6bcca7f7b3..4ffd4bdc2f3 100644 --- a/include/llvm/CodeGen/MachineFunction.h +++ b/include/llvm/CodeGen/MachineFunction.h @@ -223,7 +223,7 @@ struct LandingPadInfo { }; class MachineFunction { - const Function *Fn; + const Function &F; const TargetMachine &Target; const TargetSubtargetInfo *STI; MCContext &Ctx; @@ -359,8 +359,9 @@ public: using VariableDbgInfoMapTy = SmallVector; VariableDbgInfoMapTy VariableDbgInfos; - MachineFunction(const Function *Fn, const TargetMachine &TM, - unsigned FunctionNum, MachineModuleInfo &MMI); + MachineFunction(const Function &F, const TargetMachine &TM, + const TargetSubtargetInfo &STI, unsigned FunctionNum, + MachineModuleInfo &MMI); MachineFunction(const MachineFunction &) = delete; MachineFunction &operator=(const MachineFunction &) = delete; ~MachineFunction(); @@ -380,7 +381,7 @@ public: const DataLayout &getDataLayout() const; /// getFunction - Return the LLVM function that this machine code represents - const Function *getFunction() const { return Fn; } + const Function *getFunction() const { return &F; } /// getName - Return the name of the corresponding LLVM function. StringRef getName() const; diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index dba0dfbe886..5ffc8914b96 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -119,16 +119,16 @@ void ilist_alloc_traits::deleteNode(MachineBasicBlock *MBB) { } static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI, - const Function *Fn) { - if (Fn->hasFnAttribute(Attribute::StackAlignment)) - return Fn->getFnStackAlignment(); + const Function &F) { + if (F.hasFnAttribute(Attribute::StackAlignment)) + return F.getFnStackAlignment(); return STI->getFrameLowering()->getStackAlignment(); } -MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM, +MachineFunction::MachineFunction(const Function &F, const TargetMachine &Target, + const TargetSubtargetInfo &STI, unsigned FunctionNum, MachineModuleInfo &mmi) - : Fn(F), Target(TM), STI(TM.getSubtargetImpl(*F)), Ctx(mmi.getContext()), - MMI(mmi) { + : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) { FunctionNumber = FunctionNum; init(); } @@ -146,21 +146,21 @@ void MachineFunction::init() { // We can realign the stack if the target supports it and the user hasn't // explicitly asked us not to. bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() && - !Fn->hasFnAttribute("no-realign-stack"); + !F.hasFnAttribute("no-realign-stack"); FrameInfo = new (Allocator) MachineFrameInfo( - getFnStackAlignment(STI, Fn), /*StackRealignable=*/CanRealignSP, + getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP, /*ForceRealign=*/CanRealignSP && - Fn->hasFnAttribute(Attribute::StackAlignment)); + F.hasFnAttribute(Attribute::StackAlignment)); - if (Fn->hasFnAttribute(Attribute::StackAlignment)) - FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment()); + if (F.hasFnAttribute(Attribute::StackAlignment)) + FrameInfo->ensureMaxAlignment(F.getFnStackAlignment()); ConstantPool = new (Allocator) MachineConstantPool(getDataLayout()); Alignment = STI->getTargetLowering()->getMinFunctionAlignment(); - // FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn. + // FIXME: Shouldn't use pref alignment if explicit alignment is set on F. // FIXME: Use Function::optForSize(). - if (!Fn->hasFnAttribute(Attribute::OptimizeForSize)) + if (!F.hasFnAttribute(Attribute::OptimizeForSize)) Alignment = std::max(Alignment, STI->getTargetLowering()->getPrefFunctionAlignment()); @@ -170,7 +170,7 @@ void MachineFunction::init() { JumpTableInfo = nullptr; if (isFuncletEHPersonality(classifyEHPersonality( - Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr))) { + F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) { WinEHInfo = new (Allocator) WinEHFuncInfo(); } @@ -228,7 +228,7 @@ void MachineFunction::clear() { } const DataLayout &MachineFunction::getDataLayout() const { - return Fn->getParent()->getDataLayout(); + return F.getParent()->getDataLayout(); } /// Get the JumpTableInfo for this function. diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index 560df08c980..8f0b89657d0 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -276,7 +276,8 @@ MachineModuleInfo::getOrCreateMachineFunction(const Function &F) { MachineFunction *MF; if (I.second) { // No pre-existing machine function, create a new one. - MF = new MachineFunction(&F, TM, NextFnNum++, *this); + const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F); + MF = new MachineFunction(F, TM, STI, NextFnNum++, *this); // Update the set entry. I.first->second.reset(MF); } else { diff --git a/unittests/CodeGen/MachineInstrTest.cpp b/unittests/CodeGen/MachineInstrTest.cpp index fe8e792412f..aca640ebcf3 100644 --- a/unittests/CodeGen/MachineInstrTest.cpp +++ b/unittests/CodeGen/MachineInstrTest.cpp @@ -91,8 +91,9 @@ std::unique_ptr createMachineFunction() { auto TM = createTargetMachine(); unsigned FunctionNum = 42; MachineModuleInfo MMI(TM.get()); + const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(*F); - return llvm::make_unique(F, *TM, FunctionNum, MMI); + return llvm::make_unique(*F, *TM, STI, FunctionNum, MMI); } // This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly