-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple pass that removes all contracts from the IR, treating them as passthroughs. Run the pass in firtool's HW-to-SV pipeline early on to add additional optimization opportunities. ExportVerilog will eventually ignore contracts anyway.
- Loading branch information
1 parent
8d2f1ec
commit 1c83d54
Showing
5 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===- StripContracts.cpp -------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "circt/Dialect/Verif/VerifOps.h" | ||
#include "circt/Dialect/Verif/VerifPasses.h" | ||
#include "mlir/Pass/Pass.h" | ||
|
||
namespace circt { | ||
namespace verif { | ||
#define GEN_PASS_DEF_STRIPCONTRACTSPASS | ||
#include "circt/Dialect/Verif/Passes.h.inc" | ||
} // namespace verif | ||
} // namespace circt | ||
|
||
using namespace mlir; | ||
using namespace circt; | ||
using namespace verif; | ||
|
||
namespace { | ||
struct StripContractsPass | ||
: public verif::impl::StripContractsPassBase<StripContractsPass> { | ||
void runOnOperation() override { | ||
getOperation()->walk([](ContractOp op) { | ||
op->replaceUsesWithIf(op.getInputs(), [&](OpOperand &operand) { | ||
return operand.getOwner() != op; | ||
}); | ||
op->dropAllReferences(); | ||
op->erase(); | ||
}); | ||
} | ||
}; | ||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RUN: circt-opt --strip-contracts %s | FileCheck %s | ||
|
||
// CHECK-LABEL: func @foo | ||
func.func @foo(%arg0: i42) -> i42 { | ||
// CHECK-NOT: verif.contract | ||
%0 = verif.contract %arg0 : i42 {} | ||
// CHECK: return %arg0 | ||
return %0 : i42 | ||
} | ||
|
||
// CHECK-LABEL: hw.module @bar | ||
hw.module @bar() { | ||
// CHECK-NOT: verif.contract | ||
%0 = verif.contract %1 : i42 {} | ||
%1 = verif.contract %0 : i42 {} | ||
} |