Skip to content

Commit a052713

Browse files
committed
[mlir] Define yul dialect
1 parent 637f205 commit a052713

File tree

8 files changed

+502
-1
lines changed

8 files changed

+502
-1
lines changed

libsolidity/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,14 @@ set(mlir_sol_dialect_sources
242242
codegen/mlir/Sol/SolOps.cpp
243243
)
244244

245-
include_directories(${PROJECT_BINARY_DIR}/libsolidity/codegen/mlir)
245+
set(mlir_yul_dialect_sources
246+
codegen/mlir/Yul/YulBase.cpp
247+
codegen/mlir/Yul/YulOps.cpp
248+
)
246249

250+
include_directories(${PROJECT_BINARY_DIR}/libsolidity/codegen/mlir)
247251
add_subdirectory(codegen/mlir/Sol)
252+
add_subdirectory(codegen/mlir/Yul)
248253

249254
add_mlir_dialect_library(MLIRSolDialect
250255
${mlir_sol_dialect_sources}
@@ -256,6 +261,15 @@ add_mlir_dialect_library(MLIRSolDialect
256261
LINK_LIBS PUBLIC
257262
)
258263

264+
add_mlir_dialect_library(MLIRYulDialect
265+
${mlir_yul_dialect_sources}
266+
267+
DEPENDS
268+
MLIRYulOpsIncGen
269+
270+
LINK_LIBS PUBLIC
271+
)
272+
259273
# FIXME: Remove this once we're good with the fine-grained library dependencies.
260274
# get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
261275
# get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
@@ -275,6 +289,7 @@ add_mlir_dialect_library(MLIRSolDialect
275289

276290
set(mlir_libs
277291
MLIRSolDialect
292+
MLIRYulDialect
278293
MLIRFuncDialect
279294
MLIRSCFDialect
280295
MLIRArithDialect
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_mlir_doc(YulDialect YulDialect Yul/ -gen-dialect-doc)
2+
add_mlir_doc(YulOps YulOps Yul/ -gen-op-doc)
3+
4+
# Create MLIRYulOpsIncGen.
5+
add_mlir_dialect(YulOps yul)
6+
7+
# Generate sources from YulOps.td.
8+
set(LLVM_TARGET_DEFINITIONS YulOps.td)

libsolidity/codegen/mlir/Yul/Yul.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This file is part of solidity.
2+
3+
// solidity is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
8+
// solidity is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
13+
// You should have received a copy of the GNU General Public License
14+
// along with solidity. If not, see <http://www.gnu.org/licenses/>.
15+
16+
// SPDX-License-Identifier: GPL-3.0
17+
18+
//
19+
// Yul dialect
20+
//
21+
22+
#pragma once
23+
24+
#include "mlir/IR/BuiltinOps.h"
25+
#include "mlir/IR/BuiltinTypes.h"
26+
#include "mlir/IR/Dialect.h"
27+
#include "mlir/IR/OpDefinition.h"
28+
#include "mlir/IR/SymbolTable.h"
29+
#include "mlir/IR/Types.h"
30+
#include "mlir/Interfaces/CastInterfaces.h"
31+
#include "mlir/Interfaces/InferTypeOpInterface.h"
32+
#include "mlir/Interfaces/SideEffectInterfaces.h"
33+
34+
#include "Yul/YulOpsDialect.h.inc"
35+
36+
#define GET_OP_CLASSES
37+
#include "Yul/YulOps.h.inc"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file is part of solidity.
2+
3+
// solidity is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
8+
// solidity is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
13+
// You should have received a copy of the GNU General Public License
14+
// along with solidity. If not, see <http://www.gnu.org/licenses/>.
15+
16+
// SPDX-License-Identifier: GPL-3.0
17+
18+
#include "Yul.h"
19+
#include "mlir/Dialect/Arith/IR/Arith.h"
20+
21+
#include "Yul/YulOpsDialect.cpp.inc"
22+
23+
using namespace mlir;
24+
using namespace mlir::yul;
25+
26+
void YulDialect::initialize() {
27+
addOperations<
28+
#define GET_OP_LIST
29+
#include "Yul/YulOps.cpp.inc"
30+
>();
31+
}
32+
33+
Operation *YulDialect::materializeConstant(OpBuilder &builder, Attribute val,
34+
Type type, Location loc) {
35+
return builder.create<arith::ConstantOp>(loc, type, cast<TypedAttr>(val));
36+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This file is part of solidity.
2+
3+
// solidity is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
8+
// solidity is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
13+
// You should have received a copy of the GNU General Public License
14+
// along with solidity. If not, see <http://www.gnu.org/licenses/>.
15+
16+
// SPDX-License-Identifier: GPL-3.0
17+
18+
//
19+
// Yul dialect
20+
//
21+
22+
#ifndef MLIR_YUL_YULBASE_TD
23+
#define MLIR_YUL_YULBASE_TD
24+
25+
include "mlir/IR/OpBase.td"
26+
include "mlir/Interfaces/InferTypeOpInterface.td"
27+
include "mlir/Interfaces/SideEffectInterfaces.td"
28+
29+
//===----------------------------------------------------------------------===//
30+
// Dialect
31+
//===----------------------------------------------------------------------===//
32+
33+
def Yul_Dialect : Dialect {
34+
let name = "yul";
35+
let cppNamespace = "::mlir::yul";
36+
let hasConstantMaterializer = 1;
37+
}
38+
39+
//===----------------------------------------------------------------------===//
40+
// Types
41+
//===----------------------------------------------------------------------===//
42+
43+
def I256 : I<256>;
44+
45+
//===----------------------------------------------------------------------===//
46+
// Attributes
47+
//===----------------------------------------------------------------------===//
48+
49+
def I256Attr : SignlessIntegerAttrBase<I256,
50+
"256-bit signless integer attribute">;
51+
52+
//===----------------------------------------------------------------------===//
53+
// Op classes
54+
//===----------------------------------------------------------------------===//
55+
56+
class Yul_Op<string mnemonic, list<Trait> traits = []> : Op<Yul_Dialect,
57+
mnemonic, traits>;
58+
59+
#endif // MLIR_YUL_YULBASE_TD
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This file is part of solidity.
2+
3+
// solidity is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
8+
// solidity is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
13+
// You should have received a copy of the GNU General Public License
14+
// along with solidity. If not, see <http://www.gnu.org/licenses/>.
15+
16+
// SPDX-License-Identifier: GPL-3.0
17+
18+
#include "Yul.h"
19+
#include "mlir/IR/BuiltinAttributes.h"
20+
#include "mlir/IR/OpImplementation.h"
21+
#include "mlir/IR/ValueRange.h"
22+
23+
using namespace mlir;
24+
using namespace mlir::yul;
25+
26+
#define GET_OP_CLASSES
27+
#include "Yul/YulOps.cpp.inc"

0 commit comments

Comments
 (0)