about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2015-01-15 00:23:43 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2015-01-15 00:23:43 +1100
commit4ebde950f5afc16366b04b4c191f1c6198726da7 (patch)
treede3044be96575c3709726eed5f1ed114cee948ed
parent3d5fbae33897a8340542f21b6ded913148ca9199 (diff)
downloadrust-4ebde950f5afc16366b04b4c191f1c6198726da7.tar.gz
rust-4ebde950f5afc16366b04b4c191f1c6198726da7.zip
Document, tweak and refactor some trans code.
-rw-r--r--src/librustc_llvm/lib.rs2
-rw-r--r--src/librustc_trans/trans/cabi_x86_64.rs43
-rw-r--r--src/librustc_trans/trans/type_.rs7
3 files changed, 31 insertions, 21 deletions
diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs
index a4f9b1f98d4..e7d613f67b6 100644
--- a/src/librustc_llvm/lib.rs
+++ b/src/librustc_llvm/lib.rs
@@ -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,
diff --git a/src/librustc_trans/trans/cabi_x86_64.rs b/src/librustc_trans/trans/cabi_x86_64.rs
index 86190b1e566..c0e80ff08a2 100644
--- a/src/librustc_trans/trans/cabi_x86_64.rs
+++ b/src/librustc_trans/trans/cabi_x86_64.rs
@@ -34,6 +34,7 @@ enum RegClass {
     SSEDs,
     SSEDv,
     SSEInt,
+    /// Data that can appear in the upper half of an SSE register.
     SSEUp,
     X87,
     X87Up,
@@ -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],
diff --git a/src/librustc_trans/trans/type_.rs b/src/librustc_trans/trans/type_.rs
index 9cae142c03a..acb1623db33 100644
--- a/src/librustc_trans/trans/type_.rs
+++ b/src/librustc_trans/trans/type_.rs
@@ -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