Move get_param and set_value_name
This commit is contained in:
parent
bcab49720e
commit
7de0b1de19
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -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.
|
||||
//
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue