Skip to content

Commit 21f2684

Browse files
committed
Auto merge of #56198 - bjorn3:cg_ssa_refactor, r=eddyb
Refactor rustc_codegen_ssa cc #56108 (not all things are done yet) This removes an unsafe method from cg_ssa. r? @eddyb cc @sunfishcode
2 parents 8660eba + d108a91 commit 21f2684

38 files changed

+536
-525
lines changed

Diff for: src/librustc_codegen_llvm/abi.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
212212
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
213213
let can_store_through_cast_ptr = false;
214214
if can_store_through_cast_ptr {
215-
let cast_ptr_llty = bx.cx().type_ptr_to(cast.llvm_type(bx.cx()));
215+
let cast_ptr_llty = bx.type_ptr_to(cast.llvm_type(bx));
216216
let cast_dst = bx.pointercast(dst.llval, cast_ptr_llty);
217217
bx.store(val, cast_dst, self.layout.align.abi);
218218
} else {
@@ -231,9 +231,9 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
231231
// bitcasting to the struct type yields invalid cast errors.
232232

233233
// We instead thus allocate some scratch space...
234-
let scratch_size = cast.size(bx.cx());
235-
let scratch_align = cast.align(bx.cx());
236-
let llscratch = bx.alloca(cast.llvm_type(bx.cx()), "abi_cast", scratch_align);
234+
let scratch_size = cast.size(bx);
235+
let scratch_align = cast.align(bx);
236+
let llscratch = bx.alloca(cast.llvm_type(bx), "abi_cast", scratch_align);
237237
bx.lifetime_start(llscratch, scratch_size);
238238

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

@@ -299,7 +299,7 @@ impl ArgTypeMethods<'tcx> for Builder<'a, 'll, 'tcx> {
299299
ty.store(self, val, dst)
300300
}
301301
fn memory_ty(&self, ty: &ArgType<'tcx, Ty<'tcx>>) -> &'ll Type {
302-
ty.memory_ty(self.cx())
302+
ty.memory_ty(self)
303303
}
304304
}
305305

@@ -780,7 +780,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
780780
// by the LLVM verifier.
781781
if let layout::Int(..) = scalar.value {
782782
if !scalar.is_bool() {
783-
let range = scalar.valid_range_exclusive(bx.cx());
783+
let range = scalar.valid_range_exclusive(bx);
784784
if range.start != range.end {
785785
bx.range_metadata(callsite, range);
786786
}

Diff for: src/librustc_codegen_llvm/asm.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
5757

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

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

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

116116
llvm::LLVMSetMetadata(r, kind,
117-
llvm::LLVMMDNodeInContext(self.cx().llcx, &val, 1));
117+
llvm::LLVMMDNodeInContext(self.llcx, &val, 1));
118118
}
119119

120120
true

Diff for: src/librustc_codegen_llvm/base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ pub fn compile_codegen_unit<'ll, 'tcx>(tcx: TyCtxt<'ll, 'tcx, 'tcx>,
195195
// Run replace-all-uses-with for statics that need it
196196
for &(old_g, new_g) in cx.statics_to_rauw().borrow().iter() {
197197
unsafe {
198-
cx.static_replace_all_uses(old_g, new_g)
198+
let bitcast = llvm::LLVMConstPointerCast(new_g, cx.val_ty(old_g));
199+
llvm::LLVMReplaceAllUsesWith(old_g, bitcast);
200+
llvm::LLVMDeleteGlobal(old_g);
199201
}
200202
}
201203

0 commit comments

Comments
 (0)