]> git.lizzy.rs Git - rust.git/blob - src/bin/cg_clif.rs
Indicate both start and end of pass RSS in time-passes output
[rust.git] / src / bin / cg_clif.rs
1 #![feature(rustc_private)]
2
3 extern crate rustc_data_structures;
4 extern crate rustc_driver;
5 extern crate rustc_interface;
6 extern crate rustc_session;
7 extern crate rustc_target;
8
9 use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
10 use rustc_interface::interface;
11 use rustc_session::config::ErrorOutputType;
12 use rustc_session::early_error;
13 use rustc_target::spec::PanicStrategy;
14
15 #[derive(Default)]
16 pub struct CraneliftPassesCallbacks {
17     time_passes: bool,
18 }
19
20 impl rustc_driver::Callbacks for CraneliftPassesCallbacks {
21     fn config(&mut self, config: &mut interface::Config) {
22         // If a --prints=... option has been given, we don't print the "total"
23         // time because it will mess up the --prints output. See #64339.
24         self.time_passes = config.opts.prints.is_empty()
25             && (config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time);
26
27         config.opts.cg.panic = Some(PanicStrategy::Abort);
28         config.opts.debugging_opts.panic_abort_tests = true;
29         config.opts.maybe_sysroot = Some(config.opts.maybe_sysroot.clone().unwrap_or_else(|| {
30             std::env::current_exe()
31                 .unwrap()
32                 .parent()
33                 .unwrap()
34                 .parent()
35                 .unwrap()
36                 .to_owned()
37         }));
38     }
39 }
40
41 fn main() {
42     let start_time = std::time::Instant::now();
43     let start_rss = get_resident_set_size();
44     rustc_driver::init_rustc_env_logger();
45     let mut callbacks = CraneliftPassesCallbacks::default();
46     rustc_driver::install_ice_hook();
47     let exit_code = rustc_driver::catch_with_exit_code(|| {
48         let args = std::env::args_os()
49             .enumerate()
50             .map(|(i, arg)| {
51                 arg.into_string().unwrap_or_else(|arg| {
52                     early_error(
53                         ErrorOutputType::default(),
54                         &format!("Argument {} is not valid Unicode: {:?}", i, arg),
55                     )
56                 })
57             })
58             .collect::<Vec<_>>();
59         let mut run_compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks);
60         run_compiler.set_make_codegen_backend(Some(Box::new(move |_| {
61             Box::new(rustc_codegen_cranelift::CraneliftCodegenBackend { config: None })
62         })));
63         run_compiler.run()
64     });
65
66     if callbacks.time_passes {
67         let end_rss = get_resident_set_size();
68         print_time_passes_entry("total", start_time.elapsed(), start_rss, end_rss);
69     }
70
71     std::process::exit(exit_code)
72 }