Skip to content

Commit 0a1c509

Browse files
denismerigouxeddyb
authored andcommitted
Traitified IntrinsicCallMethods
1 parent a5aeb8e commit 0a1c509

File tree

11 files changed

+648
-624
lines changed

11 files changed

+648
-624
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
7373
use rustc_data_structures::sync::Lrc;
7474
use rustc_data_structures::indexed_vec::Idx;
7575

76-
use interfaces::{
77-
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
78-
};
76+
use interfaces::*;
7977

8078
use std::any::Any;
8179
use std::cmp;

src/librustc_codegen_llvm/builder.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ use rustc::ty::TyCtxt;
1919
use rustc::ty::layout::{Align, Size};
2020
use rustc::session::{config, Session};
2121
use rustc_data_structures::small_c_str::SmallCStr;
22-
use interfaces::{
23-
Backend,
24-
BuilderMethods, ConstMethods, BaseTypeMethods, DerivedTypeMethods, DerivedIntrinsicMethods,
25-
};
22+
use interfaces::*;
2623
use syntax;
2724

2825
use std::borrow::Cow;
@@ -59,16 +56,11 @@ bitflags! {
5956
}
6057
}
6158

62-
impl Backend for Builder<'a, 'll, 'tcx> {
63-
type Value = &'ll Value;
64-
type BasicBlock = &'ll BasicBlock;
65-
type Type = &'ll Type;
66-
type Context = &'ll llvm::Context;
59+
impl HasCodegen for Builder<'a, 'll, 'tcx> {
60+
type CodegenCx = CodegenCx<'ll, 'tcx>;
6761
}
6862

6963
impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
70-
type CodegenCx = CodegenCx<'ll, 'tcx>;
71-
7264
fn new_block<'b>(
7365
cx: &'a CodegenCx<'ll, 'tcx>,
7466
llfn: &'ll Value,

src/librustc_codegen_llvm/context.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use value::Value;
2323
use monomorphize::partitioning::CodegenUnit;
2424
use type_::Type;
2525
use type_of::PointeeInfo;
26-
use interfaces::{BaseTypeMethods, DerivedTypeMethods,
27-
IntrinsicMethods, BaseIntrinsicMethods, DerivedIntrinsicMethods};
26+
use interfaces::{BaseTypeMethods, DerivedTypeMethods, IntrinsicDeclarationMethods};
2827

2928
use rustc_data_structures::base_n;
3029
use rustc_data_structures::small_c_str::SmallCStr;
@@ -323,9 +322,7 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
323322
}
324323
}
325324

326-
impl BaseIntrinsicMethods for CodegenCx<'_, '_> {}
327-
328-
impl DerivedIntrinsicMethods for CodegenCx<'b, 'tcx> {
325+
impl IntrinsicDeclarationMethods for CodegenCx<'b, 'tcx> {
329326
fn get_intrinsic(&self, key: &str) -> &'b Value {
330327
if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
331328
return v;
@@ -647,8 +644,6 @@ impl DerivedIntrinsicMethods for CodegenCx<'b, 'tcx> {
647644
}
648645
}
649646

650-
impl IntrinsicMethods for CodegenCx<'a, 'tcx> {}
651-
652647
impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
653648
/// Generate a new symbol name with the given prefix. This symbol name must
654649
/// only be used for definitions with `internal` or `private` linkage.

src/librustc_codegen_llvm/interfaces/builder.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,29 @@ use builder::MemFlags;
1717
use super::backend::Backend;
1818
use super::type_::TypeMethods;
1919
use super::consts::ConstMethods;
20-
use super::intrinsic::IntrinsicMethods;
20+
use super::intrinsic::IntrinsicDeclarationMethods;
2121

2222
use std::borrow::Cow;
2323
use std::ops::Range;
2424
use syntax::ast::AsmDialect;
2525

26-
27-
pub trait BuilderMethods<'a, 'tcx: 'a>: Backend {
28-
type CodegenCx: 'a + TypeMethods + ConstMethods + IntrinsicMethods + Backend<
26+
pub trait HasCodegen: Backend {
27+
type CodegenCx: TypeMethods + ConstMethods + IntrinsicDeclarationMethods + Backend<
2928
Value = Self::Value,
3029
BasicBlock = Self::BasicBlock,
3130
Type = Self::Type,
3231
Context = Self::Context,
3332
>;
33+
}
34+
35+
impl<T: HasCodegen> Backend for T {
36+
type Value = <T::CodegenCx as Backend>::Value;
37+
type BasicBlock = <T::CodegenCx as Backend>::BasicBlock;
38+
type Type = <T::CodegenCx as Backend>::Type;
39+
type Context = <T::CodegenCx as Backend>::Context;
40+
}
3441

42+
pub trait BuilderMethods<'a, 'tcx: 'a>: HasCodegen {
3543
fn new_block<'b>(
3644
cx: &'a Self::CodegenCx,
3745
llfn: Self::Value,

src/librustc_codegen_llvm/interfaces/intrinsic.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,27 @@
99
// except according to those terms.
1010

1111
use super::backend::Backend;
12+
use super::builder::HasCodegen;
13+
use mir::operand::OperandRef;
14+
use rustc::ty::Ty;
15+
use abi::FnType;
16+
use syntax_pos::Span;
1217

13-
pub trait BaseIntrinsicMethods: Backend {
14-
18+
pub trait IntrinsicCallMethods<'a, 'tcx: 'a>: HasCodegen {
19+
fn codegen_intrinsic_call(
20+
&self,
21+
callee_ty: Ty<'tcx>,
22+
fn_ty: &FnType<'tcx, Ty<'tcx>>,
23+
args: &[OperandRef<'tcx, Self::Value>],
24+
llresult: Self::Value,
25+
span: Span,
26+
);
1527
}
1628

17-
pub trait DerivedIntrinsicMethods: Backend {
29+
pub trait IntrinsicDeclarationMethods: Backend {
1830
fn get_intrinsic(&self, key: &str) -> Self::Value;
1931
fn declare_intrinsic(
2032
&self,
2133
key: &str
2234
) -> Option<Self::Value>;
2335
}
24-
25-
pub trait IntrinsicMethods: BaseIntrinsicMethods + DerivedIntrinsicMethods {}

src/librustc_codegen_llvm/interfaces/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ mod type_;
1515
mod intrinsic;
1616
mod statics;
1717

18-
pub use self::builder::BuilderMethods;
18+
pub use self::builder::{BuilderMethods, HasCodegen};
1919
pub use self::backend::Backend;
2020
pub use self::consts::ConstMethods;
2121
pub use self::type_::{TypeMethods, BaseTypeMethods, DerivedTypeMethods};
22-
pub use self::intrinsic::{IntrinsicMethods, BaseIntrinsicMethods, DerivedIntrinsicMethods};
22+
pub use self::intrinsic::{IntrinsicCallMethods, IntrinsicDeclarationMethods};
2323
pub use self::statics::StaticMethods;

0 commit comments

Comments
 (0)