Skip to content

Commit 8b3e545

Browse files
committed
[mlir] Move yul ops to the new yul dialect
1 parent a052713 commit 8b3e545

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+448
-729
lines changed

libsolidity/codegen/mlir/FuseFreePtr.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//
2121

2222
#include "libsolidity/codegen/mlir/Passes.h"
23-
#include "libsolidity/codegen/mlir/Sol/Sol.h"
23+
#include "libsolidity/codegen/mlir/Yul/Yul.h"
2424
#include "mlir/Dialect/Arith/IR/Arith.h"
2525
#include "mlir/IR/Builders.h"
2626
#include "mlir/IR/Dominance.h"
@@ -51,7 +51,7 @@ struct FuseFreePtr : public PassWrapper<FuseFreePtr, OperationPass<>> {
5151
if (blk.empty())
5252
return;
5353

54-
SmallVector<sol::UpdFreePtrOp, 4> updOps;
54+
SmallVector<yul::UpdFreePtrOp, 4> updOps;
5555
SmallPtrSet<Operation *, 4> updOpsUsers;
5656

5757
auto fuseAndReset = [&]() {
@@ -67,7 +67,7 @@ struct FuseFreePtr : public PassWrapper<FuseFreePtr, OperationPass<>> {
6767
fuseAndReset();
6868
continue;
6969
}
70-
if (auto updOp = dyn_cast<sol::UpdFreePtrOp>(op)) {
70+
if (auto updOp = dyn_cast<yul::UpdFreePtrOp>(op)) {
7171
for (Operation *user : updOp->getUsers())
7272
updOpsUsers.insert(user);
7373
updOps.push_back(updOp);
@@ -78,17 +78,17 @@ struct FuseFreePtr : public PassWrapper<FuseFreePtr, OperationPass<>> {
7878

7979
/// Fuses all the UpdFreePtrOps into one at the last op so that the use-graph
8080
/// is not broken. This expects the user-graph to be dominated by the last op.
81-
void fuse(ArrayRef<sol::UpdFreePtrOp> updOps) {
81+
void fuse(ArrayRef<yul::UpdFreePtrOp> updOps) {
8282
if (updOps.size() < 2)
8383
return;
8484

8585
// Generate the total size of allocated area after all the UpdFreePtrOps.
8686
count += updOps.size();
87-
sol::UpdFreePtrOp firstUpd = updOps.front();
87+
yul::UpdFreePtrOp firstUpd = updOps.front();
8888
IRRewriter r(firstUpd);
8989
SmallVector<Location> fusedLocs{firstUpd.getLoc()};
9090
mlir::Value totalSize = firstUpd.getSize();
91-
for (sol::UpdFreePtrOp updOp : llvm::drop_begin(updOps)) {
91+
for (yul::UpdFreePtrOp updOp : llvm::drop_begin(updOps)) {
9292
fusedLocs.push_back(updOp.getLoc());
9393
r.setInsertionPoint(updOp);
9494
totalSize =
@@ -97,15 +97,15 @@ struct FuseFreePtr : public PassWrapper<FuseFreePtr, OperationPass<>> {
9797

9898
// Generate the fused UpdFreePtrOp. The users of this will be the users of
9999
// the original first UpdFreePtrOp.
100-
auto fusedUpd = r.create<sol::UpdFreePtrOp>(
100+
auto fusedUpd = r.create<yul::UpdFreePtrOp>(
101101
FusedLoc::get(r.getContext(), fusedLocs), totalSize);
102102
r.replaceAllOpUsesWith(updOps.front(), fusedUpd);
103103

104104
// The remaining UpdFreePtrOps are generated as add ops and the users are
105105
// updated accordingly.
106-
sol::UpdFreePtrOp prevUpdOp = updOps.front();
106+
yul::UpdFreePtrOp prevUpdOp = updOps.front();
107107
mlir::Value prevFreePtr = fusedUpd;
108-
for (sol::UpdFreePtrOp updOp : llvm::drop_begin(updOps)) {
108+
for (yul::UpdFreePtrOp updOp : llvm::drop_begin(updOps)) {
109109
auto add = r.create<arith::AddIOp>(updOp.getLoc(), prevFreePtr,
110110
prevUpdOp.getSize());
111111
r.replaceAllOpUsesWith(updOp, add);
@@ -114,7 +114,7 @@ struct FuseFreePtr : public PassWrapper<FuseFreePtr, OperationPass<>> {
114114
}
115115

116116
// Erase all original UpdFreePtrOps.
117-
for (sol::UpdFreePtrOp updOp : updOps)
117+
for (yul::UpdFreePtrOp updOp : updOps)
118118
r.eraseOp(updOp);
119119
}
120120

libsolidity/codegen/mlir/Sol/SolOps.td

Lines changed: 0 additions & 288 deletions
Original file line numberDiff line numberDiff line change
@@ -717,292 +717,4 @@ def Sol_ContractOp : Sol_Op<"contract", [Symbol, SymbolTable, SingleBlock,
717717
let assemblyFormat = "$sym_name $bodyRegion attr-dict";
718718
}
719719

720-
//
721-
// TODO? Move the rest of the ops to the yul dialect?
722-
//
723-
724-
def Sol_UpdFreePtrOp : Sol_Op<"upd_free_ptr"> {
725-
let arguments = (ins I256:$size);
726-
let results = (outs I256:$out);
727-
let assemblyFormat = "$size attr-dict";
728-
}
729-
730-
def Sol_ObjectOp : Sol_Op<"object", [Symbol, SymbolTable, NoTerminator,
731-
IsolatedFromAbove]> {
732-
let arguments = (ins SymbolNameAttr:$sym_name);
733-
let regions = (region AnyRegion:$body);
734-
735-
let builders = [
736-
OpBuilder<(ins CArg<"StringRef", "{}">:$name),[{
737-
$_state.addRegion()->emplaceBlock();
738-
$_state.addAttribute(getSymNameAttrName($_state.name),
739-
$_builder.getStringAttr(name));
740-
}]>
741-
];
742-
let skipDefaultBuilders = 1;
743-
744-
let extraClassDeclaration = [{
745-
Block *getEntryBlock() { return &getBody().front(); }
746-
}];
747-
748-
let assemblyFormat = "$sym_name $body attr-dict";
749-
}
750-
751-
//
752-
// We could auto-generate the following evm builtin ops from
753-
// evmasm::InstructionInfo. But I don't think it's worth the effort.
754-
//
755-
756-
def Sol_CallerOp : Sol_Op<"caller", [Pure]> {
757-
let summary = "Represents the `caller` call in yul";
758-
let results = (outs I256:$out);
759-
let assemblyFormat = "attr-dict";
760-
}
761-
762-
def Sol_GasOp : Sol_Op<"gas", [Pure]> {
763-
let summary = "Represents the `gas` call in yul";
764-
let results = (outs I256:$out);
765-
let assemblyFormat = "attr-dict";
766-
}
767-
768-
def Sol_AddressOp : Sol_Op<"address", [Pure]> {
769-
let summary = "Represents the `address` call in yul";
770-
let results = (outs I256:$out);
771-
let assemblyFormat = "attr-dict";
772-
}
773-
774-
def Sol_BuiltinCallOp : Sol_Op<"builtin_call"> {
775-
let summary = "Represents the `call` call in yul";
776-
let arguments = (ins I256:$gas, I256:$address, I256:$value, I256:$inpOffset,
777-
I256:$inpSize, I256:$outOffset, I256:$outSize);
778-
let results = (outs I256:$status);
779-
let assemblyFormat = [{
780-
$gas `,` $address `,` $value `,` $inpOffset `,` $inpSize `,` $outOffset `,`
781-
$outSize attr-dict
782-
}];
783-
}
784-
785-
def Sol_StaticCallOp : Sol_Op<"static_call"> {
786-
let summary = "Represents the `staticcall` call in yul";
787-
let arguments = (ins I256:$gas, I256:$address, I256:$inpOffset,
788-
I256:$inpSize, I256:$outOffset, I256:$outSize);
789-
let results = (outs I256:$out);
790-
let assemblyFormat = [{
791-
$gas `,` $address `,` $inpOffset `,` $inpSize `,` $outOffset `,`
792-
$outSize attr-dict
793-
}];
794-
}
795-
796-
def Sol_DelegateCallOp : Sol_Op<"delegate_call"> {
797-
let summary = "Represents the `delegatecall` call in yul";
798-
let arguments = (ins I256:$gas, I256:$address, I256:$inpOffset,
799-
I256:$inpSize, I256:$outOffset, I256:$outSize);
800-
let results = (outs I256:$out);
801-
let assemblyFormat = [{
802-
$gas `,` $address `,` $inpOffset `,` $inpSize `,` $outOffset `,`
803-
$outSize attr-dict
804-
}];
805-
}
806-
807-
def Sol_BuiltinRetOp : Sol_Op<"builtin_ret"> {
808-
let summary = "Represents the `return` call in yul";
809-
let arguments = (ins I256:$addr, I256:$size);
810-
let assemblyFormat = "$addr `,` $size attr-dict";
811-
}
812-
813-
def Sol_RevertOp : Sol_Op<"revert"> {
814-
let summary = "Represents the `revert` call in yul";
815-
// TODO: Support revert strings.
816-
let arguments = (ins I256:$addr, I256:$size);
817-
let assemblyFormat = "$addr `,` $size attr-dict";
818-
}
819-
820-
def Sol_StopOp : Sol_Op<"stop"> {
821-
let summary = "Represents the `stop` call in yul";
822-
let assemblyFormat = "attr-dict";
823-
}
824-
825-
def Sol_MLoadOp : Sol_Op<"mload"> {
826-
let summary = "Represents the `mload` call in yul";
827-
let arguments = (ins I256:$addr);
828-
let results = (outs I256:$out);
829-
let assemblyFormat = "$addr attr-dict";
830-
}
831-
832-
def Sol_MStoreOp : Sol_Op<"mstore"> {
833-
let summary = "Represents the `mstore` call in yul";
834-
let arguments = (ins I256:$addr, I256:$val);
835-
let assemblyFormat = "$addr `,` $val attr-dict";
836-
}
837-
838-
def Sol_MStore8Op : Sol_Op<"mstore8"> {
839-
let summary = "Represents the `mstore8` call in yul";
840-
let arguments = (ins I256:$addr, I256:$val);
841-
let assemblyFormat = "$addr `,` $val attr-dict";
842-
}
843-
844-
def Sol_ByteOp : Sol_Op<"byte"> {
845-
let summary = "Represents the `byte` call in yul";
846-
let arguments = (ins I256:$idx, I256:$val);
847-
let results = (outs I256:$out);
848-
let assemblyFormat = "$idx `,` $val attr-dict";
849-
}
850-
851-
def Sol_MCopyOp : Sol_Op<"mcopy"> {
852-
let summary = "Represents the `mcopy` call in yul";
853-
let arguments = (ins I256:$dst, I256:$src, I256:$size);
854-
let assemblyFormat = "$dst `,` $src `,` $size attr-dict";
855-
}
856-
857-
def Sol_MSizeOp : Sol_Op<"msize", [Pure]> {
858-
let summary = "Represents the `msize` call in yul";
859-
let results = (outs I256:$out);
860-
let assemblyFormat = "attr-dict";
861-
}
862-
863-
def Sol_CallValOp : Sol_Op<"callvalue", [Pure]> {
864-
let summary = "Represents the `callvalue` call in yul";
865-
let results = (outs I256:$out);
866-
let assemblyFormat = "attr-dict";
867-
}
868-
869-
def Sol_CallDataLoadOp : Sol_Op<"calldataload"> {
870-
let summary = "Represents the `calldataload` call in yul";
871-
let arguments = (ins I256:$addr);
872-
let results = (outs I256:$out);
873-
let assemblyFormat = "$addr attr-dict";
874-
}
875-
876-
def Sol_CallDataSizeOp : Sol_Op<"calldatasize", [Pure]> {
877-
let summary = "Represents the `calldatasize` call in yul";
878-
let results = (outs I256:$out);
879-
let assemblyFormat = "attr-dict";
880-
}
881-
882-
def Sol_CallDataCopyOp : Sol_Op<"calldatacopy"> {
883-
let summary = "Represents the `calldatacopy` call in yul";
884-
let arguments = (ins I256:$dst, I256:$src, I256:$size);
885-
let assemblyFormat = "$dst `,` $src `,` $size attr-dict";
886-
}
887-
888-
def Sol_ReturnDataSizeOp : Sol_Op<"returndatasize", [Pure]> {
889-
let summary = "Represents the `returndatasize` call in yul";
890-
let results = (outs I256:$out);
891-
let assemblyFormat = "attr-dict";
892-
}
893-
894-
def Sol_ReturnDataCopyOp : Sol_Op<"returndatacopy"> {
895-
let summary = "Represents the `returndatacopy` call in yul";
896-
let arguments = (ins I256:$dst, I256:$src, I256:$size);
897-
let assemblyFormat = "$dst `,` $src `,` $size attr-dict";
898-
}
899-
900-
def Sol_SLoadOp : Sol_Op<"sload"> {
901-
let summary = "Represents the `sload` call in yul";
902-
let arguments = (ins I256:$addr);
903-
let results = (outs I256:$out);
904-
let assemblyFormat = "$addr attr-dict";
905-
}
906-
907-
def Sol_SStoreOp : Sol_Op<"sstore"> {
908-
let summary = "Represents the `sstore` call in yul";
909-
let arguments = (ins I256:$addr, I256:$val);
910-
let assemblyFormat = "$addr `,` $val attr-dict";
911-
}
912-
913-
// TODO: Support symbolic references to objects outside the current symbol table
914-
// (including ones outside the translation unit) using SymbolRefAttr instead of
915-
// FlatSymbolRefAttr
916-
917-
def Sol_DataOffsetOp : Sol_Op<"dataoffset", [Pure]> {
918-
let summary = "Represents the `dataoffset` call in yul";
919-
let arguments = (ins FlatSymbolRefAttr:$obj);
920-
let results = (outs I256:$out);
921-
let assemblyFormat = "attr-dict";
922-
}
923-
924-
def Sol_DataSizeOp : Sol_Op<"datasize", [Pure]> {
925-
let summary = "Represents the `datasize` call in yul";
926-
let arguments = (ins FlatSymbolRefAttr:$obj);
927-
let results = (outs I256:$out);
928-
let assemblyFormat = "attr-dict";
929-
}
930-
931-
def Sol_CodeSizeOp : Sol_Op<"codesize", [Pure]> {
932-
let summary = "Represents the `codesize` call in yul";
933-
let results = (outs I256:$out);
934-
let assemblyFormat = "attr-dict";
935-
}
936-
937-
def Sol_CodeCopyOp : Sol_Op<"codecopy"> {
938-
let summary = "Represents the `codecopy` call in yul";
939-
let arguments = (ins I256:$dst, I256:$src, I256:$size);
940-
let assemblyFormat = "$dst `,` $src `,` $size attr-dict";
941-
}
942-
943-
def Sol_ExtCodeSizeOp : Sol_Op<"extcodesize", [Pure]> {
944-
let summary = "Represents the `extcodesize` call in yul";
945-
let arguments = (ins I256:$addr);
946-
let results = (outs I256:$out);
947-
let assemblyFormat = "$addr attr-dict";
948-
}
949-
950-
def Sol_CreateOp : Sol_Op<"create"> {
951-
let summary = "Represents the `create` call in yul";
952-
let arguments = (ins I256:$val, I256:$addr, I256:$size);
953-
let results = (outs I256:$out);
954-
let assemblyFormat = "$val `,` $addr `,` $size attr-dict";
955-
}
956-
957-
def Sol_Create2Op : Sol_Op<"create2"> {
958-
let summary = "Represents the `create2` call in yul";
959-
let arguments = (ins I256:$val, I256:$addr, I256:$size, I256:$salt);
960-
let results = (outs I256:$out);
961-
let assemblyFormat = "$val `,` $addr `,` $size `,` $salt attr-dict";
962-
}
963-
964-
// TODO: Is this `ConstantLike`? Adding it causes "expected ConstantLike op to
965-
// be foldable" assert fail (probably due to the missing let hasFolder = 1).
966-
def Sol_MemGuardOp : Sol_Op<"memoryguard", [Pure]> {
967-
let summary = "Represents the `memoryguard` call in yul";
968-
let arguments = (ins I256Attr:$size);
969-
let results = (outs I256:$out);
970-
let assemblyFormat = "$size attr-dict";
971-
}
972-
973-
def Sol_Keccak256Op : Sol_Op<"keccak256"> {
974-
// Note that the keccak256 yul builtin has side effects.
975-
let summary = "Represents the `keccak256` call in yul";
976-
let arguments = (ins I256:$addr, I256:$size);
977-
let results = (outs I256:$out);
978-
let assemblyFormat = "$addr `,` $size attr-dict";
979-
}
980-
981-
def Sol_LogOp : Sol_Op<"log"> {
982-
let summary = "Represents the `log*` calls in yul";
983-
let arguments = (ins I256:$addr, I256:$size, Variadic<I256>:$topics);
984-
// FIXME: Trailing spaces with empty $topics.
985-
let assemblyFormat = "$addr `,` $size oilist(`topics` `(` $topics `)` ) attr-dict";
986-
}
987-
988-
def Sol_SetImmutableOp : Sol_Op<"setimmutable"> {
989-
let summary = "Represents the `setimmutable` call in yul";
990-
let arguments = (ins I256:$addr, StrAttr:$name, I256:$val);
991-
let assemblyFormat = "$addr `,` $name `,` $val attr-dict";
992-
}
993-
994-
def Sol_LoadImmutable2Op : Sol_Op<"loadimmutable"> {
995-
let summary = "Represents the `loadimmutable` call in yul";
996-
let arguments = (ins StrAttr:$name);
997-
let results = (outs I256:$out);
998-
let assemblyFormat = "$name attr-dict";
999-
}
1000-
1001-
def Sol_LinkerSymbolOp : Sol_Op<"linkersymbol"> {
1002-
let summary = "Represents the `linkersymbol` call in yul";
1003-
let arguments = (ins StrAttr:$name);
1004-
let results = (outs I256:$out);
1005-
let assemblyFormat = "$name attr-dict";
1006-
}
1007-
1008720
#endif // MLIR_SOL_SOLOPS_TD

0 commit comments

Comments
 (0)