Skip to content

Commit b7a44bd

Browse files
committed
Convert basic cxx types to MLIR types
Currently map C++ basic types to MLIR built-in types as a temporary solution. Signed-off-by: Roberto Raggi <[email protected]>
1 parent 3fbd7fd commit b7a44bd

File tree

5 files changed

+238
-78
lines changed

5 files changed

+238
-78
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ jobs:
7272
run: |
7373
sudo apt-get -y update
7474
sudo apt-get install -y \
75-
llvm-18-dev \
76-
libmlir-18-dev \
77-
mlir-18-tools
75+
llvm-19-dev \
76+
libmlir-19-dev \
77+
mlir-19-tools
7878
7979
- name: Install unit tests requirements
8080
run: |
@@ -85,14 +85,13 @@ jobs:
8585
run: |
8686
. .venv/bin/activate
8787
88-
cmake . \
89-
-Bbuild \
90-
-DCMAKE_BUILD_TYPE=Release \
91-
-DCXX_ENABLE_MLIR=ON \
92-
-DMLIR_DIR=/usr/lib/llvm-18/lib/cmake/mlir
88+
cmake --preset default-mlir
9389
9490
cmake --build build --parallel
9591
92+
env:
93+
PATH: /usr/lib/llvm-19/bin:${{ env.PATH }}
94+
9695
- name: Test
9796
working-directory: build
9897
run: |

src/mlir/cxx/mlir/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ add_dependencies(cxx-mlir MLIRCxxOpsIncGen)
2828
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
2929

3030
target_compile_options(cxx-mlir PRIVATE
31-
$<$<COMPILE_LANGUAGE:CXX>:-Wno-all -Wno-extra -Wno-covered-switch-default>
31+
$<$<COMPILE_LANGUAGE:CXX>:-Wno-all -Wno-extra>
3232
)
3333

34+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
35+
target_compile_options(cxx-mlir PRIVATE
36+
$<$<COMPILE_LANGUAGE:CXX>:-Wno-covered-switch-default>
37+
)
38+
endif()
39+
3440
endif()

src/mlir/cxx/mlir/CxxOps.td

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,19 @@ class Cxx_Type<string name, string typeMnemonic, list<Trait> traits = []>
4242
class Cxx_Op<string mnemonic, list<Trait> traits = []>
4343
: Op<Cxx_Dialect, mnemonic, traits> {}
4444

45+
46+
// types
47+
4548
def Cxx_ExprType : Cxx_Type<"Expr", "expr">;
4649

50+
def Cxx_PointerType : Cxx_Type<"Pointer", "ptr"> {
51+
let parameters = (ins "Type":$elementType);
52+
53+
let assemblyFormat = "`<` $elementType `>`";
54+
}
55+
56+
// ops
57+
4758
def Cxx_FuncOp : Cxx_Op<"func", [FunctionOpInterface, IsolatedFromAbove]> {
4859
let arguments = (ins SymbolNameAttr:$sym_name,
4960
TypeAttrOf<FunctionType>:$function_type,
@@ -67,7 +78,7 @@ def Cxx_FuncOp : Cxx_Op<"func", [FunctionOpInterface, IsolatedFromAbove]> {
6778
}
6879

6980
def Cxx_ReturnOp : Cxx_Op<"return", [Pure, HasParent<"FuncOp">, Terminator]> {
70-
let arguments = (ins Variadic<Cxx_ExprType>:$input);
81+
let arguments = (ins Variadic<AnyType>:$input);
7182

7283
let builders = [OpBuilder<(ins), [{ build($_builder, $_state, {}); }]>];
7384

@@ -78,20 +89,7 @@ def Cxx_ReturnOp : Cxx_Op<"return", [Pure, HasParent<"FuncOp">, Terminator]> {
7889
let hasVerifier = 0;
7990
}
8091

81-
def Cxx_CallOp : Cxx_Op<"call"> {
82-
let arguments = (ins Cxx_ExprType:$callee, Variadic<AnyType>:$arguments);
83-
let results = (outs Cxx_ExprType:$result);
84-
let assemblyFormat =
85-
"$callee `(` $arguments `:` type($arguments) `)` attr-dict `:` "
86-
"type($result)";
87-
let builders =
88-
[OpBuilder<
89-
(ins "mlir::Value":$callee, "mlir::ValueRange":$arguments),
90-
[{ build($_builder, $_state, $_builder.getType<ExprType>(), callee, arguments); }]>,
91-
];
92-
}
93-
94-
def TodoExprOp : Cxx_Op<"todo.expr"> {
92+
def Cxx_TodoExprOp : Cxx_Op<"todo.expr"> {
9593
let arguments = (ins StrAttr:$message);
9694
let results = (outs Cxx_ExprType:$result);
9795
let assemblyFormat = "$message attr-dict `:` type($result)";
@@ -102,59 +100,8 @@ def TodoExprOp : Cxx_Op<"todo.expr"> {
102100
];
103101
}
104102

105-
def TodoStmtOp : Cxx_Op<"todo.stmt"> {
103+
def Cxx_TodoStmtOp : Cxx_Op<"todo.stmt"> {
106104
let arguments = (ins StrAttr:$message);
107105
let results = (outs);
108106
let assemblyFormat = "$message attr-dict";
109-
}
110-
111-
def ToBoolOp : Cxx_Op<"to.bool"> {
112-
let arguments = (ins Cxx_ExprType:$value);
113-
let results = (outs I1:$result);
114-
let assemblyFormat = "`(` $value `)` attr-dict `:` type($result)";
115-
}
116-
117-
def ImplicitCastOp : Cxx_Op<"implicit.cast"> {
118-
let arguments = (ins StrAttr:$cast, Cxx_ExprType:$value);
119-
let results = (outs Cxx_ExprType:$result);
120-
let assemblyFormat = "$cast `(` $value `)` attr-dict `:` type($result)";
121-
let builders =
122-
[OpBuilder<
123-
(ins "llvm::StringRef":$cast, "mlir::Value":$value),
124-
[{ build($_builder, $_state, $_builder.getType<ExprType>(), cast, value); }]>,
125-
];
126-
}
127-
128-
def IntLiteralOp : Cxx_Op<"int.literal"> {
129-
let arguments = (ins I64Attr:$value);
130-
let results = (outs Cxx_ExprType:$result);
131-
let assemblyFormat = "$value attr-dict `:` type($result)";
132-
let builders =
133-
[OpBuilder<
134-
(ins "int64_t":$value),
135-
[{ build($_builder, $_state, $_builder.getType<ExprType>(), value); }]>,
136-
];
137-
}
138-
139-
def IdOp : Cxx_Op<"id"> {
140-
let arguments = (ins StrAttr:$name);
141-
let results = (outs Cxx_ExprType:$result);
142-
let assemblyFormat = "$name attr-dict `:` type($result)";
143-
let builders =
144-
[OpBuilder<
145-
(ins "llvm::StringRef":$name),
146-
[{ build($_builder, $_state, $_builder.getType<ExprType>(), name); }]>,
147-
];
148-
}
149-
150-
def BinOp : Cxx_Op<"binary"> {
151-
let arguments = (ins StrAttr:$op, Cxx_ExprType:$lhs, Cxx_ExprType:$rhs);
152-
let results = (outs Cxx_ExprType:$result);
153-
let assemblyFormat =
154-
"`op` $op `(` $lhs `,` $rhs `)` attr-dict `:` type($result)";
155-
let builders =
156-
[OpBuilder<
157-
(ins "llvm::StringRef":$op, "mlir::Value":$lhs, "mlir::Value":$rhs),
158-
[{ build($_builder, $_state, $_builder.getType<ExprType>(), op, lhs, rhs); }]>,
159-
];
160-
}
107+
}

0 commit comments

Comments
 (0)