Merge commit '39683d8eb7
' into sync_cg_gcc-2022-03-26
This commit is contained in:
commit
bbff48e094
35 changed files with 1705 additions and 558 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* TODO(antoyo): implement equality in libgccjit based on https://zpz.github.io/blog/overloading-equality-operator-in-cpp-class-hierarchy/ (for type equality?)
|
||||
* TODO(antoyo): support #[inline] attributes.
|
||||
* TODO(antoyo): support LTO.
|
||||
* TODO(antoyo): support LTO (gcc's equivalent to Thin LTO is enabled by -fwhopr: https://stackoverflow.com/questions/64954525/does-gcc-have-thin-lto).
|
||||
*
|
||||
* TODO(antoyo): remove the patches.
|
||||
*/
|
||||
|
@ -21,6 +22,7 @@ extern crate rustc_middle;
|
|||
extern crate rustc_session;
|
||||
extern crate rustc_span;
|
||||
extern crate rustc_target;
|
||||
extern crate tempfile;
|
||||
|
||||
// This prevents duplicating functions and statics that are already part of the host rustc process.
|
||||
#[allow(unused_extern_crates)]
|
||||
|
@ -40,15 +42,16 @@ mod context;
|
|||
mod coverageinfo;
|
||||
mod debuginfo;
|
||||
mod declare;
|
||||
mod int;
|
||||
mod intrinsic;
|
||||
mod mono_item;
|
||||
mod type_;
|
||||
mod type_of;
|
||||
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use gccjit::{Context, OptimizationLevel};
|
||||
use gccjit::{Context, OptimizationLevel, CType};
|
||||
use rustc_ast::expand::allocator::AllocatorKind;
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
|
||||
use rustc_codegen_ssa::base::codegen_crate;
|
||||
|
@ -61,10 +64,12 @@ use rustc_errors::{ErrorGuaranteed, Handler};
|
|||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_session::config::{Lto, OptLevel, OutputFilenames};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_span::fatal_error::FatalError;
|
||||
use tempfile::TempDir;
|
||||
|
||||
pub struct PrintOnPanic<F: Fn() -> String>(pub F);
|
||||
|
||||
|
@ -77,13 +82,29 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GccCodegenBackend;
|
||||
pub struct GccCodegenBackend {
|
||||
supports_128bit_integers: Arc<Mutex<bool>>,
|
||||
}
|
||||
|
||||
impl CodegenBackend for GccCodegenBackend {
|
||||
fn init(&self, sess: &Session) {
|
||||
if sess.lto() != Lto::No {
|
||||
sess.warn("LTO is not supported. You may get a linker error.");
|
||||
}
|
||||
|
||||
let temp_dir = TempDir::new().expect("cannot create temporary directory");
|
||||
let temp_file = temp_dir.into_path().join("result.asm");
|
||||
let check_context = Context::default();
|
||||
check_context.set_print_errors_to_stderr(false);
|
||||
let _int128_ty = check_context.new_c_type(CType::UInt128t);
|
||||
// NOTE: we cannot just call compile() as this would require other files than libgccjit.so.
|
||||
check_context.compile_to_file(gccjit::OutputKind::Assembler, temp_file.to_str().expect("path to str"));
|
||||
*self.supports_128bit_integers.lock().expect("lock") = check_context.get_last_error() == Ok(None);
|
||||
}
|
||||
|
||||
fn provide(&self, providers: &mut Providers) {
|
||||
// FIXME(antoyo) compute list of enabled features from cli flags
|
||||
providers.global_backend_features = |_tcx, ()| vec![];
|
||||
}
|
||||
|
||||
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>, metadata: EncodedMetadata, need_metadata_module: bool) -> Box<dyn Any> {
|
||||
|
@ -129,7 +150,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
|
|||
}
|
||||
|
||||
fn compile_codegen_unit<'tcx>(&self, tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (ModuleCodegen<Self::Module>, u64) {
|
||||
base::compile_codegen_unit(tcx, cgu_name)
|
||||
base::compile_codegen_unit(tcx, cgu_name, *self.supports_128bit_integers.lock().expect("lock"))
|
||||
}
|
||||
|
||||
fn target_machine_factory(&self, _sess: &Session, _opt_level: OptLevel, _features: &[String]) -> TargetMachineFactoryFn<Self> {
|
||||
|
@ -237,7 +258,9 @@ impl WriteBackendMethods for GccCodegenBackend {
|
|||
/// This is the entrypoint for a hot plugged rustc_codegen_gccjit
|
||||
#[no_mangle]
|
||||
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
|
||||
Box::new(GccCodegenBackend)
|
||||
Box::new(GccCodegenBackend {
|
||||
supports_128bit_integers: Arc::new(Mutex::new(false)),
|
||||
})
|
||||
}
|
||||
|
||||
fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue