1 #![allow(non_camel_case_types, non_snake_case)]
3 use rustc::ty::{Ty, TyCtxt};
6 use rustc::hir::def_id::DefId;
7 use rustc::middle::lang_items::LangItem;
12 use crate::traits::BuilderMethods;
14 pub enum IntPredicate {
29 pub enum RealPredicate {
48 pub enum AtomicRmwBinOp {
62 pub enum AtomicOrdering {
67 // Consume, // Not specified yet.
71 SequentiallyConsistent,
74 pub enum SynchronizationScope {
75 // FIXME: figure out if this variant is needed at all.
82 #[derive(Copy, Clone, PartialEq, Debug)]
103 // FIXME(mw): Anything that is produced via DepGraph::with_task() must implement
104 // the HashStable trait. Normally DepGraph::with_task() calls are
105 // hidden behind queries, but CGU creation is a special case in two
106 // ways: (1) it's not a query and (2) CGU are output nodes, so their
107 // Fingerprints are not actually needed. It remains to be clarified
108 // how exactly this case will be handled in the red/green system but
109 // for now we content ourselves with providing a no-op HashStable
110 // implementation for CGUs.
111 mod temp_stable_hash_impls {
112 use rustc_data_structures::stable_hasher::{StableHasherResult, StableHasher,
114 use crate::ModuleCodegen;
116 impl<HCX, M> HashStable<HCX> for ModuleCodegen<M> {
117 fn hash_stable<W: StableHasherResult>(&self,
119 _: &mut StableHasher<W>) {
125 pub fn langcall(tcx: TyCtxt<'_, '_>,
130 tcx.lang_items().require(li).unwrap_or_else(|s| {
131 let msg = format!("{} {}", msg, s);
133 Some(span) => tcx.sess.span_fatal(span, &msg[..]),
134 None => tcx.sess.fatal(&msg[..]),
139 // To avoid UB from LLVM, these two functions mask RHS with an
140 // appropriate mask unconditionally (i.e., the fallback behavior for
141 // all shifts). For 32- and 64-bit types, this matches the semantics
142 // of Java. (See related discussion on #1877 and #10183.)
144 pub fn build_unchecked_lshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
149 let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs);
150 // #1877, #10183: Ensure that input is always valid
151 let rhs = shift_mask_rhs(bx, rhs);
155 pub fn build_unchecked_rshift<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
161 let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs);
162 // #1877, #10183: Ensure that input is always valid
163 let rhs = shift_mask_rhs(bx, rhs);
164 let is_signed = lhs_t.is_signed();
172 fn shift_mask_rhs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
176 let rhs_llty = bx.val_ty(rhs);
177 let shift_val = shift_mask_val(bx, rhs_llty, rhs_llty, false);
178 bx.and(rhs, shift_val)
181 pub fn shift_mask_val<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
187 let kind = bx.type_kind(llty);
189 TypeKind::Integer => {
190 // i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.
191 let val = bx.int_width(llty) - 1;
193 bx.const_int(mask_llty, !val as i64)
195 bx.const_uint(mask_llty, val)
198 TypeKind::Vector => {
199 let mask = shift_mask_val(
201 bx.element_type(llty),
202 bx.element_type(mask_llty),
205 bx.vector_splat(bx.vector_length(mask_llty), mask)
207 _ => bug!("shift_mask_val: expected Integer or Vector, found {:?}", kind),