librustc: Change i1 to i8 for bools. Attempts to put out burning tree. rs=burningtree

This commit is contained in:
Patrick Walton 2013-02-06 14:28:02 -08:00
parent 801f3225b2
commit b34f871dda
9 changed files with 86 additions and 34 deletions

View File

@ -1028,6 +1028,8 @@ pub fn pick_col(m: &[@Match]) -> uint {
pub enum branch_kind { no_branch, single, switch, compare, compare_vec_len, }
// Compiles a comparison between two things.
//
// NB: This must produce an i1, not a Rust bool (i8).
pub fn compare_values(cx: block,
lhs: ValueRef,
rhs: ValueRef,
@ -1053,7 +1055,11 @@ pub fn compare_values(cx: block,
scratch_rhs],
expr::SaveIn(
scratch_result.val));
return scratch_result.to_result(bcx);
let result = scratch_result.to_result(bcx);
Result {
bcx: result.bcx,
val: bool_to_i1(result.bcx, result.val)
}
}
ty::ty_estr(_) => {
let scratch_result = scratch_datum(cx, ty::mk_bool(cx.tcx()),
@ -1063,7 +1069,11 @@ pub fn compare_values(cx: block,
~[lhs, rhs],
expr::SaveIn(
scratch_result.val));
return scratch_result.to_result(bcx);
let result = scratch_result.to_result(bcx);
Result {
bcx: result.bcx,
val: bool_to_i1(result.bcx, result.val)
}
}
_ => {
cx.tcx().sess.bug(~"only scalars and strings supported in \
@ -1176,6 +1186,7 @@ pub fn compile_guard(bcx: block,
expr::trans_to_datum(bcx, guard_expr).to_result()
}
});
let val = bool_to_i1(bcx, val);
// Revoke the temp cleanups now that the guard successfully executed.
for temp_cleanups.each |llval| {

View File

@ -494,8 +494,13 @@ pub fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: ~str) {
// Used only for creating scalar comparison glue.
pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, }
pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
t: ty::t, op: ast::binop) -> Result {
// NB: This produces an i1, not a Rust bool (i8).
pub fn compare_scalar_types(cx: block,
lhs: ValueRef,
rhs: ValueRef,
t: ty::t,
op: ast::binop)
-> Result {
let f = |a| compare_scalar_values(cx, lhs, rhs, a, op);
match ty::get(t).sty {
@ -521,8 +526,12 @@ pub fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
// A helper function to do the actual comparison of scalar values.
pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
nt: scalar_type, op: ast::binop) -> ValueRef {
pub fn compare_scalar_values(cx: block,
lhs: ValueRef,
rhs: ValueRef,
nt: scalar_type,
op: ast::binop)
-> ValueRef {
let _icx = cx.insn_ctxt("compare_scalar_values");
fn die(cx: block) -> ! {
cx.tcx().sess.bug(~"compare_scalar_values: must be a\
@ -533,8 +542,8 @@ pub fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
// We don't need to do actual comparisons for nil.
// () == () holds but () < () does not.
match op {
ast::eq | ast::le | ast::ge => return C_bool(true),
ast::ne | ast::lt | ast::gt => return C_bool(false),
ast::eq | ast::le | ast::ge => return C_i1(true),
ast::ne | ast::lt | ast::gt => return C_i1(false),
// refinements would be nice
_ => die(cx)
}
@ -1442,7 +1451,7 @@ pub fn call_memcpy(cx: block, dst: ValueRef, src: ValueRef,
let dst_ptr = PointerCast(cx, dst, T_ptr(T_i8()));
let size = IntCast(cx, n_bytes, ccx.int_type);
let align = C_i32(1i32);
let volatile = C_bool(false);
let volatile = C_i1(false);
Call(cx, memcpy, ~[dst_ptr, src_ptr, size, align, volatile]);
}
@ -1489,7 +1498,7 @@ pub fn memzero(cx: block, llptr: ValueRef, llty: TypeRef) {
let llzeroval = C_u8(0);
let size = IntCast(cx, machine::llsize_of(ccx, llty), ccx.int_type);
let align = C_i32(1i32);
let volatile = C_bool(false);
let volatile = C_i1(false);
Call(cx, llintrinsicfn, ~[llptr, llzeroval, size, align, volatile]);
}

View File

@ -438,7 +438,9 @@ pub fn trans_call_inner(
let flag = alloca(bcx, T_bool());
Store(bcx, C_bool(false), flag);
Some(flag)
} else { None };
} else {
None
};
let (llfn, llenv) = unsafe {
match callee.data {
@ -506,7 +508,8 @@ pub fn trans_call_inner(
if ty::type_is_bot(ret_ty) {
Unreachable(bcx);
} else if ret_in_loop {
bcx = do with_cond(bcx, Load(bcx, ret_flag.get())) |bcx| {
let ret_flag_result = bool_to_i1(bcx, Load(bcx, ret_flag.get()));
bcx = do with_cond(bcx, ret_flag_result) |bcx| {
do option::iter(&copy bcx.fcx.loop_ret) |lret| {
Store(bcx, C_bool(true), lret.flagptr);
Store(bcx, C_bool(false), bcx.fcx.llretptr);

View File

@ -759,7 +759,7 @@ pub fn T_f32() -> TypeRef { unsafe { return llvm::LLVMFloatType(); } }
pub fn T_f64() -> TypeRef { unsafe { return llvm::LLVMDoubleType(); } }
pub fn T_bool() -> TypeRef { return T_i1(); }
pub fn T_bool() -> TypeRef { return T_i8(); }
pub fn T_int(targ_cfg: @session::config) -> TypeRef {
return match targ_cfg.arch {
@ -1109,6 +1109,10 @@ pub fn C_bool(b: bool) -> ValueRef {
C_integral(T_bool(), if b { 1u64 } else { 0u64 }, False)
}
pub fn C_i1(b: bool) -> ValueRef {
return C_integral(T_i1(), if b { 1 } else { 0 }, False);
}
pub fn C_i32(i: i32) -> ValueRef {
return C_integral(T_i32(), i as u64, True);
}
@ -1435,6 +1439,11 @@ pub fn struct_dtor() -> [uint * 2] {
[0, 1]
}
// Casts a Rust bool value to an i1.
pub fn bool_to_i1(bcx: block, llval: ValueRef) -> ValueRef {
build::ICmp(bcx, lib::llvm::IntNE, llval, C_bool(false))
}
//
// Local Variables:
// mode: rust

View File

@ -62,6 +62,8 @@ pub fn trans_if(bcx: block,
let then_bcx_in = scope_block(bcx, thn.info(), ~"then");
let else_bcx_in = scope_block(bcx, els.info(), ~"else");
let cond_val = bool_to_i1(bcx, cond_val);
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
debug!("then_bcx_in=%s, else_bcx_in=%s",
@ -139,6 +141,7 @@ pub fn trans_while(bcx: block, cond: @ast::expr, body: ast::blk) -> block {
// compile the condition
let Result {bcx: cond_bcx_out, val: cond_val} =
expr::trans_to_datum(cond_bcx_in, cond).to_result();
let cond_val = bool_to_i1(cond_bcx_out, cond_val);
let cond_bcx_out =
trans_block_cleanups(cond_bcx_out, block_cleanups(cond_bcx_in));
CondBr(cond_bcx_out, cond_val, body_bcx_in.llbb, next_bcx.llbb);
@ -324,6 +327,7 @@ pub fn trans_check_expr(bcx: block,
expr::trans_to_datum(bcx, pred_expr).to_result()
}
};
let val = bool_to_i1(bcx, val);
do with_cond(bcx, Not(bcx, val)) |bcx| {
trans_fail(bcx, Some(pred_expr.span), /*bad*/copy expr_str)
}

View File

@ -77,7 +77,7 @@ fn lli64(val: int) -> ValueRef {
C_i64(val as i64)
}
fn lli1(bval: bool) -> ValueRef {
C_bool(bval)
C_i1(bval)
}
fn llmdnode(elems: ~[ValueRef]) -> ValueRef {
unsafe {

View File

@ -1236,7 +1236,6 @@ fn trans_unary_datum(bcx: block,
un_expr: @ast::expr,
op: ast::unop,
sub_expr: @ast::expr) -> DatumBlock {
let _icx = bcx.insn_ctxt("trans_unary_datum");
// if deref, would be LvalueExpr
@ -1251,7 +1250,21 @@ fn trans_unary_datum(bcx: block,
return match op {
ast::not => {
let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result();
immediate_rvalue_bcx(bcx, Not(bcx, val), un_ty)
// If this is a boolean type, we must not use the LLVM Not
// instruction, as that is a *bitwise* not and we want *logical*
// not on our 8-bit boolean values.
let llresult = match ty::get(un_ty).sty {
ty::ty_bool => {
let llcond = ICmp(bcx,
lib::llvm::IntEQ,
val,
C_bool(false));
Select(bcx, llcond, C_bool(true), C_bool(false))
}
_ => Not(bcx, val)
};
immediate_rvalue_bcx(bcx, llresult, un_ty)
}
ast::neg => {
let Result {bcx, val} = trans_to_datum(bcx, sub_expr).to_result();
@ -1308,8 +1321,8 @@ fn trans_eager_binop(bcx: block,
binop_ty: ty::t,
op: ast::binop,
lhs_datum: &Datum,
rhs_datum: &Datum) -> DatumBlock
{
rhs_datum: &Datum)
-> DatumBlock {
let mut bcx = bcx;
let _icx = bcx.insn_ctxt("trans_eager_binop");
@ -1388,7 +1401,7 @@ fn trans_eager_binop(bcx: block,
}
let cmpr = base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op);
bcx = cmpr.bcx;
cmpr.val
ZExt(bcx, cmpr.val, T_i8())
}
}
_ => {
@ -1406,8 +1419,7 @@ fn trans_lazy_binop(bcx: block,
binop_expr: @ast::expr,
op: lazy_binop_ty,
a: @ast::expr,
b: @ast::expr) -> DatumBlock
{
b: @ast::expr) -> DatumBlock {
let _icx = bcx.insn_ctxt("trans_lazy_binop");
let binop_ty = expr_ty(bcx, binop_expr);
let mut bcx = bcx;
@ -1425,10 +1437,12 @@ fn trans_lazy_binop(bcx: block,
let join = base::sub_block(bcx, ~"join");
let before_rhs = base::sub_block(bcx, ~"rhs");
let lhs_i1 = bool_to_i1(past_lhs, lhs);
match op {
lazy_and => CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb),
lazy_or => CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb)
lazy_and => CondBr(past_lhs, lhs_i1, before_rhs.llbb, join.llbb),
lazy_or => CondBr(past_lhs, lhs_i1, join.llbb, before_rhs.llbb)
}
let Result {bcx: past_rhs, val: rhs} = {
do base::with_scope_result(before_rhs, b.info(), ~"rhs") |bcx| {
trans_to_datum(bcx, b).to_result()

View File

@ -524,7 +524,8 @@ pub fn trans_intrinsic(ccx: @crate_ctxt,
}
~"needs_drop" => {
let tp_ty = substs.tys[0];
Store(bcx, C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)),
Store(bcx,
C_bool(ty::type_needs_drop(ccx.tcx, tp_ty)),
fcx.llretptr);
}
~"visit_tydesc" => {
@ -574,7 +575,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt,
let src_ptr = get_param(decl, first_real_arg + 1);
let size = get_param(decl, first_real_arg + 2);
let align = C_i32(1);
let volatile = C_bool(false);
let volatile = C_i1(false);
let llfn = bcx.ccx().intrinsics.get(
&~"llvm.memmove.p0i8.p0i8.i32");
Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]);
@ -584,7 +585,7 @@ pub fn trans_intrinsic(ccx: @crate_ctxt,
let src_ptr = get_param(decl, first_real_arg + 1);
let size = get_param(decl, first_real_arg + 2);
let align = C_i32(1);
let volatile = C_bool(false);
let volatile = C_i1(false);
let llfn = bcx.ccx().intrinsics.get(
&~"llvm.memmove.p0i8.p0i8.i64");
Call(bcx, llfn, ~[dst_ptr, src_ptr, size, align, volatile]);
@ -769,49 +770,49 @@ pub fn trans_intrinsic(ccx: @crate_ctxt,
}
~"ctlz8" => {
let x = get_param(decl, first_real_arg);
let y = C_bool(false);
let y = C_i1(false);
let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i8");
Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr)
}
~"ctlz16" => {
let x = get_param(decl, first_real_arg);
let y = C_bool(false);
let y = C_i1(false);
let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i16");
Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr)
}
~"ctlz32" => {
let x = get_param(decl, first_real_arg);
let y = C_bool(false);
let y = C_i1(false);
let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i32");
Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr)
}
~"ctlz64" => {
let x = get_param(decl, first_real_arg);
let y = C_bool(false);
let y = C_i1(false);
let ctlz = ccx.intrinsics.get(&~"llvm.ctlz.i64");
Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr)
}
~"cttz8" => {
let x = get_param(decl, first_real_arg);
let y = C_bool(false);
let y = C_i1(false);
let cttz = ccx.intrinsics.get(&~"llvm.cttz.i8");
Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr)
}
~"cttz16" => {
let x = get_param(decl, first_real_arg);
let y = C_bool(false);
let y = C_i1(false);
let cttz = ccx.intrinsics.get(&~"llvm.cttz.i16");
Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr)
}
~"cttz32" => {
let x = get_param(decl, first_real_arg);
let y = C_bool(false);
let y = C_i1(false);
let cttz = ccx.intrinsics.get(&~"llvm.cttz.i32");
Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr)
}
~"cttz64" => {
let x = get_param(decl, first_real_arg);
let y = C_bool(false);
let y = C_i1(false);
let cttz = ccx.intrinsics.get(&~"llvm.cttz.i64");
Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr)
}

View File

@ -109,6 +109,7 @@ pub impl reflector {
ast::m_imm)),
ArgVals(args), SaveIn(scratch.val), DontAutorefArg);
let result = scratch.to_value_llval(bcx);
let result = bool_to_i1(bcx, result);
let next_bcx = sub_block(bcx, ~"next");
CondBr(bcx, result, next_bcx.llbb, self.final_bcx.llbb);
self.bcx = next_bcx