Skip to content

Commit

Permalink
conv:abi: Do memcpy instead of load on indirect when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jezurko committed Nov 22, 2024
1 parent 8e9307b commit ee3c204
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/vast/Conversion/ABI/LowerABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down

0 comments on commit ee3c204

Please sign in to comment.