From 55e1496cd96ed23cfcf40c11fa2cb2945c484632 Mon Sep 17 00:00:00 2001 From: ghehg <166402688+ghehg@users.noreply.github.com> Date: Mon, 17 Jun 2024 23:27:55 -0400 Subject: [PATCH] [CIR][CIRDataLayout]moving CIRDataLayout to MLIRCIR (#693) fix build failure undefined reference to `cir::CIRDataLayout::CIRDataLayout(mlir::ModuleOp)' by breaking circular dependency caused by the fact CIRDataLayout was in CIR Codegen --- .../CIR/CodeGen/CIRRecordLayoutBuilder.cpp | 26 ----------- clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp | 43 +++++++++++++++++++ clang/lib/CIR/Dialect/IR/CMakeLists.txt | 1 + 3 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp diff --git a/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp b/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp index 7ab0cf32c25a..7181673b96cd 100644 --- a/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp +++ b/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp @@ -722,29 +722,3 @@ CIRGenBitFieldInfo CIRGenBitFieldInfo::MakeInfo(CIRGenTypes &Types, CharUnits StorageOffset) { llvm_unreachable("NYI"); } - -CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout{modOp} { - auto dlSpec = modOp->getAttr(mlir::DLTIDialect::kDataLayoutAttrName) - .dyn_cast(); - assert(dlSpec && "expected dl_spec in the module"); - auto entries = dlSpec.getEntries(); - - for (auto entry : entries) { - auto entryKey = entry.getKey(); - auto strKey = entryKey.dyn_cast(); - if (!strKey) - continue; - auto entryName = strKey.strref(); - if (entryName == mlir::DLTIDialect::kDataLayoutEndiannessKey) { - auto value = entry.getValue().dyn_cast(); - assert(value && "expected string attribute"); - auto endian = value.getValue(); - if (endian == mlir::DLTIDialect::kDataLayoutEndiannessBig) - bigEndian = true; - else if (endian == mlir::DLTIDialect::kDataLayoutEndiannessLittle) - bigEndian = false; - else - llvm_unreachable("unknown endianess"); - } - } -} diff --git a/clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp b/clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp new file mode 100644 index 000000000000..fe05d25a5cac --- /dev/null +++ b/clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp @@ -0,0 +1,43 @@ +//===- CIRDialect.cpp - MLIR CIR ops implementation -----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines the CIR DataLayout class and its functions. +// +//===----------------------------------------------------------------------===//a +// + +#include "clang/CIR/Dialect/IR/CIRDataLayout.h" + +namespace cir { +CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout{modOp} { + auto dlSpec = modOp->getAttr(mlir::DLTIDialect::kDataLayoutAttrName) + .dyn_cast(); + assert(dlSpec && "expected dl_spec in the module"); + auto entries = dlSpec.getEntries(); + + for (auto entry : entries) { + auto entryKey = entry.getKey(); + auto strKey = entryKey.dyn_cast(); + if (!strKey) + continue; + auto entryName = strKey.strref(); + if (entryName == mlir::DLTIDialect::kDataLayoutEndiannessKey) { + auto value = entry.getValue().dyn_cast(); + assert(value && "expected string attribute"); + auto endian = value.getValue(); + if (endian == mlir::DLTIDialect::kDataLayoutEndiannessBig) + bigEndian = true; + else if (endian == mlir::DLTIDialect::kDataLayoutEndiannessLittle) + bigEndian = false; + else + llvm_unreachable("unknown endianess"); + } + } +} + +} // namespace cir diff --git a/clang/lib/CIR/Dialect/IR/CMakeLists.txt b/clang/lib/CIR/Dialect/IR/CMakeLists.txt index 27d826e84489..208b7b4586d8 100644 --- a/clang/lib/CIR/Dialect/IR/CMakeLists.txt +++ b/clang/lib/CIR/Dialect/IR/CMakeLists.txt @@ -1,5 +1,6 @@ add_clang_library(MLIRCIR CIRAttrs.cpp + CIRDataLayout.cpp CIRDialect.cpp CIRTypes.cpp FPEnv.cpp