Skip to content
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
6 changes: 4 additions & 2 deletions include/ep2/dialect/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct HandlerDependencyAnalysis {
friend bool operator<(const HandlerFullName &l, const HandlerFullName &r) {
return std::tie(l.event, l.atom) < std::tie(r.event, r.atom);
}
std::string mangle() const {
std::string mangle() const {
auto surffix = atom == "" ? "" : "_" + atom;
return ("__handler_" + event + surffix).str();
}
Expand All @@ -77,7 +77,9 @@ struct HandlerDependencyAnalysis {
return (event + surffix).str();
}

HandlerFullName(std::string event, std::string atom = "") : event(event), atom(atom) {}
// NOTE: This constructor stores StringRefs that point into the provided
// StringRefs. Callers must ensure the underlying data outlives this object.
HandlerFullName(llvm::StringRef event, llvm::StringRef atom = "") : event(event), atom(atom) {}
HandlerFullName(FuncOp funcOp);
HandlerFullName(ReturnOp returnOp);
HandlerFullName(InitOp initOp);
Expand Down
9 changes: 6 additions & 3 deletions lib/ep2/HandlerReplicationPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ void HandlerReplicationPass::runOnOperation() {
is replicated onto island 1, compute units 1,2 then location on
handler 1 = i1cu1, handler 2 has i1cu2.
*/
std::vector<ep2::FuncOp> toErase;
module->walk([&](ep2::FuncOp funcOp) {
if (funcOp->getAttr("type").cast<StringAttr>().getValue() == "handler" && !funcOp.isExtern()) {
parentBlock = funcOp->getBlock();
llvm::errs() << funcOp.getSymName().str() << '\n';
auto instances = cast<mlir::ArrayAttr>(funcOp->getAttr("instances")).getValue();
int sz = instances.size();
mlir::Operation::CloneOptions options(true, true);
Expand All @@ -80,13 +80,16 @@ void HandlerReplicationPass::runOnOperation() {
for (int i = 1; i<=sz; ++i) {
mlir::Operation* cloneOp = funcOp->clone(options);
cloneOp->setAttr("location", instances[i-1]);

cast<ep2::FuncOp>(cloneOp).setSymName(name + "_" + std::to_string(i));
toInsert.push_back(cloneOp);
}
funcOp->erase();
toErase.push_back(funcOp);
}
});
for (auto funcOp : toErase) {
funcOp->erase();
}
for (mlir::Operation* op : toInsert) {
parentBlock->push_back(op);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/ep2/Passes/GlobalToPartitionPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class GlobalImportPattern : public OpRewritePattern<GlobalImportOp> {
assert(global != nullptr);

rewriter.replaceOpWithNewOp<InitOp>(refOp, global.getType());
return success();
}
};
} // rewrite pattern
Expand All @@ -55,6 +56,7 @@ void GlobalToPartitionPass::runOnOperation() {
return signalPassFailure();

// remove global op if possible if necessary
llvm::SmallVector<GlobalOp> toErase;
for (auto global : moduleOp.getOps<GlobalOp>()) {
bool hasUse = false;
moduleOp->walk([&](GlobalImportOp refOp) {
Expand All @@ -63,7 +65,10 @@ void GlobalToPartitionPass::runOnOperation() {
});

if (!hasUse)
global.erase();
toErase.push_back(global);
}
for (auto global : toErase) {
global.erase();
}
}

Expand Down