/compiler/rustc_codegen_cranelift/src/driver/mod.rs

https://gitlab.com/rust-lang/rust · Rust · 53 lines · 43 code · 5 blank · 5 comment · 5 complexity · 6866c7d87af017e01baec91e161e9a57 MD5 · raw file

  1. //! Drivers are responsible for calling [`codegen_fn`] or [`codegen_static`] for each mono item and
  2. //! performing any further actions like JIT executing or writing object files.
  3. //!
  4. //! [`codegen_fn`]: crate::base::codegen_fn
  5. //! [`codegen_static`]: crate::constant::codegen_static
  6. use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
  7. use crate::prelude::*;
  8. pub(crate) mod aot;
  9. #[cfg(feature = "jit")]
  10. pub(crate) mod jit;
  11. fn predefine_mono_items<'tcx>(
  12. tcx: TyCtxt<'tcx>,
  13. module: &mut dyn Module,
  14. mono_items: &[(MonoItem<'tcx>, (RLinkage, Visibility))],
  15. ) {
  16. tcx.sess.time("predefine functions", || {
  17. let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
  18. for &(mono_item, (linkage, visibility)) in mono_items {
  19. match mono_item {
  20. MonoItem::Fn(instance) => {
  21. let name = tcx.symbol_name(instance).name;
  22. let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
  23. let sig = get_function_sig(tcx, module.isa().triple(), instance);
  24. let linkage = crate::linkage::get_clif_linkage(
  25. mono_item,
  26. linkage,
  27. visibility,
  28. is_compiler_builtins,
  29. );
  30. module.declare_function(name, linkage, &sig).unwrap();
  31. }
  32. MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
  33. }
  34. }
  35. });
  36. }
  37. fn time<R>(tcx: TyCtxt<'_>, display: bool, name: &'static str, f: impl FnOnce() -> R) -> R {
  38. if display {
  39. println!("[{:<30}: {}] start", tcx.crate_name(LOCAL_CRATE), name);
  40. let before = std::time::Instant::now();
  41. let res = tcx.sess.time(name, f);
  42. let after = std::time::Instant::now();
  43. println!("[{:<30}: {}] end time: {:?}", tcx.crate_name(LOCAL_CRATE), name, after - before);
  44. res
  45. } else {
  46. tcx.sess.time(name, f)
  47. }
  48. }