Skip to content

Commit b1a5722

Browse files
Clean up should_print functionality in Print::run_after_pass function call
Signed-off-by: Tomas Fabrizio Orsi <[email protected]>
1 parent 2615254 commit b1a5722

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

hir/src/pass.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,22 @@ impl Print {
145145
}
146146
}
147147

148-
fn should_print(&self, pass: &dyn OperationPass) -> bool {
148+
fn pass_filter(&self, pass: &dyn OperationPass) -> bool {
149149
match &self.pass_filter {
150150
PassFilter::All => true,
151151
PassFilter::Certain(passes) => passes.iter().any(|p| p == pass.name()),
152152
}
153153
}
154+
155+
fn should_print(&self, pass: &dyn OperationPass, ir_changed: IRAfterPass) -> bool {
156+
let pass_filter = self.pass_filter(pass);
157+
158+
// Always print, unless "only_when_modified" has been set and there have not been changes.
159+
let modification_filter =
160+
!matches!((ir_changed, self.only_when_modified), (IRAfterPass::Unchanged, true));
161+
162+
pass_filter && modification_filter
163+
}
154164
}
155165

156166
impl PassInstrumentation for Print {
@@ -160,20 +170,14 @@ impl PassInstrumentation for Print {
160170
op: &OperationRef,
161171
changed: IRAfterPass,
162172
) {
163-
// Always print, unless "only_when_modified" has been set and there have not been changes.
164-
let print_when_changed = if self.only_when_modified && changed == IRAfterPass::Unchanged {
165-
false
166-
} else {
167-
true
168-
};
169-
if self.should_print(pass) && print_when_changed {
173+
if self.should_print(pass, changed) {
170174
let op = op.borrow();
171175
self.print_ir(op);
172176
}
173177
}
174178

175179
fn run_before_pass(&mut self, pass: &dyn OperationPass, op: &OperationRef) {
176-
if self.should_print(pass) {
180+
if self.pass_filter(pass) {
177181
let op = op.borrow();
178182
self.print_ir(op);
179183
}

0 commit comments

Comments
 (0)