Attempt at including CodegenCx within Builder with Associated types
This commit is contained in:
parent
1929ac2007
commit
c487b825b0
4 changed files with 52 additions and 41 deletions
|
@ -157,7 +157,7 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn compare_simd_types<'a, 'll:'a, 'tcx:'ll, Builder: BuilderMethods<'a, 'll, 'tcx>>(
|
||||
pub fn compare_simd_types<'a, 'tcx: 'a, Builder: BuilderMethods<'a, 'tcx>>(
|
||||
bx: &Builder,
|
||||
lhs: Builder::Value,
|
||||
rhs: Builder::Value,
|
||||
|
|
|
@ -12,7 +12,7 @@ use llvm::{AtomicRmwBinOp, AtomicOrdering, SynchronizationScope, AsmDialect};
|
|||
use llvm::{self, False, OperandBundleDef, BasicBlock};
|
||||
use common::{self, *};
|
||||
use context::CodegenCx;
|
||||
use type_;
|
||||
use type_::Type;
|
||||
use value::Value;
|
||||
use libc::{c_uint, c_char};
|
||||
use rustc::ty::TyCtxt;
|
||||
|
@ -59,12 +59,14 @@ bitflags! {
|
|||
impl Backend for Builder<'a, 'll, 'tcx> {
|
||||
type Value = &'ll Value;
|
||||
type BasicBlock = &'ll BasicBlock;
|
||||
type Type = &'ll type_::Type;
|
||||
type Type = &'ll Type;
|
||||
type TypeKind = llvm::TypeKind;
|
||||
type Context = &'ll llvm::Context;
|
||||
}
|
||||
|
||||
impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, '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,
|
||||
|
@ -199,7 +201,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
args: &[&'ll Value],
|
||||
then: &'ll BasicBlock,
|
||||
catch: &'ll BasicBlock,
|
||||
bundle: Option<&common::OperandBundleDef<'ll, &'ll Value>>) -> &'ll Value {
|
||||
bundle: Option<&common::OperandBundleDef<&'ll Value>>) -> &'ll Value {
|
||||
self.count_insn("invoke");
|
||||
|
||||
debug!("Invoke {:?} with args ({:?})",
|
||||
|
@ -437,7 +439,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn alloca(&self, ty: Self::Type, name: &str, align: Align) -> &'ll Value {
|
||||
fn alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value {
|
||||
let bx = Builder::with_cx(self.cx);
|
||||
bx.position_at_start(unsafe {
|
||||
llvm::LLVMGetFirstBasicBlock(self.llfn())
|
||||
|
@ -445,7 +447,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
bx.dynamic_alloca(ty, name, align)
|
||||
}
|
||||
|
||||
fn dynamic_alloca(&self, ty: Self::Type, name: &str, align: Align) -> &'ll Value {
|
||||
fn dynamic_alloca(&self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value {
|
||||
self.count_insn("alloca");
|
||||
unsafe {
|
||||
let alloca = if name.is_empty() {
|
||||
|
@ -461,7 +463,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
|
||||
fn array_alloca(&self,
|
||||
ty: Self::Type,
|
||||
ty: &'ll Type,
|
||||
len: &'ll Value,
|
||||
name: &str,
|
||||
align: Align) -> &'ll Value {
|
||||
|
@ -620,77 +622,77 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
|
||||
/* Casts */
|
||||
fn trunc(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn trunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("trunc");
|
||||
unsafe {
|
||||
llvm::LLVMBuildTrunc(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn sext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn sext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("sext");
|
||||
unsafe {
|
||||
llvm::LLVMBuildSExt(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn fptoui(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn fptoui(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("fptoui");
|
||||
unsafe {
|
||||
llvm::LLVMBuildFPToUI(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn fptosi(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn fptosi(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("fptosi");
|
||||
unsafe {
|
||||
llvm::LLVMBuildFPToSI(self.llbuilder, val, dest_ty,noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn uitofp(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn uitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("uitofp");
|
||||
unsafe {
|
||||
llvm::LLVMBuildUIToFP(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn sitofp(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn sitofp(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("sitofp");
|
||||
unsafe {
|
||||
llvm::LLVMBuildSIToFP(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn fptrunc(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn fptrunc(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("fptrunc");
|
||||
unsafe {
|
||||
llvm::LLVMBuildFPTrunc(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn fpext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn fpext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("fpext");
|
||||
unsafe {
|
||||
llvm::LLVMBuildFPExt(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn ptrtoint(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn ptrtoint(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("ptrtoint");
|
||||
unsafe {
|
||||
llvm::LLVMBuildPtrToInt(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn inttoptr(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn inttoptr(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("inttoptr");
|
||||
unsafe {
|
||||
llvm::LLVMBuildIntToPtr(self.llbuilder, val, dest_ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn bitcast(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn bitcast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("bitcast");
|
||||
unsafe {
|
||||
llvm::LLVMBuildBitCast(self.llbuilder, val, dest_ty, noname())
|
||||
|
@ -698,14 +700,14 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
|
||||
|
||||
fn intcast(&self, val: &'ll Value, dest_ty: Self::Type, is_signed: bool) -> &'ll Value {
|
||||
fn intcast(&self, val: &'ll Value, dest_ty: &'ll Type, is_signed: bool) -> &'ll Value {
|
||||
self.count_insn("intcast");
|
||||
unsafe {
|
||||
llvm::LLVMRustBuildIntCast(self.llbuilder, val, dest_ty, is_signed)
|
||||
}
|
||||
}
|
||||
|
||||
fn pointercast(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn pointercast(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("pointercast");
|
||||
unsafe {
|
||||
llvm::LLVMBuildPointerCast(self.llbuilder, val, dest_ty, noname())
|
||||
|
@ -729,14 +731,14 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
|
||||
/* Miscellaneous instructions */
|
||||
fn empty_phi(&self, ty: Self::Type) -> &'ll Value {
|
||||
fn empty_phi(&self, ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("emptyphi");
|
||||
unsafe {
|
||||
llvm::LLVMBuildPhi(self.llbuilder, ty, noname())
|
||||
}
|
||||
}
|
||||
|
||||
fn phi(&self, ty: Self::Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
|
||||
fn phi(&self, ty: &'ll Type, vals: &[&'ll Value], bbs: &[&'ll BasicBlock]) -> &'ll Value {
|
||||
assert_eq!(vals.len(), bbs.len());
|
||||
let phi = self.empty_phi(ty);
|
||||
self.count_insn("addincoming");
|
||||
|
@ -749,7 +751,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
|
||||
fn inline_asm_call(&self, asm: *const c_char, cons: *const c_char,
|
||||
inputs: &[&'ll Value], output: Self::Type,
|
||||
inputs: &[&'ll Value], output: &'ll Type,
|
||||
volatile: bool, alignstack: bool,
|
||||
dia: syntax::ast::AsmDialect) -> Option<&'ll Value> {
|
||||
self.count_insn("inlineasm");
|
||||
|
@ -826,7 +828,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn va_arg(&self, list: &'ll Value, ty: Self::Type) -> &'ll Value {
|
||||
fn va_arg(&self, list: &'ll Value, ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("vaarg");
|
||||
unsafe {
|
||||
llvm::LLVMBuildVAArg(self.llbuilder, list, ty, noname())
|
||||
|
@ -961,7 +963,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn landing_pad(&self, ty: Self::Type, pers_fn: &'ll Value,
|
||||
fn landing_pad(&self, ty: &'ll Type, pers_fn: &'ll Value,
|
||||
num_clauses: usize) -> &'ll Value {
|
||||
self.count_insn("landingpad");
|
||||
unsafe {
|
||||
|
@ -1232,7 +1234,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
|
||||
fn call(&self, llfn: &'ll Value, args: &[&'ll Value],
|
||||
bundle: Option<&common::OperandBundleDef<'ll, &'ll Value>>) -> &'ll Value {
|
||||
bundle: Option<&common::OperandBundleDef<&'ll Value>>) -> &'ll Value {
|
||||
self.count_insn("call");
|
||||
|
||||
debug!("Call {:?} with args ({:?})",
|
||||
|
@ -1254,7 +1256,7 @@ impl BuilderMethods<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn zext(&self, val: &'ll Value, dest_ty: Self::Type) -> &'ll Value {
|
||||
fn zext(&self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
|
||||
self.count_insn("zext");
|
||||
unsafe {
|
||||
llvm::LLVMBuildZExt(self.llbuilder, val, dest_ty, noname())
|
||||
|
|
|
@ -50,13 +50,13 @@ pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bo
|
|||
ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
|
||||
}
|
||||
|
||||
pub struct OperandBundleDef<'a, Value: 'a> {
|
||||
pub struct OperandBundleDef<'a, Value> {
|
||||
pub name: &'a str,
|
||||
pub val: Value
|
||||
}
|
||||
|
||||
impl OperandBundleDef<'ll, &'ll Value> {
|
||||
pub fn new(name: &'ll str, val: &'ll Value) -> Self {
|
||||
impl<'a, Value> OperandBundleDef<'a, Value> {
|
||||
pub fn new(name: &'a str, val: Value) -> Self {
|
||||
OperandBundleDef {
|
||||
name,
|
||||
val
|
||||
|
|
|
@ -15,6 +15,8 @@ use rustc::ty::layout::{Align, Size};
|
|||
use rustc::session::Session;
|
||||
use builder::MemFlags;
|
||||
use super::backend::Backend;
|
||||
use super::type_::TypeMethods;
|
||||
use super::consts::ConstMethods;
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Range;
|
||||
|
@ -22,17 +24,24 @@ use syntax::ast::AsmDialect;
|
|||
|
||||
|
||||
|
||||
pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll>: Backend {
|
||||
pub trait BuilderMethods<'a, 'tcx: 'a>: Backend {
|
||||
type CodegenCx: TypeMethods + ConstMethods + Backend<
|
||||
Value = Self::Value,
|
||||
BasicBlock = Self::BasicBlock,
|
||||
Type = Self::Type,
|
||||
TypeKind = Self::TypeKind,
|
||||
Context = Self::Context,
|
||||
>;
|
||||
|
||||
fn new_block<'b>(
|
||||
cx: &'a CodegenCx<'ll, 'tcx, Self::Value>,
|
||||
cx: &'a Self::CodegenCx,
|
||||
llfn: Self::Value,
|
||||
name: &'b str
|
||||
) -> Self;
|
||||
fn with_cx(cx: &'a CodegenCx<'ll, 'tcx, Self::Value>) -> Self;
|
||||
fn with_cx(cx: &'a Self::CodegenCx) -> Self;
|
||||
fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
|
||||
fn sess(&self) -> &Session;
|
||||
fn cx(&self) -> &'a CodegenCx<'ll, 'tcx, Self::Value>;
|
||||
fn cx(&self) -> &'a Self::CodegenCx;
|
||||
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;
|
||||
fn llfn(&self) -> Self::Value;
|
||||
fn llbb(&self) -> Self::BasicBlock;
|
||||
|
@ -62,7 +71,7 @@ pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll>: Backend {
|
|||
args: &[Self::Value],
|
||||
then: Self::BasicBlock,
|
||||
catch: Self::BasicBlock,
|
||||
bundle: Option<&OperandBundleDef<'ll, Self::Value>>
|
||||
bundle: Option<&OperandBundleDef<Self::Value>>
|
||||
) -> Self::Value;
|
||||
fn unreachable(&self);
|
||||
fn add(&self, lhs: Self::Value, rhs: Self::Value) -> Self::Value;
|
||||
|
@ -278,6 +287,6 @@ pub trait BuilderMethods<'a, 'll :'a, 'tcx: 'll>: Backend {
|
|||
fn call_lifetime_intrinsic(&self, intrinsic: &str, ptr: Self::Value, size: Size);
|
||||
|
||||
fn call(&self, llfn: Self::Value, args: &[Self::Value],
|
||||
bundle: Option<&OperandBundleDef<'ll, Self::Value>>) -> Self::Value;
|
||||
bundle: Option<&OperandBundleDef<Self::Value>>) -> Self::Value;
|
||||
fn zext(&self, val: Self::Value, dest_ty: Self::Type) -> Self::Value;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue