Traitified IntrinsicCallMethods

This commit is contained in:
Denis Merigoux 2018-09-11 11:46:03 +02:00 committed by Eduard-Mihai Burtescu
parent a5aeb8edd6
commit 0a1c50955b
11 changed files with 670 additions and 646 deletions

View File

@ -73,9 +73,7 @@
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::indexed_vec::Idx;
use interfaces::{
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
};
use interfaces::*;
use std::any::Any;
use std::cmp;

View File

@ -19,10 +19,7 @@
use rustc::ty::layout::{Align, Size};
use rustc::session::{config, Session};
use rustc_data_structures::small_c_str::SmallCStr;
use interfaces::{
Backend,
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
};
use interfaces::*;
use syntax;
use std::borrow::Cow;
@ -59,16 +56,11 @@ pub struct MemFlags: u8 {
}
}
impl Backend for Builder<'a, 'll, 'tcx> {
type Value = &'ll Value;
type BasicBlock = &'ll BasicBlock;
type Type = &'ll Type;
type Context = &'ll llvm::Context;
impl HasCodegen for Builder<'a, 'll, 'tcx> {
type CodegenCx = CodegenCx<'ll, 'tcx>;
}
impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
type CodegenCx = CodegenCx<'ll, 'tcx>;
fn new_block<'b>(
cx: &'a CodegenCx<'ll, 'tcx>,
llfn: &'ll Value,

View File

@ -23,8 +23,7 @@
use monomorphize::partitioning::CodegenUnit;
use type_::Type;
use type_of::PointeeInfo;
use interfaces::{BaseTypeMethods, DerivedTypeMethods,
IntrinsicMethods, BaseIntrinsicMethods, DerivedIntrinsicMethods};
use interfaces::{BaseTypeMethods, DerivedTypeMethods, IntrinsicDeclarationMethods};
use rustc_data_structures::base_n;
use rustc_data_structures::small_c_str::SmallCStr;
@ -323,9 +322,7 @@ pub fn sess<'a>(&'a self) -> &'a Session {
}
}
impl BaseIntrinsicMethods for CodegenCx<'_, '_> {}
impl DerivedIntrinsicMethods for CodegenCx<'b, 'tcx> {
impl IntrinsicDeclarationMethods for CodegenCx<'b, 'tcx> {
fn get_intrinsic(&self, key: &str) -> &'b Value {
if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
return v;
@ -647,8 +644,6 @@ macro_rules! mk_struct {
}
}
impl IntrinsicMethods for CodegenCx<'a, 'tcx> {}
impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
/// Generate a new symbol name with the given prefix. This symbol name must
/// only be used for definitions with `internal` or `private` linkage.

View File

@ -17,21 +17,29 @@
use super::backend::Backend;
use super::type_::TypeMethods;
use super::consts::ConstMethods;
use super::intrinsic::IntrinsicMethods;
use super::intrinsic::IntrinsicDeclarationMethods;
use std::borrow::Cow;
use std::ops::Range;
use syntax::ast::AsmDialect;
pub trait BuilderMethods<'a, 'tcx: 'a>: Backend {
type CodegenCx: 'a + TypeMethods + ConstMethods + IntrinsicMethods + Backend<
pub trait HasCodegen: Backend {
type CodegenCx: TypeMethods + ConstMethods + IntrinsicDeclarationMethods + Backend<
Value = Self::Value,
BasicBlock = Self::BasicBlock,
Type = Self::Type,
Context = Self::Context,
>;
}
impl<T: HasCodegen> Backend for T {
type Value = <T::CodegenCx as Backend>::Value;
type BasicBlock = <T::CodegenCx as Backend>::BasicBlock;
type Type = <T::CodegenCx as Backend>::Type;
type Context = <T::CodegenCx as Backend>::Context;
}
pub trait BuilderMethods<'a, 'tcx: 'a>: HasCodegen {
fn new_block<'b>(
cx: &'a Self::CodegenCx,
llfn: Self::Value,

View File

@ -9,17 +9,27 @@
// except according to those terms.
use super::backend::Backend;
use super::builder::HasCodegen;
use mir::operand::OperandRef;
use rustc::ty::Ty;
use abi::FnType;
use syntax_pos::Span;
pub trait BaseIntrinsicMethods: Backend {
pub trait IntrinsicCallMethods<'a, 'tcx: 'a>: HasCodegen {
fn codegen_intrinsic_call(
&self,
callee_ty: Ty<'tcx>,
fn_ty: &FnType<'tcx, Ty<'tcx>>,
args: &[OperandRef<'tcx, Self::Value>],
llresult: Self::Value,
span: Span,
);
}
pub trait DerivedIntrinsicMethods: Backend {
pub trait IntrinsicDeclarationMethods: Backend {
fn get_intrinsic(&self, key: &str) -> Self::Value;
fn declare_intrinsic(
&self,
key: &str
) -> Option<Self::Value>;
}
pub trait IntrinsicMethods: BaseIntrinsicMethods + DerivedIntrinsicMethods {}

View File

@ -15,9 +15,9 @@
mod intrinsic;
mod statics;
pub use self::builder::BuilderMethods;
pub use self::builder::{BuilderMethods, HasCodegen};
pub use self::backend::Backend;
pub use self::consts::ConstMethods;
pub use self::type_::{TypeMethods, BaseTypeMethods, DerivedTypeMethods};
pub use self::intrinsic::{IntrinsicMethods, BaseIntrinsicMethods, DerivedIntrinsicMethods};
pub use self::intrinsic::{IntrinsicCallMethods, IntrinsicDeclarationMethods};
pub use self::statics::StaticMethods;

File diff suppressed because it is too large Load Diff

View File

@ -25,10 +25,7 @@
use type_::Type;
use value::Value;
use interfaces::{
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
StaticMethods,
};
use interfaces::*;
use syntax::symbol::Symbol;
use syntax_pos::Pos;
@ -560,8 +557,6 @@ fn codegen_terminator(&mut self,
};
if intrinsic.is_some() && intrinsic != Some("drop_in_place") {
use intrinsic::codegen_intrinsic_call;
let dest = match ret_dest {
_ if fn_ty.ret.is_indirect() => llargs[0],
ReturnDest::Nothing => {
@ -628,8 +623,8 @@ fn codegen_terminator(&mut self,
let callee_ty = instance.as_ref().unwrap().ty(bx.cx().tcx);
codegen_intrinsic_call(&bx, callee_ty, &fn_ty, &args, dest,
terminator.source_info.span);
&bx.codegen_intrinsic_call(callee_ty, &fn_ty, &args, dest,
terminator.source_info.span);
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
self.store_return(&bx, ret_dest, &fn_ty.ret, dst.llval);

View File

@ -20,7 +20,7 @@
use type_of::LayoutLlvmExt;
use glue;
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, DerivedIntrinsicMethods};
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, IntrinsicDeclarationMethods};
use std::fmt;

View File

@ -21,10 +21,7 @@
use glue;
use mir::constant::const_alloc_to_llvm;
use interfaces::{
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
StaticMethods,
};
use interfaces::*;
use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue};

View File

@ -25,7 +25,7 @@
use type_of::LayoutLlvmExt;
use value::Value;
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, DerivedIntrinsicMethods};
use interfaces::{BuilderMethods, ConstMethods, BaseTypeMethods, IntrinsicDeclarationMethods};
use super::{FunctionCx, LocalRef};
use super::operand::{OperandRef, OperandValue};