Skip to content

Commit ba833af

Browse files
committed
Allow non-LTO mode
1 parent 75aea04 commit ba833af

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

src/driver/lto.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ pub(crate) fn run_aot(
210210
metadata: EncodedMetadata,
211211
need_metadata_module: bool,
212212
) -> Box<OngoingCodegen> {
213+
tcx.dcx().note(format!("Using LTO for {}", tcx.crate_name(LOCAL_CRATE)));
214+
213215
// FIXME handle `-Ctarget-cpu=native`
214216
let target_cpu = match tcx.sess.opts.cg.target_cpu {
215217
Some(ref name) => name,

src/lib.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
166166
}
167167

168168
fn init(&self, sess: &Session) {
169-
use rustc_session::config::{InstrumentCoverage, Lto};
170-
match sess.lto() {
171-
Lto::No | Lto::ThinLocal => {
172-
if sess.opts.crate_name.as_deref() != Some("___") {
173-
sess.dcx().fatal("No LTO");
174-
}
175-
}
176-
Lto::Thin | Lto::Fat => {}
177-
}
178-
169+
use rustc_session::config::InstrumentCoverage;
179170
if sess.opts.cg.instrument_coverage() != InstrumentCoverage::No {
180171
sess.dcx()
181172
.fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift");
@@ -219,27 +210,23 @@ impl CodegenBackend for CraneliftCodegenBackend {
219210
.unwrap_or_else(|err| tcx.sess.dcx().fatal(err))
220211
});
221212
match config.codegen_mode {
222-
CodegenMode::Aot => {
223-
match tcx.sess.lto() {
224-
Lto::No | Lto::ThinLocal => {
225-
driver::aot::run_aot(tcx, metadata, need_metadata_module)
226-
}
227-
Lto::Thin | Lto::Fat => {
228-
if tcx.crate_name(LOCAL_CRATE).as_str() == "compiler_builtins" {
229-
// FIXME remove special case once inline asm is supported in LTO mode
230-
driver::aot::run_aot(tcx, metadata, need_metadata_module)
231-
} else {
232-
#[cfg(feature = "lto")]
233-
return driver::lto::run_aot(tcx, metadata, need_metadata_module);
234-
235-
#[cfg(not(feature = "lto"))]
236-
tcx.dcx().fatal(
237-
"LTO support was disabled when compiling rustc_codegen_cranelift",
238-
);
239-
}
213+
CodegenMode::Aot => match tcx.sess.lto() {
214+
Lto::No | Lto::ThinLocal => {
215+
driver::aot::run_aot(tcx, metadata, need_metadata_module)
216+
}
217+
Lto::Thin | Lto::Fat => {
218+
if tcx.crate_name(LOCAL_CRATE) == sym::compiler_builtins {
219+
return driver::aot::run_aot(tcx, metadata, need_metadata_module);
240220
}
221+
222+
#[cfg(feature = "lto")]
223+
return driver::lto::run_aot(tcx, metadata, need_metadata_module);
224+
225+
#[cfg(not(feature = "lto"))]
226+
tcx.dcx()
227+
.fatal("LTO support was disabled when compiling rustc_codegen_cranelift");
241228
}
242-
}
229+
},
243230
CodegenMode::Jit | CodegenMode::JitLazy => {
244231
#[cfg(feature = "jit")]
245232
driver::jit::run_jit(tcx, config.codegen_mode, config.jit_args);

0 commit comments

Comments
 (0)