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

[Moore] Fix the stacking fault caused by cast and remove unused headers #7219

Merged
Merged
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
4 changes: 2 additions & 2 deletions include/circt/Dialect/Moore/MoorePasses.td
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

include "mlir/Pass/PassBase.td"

def SimplifyProcedures : Pass<"simplify-procedures", "moore::SVModuleOp"> {
def SimplifyProcedures : Pass<"moore-simplify-procedures", "moore::SVModuleOp"> {
let summary = "Simplify procedures";
let description = [{
Cause we want to introduce mem2reg in the moore dialect to eliminate the
Because we want to introduce mem2reg in the moore dialect to eliminate the
local temporary variables, if the local variabels exist in the procedure
body, it can be promoted by mem2reg. But global/module-level variables
don't be promoted. So this pass is aimed at inserting a local "shadow"
Expand Down
41 changes: 20 additions & 21 deletions lib/Dialect/Moore/Transforms/SimplifyProcedures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

#include "circt/Dialect/Moore/MooreOps.h"
#include "circt/Dialect/Moore/MoorePasses.h"
#include "circt/Dialect/Moore/MooreTypes.h"
#include "mlir/IR/Builders.h"
#include "mlir/Pass/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/raw_ostream.h"

namespace circt {
namespace moore {
Expand Down Expand Up @@ -61,23 +56,27 @@ void SimplifyProceduresPass::runOnOperation() {
if (!users.contains(user))
users.insert(user);

auto varOp = cast<VariableOp>(nestedOp.getOperand(0).getDefiningOp());
auto varName = builder.getStringAttr("local_" + varOp.getName());
auto resultType = varOp.getResult().getType();
builder.setInsertionPointToStart(procedureOp.getBody());
auto readOp = builder.create<ReadOp>(
nestedOp.getLoc(), cast<RefType>(resultType).getNestedType(),
varOp.getResult());
auto newVarOp = builder.create<VariableOp>(nestedOp.getLoc(),
resultType, varName, readOp);
builder.clearInsertionPoint();
// Because the operand of moore.event_wait is net.
if (auto varOp = llvm::dyn_cast_or_null<VariableOp>(
nestedOp.getOperand(0).getDefiningOp())) {
auto varName =
builder.getStringAttr(Twine("local_") + varOp.getName());
auto resultType = varOp.getResult().getType();
builder.setInsertionPointToStart(procedureOp.getBody());
auto readOp = builder.create<ReadOp>(
nestedOp.getLoc(), cast<RefType>(resultType).getNestedType(),
varOp.getResult());
auto newVarOp = builder.create<VariableOp>(
nestedOp.getLoc(), resultType, varName, readOp);
builder.clearInsertionPoint();

// Replace the users of the global variable with a corresponding
// "shadow" variable.
for (auto *user : users) {
user->replaceUsesOfWith(user->getOperand(0), newVarOp);
if (isa<BlockingAssignOp>(user))
assignOps.insert(user);
// Replace the users of the global variable with a corresponding
// "shadow" variable.
for (auto *user : users) {
user->replaceUsesOfWith(user->getOperand(0), newVarOp);
if (isa<BlockingAssignOp>(user))
assignOps.insert(user);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/Dialect/Moore/simplify-procedures.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: circt-opt --simplify-procedures %s | FileCheck %s
// RUN: circt-opt --moore-simplify-procedures %s | FileCheck %s

// CHECK-LABEL: moore.module @Foo()
moore.module @Foo() {
Expand Down
Loading