[llvm] db126d8 - CodeGen: Make MachineFunction's subtarget member a reference (#153352)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 13 00:22:35 PDT 2025
Author: Matt Arsenault
Date: 2025-08-13T16:22:32+09:00
New Revision: db126d8004fda8998792e83e6938f4b3c221227a
URL: https://github.com/llvm/llvm-project/commit/db126d8004fda8998792e83e6938f4b3c221227a
DIFF: https://github.com/llvm/llvm-project/commit/db126d8004fda8998792e83e6938f4b3c221227a.diff
LOG: CodeGen: Make MachineFunction's subtarget member a reference (#153352)
Added:
Modified:
llvm/include/llvm/CodeGen/MachineFunction.h
llvm/lib/CodeGen/MachineFunction.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h
index 69b7a3f570c89..ef783f276b7d4 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -286,7 +286,7 @@ struct LandingPadInfo {
class LLVM_ABI MachineFunction {
Function &F;
const TargetMachine &Target;
- const TargetSubtargetInfo *STI;
+ const TargetSubtargetInfo &STI;
MCContext &Ctx;
// RegInfo - Information about each register in use in the function.
@@ -759,13 +759,13 @@ class LLVM_ABI MachineFunction {
/// getSubtarget - Return the subtarget for which this machine code is being
/// compiled.
- const TargetSubtargetInfo &getSubtarget() const { return *STI; }
+ const TargetSubtargetInfo &getSubtarget() const { return STI; }
/// getSubtarget - This method returns a pointer to the specified type of
/// TargetSubtargetInfo. In debug builds, it verifies that the object being
/// returned is of the correct type.
template<typename STC> const STC &getSubtarget() const {
- return *static_cast<const STC *>(STI);
+ return static_cast<const STC &>(STI);
}
/// getRegInfo - Return information about the registers currently in use.
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index ec40f6af3caae..82ba596049cdc 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -154,17 +154,17 @@ void ilist_alloc_traits<MachineBasicBlock>::deleteNode(MachineBasicBlock *MBB) {
MBB->getParent()->deleteMachineBasicBlock(MBB);
}
-static inline Align getFnStackAlignment(const TargetSubtargetInfo *STI,
- const Function &F) {
+static inline Align getFnStackAlignment(const TargetSubtargetInfo &STI,
+ const Function &F) {
if (auto MA = F.getFnStackAlign())
return *MA;
- return STI->getFrameLowering()->getStackAlign();
+ return STI.getFrameLowering()->getStackAlign();
}
MachineFunction::MachineFunction(Function &F, const TargetMachine &Target,
const TargetSubtargetInfo &STI, MCContext &Ctx,
unsigned FunctionNum)
- : F(F), Target(Target), STI(&STI), Ctx(Ctx) {
+ : F(F), Target(Target), STI(STI), Ctx(Ctx) {
FunctionNumber = FunctionNum;
init();
}
@@ -195,7 +195,7 @@ 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() &&
+ bool CanRealignSP = STI.getFrameLowering()->isStackRealignable() &&
!F.hasFnAttribute("no-realign-stack");
bool ForceRealignSP = F.hasFnAttribute(Attribute::StackAlignment) ||
F.hasFnAttribute("stackrealign");
@@ -209,11 +209,11 @@ void MachineFunction::init() {
FrameInfo->ensureMaxAlignment(*F.getFnStackAlign());
ConstantPool = new (Allocator) MachineConstantPool(getDataLayout());
- Alignment = STI->getTargetLowering()->getMinFunctionAlignment();
+ Alignment = STI.getTargetLowering()->getMinFunctionAlignment();
if (!F.getAlign() && !F.hasOptSize())
Alignment = std::max(Alignment,
- STI->getTargetLowering()->getPrefFunctionAlignment());
+ STI.getTargetLowering()->getPrefFunctionAlignment());
// -fsanitize=function and -fsanitize=kcfi instrument indirect function calls
// to load a type hash before the function label. Ensure functions are aligned
More information about the llvm-commits
mailing list