Skip to content

rustc_codegen_llvm: traitification of LLVM-specific CodegenCx and Builder methods #54012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 76 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
1f3faa8
rustc_codegen_llvm: begin generalizing over backend values.
irinagpopa Aug 2, 2018
67f94d8
Reduced line length to pass tidy
denismerigoux Aug 3, 2018
bc2897e
Generalized base.rs#call_memcpy and everything that it uses
denismerigoux Aug 7, 2018
ba2ed26
Generalized BasicBlocks in BuilderMethods trait
denismerigoux Aug 20, 2018
a4f6f8e
Generalized IntPredicate in the BuilderMethods trait
denismerigoux Aug 20, 2018
c42cf09
Generalized RealPredicate
denismerigoux Aug 21, 2018
138b446
Removed useless traits for IntPredicate and RealPredicate
denismerigoux Aug 21, 2018
c62e222
Generalized OperandBundleDef in BuilderMethods
denismerigoux Aug 21, 2018
6d78a14
Generalized AtomicRmwBinOp for BuilderMethods
denismerigoux Aug 21, 2018
733840b
Generalized AtomicOrdering for BuilderMethods
denismerigoux Aug 21, 2018
a401974
Generalized SynchronisationScope for BuilderMethods
denismerigoux Aug 21, 2018
b83a2b7
Generalized AsmDialect for BuilderMethods
denismerigoux Aug 21, 2018
958f94b
Removed genericity over Value in various functions
denismerigoux Aug 22, 2018
234f537
Line too long split
denismerigoux Aug 22, 2018
9be7a5e
Use associated types instead of type parameters inside the BuilderMet…
denismerigoux Aug 22, 2018
17e3189
Removed parasite yaml file and put explicit lifetimes
denismerigoux Aug 23, 2018
2680e1b
Use real type names rather than Self::
denismerigoux Aug 23, 2018
2d8ccf2
Fixed borrow-checker deficiency at stage 1
denismerigoux Aug 23, 2018
28ee44a
New files and folders for traits
denismerigoux Aug 28, 2018
78fbb2d
New Backend trait containing associated types
denismerigoux Aug 28, 2018
dfa4f77
Traitification of common.rs methods
denismerigoux Aug 28, 2018
67e865f
Replaced Codegen field access by trait method
denismerigoux Aug 28, 2018
1174b40
Added self argument for Codegen CommonMethod trait methods
denismerigoux Aug 29, 2018
a054141
Split CommonMethods to accomodate for use in back/write.rs
denismerigoux Aug 29, 2018
c67788d
CommonWriteMethods are not static any more
denismerigoux Aug 29, 2018
bfea5b2
Removed code duplication for CommonWriteMethods
denismerigoux Aug 30, 2018
b588c00
All CommonMethods now real methods (not static)
denismerigoux Aug 30, 2018
012a6e5
Use the method form for CodegenCx everywhere
denismerigoux Aug 30, 2018
638f4ac
Small generalization of some CodegenCx methods
denismerigoux Aug 30, 2018
89cd9c0
Added definition of type trait
denismerigoux Aug 30, 2018
1d8e6dc
Traitification of type_ methods
denismerigoux Sep 5, 2018
3160690
Work around to fix issue https://github.com/rust-lang/rust/issues/53912
denismerigoux Sep 6, 2018
f8bdd1f
Prefixed const methods with "const" instead of "c"
denismerigoux Sep 6, 2018
49e5874
Prefixed type methods & removed trait impl for write::CodegenContext
denismerigoux Sep 6, 2018
2a513df
Removing LLVM content from CommonMethods -> ConstMethods
denismerigoux Sep 6, 2018
79ea68f
Removed phantomdata no longer necessary
denismerigoux Sep 6, 2018
18216fc
Fixed typos
denismerigoux Sep 7, 2018
626d3cb
Attempt at including CodegenCx within Builder with Associated types
denismerigoux Sep 7, 2018
1ef9f8f
Generalized some base.rs methods
denismerigoux Sep 7, 2018
5428c7e
Generalized memset and memcpy
denismerigoux Sep 7, 2018
20a7eef
Added StaticMethods trait
denismerigoux Sep 10, 2018
037bc7a
Transfered memcpy and memset to BuilderMethods
denismerigoux Sep 10, 2018
ff46476
Traitified IntrinsicCallMethods
denismerigoux Sep 11, 2018
9a8dfd7
Generalized base::unsized_info
denismerigoux Sep 13, 2018
56f3990
Generalized base::unsize_thin_ptr
denismerigoux Sep 13, 2018
8b9ff39
Generalized base::coerce_unsized_into
denismerigoux Sep 14, 2018
c71c6cc
Generalized mir::codegen_mir (and all subsequent functions)
denismerigoux Sep 20, 2018
da0cf8c
Added 'll lifetime parameter to backend
denismerigoux Sep 21, 2018
29f4d0e
Added new lifetimes for Funclets in FunctionsCx -> compiles
denismerigoux Sep 21, 2018
88a5dea
Tidy too long lines
denismerigoux Sep 21, 2018
48af59f
Generalized mono_item.rs and base.rs:codegen_instance
denismerigoux Sep 21, 2018
8ea0331
Adapt code to latest rustc master changes
denismerigoux Sep 24, 2018
2e8af91
Generalized base:maybe_create_entry_wrapper
denismerigoux Sep 24, 2018
4460972
Move doc to trait declarations
denismerigoux Sep 24, 2018
df5a57c
Generalized base:codegen_crate
denismerigoux Sep 25, 2018
440f2fb
Renamed lifetimes for better understanding
denismerigoux Sep 26, 2018
0c10974
Preparing the generalization of base:compile_coodegen_unit
denismerigoux Sep 26, 2018
3f6f753
Added compile codegen to backend trait
denismerigoux Sep 27, 2018
570d3c0
Starting to move backend-agnostic code into codegen_utils
denismerigoux Sep 28, 2018
0da5170
Moved common.rs enums
denismerigoux Sep 28, 2018
a03673c
Moved OperandBundleDef
denismerigoux Sep 28, 2018
4a2f7c7
Adapt to latest rustc master changes
denismerigoux Sep 28, 2018
b8e7061
Moved Funclet
denismerigoux Sep 28, 2018
c785979
Moved Backend interface into rustc_codegen_utils
denismerigoux Oct 1, 2018
9a05142
Adapted to lastest rustc master changes
denismerigoux Oct 1, 2018
31dee75
Beginning of moving all backend-agnostic code to rustc_codegen_ssa
denismerigoux Oct 1, 2018
26e18a1
Moved DeclareMethods, MiscMethods and StaticMethods
denismerigoux Oct 2, 2018
431601c
Greate separation of librsutc_codegen_llvm : librustc_codegen_ssa com…
denismerigoux Oct 3, 2018
9fe9347
Finished moving backend-agnostic code to rustc_codegen_ssa
denismerigoux Oct 3, 2018
58c8f32
Fix lines too long
denismerigoux Oct 4, 2018
2a6412b
Added some docs + start to &mut self builder methods
denismerigoux Oct 4, 2018
376f4fe
All Builder methods now take &mut self instead of &self
denismerigoux Oct 5, 2018
afd940a
Added default impl for DerivedTypeMethods + empty impl for Cranelift …
denismerigoux Oct 9, 2018
b2c66a2
Traits skeletton fully in place
denismerigoux Oct 10, 2018
6d63072
Separating the back folder between backend-agnostic and LLVM-specific…
denismerigoux Oct 23, 2018
1cdea08
Added README explaining the refactoring
denismerigoux Oct 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved Backend interface into rustc_codegen_utils
  • Loading branch information
denismerigoux committed Oct 23, 2018
commit c785979e7ca5940aceed4fd1c39ed77d24e24789
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use rustc::session::config::{self, Lto};
use rustc::util::common::time_ext;
use rustc_data_structures::fx::FxHashMap;
use time_graph::Timeline;
use {ModuleCodegen, ModuleLlvm, ModuleKind};
use ModuleLlvm;
use rustc_codegen_utils::{ModuleCodegen, ModuleKind};

use libc;

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use rustc::util::nodemap::FxHashMap;
use time_graph::{self, TimeGraph, Timeline};
use llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic};
use llvm_util;
use {CodegenResults, ModuleCodegen, CompiledModule, ModuleKind, ModuleLlvm,
CachedModuleCodegen};
use {CodegenResults, ModuleLlvm};
use rustc_codegen_utils::{ModuleCodegen, ModuleKind, CachedModuleCodegen, CompiledModule};
use CrateInfo;
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc::ty::TyCtxt;
Expand Down
26 changes: 1 addition & 25 deletions src/librustc_codegen_llvm/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
//! int) and rec(x=int, y=int, z=int) will have the same llvm::Type.

use super::ModuleLlvm;
use super::ModuleCodegen;
use super::ModuleKind;
use super::CachedModuleCodegen;
use rustc_codegen_utils::{ModuleCodegen, ModuleKind, CachedModuleCodegen};
use super::LlvmCodegenBackend;

use abi;
Expand Down Expand Up @@ -1314,25 +1312,3 @@ pub fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility {
Visibility::Protected => llvm::Visibility::Protected,
}
}

// FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
// the HashStable trait. Normally DepGraph::with_task() calls are
// hidden behind queries, but CGU creation is a special case in two
// ways: (1) it's not a query and (2) CGU are output nodes, so their
// Fingerprints are not actually needed. It remains to be clarified
// how exactly this case will be handled in the red/green system but
// for now we content ourselves with providing a no-op HashStable
// implementation for CGUs.
mod temp_stable_hash_impls {
use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
HashStable};
use {ModuleCodegen, ModuleLlvm};

impl<HCX> HashStable<HCX> for ModuleCodegen<ModuleLlvm> {
fn hash_stable<W: StableHasherResult>(&self,
_: &mut HCX,
_: &mut StableHasher<W>) {
// do nothing
}
}
}
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use abi::FnType;
use rustc::ty::{FnSig, Ty, Instance};
use super::backend::Backend;
use super::Backend;
use super::builder::HasCodegen;

pub trait AbiMethods<'tcx> {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use rustc::hir::{InlineAsm, GlobalAsm};
use mir::place::PlaceRef;
use super::backend::Backend;
use super::Backend;
use super::builder::HasCodegen;

pub trait AsmBuilderMethods<'a, 'll: 'a, 'tcx: 'll> : HasCodegen<'a, 'll, 'tcx>{
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use libc::c_char;
use rustc::ty::TyCtxt;
use rustc::ty::layout::{Align, Size};
use builder::MemFlags;
use super::backend::Backend;
use super::Backend;
use super::CodegenMethods;
use super::debuginfo::DebugInfoBuilderMethods;
use super::intrinsic::IntrinsicCallMethods;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use rustc::ty::{Ty, FnSig};
use super::backend::Backend;
use super::Backend;
use super::builder::HasCodegen;
use rustc::mir;
use monomorphize::Instance;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.

use rustc::ty::Ty;
use super::backend::Backend;
use super::Backend;
use rustc::hir::def_id::DefId;
use rustc::mir::mono::{Linkage, Visibility};
use monomorphize::Instance;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::backend::Backend;
use super::Backend;
use super::builder::HasCodegen;
use mir::operand::OperandRef;
use rustc::ty::Ty;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::cell::RefCell;
use rustc::util::nodemap::FxHashMap;
use rustc::ty::{Ty, self, Instance};
use super::backend::Backend;
use super::Backend;
use rustc::session::Session;
use libc::c_uint;
use rustc::mir::mono::Stats;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_codegen_llvm/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

mod builder;
mod backend;
mod consts;
mod type_;
mod intrinsic;
Expand All @@ -21,7 +20,7 @@ mod declare;
mod asm;

pub use self::builder::{BuilderMethods, HasCodegen};
pub use self::backend::{Backend, BackendMethods};
pub use rustc_codegen_utils::interfaces::{Backend, BackendMethods};
pub use self::consts::ConstMethods;
pub use self::type_::{TypeMethods, BaseTypeMethods, DerivedTypeMethods,
LayoutTypeMethods, ArgTypeMethods};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use rustc::ty::layout::Align;
use rustc::hir::def_id::DefId;
use super::backend::Backend;
use super::Backend;

pub trait StaticMethods<'ll> : Backend<'ll> {
fn static_ptrcast(&self, val: Self::Value, ty: Self::Type) -> Self::Value;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/interfaces/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use super::backend::Backend;
use super::Backend;
use super::builder::HasCodegen;
use rustc_codegen_utils::common::TypeKind;
use syntax::ast;
Expand Down
70 changes: 1 addition & 69 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#![feature(static_nobundle)]

use back::write::create_target_machine;
use rustc::dep_graph::WorkProduct;
use syntax_pos::symbol::Symbol;

#[macro_use] extern crate bitflags;
Expand Down Expand Up @@ -67,7 +66,6 @@ extern crate cc; // Used to locate MSVC
extern crate tempfile;
extern crate memmap;

use back::bytecode::RLIB_BYTECODE_EXTENSION;
use interfaces::*;
use time_graph::TimeGraph;
use std::sync::mpsc::Receiver;
Expand All @@ -77,7 +75,6 @@ use rustc::mir::mono::Stats;

pub use llvm_util::target_features;
use std::any::Any;
use std::path::{PathBuf};
use std::sync::mpsc;
use rustc_data_structures::sync::Lrc;

Expand All @@ -94,6 +91,7 @@ use rustc::util::time_graph;
use rustc::util::nodemap::{FxHashSet, FxHashMap};
use rustc::util::profiling::ProfileCategory;
use rustc_mir::monomorphize;
use rustc_codegen_utils::{ModuleCodegen, CompiledModule};
use rustc_codegen_utils::codegen_backend::CodegenBackend;
use rustc_data_structures::svh::Svh;

Expand Down Expand Up @@ -336,72 +334,6 @@ pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
LlvmCodegenBackend::new()
}

pub struct ModuleCodegen<M> {
/// The name of the module. When the crate may be saved between
/// compilations, incremental compilation requires that name be
/// unique amongst **all** crates. Therefore, it should contain
/// something unique to this crate (e.g., a module path) as well
/// as the crate name and disambiguator.
/// We currently generate these names via CodegenUnit::build_cgu_name().
name: String,
module_llvm: M,
kind: ModuleKind,
}

struct CachedModuleCodegen {
name: String,
source: WorkProduct,
}

#[derive(Copy, Clone, Debug, PartialEq)]
enum ModuleKind {
Regular,
Metadata,
Allocator,
}

impl ModuleCodegen<ModuleLlvm> {
fn into_compiled_module(self,
emit_obj: bool,
emit_bc: bool,
emit_bc_compressed: bool,
outputs: &OutputFilenames) -> CompiledModule {
let object = if emit_obj {
Some(outputs.temp_path(OutputType::Object, Some(&self.name)))
} else {
None
};
let bytecode = if emit_bc {
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name)))
} else {
None
};
let bytecode_compressed = if emit_bc_compressed {
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name))
.with_extension(RLIB_BYTECODE_EXTENSION))
} else {
None
};

CompiledModule {
name: self.name.clone(),
kind: self.kind,
object,
bytecode,
bytecode_compressed,
}
}
}

#[derive(Debug)]
struct CompiledModule {
name: String,
kind: ModuleKind,
object: Option<PathBuf>,
bytecode: Option<PathBuf>,
bytecode_compressed: Option<PathBuf>,
}

pub struct ModuleLlvm {
llcx: &'static mut llvm::Context,
llmod_raw: *const llvm::Module,
Expand Down
22 changes: 22 additions & 0 deletions src/librustc_codegen_utils/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,25 @@ pub enum TypeKind {
X86_MMX,
Token,
}

// FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
// the HashStable trait. Normally DepGraph::with_task() calls are
// hidden behind queries, but CGU creation is a special case in two
// ways: (1) it's not a query and (2) CGU are output nodes, so their
// Fingerprints are not actually needed. It remains to be clarified
// how exactly this case will be handled in the red/green system but
// for now we content ourselves with providing a no-op HashStable
// implementation for CGUs.
mod temp_stable_hash_impls {
use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
HashStable};
use ModuleCodegen;

impl<HCX, M> HashStable<HCX> for ModuleCodegen<M> {
fn hash_stable<W: StableHasherResult>(&self,
_: &mut HCX,
_: &mut StableHasher<W>) {
// do nothing
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc::middle::allocator::AllocatorKind;
use rustc::ty::TyCtxt;
use rustc::mir::mono::Stats;
use syntax_pos::symbol::InternedString;
use time_graph::TimeGraph;
use rustc::util::time_graph::TimeGraph;
use std::sync::mpsc::Receiver;
use std::any::Any;

Expand Down
3 changes: 3 additions & 0 deletions src/librustc_codegen_utils/interfaces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
// except according to those terms.

use std::fmt;
mod backend;

pub use self::backend::{Backend, BackendMethods};

pub trait CodegenObject : Copy + PartialEq + fmt::Debug {}
72 changes: 72 additions & 0 deletions src/librustc_codegen_utils/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#![feature(custom_attribute)]
#![feature(nll)]
#![allow(unused_attributes)]
#![allow(dead_code)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]

Expand All @@ -40,7 +41,10 @@ extern crate syntax_pos;
#[macro_use] extern crate rustc_data_structures;
extern crate rustc_metadata_utils;

use std::path::PathBuf;
use rustc::ty::TyCtxt;
use rustc::dep_graph::WorkProduct;
use rustc::session::config::{OutputFilenames, OutputType};

pub mod link;
pub mod codegen_backend;
Expand All @@ -49,6 +53,74 @@ pub mod symbol_names_test;
pub mod common;
pub mod interfaces;

pub struct ModuleCodegen<M> {
/// The name of the module. When the crate may be saved between
/// compilations, incremental compilation requires that name be
/// unique amongst **all** crates. Therefore, it should contain
/// something unique to this crate (e.g., a module path) as well
/// as the crate name and disambiguator.
/// We currently generate these names via CodegenUnit::build_cgu_name().
pub name: String,
pub module_llvm: M,
pub kind: ModuleKind,
}

pub const RLIB_BYTECODE_EXTENSION: &str = "bc.z";

impl<M> ModuleCodegen<M> {
pub fn into_compiled_module(self,
emit_obj: bool,
emit_bc: bool,
emit_bc_compressed: bool,
outputs: &OutputFilenames) -> CompiledModule {
let object = if emit_obj {
Some(outputs.temp_path(OutputType::Object, Some(&self.name)))
} else {
None
};
let bytecode = if emit_bc {
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name)))
} else {
None
};
let bytecode_compressed = if emit_bc_compressed {
Some(outputs.temp_path(OutputType::Bitcode, Some(&self.name))
.with_extension(RLIB_BYTECODE_EXTENSION))
} else {
None
};

CompiledModule {
name: self.name.clone(),
kind: self.kind,
object,
bytecode,
bytecode_compressed,
}
}
}

#[derive(Debug)]
pub struct CompiledModule {
pub name: String,
pub kind: ModuleKind,
pub object: Option<PathBuf>,
pub bytecode: Option<PathBuf>,
pub bytecode_compressed: Option<PathBuf>,
}

pub struct CachedModuleCodegen {
pub name: String,
pub source: WorkProduct,
}

#[derive(Copy, Clone, Debug, PartialEq)]
pub enum ModuleKind {
Regular,
Metadata,
Allocator,
}

/// check for the #[rustc_error] annotation, which forces an
/// error in codegen. This is used to write compile-fail tests
/// that actually test that compilation succeeds without
Expand Down