&self,
bx: &Builder<'_, 'll, 'tcx>,
idx: &mut usize,
- dst: PlaceRef<'tcx, &'ll Value>,
+ dst: PlaceRef<'tcx, &'ll Value>,
);
}
// All Builders must have an llfn associated with them
#[must_use]
-pub struct Builder<'a, 'll: 'a, 'tcx: 'll> {
+pub struct Builder<'a, 'll: 'a, 'tcx: 'll, V: 'll = &'ll Value> {
pub llbuilder: &'ll mut llvm::Builder<'ll>,
- pub cx: &'a CodegenCx<'ll, 'tcx>,
+ pub cx: &'a CodegenCx<'ll, 'tcx, V>,
}
-impl Drop for Builder<'a, 'll, 'tcx> {
+impl<V> Drop for Builder<'_, '_, '_, V> {
fn drop(&mut self) {
unsafe {
llvm::LLVMDisposeBuilder(&mut *(self.llbuilder as *mut _));
/// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
/// `llvm::Context` so that several compilation units may be optimized in parallel.
/// All other LLVM data structures in the `CodegenCx` are tied to that `llvm::Context`.
-pub struct CodegenCx<'a, 'tcx: 'a> {
+pub struct CodegenCx<'a, 'tcx: 'a, V = &'a Value> {
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub check_overflow: bool,
pub use_dll_storage_attrs: bool,
pub codegen_unit: Arc<CodegenUnit<'tcx>>,
/// Cache instances of monomorphic and polymorphic items
- pub instances: RefCell<FxHashMap<Instance<'tcx>, &'a Value>>,
+ pub instances: RefCell<FxHashMap<Instance<'tcx>, V>>,
/// Cache generated vtables
- pub vtables: RefCell<FxHashMap<(Ty<'tcx>, ty::PolyExistentialTraitRef<'tcx>),
- &'a Value>>,
+ pub vtables: RefCell<FxHashMap<(Ty<'tcx>, ty::PolyExistentialTraitRef<'tcx>), V>>,
/// Cache of constant strings,
- pub const_cstr_cache: RefCell<FxHashMap<LocalInternedString, &'a Value>>,
+ pub const_cstr_cache: RefCell<FxHashMap<LocalInternedString, V>>,
/// Reverse-direction for const ptrs cast from globals.
/// Key is a Value holding a *T,
/// when we ptrcast, and we have to ptrcast during codegen
/// of a [T] const because we form a slice, a (*T,usize) pair, not
/// a pointer to an LLVM array type. Similar for trait objects.
- pub const_unsized: RefCell<FxHashMap<&'a Value, &'a Value>>,
+ pub const_unsized: RefCell<FxHashMap<V, V>>,
/// Cache of emitted const globals (value -> global)
- pub const_globals: RefCell<FxHashMap<&'a Value, &'a Value>>,
+ pub const_globals: RefCell<FxHashMap<V, V>>,
/// List of globals for static variables which need to be passed to the
/// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete.
/// (We have to make sure we don't invalidate any Values referring
/// to constants.)
- pub statics_to_rauw: RefCell<Vec<(&'a Value, &'a Value)>>,
+ pub statics_to_rauw: RefCell<Vec<(V, V)>>,
/// Statics that will be placed in the llvm.used variable
/// See http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable for details
- pub used_statics: RefCell<Vec<&'a Value>>,
+ pub used_statics: RefCell<Vec<V>>,
pub lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<VariantIdx>), &'a Type>>,
pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, &'a Type>>,
pub dbg_cx: Option<debuginfo::CrateDebugContext<'a, 'tcx>>,
- eh_personality: Cell<Option<&'a Value>>,
- eh_unwind_resume: Cell<Option<&'a Value>>,
- pub rust_try_fn: Cell<Option<&'a Value>>,
+ eh_personality: Cell<Option<V>>,
+ eh_unwind_resume: Cell<Option<V>>,
+ pub rust_try_fn: Cell<Option<V>>,
- intrinsics: RefCell<FxHashMap<&'static str, &'a Value>>,
+ intrinsics: RefCell<FxHashMap<&'static str, V>>,
/// A counter that is used for generating local symbol names
local_gen_sym_counter: Cell<usize>,
use rustc::ty::layout::LayoutOf;
use type_of::LayoutLlvmExt;
use super::FunctionCx;
+use value::Value;
-pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx>) -> BitSet<mir::Local> {
+pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx, &'ll Value>) -> BitSet<mir::Local> {
let mir = fx.mir;
let mut analyzer = LocalAnalyzer::new(fx);
analyzer.non_ssa_locals
}
-struct LocalAnalyzer<'mir, 'a: 'mir, 'll: 'a, 'tcx: 'll> {
- fx: &'mir FunctionCx<'a, 'll, 'tcx>,
+struct LocalAnalyzer<'mir, 'a: 'mir, 'll: 'a, 'tcx: 'll, V: 'll> {
+ fx: &'mir FunctionCx<'a, 'll, 'tcx, V>,
dominators: Dominators<mir::BasicBlock>,
non_ssa_locals: BitSet<mir::Local>,
// The location of the first visited direct assignment to each
first_assignment: IndexVec<mir::Local, Location>
}
-impl LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
- fn new(fx: &'mir FunctionCx<'a, 'll, 'tcx>) -> Self {
+impl LocalAnalyzer<'mir, 'a, 'll, 'tcx, &'ll Value> {
+ fn new(fx: &'mir FunctionCx<'a, 'll, 'tcx, &'ll Value>) -> Self {
let invalid_location =
mir::BasicBlock::new(fx.mir.basic_blocks().len()).start_location();
let mut analyzer = LocalAnalyzer {
}
}
-impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
+impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx, &'ll Value> {
fn visit_assign(&mut self,
block: mir::BasicBlock,
place: &mir::Place<'tcx>,
use super::operand::OperandRef;
use super::operand::OperandValue::{Pair, Ref, Immediate};
-impl FunctionCx<'a, 'll, 'tcx> {
+impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
pub fn codegen_block(&mut self, bb: mir::BasicBlock) {
let mut bx = self.build_block(bb);
let data = &self.mir[bb];
Ok((const_alloc_to_llvm(cx, alloc), alloc))
}
-impl FunctionCx<'a, 'll, 'tcx> {
+impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
fn fully_evaluate(
&mut self,
bx: &Builder<'a, 'll, 'tcx>,
use self::operand::{OperandRef, OperandValue};
/// Master context for codegenning from MIR.
-pub struct FunctionCx<'a, 'll: 'a, 'tcx: 'll> {
+pub struct FunctionCx<'a, 'll: 'a, 'tcx: 'll, V> {
instance: Instance<'tcx>,
mir: &'a mir::Mir<'tcx>,
debug_context: FunctionDebugContext<'ll>,
- llfn: &'ll Value,
+ llfn: V,
cx: &'a CodegenCx<'ll, 'tcx>,
/// don't really care about it very much. Anyway, this value
/// contains an alloca into which the personality is stored and
/// then later loaded when generating the DIVERGE_BLOCK.
- personality_slot: Option<PlaceRef<'tcx, &'ll Value>>,
+ personality_slot: Option<PlaceRef<'tcx, V>>,
/// A `Block` for each MIR `BasicBlock`
blocks: IndexVec<mir::BasicBlock, &'ll BasicBlock>,
cleanup_kinds: IndexVec<mir::BasicBlock, analyze::CleanupKind>,
/// When targeting MSVC, this stores the cleanup info for each funclet
- /// BB. This is initialized as we compute the funclets' head block in RPO.
+ /// BB. Thisrustup component add rustfmt-preview is initialized as we compute the funclets'
+ /// head block in RPO.
funclets: &'a IndexVec<mir::BasicBlock, Option<Funclet<'ll>>>,
/// This stores the landing-pad block for a given BB, computed lazily on GNU
///
/// Avoiding allocs can also be important for certain intrinsics,
/// notably `expect`.
- locals: IndexVec<mir::Local, LocalRef<'tcx, &'ll Value>>,
+ locals: IndexVec<mir::Local, LocalRef<'tcx, V>>,
/// Debug information for MIR scopes.
scopes: IndexVec<mir::SourceScope, debuginfo::MirDebugScope<'ll>>,
param_substs: &'tcx Substs<'tcx>,
}
-impl FunctionCx<'a, 'll, 'tcx> {
+impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
pub fn monomorphize<T>(&self, value: &T) -> T
where T: TypeFoldable<'tcx>
{
/// indirect.
fn arg_local_refs(
bx: &Builder<'a, 'll, 'tcx>,
- fx: &FunctionCx<'a, 'll, 'tcx>,
+ fx: &FunctionCx<'a, 'll, 'tcx, &'ll Value>,
scopes: &IndexVec<mir::SourceScope, debuginfo::MirDebugScope<'ll>>,
memory_locals: &BitSet<mir::Local>,
) -> Vec<LocalRef<'tcx, &'ll Value>> {
use base;
use common::{CodegenCx, C_undef, C_usize};
use builder::{Builder, MemFlags};
-use value::Value;
+use value::{Value, ValueTrait};
use type_of::LayoutLlvmExt;
use type_::Type;
use glue;
pub layout: TyLayout<'tcx>,
}
-impl fmt::Debug for OperandRef<'tcx, &'ll Value> {
+impl<Value: ?Sized> fmt::Debug for OperandRef<'tcx, &'ll Value> where Value: ValueTrait {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "OperandRef({:?} @ {:?})", self.val, self.layout)
}
}
}
-impl FunctionCx<'a, 'll, 'tcx> {
+impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
fn maybe_codegen_consume_direct(&mut self,
bx: &Builder<'a, 'll, 'tcx>,
place: &mir::Place<'tcx>)
}
}
-impl FunctionCx<'a, 'll, 'tcx> {
+impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
pub fn codegen_place(&mut self,
bx: &Builder<'a, 'll, 'tcx>,
place: &mir::Place<'tcx>)
use super::operand::{OperandRef, OperandValue};
use super::place::PlaceRef;
-impl FunctionCx<'a, 'll, 'tcx> {
+impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
pub fn codegen_rvalue(&mut self,
bx: Builder<'a, 'll, 'tcx>,
dest: PlaceRef<'tcx, &'ll Value>,
use super::FunctionCx;
use super::LocalRef;
use super::OperandValue;
+use value::Value;
-impl FunctionCx<'a, 'll, 'tcx> {
+impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
pub fn codegen_statement(&mut self,
bx: Builder<'a, 'll, 'tcx>,
statement: &mir::Statement<'tcx>)
use std::fmt;
use std::hash::{Hash, Hasher};
+pub trait ValueTrait: fmt::Debug {}
+
impl PartialEq for Value {
fn eq(&self, other: &Self) -> bool {
self as *const _ == other as *const _
}
}
+impl ValueTrait for Value {}
+
impl Eq for Value {}
impl Hash for Value {