Skip to content

Commit 9df71d7

Browse files
authored
[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)
Similar to #96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
1 parent 519e0bb commit 9df71d7

File tree

178 files changed

+313
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+313
-293
lines changed

llvm/include/llvm/Analysis/ScalarEvolution.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ class ScalarEvolution {
12661266
/// Return the DataLayout associated with the module this SCEV instance is
12671267
/// operating on.
12681268
const DataLayout &getDataLayout() const {
1269-
return F.getParent()->getDataLayout();
1269+
return F.getDataLayout();
12701270
}
12711271

12721272
const SCEVPredicate *getEqualPredicate(const SCEV *LHS, const SCEV *RHS);

llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class MachineIRBuilder {
284284
}
285285

286286
const DataLayout &getDataLayout() const {
287-
return getMF().getFunction().getParent()->getDataLayout();
287+
return getMF().getFunction().getDataLayout();
288288
}
289289

290290
LLVMContext &getContext() const {

llvm/include/llvm/IR/Function.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ typedef unsigned ID;
4747
class AssemblyAnnotationWriter;
4848
class Constant;
4949
class ConstantRange;
50+
class DataLayout;
5051
struct DenormalMode;
5152
class DISubprogram;
5253
enum LibFunc : unsigned;
@@ -214,6 +215,11 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
214215
/// function.
215216
LLVMContext &getContext() const;
216217

218+
/// Get the data layout of the module this function belongs to.
219+
///
220+
/// Requires the function to have a parent module.
221+
const DataLayout &getDataLayout() const;
222+
217223
/// isVarArg - Return true if this function takes a variable number of
218224
/// arguments.
219225
bool isVarArg() const { return getFunctionType()->isVarArg(); }

llvm/include/llvm/IR/GlobalValue.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace llvm {
3232

3333
class Comdat;
3434
class ConstantRange;
35+
class DataLayout;
3536
class Error;
3637
class GlobalObject;
3738
class Module;
@@ -655,6 +656,11 @@ class GlobalValue : public Constant {
655656
Module *getParent() { return Parent; }
656657
const Module *getParent() const { return Parent; }
657658

659+
/// Get the data layout of the module this global belongs to.
660+
///
661+
/// Requires the global to have a parent module.
662+
const DataLayout &getDataLayout() const;
663+
658664
// Methods for support type inquiry through isa, cast, and dyn_cast:
659665
static bool classof(const Value *V) {
660666
return V->getValueID() == Value::FunctionVal ||

llvm/lib/Analysis/AliasAnalysisEvaluator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ PreservedAnalyses AAEvaluator::run(Function &F, FunctionAnalysisManager &AM) {
9999
}
100100

101101
void AAEvaluator::runInternal(Function &F, AAResults &AA) {
102-
const DataLayout &DL = F.getParent()->getDataLayout();
102+
const DataLayout &DL = F.getDataLayout();
103103

104104
++FunctionCount;
105105

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ BasicAAResult BasicAA::run(Function &F, FunctionAnalysisManager &AM) {
19191919
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
19201920
auto &AC = AM.getResult<AssumptionAnalysis>(F);
19211921
auto *DT = &AM.getResult<DominatorTreeAnalysis>(F);
1922-
return BasicAAResult(F.getParent()->getDataLayout(), F, TLI, AC, DT);
1922+
return BasicAAResult(F.getDataLayout(), F, TLI, AC, DT);
19231923
}
19241924

19251925
BasicAAWrapperPass::BasicAAWrapperPass() : FunctionPass(ID) {
@@ -1947,7 +1947,7 @@ bool BasicAAWrapperPass::runOnFunction(Function &F) {
19471947
auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>();
19481948
auto &DTWP = getAnalysis<DominatorTreeWrapperPass>();
19491949

1950-
Result.reset(new BasicAAResult(F.getParent()->getDataLayout(), F,
1950+
Result.reset(new BasicAAResult(F.getDataLayout(), F,
19511951
TLIWP.getTLI(F), ACT.getAssumptionCache(F),
19521952
&DTWP.getDomTree()));
19531953

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ Constant *llvm::ReadByteArrayFromGlobal(const GlobalVariable *GV,
644644
if (!GV->isConstant() || !GV->hasDefinitiveInitializer())
645645
return nullptr;
646646

647-
const DataLayout &DL = GV->getParent()->getDataLayout();
647+
const DataLayout &DL = GV->getDataLayout();
648648
Constant *Init = const_cast<Constant *>(GV->getInitializer());
649649
TypeSize InitSize = DL.getTypeAllocSize(Init->getType());
650650
if (InitSize < Offset)
@@ -3485,15 +3485,15 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F,
34853485
StringRef Name = F->getName();
34863486
if (auto *FVTy = dyn_cast<FixedVectorType>(Ty))
34873487
return ConstantFoldFixedVectorCall(
3488-
Name, IID, FVTy, Operands, F->getParent()->getDataLayout(), TLI, Call);
3488+
Name, IID, FVTy, Operands, F->getDataLayout(), TLI, Call);
34893489

34903490
if (auto *SVTy = dyn_cast<ScalableVectorType>(Ty))
34913491
return ConstantFoldScalableVectorCall(
3492-
Name, IID, SVTy, Operands, F->getParent()->getDataLayout(), TLI, Call);
3492+
Name, IID, SVTy, Operands, F->getDataLayout(), TLI, Call);
34933493

34943494
if (auto *StTy = dyn_cast<StructType>(Ty))
34953495
return ConstantFoldStructCall(Name, IID, StTy, Operands,
3496-
F->getParent()->getDataLayout(), TLI, Call);
3496+
F->getDataLayout(), TLI, Call);
34973497

34983498
// TODO: If this is a library function, we already discovered that above,
34993499
// so we should pass the LibFunc, not the name (and it might be better

llvm/lib/Analysis/DependenceAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,7 +3607,7 @@ DependenceInfo::depends(Instruction *Src, Instruction *Dst,
36073607
Value *SrcPtr = getLoadStorePointerOperand(Src);
36083608
Value *DstPtr = getLoadStorePointerOperand(Dst);
36093609

3610-
switch (underlyingObjectsAlias(AA, F->getParent()->getDataLayout(),
3610+
switch (underlyingObjectsAlias(AA, F->getDataLayout(),
36113611
MemoryLocation::get(Dst),
36123612
MemoryLocation::get(Src))) {
36133613
case AliasResult::MayAlias:
@@ -4034,7 +4034,7 @@ const SCEV *DependenceInfo::getSplitIteration(const Dependence &Dep,
40344034
Value *SrcPtr = getLoadStorePointerOperand(Src);
40354035
Value *DstPtr = getLoadStorePointerOperand(Dst);
40364036
assert(underlyingObjectsAlias(
4037-
AA, F->getParent()->getDataLayout(), MemoryLocation::get(Dst),
4037+
AA, F->getDataLayout(), MemoryLocation::get(Dst),
40384038
MemoryLocation::get(Src)) == AliasResult::MustAlias);
40394039

40404040
// establish loop nesting levels

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ class CallAnalyzer : public InstVisitor<CallAnalyzer, bool> {
498498
ProfileSummaryInfo *PSI = nullptr,
499499
OptimizationRemarkEmitter *ORE = nullptr)
500500
: TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
501-
PSI(PSI), F(Callee), DL(F.getParent()->getDataLayout()), ORE(ORE),
501+
PSI(PSI), F(Callee), DL(F.getDataLayout()), ORE(ORE),
502502
CandidateCall(Call) {}
503503

504504
InlineResult analyze();
@@ -2999,7 +2999,7 @@ std::optional<InlineResult> llvm::getAttributeBasedInliningDecision(
29992999
// alloca, the inlined code would need to be adjusted to handle that the
30003000
// argument is in the alloca address space (so it is a little bit complicated
30013001
// to solve).
3002-
unsigned AllocaAS = Callee->getParent()->getDataLayout().getAllocaAddrSpace();
3002+
unsigned AllocaAS = Callee->getDataLayout().getAllocaAddrSpace();
30033003
for (unsigned I = 0, E = Call.arg_size(); I != E; ++I)
30043004
if (Call.isByValArgument(I)) {
30053005
PointerType *PTy = cast<PointerType>(Call.getArgOperand(I)->getType());

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7248,7 +7248,7 @@ const SimplifyQuery getBestSimplifyQuery(Pass &P, Function &F) {
72487248
auto *TLI = TLIWP ? &TLIWP->getTLI(F) : nullptr;
72497249
auto *ACWP = P.getAnalysisIfAvailable<AssumptionCacheTracker>();
72507250
auto *AC = ACWP ? &ACWP->getAssumptionCache(F) : nullptr;
7251-
return {F.getParent()->getDataLayout(), TLI, DT, AC};
7251+
return {F.getDataLayout(), TLI, DT, AC};
72527252
}
72537253

72547254
const SimplifyQuery getBestSimplifyQuery(LoopStandardAnalysisResults &AR,
@@ -7262,7 +7262,7 @@ const SimplifyQuery getBestSimplifyQuery(AnalysisManager<T, TArgs...> &AM,
72627262
auto *DT = AM.template getCachedResult<DominatorTreeAnalysis>(F);
72637263
auto *TLI = AM.template getCachedResult<TargetLibraryAnalysis>(F);
72647264
auto *AC = AM.template getCachedResult<AssumptionAnalysis>(F);
7265-
return {F.getParent()->getDataLayout(), TLI, DT, AC};
7265+
return {F.getDataLayout(), TLI, DT, AC};
72667266
}
72677267
template const SimplifyQuery getBestSimplifyQuery(AnalysisManager<Function> &,
72687268
Function &);

0 commit comments

Comments
 (0)