提交 645841ea 编写于 作者: M Michael Woerister

async-llvm(8): Clean up resource management and drop LLVM modules ASAP.

上级 4282dd87
......@@ -237,8 +237,6 @@ pub fn compile_input(sess: &Session,
phase5_result);
phase5_result?;
write::cleanup_llvm(&trans);
phase_6_link_output(sess, &trans, &outputs);
// Now that we won't touch anything in the incremental compilation directory
......
此差异已折叠。
......@@ -27,6 +27,7 @@
use super::ModuleLlvm;
use super::ModuleSource;
use super::ModuleTranslation;
use super::ModuleKind;
use assert_module_sources;
use back::link;
......@@ -952,6 +953,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
llcx: metadata_llcx,
llmod: metadata_llmod,
}),
kind: ModuleKind::Metadata,
};
let no_builtins = attr::contains_name(&krate.attrs, "no_builtins");
......@@ -961,7 +963,7 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
!tcx.sess.opts.output_types.should_trans() {
let empty_exported_symbols = ExportedSymbols::empty();
let linker_info = LinkerInfo::new(&shared_ccx, &empty_exported_symbols);
return OngoingCrateTranslation {
let crate_translation = OngoingCrateTranslation {
crate_name: tcx.crate_name(LOCAL_CRATE),
link: link_meta,
metadata: metadata,
......@@ -970,12 +972,18 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
linker_info: linker_info,
windows_subsystem: None,
no_integrated_as: false,
result: ::std::cell::RefCell::new(Some(::back::write::RunLLVMPassesResult {
modules: vec![],
metadata_module: metadata_module,
allocator_module: None,
})),
result: ::std::cell::RefCell::new(None),
};
::back::write::run_passes(tcx.sess,
&crate_translation,
vec![],
metadata_module,
None,
&output_filenames.outputs,
output_filenames);
return crate_translation;
}
let exported_symbols = Arc::new(ExportedSymbols::compute(tcx,
......@@ -1047,7 +1055,8 @@ fn module_translation<'a, 'tcx>(
let module = ModuleTranslation {
name: cgu_name,
symbol_name_hash,
source: ModuleSource::Preexisting(buf.clone())
source: ModuleSource::Preexisting(buf.clone()),
kind: ModuleKind::Regular,
};
return (Stats::default(), module);
}
......@@ -1108,7 +1117,8 @@ fn module_translation<'a, 'tcx>(
source: ModuleSource::Translated(ModuleLlvm {
llcx: ccx.llcx(),
llmod: ccx.llmod(),
})
}),
kind: ModuleKind::Regular,
}
};
......@@ -1196,6 +1206,7 @@ fn module_translation<'a, 'tcx>(
name: link::ALLOCATOR_MODULE_NAME.to_string(),
symbol_name_hash: 0, // we always rebuild allocator shims
source: ModuleSource::Translated(modules),
kind: ModuleKind::Allocator,
})
}
});
......
......@@ -135,7 +135,6 @@ pub mod back {
mod type_of;
mod value;
#[derive(Clone)]
pub struct ModuleTranslation {
/// The name of the module. When the crate may be saved between
/// compilations, incremental compilation requires that name be
......@@ -145,6 +144,58 @@ pub struct ModuleTranslation {
pub name: String,
pub symbol_name_hash: u64,
pub source: ModuleSource,
pub kind: ModuleKind,
}
#[derive(Copy, Clone, Debug)]
pub enum ModuleKind {
Regular,
Metadata,
Allocator,
}
impl ModuleTranslation {
pub fn into_compiled_module(self, emit_obj: bool, emit_bc: bool) -> CompiledModule {
let pre_existing = match self.source {
ModuleSource::Preexisting(_) => true,
ModuleSource::Translated(_) => false,
};
CompiledModule {
name: self.name.clone(),
kind: self.kind,
symbol_name_hash: self.symbol_name_hash,
pre_existing,
emit_obj,
emit_bc,
}
}
}
impl Drop for ModuleTranslation {
fn drop(&mut self) {
match self.source {
ModuleSource::Preexisting(_) => {
// Nothing to dispose.
},
ModuleSource::Translated(llvm) => {
unsafe {
llvm::LLVMDisposeModule(llvm.llmod);
llvm::LLVMContextDispose(llvm.llcx);
}
},
}
}
}
#[derive(Debug)]
pub struct CompiledModule {
pub name: String,
pub kind: ModuleKind,
pub symbol_name_hash: u64,
pub pre_existing: bool,
pub emit_obj: bool,
pub emit_bc: bool,
}
#[derive(Clone)]
......@@ -156,7 +207,7 @@ pub enum ModuleSource {
Translated(ModuleLlvm),
}
#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub struct ModuleLlvm {
pub llcx: llvm::ContextRef,
pub llmod: llvm::ModuleRef,
......@@ -167,9 +218,9 @@ unsafe impl Sync for ModuleTranslation { }
pub struct CrateTranslation {
pub crate_name: Symbol,
pub modules: Vec<ModuleTranslation>,
pub metadata_module: ModuleTranslation,
pub allocator_module: Option<ModuleTranslation>,
pub modules: Vec<CompiledModule>,
pub metadata_module: CompiledModule,
pub allocator_module: Option<CompiledModule>,
pub link: rustc::middle::cstore::LinkMeta,
pub metadata: rustc::middle::cstore::EncodedMetadata,
pub exported_symbols: Arc<back::symbol_export::ExportedSymbols>,
......@@ -189,7 +240,7 @@ pub struct OngoingCrateTranslation {
pub no_integrated_as: bool,
// This will be replaced by a Future.
pub result: ::std::cell::RefCell<Option<back::write::RunLLVMPassesResult>>,
pub result: ::std::cell::RefCell<Option<back::write::CompiledModules>>,
}
impl OngoingCrateTranslation {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册