Skip to content

Commit

Permalink
rustc_trans: promote constant rvalues in functions as an optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Jan 29, 2015
1 parent 652601a commit acb37ce
Show file tree
Hide file tree
Showing 19 changed files with 832 additions and 703 deletions.
1 change: 1 addition & 0 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ extern {


/* Operations on global variables */
pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
-> ValueRef;
pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
Expand Down
25 changes: 11 additions & 14 deletions src/librustc_trans/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,14 @@ impl<'a, 'tcx> Opt<'a, 'tcx> {
match *self {
ConstantValue(ConstantExpr(lit_expr)) => {
let lit_ty = ty::node_id_to_type(bcx.tcx(), lit_expr.id);
let (llval, _) = consts::const_expr(ccx, &*lit_expr);
let (llval, _) = consts::const_expr(ccx, &*lit_expr, bcx.fcx.param_substs);
let lit_datum = immediate_rvalue(llval, lit_ty);
let lit_datum = unpack_datum!(bcx, lit_datum.to_appropriate_datum(bcx));
SingleResult(Result::new(bcx, lit_datum.val))
}
ConstantRange(ConstantExpr(ref l1), ConstantExpr(ref l2)) => {
let (l1, _) = consts::const_expr(ccx, &**l1);
let (l2, _) = consts::const_expr(ccx, &**l2);
let (l1, _) = consts::const_expr(ccx, &**l1, bcx.fcx.param_substs);
let (l2, _) = consts::const_expr(ccx, &**l2, bcx.fcx.param_substs);
RangeResult(Result::new(bcx, l1), Result::new(bcx, l2))
}
Variant(disr_val, ref repr, _) => {
Expand Down Expand Up @@ -795,8 +795,8 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,

let _icx = push_ctxt("compare_values");
if ty::type_is_scalar(rhs_t) {
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
return Result::new(rs.bcx, rs.val);
let cmp = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
return Result::new(cx, cmp);
}

match rhs_t.sty {
Expand Down Expand Up @@ -1122,18 +1122,15 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
}
RangeResult(Result { val: vbegin, .. },
Result { bcx, val: vend }) => {
let Result { bcx, val: llge } =
compare_scalar_types(
bcx, test_val,
vbegin, t, ast::BiGe);
let Result { bcx, val: llle } =
compare_scalar_types(
bcx, test_val, vend,
t, ast::BiLe);
let llge = compare_scalar_types(bcx, test_val, vbegin,
t, ast::BiGe);
let llle = compare_scalar_types(bcx, test_val, vend,
t, ast::BiLe);
Result::new(bcx, And(bcx, llge, llle, DebugLoc::None))
}
LowerBound(Result { bcx, val }) => {
compare_scalar_types(bcx, test_val, val, t, ast::BiGe)
Result::new(bcx, compare_scalar_types(bcx, test_val, val,
t, ast::BiGe))
}
}
};
Expand Down
Loading

0 comments on commit acb37ce

Please sign in to comment.