llvm.org GIT mirror llvm / dfcb4f5
MachineFunction: Slight refactoring; NFC Slight cleanup/refactor in preparation for upcoming commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320882 91177308-0d34-0410-b5e6-96231b3b80d8 Matthias Braun 2 years ago
4 changed file(s) with 26 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
222222 };
223223
224224 class MachineFunction {
225 const Function *Fn;
225 const Function &F;
226226 const TargetMachine &Target;
227227 const TargetSubtargetInfo *STI;
228228 MCContext &Ctx;
358358 using VariableDbgInfoMapTy = SmallVector;
359359 VariableDbgInfoMapTy VariableDbgInfos;
360360
361 MachineFunction(const Function *Fn, const TargetMachine &TM,
362 unsigned FunctionNum, MachineModuleInfo &MMI);
361 MachineFunction(const Function &F, const TargetMachine &TM,
362 const TargetSubtargetInfo &STI, unsigned FunctionNum,
363 MachineModuleInfo &MMI);
363364 MachineFunction(const MachineFunction &) = delete;
364365 MachineFunction &operator=(const MachineFunction &) = delete;
365366 ~MachineFunction();
379380 const DataLayout &getDataLayout() const;
380381
381382 /// getFunction - Return the LLVM function that this machine code represents
382 const Function *getFunction() const { return Fn; }
383 const Function *getFunction() const { return &F; }
383384
384385 /// getName - Return the name of the corresponding LLVM function.
385386 StringRef getName() const;
118118 }
119119
120120 static inline unsigned getFnStackAlignment(const TargetSubtargetInfo *STI,
121 const Function *Fn) {
122 if (Fn->hasFnAttribute(Attribute::StackAlignment))
123 return Fn->getFnStackAlignment();
121 const Function &F) {
122 if (F.hasFnAttribute(Attribute::StackAlignment))
123 return F.getFnStackAlignment();
124124 return STI->getFrameLowering()->getStackAlignment();
125125 }
126126
127 MachineFunction::MachineFunction(const Function *F, const TargetMachine &TM,
127 MachineFunction::MachineFunction(const Function &F, const TargetMachine &Target,
128 const TargetSubtargetInfo &STI,
128129 unsigned FunctionNum, MachineModuleInfo &mmi)
129 : Fn(F), Target(TM), STI(TM.getSubtargetImpl(*F)), Ctx(mmi.getContext()),
130 MMI(mmi) {
130 : F(F), Target(Target), STI(&STI), Ctx(mmi.getContext()), MMI(mmi) {
131131 FunctionNumber = FunctionNum;
132132 init();
133133 }
145145 // We can realign the stack if the target supports it and the user hasn't
146146 // explicitly asked us not to.
147147 bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
148 !Fn->hasFnAttribute("no-realign-stack");
148 !F.hasFnAttribute("no-realign-stack");
149149 FrameInfo = new (Allocator) MachineFrameInfo(
150 getFnStackAlignment(STI, Fn), /*StackRealignable=*/CanRealignSP,
150 getFnStackAlignment(STI, F), /*StackRealignable=*/CanRealignSP,
151151 /*ForceRealign=*/CanRealignSP &&
152 Fn->hasFnAttribute(Attribute::StackAlignment));
153
154 if (Fn->hasFnAttribute(Attribute::StackAlignment))
155 FrameInfo->ensureMaxAlignment(Fn->getFnStackAlignment());
152 F.hasFnAttribute(Attribute::StackAlignment));
153
154 if (F.hasFnAttribute(Attribute::StackAlignment))
155 FrameInfo->ensureMaxAlignment(F.getFnStackAlignment());
156156
157157 ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
158158 Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
159159
160 // FIXME: Shouldn't use pref alignment if explicit alignment is set on Fn.
160 // FIXME: Shouldn't use pref alignment if explicit alignment is set on F.
161161 // FIXME: Use Function::optForSize().
162 if (!Fn->hasFnAttribute(Attribute::OptimizeForSize))
162 if (!F.hasFnAttribute(Attribute::OptimizeForSize))
163163 Alignment = std::max(Alignment,
164164 STI->getTargetLowering()->getPrefFunctionAlignment());
165165
169169 JumpTableInfo = nullptr;
170170
171171 if (isFuncletEHPersonality(classifyEHPersonality(
172 Fn->hasPersonalityFn() ? Fn->getPersonalityFn() : nullptr))) {
172 F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr))) {
173173 WinEHInfo = new (Allocator) WinEHFuncInfo();
174174 }
175175
227227 }
228228
229229 const DataLayout &MachineFunction::getDataLayout() const {
230 return Fn->getParent()->getDataLayout();
230 return F.getParent()->getDataLayout();
231231 }
232232
233233 /// Get the JumpTableInfo for this function.
275275 MachineFunction *MF;
276276 if (I.second) {
277277 // No pre-existing machine function, create a new one.
278 MF = new MachineFunction(&F, TM, NextFnNum++, *this);
278 const TargetSubtargetInfo &STI = *TM.getSubtargetImpl(F);
279 MF = new MachineFunction(F, TM, STI, NextFnNum++, *this);
279280 // Update the set entry.
280281 I.first->second.reset(MF);
281282 } else {
9090 auto TM = createTargetMachine();
9191 unsigned FunctionNum = 42;
9292 MachineModuleInfo MMI(TM.get());
93
94 return llvm::make_unique(F, *TM, FunctionNum, MMI);
93 const TargetSubtargetInfo &STI = *TM->getSubtargetImpl(*F);
94
95 return llvm::make_unique(*F, *TM, STI, FunctionNum, MMI);
9596 }
9697
9798 // This test makes sure that MachineInstr::isIdenticalTo handles Defs correctly