[llvm] [NFC][IR] Use getDataLayout member function for Function and GlobalValue (PR #228964)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 19:40:56 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Ben Wu (benwu25)

<details>
<summary>Changes</summary>

Follow up on #<!-- -->96919- removes some uses of the old pattern.

---
Full diff: https://github.com/llvm/llvm-project/pull/228964.diff


13 Files Affected:

- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+1-2) 
- (modified) llvm/lib/CodeGen/ShadowStackGCLowering.cpp (+2-2) 
- (modified) llvm/lib/Target/AArch64/SVEShuffleOpts.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp (+1-2) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/FunctionAttrs.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/CopyProf.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp (+1-1) 


``````````diff
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 37de384df866f..e349a319d9459 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -2864,8 +2864,7 @@ void AsmPrinter::emitRemarksSection(remarks::RemarkStreamer &RS) {
 
 static uint64_t globalSize(const llvm::GlobalVariable &G) {
   const Constant *Initializer = G.getInitializer();
-  return G.getParent()->getDataLayout().getTypeAllocSize(
-      Initializer->getType());
+  return G.getDataLayout().getTypeAllocSize(Initializer->getType());
 }
 
 static bool shouldTagGlobal(const llvm::GlobalVariable &G) {
diff --git a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
index 993b18ce5bcc1..a6e9934bfe45d 100644
--- a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
+++ b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
@@ -193,7 +193,7 @@ ShadowStackGCLoweringImpl::ComputeFrameLayout(Function &F) {
   // Compute the layout of the shadow stack frame using byte offsets.
   // Layout: [Next ptr | Map ptr | Root 0 | Root 1 | ... | Root N]
 
-  const DataLayout &DL = F.getParent()->getDataLayout();
+  const DataLayout &DL = F.getDataLayout();
   uint64_t PtrSize = DL.getPointerSize(0);
   Align PtrAlign = DL.getPointerABIAlignment(0);
 
@@ -311,7 +311,7 @@ bool ShadowStackGCLoweringImpl::runOnFunction(Function &F,
     return false;
 
   LLVMContext &Context = F.getContext();
-  const DataLayout &DL = F.getParent()->getDataLayout();
+  const DataLayout &DL = F.getDataLayout();
 
   // Find calls to llvm.gcroot.
   CollectRoots(F);
diff --git a/llvm/lib/Target/AArch64/SVEShuffleOpts.cpp b/llvm/lib/Target/AArch64/SVEShuffleOpts.cpp
index 361eafc2960c7..a8eb814dfad87 100644
--- a/llvm/lib/Target/AArch64/SVEShuffleOpts.cpp
+++ b/llvm/lib/Target/AArch64/SVEShuffleOpts.cpp
@@ -253,7 +253,7 @@ struct SVEShuffleOpts : public LoopPass {
     const Function *F = L->getHeader()->getParent();
     const AArch64Subtarget &ST = *TM.getSubtargetImpl(*F);
 
-    return processLoop(*L, ST, F->getParent()->getDataLayout());
+    return processLoop(*L, ST, F->getDataLayout());
   }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -279,7 +279,7 @@ AArch64SVEShuffleOptsPass::run(Loop &L, LoopAnalysisManager &AM,
   const Function *F = L.getHeader()->getParent();
   const AArch64Subtarget &ST = *TM.getSubtargetImpl(*F);
 
-  if (processLoop(L, ST, F->getParent()->getDataLayout())) {
+  if (processLoop(L, ST, F->getDataLayout())) {
     PreservedAnalyses PA;
     PA.preserveSet<CFGAnalyses>();
     PA.preserve<TargetIRAnalysis>();
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
index 2ed1be7c2ade0..6f338455aeccc 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp
@@ -1188,7 +1188,7 @@ static unsigned inlineAsmGetNumRequiredAGPRs(const InlineAsm *IA,
   unsigned AGPRDefCount = 0;
   unsigned AGPRUseCount = 0;
   unsigned MaxPhysReg = 0;
-  const DataLayout &DL = Call.getFunction()->getParent()->getDataLayout();
+  const DataLayout &DL = Call.getFunction()->getDataLayout();
 
   // TODO: Overestimates due to not accounting for tied operands
   for (const InlineAsm::ConstraintInfo &CI : IA->ParseConstraints()) {
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
index f4c97bc992975..74135e6c6857d 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
@@ -457,8 +457,7 @@ bool AMDGPULibCalls::canIncreasePrecisionOfConstantFold(
 }
 
 AMDGPULibCalls::AMDGPULibCalls(Function &F, FunctionAnalysisManager &FAM)
-    : SQ(F.getParent()->getDataLayout(),
-         &FAM.getResult<TargetLibraryAnalysis>(F),
+    : SQ(F.getDataLayout(), &FAM.getResult<TargetLibraryAnalysis>(F),
          FAM.getCachedResult<DominatorTreeAnalysis>(F),
          &FAM.getResult<AssumptionAnalysis>(F)) {}
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
index f0d1f90ca5c2c..c5e9f0fc29bc1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
@@ -231,7 +231,7 @@ static bool lowerKernelArguments(Function &F, const TargetMachine &TM,
 
   uint64_t ExplicitArgOffset = 0;
 
-  addAliasScopeMetadata(F, F.getParent()->getDataLayout(), DT);
+  addAliasScopeMetadata(F, F.getDataLayout(), DT);
 
   for (Argument &Arg : F.args()) {
     const bool IsByRef = Arg.hasByRefAttr();
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp
index caad246b4ff7f..648140ef915c2 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPreloadKernelArguments.cpp
@@ -191,7 +191,7 @@ class PreloadKernelArgInfo {
     if (!ImplicitArgPtr)
       return;
 
-    const DataLayout &DL = F.getParent()->getDataLayout();
+    const DataLayout &DL = F.getDataLayout();
     // Pair is the load and the load offset.
     SmallVector<std::pair<LoadInst *, unsigned>, 4> ImplicitArgLoads;
     for (auto *U : ImplicitArgPtr->users()) {
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 4012992d3f1d6..2a2d4c5f91988 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -20946,7 +20946,7 @@ static bool isAtomicRMWLegalXChgTy(const AtomicRMWInst *RMW) {
     return true;
 
   if (PointerType *PT = dyn_cast<PointerType>(Ty)) {
-    const DataLayout &DL = RMW->getFunction()->getParent()->getDataLayout();
+    const DataLayout &DL = RMW->getFunction()->getDataLayout();
     unsigned BW = DL.getPointerSizeInBits(PT->getAddressSpace());
     return BW == 32 || BW == 64;
   }
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
index 07c3c2c9f4fbe..2df5dfb999236 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
@@ -67,7 +67,7 @@ void llvm::computeSignatureVTs(const FunctionType *Ty,
                                SmallVectorImpl<MVT> &Results) {
   computeLegalValueVTs(ContextFunc, TM, Ty->getReturnType(), Results);
 
-  const DataLayout &DL = ContextFunc.getParent()->getDataLayout();
+  const DataLayout &DL = ContextFunc.getDataLayout();
   MVT PtrVT = MVT::getIntegerVT(DL.getPointerSizeInBits());
   if (!WebAssembly::canLowerReturn(
           Results.size(),
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 8e8f9f8c12b5e..1441c660abbd2 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -761,7 +761,7 @@ ArgumentAccessInfo getArgumentAccessInfo(const Instruction *I,
 
 // Collect the uses of argument "A" in "F".
 ArgumentUsesSummary collectArgumentUsesPerBlock(Argument &A, Function &F) {
-  auto &DL = F.getParent()->getDataLayout();
+  auto &DL = F.getDataLayout();
   unsigned PointerSize =
       DL.getIndexSizeInBits(A.getType()->getPointerAddressSpace());
   ArgumentUsesSummary Result;
diff --git a/llvm/lib/Transforms/Instrumentation/CopyProf.cpp b/llvm/lib/Transforms/Instrumentation/CopyProf.cpp
index e95b0308b1340..e009eba8a86ba 100644
--- a/llvm/lib/Transforms/Instrumentation/CopyProf.cpp
+++ b/llvm/lib/Transforms/Instrumentation/CopyProf.cpp
@@ -271,7 +271,7 @@ bool CopyProfStores::instrumentFunction(Function &F) {
   // intrinsics, AtomicRMW, and AtomicCmpXchg).
   // TODO: Skip stores to alloca if only made of fundamental types, arrays
   // thereof and (possibly) class types that are trivial and aggregate.
-  const DataLayout &DL = F.getParent()->getDataLayout();
+  const DataLayout &DL = F.getDataLayout();
   SmallVector<StoreInst *, 16> ToInstrument;
   for (BasicBlock &BB : F) {
     for (Instruction &I : BB) {
diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index 492383b72c63b..85c37105c143b 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -2249,7 +2249,7 @@ std::pair<Value *, Value *> DFSanFunction::loadShadowFast(
       // chosen by combineOrigins() iff the least-significant half of the wide
       // shadow was empty but the other half was not).
       Value *WideShadowLo =
-          F->getParent()->getDataLayout().isLittleEndian()
+          F->getDataLayout().isLittleEndian()
               ? IRB.CreateShl(
                     WideShadow,
                     ConstantInt::get(WideShadowTy, WideShadowBitWidth / 2))
diff --git a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
index c6436617d69e6..f2a080704c826 100644
--- a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
@@ -593,7 +593,7 @@ bool TypeSanitizer::sanitizeFunction(Function &F,
     Res = true;
   }
 
-  const DataLayout &DL = F.getParent()->getDataLayout();
+  const DataLayout &DL = F.getDataLayout();
   bool SanitizeFunction = F.hasFnAttribute(Attribute::SanitizeType);
   bool NeedsInstrumentation =
       MemTypeResetInsts.empty() && MemoryAccesses.empty();

``````````

</details>


https://github.com/llvm/llvm-project/pull/228964


More information about the llvm-commits mailing list