Skip to content

Commit e9214a1

Browse files
committed
codegen: be more explicit about setting giving names to allocas.
1 parent f71826e commit e9214a1

File tree

10 files changed

+42
-55
lines changed

10 files changed

+42
-55
lines changed

src/librustc_codegen_llvm/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
229229
// We instead thus allocate some scratch space...
230230
let scratch_size = cast.size(bx);
231231
let scratch_align = cast.align(bx);
232-
let llscratch = bx.alloca(cast.llvm_type(bx), "abi_cast", scratch_align);
232+
let llscratch = bx.alloca(cast.llvm_type(bx), scratch_align);
233233
bx.lifetime_start(llscratch, scratch_size);
234234

235235
// ...where we first store the value...

src/librustc_codegen_llvm/builder.rs

+5-18
Original file line numberDiff line numberDiff line change
@@ -387,23 +387,17 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
387387
)
388388
}
389389

390-
fn alloca(&mut self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value {
390+
fn alloca(&mut self, ty: &'ll Type, align: Align) -> &'ll Value {
391391
let mut bx = Builder::with_cx(self.cx);
392392
bx.position_at_start(unsafe {
393393
llvm::LLVMGetFirstBasicBlock(self.llfn())
394394
});
395-
bx.dynamic_alloca(ty, name, align)
395+
bx.dynamic_alloca(ty, align)
396396
}
397397

398-
fn dynamic_alloca(&mut self, ty: &'ll Type, name: &str, align: Align) -> &'ll Value {
398+
fn dynamic_alloca(&mut self, ty: &'ll Type, align: Align) -> &'ll Value {
399399
unsafe {
400-
let alloca = if name.is_empty() {
401-
llvm::LLVMBuildAlloca(self.llbuilder, ty, UNNAMED)
402-
} else {
403-
let name = SmallCStr::new(name);
404-
llvm::LLVMBuildAlloca(self.llbuilder, ty,
405-
name.as_ptr())
406-
};
400+
let alloca = llvm::LLVMBuildAlloca(self.llbuilder, ty, UNNAMED);
407401
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
408402
alloca
409403
}
@@ -412,16 +406,9 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
412406
fn array_alloca(&mut self,
413407
ty: &'ll Type,
414408
len: &'ll Value,
415-
name: &str,
416409
align: Align) -> &'ll Value {
417410
unsafe {
418-
let alloca = if name.is_empty() {
419-
llvm::LLVMBuildArrayAlloca(self.llbuilder, ty, len, UNNAMED)
420-
} else {
421-
let name = SmallCStr::new(name);
422-
llvm::LLVMBuildArrayAlloca(self.llbuilder, ty, len,
423-
name.as_ptr())
424-
};
411+
let alloca = llvm::LLVMBuildArrayAlloca(self.llbuilder, ty, len, UNNAMED);
425412
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
426413
alloca
427414
}

src/librustc_codegen_llvm/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ fn codegen_msvc_try(
871871
// More information can be found in libstd's seh.rs implementation.
872872
let i64p = bx.type_ptr_to(bx.type_i64());
873873
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
874-
let slot = bx.alloca(i64p, "slot", ptr_align);
874+
let slot = bx.alloca(i64p, ptr_align);
875875
bx.invoke(func, &[data], normal.llbb(), catchswitch.llbb(), None);
876876

877877
normal.ret(bx.const_i32(0));

src/librustc_codegen_ssa/mir/block.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
276276
let llslot = match op.val {
277277
Immediate(_) | Pair(..) => {
278278
let scratch =
279-
PlaceRef::alloca(&mut bx, self.fn_ty.ret.layout, "ret");
279+
PlaceRef::alloca(&mut bx, self.fn_ty.ret.layout);
280280
op.val.store(&mut bx, scratch);
281281
scratch.llval
282282
}
@@ -767,7 +767,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
767767
match (arg, op.val) {
768768
(&mir::Operand::Copy(_), Ref(_, None, _)) |
769769
(&mir::Operand::Constant(_), Ref(_, None, _)) => {
770-
let tmp = PlaceRef::alloca(&mut bx, op.layout, "const");
770+
let tmp = PlaceRef::alloca(&mut bx, op.layout);
771771
op.val.store(&mut bx, tmp);
772772
op.val = Ref(tmp.llval, None, tmp.align);
773773
}
@@ -925,7 +925,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
925925
Immediate(_) | Pair(..) => {
926926
match arg.mode {
927927
PassMode::Indirect(..) | PassMode::Cast(_) => {
928-
let scratch = PlaceRef::alloca(bx, arg.layout, "arg");
928+
let scratch = PlaceRef::alloca(bx, arg.layout);
929929
op.val.store(bx, scratch);
930930
(scratch.llval, scratch.align, true)
931931
}
@@ -940,7 +940,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
940940
// think that ATM (Rust 1.16) we only pass temporaries, but we shouldn't
941941
// have scary latent bugs around.
942942

943-
let scratch = PlaceRef::alloca(bx, arg.layout, "arg");
943+
let scratch = PlaceRef::alloca(bx, arg.layout);
944944
base::memcpy_ty(bx, scratch.llval, scratch.align, llval, align,
945945
op.layout, MemFlags::empty());
946946
(scratch.llval, scratch.align, true)
@@ -1017,7 +1017,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10171017
cx.tcx().mk_mut_ptr(cx.tcx().types.u8),
10181018
cx.tcx().types.i32
10191019
]));
1020-
let slot = PlaceRef::alloca(bx, layout, "personalityslot");
1020+
let slot = PlaceRef::alloca(bx, layout);
10211021
self.personality_slot = Some(slot);
10221022
slot
10231023
}
@@ -1116,15 +1116,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11161116
return if fn_ret.is_indirect() {
11171117
// Odd, but possible, case, we have an operand temporary,
11181118
// but the calling convention has an indirect return.
1119-
let tmp = PlaceRef::alloca(bx, fn_ret.layout, "tmp_ret");
1119+
let tmp = PlaceRef::alloca(bx, fn_ret.layout);
11201120
tmp.storage_live(bx);
11211121
llargs.push(tmp.llval);
11221122
ReturnDest::IndirectOperand(tmp, index)
11231123
} else if is_intrinsic {
11241124
// Currently, intrinsics always need a location to store
11251125
// the result, so we create a temporary `alloca` for the
11261126
// result.
1127-
let tmp = PlaceRef::alloca(bx, fn_ret.layout, "tmp_ret");
1127+
let tmp = PlaceRef::alloca(bx, fn_ret.layout);
11281128
tmp.storage_live(bx);
11291129
ReturnDest::IndirectOperand(tmp, index)
11301130
} else {
@@ -1174,7 +1174,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11741174
LocalRef::Operand(None) => {
11751175
let dst_layout = bx.layout_of(self.monomorphized_place_ty(&dst.as_ref()));
11761176
assert!(!dst_layout.ty.has_erasable_regions());
1177-
let place = PlaceRef::alloca(bx, dst_layout, "transmute_temp");
1177+
let place = PlaceRef::alloca(bx, dst_layout);
11781178
place.storage_live(bx);
11791179
self.codegen_transmute_into(bx, src, place);
11801180
let op = bx.load_operand(place);
@@ -1227,7 +1227,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12271227
DirectOperand(index) => {
12281228
// If there is a cast, we have to store and reload.
12291229
let op = if let PassMode::Cast(_) = ret_ty.mode {
1230-
let tmp = PlaceRef::alloca(bx, ret_ty.layout, "tmp_ret");
1230+
let tmp = PlaceRef::alloca(bx, ret_ty.layout);
12311231
tmp.storage_live(bx);
12321232
bx.store_arg_ty(&ret_ty, llval, tmp);
12331233
let op = bx.load_operand(tmp);

src/librustc_codegen_ssa/mir/mod.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,13 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
268268
debug!("alloc: {:?} ({}) -> place", local, name);
269269
if layout.is_unsized() {
270270
let indirect_place =
271-
PlaceRef::alloca_unsized_indirect(&mut bx, layout, &name.as_str());
271+
PlaceRef::alloca_unsized_indirect(&mut bx, layout);
272+
bx.set_var_name(indirect_place.llval, name);
272273
// FIXME: add an appropriate debuginfo
273274
LocalRef::UnsizedPlace(indirect_place)
274275
} else {
275-
let place = PlaceRef::alloca(&mut bx, layout, &name.as_str());
276+
let place = PlaceRef::alloca(&mut bx, layout);
277+
bx.set_var_name(place.llval, name);
276278
if dbg {
277279
let (scope, span) = fx.debug_loc(mir::SourceInfo {
278280
span: decl.source_info.span,
@@ -293,14 +295,13 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
293295
} else if memory_locals.contains(local) {
294296
debug!("alloc: {:?} -> place", local);
295297
if layout.is_unsized() {
296-
let indirect_place = PlaceRef::alloca_unsized_indirect(
297-
&mut bx,
298-
layout,
299-
&format!("{:?}", local),
300-
);
298+
let indirect_place = PlaceRef::alloca_unsized_indirect(&mut bx, layout);
299+
bx.set_var_name(indirect_place.llval, format_args!("{:?}", local));
301300
LocalRef::UnsizedPlace(indirect_place)
302301
} else {
303-
LocalRef::Place(PlaceRef::alloca(&mut bx, layout, &format!("{:?}", local)))
302+
let place = PlaceRef::alloca(&mut bx, layout);
303+
bx.set_var_name(place.llval, format_args!("{:?}", local));
304+
LocalRef::Place(place)
304305
}
305306
} else {
306307
// If this is an immediate local, we do not create an
@@ -470,7 +471,8 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
470471
_ => bug!("spread argument isn't a tuple?!")
471472
};
472473

473-
let place = PlaceRef::alloca(bx, bx.layout_of(arg_ty), &name);
474+
let place = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
475+
bx.set_var_name(place.llval, name);
474476
for i in 0..tupled_arg_tys.len() {
475477
let arg = &fx.fn_ty.args[idx];
476478
idx += 1;
@@ -558,11 +560,13 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
558560
llarg_idx += 1;
559561
let indirect_operand = OperandValue::Pair(llarg, llextra);
560562

561-
let tmp = PlaceRef::alloca_unsized_indirect(bx, arg.layout, &name);
563+
let tmp = PlaceRef::alloca_unsized_indirect(bx, arg.layout);
564+
bx.set_var_name(tmp.llval, name);
562565
indirect_operand.store(bx, tmp);
563566
tmp
564567
} else {
565-
let tmp = PlaceRef::alloca(bx, arg.layout, &name);
568+
let tmp = PlaceRef::alloca(bx, arg.layout);
569+
bx.set_var_name(tmp.llval, name);
566570
if fx.fn_ty.c_variadic && last_arg_idx.map(|idx| arg_index == idx).unwrap_or(false) {
567571
let va_list_did = match tcx.lang_items().va_list() {
568572
Some(did) => did,

src/librustc_codegen_ssa/mir/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
367367

368368
// Allocate an appropriate region on the stack, and copy the value into it
369369
let (llsize, _) = glue::size_and_align_of_dst(bx, unsized_ty, Some(llextra));
370-
let lldst = bx.array_alloca(bx.cx().type_i8(), llsize, "unsized_tmp", max_align);
370+
let lldst = bx.array_alloca(bx.cx().type_i8(), llsize, max_align);
371371
bx.memcpy(lldst, max_align, llptr, min_align, llsize, flags);
372372

373373
// Store the allocated region and the extra to the indirect place.

src/librustc_codegen_ssa/mir/place.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,21 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
7171
pub fn alloca<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
7272
bx: &mut Bx,
7373
layout: TyLayout<'tcx>,
74-
name: &str
7574
) -> Self {
76-
debug!("alloca({:?}: {:?})", name, layout);
7775
assert!(!layout.is_unsized(), "tried to statically allocate unsized place");
78-
let tmp = bx.alloca(bx.cx().backend_type(layout), name, layout.align.abi);
76+
let tmp = bx.alloca(bx.cx().backend_type(layout), layout.align.abi);
7977
Self::new_sized(tmp, layout)
8078
}
8179

8280
/// Returns a place for an indirect reference to an unsized place.
8381
pub fn alloca_unsized_indirect<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
8482
bx: &mut Bx,
8583
layout: TyLayout<'tcx>,
86-
name: &str,
8784
) -> Self {
88-
debug!("alloca_unsized_indirect({:?}: {:?})", name, layout);
8985
assert!(layout.is_unsized(), "tried to allocate indirect place for sized values");
9086
let ptr_ty = bx.cx().tcx().mk_mut_ptr(layout.ty);
9187
let ptr_layout = bx.cx().layout_of(ptr_ty);
92-
Self::alloca(bx, ptr_layout, name)
88+
Self::alloca(bx, ptr_layout)
9389
}
9490

9591
pub fn len<Cx: ConstMethods<'tcx, Value = V>>(

src/librustc_codegen_ssa/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6464
// index into the struct, and this case isn't
6565
// important enough for it.
6666
debug!("codegen_rvalue: creating ugly alloca");
67-
let scratch = PlaceRef::alloca(&mut bx, operand.layout, "__unsize_temp");
67+
let scratch = PlaceRef::alloca(&mut bx, operand.layout);
6868
scratch.storage_live(&mut bx);
6969
operand.val.store(&mut bx, scratch);
7070
base::coerce_unsized_into(&mut bx, scratch, dest);

src/librustc_codegen_ssa/traits/builder.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,12 @@ pub trait BuilderMethods<'a, 'tcx>:
109109
rhs: Self::Value,
110110
) -> (Self::Value, Self::Value);
111111

112-
fn alloca(&mut self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
113-
fn dynamic_alloca(&mut self, ty: Self::Type, name: &str, align: Align) -> Self::Value;
112+
fn alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
113+
fn dynamic_alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value;
114114
fn array_alloca(
115115
&mut self,
116116
ty: Self::Type,
117117
len: Self::Value,
118-
name: &str,
119118
align: Align,
120119
) -> Self::Value;
121120

src/test/codegen/personality_lifetimes.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ pub fn test() {
2020
let _s = S;
2121
// Check that the personality slot alloca gets a lifetime start in each cleanup block, not just
2222
// in the first one.
23+
// CHECK: [[SLOT:%[0-9]+]] = alloca { i8*, i32 }
2324
// CHECK-LABEL: cleanup:
24-
// CHECK: bitcast{{.*}}personalityslot
25-
// CHECK-NEXT: call void @llvm.lifetime.start
25+
// CHECK: [[BITCAST:%[0-9]+]] = bitcast { i8*, i32 }* [[SLOT]] to i8*
26+
// CHECK-NEXT: call void @llvm.lifetime.start.{{.*}}({{.*}}, i8* [[BITCAST]])
2627
// CHECK-LABEL: cleanup1:
27-
// CHECK: bitcast{{.*}}personalityslot
28-
// CHECK-NEXT: call void @llvm.lifetime.start
28+
// CHECK: [[BITCAST1:%[0-9]+]] = bitcast { i8*, i32 }* [[SLOT]] to i8*
29+
// CHECK-NEXT: call void @llvm.lifetime.start.{{.*}}({{.*}}, i8* [[BITCAST1]])
2930
might_unwind();
3031
let _t = S;
3132
might_unwind();

0 commit comments

Comments
 (0)