-
Notifications
You must be signed in to change notification settings - Fork 309
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
[firtool] fix: check uninferred resets after removing unused modules #7380
Open
unlsycn
wants to merge
4
commits into
llvm:main
Choose a base branch
from
unlsycn:definition-infer-reset-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−29
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e06c5f2
[firtool] fix: check uninferred resets after removing unused modules
unlsycn 84345ec
fix: remove redundant function declaration
unlsycn 9d6d5be
refactor: nest CheckUninferredResets on FModuleLike
unlsycn 7add1db
test: add a test to verify legal uninferred reset
unlsycn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,55 @@ | ||
//===- 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; | ||
}; | ||
} // namespace | ||
|
||
void CheckUninferredResetsPass::runOnOperation() { | ||
auto module = getOperation(); | ||
for (auto 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"; | ||
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,21 @@ | ||
// RUN: circt-opt --pass-pipeline='builtin.module(firrtl.circuit(firrtl-infer-resets,any(firrtl-check-uninferred-resets)))' --verify-diagnostics %s | ||
// RUN: circt-opt --pass-pipeline='builtin.module(firrtl.circuit(firrtl-infer-resets,firrtl-inliner,any(firrtl-check-uninferred-resets)))' %s | FileCheck %s | ||
|
||
firrtl.circuit "LegalUninferredReset" { | ||
// The following two diagnostics will only appear if firrtl-inliner is not enabled | ||
// expected-note @+2 {{the module with this uninferred reset port was defined here}} | ||
// expected-error @+1 {{a port "reset" with abstract reset type was unable to be inferred by InferResets}} | ||
firrtl.module private @Adder(in %clock: !firrtl.clock, in %reset: !firrtl.reset, in %in: !firrtl.uint<10>, out %out: !firrtl.uint<10>) { | ||
%c1_ui1 = firrtl.constant 1 : !firrtl.const.uint<1> | ||
%0 = firrtl.add %in, %c1_ui1 : (!firrtl.uint<10>, !firrtl.const.uint<1>) -> !firrtl.uint<11> | ||
%_out_T = firrtl.node interesting_name %0 : !firrtl.uint<11> | ||
%1 = firrtl.tail %_out_T, 1 : (!firrtl.uint<11>) -> !firrtl.uint<10> | ||
%_out_T_1 = firrtl.node interesting_name %1 : !firrtl.uint<10> | ||
firrtl.matchingconnect %out, %_out_T_1 : !firrtl.uint<10> | ||
} | ||
firrtl.module @LegalUninferredReset(in %clock: !firrtl.clock, in %reset: !firrtl.uint<1>) { | ||
} | ||
} | ||
|
||
// CHECK-NOT: firrtl.circuit "Adder" | ||
// CHECK: firrtl.circuit "LegalUninferredReset" |
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a test that demonstrates the correctness of your new pass and not just the firrtl lowering as a whole.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test of uninferred reset check has been included in infer-resets-errors.mlir, the test which we actually need to add is to compare the errors emitted with or without enabling firrtl-inliner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm tend to preserve this test using firtool since it is extracted from an actual use case, while adding a new minimal test. What do you think.