Skip to content

Commit ee3c204

Browse files
committed
conv:abi: Do memcpy instead of load on indirect when possible.
1 parent 8e9307b commit ee3c204

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lib/vast/Conversion/ABI/LowerABI.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,28 @@ namespace vast
453453
{
454454
auto loc = indirect.getLoc();
455455
auto mctx = indirect.getContext();
456-
auto type = hl::PointerType::get(mctx, indirect.getValue().getType());
457-
456+
auto indirect_val = indirect.getValue();
457+
auto type = hl::PointerType::get(mctx, indirect_val.getType());
458458
auto var = state.rewriter.template create< ll::Alloca >(
459459
indirect.getLoc(), type);
460+
460461
// Now we initilizae before yielding the ptr
461-
state.rewriter.template create< ll::Store >(loc, indirect.getValue(), var);
462+
if (auto load = mlir::dyn_cast< ll::Load >(indirect_val.getDefiningOp())) {
463+
size_t bits = dl.getTypeSizeInBits(indirect_val.getType());
464+
size_t bytes = dl.getTypeSize(indirect_val.getType());
465+
state.rewriter.template create< ll::MemcpyOp >(
466+
loc,
467+
load.getPtr(),
468+
var,
469+
mlir::IntegerAttr::get(mlir::IntegerType::get(mctx, bytes), bits),
470+
// FIXME:
471+
mlir::BoolAttr::get(mctx, false) /*isVolatile*/
472+
);
473+
state.rewriter.eraseOp(load);
474+
475+
} else {
476+
state.rewriter.template create< ll::Store >(loc, indirect_val, var);
477+
}
462478
co_yield var;
463479
}
464480
};

0 commit comments

Comments
 (0)