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

[MSFlow] flatten ap #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion example/machsuite
32 changes: 32 additions & 0 deletions lib/mlir/Transforms/LiftMemRefSubview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,31 @@ static LogicalResult aliasMemRef(FuncOp callee,
return success();
}

static LogicalResult matchCallerToCallee(CallOp caller, FuncOp callee) {
if (caller.getCallee() != callee.getName())
return failure();

OpBuilder b(callee.getContext());
for (auto it : enumerate(caller.getOperands())) {
auto operand = it.value();
auto targetType = callee.getArgument(it.index()).getType();
if (operand.getType() != targetType) {
assert(operand.isa<BlockArgument>());

auto f = dyn_cast<FuncOp>(
operand.cast<BlockArgument>().getOwner()->getParentOp());
assert(f && "Parent of the type-mismatched value should be a function.");

operand.setType(targetType);
auto entry = &f.getBlocks().front();
f.setType(b.getFunctionType(entry->getArgumentTypes(),
f.getType().getResults()));
}
}

return success();
}

static LogicalResult flattenPartitionDims(ModuleOp m) {
LLVM_DEBUG(dbgs() << "Flattening ..." << m << '\n');
using OpPair = std::pair<Operation *, Operation *>;
Expand Down Expand Up @@ -804,6 +829,7 @@ static LogicalResult flattenPartitionDims(ModuleOp m) {
subviewOp.erase();
}

/// Rewrite the function interface with the flattened memref type.
BlockArgument arg = memref.dyn_cast<BlockArgument>();
assert(arg);

Expand All @@ -824,6 +850,12 @@ static LogicalResult flattenPartitionDims(ModuleOp m) {
arg.setType(newSrcTy);
f.setType(b.getFunctionType(arg.getOwner()->getArgumentTypes(),
f.getType().getResults()));

// Fix the callers to this function.
m.walk([&](CallOp caller) {
if (caller.getCallee() == f.getName())
assert(succeeded(matchCallerToCallee(caller, f)));
});
}

return success();
Expand Down
2 changes: 1 addition & 1 deletion pyphism/machsuite/ms_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def run(self):
.polymer_opt()
.phism_fold_if()
.phism_loop_transforms()
.phism_array_partition()
.phism_array_partition(flatten=True)
# .lower_scf()
.lower_llvm()
.phism_vitis_opt()
Expand Down