Skip to content

Commit 55e1496

Browse files
authored
[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
1 parent 47df94c commit 55e1496

File tree

3 files changed

+44
-26
lines changed

3 files changed

+44
-26
lines changed

clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -722,29 +722,3 @@ CIRGenBitFieldInfo CIRGenBitFieldInfo::MakeInfo(CIRGenTypes &Types,
722722
CharUnits StorageOffset) {
723723
llvm_unreachable("NYI");
724724
}
725-
726-
CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout{modOp} {
727-
auto dlSpec = modOp->getAttr(mlir::DLTIDialect::kDataLayoutAttrName)
728-
.dyn_cast<mlir::DataLayoutSpecAttr>();
729-
assert(dlSpec && "expected dl_spec in the module");
730-
auto entries = dlSpec.getEntries();
731-
732-
for (auto entry : entries) {
733-
auto entryKey = entry.getKey();
734-
auto strKey = entryKey.dyn_cast<mlir::StringAttr>();
735-
if (!strKey)
736-
continue;
737-
auto entryName = strKey.strref();
738-
if (entryName == mlir::DLTIDialect::kDataLayoutEndiannessKey) {
739-
auto value = entry.getValue().dyn_cast<mlir::StringAttr>();
740-
assert(value && "expected string attribute");
741-
auto endian = value.getValue();
742-
if (endian == mlir::DLTIDialect::kDataLayoutEndiannessBig)
743-
bigEndian = true;
744-
else if (endian == mlir::DLTIDialect::kDataLayoutEndiannessLittle)
745-
bigEndian = false;
746-
else
747-
llvm_unreachable("unknown endianess");
748-
}
749-
}
750-
}
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===- CIRDialect.cpp - MLIR CIR ops implementation -----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the CIR DataLayout class and its functions.
10+
//
11+
//===----------------------------------------------------------------------===//a
12+
//
13+
14+
#include "clang/CIR/Dialect/IR/CIRDataLayout.h"
15+
16+
namespace cir {
17+
CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout{modOp} {
18+
auto dlSpec = modOp->getAttr(mlir::DLTIDialect::kDataLayoutAttrName)
19+
.dyn_cast<mlir::DataLayoutSpecAttr>();
20+
assert(dlSpec && "expected dl_spec in the module");
21+
auto entries = dlSpec.getEntries();
22+
23+
for (auto entry : entries) {
24+
auto entryKey = entry.getKey();
25+
auto strKey = entryKey.dyn_cast<mlir::StringAttr>();
26+
if (!strKey)
27+
continue;
28+
auto entryName = strKey.strref();
29+
if (entryName == mlir::DLTIDialect::kDataLayoutEndiannessKey) {
30+
auto value = entry.getValue().dyn_cast<mlir::StringAttr>();
31+
assert(value && "expected string attribute");
32+
auto endian = value.getValue();
33+
if (endian == mlir::DLTIDialect::kDataLayoutEndiannessBig)
34+
bigEndian = true;
35+
else if (endian == mlir::DLTIDialect::kDataLayoutEndiannessLittle)
36+
bigEndian = false;
37+
else
38+
llvm_unreachable("unknown endianess");
39+
}
40+
}
41+
}
42+
43+
} // namespace cir

clang/lib/CIR/Dialect/IR/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_clang_library(MLIRCIR
22
CIRAttrs.cpp
3+
CIRDataLayout.cpp
34
CIRDialect.cpp
45
CIRTypes.cpp
56
FPEnv.cpp

0 commit comments

Comments
 (0)