Skip to content

[CIR][Dialect][NFC] Remove redundant module attribute llvm.data_layout #1156

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

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ CIRGenerator::~CIRGenerator() {

static void setMLIRDataLayout(mlir::ModuleOp &mod, const llvm::DataLayout &dl) {
auto *context = mod.getContext();
mod->setAttr(mlir::LLVM::LLVMDialect::getDataLayoutAttrName(),
mlir::StringAttr::get(context, dl.getStringRepresentation()));
mlir::DataLayoutSpecInterface dlSpec = mlir::translateDataLayout(dl, context);
mod->setAttr(mlir::DLTIDialect::kDataLayoutAttrName, dlSpec);
}
Expand Down
15 changes: 3 additions & 12 deletions clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ createTargetLoweringInfo(LowerModule &LM) {
}

LowerModule::LowerModule(clang::LangOptions opts, mlir::ModuleOp &module,
mlir::StringAttr DL,
std::unique_ptr<clang::TargetInfo> target,
mlir::PatternRewriter &rewriter)
: context(module, opts), module(module), Target(std::move(target)),
ABI(createCXXABI(*this)), types(*this, DL.getValue()),
rewriter(rewriter) {
ABI(createCXXABI(*this)), types(*this), rewriter(rewriter) {
context.initBuiltinTypes(*Target);
}

Expand Down Expand Up @@ -228,13 +226,6 @@ llvm::LogicalResult LowerModule::rewriteFunctionCall(CallOp callOp,
// TODO: not to create it every time
std::unique_ptr<LowerModule>
createLowerModule(mlir::ModuleOp module, mlir::PatternRewriter &rewriter) {
assert(module->getAttr(mlir::LLVM::LLVMDialect::getDataLayoutAttrName()) &&
"Missing data layout attribute");

// Fetch the LLVM data layout string.
auto dataLayoutStr = mlir::cast<mlir::StringAttr>(
module->getAttr(mlir::LLVM::LLVMDialect::getDataLayoutAttrName()));

// Fetch target information.
llvm::Triple triple(mlir::cast<mlir::StringAttr>(
module->getAttr(cir::CIRDialect::getTripleAttrName()))
Expand All @@ -249,8 +240,8 @@ createLowerModule(mlir::ModuleOp module, mlir::PatternRewriter &rewriter) {
cir_cconv_assert(!cir::MissingFeatures::langOpts());
clang::LangOptions langOpts;

return std::make_unique<LowerModule>(langOpts, module, dataLayoutStr,
std::move(targetInfo), rewriter);
return std::make_unique<LowerModule>(langOpts, module, std::move(targetInfo),
rewriter);
}

} // namespace cir
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class LowerModule {

public:
LowerModule(clang::LangOptions opts, mlir::ModuleOp &module,
mlir::StringAttr DL, std::unique_ptr<clang::TargetInfo> target,
std::unique_ptr<clang::TargetInfo> target,
mlir::PatternRewriter &rewriter);
~LowerModule() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ unsigned LowerTypes::clangCallConvToLLVMCallConv(clang::CallingConv CC) {
}
}

LowerTypes::LowerTypes(LowerModule &LM, llvm::StringRef DLString)
LowerTypes::LowerTypes(LowerModule &LM)
: LM(LM), context(LM.getContext()), Target(LM.getTarget()),
CXXABI(LM.getCXXABI()),
TheABIInfo(LM.getTargetLoweringInfo().getABIInfo()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LowerTypes {
const ABIInfo &getABIInfo() const { return TheABIInfo; }

public:
LowerTypes(LowerModule &LM, llvm::StringRef DLString);
LowerTypes(LowerModule &LM);
~LowerTypes() = default;

const cir::CIRDataLayout &getDataLayout() const { return DL; }
Expand Down
2 changes: 0 additions & 2 deletions clang/test/CIR/CodeGen/dlti.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ void foo() {}
// CHECK-DAG: "dlti.stack_alignment" = 128 : i64
// CHECK-DAG: "dlti.endianness" = "little"
// >,
// CHECK-DAG: llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"

2 changes: 1 addition & 1 deletion clang/test/CIR/Lowering/address-space.cir
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module attributes {
cir.triple = "spirv64-unknown-unknown",
llvm.data_layout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
dlti.dl_spec = #dlti.dl_spec<i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, i64 = dense<64> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, "dlti.endianness" = "little", "dlti.global_memory_space" = 1 : ui64>
} {
cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
// LLVM: @addrspace1 = addrspace(1) global i32
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/Lowering/exceptions.cir
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
!u8i = !cir.int<u, 8>
!void = !cir.void

module @"try-catch.cpp" attributes {cir.lang = #cir.lang<cxx>, cir.sob = #cir.signed_overflow_behavior<undefined>, cir.triple = "x86_64-unknown-linux-gnu", dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<i128, dense<128> : vector<2xi64>>, #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>, #dlti.dl_entry<"dlti.endianness", "little">>, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"} {
module @"try-catch.cpp" attributes {cir.lang = #cir.lang<cxx>, cir.sob = #cir.signed_overflow_behavior<undefined>, cir.triple = "x86_64-unknown-linux-gnu", dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<i128, dense<128> : vector<2xi64>>, #dlti.dl_entry<"dlti.stack_alignment", 128 : i64>, #dlti.dl_entry<"dlti.endianness", "little">>} {
cir.global "private" constant external @_ZTIi : !cir.ptr<!u8i>
cir.global "private" constant external @_ZTIPKc : !cir.ptr<!u8i>
cir.func private @_Z8divisionii(!s32i, !s32i) -> !cir.double
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/Lowering/hello.cir
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

!s32i = !cir.int<s, 32>
!s8i = !cir.int<s, 8>
module @"/tmp/test.raw" attributes {cir.lang = #cir.lang<c>, cir.sob = #cir.signed_overflow_behavior<undefined>, dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<"dlti.endianness", "little">, #dlti.dl_entry<"dlti.stack_alignment", 128 : i32>>, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"} {
module @"/tmp/test.raw" attributes {cir.lang = #cir.lang<c>, cir.sob = #cir.signed_overflow_behavior<undefined>, dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<i32, dense<32> : vector<2xi64>>, #dlti.dl_entry<f64, dense<64> : vector<2xi64>>, #dlti.dl_entry<f16, dense<16> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<270>, dense<32> : vector<4xi64>>, #dlti.dl_entry<f128, dense<128> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr<271>, dense<32> : vector<4xi64>>, #dlti.dl_entry<!llvm.ptr<272>, dense<64> : vector<4xi64>>, #dlti.dl_entry<f80, dense<128> : vector<2xi64>>, #dlti.dl_entry<i64, dense<64> : vector<2xi64>>, #dlti.dl_entry<i1, dense<8> : vector<2xi64>>, #dlti.dl_entry<!llvm.ptr, dense<64> : vector<4xi64>>, #dlti.dl_entry<i16, dense<16> : vector<2xi64>>, #dlti.dl_entry<i8, dense<8> : vector<2xi64>>, #dlti.dl_entry<"dlti.endianness", "little">, #dlti.dl_entry<"dlti.stack_alignment", 128 : i32>>} {
cir.func private @printf(!cir.ptr<!s8i>, ...) -> !s32i
cir.global "private" constant internal @".str" = #cir.const_array<"Hello, world!\0A\00" : !cir.array<!s8i x 15>> : !cir.array<!s8i x 15> {alignment = 1 : i64}
cir.func @main() -> !s32i {
Expand Down
3 changes: 2 additions & 1 deletion clang/test/CIR/Tools/cir-translate-triple.cir
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

module attributes {
cir.triple = "x86_64-unknown-linux-gnu",
llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
dlti.dl_spec = #dlti.dl_spec<i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, !llvm.ptr<270> = dense<32> : vector<4xi64>, f64 = dense<64> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, "dlti.stack_alignment" = 128 : i64, "dlti.endianness" = "little">
} {
cir.func @foo() {
cir.return
}
}

// LLVM-DAG: target triple = "x86_64-unknown-linux-gnu"
// LLVM-DAG: target datalayout = "{{.*}}"