Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_codegen_llvm: traitification of LLVM-specific CodegenCx and Builder methods #55627

Merged
merged 73 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
5a9e6b8
rustc_codegen_llvm: begin generalizing over backend values.
irinagpopa Aug 2, 2018
c76fc3d
Work around to fix issue https://github.com/rust-lang/rust/issues/53912
denismerigoux Sep 6, 2018
83b2152
Reduced line length to pass tidy
denismerigoux Aug 3, 2018
34c5dc0
Generalized base.rs#call_memcpy and everything that it uses
denismerigoux Aug 7, 2018
14798d6
Generalized BasicBlocks in BuilderMethods trait
denismerigoux Aug 20, 2018
51b7f27
Generalized IntPredicate in the BuilderMethods trait
denismerigoux Aug 20, 2018
8590336
Generalized RealPredicate
denismerigoux Aug 21, 2018
bc86624
Removed useless traits for IntPredicate and RealPredicate
denismerigoux Aug 21, 2018
1bcb4df
Generalized OperandBundleDef in BuilderMethods
denismerigoux Aug 21, 2018
2755891
Generalized AtomicRmwBinOp for BuilderMethods
denismerigoux Aug 21, 2018
b699866
Generalized AtomicOrdering for BuilderMethods
denismerigoux Aug 21, 2018
b761538
Generalized SynchronisationScope for BuilderMethods
denismerigoux Aug 21, 2018
1ca7506
Generalized AsmDialect for BuilderMethods
denismerigoux Aug 21, 2018
9c41e1a
Removed genericity over Value in various functions
denismerigoux Aug 22, 2018
89825f2
Use associated types instead of type parameters inside the BuilderMet…
denismerigoux Aug 22, 2018
a16d85b
Removed parasite yaml file and put explicit lifetimes
denismerigoux Aug 23, 2018
7a2670e
Use real type names rather than Self::
denismerigoux Aug 23, 2018
d577ec7
New files and folders for traits
denismerigoux Aug 28, 2018
3889c2d
New Backend trait containing associated types
denismerigoux Aug 28, 2018
8714e6b
Traitification of common.rs methods
denismerigoux Aug 28, 2018
d325844
Replaced Codegen field access by trait method
denismerigoux Aug 28, 2018
83e07f9
Added self argument for Codegen CommonMethod trait methods
denismerigoux Aug 29, 2018
3aee772
Split CommonMethods to accomodate for use in back/write.rs
denismerigoux Aug 29, 2018
4cc18d3
CommonWriteMethods are not static any more
denismerigoux Aug 29, 2018
33eee83
Removed code duplication for CommonWriteMethods
denismerigoux Aug 30, 2018
6c5b990
All CommonMethods now real methods (not static)
denismerigoux Aug 30, 2018
3e77f2f
Use the method form for CodegenCx everywhere
denismerigoux Aug 30, 2018
5f28e0a
Added definition of type trait
denismerigoux Aug 30, 2018
730b13a
Traitification of type_ methods
denismerigoux Sep 5, 2018
6d42574
Prefixed const methods with "const" instead of "c"
denismerigoux Sep 6, 2018
e224f06
Prefixed type methods & removed trait impl for write::CodegenContext
denismerigoux Sep 6, 2018
a1d0d4f
Removing LLVM content from CommonMethods -> ConstMethods
denismerigoux Sep 6, 2018
4787b7c
Removed phantomdata no longer necessary
denismerigoux Sep 6, 2018
1929ac2
Fixed typos
denismerigoux Sep 7, 2018
c487b82
Attempt at including CodegenCx within Builder with Associated types
denismerigoux Sep 7, 2018
0514c7b
Generalized some base.rs methods
denismerigoux Sep 7, 2018
d77e34f
Generalized memset and memcpy
denismerigoux Sep 7, 2018
3c082a2
Added StaticMethods trait
denismerigoux Sep 10, 2018
a5aeb8e
Transfered memcpy and memset to BuilderMethods
denismerigoux Sep 10, 2018
0a1c509
Traitified IntrinsicCallMethods
denismerigoux Sep 11, 2018
484e07c
[eddyb/rebase cleanup] s/&self./self.
eddyb Nov 7, 2018
034f697
Generalized base::unsized_info
denismerigoux Sep 13, 2018
78dd95f
Generalized base::unsize_thin_ptr
denismerigoux Sep 13, 2018
cbe31a4
Generalized base::coerce_unsized_into
denismerigoux Sep 14, 2018
6a993fe
Generalized mir::codegen_mir (and all subsequent functions)
denismerigoux Sep 20, 2018
441a7c1
Generalized mono_item.rs and base.rs:codegen_instance
denismerigoux Sep 21, 2018
b14f3e5
Adapt code to latest rustc master changes
denismerigoux Sep 24, 2018
ac34068
Generalized base:maybe_create_entry_wrapper
denismerigoux Sep 24, 2018
97825a3
Move doc to trait declarations
denismerigoux Sep 24, 2018
8d530db
Generalized base:codegen_crate
denismerigoux Sep 25, 2018
91a2a80
Renamed lifetimes for better understanding
denismerigoux Sep 26, 2018
6819e6e
Preparing the generalization of base:compile_coodegen_unit
denismerigoux Sep 26, 2018
4ba09ab
Added compile codegen to backend trait
denismerigoux Sep 27, 2018
39fd4d9
Starting to move backend-agnostic code into codegen_utils
denismerigoux Sep 28, 2018
566fa4d
Moved common.rs enums
denismerigoux Sep 28, 2018
35b40f5
[eddyb/rebase cleanup] abstracted Funclet
eddyb Nov 13, 2018
b06836e
[eddyb/rebase cleanup] move type_{needs_drop,is_sized,is_freeze} to r…
eddyb Nov 13, 2018
b02e5cc
Moved Backend interface into rustc_codegen_utils
denismerigoux Oct 1, 2018
c9f26c2
Beginning of moving all backend-agnostic code to rustc_codegen_ssa
denismerigoux Oct 1, 2018
915382f
Moved DeclareMethods, MiscMethods and StaticMethods
denismerigoux Oct 2, 2018
c0a428e
Great separation of librustc_codegen_llvm: librustc_codegen_ssa compiles
denismerigoux Oct 3, 2018
015e444
Finished moving backend-agnostic code to rustc_codegen_ssa
denismerigoux Oct 3, 2018
1ebdfbb
Added some docs + start to &mut self builder methods
denismerigoux Oct 4, 2018
54dd3a4
All Builder methods now take &mut self instead of &self
denismerigoux Oct 5, 2018
b25b804
Added default impl for DerivedTypeMethods + empty impl for Cranelift …
denismerigoux Oct 9, 2018
b9e5cf9
Separating the back folder between backend-agnostic and LLVM-specific…
denismerigoux Oct 23, 2018
bf7f8cd
Added README explaining the refactoring
denismerigoux Oct 22, 2018
9bb6663
[eddyb] rustc_codegen_ssa: handle LLVM unsafety correctly.
eddyb Nov 16, 2018
9f49a26
[eddyb] rustc_codegen_utils: remove extraneous `#![allow(dead_code)]`.
eddyb Nov 16, 2018
47c84c4
[eddyb] rustc_codegen_llvm: remove unnecessary `'a` from `LlvmCodegen…
eddyb Nov 16, 2018
d1410ad
[eddyb] rustc_codegen_ssa: avoid a `Clone` bound on `TargetMachine`.
eddyb Nov 16, 2018
0b56924
[eddyb] rustc_codegen_ssa: rename `interfaces` to `traits`.
eddyb Nov 16, 2018
756f84d
[eddyb] rustc_codegen_llvm: remove unused parametrization of `Codegen…
eddyb Nov 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
use llvm::{self, AttributePlace};
use base;
use builder::{Builder, MemFlags};
use common::C_usize;
use context::CodegenCx;
use mir::place::PlaceRef;
use mir::operand::OperandValue;
use type_::Type;
use type_of::{LayoutLlvmExt, PointerKind};
use value::Value;

use interfaces::{BuilderMethods, CommonMethods};

use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TyLayout, Abi as LayoutAbi};
use rustc::ty::{self, Ty};
use rustc::ty::layout;
Expand Down Expand Up @@ -167,8 +168,18 @@ impl LlvmType for CastTarget {

pub trait ArgTypeExt<'ll, 'tcx> {
fn memory_ty(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type;
fn store(&self, bx: &Builder<'_, 'll, 'tcx>, val: &'ll Value, dst: PlaceRef<'ll, 'tcx>);
fn store_fn_arg(&self, bx: &Builder<'_, 'll, 'tcx>, idx: &mut usize, dst: PlaceRef<'ll, 'tcx>);
fn store(
&self,
bx: &Builder<'_, 'll, 'tcx>,
val: &'ll Value,
dst: PlaceRef<'tcx, &'ll Value>,
);
fn store_fn_arg(
&self,
bx: &Builder<'_, 'll, 'tcx>,
idx: &mut usize,
dst: PlaceRef<'tcx, &'ll Value>,
);
}

impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
Expand All @@ -182,7 +193,12 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
/// place for the original Rust type of this argument/return.
/// Can be used for both storing formal arguments into Rust variables
/// or results of call/invoke instructions into their destinations.
fn store(&self, bx: &Builder<'_, 'll, 'tcx>, val: &'ll Value, dst: PlaceRef<'ll, 'tcx>) {
fn store(
&self,
bx: &Builder<'_, 'll, 'tcx>,
val: &'ll Value,
dst: PlaceRef<'tcx, &'ll Value>,
) {
if self.is_ignore() {
return;
}
Expand Down Expand Up @@ -228,7 +244,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
self.layout.align,
bx.pointercast(llscratch, Type::i8p(cx)),
scratch_align,
C_usize(cx, self.layout.size.bytes()),
CodegenCx::c_usize(cx, self.layout.size.bytes()),
MemFlags::empty());

bx.lifetime_end(llscratch, scratch_size);
Expand All @@ -238,7 +254,12 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
}
}

fn store_fn_arg(&self, bx: &Builder<'a, 'll, 'tcx>, idx: &mut usize, dst: PlaceRef<'ll, 'tcx>) {
fn store_fn_arg(
&self,
bx: &Builder<'a, 'll, 'tcx>,
idx: &mut usize,
dst: PlaceRef<'tcx, &'ll Value>,
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a LLVM-ism, does Cranelift support getting at the function params from a builder? What I'd do instead is also pass a slice of values, alongside the index.

let mut next = || {
let val = llvm::get_param(bx.llfn(), *idx as c_uint);
*idx += 1;
Expand Down
15 changes: 5 additions & 10 deletions src/librustc_codegen_llvm/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
// except according to those terms.

use llvm;
use common::*;
use context::CodegenCx;
use type_::Type;
use type_of::LayoutLlvmExt;
use builder::Builder;
use value::Value;

use rustc::hir;
use interfaces::{BuilderMethods, CommonMethods};

use mir::place::PlaceRef;
use mir::operand::OperandValue;

use std::ffi::CString;
use syntax::ast::AsmDialect;
use libc::{c_uint, c_char};

// Take an inline assembly expression and splat it out via LLVM
pub fn codegen_inline_asm(
bx: &Builder<'a, 'll, 'tcx>,
ia: &hir::InlineAsm,
outputs: Vec<PlaceRef<'ll, 'tcx>>,
outputs: Vec<PlaceRef<'tcx, &'ll Value>>,
mut inputs: Vec<&'ll Value>
) -> bool {
let mut ext_constraints = vec![];
Expand Down Expand Up @@ -81,11 +81,6 @@ pub fn codegen_inline_asm(
_ => Type::struct_(bx.cx, &output_types, false)
};

let dialect = match ia.dialect {
AsmDialect::Att => llvm::AsmDialect::Att,
AsmDialect::Intel => llvm::AsmDialect::Intel,
};

let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
let constraint_cstr = CString::new(all_constraints).unwrap();
let r = bx.inline_asm_call(
Expand All @@ -95,7 +90,7 @@ pub fn codegen_inline_asm(
output_type,
ia.volatile,
ia.alignstack,
dialect
ia.dialect
);
if r.is_none() {
return false;
Expand All @@ -116,7 +111,7 @@ pub fn codegen_inline_asm(
let kind = llvm::LLVMGetMDKindIDInContext(bx.cx.llcx,
key.as_ptr() as *const c_char, key.len() as c_uint);

let val: &'ll Value = C_i32(bx.cx, ia.ctxt.outer().as_u32() as i32);
let val: &'ll Value = CodegenCx::c_i32(bx.cx, ia.ctxt.outer().as_u32() as i32);

llvm::LLVMSetMetadata(r, kind,
llvm::LLVMMDNodeInContext(bx.cx.llcx, &val, 1));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ fn link_natively(sess: &Session,
// with some thread pool working in the background. It seems that no one
// currently knows a fix for this so in the meantime we're left with this...
info!("{:?}", &cmd);
let retry_on_segfault = env::var("RUSTC_RETRY_LINKER_ON_SEGFAULT").is_ok();
let retry_on_segfault = env::var("RUSTc_RETRY_LINKER_ON_SEGFAULT").is_ok();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this change in capitalization intentional? I doubt it =)

let mut prog;
let mut i = 0;
loop {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use syntax::ext::hygiene::Mark;
use syntax_pos::MultiSpan;
use syntax_pos::symbol::Symbol;
use type_::Type;
use context::{is_pie_binary, get_reloc_model};
use common::{C_bytes_in_context, val_ty};
use context::{is_pie_binary, get_reloc_model, CodegenCx};
use interfaces::CommonMethods;
use jobserver::{Client, Acquired};
use rustc_demangle;

Expand Down Expand Up @@ -884,10 +884,10 @@ unsafe fn embed_bitcode(cgcx: &CodegenContext,
llcx: &llvm::Context,
llmod: &llvm::Module,
bitcode: Option<&[u8]>) {
let llconst = C_bytes_in_context(llcx, bitcode.unwrap_or(&[]));
let llconst = CodegenCx::c_bytes_in_context(llcx, bitcode.unwrap_or(&[]));
let llglobal = llvm::LLVMAddGlobal(
llmod,
val_ty(llconst),
CodegenCx::val_ty(llconst),
"rustc.embedded.module\0".as_ptr() as *const _,
);
llvm::LLVMSetInitializer(llglobal, llconst);
Expand All @@ -904,10 +904,10 @@ unsafe fn embed_bitcode(cgcx: &CodegenContext,
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);

let llconst = C_bytes_in_context(llcx, &[]);
let llconst = CodegenCx::c_bytes_in_context(llcx, &[]);
let llglobal = llvm::LLVMAddGlobal(
llmod,
val_ty(llconst),
CodegenCx::val_ty(llconst),
"rustc.embedded.cmdline\0".as_ptr() as *const _,
);
llvm::LLVMSetInitializer(llglobal, llconst);
Expand Down
83 changes: 44 additions & 39 deletions src/librustc_codegen_llvm/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ use mir::place::PlaceRef;
use attributes;
use builder::{Builder, MemFlags};
use callee;
use common::{C_bool, C_bytes_in_context, C_usize};
use rustc_mir::monomorphize::item::DefPathBasedNames;
use common::{C_struct_in_context, C_array, val_ty};
use common::{IntPredicate, RealPredicate};
use consts;
use context::CodegenCx;
use debuginfo;
Expand All @@ -75,6 +74,8 @@ use rustc_data_structures::small_c_str::SmallCStr;
use rustc_data_structures::sync::Lrc;
use rustc_data_structures::indexed_vec::Idx;

use interfaces::{BuilderMethods, CommonMethods};

use std::any::Any;
use std::cmp;
use std::ffi::CString;
Expand Down Expand Up @@ -124,14 +125,14 @@ impl Drop for StatRecorder<'a, 'll, 'tcx> {

pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind,
signed: bool)
-> llvm::IntPredicate {
-> IntPredicate {
match op {
hir::BinOpKind::Eq => llvm::IntEQ,
hir::BinOpKind::Ne => llvm::IntNE,
hir::BinOpKind::Lt => if signed { llvm::IntSLT } else { llvm::IntULT },
hir::BinOpKind::Le => if signed { llvm::IntSLE } else { llvm::IntULE },
hir::BinOpKind::Gt => if signed { llvm::IntSGT } else { llvm::IntUGT },
hir::BinOpKind::Ge => if signed { llvm::IntSGE } else { llvm::IntUGE },
hir::BinOpKind::Eq => IntPredicate::IntEQ,
hir::BinOpKind::Ne => IntPredicate::IntNE,
hir::BinOpKind::Lt => if signed { IntPredicate::IntSLT } else { IntPredicate::IntULT },
hir::BinOpKind::Le => if signed { IntPredicate::IntSLE } else { IntPredicate::IntULE },
hir::BinOpKind::Gt => if signed { IntPredicate::IntSGT } else { IntPredicate::IntUGT },
hir::BinOpKind::Ge => if signed { IntPredicate::IntSGE } else { IntPredicate::IntUGE },
op => {
bug!("comparison_op_to_icmp_predicate: expected comparison operator, \
found {:?}",
Expand All @@ -140,14 +141,14 @@ pub fn bin_op_to_icmp_predicate(op: hir::BinOpKind,
}
}

pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> llvm::RealPredicate {
pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
match op {
hir::BinOpKind::Eq => llvm::RealOEQ,
hir::BinOpKind::Ne => llvm::RealUNE,
hir::BinOpKind::Lt => llvm::RealOLT,
hir::BinOpKind::Le => llvm::RealOLE,
hir::BinOpKind::Gt => llvm::RealOGT,
hir::BinOpKind::Ge => llvm::RealOGE,
hir::BinOpKind::Eq => RealPredicate::RealOEQ,
hir::BinOpKind::Ne => RealPredicate::RealUNE,
hir::BinOpKind::Lt => RealPredicate::RealOLT,
hir::BinOpKind::Le => RealPredicate::RealOLE,
hir::BinOpKind::Gt => RealPredicate::RealOGT,
hir::BinOpKind::Ge => RealPredicate::RealOGE,
op => {
bug!("comparison_op_to_fcmp_predicate: expected comparison operator, \
found {:?}",
Expand Down Expand Up @@ -197,7 +198,7 @@ pub fn unsized_info(
let (source, target) = cx.tcx.struct_lockstep_tails(source, target);
match (&source.sty, &target.sty) {
(&ty::Array(_, len), &ty::Slice(_)) => {
C_usize(cx, len.unwrap_usize(cx.tcx))
CodegenCx::c_usize(cx, len.unwrap_usize(cx.tcx))
}
(&ty::Dynamic(..), &ty::Dynamic(..)) => {
// For now, upcasts are limited to changes in marker
Expand Down Expand Up @@ -275,8 +276,8 @@ pub fn unsize_thin_ptr(
/// to a value of type `dst_ty` and store the result in `dst`
pub fn coerce_unsized_into(
bx: &Builder<'a, 'll, 'tcx>,
src: PlaceRef<'ll, 'tcx>,
dst: PlaceRef<'ll, 'tcx>
src: PlaceRef<'tcx, &'ll Value>,
dst: PlaceRef<'tcx, &'ll Value>
) {
let src_ty = src.layout.ty;
let dst_ty = dst.layout.ty;
Expand Down Expand Up @@ -349,8 +350,8 @@ fn cast_shift_rhs<'ll, F, G>(op: hir::BinOpKind,
{
// Shifts may have any size int on the rhs
if op.is_shift() {
let mut rhs_llty = val_ty(rhs);
let mut lhs_llty = val_ty(lhs);
let mut rhs_llty = CodegenCx::val_ty(rhs);
let mut lhs_llty = CodegenCx::val_ty(lhs);
if rhs_llty.kind() == TypeKind::Vector {
rhs_llty = rhs_llty.element_type()
}
Expand Down Expand Up @@ -387,9 +388,12 @@ pub fn call_assume(bx: &Builder<'_, 'll, '_>, val: &'ll Value) {
bx.call(assume_intrinsic, &[val], None);
}

pub fn from_immediate(bx: &Builder<'_, 'll, '_>, val: &'ll Value) -> &'ll Value {
if val_ty(val) == Type::i1(bx.cx) {
bx.zext(val, Type::i8(bx.cx))
pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll>(
bx: &Builder<'_ ,'ll, '_, &'ll Value>,
val: &'ll Value
) -> &'ll Value {
if CodegenCx::val_ty(val) == Type::i1(bx.cx()) {
bx.zext(val, Type::i8(bx.cx()))
} else {
val
}
Expand Down Expand Up @@ -417,8 +421,8 @@ pub fn to_immediate_scalar(
val
}

pub fn call_memcpy(
bx: &Builder<'_, 'll, '_>,
pub fn call_memcpy<'a, 'll: 'a, 'tcx: 'll>(
bx: &Builder<'_ ,'ll, '_, &'ll Value>,
dst: &'ll Value,
dst_align: Align,
src: &'ll Value,
Expand All @@ -429,20 +433,20 @@ pub fn call_memcpy(
if flags.contains(MemFlags::NONTEMPORAL) {
// HACK(nox): This is inefficient but there is no nontemporal memcpy.
let val = bx.load(src, src_align);
let ptr = bx.pointercast(dst, val_ty(val).ptr_to());
let ptr = bx.pointercast(dst, CodegenCx::val_ty(val).ptr_to());
bx.store_with_flags(val, ptr, dst_align, flags);
return;
}
let cx = bx.cx;
let cx = bx.cx();
let src_ptr = bx.pointercast(src, Type::i8p(cx));
let dst_ptr = bx.pointercast(dst, Type::i8p(cx));
let size = bx.intcast(n_bytes, cx.isize_ty, false);
let volatile = flags.contains(MemFlags::VOLATILE);
bx.memcpy(dst_ptr, dst_align.abi(), src_ptr, src_align.abi(), size, volatile);
}

pub fn memcpy_ty(
bx: &Builder<'_, 'll, 'tcx>,
pub fn memcpy_ty<'a, 'll: 'a, 'tcx: 'll>(
bx: &Builder<'_ ,'ll, '_, &'ll Value>,
dst: &'ll Value,
dst_align: Align,
src: &'ll Value,
Expand All @@ -455,7 +459,7 @@ pub fn memcpy_ty(
return;
}

call_memcpy(bx, dst, dst_align, src, src_align, C_usize(bx.cx, size), flags);
call_memcpy(bx, dst, dst_align, src, src_align, CodegenCx::c_usize(bx.cx(), size), flags);
}

pub fn call_memset(
Expand All @@ -469,7 +473,7 @@ pub fn call_memset(
let ptr_width = &bx.cx.sess().target.target.target_pointer_width;
let intrinsic_key = format!("llvm.memset.p0i8.i{}", ptr_width);
let llintrinsicfn = bx.cx.get_intrinsic(&intrinsic_key);
let volatile = C_bool(bx.cx, volatile);
let volatile = CodegenCx::c_bool(bx.cx, volatile);
bx.call(llintrinsicfn, &[ptr, fill_byte, size, align, volatile], None)
}

Expand Down Expand Up @@ -545,7 +549,8 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
rust_main_def_id: DefId,
use_start_lang_item: bool,
) {
let llfty = Type::func(&[Type::c_int(cx), Type::i8p(cx).ptr_to()], Type::c_int(cx));
let llfty =
Type::func(&[Type::c_int(cx), Type::i8p(cx).ptr_to()], Type::c_int(cx));

let main_ret_ty = cx.tcx.fn_sig(rust_main_def_id).output();
// Given that `main()` has no arguments,
Expand Down Expand Up @@ -643,12 +648,12 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
DeflateEncoder::new(&mut compressed, Compression::fast())
.write_all(&metadata.raw_data).unwrap();

let llmeta = C_bytes_in_context(metadata_llcx, &compressed);
let llconst = C_struct_in_context(metadata_llcx, &[llmeta], false);
let llmeta = CodegenCx::c_bytes_in_context(metadata_llcx, &compressed);
let llconst = CodegenCx::c_struct_in_context(metadata_llcx, &[llmeta], false);
let name = exported_symbols::metadata_symbol_name(tcx);
let buf = CString::new(name).unwrap();
let llglobal = unsafe {
llvm::LLVMAddGlobal(metadata_llmod, val_ty(llconst), buf.as_ptr())
llvm::LLVMAddGlobal(metadata_llmod, CodegenCx::val_ty(llconst), buf.as_ptr())
};
unsafe {
llvm::LLVMSetInitializer(llglobal, llconst);
Expand Down Expand Up @@ -1134,7 +1139,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// Run replace-all-uses-with for statics that need it
for &(old_g, new_g) in cx.statics_to_rauw.borrow().iter() {
unsafe {
let bitcast = llvm::LLVMConstPointerCast(new_g, val_ty(old_g));
let bitcast = llvm::LLVMConstPointerCast(new_g, CodegenCx::val_ty(old_g));
llvm::LLVMReplaceAllUsesWith(old_g, bitcast);
llvm::LLVMDeleteGlobal(old_g);
}
Expand All @@ -1145,11 +1150,11 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if !cx.used_statics.borrow().is_empty() {
let name = const_cstr!("llvm.used");
let section = const_cstr!("llvm.metadata");
let array = C_array(Type::i8(&cx).ptr_to(), &*cx.used_statics.borrow());
let array = CodegenCx::c_array(Type::i8(&cx).ptr_to(), &*cx.used_statics.borrow());

unsafe {
let g = llvm::LLVMAddGlobal(cx.llmod,
val_ty(array),
CodegenCx::val_ty(array),
name.as_ptr());
llvm::LLVMSetInitializer(g, array);
llvm::LLVMRustSetLinkage(g, llvm::Linkage::AppendingLinkage);
Expand Down
Loading