Skip to content

Commit b02e5cc

Browse files
denismerigouxeddyb
authored andcommitted
Moved Backend interface into rustc_codegen_utils
1 parent b06836e commit b02e5cc

File tree

17 files changed

+129
-113
lines changed

17 files changed

+129
-113
lines changed

src/librustc_codegen_llvm/back/lto.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use rustc::util::common::time_ext;
2424
use rustc_data_structures::fx::FxHashMap;
2525
use rustc_codegen_utils::symbol_export;
2626
use time_graph::Timeline;
27-
use {ModuleCodegen, ModuleLlvm, ModuleKind};
27+
use ModuleLlvm;
28+
use rustc_codegen_utils::{ModuleCodegen, ModuleKind};
2829

2930
use libc;
3031

src/librustc_codegen_llvm/back/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use rustc::util::nodemap::FxHashMap;
2626
use time_graph::{self, TimeGraph, Timeline};
2727
use llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic};
2828
use llvm_util;
29-
use {CodegenResults, ModuleCodegen, CompiledModule, ModuleKind, ModuleLlvm,
30-
CachedModuleCodegen};
29+
use {CodegenResults, ModuleLlvm};
30+
use rustc_codegen_utils::{ModuleCodegen, ModuleKind, CachedModuleCodegen, CompiledModule};
3131
use CrateInfo;
3232
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
3333
use rustc::ty::TyCtxt;

src/librustc_codegen_llvm/base.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
//! int) and rec(x=int, y=int, z=int) will have the same llvm::Type.
2525
2626
use super::ModuleLlvm;
27-
use super::ModuleCodegen;
28-
use super::ModuleKind;
29-
use super::CachedModuleCodegen;
27+
use rustc_codegen_utils::{ModuleCodegen, ModuleKind, CachedModuleCodegen};
3028
use super::LlvmCodegenBackend;
3129

3230
use abi;
@@ -1197,25 +1195,3 @@ pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
11971195
Visibility::Protected => llvm::Visibility::Protected,
11981196
}
11991197
}
1200-
1201-
// FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
1202-
// the HashStable trait. Normally DepGraph::with_task() calls are
1203-
// hidden behind queries, but CGU creation is a special case in two
1204-
// ways: (1) it's not a query and (2) CGU are output nodes, so their
1205-
// Fingerprints are not actually needed. It remains to be clarified
1206-
// how exactly this case will be handled in the red/green system but
1207-
// for now we content ourselves with providing a no-op HashStable
1208-
// implementation for CGUs.
1209-
mod temp_stable_hash_impls {
1210-
use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
1211-
HashStable};
1212-
use {ModuleCodegen, ModuleLlvm};
1213-
1214-
impl<HCX> HashStable<HCX> for ModuleCodegen<ModuleLlvm> {
1215-
fn hash_stable<W: StableHasherResult>(&self,
1216-
_: &mut HCX,
1217-
_: &mut StableHasher<W>) {
1218-
// do nothing
1219-
}
1220-
}
1221-
}

src/librustc_codegen_llvm/interfaces/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::backend::Backend;
11+
use super::Backend;
1212
use super::HasCodegen;
1313
use mir::place::PlaceRef;
1414
use rustc::hir::{GlobalAsm, InlineAsm};

src/librustc_codegen_llvm/interfaces/builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
213213
fn set_cleanup(&self, landing_pad: Self::Value);
214214
fn resume(&self, exn: Self::Value) -> Self::Value;
215215
fn cleanup_pad(&self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;
216-
fn cleanup_ret(&self, funclet: &Self::Funclet, unwind: Option<Self::BasicBlock>) -> Self::Value;
216+
fn cleanup_ret(&self, funclet: &Self::Funclet, unwind: Option<Self::BasicBlock>)
217+
-> Self::Value;
217218
fn catch_pad(&self, parent: Self::Value, args: &[Self::Value]) -> Self::Funclet;
218219
fn catch_ret(&self, funclet: &Self::Funclet, unwind: Self::BasicBlock) -> Self::Value;
219220
fn catch_switch(

src/librustc_codegen_llvm/interfaces/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::backend::Backend;
11+
use super::Backend;
1212
use super::HasCodegen;
1313
use debuginfo::{FunctionDebugContext, MirDebugScope, VariableAccess, VariableKind};
1414
use monomorphize::Instance;

src/librustc_codegen_llvm/interfaces/declare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::backend::Backend;
11+
use super::Backend;
1212
use monomorphize::Instance;
1313
use rustc::hir::def_id::DefId;
1414
use rustc::mir::mono::{Linkage, Visibility};

src/librustc_codegen_llvm/interfaces/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::backend::Backend;
11+
use super::Backend;
1212
use super::HasCodegen;
1313
use abi::FnType;
1414
use mir::operand::OperandRef;

src/librustc_codegen_llvm/interfaces/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::backend::Backend;
11+
use super::Backend;
1212
use libc::c_uint;
1313
use monomorphize::partitioning::CodegenUnit;
1414
use rustc::mir::mono::Stats;

src/librustc_codegen_llvm/interfaces/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
mod abi;
1212
mod asm;
13-
mod backend;
1413
mod builder;
1514
mod consts;
1615
mod debuginfo;
@@ -22,7 +21,6 @@ mod type_;
2221

2322
pub use self::abi::{AbiBuilderMethods, AbiMethods};
2423
pub use self::asm::{AsmBuilderMethods, AsmMethods};
25-
pub use self::backend::{Backend, BackendMethods, BackendTypes};
2624
pub use self::builder::BuilderMethods;
2725
pub use self::consts::ConstMethods;
2826
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};
@@ -33,8 +31,7 @@ pub use self::statics::StaticMethods;
3331
pub use self::type_::{
3432
ArgTypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, TypeMethods,
3533
};
36-
37-
use std::fmt;
34+
pub use rustc_codegen_utils::interfaces::{Backend, BackendMethods, BackendTypes, CodegenObject};
3835

3936
pub trait CodegenMethods<'tcx>:
4037
Backend<'tcx>
@@ -76,6 +73,3 @@ pub trait HasCodegen<'tcx>: Backend<'tcx> {
7673
DIScope = Self::DIScope,
7774
>;
7875
}
79-
80-
pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
81-
impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}

src/librustc_codegen_llvm/interfaces/statics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::backend::Backend;
11+
use super::Backend;
1212
use rustc::hir::def_id::DefId;
1313
use rustc::ty::layout::Align;
1414

src/librustc_codegen_llvm/interfaces/type_.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use super::backend::Backend;
11+
use super::Backend;
1212
use super::HasCodegen;
1313
use mir::place::PlaceRef;
1414
use rustc::ty::layout::TyLayout;

src/librustc_codegen_llvm/lib.rs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#![feature(static_nobundle)]
3838

3939
use back::write::create_target_machine;
40-
use rustc::dep_graph::WorkProduct;
4140
use syntax_pos::symbol::Symbol;
4241

4342
#[macro_use] extern crate bitflags;
@@ -67,7 +66,6 @@ extern crate cc; // Used to locate MSVC
6766
extern crate tempfile;
6867
extern crate memmap;
6968

70-
use back::bytecode::RLIB_BYTECODE_EXTENSION;
7169
use interfaces::*;
7270
use time_graph::TimeGraph;
7371
use std::sync::mpsc::Receiver;
@@ -93,7 +91,7 @@ use rustc::util::time_graph;
9391
use rustc::util::nodemap::{FxHashSet, FxHashMap};
9492
use rustc::util::profiling::ProfileCategory;
9593
use rustc_mir::monomorphize;
96-
use rustc_codegen_utils::{CompiledModule, ModuleKind};
94+
use rustc_codegen_utils::{ModuleCodegen, CompiledModule};
9795
use rustc_codegen_utils::codegen_backend::CodegenBackend;
9896
use rustc_data_structures::svh::Svh;
9997

@@ -329,56 +327,6 @@ pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
329327
LlvmCodegenBackend::new()
330328
}
331329

332-
pub struct ModuleCodegen<M> {
333-
/// The name of the module. When the crate may be saved between
334-
/// compilations, incremental compilation requires that name be
335-
/// unique amongst **all** crates. Therefore, it should contain
336-
/// something unique to this crate (e.g., a module path) as well
337-
/// as the crate name and disambiguator.
338-
/// We currently generate these names via CodegenUnit::build_cgu_name().
339-
name: String,
340-
module_llvm: M,
341-
kind: ModuleKind,
342-
}
343-
344-
struct CachedModuleCodegen {
345-
name: String,
346-
source: WorkProduct,
347-
}
348-
349-
impl ModuleCodegen<ModuleLlvm> {
350-
fn into_compiled_module(self,
351-
emit_obj: bool,
352-
emit_bc: bool,
353-
emit_bc_compressed: bool,
354-
outputs: &OutputFilenames) -> CompiledModule {
355-
let object = if emit_obj {
356-
Some(outputs.temp_path(OutputType::Object, Some(&self.name)))
357-
} else {
358-
None
359-
};
360-
let bytecode = if emit_bc {
361-
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name)))
362-
} else {
363-
None
364-
};
365-
let bytecode_compressed = if emit_bc_compressed {
366-
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name))
367-
.with_extension(RLIB_BYTECODE_EXTENSION))
368-
} else {
369-
None
370-
};
371-
372-
CompiledModule {
373-
name: self.name.clone(),
374-
kind: self.kind,
375-
object,
376-
bytecode,
377-
bytecode_compressed,
378-
}
379-
}
380-
}
381-
382330
pub struct ModuleLlvm {
383331
llcx: &'static mut llvm::Context,
384332
llmod_raw: *const llvm::Module,

src/librustc_codegen_utils/common.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,25 @@ pub enum TypeKind {
113113
X86_MMX,
114114
Token,
115115
}
116+
117+
// FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
118+
// the HashStable trait. Normally DepGraph::with_task() calls are
119+
// hidden behind queries, but CGU creation is a special case in two
120+
// ways: (1) it's not a query and (2) CGU are output nodes, so their
121+
// Fingerprints are not actually needed. It remains to be clarified
122+
// how exactly this case will be handled in the red/green system but
123+
// for now we content ourselves with providing a no-op HashStable
124+
// implementation for CGUs.
125+
mod temp_stable_hash_impls {
126+
use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
127+
HashStable};
128+
use ModuleCodegen;
129+
130+
impl<HCX, M> HashStable<HCX> for ModuleCodegen<M> {
131+
fn hash_stable<W: StableHasherResult>(&self,
132+
_: &mut HCX,
133+
_: &mut StableHasher<W>) {
134+
// do nothing
135+
}
136+
}
137+
}

src/librustc_codegen_llvm/interfaces/backend.rs renamed to src/librustc_codegen_utils/interfaces/backend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use rustc::middle::cstore::EncodedMetadata;
1717
use rustc::mir::mono::Stats;
1818
use rustc::session::Session;
1919
use rustc::ty::TyCtxt;
20+
use rustc::util::time_graph::TimeGraph;
2021
use std::any::Any;
2122
use std::sync::mpsc::Receiver;
2223
use syntax_pos::symbol::InternedString;
23-
use time_graph::TimeGraph;
2424
use ModuleCodegen;
2525

2626
pub trait BackendTypes {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
mod backend;
12+
13+
pub use self::backend::{Backend, BackendMethods, BackendTypes};
14+
15+
use std::fmt;
16+
17+
pub trait CodegenObject: Copy + PartialEq + fmt::Debug {}
18+
impl<T: Copy + PartialEq + fmt::Debug> CodegenObject for T {}

0 commit comments

Comments
 (0)