Skip to content

Commit 11a347d

Browse files
committed
Allow non-LTO mode
1 parent 25433c9 commit 11a347d

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
@@ -209,6 +209,8 @@ pub(crate) fn run_aot(
209209
metadata: EncodedMetadata,
210210
need_metadata_module: bool,
211211
) -> Box<OngoingCodegen> {
212+
tcx.dcx().note(format!("Using LTO for {}", tcx.crate_name(LOCAL_CRATE)));
213+
212214
// FIXME handle `-Ctarget-cpu=native`
213215
let target_cpu = match tcx.sess.opts.cg.target_cpu {
214216
Some(ref name) => name,

src/lib.rs

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

165165
fn init(&self, sess: &Session) {
166-
use rustc_session::config::{InstrumentCoverage, Lto};
167-
match sess.lto() {
168-
Lto::No | Lto::ThinLocal => {
169-
if sess.opts.crate_name.as_deref() != Some("___") {
170-
sess.dcx().fatal("No LTO");
171-
}
172-
}
173-
Lto::Thin | Lto::Fat => {}
174-
}
175-
166+
use rustc_session::config::InstrumentCoverage;
176167
if sess.opts.cg.instrument_coverage() != InstrumentCoverage::No {
177168
sess.dcx()
178169
.fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift");
@@ -216,27 +207,23 @@ impl CodegenBackend for CraneliftCodegenBackend {
216207
.unwrap_or_else(|err| tcx.sess.dcx().fatal(err))
217208
});
218209
match config.codegen_mode {
219-
CodegenMode::Aot => {
220-
match tcx.sess.lto() {
221-
Lto::No | Lto::ThinLocal => {
222-
driver::aot::run_aot(tcx, metadata, need_metadata_module)
223-
}
224-
Lto::Thin | Lto::Fat => {
225-
if tcx.crate_name(LOCAL_CRATE).as_str() == "compiler_builtins" {
226-
// FIXME remove special case once inline asm is supported in LTO mode
227-
driver::aot::run_aot(tcx, metadata, need_metadata_module)
228-
} else {
229-
#[cfg(feature = "lto")]
230-
return driver::lto::run_aot(tcx, metadata, need_metadata_module);
231-
232-
#[cfg(not(feature = "lto"))]
233-
tcx.dcx().fatal(
234-
"LTO support was disabled when compiling rustc_codegen_cranelift",
235-
);
236-
}
210+
CodegenMode::Aot => match tcx.sess.lto() {
211+
Lto::No | Lto::ThinLocal => {
212+
driver::aot::run_aot(tcx, metadata, need_metadata_module)
213+
}
214+
Lto::Thin | Lto::Fat => {
215+
if tcx.crate_name(LOCAL_CRATE) == sym::compiler_builtins {
216+
return driver::aot::run_aot(tcx, metadata, need_metadata_module);
237217
}
218+
219+
#[cfg(feature = "lto")]
220+
return driver::lto::run_aot(tcx, metadata, need_metadata_module);
221+
222+
#[cfg(not(feature = "lto"))]
223+
tcx.dcx()
224+
.fatal("LTO support was disabled when compiling rustc_codegen_cranelift");
238225
}
239-
}
226+
},
240227
CodegenMode::Jit | CodegenMode::JitLazy => {
241228
#[cfg(feature = "jit")]
242229
driver::jit::run_jit(tcx, config.codegen_mode, config.jit_args);

0 commit comments

Comments
 (0)