From 8e9307beca02cff61caad05bdb3d3a6a37538b89 Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Fri, 22 Nov 2024 16:58:59 +0100 Subject: [PATCH 1/2] ll: Add Memcpy op. --- include/vast/Dialect/LowLevel/LowLevelOps.td | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/vast/Dialect/LowLevel/LowLevelOps.td b/include/vast/Dialect/LowLevel/LowLevelOps.td index 4867ff2e20..6e1418c87b 100644 --- a/include/vast/Dialect/LowLevel/LowLevelOps.td +++ b/include/vast/Dialect/LowLevel/LowLevelOps.td @@ -385,4 +385,10 @@ def LowLevel_FuncOp : Core_FuncBaseOp< LowLevel_Dialect, "func", [ IsolatedFromAbove ] > {} +def LowLevel_MemcpyOp : LowLevel_Op < "memcpy" > + , Arguments<(ins AnyType:$dst, AnyType:$src, TypedAttrInterface:$size, BoolAttr:$isVolatile)> +{ + let summary = "Memcopy intrinsic."; +} + #endif // VAST_DIALECT_IR_LOWLEVELOPS From ee3c20453b23e538757db8b41bf39e11f6ea0ae0 Mon Sep 17 00:00:00 2001 From: Robert Konicar Date: Fri, 22 Nov 2024 16:59:57 +0100 Subject: [PATCH 2/2] conv:abi: Do memcpy instead of load on indirect when possible. --- lib/vast/Conversion/ABI/LowerABI.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/vast/Conversion/ABI/LowerABI.cpp b/lib/vast/Conversion/ABI/LowerABI.cpp index c6360d295e..32f1f9664c 100644 --- a/lib/vast/Conversion/ABI/LowerABI.cpp +++ b/lib/vast/Conversion/ABI/LowerABI.cpp @@ -453,12 +453,28 @@ namespace vast { auto loc = indirect.getLoc(); auto mctx = indirect.getContext(); - auto type = hl::PointerType::get(mctx, indirect.getValue().getType()); - + auto indirect_val = indirect.getValue(); + auto type = hl::PointerType::get(mctx, indirect_val.getType()); auto var = state.rewriter.template create< ll::Alloca >( indirect.getLoc(), type); + // Now we initilizae before yielding the ptr - state.rewriter.template create< ll::Store >(loc, indirect.getValue(), var); + if (auto load = mlir::dyn_cast< ll::Load >(indirect_val.getDefiningOp())) { + size_t bits = dl.getTypeSizeInBits(indirect_val.getType()); + size_t bytes = dl.getTypeSize(indirect_val.getType()); + state.rewriter.template create< ll::MemcpyOp >( + loc, + load.getPtr(), + var, + mlir::IntegerAttr::get(mlir::IntegerType::get(mctx, bytes), bits), + // FIXME: + mlir::BoolAttr::get(mctx, false) /*isVolatile*/ + ); + state.rewriter.eraseOp(load); + + } else { + state.rewriter.template create< ll::Store >(loc, indirect_val, var); + } co_yield var; } };