//! Code that is useful in various codegen modules.
-use llvm::{self, True, False, Bool, BasicBlock};
+use llvm::{self, True, False, Bool, BasicBlock, OperandBundleDef};
use rustc::hir::def_id::DefId;
use rustc::middle::lang_items::LangItem;
use abi;
use value::Value;
use interfaces::*;
-use rustc::ty::{self, Ty, TyCtxt};
+use rustc::ty::{Ty, TyCtxt};
use rustc::ty::layout::{HasDataLayout, LayoutOf, self, TyLayout, Size};
use rustc::mir::interpret::{Scalar, AllocType, Allocation};
use rustc::hir;
use mir::constant::const_alloc_to_llvm;
use mir::place::PlaceRef;
+use rustc_codegen_ssa::common::TypeKind;
use libc::{c_uint, c_char};
use syntax::symbol::LocalInternedString;
use syntax::ast::Mutability;
-use syntax_pos::{Span, DUMMY_SP};
+use syntax_pos::Span;
pub use context::CodegenCx;
-pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
- ty.needs_drop(tcx, ty::ParamEnv::reveal_all())
-}
-
-pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
- ty.is_sized(tcx.at(DUMMY_SP), ty::ParamEnv::reveal_all())
-}
-
-pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
- ty.is_freeze(tcx, ty::ParamEnv::reveal_all(), DUMMY_SP)
-}
-
-pub struct OperandBundleDef<'a, V> {
- pub name: &'a str,
- pub val: V
-}
-
-impl<'a, V> OperandBundleDef<'a, V> {
- pub fn new(name: &'a str, val: V) -> Self {
- OperandBundleDef {
- name,
- val
- }
- }
-}
-
-pub enum IntPredicate {
- IntEQ,
- IntNE,
- IntUGT,
- IntUGE,
- IntULT,
- IntULE,
- IntSGT,
- IntSGE,
- IntSLT,
- IntSLE
-}
-
-#[allow(dead_code)]
-pub enum RealPredicate {
- RealPredicateFalse,
- RealOEQ,
- RealOGT,
- RealOGE,
- RealOLT,
- RealOLE,
- RealONE,
- RealORD,
- RealUNO,
- RealUEQ,
- RealUGT,
- RealUGE,
- RealULT,
- RealULE,
- RealUNE,
- RealPredicateTrue
-}
-
-pub enum AtomicRmwBinOp {
- AtomicXchg,
- AtomicAdd,
- AtomicSub,
- AtomicAnd,
- AtomicNand,
- AtomicOr,
- AtomicXor,
- AtomicMax,
- AtomicMin,
- AtomicUMax,
- AtomicUMin
-}
-
-pub enum AtomicOrdering {
- #[allow(dead_code)]
- NotAtomic,
- Unordered,
- Monotonic,
- // Consume, // Not specified yet.
- Acquire,
- Release,
- AcquireRelease,
- SequentiallyConsistent,
-}
-
-pub enum SynchronizationScope {
- // FIXME: figure out if this variant is needed at all.
- #[allow(dead_code)]
- Other,
- SingleThread,
- CrossThread,
-}
-
-#[derive(Copy, Clone, PartialEq, Debug)]
-pub enum TypeKind {
- Void,
- Half,
- Float,
- Double,
- X86_FP80,
- FP128,
- PPc_FP128,
- Label,
- Integer,
- Function,
- Struct,
- Array,
- Pointer,
- Vector,
- Metadata,
- X86_MMX,
- Token,
-}
-
/*
* A note on nomenclature of linking: "extern", "foreign", and "upcall".
*
/// When inside of a landing pad, each function call in LLVM IR needs to be
/// annotated with which landing pad it's a part of. This is accomplished via
/// the `OperandBundleDef` value created for MSVC landing pads.
-pub struct Funclet<'a, V> {
- cleanuppad: V,
- operand: OperandBundleDef<'a, V>,
+pub struct Funclet<'ll> {
+ cleanuppad: &'ll Value,
+ operand: OperandBundleDef<'ll>,
}
-impl<'a, V: CodegenObject> Funclet<'a, V> {
- pub fn new(cleanuppad: V) -> Self {
+impl Funclet<'ll> {
+ pub fn new(cleanuppad: &'ll Value) -> Self {
Funclet {
cleanuppad,
- operand: OperandBundleDef::new("funclet", cleanuppad),
+ operand: OperandBundleDef::new("funclet", &[cleanuppad]),
}
}
- pub fn cleanuppad(&self) -> V {
+ pub fn cleanuppad(&self) -> &'ll Value {
self.cleanuppad
}
- pub fn bundle(&self) -> &OperandBundleDef<'a, V> {
+ pub fn bundle(&self) -> &OperandBundleDef<'ll> {
&self.operand
}
}
type BasicBlock = &'ll BasicBlock;
type Type = &'ll Type;
type Context = &'ll llvm::Context;
+ type Funclet = Funclet<'ll>;
type DIScope = &'ll llvm::debuginfo::DIScope;
}
impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
- // LLVM constant constructors.
fn const_null(&self, t: &'ll Type) -> &'ll Value {
unsafe {
llvm::LLVMConstNull(t)
self.const_uint(self.type_i8(), i as u64)
}
-
- // This is a 'c-like' raw string, which differs from
- // our boxed-and-length-annotated strings.
fn const_cstr(
&self,
s: LocalInternedString,
}
}
- // NB: Do not use `do_spill_noroot` to make this into a constant string, or
- // you will be kicked off fast isel. See issue #4352 for an example of this.
fn const_str_slice(&self, s: LocalInternedString) -> &'ll Value {
let len = s.len();
let cs = consts::ptrcast(self.const_cstr(s, false),