Skip to content

Commit 4ebde95

Browse files
committed
Document, tweak and refactor some trans code.
1 parent 3d5fbae commit 4ebde95

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

src/librustc_llvm/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub enum RealPredicate {
304304

305305
// The LLVM TypeKind type - must stay in sync with the def of
306306
// LLVMTypeKind in llvm/include/llvm-c/Core.h
307-
#[derive(Copy, PartialEq)]
307+
#[derive(Copy, PartialEq, Show)]
308308
#[repr(C)]
309309
pub enum TypeKind {
310310
Void = 0,

src/librustc_trans/trans/cabi_x86_64.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum RegClass {
3434
SSEDs,
3535
SSEDv,
3636
SSEInt,
37+
/// Data that can appear in the upper half of an SSE register.
3738
SSEUp,
3839
X87,
3940
X87Up,
@@ -155,26 +156,28 @@ fn classify_ty(ty: Type) -> Vec<RegClass> {
155156
fn unify(cls: &mut [RegClass],
156157
i: uint,
157158
newv: RegClass) {
158-
if cls[i] == newv {
159-
return;
160-
} else if cls[i] == NoClass {
161-
cls[i] = newv;
162-
} else if newv == NoClass {
163-
return;
164-
} else if cls[i] == Memory || newv == Memory {
165-
cls[i] = Memory;
166-
} else if cls[i] == Int || newv == Int {
167-
cls[i] = Int;
168-
} else if cls[i] == X87 ||
169-
cls[i] == X87Up ||
170-
cls[i] == ComplexX87 ||
171-
newv == X87 ||
172-
newv == X87Up ||
173-
newv == ComplexX87 {
174-
cls[i] = Memory;
175-
} else {
176-
cls[i] = newv;
177-
}
159+
if cls[i] == newv { return }
160+
161+
let to_write = match (cls[i], newv) {
162+
(NoClass, _) => newv,
163+
(_, NoClass) => return,
164+
165+
(Memory, _) |
166+
(_, Memory) => Memory,
167+
168+
(Int, _) |
169+
(_, Int) => Int,
170+
171+
(X87, _) |
172+
(X87Up, _) |
173+
(ComplexX87, _) |
174+
(_, X87) |
175+
(_, X87Up) |
176+
(_, ComplexX87) => Memory,
177+
178+
(_, _) => newv
179+
};
180+
cls[i] = to_write;
178181
}
179182

180183
fn classify_struct(tys: &[Type],

src/librustc_trans/trans/type_.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ impl Type {
284284
}
285285
}
286286

287+
/// Return the number of elements in `self` if it is a LLVM vector type.
288+
pub fn vector_length(&self) -> uint {
289+
unsafe {
290+
llvm::LLVMGetVectorSize(self.to_ref()) as uint
291+
}
292+
}
293+
287294
pub fn array_length(&self) -> uint {
288295
unsafe {
289296
llvm::LLVMGetArrayLength(self.to_ref()) as uint

0 commit comments

Comments
 (0)