Skip to content

Commit 67030f2

Browse files
committed
---
yaml --- r: 227060 b: refs/heads/master c: 1f5739f h: refs/heads/master v: v3
1 parent 1bc3303 commit 67030f2

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 2115468f3363362e3c23b0aeb088cd8d39f6f2a6
2+
refs/heads/master: 1f5739fb3cdaff001d1af138a7b9b096a06c94e8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
44
refs/heads/try: b53c0f93eedcdedd4fd89bccc5a3a09d1c5cd23e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/librustc_trans/trans/intrinsic.rs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use arena::TypedArena;
1414
use intrinsics::{self, Intrinsic};
15+
use libc;
1516
use llvm;
1617
use llvm::{SequentiallyConsistent, Acquire, Release, AtomicXchg, ValueRef, TypeKind};
1718
use middle::subst;
@@ -24,6 +25,7 @@ use trans::callee;
2425
use trans::cleanup;
2526
use trans::cleanup::CleanupMethods;
2627
use trans::common::*;
28+
use trans::consts;
2729
use trans::datum::*;
2830
use trans::debuginfo::DebugLoc;
2931
use trans::declare;
@@ -38,6 +40,7 @@ use middle::ty::{self, Ty, HasTypeFlags};
3840
use middle::subst::Substs;
3941
use syntax::abi::{self, RustIntrinsic};
4042
use syntax::ast;
43+
use syntax::ptr::P;
4144
use syntax::parse::token;
4245

4346
pub fn get_simple_intrinsic(ccx: &CrateContext, item: &ast::ForeignItem) -> Option<ValueRef> {
@@ -343,6 +346,13 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
343346
}
344347
}
345348

349+
// save the actual AST arguments for later (some places need to do
350+
// const-evaluation on them)
351+
let expr_arguments = match args {
352+
callee::ArgExprs(args) => Some(args),
353+
_ => None,
354+
};
355+
346356
// Push the arguments.
347357
let mut llargs = Vec::new();
348358
bcx = callee::trans_args(bcx,
@@ -805,6 +815,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
805815
generic_simd_intrinsic(bcx, name,
806816
substs,
807817
callee_ty,
818+
expr_arguments,
808819
&llargs,
809820
ret_ty, llret_ty,
810821
call_debug_location,
@@ -1307,15 +1318,18 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
13071318
return rust_try
13081319
}
13091320

1310-
fn generic_simd_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
1311-
name: &str,
1312-
_substs: subst::Substs<'tcx>,
1313-
callee_ty: Ty<'tcx>,
1314-
llargs: &[ValueRef],
1315-
ret_ty: Ty<'tcx>,
1316-
llret_ty: Type,
1317-
call_debug_location: DebugLoc,
1318-
call_info: NodeIdAndSpan) -> ValueRef {
1321+
fn generic_simd_intrinsic<'blk, 'tcx, 'a>
1322+
(bcx: Block<'blk, 'tcx>,
1323+
name: &str,
1324+
substs: subst::Substs<'tcx>,
1325+
callee_ty: Ty<'tcx>,
1326+
args: Option<&[P<ast::Expr>]>,
1327+
llargs: &[ValueRef],
1328+
ret_ty: Ty<'tcx>,
1329+
llret_ty: Type,
1330+
call_debug_location: DebugLoc,
1331+
call_info: NodeIdAndSpan) -> ValueRef
1332+
{
13191333
let tcx = bcx.tcx();
13201334
let arg_tys = match callee_ty.sty {
13211335
ty::TyBareFn(_, ref f) => {
@@ -1376,7 +1390,6 @@ fn generic_simd_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
13761390
Err(_) => tcx.sess.span_bug(call_info.span,
13771391
"bad `simd_shuffle` instruction only caught in trans?")
13781392
};
1379-
assert_eq!(llargs.len(), 2 + n);
13801393

13811394
require!(arg_tys[0] == arg_tys[1],
13821395
"SIMD shuffle intrinsic monomorphised with different input types");
@@ -1394,12 +1407,18 @@ fn generic_simd_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
13941407

13951408
let total_len = in_len as u64 * 2;
13961409

1397-
let indices: Option<Vec<_>> = llargs[2..]
1398-
.iter()
1399-
.enumerate()
1400-
.map(|(i, val)| {
1401-
let arg_idx = i + 2;
1402-
let c = const_to_opt_uint(*val);
1410+
let vector = match args {
1411+
Some(args) => &args[2],
1412+
None => bcx.sess().span_bug(call_info.span,
1413+
"intrinsic call with unexpected argument shape"),
1414+
};
1415+
let vector = consts::const_expr(bcx.ccx(), vector, tcx.mk_substs(substs), None).0;
1416+
1417+
let indices: Option<Vec<_>> = (0..n)
1418+
.map(|i| {
1419+
let arg_idx = i;
1420+
let val = const_get_elt(bcx.ccx(), vector, &[i as libc::c_uint]);
1421+
let c = const_to_opt_uint(val);
14031422
match c {
14041423
None => {
14051424
bcx.sess().span_err(call_info.span,

trunk/src/librustc_typeck/check/intrinsic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use middle::ty_fold::TypeFolder;
2121
use {CrateCtxt, require_same_types};
2222

2323
use std::collections::{HashMap};
24-
use std::iter;
2524
use syntax::abi;
2625
use syntax::attr::AttrMetaMethods;
2726
use syntax::ast;
@@ -387,8 +386,8 @@ pub fn check_platform_intrinsic_type(ccx: &CrateCtxt,
387386
name if name.starts_with("simd_shuffle") => {
388387
match name["simd_shuffle".len()..].parse() {
389388
Ok(n) => {
390-
let mut params = vec![param(0), param(0)];
391-
params.extend(iter::repeat(tcx.types.u32).take(n));
389+
let params = vec![param(0), param(0),
390+
tcx.mk_ty(ty::TyArray(tcx.types.u32, n))];
392391

393392
let ictxt = infer::new_infer_ctxt(tcx, &tcx.tables, None, false);
394393
let ret = ictxt.next_ty_var();

0 commit comments

Comments
 (0)