Skip to content

Commit 496edbe

Browse files
committed
Generalized some base.rs methods
1 parent 5e731d6 commit 496edbe

File tree

9 files changed

+490
-135
lines changed

9 files changed

+490
-135
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use super::CachedModuleCodegen;
3030

3131
use abi;
3232
use back::write::{self, OngoingCodegen};
33-
use llvm::{self, TypeKind, get_param};
33+
use llvm::{self, get_param};
3434
use metadata;
3535
use rustc::dep_graph::cgu_reuse_tracker::CguReuse;
3636
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
@@ -55,7 +55,7 @@ use builder::{Builder, MemFlags};
5555
use callee;
5656
use rustc_mir::monomorphize::collector::{self, MonoItemCollectionMode};
5757
use rustc_mir::monomorphize::item::DefPathBasedNames;
58-
use common::{self, IntPredicate, RealPredicate};
58+
use common::{self, IntPredicate, RealPredicate, TypeKind};
5959
use consts;
6060
use context::CodegenCx;
6161
use debuginfo;
@@ -67,7 +67,6 @@ use monomorphize::partitioning::{CodegenUnit, CodegenUnitExt};
6767
use rustc_codegen_utils::symbol_names_test;
6868
use time_graph;
6969
use mono_item::{MonoItem, MonoItemExt};
70-
use type_::Type;
7170
use type_of::LayoutLlvmExt;
7271
use rustc::util::nodemap::FxHashMap;
7372
use CrateInfo;
@@ -334,21 +333,31 @@ pub fn coerce_unsized_into(
334333
}
335334
}
336335

337-
pub fn cast_shift_expr_rhs(
338-
bx: &Builder<'_, 'll, '_, &'ll Value>, op: hir::BinOpKind, lhs: &'ll Value, rhs: &'ll Value
339-
) -> &'ll Value {
336+
pub fn cast_shift_expr_rhs<'a, 'll: 'a, 'tcx: 'll, Builder : BuilderMethods<'a, 'll, 'tcx>>(
337+
bx: &Builder,
338+
op: hir::BinOpKind,
339+
lhs: <Builder::CodegenCx as Backend>::Value,
340+
rhs: <Builder::CodegenCx as Backend>::Value
341+
) -> <Builder::CodegenCx as Backend>::Value {
340342
cast_shift_rhs(bx, op, lhs, rhs, |a, b| bx.trunc(a, b), |a, b| bx.zext(a, b))
341343
}
342344

343-
fn cast_shift_rhs<'ll, F, G>(bx: &Builder<'_, 'll, '_, &'ll Value>,
344-
op: hir::BinOpKind,
345-
lhs: &'ll Value,
346-
rhs: &'ll Value,
347-
trunc: F,
348-
zext: G)
349-
-> &'ll Value
350-
where F: FnOnce(&'ll Value, &'ll Type) -> &'ll Value,
351-
G: FnOnce(&'ll Value, &'ll Type) -> &'ll Value
345+
fn cast_shift_rhs<'a, 'll :'a, 'tcx : 'll, F, G, Builder : BuilderMethods<'a, 'll, 'tcx>>(
346+
bx: &Builder,
347+
op: hir::BinOpKind,
348+
lhs: <Builder::CodegenCx as Backend>::Value,
349+
rhs: <Builder::CodegenCx as Backend>::Value,
350+
trunc: F,
351+
zext: G
352+
) -> <Builder::CodegenCx as Backend>::Value
353+
where F: FnOnce(
354+
<Builder::CodegenCx as Backend>::Value,
355+
<Builder::CodegenCx as Backend>::Type
356+
) -> <Builder::CodegenCx as Backend>::Value,
357+
G: FnOnce(
358+
<Builder::CodegenCx as Backend>::Value,
359+
<Builder::CodegenCx as Backend>::Type
360+
) -> <Builder::CodegenCx as Backend>::Value
352361
{
353362
// Shifts may have any size int on the rhs
354363
if op.is_shift() {
@@ -390,33 +399,33 @@ pub fn call_assume(bx: &Builder<'_, 'll, '_, &'ll Value>, val: &'ll Value) {
390399
bx.call(assume_intrinsic, &[val], None);
391400
}
392401

393-
pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll>(
394-
bx: &Builder<'_ ,'ll, '_, &'ll Value>,
395-
val: &'ll Value
396-
) -> &'ll Value {
402+
pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll, Builder : BuilderMethods<'a, 'll ,'tcx>>(
403+
bx: &Builder,
404+
val: <Builder::CodegenCx as Backend>::Value
405+
) -> <Builder::CodegenCx as Backend>::Value {
397406
if bx.cx().val_ty(val) == bx.cx().type_i1() {
398407
bx.zext(val, bx.cx().type_i8())
399408
} else {
400409
val
401410
}
402411
}
403412

404-
pub fn to_immediate(
405-
bx: &Builder<'_, 'll, '_, &'ll Value>,
406-
val: &'ll Value,
413+
pub fn to_immediate<'a, 'll, 'tcx, Builder : BuilderMethods<'a, 'll, 'tcx>>(
414+
bx: &Builder,
415+
val: <Builder::CodegenCx as Backend>::Value,
407416
layout: layout::TyLayout,
408-
) -> &'ll Value {
417+
) -> <Builder::CodegenCx as Backend>::Value {
409418
if let layout::Abi::Scalar(ref scalar) = layout.abi {
410419
return to_immediate_scalar(bx, val, scalar);
411420
}
412421
val
413422
}
414423

415-
pub fn to_immediate_scalar(
416-
bx: &Builder<'_, 'll, '_, &'ll Value>,
417-
val: &'ll Value,
424+
pub fn to_immediate_scalar<'a, 'll, 'tcx, Builder : BuilderMethods<'a, 'll, 'tcx>>(
425+
bx: &Builder,
426+
val: <Builder::CodegenCx as Backend>::Value,
418427
scalar: &layout::Scalar,
419-
) -> &'ll Value {
428+
) -> <Builder::CodegenCx as Backend>::Value {
420429
if scalar.is_bool() {
421430
return bx.trunc(val, bx.cx().type_i1());
422431
}

src/librustc_codegen_llvm/builder.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +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::{BuilderMethods, Backend, ConstMethods, TypeMethods};
22+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
2323
use syntax;
2424

2525
use std::borrow::Cow;
@@ -56,14 +56,6 @@ bitflags! {
5656
}
5757
}
5858

59-
impl Backend for Builder<'a, 'll, 'tcx, &'ll Value> {
60-
type Value = &'ll Value;
61-
type BasicBlock = &'ll BasicBlock;
62-
type Type = &'ll Type;
63-
type TypeKind = llvm::TypeKind;
64-
type Context = &'ll llvm::Context;
65-
}
66-
6759
impl BuilderMethods<'a, 'll, 'tcx>
6860
for Builder<'a, 'll, 'tcx, &'ll Value> {
6961

@@ -1177,7 +1169,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
11771169
let stored_ty = self.cx.val_ty(val);
11781170
let stored_ptr_ty = self.cx.type_ptr_to(stored_ty);
11791171

1180-
assert_eq!(self.cx.type_kind(dest_ptr_ty), llvm::TypeKind::Pointer);
1172+
assert_eq!(self.cx.type_kind(dest_ptr_ty), TypeKind::Pointer);
11811173

11821174
if dest_ptr_ty == stored_ptr_ty {
11831175
ptr
@@ -1196,11 +1188,11 @@ impl BuilderMethods<'a, 'll, 'tcx>
11961188
args: &'b [&'ll Value]) -> Cow<'b, [&'ll Value]> {
11971189
let mut fn_ty = self.cx.val_ty(llfn);
11981190
// Strip off pointers
1199-
while self.cx.type_kind(fn_ty) == llvm::TypeKind::Pointer {
1191+
while self.cx.type_kind(fn_ty) == TypeKind::Pointer {
12001192
fn_ty = self.cx.element_type(fn_ty);
12011193
}
12021194

1203-
assert!(self.cx.type_kind(fn_ty) == llvm::TypeKind::Function,
1195+
assert!(self.cx.type_kind(fn_ty) == TypeKind::Function,
12041196
"builder::{} not passed a function, but {:?}", typ, fn_ty);
12051197

12061198
let param_tys = self.cx.func_params_types(fn_ty);

src/librustc_codegen_llvm/common.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
//! Code that is useful in various codegen modules.
1414
15-
use llvm::{self, TypeKind};
16-
use llvm::{True, False, Bool, BasicBlock};
15+
use llvm::{self, True, False, Bool, BasicBlock};
1716
use rustc::hir::def_id::DefId;
1817
use rustc::middle::lang_items::LangItem;
1918
use abi;
@@ -131,6 +130,27 @@ pub enum SynchronizationScope {
131130
CrossThread,
132131
}
133132

133+
#[derive(Copy, Clone, PartialEq, Debug)]
134+
pub enum TypeKind {
135+
Void,
136+
Half,
137+
Float,
138+
Double,
139+
X86_FP80,
140+
FP128,
141+
PPc_FP128,
142+
Label,
143+
Integer,
144+
Function,
145+
Struct,
146+
Array,
147+
Pointer,
148+
Vector,
149+
Metadata,
150+
X86_MMX,
151+
Token,
152+
}
153+
134154
/*
135155
* A note on nomenclature of linking: "extern", "foreign", and "upcall".
136156
*
@@ -197,7 +217,6 @@ impl Backend for CodegenCx<'ll, 'tcx, &'ll Value> {
197217
type Value = &'ll Value;
198218
type BasicBlock = &'ll BasicBlock;
199219
type Type = &'ll Type;
200-
type TypeKind = llvm::TypeKind;
201220
type Context = &'ll llvm::Context;
202221
}
203222

src/librustc_codegen_llvm/interfaces/backend.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
use std::fmt::Debug;
1212

1313
pub trait Backend {
14-
type Value : Debug + PartialEq;
14+
type Value : Debug + PartialEq + Copy;
1515
type BasicBlock;
16-
type Type : Debug + PartialEq;
17-
type TypeKind;
16+
type Type : Debug + PartialEq + Copy;
1817
type Context;
1918
}

0 commit comments

Comments
 (0)