Skip to content

Commit

Permalink
Move doc to trait declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
denismerigoux authored and eddyb committed Nov 16, 2018
1 parent ac34068 commit 97825a3
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 111 deletions.
1 change: 0 additions & 1 deletion src/librustc_codegen_llvm/asm.rs
Expand Up @@ -25,7 +25,6 @@ use libc::{c_uint, c_char};


impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
// Take an inline assembly expression and splat it out via LLVM
fn codegen_inline_asm(
&self,
ia: &hir::InlineAsm,
Expand Down
68 changes: 34 additions & 34 deletions src/librustc_codegen_llvm/base.rs
Expand Up @@ -156,14 +156,14 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
}
}

pub fn compare_simd_types<'a, 'tcx: 'a, Builder: BuilderMethods<'a, 'tcx>>(
bx: &Builder,
lhs: Builder::Value,
rhs: Builder::Value,
pub fn compare_simd_types<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
bx: &Bx,
lhs: Bx::Value,
rhs: Bx::Value,
t: Ty<'tcx>,
ret_ty: Builder::Type,
ret_ty: Bx::Type,
op: hir::BinOpKind
) -> Builder::Value {
) -> Bx::Value {
let signed = match t.sty {
ty::Float(_) => {
let cmp = bin_op_to_fcmp_predicate(op);
Expand Down Expand Up @@ -332,31 +332,31 @@ pub fn coerce_unsized_into<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
}
}

pub fn cast_shift_expr_rhs<'a, 'tcx: 'a, Builder: BuilderMethods<'a, 'tcx>>(
bx: &Builder,
pub fn cast_shift_expr_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
bx: &Bx,
op: hir::BinOpKind,
lhs: Builder::Value,
rhs: Builder::Value
) -> Builder::Value {
lhs: Bx::Value,
rhs: Bx::Value
) -> Bx::Value {
cast_shift_rhs(bx, op, lhs, rhs, |a, b| bx.trunc(a, b), |a, b| bx.zext(a, b))
}

fn cast_shift_rhs<'a, 'tcx: 'a, F, G, Builder: BuilderMethods<'a, 'tcx>>(
bx: &Builder,
fn cast_shift_rhs<'a, 'tcx: 'a, F, G, Bx: BuilderMethods<'a, 'tcx>>(
bx: &Bx,
op: hir::BinOpKind,
lhs: Builder::Value,
rhs: Builder::Value,
lhs: Bx::Value,
rhs: Bx::Value,
trunc: F,
zext: G
) -> Builder::Value
) -> Bx::Value
where F: FnOnce(
Builder::Value,
Builder::Type
) -> Builder::Value,
Bx::Value,
Bx::Type
) -> Bx::Value,
G: FnOnce(
Builder::Value,
Builder::Type
) -> Builder::Value
Bx::Value,
Bx::Type
) -> Bx::Value
{
// Shifts may have any size int on the rhs
if op.is_shift() {
Expand Down Expand Up @@ -412,33 +412,33 @@ pub fn from_immediate<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
}
}

pub fn to_immediate<'a, 'tcx: 'a, Builder: BuilderMethods<'a, 'tcx>>(
bx: &Builder,
val: Builder::Value,
pub fn to_immediate<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
bx: &Bx,
val: Bx::Value,
layout: layout::TyLayout,
) -> Builder::Value {
) -> Bx::Value {
if let layout::Abi::Scalar(ref scalar) = layout.abi {
return to_immediate_scalar(bx, val, scalar);
}
val
}

pub fn to_immediate_scalar<'a, 'tcx: 'a, Builder: BuilderMethods<'a, 'tcx>>(
bx: &Builder,
val: Builder::Value,
pub fn to_immediate_scalar<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
bx: &Bx,
val: Bx::Value,
scalar: &layout::Scalar,
) -> Builder::Value {
) -> Bx::Value {
if scalar.is_bool() {
return bx.trunc(val, bx.cx().type_i1());
}
val
}

pub fn memcpy_ty<'a, 'tcx: 'a, Builder: BuilderMethods<'a, 'tcx>>(
bx: &Builder,
dst: Builder::Value,
pub fn memcpy_ty<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
bx: &Bx,
dst: Bx::Value,
dst_align: Align,
src: Builder::Value,
src: Bx::Value,
src_align: Align,
layout: TyLayout<'tcx>,
flags: MemFlags,
Expand Down
10 changes: 0 additions & 10 deletions src/librustc_codegen_llvm/builder.rs
Expand Up @@ -1265,7 +1265,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
}

/// Returns the ptr value that should be used for storing `val`.
fn check_store<'b>(&self,
val: &'ll Value,
ptr: &'ll Value) -> &'ll Value {
Expand All @@ -1285,7 +1284,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
}

/// Returns the args that should be used for a call to `llfn`.
fn check_call<'b>(&self,
typ: &str,
llfn: &'ll Value,
Expand Down Expand Up @@ -1336,14 +1334,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
self.call_lifetime_intrinsic("llvm.lifetime.end", ptr, size);
}

/// If LLVM lifetime intrinsic support is enabled (i.e. optimizations
/// on), and `ptr` is nonzero-sized, then extracts the size of `ptr`
/// and the intrinsic for `lt` and passes them to `emit`, which is in
/// charge of generating code to call the passed intrinsic on whatever
/// block of generated code is targeted for the intrinsic.
///
/// If LLVM lifetime intrinsic support is disabled (i.e. optimizations
/// off) or `ptr` is zero-sized, then no-op (does not call `emit`).
fn call_lifetime_intrinsic(&self, intrinsic: &str, ptr: &'ll Value, size: Size) {
if self.cx.sess().opts.optimize == config::OptLevel::No {
return;
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_codegen_llvm/callee.rs
Expand Up @@ -203,9 +203,7 @@ pub fn get_fn(
llfn
}

pub fn resolve_and_get_fn<'tcx,
Cx: Backend<'tcx> + MiscMethods<'tcx> + TypeMethods<'tcx>
>(
pub fn resolve_and_get_fn<'tcx, Cx: CodegenMethods<'tcx>>(
cx: &Cx,
def_id: DefId,
substs: &'tcx Substs<'tcx>,
Expand Down
6 changes: 0 additions & 6 deletions src/librustc_codegen_llvm/common.rs
Expand Up @@ -224,7 +224,6 @@ impl BackendTypes for CodegenCx<'ll, 'tcx> {
}

impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
// LLVM constant constructors.
fn const_null(&self, t: &'ll Type) -> &'ll Value {
unsafe {
llvm::LLVMConstNull(t)
Expand Down Expand Up @@ -286,9 +285,6 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
self.const_uint(self.type_i8(), i as u64)
}


// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
fn const_cstr(
&self,
s: LocalInternedString,
Expand Down Expand Up @@ -316,8 +312,6 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}

// NB: Do not use `do_spill_noroot` to make this into a constant string, or
// you will be kicked off fast isel. See issue #4352 for an example of this.
fn const_str_slice(&self, s: LocalInternedString) -> &'ll Value {
let len = s.len();
let cs = consts::ptrcast(self.const_cstr(s, false),
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_llvm/context.rs
Expand Up @@ -444,7 +444,6 @@ impl IntrinsicDeclarationMethods<'tcx> for CodegenCx<'b, 'tcx> {
self.declare_intrinsic(key).unwrap_or_else(|| bug!("unknown intrinsic '{}'", key))
}

/// Declare any llvm intrinsics that you might need
fn declare_intrinsic(
&self,
key: &str
Expand Down
6 changes: 0 additions & 6 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Expand Up @@ -285,12 +285,6 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
}

impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
/// Creates the function-specific debug context.
///
/// Returns the FunctionDebugContext for the function which holds state needed
/// for debug info creation. The function may also return another variant of the
/// FunctionDebugContext enum which indicates why no debuginfo should be created
/// for the function.
fn create_function_debug_context(
&self,
instance: Instance<'tcx>,
Expand Down
40 changes: 0 additions & 40 deletions src/librustc_codegen_llvm/declare.rs
Expand Up @@ -97,10 +97,6 @@ fn declare_raw_fn(

impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {

/// Declare a global value.
///
/// If there’s a value with the same name already declared, the function will
/// return its Value instead.
fn declare_global(
&self,
name: &str, ty: &'ll Type
Expand All @@ -112,13 +108,6 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}

/// Declare a C ABI function.
///
/// Only use this for foreign function ABIs and glue. For Rust functions use
/// `declare_fn` instead.
///
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing Value instead.
fn declare_cfn(
&self,
name: &str,
Expand All @@ -127,11 +116,6 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
declare_raw_fn(self, name, llvm::CCallConv, fn_type)
}


/// Declare a Rust function.
///
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing Value instead.
fn declare_fn(
&self,
name: &str,
Expand All @@ -157,13 +141,6 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
llfn
}


/// Declare a global with an intention to define it.
///
/// Use this function when you intend to define a global. This function will
/// return None if the name already has a definition associated with it. In that
/// case an error should be reported to the user, because it usually happens due
/// to user’s fault (e.g. misuse of #[no_mangle] or #[export_name] attributes).
fn define_global(
&self,
name: &str,
Expand All @@ -176,20 +153,12 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}

/// Declare a private global
///
/// Use this function when you intend to define a global without a name.
fn define_private_global(&self, ty: &'ll Type) -> &'ll Value {
unsafe {
llvm::LLVMRustInsertPrivateGlobal(self.llmod, ty)
}
}

/// Declare a Rust function with an intention to define it.
///
/// Use this function when you intend to define a function. This function will
/// return panic if the name already has a definition associated with it. This
/// can happen with #[no_mangle] or #[export_name], for example.
fn define_fn(
&self,
name: &str,
Expand All @@ -202,11 +171,6 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}
}

/// Declare a Rust function with an intention to define it.
///
/// Use this function when you intend to define a function. This function will
/// return panic if the name already has a definition associated with it. This
/// can happen with #[no_mangle] or #[export_name], for example.
fn define_internal_fn(
&self,
name: &str,
Expand All @@ -217,16 +181,12 @@ impl DeclareMethods<'tcx> for CodegenCx<'ll, 'tcx> {
llfn
}


/// Get declared value by name.
fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
debug!("get_declared_value(name={:?})", name);
let namebuf = SmallCStr::new(name);
unsafe { llvm::LLVMRustGetNamedValue(self.llmod, namebuf.as_ptr()) }
}

/// Get defined or externally defined (AvailableExternally linkage) value by
/// name.
fn get_defined_value(&self, name: &str) -> Option<&'ll Value> {
self.get_declared_value(name).and_then(|val|{
let declaration = unsafe {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/interfaces/asm.rs
Expand Up @@ -14,6 +14,7 @@ use mir::place::PlaceRef;
use rustc::hir::{GlobalAsm, InlineAsm};

pub trait AsmBuilderMethods<'tcx>: HasCodegen<'tcx> {
// Take an inline assembly expression and splat it out via LLVM
fn codegen_inline_asm(
&self,
ia: &InlineAsm,
Expand Down
11 changes: 11 additions & 0 deletions src/librustc_codegen_llvm/interfaces/builder.rs
Expand Up @@ -244,7 +244,10 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
fn add_incoming_to_phi(&self, phi: Self::Value, val: Self::Value, bb: Self::BasicBlock);
fn set_invariant_load(&self, load: Self::Value);

/// Returns the ptr value that should be used for storing `val`.
fn check_store(&self, val: Self::Value, ptr: Self::Value) -> Self::Value;

/// Returns the args that should be used for a call to `llfn`.
fn check_call<'b>(
&self,
typ: &str,
Expand All @@ -256,6 +259,14 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
fn lifetime_start(&self, ptr: Self::Value, size: Size);
fn lifetime_end(&self, ptr: Self::Value, size: Size);

/// If LLVM lifetime intrinsic support is enabled (i.e. optimizations
/// on), and `ptr` is nonzero-sized, then extracts the size of `ptr`
/// and the intrinsic for `lt` and passes them to `emit`, which is in
/// charge of generating code to call the passed intrinsic on whatever
/// block of generated code is targeted for the intrinsic.
///
/// If LLVM lifetime intrinsic support is disabled (i.e. optimizations
/// off) or `ptr` is zero-sized, then no-op (does not call `emit`).
fn call_lifetime_intrinsic(&self, intrinsic: &str, ptr: Self::Value, size: Size);

fn call(
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_codegen_llvm/interfaces/consts.rs
Expand Up @@ -17,6 +17,7 @@ use syntax::symbol::LocalInternedString;

pub trait ConstMethods<'tcx>: Backend<'tcx> {
// Constant constructors

fn const_null(&self, t: Self::Type) -> Self::Value;
fn const_undef(&self, t: Self::Type) -> Self::Value;
fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
Expand All @@ -28,7 +29,11 @@ pub trait ConstMethods<'tcx>: Backend<'tcx> {
fn const_u64(&self, i: u64) -> Self::Value;
fn const_usize(&self, i: u64) -> Self::Value;
fn const_u8(&self, i: u8) -> Self::Value;

// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
fn const_cstr(&self, s: LocalInternedString, null_terminated: bool) -> Self::Value;

fn const_str_slice(&self, s: LocalInternedString) -> Self::Value;
fn const_fat_ptr(&self, ptr: Self::Value, meta: Self::Value) -> Self::Value;
fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_codegen_llvm/interfaces/debuginfo.rs
Expand Up @@ -21,13 +21,21 @@ use syntax_pos::{SourceFile, Span};

pub trait DebugInfoMethods<'tcx>: Backend<'tcx> {
fn create_vtable_metadata(&self, ty: Ty<'tcx>, vtable: Self::Value);

/// Creates the function-specific debug context.
///
/// Returns the FunctionDebugContext for the function which holds state needed
/// for debug info creation. The function may also return another variant of the
/// FunctionDebugContext enum which indicates why no debuginfo should be created
/// for the function.
fn create_function_debug_context(
&self,
instance: Instance<'tcx>,
sig: ty::FnSig<'tcx>,
llfn: Self::Value,
mir: &mir::Mir,
) -> FunctionDebugContext<Self::DIScope>;

fn create_mir_scopes(
&self,
mir: &mir::Mir,
Expand Down

0 comments on commit 97825a3

Please sign in to comment.