Skip to content

Commit 75c7bca

Browse files
authored
[DataLayout] Remove constructor accepting a pointer to Module (#102841)
The constructor initializes `*this` with `M->getDataLayout()`, which is effectively the same as calling the copy constructor. There does not seem to be a case where a copy would be necessary. Pull Request: #102841
1 parent f8f34c7 commit 75c7bca

File tree

11 files changed

+28
-45
lines changed

11 files changed

+28
-45
lines changed

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ class CGObjCGNU : public CGObjCRuntime {
278278
Fields.addInt(IntTy, count);
279279
// int size; (only in GNUstep v2 ABI.
280280
if (isRuntime(ObjCRuntime::GNUstep, 2)) {
281-
llvm::DataLayout td(&TheModule);
282-
Fields.addInt(IntTy, td.getTypeSizeInBits(PropertyMetadataTy) /
283-
CGM.getContext().getCharWidth());
281+
const llvm::DataLayout &DL = TheModule.getDataLayout();
282+
Fields.addInt(IntTy, DL.getTypeSizeInBits(PropertyMetadataTy) /
283+
CGM.getContext().getCharWidth());
284284
}
285285
// struct objc_property_list *next;
286286
Fields.add(NULLPtr);
@@ -1190,9 +1190,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
11901190
// int count;
11911191
MethodList.addInt(IntTy, Methods.size());
11921192
// int size; // sizeof(struct objc_method_description)
1193-
llvm::DataLayout td(&TheModule);
1194-
MethodList.addInt(IntTy, td.getTypeSizeInBits(ObjCMethodDescTy) /
1195-
CGM.getContext().getCharWidth());
1193+
const llvm::DataLayout &DL = TheModule.getDataLayout();
1194+
MethodList.addInt(IntTy, DL.getTypeSizeInBits(ObjCMethodDescTy) /
1195+
CGM.getContext().getCharWidth());
11961196
// struct objc_method_description[]
11971197
auto MethodArray = MethodList.beginArray(ObjCMethodDescTy);
11981198
for (auto *M : Methods) {
@@ -1828,7 +1828,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
18281828
int ivar_count = 0;
18291829
for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
18301830
IVD = IVD->getNextIvar()) ivar_count++;
1831-
llvm::DataLayout td(&TheModule);
1831+
const llvm::DataLayout &DL = TheModule.getDataLayout();
18321832
// struct objc_ivar_list *ivars;
18331833
ConstantInitBuilder b(CGM);
18341834
auto ivarListBuilder = b.beginStruct();
@@ -1841,8 +1841,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
18411841
PtrToInt8Ty,
18421842
Int32Ty,
18431843
Int32Ty);
1844-
ivarListBuilder.addInt(SizeTy, td.getTypeSizeInBits(ObjCIvarTy) /
1845-
CGM.getContext().getCharWidth());
1844+
ivarListBuilder.addInt(SizeTy, DL.getTypeSizeInBits(ObjCIvarTy) /
1845+
CGM.getContext().getCharWidth());
18461846
// struct objc_ivar ivars[]
18471847
auto ivarArrayBuilder = ivarListBuilder.beginArray();
18481848
for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
@@ -3019,9 +3019,9 @@ GenerateMethodList(StringRef ClassName,
30193019
bool isV2ABI = isRuntime(ObjCRuntime::GNUstep, 2);
30203020
if (isV2ABI) {
30213021
// size_t size;
3022-
llvm::DataLayout td(&TheModule);
3023-
MethodList.addInt(SizeTy, td.getTypeSizeInBits(ObjCMethodTy) /
3024-
CGM.getContext().getCharWidth());
3022+
const llvm::DataLayout &DL = TheModule.getDataLayout();
3023+
MethodList.addInt(SizeTy, DL.getTypeSizeInBits(ObjCMethodTy) /
3024+
CGM.getContext().getCharWidth());
30253025
ObjCMethodTy =
30263026
llvm::StructType::get(CGM.getLLVMContext(), {
30273027
IMPTy, // Method pointer
@@ -3161,10 +3161,9 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
31613161
Elements.addInt(LongTy, info);
31623162
// instance_size
31633163
if (isMeta) {
3164-
llvm::DataLayout td(&TheModule);
3165-
Elements.addInt(LongTy,
3166-
td.getTypeSizeInBits(ClassTy) /
3167-
CGM.getContext().getCharWidth());
3164+
const llvm::DataLayout &DL = TheModule.getDataLayout();
3165+
Elements.addInt(LongTy, DL.getTypeSizeInBits(ClassTy) /
3166+
CGM.getContext().getCharWidth());
31683167
} else
31693168
Elements.add(InstanceSize);
31703169
// ivars

clang/lib/CodeGen/CodeGenTBAA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ TBAAAccessInfo CodeGenTBAA::getAccessInfo(QualType AccessType) {
318318
}
319319

320320
TBAAAccessInfo CodeGenTBAA::getVTablePtrAccessInfo(llvm::Type *VTablePtrType) {
321-
llvm::DataLayout DL(&Module);
321+
const llvm::DataLayout &DL = Module.getDataLayout();
322322
unsigned Size = DL.getPointerTypeSize(VTablePtrType);
323323
return TBAAAccessInfo(createScalarTypeNode("vtable pointer", getRoot(), Size),
324324
Size);

llvm/include/llvm/IR/DataLayout.h

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

4646
class GlobalVariable;
4747
class LLVMContext;
48-
class Module;
4948
class StructLayout;
5049
class Triple;
5150
class Value;
@@ -195,9 +194,6 @@ class DataLayout {
195194
reset(LayoutDescription);
196195
}
197196

198-
/// Initialize target data from properties stored in the module.
199-
explicit DataLayout(const Module *M);
200-
201197
DataLayout(const DataLayout &DL) { *this = DL; }
202198

203199
~DataLayout(); // Not virtual, do not subclass this class
@@ -207,8 +203,6 @@ class DataLayout {
207203
bool operator==(const DataLayout &Other) const;
208204
bool operator!=(const DataLayout &Other) const { return !(*this == Other); }
209205

210-
void init(const Module *M);
211-
212206
/// Parse a data layout string (with fallback to default values).
213207
void reset(StringRef LayoutDescription);
214208

llvm/lib/Analysis/InlineCost.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,8 +3246,7 @@ InlineCostAnnotationPrinterPass::run(Function &F,
32463246
};
32473247
Module *M = F.getParent();
32483248
ProfileSummaryInfo PSI(*M);
3249-
DataLayout DL(M);
3250-
TargetTransformInfo TTI(DL);
3249+
TargetTransformInfo TTI(M->getDataLayout());
32513250
// FIXME: Redesign the usage of InlineParams to expand the scope of this pass.
32523251
// In the current implementation, the type of InlineParams doesn't matter as
32533252
// the pass serves only for verification of inliner's decisions.

llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,13 +2826,12 @@ bool AssignmentTrackingAnalysis::runOnFunction(Function &F) {
28262826

28272827
LLVM_DEBUG(dbgs() << "AssignmentTrackingAnalysis run on " << F.getName()
28282828
<< "\n");
2829-
auto DL = std::make_unique<DataLayout>(F.getParent());
28302829

28312830
// Clear previous results.
28322831
Results->clear();
28332832

28342833
FunctionVarLocsBuilder Builder;
2835-
analyzeFunction(F, *DL.get(), &Builder);
2834+
analyzeFunction(F, F.getDataLayout(), &Builder);
28362835

28372836
// Save these results.
28382837
Results->init(Builder);

llvm/lib/FuzzMutate/RandomIRBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ AllocaInst *RandomIRBuilder::createStackMemory(Function *F, Type *Ty,
6767
Value *Init) {
6868
/// TODO: For all Allocas, maybe allocate an array.
6969
BasicBlock *EntryBB = &F->getEntryBlock();
70-
DataLayout DL(F->getParent());
70+
const DataLayout &DL = F->getDataLayout();
7171
AllocaInst *Alloca = new AllocaInst(Ty, DL.getAllocaAddrSpace(), "A",
7272
EntryBB->getFirstInsertionPt());
7373
if (Init)
@@ -423,7 +423,7 @@ Function *RandomIRBuilder::createFunctionDefinition(Module &M,
423423
// TODO: Some arguments and a return value would probably be more
424424
// interesting.
425425
LLVMContext &Context = M.getContext();
426-
DataLayout DL(&M);
426+
const DataLayout &DL = M.getDataLayout();
427427
BasicBlock *BB = BasicBlock::Create(Context, "BB", F);
428428
Type *RetTy = F->getReturnType();
429429
if (RetTy != Type::getVoidTy(Context)) {

llvm/lib/IR/DataLayout.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/IR/DerivedTypes.h"
2323
#include "llvm/IR/GetElementPtrTypeIterator.h"
2424
#include "llvm/IR/GlobalVariable.h"
25-
#include "llvm/IR/Module.h"
2625
#include "llvm/IR/Type.h"
2726
#include "llvm/IR/Value.h"
2827
#include "llvm/Support/Casting.h"
@@ -589,12 +588,6 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
589588
return Error::success();
590589
}
591590

592-
DataLayout::DataLayout(const Module *M) {
593-
init(M);
594-
}
595-
596-
void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }
597-
598591
static SmallVectorImpl<LayoutAlignElem>::const_iterator
599592
findAlignmentLowerBound(const SmallVectorImpl<LayoutAlignElem> &Alignments,
600593
uint32_t BitWidth) {

llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static void adjustByValArgAlignment(Argument *Arg, Value *ArgInParamAS,
328328
const NVPTXTargetLowering *TLI) {
329329
Function *Func = Arg->getParent();
330330
Type *StructType = Arg->getParamByValType();
331-
const DataLayout DL(Func->getParent());
331+
const DataLayout &DL = Func->getDataLayout();
332332

333333
uint64_t NewArgAlign =
334334
TLI->getFunctionParamOptimizedAlign(Func, StructType, DL).value();

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,8 +1896,8 @@ static void trackInlinedStores(Function::iterator Start, Function::iterator End,
18961896
LLVM_DEBUG(errs() << "trackInlinedStores into "
18971897
<< Start->getParent()->getName() << " from "
18981898
<< CB.getCalledFunction()->getName() << "\n");
1899-
std::unique_ptr<DataLayout> DL = std::make_unique<DataLayout>(CB.getModule());
1900-
at::trackAssignments(Start, End, collectEscapedLocals(*DL, CB), *DL);
1899+
const DataLayout &DL = CB.getDataLayout();
1900+
at::trackAssignments(Start, End, collectEscapedLocals(DL, CB), DL);
19011901
}
19021902

19031903
/// Update inlined instructions' DIAssignID metadata. We need to do this

llvm/unittests/IR/IRBuilderTest.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,10 @@ TEST_F(IRBuilderTest, GetIntTy) {
521521
IntegerType *Ty1 = Builder.getInt1Ty();
522522
EXPECT_EQ(Ty1, IntegerType::get(Ctx, 1));
523523

524-
DataLayout* DL = new DataLayout(M.get());
525-
IntegerType *IntPtrTy = Builder.getIntPtrTy(*DL);
526-
unsigned IntPtrBitSize = DL->getPointerSizeInBits(0);
524+
const DataLayout &DL = M->getDataLayout();
525+
IntegerType *IntPtrTy = Builder.getIntPtrTy(DL);
526+
unsigned IntPtrBitSize = DL.getPointerSizeInBits(0);
527527
EXPECT_EQ(IntPtrTy, IntegerType::get(Ctx, IntPtrBitSize));
528-
delete DL;
529528
}
530529

531530
TEST_F(IRBuilderTest, UnaryOperators) {

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ define void @foo(ptr %ptr, <2 x ptr> %ptrs) {
14971497
// Check hasNoUnsignedWrap().
14981498
EXPECT_EQ(GEP->hasNoUnsignedWrap(), LLVMGEP->hasNoUnsignedWrap());
14991499
// Check accumulateConstantOffset().
1500-
DataLayout DL(M.get());
1500+
const DataLayout &DL = M->getDataLayout();
15011501
APInt Offset1 =
15021502
APInt::getZero(DL.getIndexSizeInBits(GEP->getPointerAddressSpace()));
15031503
APInt Offset2 =
@@ -1577,7 +1577,7 @@ define void @foo() {
15771577
ret void
15781578
}
15791579
)IR");
1580-
DataLayout DL(M.get());
1580+
const DataLayout &DL = M->getDataLayout();
15811581
llvm::Function &LLVMF = *M->getFunction("foo");
15821582
llvm::BasicBlock *LLVMBB = &*LLVMF.begin();
15831583
auto LLVMIt = LLVMBB->begin();

0 commit comments

Comments
 (0)