-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[firtool] fix: check uninferred resets after removing unused modules
The Chisel's Definition API generates modules that are not instantiated, whose reset cannot be inferred properly. Check the uninferred resets after removing unreferenced modules to resolve it. Signed-off-by: unlsycn <[email protected]>
- Loading branch information
Showing
8 changed files
with
112 additions
and
29 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
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,62 @@ | ||
//===- CheckUninferredResets.cpp - Verify no uninferred resets ------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This pass checks to see if there are abstract type resets which have not | ||
// been inferred correctly. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "circt/Dialect/FIRRTL/FIRRTLOpInterfaces.h" | ||
#include "circt/Dialect/FIRRTL/FIRRTLUtils.h" | ||
#include "circt/Dialect/FIRRTL/Passes.h" | ||
#include "mlir/Pass/Pass.h" | ||
|
||
namespace circt { | ||
namespace firrtl { | ||
#define GEN_PASS_DEF_CHECKUNINFERREDRESETS | ||
#include "circt/Dialect/FIRRTL/Passes.h.inc" | ||
} // namespace firrtl | ||
} // namespace circt | ||
|
||
using namespace mlir; | ||
using namespace circt; | ||
using namespace firrtl; | ||
|
||
namespace { | ||
struct CheckUninferredResetsPass | ||
: public circt::firrtl::impl::CheckUninferredResetsBase< | ||
CheckUninferredResetsPass> { | ||
void runOnOperation() override; | ||
|
||
LogicalResult verifyNoAbstractReset(); | ||
}; | ||
} // namespace | ||
|
||
void CheckUninferredResetsPass::runOnOperation() { | ||
bool hasAbstractResetPorts = false; | ||
for (FModuleLike module : | ||
getOperation().getBodyBlock()->getOps<FModuleLike>()) { | ||
for (PortInfo port : module.getPorts()) { | ||
if (getBaseOfType<ResetType>(port.type)) { | ||
auto diag = emitError(port.loc) | ||
<< "a port \"" << port.getName() | ||
<< "\" with abstract reset type was unable to be " | ||
"inferred by InferResets (is this a top-level port?)"; | ||
diag.attachNote(module->getLoc()) | ||
<< "the module with this uninferred reset port was defined here"; | ||
hasAbstractResetPorts = true; | ||
} | ||
} | ||
} | ||
if (hasAbstractResetPorts) | ||
return signalPassFailure(); | ||
} | ||
|
||
std::unique_ptr<mlir::Pass> circt::firrtl::createCheckUninferredResetsPass() { | ||
return std::make_unique<CheckUninferredResetsPass>(); | ||
} |
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
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,31 @@ | ||
; RUN: firtool %s --verify-diagnostics --split-input-file | ||
; The Chisel's Definition API generates modules that are not instantiated, | ||
; whose reset cannot be inferred properly. These modules should be removed | ||
; before checking abstract type resets. | ||
|
||
FIRRTL version 3.3.0 | ||
circuit Foo: | ||
module Adder : | ||
input clock : Clock | ||
input reset : Reset | ||
input in : UInt<10> | ||
output out : UInt<10> | ||
|
||
node _out_T = add(in, UInt<1>(0h1)) | ||
node _out_T_1 = tail(_out_T, 1) | ||
connect out, _out_T_1 | ||
|
||
; expected-warning @below {{module `Foo` is empty}} | ||
module Foo : | ||
input clock : Clock | ||
input reset : UInt<1> | ||
|
||
;// ----- | ||
|
||
FIRRTL version 3.3.0 | ||
circuit Bar: | ||
; expected-note @below {{the module with this uninferred reset port was defined here}} | ||
module Bar : | ||
input clock : Clock | ||
; expected-error @below {{a port "reset" with abstract reset type was unable to be inferred by InferResets}} | ||
input reset : Reset |