Skip to content

Commit 1cea8e1

Browse files
Auto merge of #112049 - Kobzol:pgo-omit-benchmarks, r=<try>
[do not merge] CI experiments Various CI experiments for try/dist builds. r? `@ghost`
2 parents e4b9d01 + c79153e commit 1cea8e1

File tree

18 files changed

+240
-524
lines changed

18 files changed

+240
-524
lines changed

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 58 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub(crate) fn codegen_fn<'tcx>(
106106
next_ssa_var: 0,
107107
};
108108

109-
tcx.prof.generic_activity("codegen clif ir").run(|| codegen_fn_body(&mut fx, start_block));
109+
codegen_fn_body(&mut fx, start_block);
110110
fx.bcx.seal_all_blocks();
111111
fx.bcx.finalize();
112112

@@ -136,14 +136,11 @@ pub(crate) fn codegen_fn<'tcx>(
136136

137137
pub(crate) fn compile_fn(
138138
cx: &mut crate::CodegenCx,
139-
profiler: &SelfProfilerRef,
139+
_profiler: &SelfProfilerRef,
140140
cached_context: &mut Context,
141141
module: &mut dyn Module,
142142
codegened_func: CodegenedFunction,
143143
) {
144-
let _timer =
145-
profiler.generic_activity_with_arg("compile function", &*codegened_func.symbol_name);
146-
147144
let clif_comments = codegened_func.clif_comments;
148145

149146
// Store function in context
@@ -180,36 +177,34 @@ pub(crate) fn compile_fn(
180177
};
181178

182179
// Define function
183-
profiler.generic_activity("define function").run(|| {
184-
context.want_disasm = cx.should_write_ir;
185-
match module.define_function(codegened_func.func_id, context) {
186-
Ok(()) => {}
187-
Err(ModuleError::Compilation(CodegenError::ImplLimitExceeded)) => {
188-
let early_dcx = rustc_session::EarlyDiagCtxt::new(
189-
rustc_session::config::ErrorOutputType::default(),
190-
);
191-
early_dcx.early_fatal(format!(
192-
"backend implementation limit exceeded while compiling {name}",
193-
name = codegened_func.symbol_name
194-
));
195-
}
196-
Err(ModuleError::Compilation(CodegenError::Verifier(err))) => {
197-
let early_dcx = rustc_session::EarlyDiagCtxt::new(
198-
rustc_session::config::ErrorOutputType::default(),
199-
);
200-
let _ = early_dcx.early_err(format!("{:?}", err));
201-
let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
202-
&context.func,
203-
Some(Box::new(&clif_comments)),
204-
err,
205-
);
206-
early_dcx.early_fatal(format!("cranelift verify error:\n{}", pretty_error));
207-
}
208-
Err(err) => {
209-
panic!("Error while defining {name}: {err:?}", name = codegened_func.symbol_name);
210-
}
180+
context.want_disasm = cx.should_write_ir;
181+
match module.define_function(codegened_func.func_id, context) {
182+
Ok(()) => {}
183+
Err(ModuleError::Compilation(CodegenError::ImplLimitExceeded)) => {
184+
let early_dcx = rustc_session::EarlyDiagCtxt::new(
185+
rustc_session::config::ErrorOutputType::default(),
186+
);
187+
early_dcx.early_fatal(format!(
188+
"backend implementation limit exceeded while compiling {name}",
189+
name = codegened_func.symbol_name
190+
));
211191
}
212-
});
192+
Err(ModuleError::Compilation(CodegenError::Verifier(err))) => {
193+
let early_dcx = rustc_session::EarlyDiagCtxt::new(
194+
rustc_session::config::ErrorOutputType::default(),
195+
);
196+
let _ = early_dcx.early_err(format!("{:?}", err));
197+
let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
198+
&context.func,
199+
Some(Box::new(&clif_comments)),
200+
err,
201+
);
202+
early_dcx.early_fatal(format!("cranelift verify error:\n{}", pretty_error));
203+
}
204+
Err(err) => {
205+
panic!("Error while defining {name}: {err:?}", name = codegened_func.symbol_name);
206+
}
207+
}
213208

214209
if cx.should_write_ir {
215210
// Write optimized function to file for debugging
@@ -233,37 +228,33 @@ pub(crate) fn compile_fn(
233228

234229
// Define debuginfo for function
235230
let debug_context = &mut cx.debug_context;
236-
profiler.generic_activity("generate debug info").run(|| {
237-
if let Some(debug_context) = debug_context {
238-
codegened_func.func_debug_cx.unwrap().finalize(
239-
debug_context,
240-
codegened_func.func_id,
241-
context,
242-
);
243-
}
244-
});
231+
if let Some(debug_context) = debug_context {
232+
codegened_func.func_debug_cx.unwrap().finalize(
233+
debug_context,
234+
codegened_func.func_id,
235+
context,
236+
);
237+
}
245238
}
246239

247240
fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func: &Function) {
248241
if !enable_verifier(tcx.sess) {
249242
return;
250243
}
251244

252-
tcx.prof.generic_activity("verify clif ir").run(|| {
253-
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
254-
match cranelift_codegen::verify_function(&func, &flags) {
255-
Ok(_) => {}
256-
Err(err) => {
257-
tcx.dcx().err(format!("{:?}", err));
258-
let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
259-
&func,
260-
Some(Box::new(writer)),
261-
err,
262-
);
263-
tcx.dcx().fatal(format!("cranelift verify error:\n{}", pretty_error));
264-
}
245+
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
246+
match cranelift_codegen::verify_function(&func, &flags) {
247+
Ok(_) => {}
248+
Err(err) => {
249+
tcx.dcx().err(format!("{:?}", err));
250+
let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
251+
&func,
252+
Some(Box::new(writer)),
253+
err,
254+
);
255+
tcx.dcx().fatal(format!("cranelift verify error:\n{}", pretty_error));
265256
}
266-
});
257+
}
267258
}
268259

269260
fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
@@ -277,10 +268,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
277268
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
278269
return;
279270
}
280-
fx.tcx
281-
.prof
282-
.generic_activity("codegen prelude")
283-
.run(|| crate::abi::codegen_fn_prelude(fx, start_block));
271+
crate::abi::codegen_fn_prelude(fx, start_block);
284272

285273
let reachable_blocks = traversal::mono_reachable_as_bitset(fx.mir, fx.tcx, fx.instance);
286274

@@ -475,19 +463,15 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
475463
fn_span,
476464
unwind,
477465
call_source: _,
478-
} => {
479-
fx.tcx.prof.generic_activity("codegen call").run(|| {
480-
crate::abi::codegen_terminator_call(
481-
fx,
482-
mir::SourceInfo { span: *fn_span, ..source_info },
483-
func,
484-
args,
485-
*destination,
486-
*target,
487-
*unwind,
488-
)
489-
});
490-
}
466+
} => crate::abi::codegen_terminator_call(
467+
fx,
468+
mir::SourceInfo { span: *fn_span, ..source_info },
469+
func,
470+
args,
471+
*destination,
472+
*target,
473+
*unwind,
474+
),
491475
// FIXME(explicit_tail_calls): add support for tail calls to the cranelift backend, once cranelift supports tail calls
492476
TerminatorKind::TailCall { fn_span, .. } => span_bug!(
493477
*fn_span,

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -595,46 +595,38 @@ fn module_codegen(
595595
let profiler = tcx.prof.clone();
596596

597597
OngoingModuleCodegen::Async(std::thread::spawn(move || {
598-
profiler.clone().generic_activity_with_arg("compile functions", &*cgu_name).run(|| {
599-
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
600-
profiler.clone(),
601-
)));
602-
603-
let mut cached_context = Context::new();
604-
for codegened_func in codegened_functions {
605-
crate::base::compile_fn(
606-
&mut cx,
607-
&profiler,
608-
&mut cached_context,
609-
&mut module,
610-
codegened_func,
611-
);
612-
}
613-
});
598+
cranelift_codegen::timing::set_thread_profiler(Box::new(super::MeasuremeProfiler(
599+
profiler.clone(),
600+
)));
601+
602+
let mut cached_context = Context::new();
603+
for codegened_func in codegened_functions {
604+
crate::base::compile_fn(
605+
&mut cx,
606+
&profiler,
607+
&mut cached_context,
608+
&mut module,
609+
codegened_func,
610+
);
611+
}
614612

615-
let global_asm_object_file =
616-
profiler.generic_activity_with_arg("compile assembly", &*cgu_name).run(|| {
617-
crate::global_asm::compile_global_asm(
618-
&global_asm_config,
619-
&cgu_name,
620-
&cx.global_asm,
621-
cx.invocation_temp.as_deref(),
622-
)
623-
})?;
624-
625-
let codegen_result =
626-
profiler.generic_activity_with_arg("write object file", &*cgu_name).run(|| {
627-
emit_cgu(
628-
&global_asm_config.output_filenames,
629-
cx.invocation_temp.as_deref(),
630-
&profiler,
631-
cgu_name,
632-
module,
633-
cx.debug_context,
634-
global_asm_object_file,
635-
&producer,
636-
)
637-
});
613+
let global_asm_object_file = crate::global_asm::compile_global_asm(
614+
&global_asm_config,
615+
&cgu_name,
616+
&cx.global_asm,
617+
cx.invocation_temp.as_deref(),
618+
)?;
619+
620+
let codegen_result = emit_cgu(
621+
&global_asm_config.output_filenames,
622+
cx.invocation_temp.as_deref(),
623+
&profiler,
624+
cgu_name,
625+
module,
626+
cx.debug_context,
627+
global_asm_object_file,
628+
&producer,
629+
);
638630
std::mem::drop(token);
639631
codegen_result
640632
}))

compiler/rustc_codegen_cranelift/src/driver/mod.rs

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,37 @@ fn predefine_mono_items<'tcx>(
1919
module: &mut dyn Module,
2020
mono_items: &[(MonoItem<'tcx>, MonoItemData)],
2121
) {
22-
tcx.prof.generic_activity("predefine functions").run(|| {
23-
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
24-
for &(mono_item, data) in mono_items {
25-
match mono_item {
26-
MonoItem::Fn(instance) => {
27-
let name = tcx.symbol_name(instance).name;
28-
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
29-
let sig =
30-
get_function_sig(tcx, module.target_config().default_call_conv, instance);
31-
let linkage = crate::linkage::get_clif_linkage(
32-
mono_item,
33-
data.linkage,
34-
data.visibility,
35-
is_compiler_builtins,
36-
);
37-
let is_naked = tcx
38-
.codegen_fn_attrs(instance.def_id())
39-
.flags
40-
.contains(CodegenFnAttrFlags::NAKED);
41-
module
42-
.declare_function(
43-
name,
44-
// Naked functions are defined in a separate object
45-
// file from the codegen unit rustc expects them to
46-
// be defined in.
47-
if is_naked { Linkage::Import } else { linkage },
48-
&sig,
49-
)
50-
.unwrap();
51-
}
52-
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
22+
let is_compiler_builtins = tcx.is_compiler_builtins(LOCAL_CRATE);
23+
for &(mono_item, data) in mono_items {
24+
match mono_item {
25+
MonoItem::Fn(instance) => {
26+
let name = tcx.symbol_name(instance).name;
27+
let _inst_guard = crate::PrintOnPanic(|| format!("{:?} {}", instance, name));
28+
let sig = get_function_sig(tcx, module.target_config().default_call_conv, instance);
29+
let linkage = crate::linkage::get_clif_linkage(
30+
mono_item,
31+
data.linkage,
32+
data.visibility,
33+
is_compiler_builtins,
34+
);
35+
let is_naked = tcx
36+
.codegen_fn_attrs(instance.def_id())
37+
.flags
38+
.contains(CodegenFnAttrFlags::NAKED);
39+
module
40+
.declare_function(
41+
name,
42+
// Naked functions are defined in a separate object
43+
// file from the codegen unit rustc expects them to
44+
// be defined in.
45+
if is_naked { Linkage::Import } else { linkage },
46+
&sig,
47+
)
48+
.unwrap();
5349
}
50+
MonoItem::Static(_) | MonoItem::GlobalAsm(_) => {}
5451
}
55-
});
52+
}
5653
}
5754

5855
struct MeasuremeProfiler(SelfProfilerRef);
@@ -72,15 +69,11 @@ impl Drop for TimingGuard {
7269
}
7370

7471
impl cranelift_codegen::timing::Profiler for MeasuremeProfiler {
75-
fn start_pass(&self, pass: cranelift_codegen::timing::Pass) -> Box<dyn std::any::Any> {
76-
let mut timing_guard = Box::new(TimingGuard {
72+
fn start_pass(&self, _pass: cranelift_codegen::timing::Pass) -> Box<dyn std::any::Any> {
73+
let timing_guard = Box::new(TimingGuard {
7774
profiler: std::mem::ManuallyDrop::new(self.0.clone()),
7875
inner: None,
7976
});
80-
timing_guard.inner = Some(
81-
unsafe { &*(&*timing_guard.profiler as &SelfProfilerRef as *const SelfProfilerRef) }
82-
.generic_activity(pass.description()),
83-
);
8477
timing_guard
8578
}
8679
}

0 commit comments

Comments
 (0)