1 #![allow(non_camel_case_types, non_snake_case)]
3 use rustc::ty::{self, Ty, TyCtxt};
4 use syntax_pos::{DUMMY_SP, Span};
6 use rustc::hir::def_id::DefId;
7 use rustc::middle::lang_items::LangItem;
12 use traits::BuilderMethods;
14 pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
15 ty.needs_drop(tcx, ty::ParamEnv::reveal_all())
18 pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
19 ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all())
22 pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
23 ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
26 pub enum IntPredicate {
41 pub enum RealPredicate {
60 pub enum AtomicRmwBinOp {
74 pub enum AtomicOrdering {
79 // Consume, // Not specified yet.
83 SequentiallyConsistent,
86 pub enum SynchronizationScope {
87 // FIXME: figure out if this variant is needed at all.
94 #[derive(Copy, Clone, PartialEq, Debug)]
115 // FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
116 // the HashStable trait. Normally DepGraph::with_task() calls are
117 // hidden behind queries, but CGU creation is a special case in two
118 // ways: (1) it's not a query and (2) CGU are output nodes, so their
119 // Fingerprints are not actually needed. It remains to be clarified
120 // how exactly this case will be handled in the red/green system but
121 // for now we content ourselves with providing a no-op HashStable
122 // implementation for CGUs.
123 mod temp_stable_hash_impls {
124 use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
128 impl<HCX, M> HashStable<HCX> for ModuleCodegen<M> {
129 fn hash_stable<W: StableHasherResult>(&self,
131 _: &mut StableHasher<W>) {
137 pub fn langcall(tcx: TyCtxt,
142 tcx.lang_items().require(li).unwrap_or_else(|s| {
143 let msg = format!("{} {}", msg, s);
145 Some(span) => tcx.sess.span_fatal(span, &msg[..]),
146 None => tcx.sess.fatal(&msg[..]),
151 // To avoid UB from LLVM, these two functions mask RHS with an
152 // appropriate mask unconditionally (i.e., the fallback behavior for
153 // all shifts). For 32- and 64-bit types, this matches the semantics
154 // of Java. (See related discussion on #1877 and #10183.)
156 pub fn build_unchecked_lshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
161 let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs);
162 // #1877, #10183: Ensure that input is always valid
163 let rhs = shift_mask_rhs(bx, rhs);
167 pub fn build_unchecked_rshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
173 let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs);
174 // #1877, #10183: Ensure that input is always valid
175 let rhs = shift_mask_rhs(bx, rhs);
176 let is_signed = lhs_t.is_signed();
184 fn shift_mask_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
188 let rhs_llty = bx.val_ty(rhs);
189 let shift_val = shift_mask_val(bx, rhs_llty, rhs_llty, false);
190 bx.and(rhs, shift_val)
193 pub fn shift_mask_val<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
199 let kind = bx.type_kind(llty);
201 TypeKind::Integer => {
202 // i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.
203 let val = bx.int_width(llty) - 1;
205 bx.const_int(mask_llty, !val as i64)
207 bx.const_uint(mask_llty, val)
210 TypeKind::Vector => {
211 let mask = shift_mask_val(
213 bx.element_type(llty),
214 bx.element_type(mask_llty),
217 bx.vector_splat(bx.vector_length(mask_llty), mask)
219 _ => bug!("shift_mask_val: expected Integer or Vector, found {:?}", kind),