Skip to content

Commit acb37ce

Browse files
committed
rustc_trans: promote constant rvalues in functions as an optimization.
1 parent 652601a commit acb37ce

19 files changed

+832
-703
lines changed

src/librustc_llvm/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ extern {
893893

894894

895895
/* Operations on global variables */
896+
pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
896897
pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
897898
-> ValueRef;
898899
pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,

src/librustc_trans/trans/_match.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ impl<'a, 'tcx> Opt<'a, 'tcx> {
274274
match *self {
275275
ConstantValue(ConstantExpr(lit_expr)) => {
276276
let lit_ty = ty::node_id_to_type(bcx.tcx(), lit_expr.id);
277-
let (llval, _) = consts::const_expr(ccx, &*lit_expr);
277+
let (llval, _) = consts::const_expr(ccx, &*lit_expr, bcx.fcx.param_substs);
278278
let lit_datum = immediate_rvalue(llval, lit_ty);
279279
let lit_datum = unpack_datum!(bcx, lit_datum.to_appropriate_datum(bcx));
280280
SingleResult(Result::new(bcx, lit_datum.val))
281281
}
282282
ConstantRange(ConstantExpr(ref l1), ConstantExpr(ref l2)) => {
283-
let (l1, _) = consts::const_expr(ccx, &**l1);
284-
let (l2, _) = consts::const_expr(ccx, &**l2);
283+
let (l1, _) = consts::const_expr(ccx, &**l1, bcx.fcx.param_substs);
284+
let (l2, _) = consts::const_expr(ccx, &**l2, bcx.fcx.param_substs);
285285
RangeResult(Result::new(bcx, l1), Result::new(bcx, l2))
286286
}
287287
Variant(disr_val, ref repr, _) => {
@@ -795,8 +795,8 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
795795

796796
let _icx = push_ctxt("compare_values");
797797
if ty::type_is_scalar(rhs_t) {
798-
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
799-
return Result::new(rs.bcx, rs.val);
798+
let cmp = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
799+
return Result::new(cx, cmp);
800800
}
801801

802802
match rhs_t.sty {
@@ -1122,18 +1122,15 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11221122
}
11231123
RangeResult(Result { val: vbegin, .. },
11241124
Result { bcx, val: vend }) => {
1125-
let Result { bcx, val: llge } =
1126-
compare_scalar_types(
1127-
bcx, test_val,
1128-
vbegin, t, ast::BiGe);
1129-
let Result { bcx, val: llle } =
1130-
compare_scalar_types(
1131-
bcx, test_val, vend,
1132-
t, ast::BiLe);
1125+
let llge = compare_scalar_types(bcx, test_val, vbegin,
1126+
t, ast::BiGe);
1127+
let llle = compare_scalar_types(bcx, test_val, vend,
1128+
t, ast::BiLe);
11331129
Result::new(bcx, And(bcx, llge, llle, DebugLoc::None))
11341130
}
11351131
LowerBound(Result { bcx, val }) => {
1136-
compare_scalar_types(bcx, test_val, val, t, ast::BiGe)
1132+
Result::new(bcx, compare_scalar_types(bcx, test_val, val,
1133+
t, ast::BiGe))
11371134
}
11381135
}
11391136
};

0 commit comments

Comments
 (0)