Skip to content

Commit 12fb5a3

Browse files
committed
[CIR][MLIR] Add minimal NamedTuple to core MLIR
No operation yet. Just lowering to memref<!named_tuple.named_tuple<>> for now.
1 parent 72ecb68 commit 12fb5a3

File tree

20 files changed

+307
-5
lines changed

20 files changed

+307
-5
lines changed

clang/lib/CIR/Lowering/ThroughMLIR/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ add_clang_library(clangCIRLoweringThroughMLIR
4040
MLIRTransforms
4141
MLIRSupport
4242
MLIRMemRefDialect
43+
MLIRNamedTupleDialect
4344
MLIROpenMPDialect
4445
MLIROpenMPToLLVMIRTranslation
4546
)

clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
3030
#include "mlir/Dialect/Math/IR/Math.h"
3131
#include "mlir/Dialect/MemRef/IR/MemRef.h"
32+
#include "mlir/Dialect/NamedTuple/IR/NamedTuple.h"
3233
#include "mlir/Dialect/SCF/IR/SCF.h"
3334
#include "mlir/Dialect/SCF/Transforms/Passes.h"
3435
#include "mlir/Dialect/Vector/IR/VectorOps.h"
@@ -84,6 +85,7 @@ struct ConvertCIRToMLIRPass
8485
mlir::affine::AffineDialect, mlir::memref::MemRefDialect,
8586
mlir::arith::ArithDialect, mlir::cf::ControlFlowDialect,
8687
mlir::scf::SCFDialect, mlir::math::MathDialect,
88+
mlir::named_tuple::NamedTupleDialect,
8789
mlir::vector::VectorDialect>();
8890
}
8991
void runOnOperation() final;
@@ -1455,12 +1457,11 @@ mlir::TypeConverter prepareTypeConverter(mlir::DataLayout &dataLayout) {
14551457
}
14561458
}
14571459

1458-
// Struct has a name: lower as an identified struct.
1459-
mlir::TupleType tuple;
14601460
// FIXME(cir): all the following has to be somehow kept. With some
14611461
// attributes?
1462-
tuple = mlir::TupleType::get(type.getContext(), mlirMembers);
1463-
return tuple;
1462+
// Struct has a name: lower as an identified struct.
1463+
return mlir::named_tuple::NamedTupleType::get(
1464+
type.getContext(), type.getName().strref(), mlirMembers);
14641465
});
14651466

14661467
return converter;

clang/test/CIR/Lowering/ThroughMLIR/struct.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ struct s {
66
float b;
77
};
88
int main() { s v; }
9-
// CHECK: memref<tuple<i32, f32>>
9+
// CHECK: memref<!named_tuple.named_tuple<"s", [i32, f32]>>

mlir/include/mlir/Dialect/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_subdirectory(MemRef)
2222
add_subdirectory(Mesh)
2323
add_subdirectory(MLProgram)
2424
add_subdirectory(MPI)
25+
add_subdirectory(NamedTuple)
2526
add_subdirectory(NVGPU)
2627
add_subdirectory(OpenACC)
2728
add_subdirectory(OpenACCMPCommon)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(IR)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_mlir_dialect(NamedTuple named_tuple)
2+
add_mlir_doc(NamedTuple NamedTuple Dialects/ -gen-dialect-doc)
3+
add_mlir_doc(NamedTupleOps NamedTupleOps Dialects/ -gen-op-doc)
4+
add_mlir_doc(NamedTupleTypes NamedTupleTypes Dialects/ -gen-typedef-doc)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This file is licensed 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 NamedTuple dialect operations.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_DIALECT_NAMED_TUPLE_IR_NAMED_TUPLE_H
14+
#define MLIR_DIALECT_NAMED_TUPLE_IR_NAMED_TUPLE_H
15+
16+
#include "mlir/Dialect/NamedTuple/IR/NamedTupleDialect.h"
17+
#include "mlir/Dialect/NamedTuple/IR/NamedTupleTypes.h"
18+
19+
#include "mlir/Dialect/NamedTuple/IR/NamedTuple.h.inc"
20+
21+
#endif // MLIR_DIALECT_NAMED_TUPLE_IR_NAMED_TUPLE_H
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This file is licensed 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+
// Main file processed by tablegen to generate the NamedTuple dialect, types and
10+
// operations
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef NAMED_TUPLE
15+
#define NAMED_TUPLE
16+
17+
include "mlir/Dialect/NamedTuple/IR/NamedTupleDialect.td"
18+
include "mlir/Dialect/NamedTuple/IR/NamedTupleTypes.td"
19+
include "mlir/Dialect/NamedTuple/IR/NamedTupleOps.td"
20+
21+
#endif // NAMED_TUPLE
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This file is licensed 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 declares the NamedTuple dialect.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef MLIR_DIALECT_NAMED_TUPLE_IR_NAMED_TUPLE_DIALECT_H
14+
#define MLIR_DIALECT_NAMED_TUPLE_IR_NAMED_TUPLE_DIALECT_H
15+
16+
#include "mlir/IR/Dialect.h"
17+
18+
#include "mlir/Dialect/NamedTuple/IR/NamedTupleDialect.h.inc"
19+
20+
21+
#endif // MLIR_DIALECT_NAMED_TUPLE_IR_NAMED_TUPLE_DIALECT_H
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This file is licensed 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+
#ifndef NAMED_TUPLE_DIALECT
10+
#define NAMED_TUPLE_DIALECT
11+
12+
include "mlir/IR/DialectBase.td"
13+
14+
//===----------------------------------------------------------------------===//
15+
// NamedTuple dialect definition.
16+
//===----------------------------------------------------------------------===//
17+
18+
def NamedTuple_Dialect : Dialect {
19+
let name = "named_tuple";
20+
let summary = "NamedTuple dialect providing a tuple type with member names";
21+
let cppNamespace = "::mlir::named_tuple";
22+
let useDefaultTypePrinterParser = 1;
23+
}
24+
25+
#endif // NAMED_TUPLE_DIALECT

0 commit comments

Comments
 (0)