Skip to content

Consolidate codes dealing with LLVM struct type #5089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,12 +1379,7 @@ pub fn type_to_str_inner(names: @TypeNames, +outer0: &[TypeRef], ty: TypeRef)
type_to_str_inner(names, outer, out_ty)).to_managed();
}
Struct => {
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
let mut elts = vec::from_elem(n_elts, 0 as TypeRef);
if !elts.is_empty() {
llvm::LLVMGetStructElementTypes(
ty, ptr::to_mut_unsafe_ptr(&mut elts[0]));
}
let elts = struct_tys(ty);
// See [Note at-str]
return fmt!("{%s}", tys_str(names, outer, elts)).to_managed();
}
Expand Down Expand Up @@ -1445,17 +1440,16 @@ pub fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] {
}
}

pub fn struct_element_types(struct_ty: TypeRef) -> ~[TypeRef] {
pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] {
unsafe {
let count = llvm::LLVMCountStructElementTypes(struct_ty);
let mut buf: ~[TypeRef] =
vec::from_elem(count as uint,
cast::transmute::<uint,TypeRef>(0));
if buf.len() > 0 {
llvm::LLVMGetStructElementTypes(
struct_ty, ptr::to_mut_unsafe_ptr(&mut buf[0]));
let n_elts = llvm::LLVMCountStructElementTypes(struct_ty) as uint;
if n_elts == 0 {
return ~[];
}
return buf;
let mut elts = vec::from_elem(n_elts, ptr::null());
llvm::LLVMGetStructElementTypes(
struct_ty, ptr::to_mut_unsafe_ptr(&mut elts[0]));
return elts;
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2150,11 +2150,6 @@ pub fn trans_mod(ccx: @CrateContext, m: ast::_mod) {
}
}

pub fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef {
// Bit of a kludge: pick the fn typeref out of the pair.
return struct_elt(llpairty, 0u);
}

pub fn register_fn(ccx: @CrateContext,
sp: span,
+path: path,
Expand Down
14 changes: 1 addition & 13 deletions src/librustc/middle/trans/cabi_x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use lib::llvm::{llvm, TypeRef, ValueRef, Integer, Pointer, Float, Double};
use lib::llvm::{Struct, Array, Attribute};
use lib::llvm::{StructRetAttribute, ByValAttribute};
use lib::llvm::struct_tys;
use middle::trans::common::*;
use middle::trans::cabi::*;

Expand Down Expand Up @@ -65,19 +66,6 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] {
return (off + a - 1u) / a * a;
}

fn struct_tys(ty: TypeRef) -> ~[TypeRef] {
unsafe {
let n = llvm::LLVMCountStructElementTypes(ty);
if (n == 0) {
return ~[];
}
let mut elts = vec::from_elem(n as uint, ptr::null());
llvm::LLVMGetStructElementTypes(ty,
ptr::to_mut_unsafe_ptr(&mut elts[0]));
return elts;
}
}

fn ty_align(ty: TypeRef) -> uint {
unsafe {
return match llvm::LLVMGetTypeKind(ty) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ pub fn trans_rtcall_or_lang_call_with_type_params(bcx: block,
fty);
let mut llfnty = type_of::type_of(callee.bcx.ccx(),
substituted);
llfnty = T_ptr(struct_elt(llfnty, 0));
llfnty = lib::llvm::struct_tys(llfnty)[0];
new_llval = PointerCast(callee.bcx, fn_data.llfn, llfnty);
}
_ => fail!()
Expand Down
13 changes: 0 additions & 13 deletions src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,19 +645,6 @@ pub fn val_str(tn: @TypeNames, v: ValueRef) -> @str {
return ty_str(tn, val_ty(v));
}

// Returns the nth element of the given LLVM structure type.
pub fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef {
unsafe {
let elt_count = llvm::LLVMCountStructElementTypes(llstructty) as uint;
assert (n < elt_count);
let mut elt_tys = vec::from_elem(elt_count, T_nil());
llvm::LLVMGetStructElementTypes(
llstructty,
ptr::to_mut_unsafe_ptr(&mut elt_tys[0]));
return llvm::LLVMGetElementType(elt_tys[n]);
}
}

pub fn in_scope_cx(cx: block, f: &fn(&mut scope_info)) {
let mut cur = cx;
loop {
Expand Down