Skip to content

Commit 34c5dc0

Browse files
denismerigouxeddyb
authored andcommitted
Generalized base.rs#call_memcpy and everything that it uses
Generalized operand.rs#nontemporal_store and fixed tidy issues Generalized operand.rs#nontemporal_store's implem even more With a BuilderMethod trait implemented by Builder for LLVM Cleaned builder.rs : no more code duplication, no more ValueTrait Full traitification of builder.rs
1 parent 83b2152 commit 34c5dc0

28 files changed

+792
-313
lines changed

.atom-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cmd: ./x.py -i check

src/librustc_codegen_llvm/abi.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use type_::Type;
1919
use type_of::{LayoutLlvmExt, PointerKind};
2020
use value::Value;
2121

22+
use traits::BuilderMethods;
23+
2224
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TyLayout, Abi as LayoutAbi};
2325
use rustc::ty::{self, Ty};
2426
use rustc::ty::layout;
@@ -119,7 +121,7 @@ impl LlvmType for Reg {
119121
}
120122
}
121123
RegKind::Vector => {
122-
Type::vector(Type::i8(cx), self.size.bytes())
124+
Type::vector::<Value>(Type::i8(cx), self.size.bytes())
123125
}
124126
}
125127
}
@@ -143,7 +145,7 @@ impl LlvmType for CastTarget {
143145

144146
// Simplify to array when all chunks are the same size and type
145147
if rem_bytes == 0 {
146-
return Type::array(rest_ll_unit, rest_count);
148+
return Type::array::<Value>(rest_ll_unit, rest_count);
147149
}
148150
}
149151

@@ -167,7 +169,12 @@ impl LlvmType for CastTarget {
167169

168170
pub trait ArgTypeExt<'ll, 'tcx> {
169171
fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
170-
fn store(&self, bx: &Builder<'_, 'll, 'tcx>, val: &'ll Value, dst: PlaceRef<'tcx, &'ll Value>);
172+
fn store(
173+
&self,
174+
bx: &Builder<'_, 'll, 'tcx>,
175+
val: &'ll Value,
176+
dst: PlaceRef<'tcx, &'ll Value>,
177+
);
171178
fn store_fn_arg(
172179
&self,
173180
bx: &Builder<'_, 'll, 'tcx>,
@@ -187,7 +194,12 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
187194
/// place for the original Rust type of this argument/return.
188195
/// Can be used for both storing formal arguments into Rust variables
189196
/// or results of call/invoke instructions into their destinations.
190-
fn store(&self, bx: &Builder<'_, 'll, 'tcx>, val: &'ll Value, dst: PlaceRef<'tcx, &'ll Value>) {
197+
fn store(
198+
&self,
199+
bx: &Builder<'_, 'll, 'tcx>,
200+
val: &'ll Value,
201+
dst: PlaceRef<'tcx, &'ll Value>,
202+
) {
191203
if self.is_ignore() {
192204
return;
193205
}
@@ -663,9 +675,9 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
663675
}
664676

665677
if self.variadic {
666-
Type::variadic_func(&llargument_tys, llreturn_ty)
678+
Type::variadic_func::<Value>(&llargument_tys, llreturn_ty)
667679
} else {
668-
Type::func(&llargument_tys, llreturn_ty)
680+
Type::func::<Value>(&llargument_tys, llreturn_ty)
669681
}
670682
}
671683

src/librustc_codegen_llvm/asm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use builder::Builder;
1616
use value::Value;
1717

1818
use rustc::hir;
19+
use traits::BuilderMethods;
1920

2021
use mir::place::PlaceRef;
2122
use mir::operand::OperandValue;

src/librustc_codegen_llvm/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
127127
.filter(|l| !l.is_empty())
128128
}
129129

130-
pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
130+
pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_, &'ll Value>, llfn: &'ll Value) {
131131
let cpu = llvm_util::target_cpu(cx.tcx.sess);
132132
let target_cpu = CString::new(cpu).unwrap();
133133
llvm::AddFunctionAttrStringValue(

src/librustc_codegen_llvm/back/write.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use context::{is_pie_binary, get_reloc_model};
4949
use common::{C_bytes_in_context, val_ty};
5050
use jobserver::{Client, Acquired};
5151
use rustc_demangle;
52+
use value::Value;
5253

5354
use std::any::Any;
5455
use std::ffi::{CString, CStr};
@@ -2574,7 +2575,7 @@ fn create_msvc_imps(cgcx: &CodegenContext, llcx: &llvm::Context, llmod: &llvm::M
25742575
"\x01__imp_"
25752576
};
25762577
unsafe {
2577-
let i8p_ty = Type::i8p_llcx(llcx);
2578+
let i8p_ty = Type::i8p_llcx::<Value>(llcx);
25782579
let globals = base::iter_globals(llmod)
25792580
.filter(|&val| {
25802581
llvm::LLVMRustGetLinkage(val) == llvm::Linkage::ExternalLinkage &&

src/librustc_codegen_llvm/base.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ use rustc_data_structures::small_c_str::SmallCStr;
7575
use rustc_data_structures::sync::Lrc;
7676
use rustc_data_structures::indexed_vec::Idx;
7777

78+
use traits::BuilderMethods;
79+
7880
use std::any::Any;
7981
use std::cmp;
8082
use std::ffi::CString;
@@ -86,7 +88,7 @@ use syntax_pos::symbol::InternedString;
8688
use syntax::attr;
8789
use rustc::hir::{self, CodegenFnAttrs};
8890

89-
use value::Value;
91+
use value::{Value, ValueTrait};
9092

9193
use mir::operand::OperandValue;
9294

@@ -387,9 +389,14 @@ pub fn call_assume(bx: &Builder<'_, 'll, '_>, val: &'ll Value) {
387389
bx.call(assume_intrinsic, &[val], None);
388390
}
389391

390-
pub fn from_immediate(bx: &Builder<'_, 'll, '_>, val: &'ll Value) -> &'ll Value {
391-
if val_ty(val) == Type::i1(bx.cx) {
392-
bx.zext(val, Type::i8(bx.cx))
392+
pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll,
393+
Value : ?Sized,
394+
Builder: BuilderMethods<'a, 'll, 'tcx, Value>>(
395+
bx: &Builder,
396+
val: &'ll Value
397+
) -> &'ll Value where Value : ValueTrait {
398+
if val_ty(val) == Type::i1(bx.cx()) {
399+
bx.zext(val, Type::i8(bx.cx()))
393400
} else {
394401
val
395402
}
@@ -417,45 +424,49 @@ pub fn to_immediate_scalar(
417424
val
418425
}
419426

420-
pub fn call_memcpy(
421-
bx: &Builder<'_, 'll, '_>,
427+
pub fn call_memcpy<'a, 'll: 'a, 'tcx: 'll,
428+
Value : ?Sized,
429+
Builder: BuilderMethods<'a, 'll, 'tcx, Value>>(
430+
bx: &Builder,
422431
dst: &'ll Value,
423432
dst_align: Align,
424433
src: &'ll Value,
425434
src_align: Align,
426435
n_bytes: &'ll Value,
427436
flags: MemFlags,
428-
) {
437+
) where Value : ValueTrait {
429438
if flags.contains(MemFlags::NONTEMPORAL) {
430439
// HACK(nox): This is inefficient but there is no nontemporal memcpy.
431440
let val = bx.load(src, src_align);
432441
let ptr = bx.pointercast(dst, val_ty(val).ptr_to());
433442
bx.store_with_flags(val, ptr, dst_align, flags);
434443
return;
435444
}
436-
let cx = bx.cx;
445+
let cx = bx.cx();
437446
let src_ptr = bx.pointercast(src, Type::i8p(cx));
438447
let dst_ptr = bx.pointercast(dst, Type::i8p(cx));
439448
let size = bx.intcast(n_bytes, cx.isize_ty, false);
440449
let volatile = flags.contains(MemFlags::VOLATILE);
441450
bx.memcpy(dst_ptr, dst_align.abi(), src_ptr, src_align.abi(), size, volatile);
442451
}
443452

444-
pub fn memcpy_ty(
445-
bx: &Builder<'_, 'll, 'tcx>,
453+
pub fn memcpy_ty<'a, 'll: 'a, 'tcx: 'll,
454+
Value : ?Sized,
455+
Builder: BuilderMethods<'a, 'll, 'tcx, Value>>(
456+
bx: &Builder,
446457
dst: &'ll Value,
447458
dst_align: Align,
448459
src: &'ll Value,
449460
src_align: Align,
450461
layout: TyLayout<'tcx>,
451462
flags: MemFlags,
452-
) {
463+
) where Value : ValueTrait {
453464
let size = layout.size.bytes();
454465
if size == 0 {
455466
return;
456467
}
457468

458-
call_memcpy(bx, dst, dst_align, src, src_align, C_usize(bx.cx, size), flags);
469+
call_memcpy(bx, dst, dst_align, src, src_align, C_usize(bx.cx(), size), flags);
459470
}
460471

461472
pub fn call_memset(
@@ -545,7 +556,8 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
545556
rust_main_def_id: DefId,
546557
use_start_lang_item: bool,
547558
) {
548-
let llfty = Type::func(&[Type::c_int(cx), Type::i8p(cx).ptr_to()], Type::c_int(cx));
559+
let llfty =
560+
Type::func::<Value>(&[Type::c_int(cx), Type::i8p(cx).ptr_to()], Type::c_int(cx));
549561

550562
let main_ret_ty = cx.tcx.fn_sig(rust_main_def_id).output();
551563
// Given that `main()` has no arguments,

0 commit comments

Comments
 (0)