Skip to content

Commit

Permalink
Document, tweak and refactor some trans code.
Browse files Browse the repository at this point in the history
  • Loading branch information
huonw committed Jan 14, 2015
1 parent 3d5fbae commit 4ebde95
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/librustc_llvm/lib.rs
Expand Up @@ -304,7 +304,7 @@ pub enum RealPredicate {

// The LLVM TypeKind type - must stay in sync with the def of
// LLVMTypeKind in llvm/include/llvm-c/Core.h
#[derive(Copy, PartialEq)]
#[derive(Copy, PartialEq, Show)]
#[repr(C)]
pub enum TypeKind {
Void = 0,
Expand Down
43 changes: 23 additions & 20 deletions src/librustc_trans/trans/cabi_x86_64.rs
Expand Up @@ -34,6 +34,7 @@ enum RegClass {
SSEDs,
SSEDv,
SSEInt,
/// Data that can appear in the upper half of an SSE register.
SSEUp,
X87,
X87Up,
Expand Down Expand Up @@ -155,26 +156,28 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
fn unify(cls: &mut [RegClass],
i: uint,
newv: RegClass) {
if cls[i] == newv {
return;
} else if cls[i] == NoClass {
cls[i] = newv;
} else if newv == NoClass {
return;
} else if cls[i] == Memory || newv == Memory {
cls[i] = Memory;
} else if cls[i] == Int || newv == Int {
cls[i] = Int;
} else if cls[i] == X87 ||
cls[i] == X87Up ||
cls[i] == ComplexX87 ||
newv == X87 ||
newv == X87Up ||
newv == ComplexX87 {
cls[i] = Memory;
} else {
cls[i] = newv;
}
if cls[i] == newv { return }

let to_write = match (cls[i], newv) {
(NoClass, _) => newv,
(_, NoClass) => return,

(Memory, _) |
(_, Memory) => Memory,

(Int, _) |
(_, Int) => Int,

(X87, _) |
(X87Up, _) |
(ComplexX87, _) |
(_, X87) |
(_, X87Up) |
(_, ComplexX87) => Memory,

(_, _) => newv
};
cls[i] = to_write;
}

fn classify_struct(tys: &[Type],
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_trans/trans/type_.rs
Expand Up @@ -284,6 +284,13 @@ impl Type {
}
}

/// Return the number of elements in `self` if it is a LLVM vector type.
pub fn vector_length(&self) -> uint {
unsafe {
llvm::LLVMGetVectorSize(self.to_ref()) as uint
}
}

pub fn array_length(&self) -> uint {
unsafe {
llvm::LLVMGetArrayLength(self.to_ref()) as uint
Expand Down

0 comments on commit 4ebde95

Please sign in to comment.