[llvm] [IR] Add getDataLayout() helpers to Function and GlobalValue (PR #96919)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 27 08:35:35 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-compiler-rt-sanitizer
@llvm/pr-subscribers-coroutines
@llvm/pr-subscribers-llvm-globalisel
@llvm/pr-subscribers-llvm-binary-utilities
@llvm/pr-subscribers-backend-m68k

@llvm/pr-subscribers-backend-x86

Author: Nikita Popov (nikic)

<details>
<summary>Changes</summary>

Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.

---

Patch is 166.68 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/96919.diff


178 Files Affected:

- (modified) llvm/include/llvm/Analysis/ScalarEvolution.h (+1-1) 
- (modified) llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h (+1-1) 
- (modified) llvm/include/llvm/IR/Function.h (+6) 
- (modified) llvm/include/llvm/IR/GlobalValue.h (+6) 
- (modified) llvm/lib/Analysis/AliasAnalysisEvaluator.cpp (+1-1) 
- (modified) llvm/lib/Analysis/BasicAliasAnalysis.cpp (+2-2) 
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+4-4) 
- (modified) llvm/lib/Analysis/DependenceAnalysis.cpp (+2-2) 
- (modified) llvm/lib/Analysis/InlineCost.cpp (+2-2) 
- (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+2-2) 
- (modified) llvm/lib/Analysis/LazyValueInfo.cpp (+1-1) 
- (modified) llvm/lib/Analysis/Lint.cpp (+1-1) 
- (modified) llvm/lib/Analysis/MemDerefPrinter.cpp (+1-1) 
- (modified) llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp (+1-1) 
- (modified) llvm/lib/Analysis/StackLifetime.cpp (+1-1) 
- (modified) llvm/lib/Analysis/StackSafetyAnalysis.cpp (+2-2) 
- (modified) llvm/lib/Analysis/TargetTransformInfo.cpp (+1-1) 
- (modified) llvm/lib/Analysis/ValueTracking.cpp (+1-1) 
- (modified) llvm/lib/AsmParser/LLParser.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/Analysis.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (+11-11) 
- (modified) llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/AtomicExpandPass.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/BasicTargetTransformInfo.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/CodeGenPrepare.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/ExpandMemCmp.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/ExpandVectorPredication.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/GlobalISel/CallLowering.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/GlobalISel/LoadStoreOpt.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/HardwareLoops.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/IndirectBrExpandPass.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/MachineFunction.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/SafeStack.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp (+2-2) 
- (modified) llvm/lib/CodeGen/SjLjEHPrepare.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (+3-3) 
- (modified) llvm/lib/CodeGen/TypePromotion.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/WinEHPrepare.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/ExecutionEngine.cpp (+2-2) 
- (modified) llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp (+1-1) 
- (modified) llvm/lib/ExecutionEngine/Orc/Mangling.cpp (+1-1) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+2-2) 
- (modified) llvm/lib/IR/DebugInfo.cpp (+1-1) 
- (modified) llvm/lib/IR/Function.cpp (+4) 
- (modified) llvm/lib/IR/Globals.cpp (+4) 
- (modified) llvm/lib/IR/Mangler.cpp (+3-3) 
- (modified) llvm/lib/Linker/LinkModules.cpp (+1-1) 
- (modified) llvm/lib/Object/IRSymtab.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+3-3) 
- (modified) llvm/lib/Target/AArch64/AArch64StackTagging.cpp (+1-1) 
- (modified) llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp (+3-3) 
- (modified) llvm/lib/Target/AArch64/GISel/AArch64PreLegalizerCombiner.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAliasAnalysis.h (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUCallLowering.cpp (+5-5) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp (+3-3) 
- (modified) llvm/lib/Target/AMDGPU/R600TargetTransformInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/ARC/ARCTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (+6-6) 
- (modified) llvm/lib/Target/ARM/ARMTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/ARM/MVEGatherScatterLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/BPF/BPFTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/BPF/BTFDebug.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DirectXAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/Target/DirectX/DirectXTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/Hexagon/HexagonISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp (+2-2) 
- (modified) llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp (+1-1) 
- (modified) llvm/lib/Target/Lanai/LanaiTargetObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Target/Lanai/LanaiTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/LoongArch/LoongArchTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/M68k/GISel/M68kCallLowering.cpp (+3-3) 
- (modified) llvm/lib/Target/Mips/MipsTargetMachine.cpp (+1-1) 
- (modified) llvm/lib/Target/Mips/MipsTargetObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Target/Mips/MipsTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/NVPTX/NVVMReflect.cpp (+1-1) 
- (modified) llvm/lib/Target/PowerPC/GISel/PPCCallLowering.cpp (+2-2) 
- (modified) llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp (+7-7) 
- (modified) llvm/lib/Target/PowerPC/PPCISelLowering.cpp (+4-4) 
- (modified) llvm/lib/Target/PowerPC/PPCInstrInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVCodeGenPrepare.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVTargetObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp (+2-2) 
- (modified) llvm/lib/Target/SPIRV/SPIRVTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/SystemZ/SystemZISelDAGToDAG.cpp (+1-1) 
- (modified) llvm/lib/Target/SystemZ/SystemZSubtarget.cpp (+1-1) 
- (modified) llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/TargetLoweringObjectFile.cpp (+3-3) 
- (modified) llvm/lib/Target/TargetMachine.cpp (+2-2) 
- (modified) llvm/lib/Target/VE/VETargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp (+1-1) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/X86/GISel/X86CallLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/X86PartialReduction.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/X86TargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Target/XCore/XCoreISelLowering.cpp (+1-1) 
- (modified) llvm/lib/Target/XCore/XCoreTargetObjectFile.cpp (+1-1) 
- (modified) llvm/lib/Target/XCore/XCoreTargetTransformInfo.h (+1-1) 
- (modified) llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Coroutines/CoroElide.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Coroutines/CoroFrame.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Coroutines/CoroSplit.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/ArgumentPromotion.cpp (+3-3) 
- (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/ConstantMerge.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/FunctionAttrs.cpp (+2-2) 
- (modified) llvm/lib/Transforms/IPO/GlobalOpt.cpp (+5-5) 
- (modified) llvm/lib/Transforms/IPO/GlobalSplit.cpp (+1-1) 
- (modified) llvm/lib/Transforms/IPO/PartialInlining.cpp (+2-2) 
- (modified) llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp (+1-1) 
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+5-5) 
- (modified) llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (+4-4) 
- (modified) llvm/lib/Transforms/Instrumentation/MemProfiler.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+17-17) 
- (modified) llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/AnnotationRemarks.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/ConstantHoisting.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/ConstraintElimination.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/EarlyCSE.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/Float2Int.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/GVN.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/IndVarSimplify.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/InferAlignment.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/InstSimplifyPass.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/JumpTableToSwitch.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/LoopFlatten.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/LoopFuse.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/NaryReassociate.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/NewGVN.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/SCCP.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/SROA.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/StructurizeCFG.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Utils/CallPromotionUtils.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/CloneFunction.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/DemoteRegToStack.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/FunctionComparator.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Utils/InlineFunction.cpp (+5-5) 
- (modified) llvm/lib/Transforms/Utils/LoopConstrainer.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp (+4-4) 
- (modified) llvm/lib/Transforms/Utils/LowerSwitch.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+3-3) 
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+1-1) 
- (modified) llvm/lib/Transforms/Vectorize/VectorCombine.cpp (+1-1) 
- (modified) llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp (+1-1) 


``````````diff
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index 250848295cd36..88c085533eb86 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1266,7 +1266,7 @@ class ScalarEvolution {
   /// Return the DataLayout associated with the module this SCEV instance is
   /// operating on.
   const DataLayout &getDataLayout() const {
-    return F.getParent()->getDataLayout();
+    return F.getDataLayout();
   }
 
   const SCEVPredicate *getEqualPredicate(const SCEV *LHS, const SCEV *RHS);
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
index a95ed3109feb8..588d1235d12b1 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
@@ -284,7 +284,7 @@ class MachineIRBuilder {
   }
 
   const DataLayout &getDataLayout() const {
-    return getMF().getFunction().getParent()->getDataLayout();
+    return getMF().getFunction().getDataLayout();
   }
 
   LLVMContext &getContext() const {
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index 6bd997b7ac75a..fd7a6aa46eea0 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -47,6 +47,7 @@ typedef unsigned ID;
 class AssemblyAnnotationWriter;
 class Constant;
 class ConstantRange;
+class DataLayout;
 struct DenormalMode;
 class DISubprogram;
 enum LibFunc : unsigned;
@@ -214,6 +215,11 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
   /// function.
   LLVMContext &getContext() const;
 
+  /// Get the data layout of the module this function belongs to.
+  ///
+  /// Requires the function to have a parent module.
+  const DataLayout &getDataLayout() const;
+
   /// isVarArg - Return true if this function takes a variable number of
   /// arguments.
   bool isVarArg() const { return getFunctionType()->isVarArg(); }
diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h
index b1262b27f0221..540a21c1118b8 100644
--- a/llvm/include/llvm/IR/GlobalValue.h
+++ b/llvm/include/llvm/IR/GlobalValue.h
@@ -32,6 +32,7 @@ namespace llvm {
 
 class Comdat;
 class ConstantRange;
+class DataLayout;
 class Error;
 class GlobalObject;
 class Module;
@@ -655,6 +656,11 @@ class GlobalValue : public Constant {
   Module *getParent() { return Parent; }
   const Module *getParent() const { return Parent; }
 
+  /// Get the data layout of the module this global belongs to.
+  ///
+  /// Requires the global to have a parent module.
+  const DataLayout &getDataLayout() const;
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static bool classof(const Value *V) {
     return V->getValueID() == Value::FunctionVal ||
diff --git a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp
index f4b4d8888a547..59801642c9221 100644
--- a/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp
+++ b/llvm/lib/Analysis/AliasAnalysisEvaluator.cpp
@@ -99,7 +99,7 @@ PreservedAnalyses AAEvaluator::run(Function &F, FunctionAnalysisManager &AM) {
 }
 
 void AAEvaluator::runInternal(Function &F, AAResults &AA) {
-  const DataLayout &DL = F.getParent()->getDataLayout();
+  const DataLayout &DL = F.getDataLayout();
 
   ++FunctionCount;
 
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index c110943ad0d58..161a3034e4829 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1919,7 +1919,7 @@ BasicAAResult BasicAA::run(Function &F, FunctionAnalysisManager &AM) {
   auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
   auto &AC = AM.getResult<AssumptionAnalysis>(F);
   auto *DT = &AM.getResult<DominatorTreeAnalysis>(F);
-  return BasicAAResult(F.getParent()->getDataLayout(), F, TLI, AC, DT);
+  return BasicAAResult(F.getDataLayout(), F, TLI, AC, DT);
 }
 
 BasicAAWrapperPass::BasicAAWrapperPass() : FunctionPass(ID) {
@@ -1947,7 +1947,7 @@ bool BasicAAWrapperPass::runOnFunction(Function &F) {
   auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>();
   auto &DTWP = getAnalysis<DominatorTreeWrapperPass>();
 
-  Result.reset(new BasicAAResult(F.getParent()->getDataLayout(), F,
+  Result.reset(new BasicAAResult(F.getDataLayout(), F,
                                  TLIWP.getTLI(F), ACT.getAssumptionCache(F),
                                  &DTWP.getDomTree()));
 
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 9a5c0f442de42..962880f68f076 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -644,7 +644,7 @@ Constant *llvm::ReadByteArrayFromGlobal(const GlobalVariable *GV,
   if (!GV->isConstant() || !GV->hasDefinitiveInitializer())
     return nullptr;
 
-  const DataLayout &DL = GV->getParent()->getDataLayout();
+  const DataLayout &DL = GV->getDataLayout();
   Constant *Init = const_cast<Constant *>(GV->getInitializer());
   TypeSize InitSize = DL.getTypeAllocSize(Init->getType());
   if (InitSize < Offset)
@@ -3485,15 +3485,15 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F,
   StringRef Name = F->getName();
   if (auto *FVTy = dyn_cast<FixedVectorType>(Ty))
     return ConstantFoldFixedVectorCall(
-        Name, IID, FVTy, Operands, F->getParent()->getDataLayout(), TLI, Call);
+        Name, IID, FVTy, Operands, F->getDataLayout(), TLI, Call);
 
   if (auto *SVTy = dyn_cast<ScalableVectorType>(Ty))
     return ConstantFoldScalableVectorCall(
-        Name, IID, SVTy, Operands, F->getParent()->getDataLayout(), TLI, Call);
+        Name, IID, SVTy, Operands, F->getDataLayout(), TLI, Call);
 
   if (auto *StTy = dyn_cast<StructType>(Ty))
     return ConstantFoldStructCall(Name, IID, StTy, Operands,
-                                  F->getParent()->getDataLayout(), TLI, Call);
+                                  F->getDataLayout(), TLI, Call);
 
   // TODO: If this is a library function, we already discovered that above,
   //       so we should pass the LibFunc, not the name (and it might be better
diff --git a/llvm/lib/Analysis/DependenceAnalysis.cpp b/llvm/lib/Analysis/DependenceAnalysis.cpp
index e0e7dd18cd8d4..8e44d548cb56f 100644
--- a/llvm/lib/Analysis/DependenceAnalysis.cpp
+++ b/llvm/lib/Analysis/DependenceAnalysis.cpp
@@ -3607,7 +3607,7 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
   Value *SrcPtr = getLoadStorePointerOperand(Src);
   Value *DstPtr = getLoadStorePointerOperand(Dst);
 
-  switch (underlyingObjectsAlias(AA, F->getParent()->getDataLayout(),
+  switch (underlyingObjectsAlias(AA, F->getDataLayout(),
                                  MemoryLocation::get(Dst),
                                  MemoryLocation::get(Src))) {
   case AliasResult::MayAlias:
@@ -4034,7 +4034,7 @@ const SCEV *DependenceInfo::getSplitIteration(const Dependence &Dep,
   Value *SrcPtr = getLoadStorePointerOperand(Src);
   Value *DstPtr = getLoadStorePointerOperand(Dst);
   assert(underlyingObjectsAlias(
-             AA, F->getParent()->getDataLayout(), MemoryLocation::get(Dst),
+             AA, F->getDataLayout(), MemoryLocation::get(Dst),
              MemoryLocation::get(Src)) == AliasResult::MustAlias);
 
   // establish loop nesting levels
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index f5b17dca49735..94aa8ecf6f558 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -498,7 +498,7 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
                ProfileSummaryInfo *PSI = nullptr,
                OptimizationRemarkEmitter *ORE = nullptr)
       : TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
-        PSI(PSI), F(Callee), DL(F.getParent()->getDataLayout()), ORE(ORE),
+        PSI(PSI), F(Callee), DL(F.getDataLayout()), ORE(ORE),
         CandidateCall(Call) {}
 
   InlineResult analyze();
@@ -2999,7 +2999,7 @@ std::optional<InlineResult> llvm::getAttributeBasedInliningDecision(
   // alloca, the inlined code would need to be adjusted to handle that the
   // argument is in the alloca address space (so it is a little bit complicated
   // to solve).
-  unsigned AllocaAS = Callee->getParent()->getDataLayout().getAllocaAddrSpace();
+  unsigned AllocaAS = Callee->getDataLayout().getAllocaAddrSpace();
   for (unsigned I = 0, E = Call.arg_size(); I != E; ++I)
     if (Call.isByValArgument(I)) {
       PointerType *PTy = cast<PointerType>(Call.getArgOperand(I)->getType());
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 2081f8b70ddb7..cdcc40c596b77 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -7248,7 +7248,7 @@ const SimplifyQuery getBestSimplifyQuery(Pass &P, Function &F) {
   auto *TLI = TLIWP ? &TLIWP->getTLI(F) : nullptr;
   auto *ACWP = P.getAnalysisIfAvailable<AssumptionCacheTracker>();
   auto *AC = ACWP ? &ACWP->getAssumptionCache(F) : nullptr;
-  return {F.getParent()->getDataLayout(), TLI, DT, AC};
+  return {F.getDataLayout(), TLI, DT, AC};
 }
 
 const SimplifyQuery getBestSimplifyQuery(LoopStandardAnalysisResults &AR,
@@ -7262,7 +7262,7 @@ const SimplifyQuery getBestSimplifyQuery(AnalysisManager<T, TArgs...> &AM,
   auto *DT = AM.template getCachedResult<DominatorTreeAnalysis>(F);
   auto *TLI = AM.template getCachedResult<TargetLibraryAnalysis>(F);
   auto *AC = AM.template getCachedResult<AssumptionAnalysis>(F);
-  return {F.getParent()->getDataLayout(), TLI, DT, AC};
+  return {F.getDataLayout(), TLI, DT, AC};
 }
 template const SimplifyQuery getBestSimplifyQuery(AnalysisManager<Function> &,
                                                   Function &);
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index 3597f8f08e770..ef4d14dbe6045 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1689,7 +1689,7 @@ LazyValueInfo LazyValueAnalysis::run(Function &F,
                                      FunctionAnalysisManager &FAM) {
   auto &AC = FAM.getResult<AssumptionAnalysis>(F);
 
-  return LazyValueInfo(&AC, &F.getParent()->getDataLayout());
+  return LazyValueInfo(&AC, &F.getDataLayout());
 }
 
 /// Returns true if we can statically tell that this value will never be a
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp
index df1b22d48ca7a..496308a0c247a 100644
--- a/llvm/lib/Analysis/Lint.cpp
+++ b/llvm/lib/Analysis/Lint.cpp
@@ -709,7 +709,7 @@ Value *Lint::findValueImpl(Value *V, bool OffsetOk,
 
 PreservedAnalyses LintPass::run(Function &F, FunctionAnalysisManager &AM) {
   auto *Mod = F.getParent();
-  auto *DL = &F.getParent()->getDataLayout();
+  auto *DL = &F.getDataLayout();
   auto *AA = &AM.getResult<AAManager>(F);
   auto *AC = &AM.getResult<AssumptionAnalysis>(F);
   auto *DT = &AM.getResult<DominatorTreeAnalysis>(F);
diff --git a/llvm/lib/Analysis/MemDerefPrinter.cpp b/llvm/lib/Analysis/MemDerefPrinter.cpp
index 2632bc50d6e69..e858d94143544 100644
--- a/llvm/lib/Analysis/MemDerefPrinter.cpp
+++ b/llvm/lib/Analysis/MemDerefPrinter.cpp
@@ -26,7 +26,7 @@ PreservedAnalyses MemDerefPrinterPass::run(Function &F,
   SmallVector<Value *, 4> Deref;
   SmallPtrSet<Value *, 4> DerefAndAligned;
 
-  const DataLayout &DL = F.getParent()->getDataLayout();
+  const DataLayout &DL = F.getDataLayout();
   for (auto &I : instructions(F)) {
     if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
       Value *PO = LI->getPointerOperand();
diff --git a/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp b/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
index ca87bc3c78bed..458ccc108a083 100644
--- a/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/ObjCARCAliasAnalysis.cpp
@@ -142,5 +142,5 @@ ModRefInfo ObjCARCAAResult::getModRefInfo(const CallBase *Call,
 AnalysisKey ObjCARCAA::Key;
 
 ObjCARCAAResult ObjCARCAA::run(Function &F, FunctionAnalysisManager &AM) {
-  return ObjCARCAAResult(F.getParent()->getDataLayout());
+  return ObjCARCAAResult(F.getDataLayout());
 }
diff --git a/llvm/lib/Analysis/StackLifetime.cpp b/llvm/lib/Analysis/StackLifetime.cpp
index 3e1b5dea6f6c2..21f54c7cbc849 100644
--- a/llvm/lib/Analysis/StackLifetime.cpp
+++ b/llvm/lib/Analysis/StackLifetime.cpp
@@ -87,7 +87,7 @@ void StackLifetime::collectMarkers() {
   DenseMap<const BasicBlock *, SmallDenseMap<const IntrinsicInst *, Marker>>
       BBMarkerSet;
 
-  const DataLayout &DL = F.getParent()->getDataLayout();
+  const DataLayout &DL = F.getDataLayout();
 
   // Compute the set of start/end markers per basic block.
   for (const BasicBlock *BB : depth_first(&F)) {
diff --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
index c700d80e0d453..27360d0e84cb2 100644
--- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -268,7 +268,7 @@ class StackSafetyLocalAnalysis {
 
 public:
   StackSafetyLocalAnalysis(Function &F, ScalarEvolution &SE)
-      : F(F), DL(F.getParent()->getDataLayout()), SE(SE),
+      : F(F), DL(F.getDataLayout()), SE(SE),
         PointerSize(DL.getPointerSizeInBits()),
         UnknownRange(PointerSize, true) {}
 
@@ -852,7 +852,7 @@ GVToSSI createGlobalStackSafetyInfo(
     }
 
   uint32_t PointerSize =
-      Copy.begin()->first->getParent()->getDataLayout().getPointerSizeInBits();
+      Copy.begin()->first->getDataLayout().getPointerSizeInBits();
   StackSafetyDataFlowAnalysis<GlobalValue> SSDFA(PointerSize, std::move(Copy));
 
   for (const auto &F : SSDFA.run()) {
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 5e30d907d18bb..c175d1737e54b 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -1354,7 +1354,7 @@ TargetIRAnalysis::Result TargetIRAnalysis::run(const Function &F,
 AnalysisKey TargetIRAnalysis::Key;
 
 TargetIRAnalysis::Result TargetIRAnalysis::getDefaultTTI(const Function &F) {
-  return Result(F.getParent()->getDataLayout());
+  return Result(F.getDataLayout());
 }
 
 // Register the basic pass.
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d0d9caaec5e36..32ebb320d8edb 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6111,7 +6111,7 @@ bool llvm::getConstantDataArrayInfo(const Value *V,
     // Fail if V is not based on constant global object.
     return false;
 
-  const DataLayout &DL = GV->getParent()->getDataLayout();
+  const DataLayout &DL = GV->getDataLayout();
   APInt Off(DL.getIndexTypeSizeInBits(V->getType()), 0);
 
   if (GV != V->stripAndAccumulateConstantOffsets(DL, Off,
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 21d386097fc63..059d42d9faa7f 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -8282,7 +8282,7 @@ int LLParser::parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS) {
     return error(NewLoc, "cmpxchg operand must be a first class value");
 
   const Align DefaultAlignment(
-      PFS.getFunction().getParent()->getDataLayout().getTypeStoreSize(
+      PFS.getFunction().getDataLayout().getTypeStoreSize(
           Cmp->getType()));
 
   AtomicCmpXchgInst *CXI =
@@ -8388,13 +8388,13 @@ int LLParser::parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS) {
   }
 
   unsigned Size =
-      PFS.getFunction().getParent()->getDataLayout().getTypeStoreSizeInBits(
+      PFS.getFunction().getDataLayout().getTypeStoreSizeInBits(
           Val->getType());
   if (Size < 8 || (Size & (Size - 1)))
     return error(ValLoc, "atomicrmw operand must be power-of-two byte-sized"
                          " integer");
   const Align DefaultAlignment(
-      PFS.getFunction().getParent()->getDataLayout().getTypeStoreSize(
+      PFS.getFunction().getDataLayout().getTypeStoreSize(
           Val->getType()));
   AtomicRMWInst *RMWI =
       new AtomicRMWInst(Operation, Ptr, Val,
diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
index e693cdbd0ccc1..7fc18639e5852 100644
--- a/llvm/lib/CodeGen/Analysis.cpp
+++ b/llvm/lib/CodeGen/Analysis.cpp
@@ -730,7 +730,7 @@ bool llvm::returnTypeIsEligibleForTailCall(const Function *F,
     // index is compatible with the value we return.
     if (!slotOnlyDiscardsData(RetVal, CallVal, TmpRetPath, TmpCallPath,
                               AllowDifferingSizes, TLI,
-                              F->getParent()->getDataLayout()))
+                              F->getDataLayout()))
       return false;
 
     CallEmpty  = !nextRealType(CallSubTypes, CallPath);
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 40f4dc2689cdf..609516f4bde95 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -783,7 +783,7 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
 
   SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
 
-  const DataLayout &DL = GV->getParent()->getDataLayout();
+  const DataLayout &DL = GV->getDataLayout();
   uint64_t Size = DL.getTypeAllocSize(GV->getValueType());
 
   // If the alignment is specified, we *must* obey it.  Overaligning a global
@@ -871,7 +871,7 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
       emitAlignment(Alignment, GV);
       OutStreamer->emitLabel(MangSym);
 
-      emitGlobalConstant(GV->getParent()->getDataLayout(),
+      emitGlobalConstant(GV->getDataLayout(),
                          GV->getInitializer());
     }
 
@@ -911,7 +911,7 @@ void AsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
   if (LocalAlias != EmittedInitSym)
     OutStreamer->emitLabel(LocalAlias);
 
-  emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer());
+  emitGlobalConstant(GV->getDataLayout(), GV->getInitializer());
 
   if (MAI->hasDotTypeDotSizeDirective())
     // .size foo, 42
@@ -935,7 +935,7 @@ void AsmPrinter::emitFunctionPrefix(ArrayRef<const Constant *> Prefix) {
   const Function &F = MF->getFunction();
   if (!MAI->hasSubsectionsViaSymbols()) {
     for (auto &C : Prefix)
-      emitGlobalConstant(F.getParent()->getDataLayout(), C);
+      emitGlobalConstant(F.getDataLayout(), C);
     return;
   }
   // Preserving prefix-like data on platforms which use subsections-via-symbols
@@ -945,7 +945,7 @@ void AsmPrinter::emitFunctionPrefix(ArrayRef<const Constant *> Prefix) {
   OutStreamer->emitLabel(OutContext.createLinkerPrivateTempSymbol());
 
   for (auto &C : Prefix) {
-    emitGlobalConstant(F.getParent()->getDataLayout(), C);
+    emitGlobalConstant(F.getDataLayout(), C);
   }
 
   // Emit an .alt_entry directive for the actual function symbol.
@@ -1080,7 +1080,7 @@ void AsmPrinter::emitFunctionHeader() {
 
   // Emit the prologue data.
   if (F.hasPrologueData())
-    emitGlobalConstant(F.getParent()->getDataLayout(), F.getPrologueData());
+    emitGlobalConstant(F.getDataLayout(), F.getPrologueData());
 }
 
 /// EmitFunctionEntryLabel - Emit the label that is the entrypoint for the
@@ -1527,7 +1527,7 @@ void AsmPrinter::emitKCFITrapEntry(const MachineFunction &MF,
 void AsmPrinter::emitKCFITypeId(const MachineFunction &MF) {
   const Function &F = MF.getFunction();
   if (const MDNode *MD = F.getMetadata(LLVMContext::MD_kcfi_type))
-    emitGlobalConstant(F.getParent()->getDataLayout(),
+    emitGlobalConstant(F.getDataLayout(),
                        mdconst::extract<ConstantInt>(MD->getOperand(0)));
 }
 
@@ -1677,7 +1677,7 @@ void AsmPrinter::emitPCSections(const MachineFunction &MF) {
         for (const MDOperand &AuxMDO : AuxMDs->operands()) {
           assert(isa<ConstantAsMetadata>(AuxMDO) && "expecting a constant");
           const Constant *C = cast<ConstantAsMetadata>(AuxMDO)->getValue();
-          const DataLayout &DL = F.getParent()->getDataLayout();
+          const DataLayout &DL = F.getDataLayout();
           const uint64_t Size = DL.getTypeStoreSize(C->getType());
 
           if (auto *CI = dyn_cast<ConstantInt>(C);
@@ -2925,14 +2925,14 @@ bool AsmPrinter::emitSpecialLLVMGlobal(const GlobalVariable *GV) {
   assert(GV->hasInitializer() && "Not a special LLVM gl...
[truncated]

``````````

</details>


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


More information about the llvm-commits mailing list