Skip to content

Commit f4473a4

Browse files
committed
rustc_trans: promote constant rvalues in functions as an optimization.
1 parent df3cc0c commit f4473a4

File tree

19 files changed

+879
-776
lines changed

19 files changed

+879
-776
lines changed

src/librustc_llvm/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ extern {
881881

882882

883883
/* Operations on global variables */
884+
pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
884885
pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
885886
-> ValueRef;
886887
pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,

src/librustc_trans/trans/_match.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ impl<'a, 'tcx> Opt<'a, 'tcx> {
278278
match *self {
279279
ConstantValue(ConstantExpr(lit_expr), _) => {
280280
let lit_ty = ty::node_id_to_type(bcx.tcx(), lit_expr.id);
281-
let (llval, _) = consts::const_expr(ccx, &*lit_expr);
281+
let (llval, _) = consts::const_expr(ccx, &*lit_expr, bcx.fcx.param_substs);
282282
let lit_datum = immediate_rvalue(llval, lit_ty);
283283
let lit_datum = unpack_datum!(bcx, lit_datum.to_appropriate_datum(bcx));
284284
SingleResult(Result::new(bcx, lit_datum.val))
285285
}
286286
ConstantRange(ConstantExpr(ref l1), ConstantExpr(ref l2), _) => {
287-
let (l1, _) = consts::const_expr(ccx, &**l1);
288-
let (l2, _) = consts::const_expr(ccx, &**l2);
287+
let (l1, _) = consts::const_expr(ccx, &**l1, bcx.fcx.param_substs);
288+
let (l2, _) = consts::const_expr(ccx, &**l2, bcx.fcx.param_substs);
289289
RangeResult(Result::new(bcx, l1), Result::new(bcx, l2))
290290
}
291291
Variant(disr_val, ref repr, _, _) => {
@@ -832,8 +832,8 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
832832

833833
let _icx = push_ctxt("compare_values");
834834
if ty::type_is_scalar(rhs_t) {
835-
let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq, debug_loc);
836-
return Result::new(rs.bcx, rs.val);
835+
let cmp = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq, debug_loc);
836+
return Result::new(cx, cmp);
837837
}
838838

839839
match rhs_t.sty {
@@ -1163,29 +1163,16 @@ fn compile_submatch_continue<'a, 'p, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
11631163
}
11641164
RangeResult(Result { val: vbegin, .. },
11651165
Result { bcx, val: vend }) => {
1166-
let Result { bcx, val: llge } =
1167-
compare_scalar_types(bcx,
1168-
test_val,
1169-
vbegin,
1170-
t,
1171-
ast::BiGe,
1172-
debug_loc);
1173-
let Result { bcx, val: llle } =
1174-
compare_scalar_types(bcx,
1175-
test_val,
1176-
vend,
1177-
t,
1178-
ast::BiLe,
1179-
debug_loc);
1180-
Result::new(bcx, And(bcx, llge, llle, debug_loc))
1166+
let llge = compare_scalar_types(bcx, test_val, vbegin,
1167+
t, ast::BiGe, debug_loc);
1168+
let llle = compare_scalar_types(bcx, test_val, vend,
1169+
t, ast::BiLe, debug_loc);
1170+
Result::new(bcx, And(bcx, llge, llle, DebugLoc::None))
11811171
}
11821172
LowerBound(Result { bcx, val }) => {
1183-
compare_scalar_types(bcx,
1184-
test_val,
1185-
val,
1186-
t,
1187-
ast::BiGe,
1188-
debug_loc)
1173+
Result::new(bcx, compare_scalar_types(bcx, test_val,
1174+
val, t, ast::BiGe,
1175+
debug_loc))
11891176
}
11901177
}
11911178
};

0 commit comments

Comments
 (0)