[llvm] CodeGen: Prefer getting the Triple from the Module (PR #228620)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 3 01:49:51 PDT 2026
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/228620
>From f71f2b8b492998c86cf4ce4bcf6a61429e2fa655 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sat, 3 Oct 2026 01:18:21 +0200
Subject: [PATCH] CodeGen: Prefer getting the Triple from the Module
Take the triple from the contextual module rather than TargetMachine
when it's already readily available.
Co-authored-by: Claude Opus 5 <noreply at anthropic.com>
---
llvm/lib/CodeGen/Analysis.cpp | 2 +-
llvm/lib/CodeGen/TargetLoweringBase.cpp | 8 ++++----
llvm/lib/LTO/LTOBackend.cpp | 2 +-
llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 2 +-
.../Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp | 2 +-
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 4 ++--
llvm/lib/Target/X86/X86ISelLowering.cpp | 2 +-
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
index 78cf31cff0ea03..bc52b094af89d8 100644
--- a/llvm/lib/CodeGen/Analysis.cpp
+++ b/llvm/lib/CodeGen/Analysis.cpp
@@ -604,7 +604,7 @@ bool llvm::canDescribeGlobalAddressInDebugInfo(const GlobalValue *GV,
// those addends for global variables, but they need a relocation, which a
// location list cannot carry, so a local pointing at such a global has to
// keep being described by whatever register holds the computed address.
- if (TM.getTargetTriple().isWasm() && TM.getRelocationModel() == Reloc::PIC_)
+ if (M.getTargetTriple().isWasm() && TM.getRelocationModel() == Reloc::PIC_)
return false;
if (TM.getRelocationModel() == Reloc::RWPI ||
TM.getRelocationModel() == Reloc::ROPI_RWPI) {
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 1217c0d80a5dbd..1c7bca06b225ac 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -2221,10 +2221,10 @@ void TargetLoweringBase::insertSSPDeclarations(
// FreeBSD has "__stack_chk_guard" defined externally on libc.so
if (M.getDirectAccessExternalData() &&
- !TM.getTargetTriple().isOSCygMing() &&
- !(TM.getTargetTriple().isPPC64() &&
- TM.getTargetTriple().isOSFreeBSD()) &&
- (!TM.getTargetTriple().isOSDarwin() ||
+ !M.getTargetTriple().isOSCygMing() &&
+ !(M.getTargetTriple().isPPC64() &&
+ M.getTargetTriple().isOSFreeBSD()) &&
+ (!M.getTargetTriple().isOSDarwin() ||
TM.getRelocationModel() == Reloc::Static))
GV->setDSOLocal(true);
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 0d253647ae46c8..1136d50e056559 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -715,7 +715,7 @@ Error lto::thinBackend(const Config &Conf, unsigned Task, AddStreamFn AddStream,
// When linking an ELF shared object, dso_local should be dropped. We
// conservatively do this for -fpic.
bool ClearDSOLocalOnDeclarations =
- TM->getTargetTriple().isOSBinFormatELF() &&
+ Mod.getTargetTriple().isOSBinFormatELF() &&
TM->getRelocationModel() != Reloc::Static &&
Mod.getPIELevel() == PIELevel::Default;
renameModuleForThinLTO(Mod, CombinedIndex, ClearDSOLocalOnDeclarations);
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
index 78b4208bb796a7..710594d360df37 100644
--- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp
@@ -463,7 +463,7 @@ ProcessThinLTOModule(Module &TheModule, ModuleSummaryIndex &Index,
// When linking an ELF shared object, dso_local should be dropped. We
// conservatively do this for -fpic.
bool ClearDSOLocalOnDeclarations =
- TM.getTargetTriple().isOSBinFormatELF() &&
+ TheModule.getTargetTriple().isOSBinFormatELF() &&
TM.getRelocationModel() != Reloc::Static &&
TheModule.getPIELevel() == PIELevel::Default;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp b/llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp
index 32f81623c01171..64258e5811e4a3 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp
@@ -39,7 +39,7 @@ class AMDGPURemoveIncompatibleFunctions {
bool checkFunction(Function &F);
bool run(Module &M) {
- assert(TM->getTargetTriple().isAMDGCN());
+ assert(M.getTargetTriple().isAMDGCN());
SmallVector<Function *, 4> FnsToDelete;
for (Function &F : M) {
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 937631c276cfeb..987ec7bedaa1f4 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -2666,11 +2666,11 @@ Instruction *SPIRVEmitIntrinsicsImpl::visitAtomicRMWInst(AtomicRMWInst &I) {
unsigned AS = I.getPointerOperand()->getType()->getPointerAddressSpace();
uint32_t Scope = static_cast<uint32_t>(
- getMemScope(TM.getTargetTriple(), I.getContext(), I.getSyncScopeID()));
+ getMemScope(M->getTargetTriple(), I.getContext(), I.getSyncScopeID()));
uint32_t ScSem = static_cast<uint32_t>(
getMemSemanticsForStorageClass(addressSpaceToStorageClass(AS, ST)));
uint32_t MemSem = getMemSemanticsWithStorageClass(
- TM.getTargetTriple(),
+ M->getTargetTriple(),
static_cast<uint32_t>(getMemSemantics(I.getOrdering())), ScSem);
SmallString<64> FuncName(Op == AtomicRMWInst::UIncWrap
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index a84d017d9c6cd7..ccd53f8aaaffed 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -64315,7 +64315,7 @@ SDValue X86TargetLowering::expandIndirectJTBranch(const SDLoc &dl,
// Upon ISEL, the pattern will convert it to jmp with NoTrack prefix.
SDValue Chain = Value;
// Jump table debug info is only needed if CodeView is enabled.
- if (DAG.getTarget().getTargetTriple().isOSBinFormatCOFF())
+ if (M->getTargetTriple().isOSBinFormatCOFF())
Chain = DAG.getJumpTableDebugInfo(JTI, Chain, dl);
return DAG.getNode(X86ISD::NT_BRIND, dl, MVT::Other, Chain, Addr);
}
More information about the llvm-commits
mailing list