Skip to content

Commit

Permalink
Auto merge of #56198 - bjorn3:cg_ssa_refactor, r=eddyb
Browse files Browse the repository at this point in the history
Refactor rustc_codegen_ssa

cc #56108 (not all things are done yet)

This removes an unsafe method from cg_ssa.

r? @eddyb
cc @sunfishcode
  • Loading branch information
bors committed Dec 2, 2018
2 parents 8660eba + d108a91 commit 21f2684
Show file tree
Hide file tree
Showing 38 changed files with 536 additions and 525 deletions.
14 changes: 7 additions & 7 deletions src/librustc_codegen_llvm/abi.rs
Expand Up @@ -212,7 +212,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
let can_store_through_cast_ptr = false;
if can_store_through_cast_ptr {
let cast_ptr_llty = bx.cx().type_ptr_to(cast.llvm_type(bx.cx()));
let cast_ptr_llty = bx.type_ptr_to(cast.llvm_type(bx));
let cast_dst = bx.pointercast(dst.llval, cast_ptr_llty);
bx.store(val, cast_dst, self.layout.align.abi);
} else {
Expand All @@ -231,9 +231,9 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
// bitcasting to the struct type yields invalid cast errors.

// We instead thus allocate some scratch space...
let scratch_size = cast.size(bx.cx());
let scratch_align = cast.align(bx.cx());
let llscratch = bx.alloca(cast.llvm_type(bx.cx()), "abi_cast", scratch_align);
let scratch_size = cast.size(bx);
let scratch_align = cast.align(bx);
let llscratch = bx.alloca(cast.llvm_type(bx), "abi_cast", scratch_align);
bx.lifetime_start(llscratch, scratch_size);

// ...where we first store the value...
Expand All @@ -245,7 +245,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
self.layout.align.abi,
llscratch,
scratch_align,
bx.cx().const_usize(self.layout.size.bytes()),
bx.const_usize(self.layout.size.bytes()),
MemFlags::empty()
);

Expand Down Expand Up @@ -299,7 +299,7 @@ impl ArgTypeMethods<'tcx> for Builder<'a, 'll, 'tcx> {
ty.store(self, val, dst)
}
fn memory_ty(&self, ty: &ArgType<'tcx, Ty<'tcx>>) -> &'ll Type {
ty.memory_ty(self.cx())
ty.memory_ty(self)
}
}

Expand Down Expand Up @@ -780,7 +780,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
// by the LLVM verifier.
if let layout::Int(..) = scalar.value {
if !scalar.is_bool() {
let range = scalar.valid_range_exclusive(bx.cx());
let range = scalar.valid_range_exclusive(bx);
if range.start != range.end {
bx.range_metadata(callsite, range);
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_codegen_llvm/asm.rs
Expand Up @@ -57,7 +57,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {

// Default per-arch clobbers
// Basically what clang does
let arch_clobbers = match &self.cx().sess().target.target.arch[..] {
let arch_clobbers = match &self.sess().target.target.arch[..] {
"x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"],
"mips" | "mips64" => vec!["~{$1}"],
_ => Vec::new()
Expand All @@ -76,9 +76,9 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
// Depending on how many outputs we have, the return type is different
let num_outputs = output_types.len();
let output_type = match num_outputs {
0 => self.cx().type_void(),
0 => self.type_void(),
1 => output_types[0],
_ => self.cx().type_struct(&output_types, false)
_ => self.type_struct(&output_types, false)
};

let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
Expand Down Expand Up @@ -108,13 +108,13 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
// back to source locations. See #17552.
unsafe {
let key = "srcloc";
let kind = llvm::LLVMGetMDKindIDInContext(self.cx().llcx,
let kind = llvm::LLVMGetMDKindIDInContext(self.llcx,
key.as_ptr() as *const c_char, key.len() as c_uint);

let val: &'ll Value = self.cx().const_i32(ia.ctxt.outer().as_u32() as i32);
let val: &'ll Value = self.const_i32(ia.ctxt.outer().as_u32() as i32);

llvm::LLVMSetMetadata(r, kind,
llvm::LLVMMDNodeInContext(self.cx().llcx, &val, 1));
llvm::LLVMMDNodeInContext(self.llcx, &val, 1));
}

true
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_codegen_llvm/base.rs
Expand Up @@ -195,7 +195,9 @@ pub fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, '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 {
cx.static_replace_all_uses(old_g, new_g)
let bitcast = llvm::LLVMConstPointerCast(new_g, cx.val_ty(old_g));
llvm::LLVMReplaceAllUsesWith(old_g, bitcast);
llvm::LLVMDeleteGlobal(old_g);
}
}

Expand Down

0 comments on commit 21f2684

Please sign in to comment.