Skip to content

Commit bf1253b

Browse files
authored
Rollup merge of #64435 - eddyb:arguments-against-arg, r=rkruppe
codegen: use "_N" (like for other locals) instead of "argN", for argument names. Based on #64408 (second commit is new), fixing something I mentioned in #64408 (which turned to be an immediate blocker for unifying relevant codepaths). Closes #64408 (by containing it). r? @rkruppe
2 parents 5160e4b + bdad2c5 commit bf1253b

18 files changed

+98
-110
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

+17-12
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
@@ -452,10 +453,11 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
452453
mir.args_iter().enumerate().map(|(arg_index, local)| {
453454
let arg_decl = &mir.local_decls[local];
454455

456+
// FIXME(eddyb) don't allocate a `String` unless it gets used.
455457
let name = if let Some(name) = arg_decl.name {
456458
name.as_str().to_string()
457459
} else {
458-
format!("arg{}", arg_index)
460+
format!("{:?}", local)
459461
};
460462

461463
if Some(local) == mir.spread_arg {
@@ -470,7 +472,8 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
470472
_ => bug!("spread argument isn't a tuple?!")
471473
};
472474

473-
let place = PlaceRef::alloca(bx, bx.layout_of(arg_ty), &name);
475+
let place = PlaceRef::alloca(bx, bx.layout_of(arg_ty));
476+
bx.set_var_name(place.llval, name);
474477
for i in 0..tupled_arg_tys.len() {
475478
let arg = &fx.fn_ty.args[idx];
476479
idx += 1;
@@ -558,11 +561,13 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
558561
llarg_idx += 1;
559562
let indirect_operand = OperandValue::Pair(llarg, llextra);
560563

561-
let tmp = PlaceRef::alloca_unsized_indirect(bx, arg.layout, &name);
564+
let tmp = PlaceRef::alloca_unsized_indirect(bx, arg.layout);
565+
bx.set_var_name(tmp.llval, name);
562566
indirect_operand.store(bx, tmp);
563567
tmp
564568
} else {
565-
let tmp = PlaceRef::alloca(bx, arg.layout, &name);
569+
let tmp = PlaceRef::alloca(bx, arg.layout);
570+
bx.set_var_name(tmp.llval, name);
566571
if fx.fn_ty.c_variadic && last_arg_idx.map(|idx| arg_index == idx).unwrap_or(false) {
567572
let va_list_did = match tcx.lang_items().va_list() {
568573
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/adjustments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![crate_type = "lib"]
44

55
// Hack to get the correct size for the length part in slices
6-
// CHECK: @helper([[USIZE:i[0-9]+]] %arg0)
6+
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
77
#[no_mangle]
88
pub fn helper(_: usize) {
99
}

src/test/codegen/fastcall-inreg.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,27 @@
4949
#![crate_type = "lib"]
5050

5151
pub mod tests {
52-
// CHECK: @f1(i32 inreg %arg0, i32 inreg %arg1, i32 %arg2)
52+
// CHECK: @f1(i32 inreg %_1, i32 inreg %_2, i32 %_3)
5353
#[no_mangle]
5454
pub extern "fastcall" fn f1(_: i32, _: i32, _: i32) {}
5555

56-
// CHECK: @f2(i32* inreg %arg0, i32* inreg %arg1, i32* %arg2)
56+
// CHECK: @f2(i32* inreg %_1, i32* inreg %_2, i32* %_3)
5757
#[no_mangle]
5858
pub extern "fastcall" fn f2(_: *const i32, _: *const i32, _: *const i32) {}
5959

60-
// CHECK: @f3(float %arg0, i32 inreg %arg1, i32 inreg %arg2, i32 %arg3)
60+
// CHECK: @f3(float %_1, i32 inreg %_2, i32 inreg %_3, i32 %_4)
6161
#[no_mangle]
6262
pub extern "fastcall" fn f3(_: f32, _: i32, _: i32, _: i32) {}
6363

64-
// CHECK: @f4(i32 inreg %arg0, float %arg1, i32 inreg %arg2, i32 %arg3)
64+
// CHECK: @f4(i32 inreg %_1, float %_2, i32 inreg %_3, i32 %_4)
6565
#[no_mangle]
6666
pub extern "fastcall" fn f4(_: i32, _: f32, _: i32, _: i32) {}
6767

68-
// CHECK: @f5(i64 %arg0, i32 %arg1)
68+
// CHECK: @f5(i64 %_1, i32 %_2)
6969
#[no_mangle]
7070
pub extern "fastcall" fn f5(_: i64, _: i32) {}
7171

72-
// CHECK: @f6(i1 inreg zeroext %arg0, i32 inreg %arg1, i32 %arg2)
72+
// CHECK: @f6(i1 inreg zeroext %_1, i32 inreg %_2, i32 %_3)
7373
#[no_mangle]
7474
pub extern "fastcall" fn f6(_: bool, _: i32, _: i32) {}
7575
}

0 commit comments

Comments
 (0)