Skip to content

Commit 83c3503

Browse files
committed
Greate separation of librsutc_codegen_llvm : librustc_codegen_ssa compiles
1 parent 63fb606 commit 83c3503

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1763
-1170
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 12 additions & 758 deletions
Large diffs are not rendered by default.

src/librustc_codegen_llvm/builder.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ fn noname() -> *const c_char {
5252
&CNULL
5353
}
5454

55-
bitflags! {
56-
pub struct MemFlags: u8 {
57-
const VOLATILE = 1 << 0;
58-
const NONTEMPORAL = 1 << 1;
59-
const UNALIGNED = 1 << 2;
60-
}
61-
}
62-
6355
impl HasCodegen<'a, 'll, 'tcx> for Builder<'a, 'll, 'tcx, &'ll Value> {
6456
type CodegenCx = CodegenCx<'ll, 'tcx, &'ll Value>;
6557
}

src/librustc_codegen_llvm/callee.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -203,34 +203,3 @@ pub fn get_fn(
203203

204204
llfn
205205
}
206-
207-
pub fn resolve_and_get_fn<'ll, 'tcx: 'll, Cx : CodegenMethods<'ll, 'tcx>>(
208-
cx: &Cx,
209-
def_id: DefId,
210-
substs: &'tcx Substs<'tcx>,
211-
) -> Cx::Value {
212-
cx.get_fn(
213-
ty::Instance::resolve(
214-
*cx.tcx(),
215-
ty::ParamEnv::reveal_all(),
216-
def_id,
217-
substs
218-
).unwrap()
219-
)
220-
}
221-
222-
pub fn resolve_and_get_fn_for_vtable(
223-
cx: &CodegenCx<'ll, 'tcx>,
224-
def_id: DefId,
225-
substs: &'tcx Substs<'tcx>,
226-
) -> &'ll Value {
227-
get_fn(
228-
cx,
229-
ty::Instance::resolve_for_vtable(
230-
cx.tcx,
231-
ty::ParamEnv::reveal_all(),
232-
def_id,
233-
substs
234-
).unwrap()
235-
)
236-
}

src/librustc_codegen_llvm/common.rs

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -368,88 +368,3 @@ pub fn struct_in_context(
368368
fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
369369
((hi as u128) << 64) | (lo as u128)
370370
}
371-
372-
pub fn langcall(tcx: TyCtxt,
373-
span: Option<Span>,
374-
msg: &str,
375-
li: LangItem)
376-
-> DefId {
377-
tcx.lang_items().require(li).unwrap_or_else(|s| {
378-
let msg = format!("{} {}", msg, s);
379-
match span {
380-
Some(span) => tcx.sess.span_fatal(span, &msg[..]),
381-
None => tcx.sess.fatal(&msg[..]),
382-
}
383-
})
384-
}
385-
386-
// To avoid UB from LLVM, these two functions mask RHS with an
387-
// appropriate mask unconditionally (i.e. the fallback behavior for
388-
// all shifts). For 32- and 64-bit types, this matches the semantics
389-
// of Java. (See related discussion on #1877 and #10183.)
390-
391-
pub fn build_unchecked_lshift<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a, 'll, 'tcx>>(
392-
bx: &Bx,
393-
lhs: <Bx::CodegenCx as Backend<'ll>>::Value,
394-
rhs: <Bx::CodegenCx as Backend<'ll>>::Value
395-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
396-
let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shl, lhs, rhs);
397-
// #1877, #10183: Ensure that input is always valid
398-
let rhs = shift_mask_rhs(bx, rhs);
399-
bx.shl(lhs, rhs)
400-
}
401-
402-
pub fn build_unchecked_rshift<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a, 'll, 'tcx>>(
403-
bx: &Bx,
404-
lhs_t: Ty<'tcx>,
405-
lhs: <Bx::CodegenCx as Backend<'ll>>::Value,
406-
rhs: <Bx::CodegenCx as Backend<'ll>>::Value
407-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
408-
let rhs = base::cast_shift_expr_rhs(bx, hir::BinOpKind::Shr, lhs, rhs);
409-
// #1877, #10183: Ensure that input is always valid
410-
let rhs = shift_mask_rhs(bx, rhs);
411-
let is_signed = lhs_t.is_signed();
412-
if is_signed {
413-
bx.ashr(lhs, rhs)
414-
} else {
415-
bx.lshr(lhs, rhs)
416-
}
417-
}
418-
419-
fn shift_mask_rhs<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a, 'll, 'tcx>>(
420-
bx: &Bx,
421-
rhs: <Bx::CodegenCx as Backend<'ll>>::Value
422-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
423-
let rhs_llty = bx.cx().val_ty(rhs);
424-
bx.and(rhs, shift_mask_val(bx, rhs_llty, rhs_llty, false))
425-
}
426-
427-
pub fn shift_mask_val<'a, 'll: 'a, 'tcx: 'll, Bx: BuilderMethods<'a, 'll, 'tcx>>(
428-
bx: &Bx,
429-
llty: <Bx::CodegenCx as Backend<'ll>>::Type,
430-
mask_llty: <Bx::CodegenCx as Backend<'ll>>::Type,
431-
invert: bool
432-
) -> <Bx::CodegenCx as Backend<'ll>>::Value {
433-
let kind = bx.cx().type_kind(llty);
434-
match kind {
435-
TypeKind::Integer => {
436-
// i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.
437-
let val = bx.cx().int_width(llty) - 1;
438-
if invert {
439-
bx.cx().const_int(mask_llty, !val as i64)
440-
} else {
441-
bx.cx().const_uint(mask_llty, val)
442-
}
443-
},
444-
TypeKind::Vector => {
445-
let mask = shift_mask_val(
446-
bx,
447-
bx.cx().element_type(llty),
448-
bx.cx().element_type(mask_llty),
449-
invert
450-
);
451-
bx.vector_splat(bx.cx().vector_length(mask_llty), mask)
452-
},
453-
_ => bug!("shift_mask_val: expected Integer or Vector, found {:?}", kind),
454-
}
455-
}

src/librustc_codegen_llvm/consts.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,61 @@ use rustc::hir::{self, CodegenFnAttrs, CodegenFnAttrFlags};
3232
use std::ffi::{CStr, CString};
3333

3434

35+
pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_, &'ll Value>, alloc: &Allocation) -> &'ll Value {
36+
let mut llvals = Vec::with_capacity(alloc.relocations.len() + 1);
37+
let layout = cx.data_layout();
38+
let pointer_size = layout.pointer_size.bytes() as usize;
39+
40+
let mut next_offset = 0;
41+
for &(offset, alloc_id) in alloc.relocations.iter() {
42+
let offset = offset.bytes();
43+
assert_eq!(offset as usize as u64, offset);
44+
let offset = offset as usize;
45+
if offset > next_offset {
46+
llvals.push(cx.const_bytes(&alloc.bytes[next_offset..offset]));
47+
}
48+
let ptr_offset = read_target_uint(
49+
layout.endian,
50+
&alloc.bytes[offset..(offset + pointer_size)],
51+
).expect("const_alloc_to_llvm: could not read relocation pointer") as u64;
52+
llvals.push(cx.scalar_to_backend(
53+
Pointer { alloc_id, offset: Size::from_bytes(ptr_offset) }.into(),
54+
&layout::Scalar {
55+
value: layout::Primitive::Pointer,
56+
valid_range: 0..=!0
57+
},
58+
cx.type_i8p()
59+
));
60+
next_offset = offset + pointer_size;
61+
}
62+
if alloc.bytes.len() >= next_offset {
63+
llvals.push(cx.const_bytes(&alloc.bytes[next_offset ..]));
64+
}
65+
66+
cx.const_struct(&llvals, true)
67+
}
68+
69+
pub fn codegen_static_initializer(
70+
cx: &CodegenCx<'ll, 'tcx, &'ll Value>,
71+
def_id: DefId,
72+
) -> Result<(&'ll Value, &'tcx Allocation), Lrc<ConstEvalErr<'tcx>>> {
73+
let instance = ty::Instance::mono(cx.tcx, def_id);
74+
let cid = GlobalId {
75+
instance,
76+
promoted: None,
77+
};
78+
let param_env = ty::ParamEnv::reveal_all();
79+
let static_ = cx.tcx.const_eval(param_env.and(cid))?;
80+
81+
let alloc = match static_.val {
82+
ConstValue::ByRef(_, alloc, n) if n.bytes() == 0 => alloc,
83+
_ => bug!("static const eval returned {:#?}", static_),
84+
};
85+
Ok((const_alloc_to_llvm(cx, alloc), alloc))
86+
}
87+
88+
89+
3590
fn set_global_alignment(cx: &CodegenCx<'ll, '_, &'ll Value>,
3691
gv: &'ll Value,
3792
mut align: Align) {

src/librustc_codegen_llvm/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ impl MiscMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll Value> {
446446
attributes::apply_target_cpu_attr(self, llfn)
447447
}
448448

449+
fn env_alloca_allowed(&self) {
450+
unsafe { llvm::LLVMRustVersionMajor() < 6 }
451+
}
449452

450453
fn create_used_variable(&self) {
451454
let name = const_cstr!("llvm.used");

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
2727

2828
use syntax_pos::BytePos;
2929

30-
#[derive(Clone, Copy, Debug)]
31-
pub struct MirDebugScope<D> {
32-
pub scope_metadata: Option<D>,
33-
// Start and end offsets of the file to which this DIScope belongs.
34-
// These are used to quickly determine whether some span refers to the same file.
35-
pub file_start_pos: BytePos,
36-
pub file_end_pos: BytePos,
37-
}
38-
39-
impl<D> MirDebugScope<D> {
40-
pub fn is_valid(&self) -> bool {
41-
self.scope_metadata.is_some()
42-
}
43-
}
44-
4530
/// Produce DIScope DIEs for each MIR Scope which has variables defined in it.
4631
/// If debuginfo is disabled, the returned vector is empty.
4732
pub fn create_mir_scopes(

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -111,53 +111,6 @@ impl<'a, 'tcx> CrateDebugContext<'a, 'tcx> {
111111
}
112112
}
113113

114-
pub enum FunctionDebugContext<'ll> {
115-
RegularContext(FunctionDebugContextData<'ll>),
116-
DebugInfoDisabled,
117-
FunctionWithoutDebugInfo,
118-
}
119-
120-
impl FunctionDebugContext<'ll> {
121-
pub fn get_ref<'a>(&'a self, span: Span) -> &'a FunctionDebugContextData<'ll> {
122-
match *self {
123-
FunctionDebugContext::RegularContext(ref data) => data,
124-
FunctionDebugContext::DebugInfoDisabled => {
125-
span_bug!(span, "{}", FunctionDebugContext::debuginfo_disabled_message());
126-
}
127-
FunctionDebugContext::FunctionWithoutDebugInfo => {
128-
span_bug!(span, "{}", FunctionDebugContext::should_be_ignored_message());
129-
}
130-
}
131-
}
132-
133-
fn debuginfo_disabled_message() -> &'static str {
134-
"debuginfo: Error trying to access FunctionDebugContext although debug info is disabled!"
135-
}
136-
137-
fn should_be_ignored_message() -> &'static str {
138-
"debuginfo: Error trying to access FunctionDebugContext for function that should be \
139-
ignored by debug info!"
140-
}
141-
}
142-
143-
pub struct FunctionDebugContextData<'ll> {
144-
fn_metadata: &'ll DISubprogram,
145-
source_locations_enabled: Cell<bool>,
146-
pub defining_crate: CrateNum,
147-
}
148-
149-
pub enum VariableAccess<'a, V> {
150-
// The llptr given is an alloca containing the variable's value
151-
DirectVariable { alloca: V },
152-
// The llptr given is an alloca containing the start of some pointer chain
153-
// leading to the variable's content.
154-
IndirectVariable { alloca: V, address_operations: &'a [i64] }
155-
}
156-
157-
pub enum VariableKind {
158-
ArgumentVariable(usize /*index*/),
159-
LocalVariable,
160-
}
161114

162115
/// Create any deferred debug metadata nodes
163116
pub fn finalize(cx: &CodegenCx<'ll, '_, &'ll Value>) {
@@ -596,4 +549,13 @@ impl<'ll, 'tcx: 'll> DebugInfoMethods<'ll, 'tcx> for CodegenCx<'ll, 'tcx, &'ll V
596549
fn debuginfo_finalize(&self) {
597550
finalize(self)
598551
}
552+
553+
fn debuginfo_upvar_decls_ops_sequence(&self, byte_offset_of_var_in_env: u64) -> &[i64] {
554+
unsafe {
555+
[llvm::LLVMRustDIBuilderCreateOpDeref(),
556+
llvm::LLVMRustDIBuilderCreateOpPlusUconst(),
557+
byte_offset_of_var_in_env as i64,
558+
llvm::LLVMRustDIBuilderCreateOpDeref()]
559+
};
560+
}
599561
}

src/librustc_codegen_llvm/debuginfo/source_loc.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ pub fn set_source_location(
5151
set_debug_location(bx, dbg_loc);
5252
}
5353

54-
/// Enables emitting source locations for the given functions.
55-
///
56-
/// Since we don't want source locations to be emitted for the function prelude,
57-
/// they are disabled when beginning to codegen a new function. This functions
58-
/// switches source location emitting on and must therefore be called before the
59-
/// first real statement/expression of the function is codegened.
60-
pub fn start_emitting_source_locations(dbg_context: &FunctionDebugContext<'ll>) {
61-
if let FunctionDebugContext::RegularContext(ref data) = *dbg_context {
62-
data.source_locations_enabled.set(true);
63-
}
64-
}
65-
6654

6755
#[derive(Copy, Clone, PartialEq)]
6856
pub enum InternalDebugLocation<'ll> {

src/librustc_codegen_llvm/interfaces/mod.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
mod builder;
12-
mod consts;
13-
mod type_;
14-
mod intrinsic;
15-
mod debuginfo;
16-
mod abi;
17-
mod asm;
18-
19-
pub use self::builder::{BuilderMethods, HasCodegen};
2011
pub use rustc_codegen_ssa::interfaces::{Backend, BackendMethods, CodegenObject, MiscMethods,
21-
StaticMethods, DeclareMethods, PreDefineMethods};
22-
pub use self::consts::ConstMethods;
23-
pub use self::type_::{TypeMethods, BaseTypeMethods, DerivedTypeMethods,
24-
LayoutTypeMethods, ArgTypeMethods};
25-
pub use self::intrinsic::{IntrinsicCallMethods, IntrinsicDeclarationMethods};
26-
pub use self::debuginfo::{DebugInfoMethods, DebugInfoBuilderMethods};
27-
pub use self::abi::{AbiMethods, AbiBuilderMethods};
28-
pub use self::asm::{AsmMethods, AsmBuilderMethods};
29-
30-
pub trait CodegenMethods<'ll, 'tcx: 'll> :
31-
Backend<'ll> + TypeMethods<'ll, 'tcx> + MiscMethods<'ll, 'tcx> + ConstMethods<'ll, 'tcx> +
32-
StaticMethods<'ll> + DebugInfoMethods<'ll, 'tcx> + AbiMethods<'tcx> +
33-
IntrinsicDeclarationMethods<'ll> + DeclareMethods<'ll, 'tcx> + AsmMethods +
34-
PreDefineMethods<'ll, 'tcx> {}
12+
StaticMethods, DeclareMethods, PreDefineMethods, BuilderMethods, HasCodegen, ConstMethods,
13+
TypeMethods, BaseTypeMethods, DerivedTypeMethods, LayoutTypeMethods, ArgTypeMethods,
14+
IntrinsicCallMethods, IntrinsicDeclarationMethods, DebugInfoMethods, DebugInfoBuilderMethods,
15+
AbiMethods, AbiBuilderMethods, AsmMethods, AsmBuilderMethods, CodegenMethods};

0 commit comments

Comments
 (0)