Skip to content

Commit 7f02604

Browse files
authored
Rollup merge of #92877 - Amanieu:remove_llvm_nounwind, r=Mark-Simulacrum
Remove LLVMRustMarkAllFunctionsNounwind This was originally introduced in #10916 as a way to remove all landing pads when performing LTO. However this is no longer necessary today since rustc properly marks all functions and call-sites as nounwind where appropriate. In fact this is incorrect in the presence of `extern "C-unwind"` which must create a landing pad when compiled with `-C panic=abort` so that foreign exceptions are caught and properly turned into aborts.
2 parents 6acb704 + 606d9c0 commit 7f02604

File tree

4 files changed

+1
-40
lines changed

4 files changed

+1
-40
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

-17
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,6 @@ fn fat_lto(
349349
);
350350
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
351351
}
352-
353-
if cgcx.no_landing_pads {
354-
unsafe {
355-
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
356-
}
357-
save_temp_bitcode(cgcx, &module, "lto.after-nounwind");
358-
}
359352
}
360353

361354
Ok(LtoModuleCodegen::Fat { module: Some(module), _serialized_bitcode: serialized_bitcode })
@@ -770,16 +763,6 @@ pub unsafe fn optimize_thin_module(
770763
return Err(write::llvm_err(&diag_handler, msg));
771764
}
772765

773-
// Like with "fat" LTO, get some better optimizations if landing pads
774-
// are disabled by removing all landing pads.
775-
if cgcx.no_landing_pads {
776-
let _timer = cgcx
777-
.prof
778-
.generic_activity_with_arg("LLVM_thin_lto_remove_landing_pads", thin_module.name());
779-
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
780-
save_temp_bitcode(cgcx, &module, "thin-lto-after-nounwind");
781-
}
782-
783766
// Up next comes the per-module local analyses that we do for Thin LTO.
784767
// Each of these functions is basically copied from the LLVM
785768
// implementation and then tailored to suit this implementation. Ideally

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,6 @@ extern "C" {
23202320
pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
23212321
pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
23222322
pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
2323-
pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);
23242323

23252324
pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
23262325
pub fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;

compiler/rustc_codegen_ssa/src/back/write.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_session::Session;
3232
use rustc_span::source_map::SourceMap;
3333
use rustc_span::symbol::sym;
3434
use rustc_span::{BytePos, FileName, InnerSpan, Pos, Span};
35-
use rustc_target::spec::{MergeFunctions, PanicStrategy, SanitizerSet};
35+
use rustc_target::spec::{MergeFunctions, SanitizerSet};
3636

3737
use std::any::Any;
3838
use std::fs;
@@ -313,7 +313,6 @@ pub struct CodegenContext<B: WriteBackendMethods> {
313313
pub backend: B,
314314
pub prof: SelfProfilerRef,
315315
pub lto: Lto,
316-
pub no_landing_pads: bool,
317316
pub save_temps: bool,
318317
pub fewer_names: bool,
319318
pub time_trace: bool,
@@ -1039,7 +1038,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
10391038
crate_types: sess.crate_types().to_vec(),
10401039
each_linked_rlib_for_lto,
10411040
lto: sess.lto(),
1042-
no_landing_pads: sess.panic_strategy() == PanicStrategy::Abort,
10431041
fewer_names: sess.fewer_names(),
10441042
save_temps: sess.opts.cg.save_temps,
10451043
time_trace: sess.opts.debugging_opts.llvm_time_trace,

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

-19
Original file line numberDiff line numberDiff line change
@@ -1168,25 +1168,6 @@ extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
11681168
passes.run(*unwrap(M));
11691169
}
11701170

1171-
extern "C" void LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
1172-
for (Module::iterator GV = unwrap(M)->begin(), E = unwrap(M)->end(); GV != E;
1173-
++GV) {
1174-
GV->setDoesNotThrow();
1175-
Function *F = dyn_cast<Function>(GV);
1176-
if (F == nullptr)
1177-
continue;
1178-
1179-
for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
1180-
for (BasicBlock::iterator I = B->begin(), IE = B->end(); I != IE; ++I) {
1181-
if (isa<InvokeInst>(I)) {
1182-
InvokeInst *CI = cast<InvokeInst>(I);
1183-
CI->setDoesNotThrow();
1184-
}
1185-
}
1186-
}
1187-
}
1188-
}
1189-
11901171
extern "C" void
11911172
LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
11921173
LLVMTargetMachineRef TMR) {

0 commit comments

Comments
 (0)