[llvm] 1e80bdc - CodeGen: Prefer getting the Triple from the Module when convenient (#228429)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 3 01:35:53 PDT 2026
Author: Matt Arsenault
Date: 2026-10-03T10:35:41+02:00
New Revision: 1e80bdc439e5034eecd5e667132aaab24636a188
URL: https://github.com/llvm/llvm-project/commit/1e80bdc439e5034eecd5e667132aaab24636a188
DIFF: https://github.com/llvm/llvm-project/commit/1e80bdc439e5034eecd5e667132aaab24636a188.diff
LOG: CodeGen: Prefer getting the Triple from the Module when convenient (#228429)
Take the triple from the contextual module rather than TargetMachine when it's
already readily available.
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/ARM/ARMAsmPrinter.cpp
llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
llvm/lib/Target/Mips/MipsAsmPrinter.cpp
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
llvm/lib/Target/SystemZ/SystemZXPLINKAsmPrinter.cpp
llvm/lib/Target/X86/X86AsmPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index b16ac47025d71c..ae8d8fbe84c03d 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -523,7 +523,7 @@ bool AsmPrinter::doInitialization(Module &M) {
HasSplitStack = false;
HasNoSplitStack = false;
DbgInfoAvailable = !M.debug_compile_units().empty();
- const Triple &Target = TM.getTargetTriple();
+ const Triple &Target = M.getTargetTriple();
AddrLabelSymbols = nullptr;
@@ -773,8 +773,8 @@ MCSymbol *AsmPrinter::getSymbolPreferLocal(const GlobalValue &GV) const {
// assembler would otherwise be conservative and assume a global default
// visibility symbol can be interposable, even if the code generator already
// assumed it.
- if (TM.getTargetTriple().isOSBinFormatELF() && GV.canBenefitFromLocalAlias()) {
- const Module &M = *GV.getParent();
+ const Module &M = *GV.getParent();
+ if (M.getTargetTriple().isOSBinFormatELF() && GV.canBenefitFromLocalAlias()) {
if (TM.getRelocationModel() != Reloc::Static &&
M.getPIELevel() == PIELevel::Default && GV.isDSOLocal())
return getSymbolWithGlobalValueBase(&GV, "$local");
@@ -2096,8 +2096,9 @@ void AsmPrinter::emitFunctionBody() {
bool HasAnyRealCode = false;
int NumInstsInFunction = 0;
// Only x86 needs this padding; the Arm unwinders back the PC up themselves.
- bool NeedsEHaNops = MMI->getModule()->getModuleFlag("eh-asynch") &&
- TM.getTargetTriple().isX86();
+ const Module *M = MMI->getModule();
+ bool NeedsEHaNops =
+ M->getTargetTriple().isX86() && M->getModuleFlag("eh-asynch");
const MCSubtargetInfo *STI = nullptr;
if (this->MF)
@@ -2345,7 +2346,7 @@ void AsmPrinter::emitFunctionBody() {
// If there is a post-instruction symbol, emit a label for it here.
if (MCSymbol *S = MI.getPostInstrSymbol()) {
// Emit the weak symbol attribute used for the prefetch target fallback.
- if (TM.getTargetTriple().isOSBinFormatELF()) {
+ if (M->getTargetTriple().isOSBinFormatELF()) {
MCSymbolELF *ESym = static_cast<MCSymbolELF *>(S);
if (ESym->getBinding() == ELF::STB_WEAK)
OutStreamer->emitSymbolAttribute(S, MCSA_Weak);
@@ -2454,7 +2455,7 @@ void AsmPrinter::emitFunctionBody() {
// after linking, causing the kernel not to load the binary:
// https://developercommunity.visualstudio.com/content/problem/45366/vc-linker-creates-invalid-dll-with-clang-cl.html
// FIXME: Hide this behind some API in e.g. MCAsmInfo or MCTargetStreamer.
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M->getTargetTriple();
if (!HasAnyRealCode && (MAI.hasSubsectionsViaSymbols() ||
(TT.isOSWindows() && TT.isOSBinFormatCOFF()))) {
MCInst Noop = MF->getSubtarget().getInstrInfo()->getNop();
@@ -2692,7 +2693,7 @@ void AsmPrinter::emitGlobalAlias(const Module &M, const GlobalAlias &GA) {
// so AIX has to use the extra-label-at-definition strategy. At this
// point, all the extra label is emitted, we just have to emit linkage for
// those labels.
- if (TM.getTargetTriple().isOSBinFormatXCOFF()) {
+ if (M.getTargetTriple().isOSBinFormatXCOFF()) {
// Linkage for alias of global variable has been emitted.
if (isa_and_nonnull<GlobalVariable>(BaseObject))
return;
@@ -2717,7 +2718,7 @@ void AsmPrinter::emitGlobalAlias(const Module &M, const GlobalAlias &GA) {
// This affects codegen when the aliasee is not a function.
if (IsFunction) {
OutStreamer->emitSymbolAttribute(Name, MCSA_ELF_TypeFunction);
- if (TM.getTargetTriple().isOSBinFormatCOFF()) {
+ if (M.getTargetTriple().isOSBinFormatCOFF()) {
OutStreamer->beginCOFFSymbolDef(Name);
OutStreamer->emitCOFFSymbolStorageClass(
GA.hasLocalLinkage() ? COFF::IMAGE_SYM_CLASS_STATIC
@@ -2764,7 +2765,7 @@ void AsmPrinter::emitGlobalIFunc(Module &M, const GlobalIFunc &GI) {
assert(GI.hasLocalLinkage() && "Invalid ifunc linkage");
};
- if (TM.getTargetTriple().isOSBinFormatELF()) {
+ if (M.getTargetTriple().isOSBinFormatELF()) {
MCSymbol *Name = getSymbol(&GI);
EmitLinkage(Name);
OutStreamer->emitSymbolAttribute(Name, MCSA_ELF_TypeIndFunction);
@@ -2780,7 +2781,7 @@ void AsmPrinter::emitGlobalIFunc(Module &M, const GlobalIFunc &GI) {
return;
}
- if (!TM.getTargetTriple().isOSBinFormatMachO() || !getIFuncMCSubtargetInfo())
+ if (!M.getTargetTriple().isOSBinFormatMachO() || !getIFuncMCSubtargetInfo())
reportFatalUsageError("IFuncs are not supported on this platform");
// On Darwin platforms, emit a manually-constructed .symbol_resolver that
@@ -2946,7 +2947,7 @@ bool AsmPrinter::doFinalization(Module &M) {
// accesses to MF specific features at the module level and so that
// we can conditionalize accesses based on whether or not it is nullptr.
MF = nullptr;
- const Triple &Target = TM.getTargetTriple();
+ const Triple &Target = M.getTargetTriple();
std::vector<GlobalVariable *> GlobalsToTag;
for (GlobalVariable &G : M.globals()) {
@@ -3099,7 +3100,7 @@ bool AsmPrinter::doFinalization(Module &M) {
// sections after DWARF.
for (const auto &IFunc : M.ifuncs())
emitGlobalIFunc(M, IFunc);
- if (TM.getTargetTriple().isOSBinFormatXCOFF() && hasDebugInfo()) {
+ if (M.getTargetTriple().isOSBinFormatXCOFF() && hasDebugInfo()) {
// Emit section end. This is used to tell the debug line section where the
// end is for a text section if we don't use .loc to represent the debug
// line.
@@ -3160,7 +3161,7 @@ bool AsmPrinter::doFinalization(Module &M) {
// Emit .note.GNU-split-stack and .note.GNU-no-split-stack sections if
// split-stack is used.
- if (TM.getTargetTriple().isOSBinFormatELF() && HasSplitStack) {
+ if (M.getTargetTriple().isOSBinFormatELF() && HasSplitStack) {
OutStreamer->switchSection(OutContext.getELFSection(".note.GNU-split-stack",
ELF::SHT_PROGBITS, 0));
if (HasNoSplitStack)
@@ -5252,7 +5253,7 @@ AsmPrinter::getCodeViewJumpTableInfo(int JTI, const MachineInstr *BranchInstr,
}
void AsmPrinter::emitCOFFReplaceableFunctionData(Module &M) {
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
assert(TT.isOSBinFormatCOFF());
bool IsTargetArm64EC = TT.isWindowsArm64EC();
@@ -5317,7 +5318,7 @@ void AsmPrinter::emitCOFFReplaceableFunctionData(Module &M) {
}
void AsmPrinter::emitCOFFFeatureSymbol(Module &M) {
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
assert(TT.isOSBinFormatCOFF());
// Emit an absolute @feat.00 symbol.
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 5a502f785e0f40..51acae3a763883 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -423,7 +423,7 @@ static bool getOptionalBooleanModuleFlag(Module &M, StringRef Name) {
}
void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) {
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
if (TT.isOSBinFormatCOFF()) {
emitCOFFFeatureSymbol(M);
@@ -831,7 +831,7 @@ void AArch64AsmPrinter::emitHwasanMemaccessSymbols(Module &M) {
if (HwasanMemaccessSymbols.empty())
return;
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
assert(TT.isOSBinFormatELF());
// AArch64Subtarget is huge, so heap allocate it so we don't run out of stack
// space.
@@ -1045,7 +1045,7 @@ static void emitAuthenticatedPointer(MCStreamer &OutStreamer,
void AArch64AsmPrinter::emitEndOfAsmFile(Module &M) {
emitHwasanMemaccessSymbols(M);
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
if (TT.isOSBinFormatMachO()) {
// Output authenticated pointers as indirect symbols, if we have any.
MachineModuleInfoMachO &MMIMacho =
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index ef21aa3ba6adfb..0ab4311d01c4ab 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -535,7 +535,7 @@ void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,
}
void ARMAsmPrinter::emitStartOfAsmFile(Module &M) {
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
auto &TS =
static_cast<ARMTargetStreamer &>(*OutStreamer->getTargetStreamer());
// Use unified assembler syntax.
@@ -576,7 +576,7 @@ emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
void ARMAsmPrinter::emitEndOfAsmFile(Module &M) {
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
if (TT.isOSBinFormatMachO()) {
// All darwin targets use mach-o.
const TargetLoweringObjectFileMachO &TLOFMacho =
@@ -830,7 +830,7 @@ void ARMAsmPrinter::emitAttributes() {
if (const Module *SourceModule = MMI->getModule()) {
// ABI_PCS_wchar_t to indicate wchar_t width
// FIXME: There is no way to emit value 0 (wchar_t prohibited).
- int WCharWidth = TM.getTargetTriple().getDefaultWCharSize();
+ int WCharWidth = SourceModule->getTargetTriple().getDefaultWCharSize();
if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>(
SourceModule->getModuleFlag("wchar_size")))
WCharWidth = WCharWidthValue->getZExtValue();
diff --git a/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp b/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
index 90b86a60bc675d..db67486b2d2a24 100644
--- a/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
+++ b/llvm/lib/Target/CSKY/CSKYAsmPrinter.cpp
@@ -129,7 +129,7 @@ void CSKYAsmPrinter::emitFunctionBodyEnd() {
}
void CSKYAsmPrinter::emitStartOfAsmFile(Module &M) {
- if (TM.getTargetTriple().isOSBinFormatELF())
+ if (M.getTargetTriple().isOSBinFormatELF())
emitAttributes(M);
}
@@ -137,7 +137,7 @@ void CSKYAsmPrinter::emitEndOfAsmFile(Module &M) {
CSKYTargetStreamer &CTS =
static_cast<CSKYTargetStreamer &>(*OutStreamer->getTargetStreamer());
- if (TM.getTargetTriple().isOSBinFormatELF())
+ if (M.getTargetTriple().isOSBinFormatELF())
CTS.finishAttributeSection();
}
diff --git a/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp b/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
index b965f8c1fbc089..143cee16477220 100644
--- a/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonAsmPrinter.cpp
@@ -34,6 +34,7 @@
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/Module.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDirectives.h"
#include "llvm/MC/MCExpr.h"
@@ -785,14 +786,14 @@ void HexagonAsmPrinter::emitInstruction(const MachineInstr *MI) {
}
void HexagonAsmPrinter::emitStartOfAsmFile(Module &M) {
- if (TM.getTargetTriple().isOSBinFormatELF())
+ if (M.getTargetTriple().isOSBinFormatELF())
emitAttributes();
}
void HexagonAsmPrinter::emitEndOfAsmFile(Module &M) {
HexagonTargetStreamer &HTS =
static_cast<HexagonTargetStreamer &>(*OutStreamer->getTargetStreamer());
- if (TM.getTargetTriple().isOSBinFormatELF())
+ if (M.getTargetTriple().isOSBinFormatELF())
HTS.finishAttributeSection();
}
diff --git a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
index 38ee358a4de6c5..2fd290c846e8ee 100644
--- a/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
@@ -52,7 +52,7 @@ void LoongArchAsmPrinter::emitStartOfAsmFile(Module &M) {
StringRef ABIName = M.getTargetABIFromMD();
if (!ABIName.empty()) {
getTargetStreamer().setTargetABI(LoongArchABI::computeTargetABI(
- TM.getTargetTriple(), TM.getMCSubtargetInfo().getFeatureBits(),
+ M.getTargetTriple(), TM.getMCSubtargetInfo().getFeatureBits(),
ABIName));
}
}
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index 4db0409e4837ef..d2d7e491223c3c 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -720,7 +720,7 @@ printRegisterList(const MachineInstr *MI, int opNum, raw_ostream &O) {
}
void MipsAsmPrinter::emitStartOfAsmFile(Module &M) {
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
if (TT.isOSBinFormatELF()) {
MipsTargetStreamer &TS = getTargetStreamer();
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 97a8e28c601d0f..0d3275b4b56c5b 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -3077,7 +3077,7 @@ bool PPCAIXAsmPrinter::doInitialization(Module &M) {
const bool Result = PPCAsmPrinter::doInitialization(M);
// Emit the .machine directive on AIX.
- const Triple &Target = TM.getTargetTriple();
+ const Triple &Target = M.getTargetTriple();
XCOFF::CFileCpuId TargetCpuId = XCOFF::TCPU_INVALID;
// Walk through the "target-cpu" attribute of functions and use the newest
// level as the CPU of the module.
diff --git a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
index eccf36e9af184c..4b092194c3e38a 100644
--- a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -685,14 +685,14 @@ void RISCVAsmPrinter::emitStartOfAsmFile(Module &M) {
RTS.setFlagsFromFeatures(SubtargetInfo);
}
- if (TM.getTargetTriple().isOSBinFormatELF())
+ if (M.getTargetTriple().isOSBinFormatELF())
emitAttributes(SubtargetInfo);
}
void RISCVAsmPrinter::emitEndOfAsmFile(Module &M) {
RISCVTargetStreamer &RTS = getTargetStreamer();
- if (TM.getTargetTriple().isOSBinFormatELF()) {
+ if (M.getTargetTriple().isOSBinFormatELF()) {
RTS.finishAttributeSection();
emitNoteGnuProperty(M);
}
@@ -832,7 +832,7 @@ void RISCVAsmPrinter::EmitHwasanMemaccessSymbols(Module &M) {
if (HwasanMemaccessSymbols.empty())
return;
- assert(TM.getTargetTriple().isOSBinFormatELF());
+ assert(M.getTargetTriple().isOSBinFormatELF());
// Use MCSubtargetInfo from TargetMachine. Individual functions may have
// attributes that
diff er from other functions in the module and we have no
// way to know which function is correct.
@@ -1052,7 +1052,7 @@ void RISCVAsmPrinter::EmitHwasanMemaccessSymbols(Module &M) {
}
void RISCVAsmPrinter::emitNoteGnuProperty(const Module &M) {
- assert(TM.getTargetTriple().isOSBinFormatELF() && "invalid binary format");
+ assert(M.getTargetTriple().isOSBinFormatELF() && "invalid binary format");
uint32_t GnuProps = 0;
if (const Metadata *const Flag = M.getModuleFlag("cf-protection-return");
Flag && !mdconst::extract<ConstantInt>(Flag)->isZero())
diff --git a/llvm/lib/Target/SystemZ/SystemZXPLINKAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZXPLINKAsmPrinter.cpp
index 19cc3d6d5c3143..81bda7f0ed518a 100644
--- a/llvm/lib/Target/SystemZ/SystemZXPLINKAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZXPLINKAsmPrinter.cpp
@@ -807,7 +807,7 @@ void SystemZXPLINKAsmPrinter::emitPPA2(Module &M) {
void SystemZXPLINKAsmPrinter::emitGlobalAlias(const Module &M,
const GlobalAlias &GA) {
- if (!TM.getTargetTriple().isOSzOS())
+ if (!M.getTargetTriple().isOSzOS())
return AsmPrinter::emitGlobalAlias(M, GA);
// Aliased function labels have already been emitted for z/OS
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 20911e8d2a37c8..a126c093a54aab 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -200,9 +200,10 @@ void X86AsmPrinter::emitKCFITypeId(const MachineFunction &MF) {
EmitKCFITypePadding(MF);
unsigned DestReg = X86::EAX;
- if (F.getParent()->getModuleFlag("kcfi-arity")) {
+ const Module *M = F.getParent();
+ if (M->getModuleFlag("kcfi-arity")) {
// The ArityToRegMap assumes the 64-bit SysV ABI.
- [[maybe_unused]] const auto &Triple = MF.getTarget().getTargetTriple();
+ [[maybe_unused]] const auto &Triple = M->getTargetTriple();
assert(Triple.isX86_64() && !Triple.isOSWindows());
// Determine the function's arity (i.e., the number of arguments) at the ABI
@@ -920,7 +921,7 @@ bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
}
void X86AsmPrinter::emitStartOfAsmFile(Module &M) {
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
if (TT.isOSBinFormatELF()) {
// Assemble feature flags that may require creation of a note section.
@@ -1062,7 +1063,7 @@ static bool usesMSVCFloatingPoint(const Triple &TT, const Module &M) {
}
void X86AsmPrinter::emitEndOfAsmFile(Module &M) {
- const Triple &TT = TM.getTargetTriple();
+ const Triple &TT = M.getTargetTriple();
if (TT.isOSBinFormatMachO()) {
// Mach-O uses non-lazy symbol stubs to encode per-TU information into
More information about the llvm-commits
mailing list