[llvm] r320882 - MachineFunction: Slight refactoring; NFC
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 15 14:22:46 PST 2017
Author: matze
Date: Fri Dec 15 14:22:46 2017
New Revision: 320882
URL: http://llvm.org/viewvc/llvm-project?rev=320882&view=rev
Log:
MachineFunction: Slight refactoring; NFC
Slight cleanup/refactor in preparation for upcoming commit.
Modified:
llvm/trunk/include/llvm/CodeGen/MachineFunction.h
llvm/trunk/lib/CodeGen/MachineFunction.cpp
llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
Modified: llvm/trunk/include/llvm/CodeGen/MachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFunction.h?rev=320882&r1=320881&r2=320882&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFunction.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFunction.h Fri Dec 15 14:22:46 2017
@@ -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<VariableDbgInfo, 4>;
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;
Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=320882&r1=320881&r2=320882&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Fri Dec 15 14:22:46 2017
@@ -119,16 +119,16 @@ void ilist_alloc_traits<MachineBasicBloc
}
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.
Modified: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp?rev=320882&r1=320881&r2=320882&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp Fri Dec 15 14:22:46 2017
@@ -276,7 +276,8 @@ MachineModuleInfo::getOrCreateMachineFun
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 {
Modified: llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp?rev=320882&r1=320881&r2=320882&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/MachineInstrTest.cpp Fri Dec 15 14:22:46 2017
@@ -91,8 +91,9 @@ std::unique_ptr<MachineFunction> createM
auto TM = createTargetMachine();
unsigned FunctionNum = 42;
MachineModuleInfo MMI(TM.get());
+ const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(*F);
- return llvm::make_unique<MachineFunction>(F, *TM, FunctionNum, MMI);
+ return llvm::make_unique<MachineFunction>(*F, *TM, STI, FunctionNum, MMI);
}
// This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly
More information about the llvm-commits
mailing list