Skip to content

Commit db126d8

Browse files
authored
CodeGen: Make MachineFunction's subtarget member a reference (#153352)
1 parent 02ab6f3 commit db126d8

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ struct LandingPadInfo {
286286
class LLVM_ABI MachineFunction {
287287
Function &F;
288288
const TargetMachine &Target;
289-
const TargetSubtargetInfo *STI;
289+
const TargetSubtargetInfo &STI;
290290
MCContext &Ctx;
291291

292292
// RegInfo - Information about each register in use in the function.
@@ -759,13 +759,13 @@ class LLVM_ABI MachineFunction {
759759

760760
/// getSubtarget - Return the subtarget for which this machine code is being
761761
/// compiled.
762-
const TargetSubtargetInfo &getSubtarget() const { return *STI; }
762+
const TargetSubtargetInfo &getSubtarget() const { return STI; }
763763

764764
/// getSubtarget - This method returns a pointer to the specified type of
765765
/// TargetSubtargetInfo. In debug builds, it verifies that the object being
766766
/// returned is of the correct type.
767767
template<typename STC> const STC &getSubtarget() const {
768-
return *static_cast<const STC *>(STI);
768+
return static_cast<const STC &>(STI);
769769
}
770770

771771
/// getRegInfo - Return information about the registers currently in use.

llvm/lib/CodeGen/MachineFunction.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,17 @@ void ilist_alloc_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) {
154154
MBB->getParent()->deleteMachineBasicBlock(MBB);
155155
}
156156

157-
static inline Align getFnStackAlignment(const TargetSubtargetInfo *STI,
158-
const Function &F) {
157+
static inline Align getFnStackAlignment(const TargetSubtargetInfo &STI,
158+
const Function &F) {
159159
if (auto MA = F.getFnStackAlign())
160160
return *MA;
161-
return STI->getFrameLowering()->getStackAlign();
161+
return STI.getFrameLowering()->getStackAlign();
162162
}
163163

164164
MachineFunction::MachineFunction(Function &F, const TargetMachine &Target,
165165
const TargetSubtargetInfo &STI, MCContext &Ctx,
166166
unsigned FunctionNum)
167-
: F(F), Target(Target), STI(&STI), Ctx(Ctx) {
167+
: F(F), Target(Target), STI(STI), Ctx(Ctx) {
168168
FunctionNumber = FunctionNum;
169169
init();
170170
}
@@ -195,7 +195,7 @@ void MachineFunction::init() {
195195

196196
// We can realign the stack if the target supports it and the user hasn't
197197
// explicitly asked us not to.
198-
bool CanRealignSP = STI->getFrameLowering()->isStackRealignable() &&
198+
bool CanRealignSP = STI.getFrameLowering()->isStackRealignable() &&
199199
!F.hasFnAttribute("no-realign-stack");
200200
bool ForceRealignSP = F.hasFnAttribute(Attribute::StackAlignment) ||
201201
F.hasFnAttribute("stackrealign");
@@ -209,11 +209,11 @@ void MachineFunction::init() {
209209
FrameInfo->ensureMaxAlignment(*F.getFnStackAlign());
210210

211211
ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
212-
Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
212+
Alignment = STI.getTargetLowering()->getMinFunctionAlignment();
213213

214214
if (!F.getAlign() && !F.hasOptSize())
215215
Alignment = std::max(Alignment,
216-
STI->getTargetLowering()->getPrefFunctionAlignment());
216+
STI.getTargetLowering()->getPrefFunctionAlignment());
217217

218218
// -fsanitize=function and -fsanitize=kcfi instrument indirect function calls
219219
// to load a type hash before the function label. Ensure functions are aligned

0 commit comments

Comments
 (0)