Skip to content

Commit 7de0b1d

Browse files
committed
Move get_param and set_value_name
1 parent bcab497 commit 7de0b1d

File tree

10 files changed

+46
-38
lines changed

10 files changed

+46
-38
lines changed

src/librustc_codegen_llvm/abi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,4 +859,8 @@ impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
859859
) {
860860
ty.apply_attrs_callsite(self, callsite)
861861
}
862+
863+
fn get_param(&self, index: usize) -> Self::Value {
864+
llvm::get_param(self.llfn(), index as c_uint)
865+
}
862866
}

src/librustc_codegen_llvm/builder.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,25 +121,12 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
121121
Builder::new_block(self.cx, self.llfn(), name)
122122
}
123123

124-
fn llfn(&self) -> &'ll Value {
125-
unsafe {
126-
llvm::LLVMGetBasicBlockParent(self.llbb())
127-
}
128-
}
129-
130124
fn llbb(&self) -> &'ll BasicBlock {
131125
unsafe {
132126
llvm::LLVMGetInsertBlock(self.llbuilder)
133127
}
134128
}
135129

136-
fn set_value_name(&mut self, value: &'ll Value, name: &str) {
137-
let cname = SmallCStr::new(name);
138-
unsafe {
139-
llvm::LLVMSetValueName(value, cname.as_ptr());
140-
}
141-
}
142-
143130
fn position_at_end(&mut self, llbb: &'ll BasicBlock) {
144131
unsafe {
145132
llvm::LLVMPositionBuilderAtEnd(self.llbuilder, llbb);
@@ -768,6 +755,14 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
768755
}
769756
}
770757

758+
fn struct_gep(&mut self, ptr: &'ll Value, idx: u64) -> &'ll Value {
759+
self.count_insn("structgep");
760+
assert_eq!(idx as c_uint as u64, idx);
761+
unsafe {
762+
llvm::LLVMBuildStructGEP(self.llbuilder, ptr, idx as c_uint, noname())
763+
}
764+
}
765+
771766
/* Casts */
772767
fn trunc(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
773768
self.count_insn("trunc");
@@ -999,6 +994,14 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
999994
}
1000995
}
1001996

997+
#[allow(dead_code)]
998+
fn va_arg(&mut self, list: &'ll Value, ty: &'ll Type) -> &'ll Value {
999+
self.count_insn("vaarg");
1000+
unsafe {
1001+
llvm::LLVMBuildVAArg(self.llbuilder, list, ty, noname())
1002+
}
1003+
}
1004+
10021005
fn extract_element(&mut self, vec: &'ll Value, idx: &'ll Value) -> &'ll Value {
10031006
self.count_insn("extractelement");
10041007
unsafe {
@@ -1241,13 +1244,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12411244
}
12421245
}
12431246

1244-
fn struct_gep(&mut self, ptr: &'ll Value, idx: u64) -> &'ll Value {
1245-
self.count_insn("structgep");
1246-
assert_eq!(idx as c_uint as u64, idx);
1247-
unsafe {
1248-
llvm::LLVMBuildStructGEP(self.llbuilder, ptr, idx as c_uint, noname())
1249-
}
1250-
}
12511247

12521248
fn cx(&self) -> &CodegenCx<'ll, 'tcx> {
12531249
self.cx
@@ -1263,7 +1259,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
12631259
}
12641260

12651261
impl StaticBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
1266-
fn get_static(&mut self, def_id: DefId) -> &'ll Value {
1262+
fn get_static(&mut self, def_id: DefId) -> &'ll Value {
12671263
// Forward to the `get_static` method of `CodegenCx`
12681264
self.cx().get_static(def_id)
12691265
}
@@ -1300,6 +1296,12 @@ impl StaticBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
13001296
}
13011297

13021298
impl Builder<'a, 'll, 'tcx> {
1299+
pub fn llfn(&self) -> &'ll Value {
1300+
unsafe {
1301+
llvm::LLVMGetBasicBlockParent(self.llbb())
1302+
}
1303+
}
1304+
13031305
fn count_insn(&self, category: &str) {
13041306
if self.sess().codegen_stats() {
13051307
self.stats.borrow_mut().n_llvm_insns += 1;

src/librustc_codegen_llvm/context.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::monomorphize::partitioning::CodegenUnit;
1010
use crate::type_::Type;
1111
use crate::type_of::PointeeInfo;
1212
use rustc_codegen_ssa::traits::*;
13-
use libc::c_uint;
1413

1514
use rustc_data_structures::base_n;
1615
use rustc_data_structures::small_c_str::SmallCStr;
@@ -326,10 +325,6 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
326325
get_fn(self, instance)
327326
}
328327

329-
fn get_param(&self, llfn: &'ll Value, index: usize) -> &'ll Value {
330-
llvm::get_param(llfn, index as c_uint)
331-
}
332-
333328
fn eh_personality(&self) -> &'ll Value {
334329
// The exception handling personality function.
335330
//

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
225225
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
226226
gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
227227
}
228+
229+
fn set_value_name(&mut self, value: &'ll Value, name: &str) {
230+
let cname = SmallCStr::new(name);
231+
unsafe {
232+
llvm::LLVMSetValueName(value, cname.as_ptr());
233+
}
234+
}
228235
}
229236

230237
impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {

src/librustc_codegen_ssa/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
501501
bx.insert_reference_to_gdb_debug_scripts_section_global();
502502

503503
// Params from native main() used as args for rust start function
504-
let param_argc = cx.get_param(llfn, 0);
505-
let param_argv = cx.get_param(llfn, 1);
504+
let param_argc = bx.get_param(0);
505+
let param_argv = bx.get_param(1);
506506
let arg_argc = bx.intcast(param_argc, cx.type_isize(), true);
507507
let arg_argv = param_argv;
508508

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
295295
// Temporary or return place
296296
if local == mir::RETURN_PLACE && fx.fn_ty.ret.is_indirect() {
297297
debug!("alloc: {:?} (return place) -> place", local);
298-
let llretptr = fx.cx.get_param(llfn, 0);
298+
let llretptr = bx.get_param(0);
299299
LocalRef::Place(PlaceRef::new_sized(llretptr, layout, layout.align.abi))
300300
} else if memory_locals.contains(local) {
301301
debug!("alloc: {:?} -> place", local);
@@ -523,18 +523,18 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
523523
}
524524
PassMode::Ignore(IgnoreMode::CVarArgs) => {}
525525
PassMode::Direct(_) => {
526-
let llarg = bx.get_param(bx.llfn(), llarg_idx);
526+
let llarg = bx.get_param(llarg_idx);
527527
bx.set_value_name(llarg, &name);
528528
llarg_idx += 1;
529529
return local(
530530
OperandRef::from_immediate_or_packed_pair(bx, llarg, arg.layout));
531531
}
532532
PassMode::Pair(..) => {
533-
let a = bx.get_param(bx.llfn(), llarg_idx);
533+
let a = bx.get_param(llarg_idx);
534534
bx.set_value_name(a, &(name.clone() + ".0"));
535535
llarg_idx += 1;
536536

537-
let b = bx.get_param(bx.llfn(), llarg_idx);
537+
let b = bx.get_param(llarg_idx);
538538
bx.set_value_name(b, &(name + ".1"));
539539
llarg_idx += 1;
540540

@@ -551,16 +551,16 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
551551
// Don't copy an indirect argument to an alloca, the caller
552552
// already put it in a temporary alloca and gave it up.
553553
// FIXME: lifetimes
554-
let llarg = bx.get_param(bx.llfn(), llarg_idx);
554+
let llarg = bx.get_param(llarg_idx);
555555
bx.set_value_name(llarg, &name);
556556
llarg_idx += 1;
557557
PlaceRef::new_sized(llarg, arg.layout, arg.layout.align.abi)
558558
} else if arg.is_unsized_indirect() {
559559
// As the storage for the indirect argument lives during
560560
// the whole function call, we just copy the fat pointer.
561-
let llarg = bx.get_param(bx.llfn(), llarg_idx);
561+
let llarg = bx.get_param(llarg_idx);
562562
llarg_idx += 1;
563-
let llextra = bx.get_param(bx.llfn(), llarg_idx);
563+
let llextra = bx.get_param(llarg_idx);
564564
llarg_idx += 1;
565565
let indirect_operand = OperandValue::Pair(llarg, llextra);
566566

src/librustc_codegen_ssa/traits/abi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ pub trait AbiMethods<'tcx> {
1010

1111
pub trait AbiBuilderMethods<'tcx>: BackendTypes {
1212
fn apply_attrs_callsite(&mut self, ty: &FnType<'tcx, Ty<'tcx>>, callsite: Self::Value);
13+
fn get_param(&self, index: usize) -> Self::Value;
1314
}

src/librustc_codegen_ssa/traits/builder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
3636
fn with_cx(cx: &'a Self::CodegenCx) -> Self;
3737
fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
3838
fn cx(&self) -> &Self::CodegenCx;
39-
fn llfn(&self) -> Self::Value;
4039
fn llbb(&self) -> Self::BasicBlock;
4140

42-
fn set_value_name(&mut self, value: Self::Value, name: &str);
4341
fn position_at_end(&mut self, llbb: Self::BasicBlock);
4442
fn ret_void(&mut self);
4543
fn ret(&mut self, v: Self::Value);
@@ -209,6 +207,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
209207
else_val: Self::Value,
210208
) -> Self::Value;
211209

210+
fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
212211
fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
213212
fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
214213
fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;

src/librustc_codegen_ssa/traits/debuginfo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ pub trait DebugInfoBuilderMethods<'tcx>: BackendTypes {
5858
span: Span,
5959
);
6060
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self);
61+
fn set_value_name(&mut self, value: Self::Value, name: &str);
6162
}

src/librustc_codegen_ssa/traits/misc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub trait MiscMethods<'tcx>: BackendTypes {
1414
fn check_overflow(&self) -> bool;
1515
fn instances(&self) -> &RefCell<FxHashMap<Instance<'tcx>, Self::Value>>;
1616
fn get_fn(&self, instance: Instance<'tcx>) -> Self::Value;
17-
fn get_param(&self, llfn: Self::Value, index: usize) -> Self::Value;
1817
fn eh_personality(&self) -> Self::Value;
1918
fn eh_unwind_resume(&self) -> Self::Value;
2019
fn sess(&self) -> &Session;

0 commit comments

Comments
 (0)