Skip to content

Commit 46d67c1

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

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

hir/src/pass.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,24 @@ 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 = match (ir_changed, self.only_when_modified) {
160+
(IRAfterPass::Unchanged, true) => false,
161+
_ => true,
162+
};
163+
164+
pass_filter && modification_filter
165+
}
154166
}
155167

156168
impl PassInstrumentation for Print {
@@ -160,20 +172,14 @@ impl PassInstrumentation for Print {
160172
op: &OperationRef,
161173
changed: IRAfterPass,
162174
) {
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 {
175+
if self.should_print(pass, changed) {
170176
let op = op.borrow();
171177
self.print_ir(op);
172178
}
173179
}
174180

175181
fn run_before_pass(&mut self, pass: &dyn OperationPass, op: &OperationRef) {
176-
if self.should_print(pass) {
182+
if self.pass_filter(pass) {
177183
let op = op.borrow();
178184
self.print_ir(op);
179185
}

0 commit comments

Comments
 (0)