@@ -27,6 +27,7 @@ pub struct Print {
27
27
filter : OpFilter ,
28
28
pass_filter : PassFilter ,
29
29
target : Option < compact_str:: CompactString > ,
30
+ only_when_modified : bool ,
30
31
}
31
32
32
33
/// Filter for the different passes.
@@ -61,6 +62,7 @@ impl Print {
61
62
filter : OpFilter :: All ,
62
63
pass_filter : PassFilter :: All ,
63
64
target : None ,
65
+ only_when_modified : false ,
64
66
}
65
67
}
66
68
@@ -72,22 +74,31 @@ impl Print {
72
74
filter : OpFilter :: Type { dialect, op } ,
73
75
pass_filter : PassFilter :: All ,
74
76
target : None ,
77
+ only_when_modified : false ,
75
78
}
76
79
}
77
80
81
+ // pub fn from_config(config: IRPrintingConfig) {
82
+ // if config.print
83
+ // }
78
84
/// Adds a PassFilter to Print. IR will only be printed before and after those passes are
79
85
/// executed.
80
86
pub fn with_pass_filter ( mut self , passes : Vec < String > ) -> Self {
81
87
self . pass_filter = PassFilter :: Certain ( passes) ;
82
88
self
83
89
}
84
90
91
+ pub fn with_only_print_when_modified ( & mut self ) {
92
+ self . only_when_modified = true ;
93
+ }
94
+
85
95
/// Create a printer that only prints `Symbol` operations containing `name`
86
96
pub fn symbol_matching ( name : & ' static str ) -> Self {
87
97
Self {
88
98
filter : OpFilter :: Symbol ( Some ( name) ) ,
89
99
pass_filter : PassFilter :: All ,
90
100
target : None ,
101
+ only_when_modified : false ,
91
102
}
92
103
}
93
104
@@ -105,7 +116,7 @@ impl Print {
105
116
match self . filter {
106
117
OpFilter :: All => {
107
118
let target = self . target . as_deref ( ) . unwrap_or ( "printer" ) ;
108
- log:: trace !( target: target, "{op}" ) ;
119
+ log:: error !( target: target, "{op}" ) ;
109
120
}
110
121
OpFilter :: Type {
111
122
dialect,
@@ -114,21 +125,21 @@ impl Print {
114
125
let name = op. name ( ) ;
115
126
if name. dialect ( ) == dialect && name. name ( ) == op_name {
116
127
let target = self . target . as_deref ( ) . unwrap_or ( "printer" ) ;
117
- log:: trace !( target: target, "{op}" ) ;
128
+ log:: error !( target: target, "{op}" ) ;
118
129
}
119
130
}
120
131
OpFilter :: Symbol ( None ) => {
121
132
if let Some ( sym) = op. as_symbol ( ) {
122
133
let name = sym. name ( ) . as_str ( ) ;
123
134
let target = self . target . as_deref ( ) . unwrap_or ( name) ;
124
- log:: trace !( target: target, "{}" , sym. as_symbol_operation( ) ) ;
135
+ log:: error !( target: target, "{}" , sym. as_symbol_operation( ) ) ;
125
136
}
126
137
}
127
138
OpFilter :: Symbol ( Some ( filter) ) => {
128
139
if let Some ( sym) = op. as_symbol ( ) . filter ( |sym| sym. name ( ) . as_str ( ) . contains ( filter) )
129
140
{
130
141
let target = self . target . as_deref ( ) . unwrap_or ( filter) ;
131
- log:: trace !( target: target, "{}" , sym. as_symbol_operation( ) ) ;
142
+ log:: error !( target: target, "{}" , sym. as_symbol_operation( ) ) ;
132
143
}
133
144
}
134
145
}
@@ -165,14 +176,35 @@ impl Pass for Print {
165
176
}
166
177
167
178
impl PassInstrumentation for Print {
168
- fn run_after_pass ( & mut self , pass : & dyn OperationPass , op : & OperationRef , _changed : bool ) {
169
- if self . should_print ( pass) {
179
+ fn run_after_pass ( & mut self , pass : & dyn OperationPass , op : & OperationRef , changed : bool ) {
180
+ std:: println!(
181
+ "
182
+ ------------------------------------DESPUES:\
183
+ {}-------------------------------------------------------
184
+ " ,
185
+ pass. name( )
186
+ ) ;
187
+ std:: println!( "RESULTADO DE CHANGED: {}" , changed) ;
188
+ #[ allow( clippy:: needless_bool) ]
189
+ // Always print, unless "only_when_modified" has been set and there have not been changes.
190
+ let print_when_changed = if self . only_when_modified && !changed {
191
+ false
192
+ } else {
193
+ true
194
+ } ;
195
+ if self . should_print ( pass) && print_when_changed {
170
196
let op = op. borrow ( ) ;
171
197
self . print_ir ( op) ;
172
198
}
173
199
}
174
200
175
201
fn run_before_pass ( & mut self , pass : & dyn OperationPass , op : & OperationRef ) {
202
+ std:: println!(
203
+ "
204
+ ------------------------------------ANTES:{}-------------------------------------------------------
205
+ " ,
206
+ pass. name( )
207
+ ) ;
176
208
if self . should_print ( pass) {
177
209
let op = op. borrow ( ) ;
178
210
self . print_ir ( op) ;
0 commit comments