Skip to content

Commit 23883b5

Browse files
[mlir][Sol] Add calldata -> memory DataLocCast lowering for dynamic bytes/string
Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
1 parent d681f20 commit 23883b5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mlir/lib/Conversion/SolToStandard/SolToYul.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,25 @@ struct DataLocCastOpLowering : public OpConversionPattern<sol::DataLocCastOp> {
18941894
}
18951895
}
18961896

1897+
// From calldata to memory.
1898+
if (srcDataLoc == sol::DataLocation::CallData &&
1899+
dstDataLoc == sol::DataLocation::Memory) {
1900+
// String/bytes type.
1901+
if (isa<sol::StringType>(srcTy)) {
1902+
Value sizeInBytes = evmB.genDynSize(adaptor.getInp(), srcTy);
1903+
Value memAddr = evmB.genMemAllocForDynArray(
1904+
sizeInBytes, bExt.genRoundUpToMultiple<32>(sizeInBytes));
1905+
Value srcDataAddr = evmB.genDataAddrPtr(adaptor.getInp(), srcTy);
1906+
Value dstDataAddr =
1907+
r.create<arith::AddIOp>(loc, memAddr, bExt.genI256Const(32));
1908+
1909+
r.create<yul::CallDataCopyOp>(loc, dstDataAddr, srcDataAddr,
1910+
sizeInBytes);
1911+
r.replaceOp(op, memAddr);
1912+
return success();
1913+
}
1914+
}
1915+
18971916
llvm_unreachable("NYI");
18981917
return failure();
18991918
}

0 commit comments

Comments
 (0)