Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataLayout] Remove constructor accepting a pointer to Module #102841

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions clang/lib/CodeGen/CGObjCGNU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ class CGObjCGNU : public CGObjCRuntime {
Fields.addInt(IntTy, count);
// int size; (only in GNUstep v2 ABI.
if (isRuntime(ObjCRuntime::GNUstep, 2)) {
llvm::DataLayout td(&TheModule);
Fields.addInt(IntTy, td.getTypeSizeInBits(PropertyMetadataTy) /
CGM.getContext().getCharWidth());
const llvm::DataLayout &DL = TheModule.getDataLayout();
Fields.addInt(IntTy, DL.getTypeSizeInBits(PropertyMetadataTy) /
CGM.getContext().getCharWidth());
}
// struct objc_property_list *next;
Fields.add(NULLPtr);
Expand Down Expand Up @@ -1190,9 +1190,9 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
// int count;
MethodList.addInt(IntTy, Methods.size());
// int size; // sizeof(struct objc_method_description)
llvm::DataLayout td(&TheModule);
MethodList.addInt(IntTy, td.getTypeSizeInBits(ObjCMethodDescTy) /
CGM.getContext().getCharWidth());
const llvm::DataLayout &DL = TheModule.getDataLayout();
MethodList.addInt(IntTy, DL.getTypeSizeInBits(ObjCMethodDescTy) /
CGM.getContext().getCharWidth());
// struct objc_method_description[]
auto MethodArray = MethodList.beginArray(ObjCMethodDescTy);
for (auto *M : Methods) {
Expand Down Expand Up @@ -1828,7 +1828,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
int ivar_count = 0;
for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
IVD = IVD->getNextIvar()) ivar_count++;
llvm::DataLayout td(&TheModule);
const llvm::DataLayout &DL = TheModule.getDataLayout();
// struct objc_ivar_list *ivars;
ConstantInitBuilder b(CGM);
auto ivarListBuilder = b.beginStruct();
Expand All @@ -1841,8 +1841,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
PtrToInt8Ty,
Int32Ty,
Int32Ty);
ivarListBuilder.addInt(SizeTy, td.getTypeSizeInBits(ObjCIvarTy) /
CGM.getContext().getCharWidth());
ivarListBuilder.addInt(SizeTy, DL.getTypeSizeInBits(ObjCIvarTy) /
CGM.getContext().getCharWidth());
// struct objc_ivar ivars[]
auto ivarArrayBuilder = ivarListBuilder.beginArray();
for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
Expand Down Expand Up @@ -3019,9 +3019,9 @@ GenerateMethodList(StringRef ClassName,
bool isV2ABI = isRuntime(ObjCRuntime::GNUstep, 2);
if (isV2ABI) {
// size_t size;
llvm::DataLayout td(&TheModule);
MethodList.addInt(SizeTy, td.getTypeSizeInBits(ObjCMethodTy) /
CGM.getContext().getCharWidth());
const llvm::DataLayout &DL = TheModule.getDataLayout();
MethodList.addInt(SizeTy, DL.getTypeSizeInBits(ObjCMethodTy) /
CGM.getContext().getCharWidth());
ObjCMethodTy =
llvm::StructType::get(CGM.getLLVMContext(), {
IMPTy, // Method pointer
Expand Down Expand Up @@ -3161,10 +3161,9 @@ llvm::Constant *CGObjCGNU::GenerateClassStructure(
Elements.addInt(LongTy, info);
// instance_size
if (isMeta) {
llvm::DataLayout td(&TheModule);
Elements.addInt(LongTy,
td.getTypeSizeInBits(ClassTy) /
CGM.getContext().getCharWidth());
const llvm::DataLayout &DL = TheModule.getDataLayout();
Elements.addInt(LongTy, DL.getTypeSizeInBits(ClassTy) /
CGM.getContext().getCharWidth());
} else
Elements.add(InstanceSize);
// ivars
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenTBAA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ TBAAAccessInfo CodeGenTBAA::getAccessInfo(QualType AccessType) {
}

TBAAAccessInfo CodeGenTBAA::getVTablePtrAccessInfo(llvm::Type *VTablePtrType) {
llvm::DataLayout DL(&Module);
const llvm::DataLayout &DL = Module.getDataLayout();
unsigned Size = DL.getPointerTypeSize(VTablePtrType);
return TBAAAccessInfo(createScalarTypeNode("vtable pointer", getRoot(), Size),
Size);
Expand Down
6 changes: 0 additions & 6 deletions llvm/include/llvm/IR/DataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace llvm {

class GlobalVariable;
class LLVMContext;
class Module;
class StructLayout;
class Triple;
class Value;
Expand Down Expand Up @@ -194,9 +193,6 @@ class DataLayout {
reset(LayoutDescription);
}

/// Initialize target data from properties stored in the module.
explicit DataLayout(const Module *M);

DataLayout(const DataLayout &DL) { *this = DL; }

~DataLayout(); // Not virtual, do not subclass this class
Expand Down Expand Up @@ -225,8 +221,6 @@ class DataLayout {
bool operator==(const DataLayout &Other) const;
bool operator!=(const DataLayout &Other) const { return !(*this == Other); }

void init(const Module *M);

/// Parse a data layout string (with fallback to default values).
void reset(StringRef LayoutDescription);

Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Analysis/InlineCost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3246,8 +3246,7 @@ InlineCostAnnotationPrinterPass::run(Function &F,
};
Module *M = F.getParent();
ProfileSummaryInfo PSI(*M);
DataLayout DL(M);
TargetTransformInfo TTI(DL);
TargetTransformInfo TTI(M->getDataLayout());
// FIXME: Redesign the usage of InlineParams to expand the scope of this pass.
// In the current implementation, the type of InlineParams doesn't matter as
// the pass serves only for verification of inliner's decisions.
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2826,13 +2826,12 @@ bool AssignmentTrackingAnalysis::runOnFunction(Function &F) {

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

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

FunctionVarLocsBuilder Builder;
analyzeFunction(F, *DL.get(), &Builder);
analyzeFunction(F, F.getDataLayout(), &Builder);

// Save these results.
Results->init(Builder);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/FuzzMutate/RandomIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ AllocaInst *RandomIRBuilder::createStackMemory(Function *F, Type *Ty,
Value *Init) {
/// TODO: For all Allocas, maybe allocate an array.
BasicBlock *EntryBB = &F->getEntryBlock();
DataLayout DL(F->getParent());
const DataLayout &DL = F->getDataLayout();
AllocaInst *Alloca = new AllocaInst(Ty, DL.getAllocaAddrSpace(), "A",
EntryBB->getFirstInsertionPt());
if (Init)
Expand Down Expand Up @@ -423,7 +423,7 @@ Function *RandomIRBuilder::createFunctionDefinition(Module &M,
// TODO: Some arguments and a return value would probably be more
// interesting.
LLVMContext &Context = M.getContext();
DataLayout DL(&M);
const DataLayout &DL = M.getDataLayout();
BasicBlock *BB = BasicBlock::Create(Context, "BB", F);
Type *RetTy = F->getReturnType();
if (RetTy != Type::getVoidTy(Context)) {
Expand Down
7 changes: 0 additions & 7 deletions llvm/lib/IR/DataLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
Expand Down Expand Up @@ -550,12 +549,6 @@ Error DataLayout::parseSpecifier(StringRef Desc) {
return Error::success();
}

DataLayout::DataLayout(const Module *M) {
init(M);
}

void DataLayout::init(const Module *M) { *this = M->getDataLayout(); }

bool DataLayout::operator==(const DataLayout &Other) const {
bool Ret = BigEndian == Other.BigEndian &&
AllocaAddrSpace == Other.AllocaAddrSpace &&
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ static void adjustByValArgAlignment(Argument *Arg, Value *ArgInParamAS,
const NVPTXTargetLowering *TLI) {
Function *Func = Arg->getParent();
Type *StructType = Arg->getParamByValType();
const DataLayout DL(Func->getParent());
const DataLayout &DL = Func->getDataLayout();

uint64_t NewArgAlign =
TLI->getFunctionParamOptimizedAlign(Func, StructType, DL).value();
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/InlineFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,8 +1896,8 @@ static void trackInlinedStores(Function::iterator Start, Function::iterator End,
LLVM_DEBUG(errs() << "trackInlinedStores into "
<< Start->getParent()->getName() << " from "
<< CB.getCalledFunction()->getName() << "\n");
std::unique_ptr<DataLayout> DL = std::make_unique<DataLayout>(CB.getModule());
at::trackAssignments(Start, End, collectEscapedLocals(*DL, CB), *DL);
const DataLayout &DL = CB.getDataLayout();
at::trackAssignments(Start, End, collectEscapedLocals(DL, CB), DL);
}

/// Update inlined instructions' DIAssignID metadata. We need to do this
Expand Down
7 changes: 3 additions & 4 deletions llvm/unittests/IR/IRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,10 @@ TEST_F(IRBuilderTest, GetIntTy) {
IntegerType *Ty1 = Builder.getInt1Ty();
EXPECT_EQ(Ty1, IntegerType::get(Ctx, 1));

DataLayout* DL = new DataLayout(M.get());
IntegerType *IntPtrTy = Builder.getIntPtrTy(*DL);
unsigned IntPtrBitSize = DL->getPointerSizeInBits(0);
const DataLayout &DL = M->getDataLayout();
IntegerType *IntPtrTy = Builder.getIntPtrTy(DL);
unsigned IntPtrBitSize = DL.getPointerSizeInBits(0);
EXPECT_EQ(IntPtrTy, IntegerType::get(Ctx, IntPtrBitSize));
delete DL;
}

TEST_F(IRBuilderTest, UnaryOperators) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/unittests/SandboxIR/SandboxIRTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ define void @foo(ptr %ptr, <2 x ptr> %ptrs) {
// Check hasNoUnsignedWrap().
EXPECT_EQ(GEP->hasNoUnsignedWrap(), LLVMGEP->hasNoUnsignedWrap());
// Check accumulateConstantOffset().
DataLayout DL(M.get());
const DataLayout &DL = M->getDataLayout();
APInt Offset1 =
APInt::getZero(DL.getIndexSizeInBits(GEP->getPointerAddressSpace()));
APInt Offset2 =
Expand Down Expand Up @@ -1533,7 +1533,7 @@ define void @foo() {
ret void
}
)IR");
DataLayout DL(M.get());
const DataLayout &DL = M->getDataLayout();
llvm::Function &LLVMF = *M->getFunction("foo");
llvm::BasicBlock *LLVMBB = &*LLVMF.begin();
auto LLVMIt = LLVMBB->begin();
Expand Down
Loading