Skip to content

Commit

Permalink
Move get_param and set_value_name
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Mar 29, 2019
1 parent bcab497 commit 7de0b1d
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 38 deletions.
4 changes: 4 additions & 0 deletions src/librustc_codegen_llvm/abi.rs
Expand Up @@ -859,4 +859,8 @@ impl AbiBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
) {
ty.apply_attrs_callsite(self, callsite)
}

fn get_param(&self, index: usize) -> Self::Value {
llvm::get_param(self.llfn(), index as c_uint)
}
}
44 changes: 23 additions & 21 deletions src/librustc_codegen_llvm/builder.rs
Expand Up @@ -121,25 +121,12 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
Builder::new_block(self.cx, self.llfn(), name)
}

fn llfn(&self) -> &'ll Value {
unsafe {
llvm::LLVMGetBasicBlockParent(self.llbb())
}
}

fn llbb(&self) -> &'ll BasicBlock {
unsafe {
llvm::LLVMGetInsertBlock(self.llbuilder)
}
}

fn set_value_name(&mut self, value: &'ll Value, name: &str) {
let cname = SmallCStr::new(name);
unsafe {
llvm::LLVMSetValueName(value, cname.as_ptr());
}
}

fn position_at_end(&mut self, llbb: &'ll BasicBlock) {
unsafe {
llvm::LLVMPositionBuilderAtEnd(self.llbuilder, llbb);
Expand Down Expand Up @@ -768,6 +755,14 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
}

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

/* Casts */
fn trunc(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
self.count_insn("trunc");
Expand Down Expand Up @@ -999,6 +994,14 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
}

#[allow(dead_code)]
fn va_arg(&mut self, list: &'ll Value, ty: &'ll Type) -> &'ll Value {
self.count_insn("vaarg");
unsafe {
llvm::LLVMBuildVAArg(self.llbuilder, list, ty, noname())
}
}

fn extract_element(&mut self, vec: &'ll Value, idx: &'ll Value) -> &'ll Value {
self.count_insn("extractelement");
unsafe {
Expand Down Expand Up @@ -1241,13 +1244,6 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
}

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

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

impl StaticBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
fn get_static(&mut self, def_id: DefId) -> &'ll Value {
fn get_static(&mut self, def_id: DefId) -> &'ll Value {
// Forward to the `get_static` method of `CodegenCx`
self.cx().get_static(def_id)
}
Expand Down Expand Up @@ -1300,6 +1296,12 @@ impl StaticBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
}

impl Builder<'a, 'll, 'tcx> {
pub fn llfn(&self) -> &'ll Value {
unsafe {
llvm::LLVMGetBasicBlockParent(self.llbb())
}
}

fn count_insn(&self, category: &str) {
if self.sess().codegen_stats() {
self.stats.borrow_mut().n_llvm_insns += 1;
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_codegen_llvm/context.rs
Expand Up @@ -10,7 +10,6 @@ use crate::monomorphize::partitioning::CodegenUnit;
use crate::type_::Type;
use crate::type_of::PointeeInfo;
use rustc_codegen_ssa::traits::*;
use libc::c_uint;

use rustc_data_structures::base_n;
use rustc_data_structures::small_c_str::SmallCStr;
Expand Down Expand Up @@ -326,10 +325,6 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
get_fn(self, instance)
}

fn get_param(&self, llfn: &'ll Value, index: usize) -> &'ll Value {
llvm::get_param(llfn, index as c_uint)
}

fn eh_personality(&self) -> &'ll Value {
// The exception handling personality function.
//
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_codegen_llvm/debuginfo/mod.rs
Expand Up @@ -225,6 +225,13 @@ impl DebugInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
}

fn set_value_name(&mut self, value: &'ll Value, name: &str) {
let cname = SmallCStr::new(name);
unsafe {
llvm::LLVMSetValueName(value, cname.as_ptr());
}
}
}

impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/base.rs
Expand Up @@ -501,8 +501,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
bx.insert_reference_to_gdb_debug_scripts_section_global();

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

Expand Down
14 changes: 7 additions & 7 deletions src/librustc_codegen_ssa/mir/mod.rs
Expand Up @@ -295,7 +295,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
// Temporary or return place
if local == mir::RETURN_PLACE && fx.fn_ty.ret.is_indirect() {
debug!("alloc: {:?} (return place) -> place", local);
let llretptr = fx.cx.get_param(llfn, 0);
let llretptr = bx.get_param(0);
LocalRef::Place(PlaceRef::new_sized(llretptr, layout, layout.align.abi))
} else if memory_locals.contains(local) {
debug!("alloc: {:?} -> place", local);
Expand Down Expand Up @@ -523,18 +523,18 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
}
PassMode::Ignore(IgnoreMode::CVarArgs) => {}
PassMode::Direct(_) => {
let llarg = bx.get_param(bx.llfn(), llarg_idx);
let llarg = bx.get_param(llarg_idx);
bx.set_value_name(llarg, &name);
llarg_idx += 1;
return local(
OperandRef::from_immediate_or_packed_pair(bx, llarg, arg.layout));
}
PassMode::Pair(..) => {
let a = bx.get_param(bx.llfn(), llarg_idx);
let a = bx.get_param(llarg_idx);
bx.set_value_name(a, &(name.clone() + ".0"));
llarg_idx += 1;

let b = bx.get_param(bx.llfn(), llarg_idx);
let b = bx.get_param(llarg_idx);
bx.set_value_name(b, &(name + ".1"));
llarg_idx += 1;

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

Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/traits/abi.rs
Expand Up @@ -10,4 +10,5 @@ pub trait AbiMethods<'tcx> {

pub trait AbiBuilderMethods<'tcx>: BackendTypes {
fn apply_attrs_callsite(&mut self, ty: &FnType<'tcx, Ty<'tcx>>, callsite: Self::Value);
fn get_param(&self, index: usize) -> Self::Value;
}
3 changes: 1 addition & 2 deletions src/librustc_codegen_ssa/traits/builder.rs
Expand Up @@ -36,10 +36,8 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
fn with_cx(cx: &'a Self::CodegenCx) -> Self;
fn build_sibling_block<'b>(&self, name: &'b str) -> Self;
fn cx(&self) -> &Self::CodegenCx;
fn llfn(&self) -> Self::Value;
fn llbb(&self) -> Self::BasicBlock;

fn set_value_name(&mut self, value: Self::Value, name: &str);
fn position_at_end(&mut self, llbb: Self::BasicBlock);
fn ret_void(&mut self);
fn ret(&mut self, v: Self::Value);
Expand Down Expand Up @@ -209,6 +207,7 @@ pub trait BuilderMethods<'a, 'tcx: 'a>:
else_val: Self::Value,
) -> Self::Value;

fn va_arg(&mut self, list: Self::Value, ty: Self::Type) -> Self::Value;
fn extract_element(&mut self, vec: Self::Value, idx: Self::Value) -> Self::Value;
fn vector_splat(&mut self, num_elts: usize, elt: Self::Value) -> Self::Value;
fn extract_value(&mut self, agg_val: Self::Value, idx: u64) -> Self::Value;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/traits/debuginfo.rs
Expand Up @@ -58,4 +58,5 @@ pub trait DebugInfoBuilderMethods<'tcx>: BackendTypes {
span: Span,
);
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self);
fn set_value_name(&mut self, value: Self::Value, name: &str);
}
1 change: 0 additions & 1 deletion src/librustc_codegen_ssa/traits/misc.rs
Expand Up @@ -14,7 +14,6 @@ pub trait MiscMethods<'tcx>: BackendTypes {
fn check_overflow(&self) -> bool;
fn instances(&self) -> &RefCell<FxHashMap<Instance<'tcx>, Self::Value>>;
fn get_fn(&self, instance: Instance<'tcx>) -> Self::Value;
fn get_param(&self, llfn: Self::Value, index: usize) -> Self::Value;
fn eh_personality(&self) -> Self::Value;
fn eh_unwind_resume(&self) -> Self::Value;
fn sess(&self) -> &Session;
Expand Down

0 comments on commit 7de0b1d

Please sign in to comment.