84
84
def_id : DefId ,
85
85
dead_unwinds : Option < & ' a BitSet < BasicBlock > > ,
86
86
entry_sets : IndexVec < BasicBlock , A :: Domain > ,
87
+ pass_name : Option < & ' static str > ,
87
88
analysis : A ,
88
89
89
90
/// Cached, cumulative transfer functions for each block.
@@ -174,6 +175,7 @@ where
174
175
body,
175
176
def_id,
176
177
dead_unwinds : None ,
178
+ pass_name : None ,
177
179
entry_sets,
178
180
apply_trans_for_block,
179
181
}
@@ -189,6 +191,15 @@ where
189
191
self
190
192
}
191
193
194
+ /// Adds an identifier to the graphviz output for this particular run of a dataflow analysis.
195
+ ///
196
+ /// Some analyses are run multiple times in the compilation pipeline. Give them a `pass_name`
197
+ /// to differentiate them. Otherwise, only the results for the latest run will be saved.
198
+ pub fn pass_name ( mut self , name : & ' static str ) -> Self {
199
+ self . pass_name = Some ( name) ;
200
+ self
201
+ }
202
+
192
203
/// Computes the fixpoint for this dataflow problem and returns it.
193
204
pub fn iterate_to_fixpoint ( self ) -> Results < ' tcx , A >
194
205
where
@@ -202,6 +213,7 @@ where
202
213
mut entry_sets,
203
214
tcx,
204
215
apply_trans_for_block,
216
+ pass_name,
205
217
..
206
218
} = self ;
207
219
@@ -249,7 +261,7 @@ where
249
261
250
262
let results = Results { analysis, entry_sets } ;
251
263
252
- let res = write_graphviz_results ( tcx, def_id, & body, & results) ;
264
+ let res = write_graphviz_results ( tcx, def_id, & body, & results, pass_name ) ;
253
265
if let Err ( e) = res {
254
266
warn ! ( "Failed to write graphviz dataflow results: {}" , e) ;
255
267
}
@@ -267,6 +279,7 @@ fn write_graphviz_results<A>(
267
279
def_id : DefId ,
268
280
body : & mir:: Body < ' tcx > ,
269
281
results : & Results < ' tcx , A > ,
282
+ pass_name : Option < & ' static str > ,
270
283
) -> std:: io:: Result < ( ) >
271
284
where
272
285
A : Analysis < ' tcx > ,
@@ -285,12 +298,17 @@ where
285
298
None if tcx. sess . opts . debugging_opts . dump_mir_dataflow
286
299
&& dump_enabled ( tcx, A :: NAME , def_id) =>
287
300
{
301
+ // FIXME: Use some variant of `pretty::dump_path` for this
288
302
let mut path = PathBuf :: from ( & tcx. sess . opts . debugging_opts . dump_mir_dir ) ;
289
303
304
+ let crate_name = tcx. crate_name ( def_id. krate ) ;
290
305
let item_name = ty:: print:: with_forced_impl_filename_line ( || {
291
306
tcx. def_path ( def_id) . to_filename_friendly_no_crate ( )
292
307
} ) ;
293
- path. push ( format ! ( "rustc.{}.{}.dot" , item_name, A :: NAME ) ) ;
308
+
309
+ let pass_name = pass_name. map ( |s| format ! ( ".{}" , s) ) . unwrap_or_default ( ) ;
310
+
311
+ path. push ( format ! ( "{}.{}.{}{}.dot" , crate_name, item_name, A :: NAME , pass_name) ) ;
294
312
path
295
313
}
296
314
0 commit comments