Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions libsolidity/codegen/mlir/SolidityToMLIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class SolidityToMLIRPass {
&identifiedStructsInProgress) const {
if (auto arrTy = mlir::dyn_cast<mlir::sol::ArrayType>(ty))
return mlir::sol::ArrayType::get(
b.getContext(), arrTy.getSize(),
b.getContext(), arrTy.getSizeOpt(),
toMemoryType(arrTy.getEltType(), identifiedStructsInProgress),
mlir::sol::DataLocation::Memory);
if (auto structTy = mlir::dyn_cast<mlir::sol::StructType>(ty)) {
Expand Down Expand Up @@ -737,11 +737,11 @@ mlir::Type SolidityToMLIRPass::getType(
mlir::Type eltTy = getType(arrTy->baseType(), /*indirectFn=*/true,
identifiedStructsInProgress);

// TODO: Does convert_to already do this?
assert(arrTy->length() <= INT64_MAX);
int64_t size = arrTy->isDynamicallySized()
? -1
: arrTy->length().convert_to<int64_t>();
std::optional<llvm::APInt> size =
arrTy->isDynamicallySized()
? /*size=*/std::nullopt
: std::optional<llvm::APInt>(
mlirgen::getAPInt(arrTy->length(), 256));
return mlir::sol::ArrayType::get(b.getContext(), size, eltTy,
getDataLocation(arrTy));
}
Expand All @@ -754,8 +754,8 @@ mlir::Type SolidityToMLIRPass::getType(

mlir::Type eltTy = getType(arrTy.baseType(), /*indirectFn=*/true,
identifiedStructsInProgress);
return mlir::sol::ArrayType::get(b.getContext(), /*size=*/-1, eltTy,
getDataLocation(&arrTy));
return mlir::sol::ArrayType::get(b.getContext(), /*size=*/std::nullopt,
eltTy, getDataLocation(&arrTy));
}
case Type::Category::Struct: {
const auto *structTy = static_cast<StructType const *>(ty);
Expand Down
331 changes: 169 additions & 162 deletions test/lit/mlirCodegen/EVM/abi-decode-storage.sol

Large diffs are not rendered by default.

1,089 changes: 506 additions & 583 deletions test/lit/mlirCodegen/EVM/abi-encode-struct.sol

Large diffs are not rendered by default.

334 changes: 177 additions & 157 deletions test/lit/mlirCodegen/EVM/array-copy.sol

Large diffs are not rendered by default.

666 changes: 666 additions & 0 deletions test/lit/mlirCodegen/EVM/array-huge-static.sol

Large diffs are not rendered by default.

260 changes: 138 additions & 122 deletions test/lit/mlirCodegen/EVM/array-pop-dyn.sol

Large diffs are not rendered by default.

573 changes: 240 additions & 333 deletions test/lit/mlirCodegen/EVM/array-pop-fixed-complex.sol

Large diffs are not rendered by default.

372 changes: 197 additions & 175 deletions test/lit/mlirCodegen/EVM/array-pop-struct-clear.sol

Large diffs are not rendered by default.

206 changes: 106 additions & 100 deletions test/lit/mlirCodegen/EVM/array-pop-struct.sol

Large diffs are not rendered by default.

1,812 changes: 817 additions & 995 deletions test/lit/mlirCodegen/EVM/bytes-to-storage-cleanup.sol

Large diffs are not rendered by default.

891 changes: 310 additions & 581 deletions test/lit/mlirCodegen/EVM/concat.sol

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/lit/mlirCodegen/EVM/delete-mapping-array.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ contract C {
function delFixed() public { delete fixedArr; }
function delDyn() public { delete dynArr; }
}

// NOTE: Assertions have been autogenerated by test/updFileCheckTest.py
// CHECK: #Default = #sol<RevertStrings Default>
// CHECK-NEXT: #Osaka = #sol<EvmVersion Osaka>
Expand Down
119 changes: 66 additions & 53 deletions test/lit/mlirCodegen/EVM/delete.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ contract Delete {
// CHECK-NEXT: #loc7 = loc({{.*}}:125:8)
// CHECK-NEXT: #loc10 = loc({{.*}}:119:8)
// CHECK-NEXT: #loc16 = loc({{.*}}:107:8)
// CHECK-NEXT: #loc19 = loc({{.*}}:101:8)
// CHECK-NEXT: #loc22 = loc({{.*}}:96:8)
// CHECK-NEXT: #loc37 = loc({{.*}}:78:8)
// CHECK-NEXT: #loc42 = loc({{.*}}:72:8)
// CHECK-NEXT: #loop_unroll = #llvm.loop_unroll<full = true>
// CHECK-NEXT: #loop_annotation = #llvm.loop_annotation<unroll = #loop_unroll>
// CHECK-NEXT: module @Delete_287 attributes {llvm.data_layout = "E-p:256:256-i256:256:256-S256-a:256:256", llvm.target_triple = "evm-unknown-unknown", sol.evm_version = #Osaka, sol.revert_strings = #Default} {
// CHECK-NEXT: func.func @".unreachable"() attributes {llvm.linkage = #llvm.linkage<private>, passthrough = ["nofree", "null_pointer_is_valid"]} {
// CHECK-NEXT: llvm.unreachable loc(#loc1)
Expand Down Expand Up @@ -575,42 +579,46 @@ contract Delete {
// CHECK-NEXT: func.func @deleteMixedStruct_279() attributes {llvm.linkage = #llvm.linkage<private>, passthrough = ["nofree", "null_pointer_is_valid"]} {
// CHECK-NEXT: %c21_i256 = arith.constant 21 : i256 loc(#loc)
// CHECK-NEXT: %c19_i256 = arith.constant 19 : i256 loc(#loc)
// CHECK-NEXT: %c18_i256 = arith.constant 18 : i256 loc(#loc)
// CHECK-NEXT: %c17_i256 = arith.constant 17 : i256 loc(#loc)
// CHECK-NEXT: %c32_i256 = arith.constant 32 : i256 loc(#loc)
// CHECK-NEXT: %c1_i256 = arith.constant 1 : i256 loc(#loc)
// CHECK-NEXT: %c3_i256 = arith.constant 3 : i256 loc(#loc)
// CHECK-NEXT: %c16_i256 = arith.constant 16 : i256 loc(#loc6)
// CHECK-NEXT: %c0_i256 = arith.constant 0 : i256 loc(#loc)
// CHECK-NEXT: %0 = llvm.inttoptr %c16_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %0 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %1 = llvm.inttoptr %c17_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %1 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %2 = llvm.inttoptr %c18_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %2 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %3 = llvm.inttoptr %c19_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %4 = llvm.load %3 {alignment = 1 : i64} : !llvm.ptr<5> -> i256 loc(#loc7)
// CHECK-NEXT: %5 = llvm.inttoptr %c19_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %5 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %6 = arith.cmpi ugt, %4, %c0_i256 : i256 loc(#loc7)
// CHECK-NEXT: cf.cond_br %6, ^bb1, ^bb4 loc(#loc7)
// CHECK-NEXT: ^bb1: // pred: ^bb0
// CHECK-NEXT: %7 = llvm.inttoptr %c0_i256 : i256 to !llvm.ptr<1> loc(#loc7)
// CHECK-NEXT: llvm.store %c19_i256, %7 {alignment = 1 : i64} : i256, !llvm.ptr<1> loc(#loc7)
// CHECK-NEXT: %8 = llvm.inttoptr %c0_i256 : i256 to !llvm.ptr<1> loc(#loc7)
// CHECK-NEXT: %9 = "llvm.intrcall"(%8, %c32_i256) <{id = 4085 : i32, name = "evm.sha3"}> : (!llvm.ptr<1>, i256) -> i256 loc(#loc7)
// CHECK-NEXT: cf.br ^bb2(%c0_i256 : i256) loc(#loc7)
// CHECK-NEXT: ^bb2(%10: i256 loc({{.*}}:125:8)): // 2 preds: ^bb1, ^bb3
// CHECK-NEXT: %11 = arith.cmpi ult, %10, %4 : i256 loc(#loc7)
// CHECK-NEXT: cf.cond_br %11, ^bb3(%10 : i256), ^bb4 loc(#loc7)
// CHECK-NEXT: ^bb3(%12: i256 loc({{.*}}:125:8)): // pred: ^bb2
// CHECK-NEXT: %13 = arith.addi %9, %12 : i256 loc(#loc7)
// CHECK-NEXT: %14 = llvm.inttoptr %13 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %14 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %15 = arith.addi %12, %c1_i256 : i256 loc(#loc7)
// CHECK-NEXT: cf.br ^bb2(%15 : i256) loc(#loc7)
// CHECK-NEXT: ^bb4: // 2 preds: ^bb0, ^bb2
// CHECK-NEXT: %16 = llvm.inttoptr %c21_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %16 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: cf.br ^bb1(%c0_i256 : i256) loc(#loc7)
// CHECK-NEXT: ^bb1(%0: i256 loc({{.*}}:125:8)): // 2 preds: ^bb0, ^bb2
// CHECK-NEXT: %1 = arith.cmpi ult, %0, %c3_i256 : i256 loc(#loc7)
// CHECK-NEXT: cf.cond_br %1, ^bb2(%0 : i256), ^bb3 loc(#loc7)
// CHECK-NEXT: ^bb2(%2: i256 loc({{.*}}:125:8)): // pred: ^bb1
// CHECK-NEXT: %3 = arith.addi %2, %c16_i256 : i256 loc(#loc7)
// CHECK-NEXT: %4 = llvm.inttoptr %3 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %4 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %5 = arith.addi %2, %c1_i256 : i256 loc(#loc7)
// CHECK-NEXT: cf.br ^bb1(%5 : i256) {loop_annotation = #loop_annotation} loc(#loc7)
// CHECK-NEXT: ^bb3: // pred: ^bb1
// CHECK-NEXT: %6 = llvm.inttoptr %c19_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %7 = llvm.load %6 {alignment = 1 : i64} : !llvm.ptr<5> -> i256 loc(#loc7)
// CHECK-NEXT: %8 = llvm.inttoptr %c19_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %8 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %9 = arith.cmpi ugt, %7, %c0_i256 : i256 loc(#loc7)
// CHECK-NEXT: cf.cond_br %9, ^bb4, ^bb7 loc(#loc7)
// CHECK-NEXT: ^bb4: // pred: ^bb3
// CHECK-NEXT: %10 = llvm.inttoptr %c0_i256 : i256 to !llvm.ptr<1> loc(#loc7)
// CHECK-NEXT: llvm.store %c19_i256, %10 {alignment = 1 : i64} : i256, !llvm.ptr<1> loc(#loc7)
// CHECK-NEXT: %11 = llvm.inttoptr %c0_i256 : i256 to !llvm.ptr<1> loc(#loc7)
// CHECK-NEXT: %12 = "llvm.intrcall"(%11, %c32_i256) <{id = 4085 : i32, name = "evm.sha3"}> : (!llvm.ptr<1>, i256) -> i256 loc(#loc7)
// CHECK-NEXT: cf.br ^bb5(%c0_i256 : i256) loc(#loc7)
// CHECK-NEXT: ^bb5(%13: i256 loc({{.*}}:125:8)): // 2 preds: ^bb4, ^bb6
// CHECK-NEXT: %14 = arith.cmpi ult, %13, %7 : i256 loc(#loc7)
// CHECK-NEXT: cf.cond_br %14, ^bb6(%13 : i256), ^bb7 loc(#loc7)
// CHECK-NEXT: ^bb6(%15: i256 loc({{.*}}:125:8)): // pred: ^bb5
// CHECK-NEXT: %16 = arith.addi %12, %15 : i256 loc(#loc7)
// CHECK-NEXT: %17 = llvm.inttoptr %16 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %17 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: %18 = arith.addi %15, %c1_i256 : i256 loc(#loc7)
// CHECK-NEXT: cf.br ^bb5(%18 : i256) loc(#loc7)
// CHECK-NEXT: ^bb7: // 2 preds: ^bb3, ^bb5
// CHECK-NEXT: %19 = llvm.inttoptr %c21_i256 : i256 to !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: llvm.store %c0_i256, %19 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc7)
// CHECK-NEXT: return loc(#loc5)
// CHECK-NEXT: } loc(#loc5)
// CHECK-NEXT: func.func @deleteMapArr2D_272() attributes {llvm.linkage = #llvm.linkage<private>, passthrough = ["nofree", "null_pointer_is_valid"]} {
Expand Down Expand Up @@ -680,19 +688,21 @@ contract Delete {
// CHECK-NEXT: return loc(#loc14)
// CHECK-NEXT: } loc(#loc14)
// CHECK-NEXT: func.func @deletePointFixed_251() attributes {llvm.linkage = #llvm.linkage<private>, passthrough = ["nofree", "null_pointer_is_valid"]} {
// CHECK-NEXT: %c12_i256 = arith.constant 12 : i256 loc(#loc)
// CHECK-NEXT: %c11_i256 = arith.constant 11 : i256 loc(#loc)
// CHECK-NEXT: %c10_i256 = arith.constant 10 : i256 loc(#loc)
// CHECK-NEXT: %c9_i256 = arith.constant 9 : i256 loc(#loc18)
// CHECK-NEXT: %c0_i256 = arith.constant 0 : i256 loc(#loc)
// CHECK-NEXT: %0 = llvm.inttoptr %c9_i256 : i256 to !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: llvm.store %c0_i256, %0 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: %1 = llvm.inttoptr %c10_i256 : i256 to !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: llvm.store %c0_i256, %1 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: %2 = llvm.inttoptr %c11_i256 : i256 to !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: llvm.store %c0_i256, %2 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: %3 = llvm.inttoptr %c12_i256 : i256 to !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: llvm.store %c0_i256, %3 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: %c4_i256 = arith.constant 4 : i256 loc(#loc19)
// CHECK-NEXT: %c1_i256 = arith.constant 1 : i256 loc(#loc19)
// CHECK-NEXT: cf.br ^bb1(%c0_i256 : i256) loc(#loc19)
// CHECK-NEXT: ^bb1(%0: i256 loc({{.*}}:101:8)): // 2 preds: ^bb0, ^bb2
// CHECK-NEXT: %1 = arith.cmpi ult, %0, %c4_i256 : i256 loc(#loc19)
// CHECK-NEXT: cf.cond_br %1, ^bb2(%0 : i256), ^bb3 loc(#loc19)
// CHECK-NEXT: ^bb2(%2: i256 loc({{.*}}:101:8)): // pred: ^bb1
// CHECK-NEXT: %3 = arith.addi %2, %c9_i256 : i256 loc(#loc19)
// CHECK-NEXT: %4 = llvm.inttoptr %3 : i256 to !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: llvm.store %c0_i256, %4 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc19)
// CHECK-NEXT: %5 = arith.addi %2, %c1_i256 : i256 loc(#loc19)
// CHECK-NEXT: cf.br ^bb1(%5 : i256) {loop_annotation = #loop_annotation} loc(#loc19)
// CHECK-NEXT: ^bb3: // pred: ^bb1
// CHECK-NEXT: return loc(#loc17)
// CHECK-NEXT: } loc(#loc17)
// CHECK-NEXT: func.func @deletePointArr_244() attributes {llvm.linkage = #llvm.linkage<private>, passthrough = ["nofree", "null_pointer_is_valid"]} {
Expand Down Expand Up @@ -865,25 +875,30 @@ contract Delete {
// CHECK-NEXT: return loc(#loc34)
// CHECK-NEXT: } loc(#loc34)
// CHECK-NEXT: func.func @deleteStaticArr_176() attributes {llvm.linkage = #llvm.linkage<private>, passthrough = ["nofree", "null_pointer_is_valid"]} {
// CHECK-NEXT: %c3_i256 = arith.constant 3 : i256 loc(#loc)
// CHECK-NEXT: %c6_i256 = arith.constant 6 : i256 loc(#loc)
// CHECK-NEXT: %c2_i256 = arith.constant 2 : i256 loc(#loc)
// CHECK-NEXT: %c5_i256 = arith.constant 5 : i256 loc(#loc)
// CHECK-NEXT: %c3_i256 = arith.constant 3 : i256 loc(#loc)
// CHECK-NEXT: %c1_i256 = arith.constant 1 : i256 loc(#loc)
// CHECK-NEXT: %c0_i256 = arith.constant 0 : i256 loc(#loc)
// CHECK-NEXT: %c4_i256 = arith.constant 4 : i256 loc(#loc)
// CHECK-NEXT: %c1_i256 = arith.constant 1 : i256 loc(#loc39)
// CHECK-NEXT: %0 = llvm.inttoptr %c4_i256 : i256 to !llvm.ptr<5> loc(#loc39)
// CHECK-NEXT: llvm.store %c1_i256, %0 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc39)
// CHECK-NEXT: %1 = llvm.inttoptr %c5_i256 : i256 to !llvm.ptr<5> loc(#loc40)
// CHECK-NEXT: llvm.store %c2_i256, %1 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc40)
// CHECK-NEXT: %2 = llvm.inttoptr %c6_i256 : i256 to !llvm.ptr<5> loc(#loc41)
// CHECK-NEXT: llvm.store %c3_i256, %2 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc41)
// CHECK-NEXT: %3 = llvm.inttoptr %c4_i256 : i256 to !llvm.ptr<5> loc(#loc42)
// CHECK-NEXT: llvm.store %c0_i256, %3 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc42)
// CHECK-NEXT: %4 = llvm.inttoptr %c5_i256 : i256 to !llvm.ptr<5> loc(#loc42)
// CHECK-NEXT: llvm.store %c0_i256, %4 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc42)
// CHECK-NEXT: %5 = llvm.inttoptr %c6_i256 : i256 to !llvm.ptr<5> loc(#loc42)
// CHECK-NEXT: llvm.store %c0_i256, %5 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc42)
// CHECK-NEXT: cf.br ^bb1(%c0_i256 : i256) loc(#loc42)
// CHECK-NEXT: ^bb1(%3: i256 loc({{.*}}:72:8)): // 2 preds: ^bb0, ^bb2
// CHECK-NEXT: %4 = arith.cmpi ult, %3, %c3_i256 : i256 loc(#loc42)
// CHECK-NEXT: cf.cond_br %4, ^bb2(%3 : i256), ^bb3 loc(#loc42)
// CHECK-NEXT: ^bb2(%5: i256 loc({{.*}}:72:8)): // pred: ^bb1
// CHECK-NEXT: %6 = arith.addi %5, %c4_i256 : i256 loc(#loc42)
// CHECK-NEXT: %7 = llvm.inttoptr %6 : i256 to !llvm.ptr<5> loc(#loc42)
// CHECK-NEXT: llvm.store %c0_i256, %7 {alignment = 1 : i64} : i256, !llvm.ptr<5> loc(#loc42)
// CHECK-NEXT: %8 = arith.addi %5, %c1_i256 : i256 loc(#loc42)
// CHECK-NEXT: cf.br ^bb1(%8 : i256) {loop_annotation = #loop_annotation} loc(#loc42)
// CHECK-NEXT: ^bb3: // pred: ^bb1
// CHECK-NEXT: return loc(#loc38)
// CHECK-NEXT: } loc(#loc38)
// CHECK-NEXT: func.func @deleteStaticElem_151() attributes {llvm.linkage = #llvm.linkage<private>, passthrough = ["nofree", "null_pointer_is_valid"]} {
Expand Down Expand Up @@ -981,7 +996,6 @@ contract Delete {
// CHECK-NEXT: #loc15 = loc({{.*}}:27:4)
// CHECK-NEXT: #loc17 = loc({{.*}}:100:4)
// CHECK-NEXT: #loc18 = loc({{.*}}:26:4)
// CHECK-NEXT: #loc19 = loc({{.*}}:101:8)
// CHECK-NEXT: #loc20 = loc({{.*}}:95:4)
// CHECK-NEXT: #loc21 = loc({{.*}}:25:4)
// CHECK-NEXT: #loc23 = loc({{.*}}:88:4)
Expand All @@ -1002,7 +1016,6 @@ contract Delete {
// CHECK-NEXT: #loc39 = loc({{.*}}:71:8)
// CHECK-NEXT: #loc40 = loc({{.*}}:71:26)
// CHECK-NEXT: #loc41 = loc({{.*}}:71:44)
// CHECK-NEXT: #loc42 = loc({{.*}}:72:8)
// CHECK-NEXT: #loc43 = loc({{.*}}:64:4)
// CHECK-NEXT: #loc44 = loc({{.*}}:65:8)
// CHECK-NEXT: #loc45 = loc({{.*}}:65:26)
Expand Down
Loading