Skip to content

Commit 5e731d6

Browse files
committed
Attempt at including CodegenCx within Builder with Associated types
1 parent 555b144 commit 5e731d6

File tree

3 files changed

+200
-194
lines changed

3 files changed

+200
-194
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use CrateInfo;
7474
use rustc_data_structures::small_c_str::SmallCStr;
7575
use rustc_data_structures::sync::Lrc;
7676

77-
use interfaces::{BuilderMethods, ConstMethods, TypeMethods};
77+
use interfaces::{BuilderMethods, ConstMethods, TypeMethods, Backend};
7878

7979
use std::any::Any;
8080
use std::cmp;
@@ -160,12 +160,12 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
160160

161161
pub fn compare_simd_types<'a, 'll:'a, 'tcx:'ll, Builder : BuilderMethods<'a, 'll, 'tcx>>(
162162
bx: &Builder,
163-
lhs: Builder::Value,
164-
rhs: Builder::Value,
163+
lhs: <Builder::CodegenCx as Backend>::Value,
164+
rhs: <Builder::CodegenCx as Backend>::Value,
165165
t: Ty<'tcx>,
166-
ret_ty: Builder::Type,
166+
ret_ty: <Builder::CodegenCx as Backend>::Type,
167167
op: hir::BinOpKind
168-
) -> Builder::Value {
168+
) -> <Builder::CodegenCx as Backend>::Value {
169169
let signed = match t.sty {
170170
ty::Float(_) => {
171171
let cmp = bin_op_to_fcmp_predicate(op);

src/librustc_codegen_llvm/builder.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope, AsmDialect};
1212
use llvm::{self, False, OperandBundleDef, BasicBlock};
1313
use common::{self, *};
1414
use context::CodegenCx;
15-
use type_;
15+
use type_::Type;
1616
use value::Value;
1717
use libc::{c_uint, c_char};
1818
use rustc::ty::TyCtxt;
@@ -59,14 +59,16 @@ bitflags! {
5959
impl Backend for Builder<'a, 'll, 'tcx, &'ll Value> {
6060
type Value = &'ll Value;
6161
type BasicBlock = &'ll BasicBlock;
62-
type Type = &'ll type_::Type;
62+
type Type = &'ll Type;
6363
type TypeKind = llvm::TypeKind;
6464
type Context = &'ll llvm::Context;
6565
}
6666

6767
impl BuilderMethods<'a, 'll, 'tcx>
6868
for Builder<'a, 'll, 'tcx, &'ll Value> {
6969

70+
type CodegenCx = CodegenCx<'ll, 'tcx, &'ll Value>;
71+
7072
fn new_block<'b>(
7173
cx: &'a CodegenCx<'ll, 'tcx, &'ll Value>,
7274
llfn: &'ll Value,
@@ -455,15 +457,15 @@ impl BuilderMethods<'a, 'll, 'tcx>
455457
}
456458
}
457459

458-
fn alloca(&self, ty: Self::Type, name: &str, align: Align) -> &'ll Value {
460+
fn alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value {
459461
let bx = Builder::with_cx(self.cx);
460462
bx.position_at_start(unsafe {
461463
llvm::LLVMGetFirstBasicBlock(self.llfn())
462464
});
463465
bx.dynamic_alloca(ty, name, align)
464466
}
465467

466-
fn dynamic_alloca(&self, ty: Self::Type, name: &str, align: Align) -> &'ll Value {
468+
fn dynamic_alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value {
467469
self.count_insn("alloca");
468470
unsafe {
469471
let alloca = if name.is_empty() {
@@ -479,7 +481,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
479481
}
480482

481483
fn array_alloca(&self,
482-
ty: Self::Type,
484+
ty: &'ll Type,
483485
len: &'ll Value,
484486
name: &str,
485487
align: Align) -> &'ll Value {
@@ -638,92 +640,92 @@ impl BuilderMethods<'a, 'll, 'tcx>
638640
}
639641

640642
/* Casts */
641-
fn trunc(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
643+
fn trunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
642644
self.count_insn("trunc");
643645
unsafe {
644646
llvm::LLVMBuildTrunc(self.llbuilder, val, dest_ty, noname())
645647
}
646648
}
647649

648-
fn sext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
650+
fn sext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
649651
self.count_insn("sext");
650652
unsafe {
651653
llvm::LLVMBuildSExt(self.llbuilder, val, dest_ty, noname())
652654
}
653655
}
654656

655-
fn fptoui(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
657+
fn fptoui(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
656658
self.count_insn("fptoui");
657659
unsafe {
658660
llvm::LLVMBuildFPToUI(self.llbuilder, val, dest_ty, noname())
659661
}
660662
}
661663

662-
fn fptosi(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
664+
fn fptosi(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
663665
self.count_insn("fptosi");
664666
unsafe {
665667
llvm::LLVMBuildFPToSI(self.llbuilder, val, dest_ty,noname())
666668
}
667669
}
668670

669-
fn uitofp(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
671+
fn uitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
670672
self.count_insn("uitofp");
671673
unsafe {
672674
llvm::LLVMBuildUIToFP(self.llbuilder, val, dest_ty, noname())
673675
}
674676
}
675677

676-
fn sitofp(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
678+
fn sitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
677679
self.count_insn("sitofp");
678680
unsafe {
679681
llvm::LLVMBuildSIToFP(self.llbuilder, val, dest_ty, noname())
680682
}
681683
}
682684

683-
fn fptrunc(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
685+
fn fptrunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
684686
self.count_insn("fptrunc");
685687
unsafe {
686688
llvm::LLVMBuildFPTrunc(self.llbuilder, val, dest_ty, noname())
687689
}
688690
}
689691

690-
fn fpext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
692+
fn fpext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
691693
self.count_insn("fpext");
692694
unsafe {
693695
llvm::LLVMBuildFPExt(self.llbuilder, val, dest_ty, noname())
694696
}
695697
}
696698

697-
fn ptrtoint(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
699+
fn ptrtoint(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
698700
self.count_insn("ptrtoint");
699701
unsafe {
700702
llvm::LLVMBuildPtrToInt(self.llbuilder, val, dest_ty, noname())
701703
}
702704
}
703705

704-
fn inttoptr(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
706+
fn inttoptr(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
705707
self.count_insn("inttoptr");
706708
unsafe {
707709
llvm::LLVMBuildIntToPtr(self.llbuilder, val, dest_ty, noname())
708710
}
709711
}
710712

711-
fn bitcast(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
713+
fn bitcast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
712714
self.count_insn("bitcast");
713715
unsafe {
714716
llvm::LLVMBuildBitCast(self.llbuilder, val, dest_ty, noname())
715717
}
716718
}
717719

718720

719-
fn intcast(&self, val: &'ll Value, dest_ty: Self::Type, is_signed: bool) -> &'ll Value {
721+
fn intcast(&self, val: &'ll Value, dest_ty: &'ll Type, is_signed: bool) -> &'ll Value {
720722
self.count_insn("intcast");
721723
unsafe {
722724
llvm::LLVMRustBuildIntCast(self.llbuilder, val, dest_ty, is_signed)
723725
}
724726
}
725727

726-
fn pointercast(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
728+
fn pointercast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
727729
self.count_insn("pointercast");
728730
unsafe {
729731
llvm::LLVMBuildPointerCast(self.llbuilder, val, dest_ty, noname())
@@ -747,14 +749,14 @@ impl BuilderMethods<'a, 'll, 'tcx>
747749
}
748750

749751
/* Miscellaneous instructions */
750-
fn empty_phi(&self, ty: Self::Type) -> &'ll Value {
752+
fn empty_phi(&self, ty: &'ll Type) -> &'ll Value {
751753
self.count_insn("emptyphi");
752754
unsafe {
753755
llvm::LLVMBuildPhi(self.llbuilder, ty, noname())
754756
}
755757
}
756758

757-
fn phi(&self, ty: Self::Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
759+
fn phi(&self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
758760
assert_eq!(vals.len(), bbs.len());
759761
let phi = self.empty_phi(ty);
760762
self.count_insn("addincoming");
@@ -767,7 +769,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
767769
}
768770

769771
fn inline_asm_call(&self, asm: *const c_char, cons: *const c_char,
770-
inputs: &[&'ll Value], output: Self::Type,
772+
inputs: &[&'ll Value], output: &'ll Type,
771773
volatile: bool, alignstack: bool,
772774
dia: syntax::ast::AsmDialect) -> Option<&'ll Value> {
773775
self.count_insn("inlineasm");
@@ -826,7 +828,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
826828
}
827829

828830
#[allow(dead_code)]
829-
fn va_arg(&self, list: &'ll Value, ty: Self::Type) -> &'ll Value {
831+
fn va_arg(&self, list: &'ll Value, ty: &'ll Type) -> &'ll Value {
830832
self.count_insn("vaarg");
831833
unsafe {
832834
llvm::LLVMBuildVAArg(self.llbuilder, list, ty, noname())
@@ -992,7 +994,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
992994
}
993995
}
994996

995-
fn landing_pad(&self, ty: Self::Type, pers_fn: &'ll Value,
997+
fn landing_pad(&self, ty: &'ll Type, pers_fn: &'ll Value,
996998
num_clauses: usize) -> &'ll Value {
997999
self.count_insn("landingpad");
9981000
unsafe {
@@ -1296,7 +1298,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
12961298
}
12971299
}
12981300

1299-
fn zext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
1301+
fn zext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
13001302
self.count_insn("zext");
13011303
unsafe {
13021304
llvm::LLVMBuildZExt(self.llbuilder, val, dest_ty, noname())

0 commit comments

Comments
 (0)