Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lowering of big structs passed by value #751

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions include/vast/Dialect/LowLevel/LowLevelOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 19 additions & 3 deletions lib/vast/Conversion/ABI/LowerABI.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2021-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Conversion/ABI/LowerABI.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on lib/vast/Conversion/ABI/LowerABI.cpp

File lib/vast/Conversion/ABI/LowerABI.cpp does not conform to Custom style guidelines. (lines 457, 463, 465, 466, 467, 468, 469, 470)

#include "vast/Conversion/Passes.hpp"

Expand Down Expand Up @@ -453,12 +453,28 @@
{
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