[cfe-commits] r107078 - in /cfe/trunk: lib/CodeGen/TargetInfo.cpp test/CodeGenCXX/mangle-exprs.cpp test/CodeGenCXX/member-functions.cpp

Chris Lattner sabre at nondot.org
Mon Jun 28 14:59:07 PDT 2010


Author: lattner
Date: Mon Jun 28 16:59:07 2010
New Revision: 107078

URL: http://llvm.org/viewvc/llvm-project?rev=107078&view=rev
Log:
pass/return structs of char and short as i8/i16 to avoid
aweful through-memory coersion, just like we do for i32 now.

Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp
    cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
    cfe/trunk/test/CodeGenCXX/member-functions.cpp

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=107078&r1=107077&r2=107078&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Jun 28 16:59:07 2010
@@ -1116,11 +1116,15 @@
       return (Ty->isPromotableIntegerType() ?
               ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
     
-    // If this is a 32-bit structure that is passed as an int64, then it will be
-    // passed in the low 32-bits of a 64-bit GPR, which is the same as how an
-    // i32 is passed.  Coerce to a i32 instead of a i64.
-    if (Context.getTypeSizeInChars(Ty).getQuantity() == 4)
-      CoerceTo = llvm::Type::getInt32Ty(CoerceTo->getContext());
+    // If this is a 8/16/32-bit structure that is passed as an int64, then it
+    // will be passed in the low 8/16/32-bits of a 64-bit GPR, which is the same
+    // as how an i8/i16/i32 is passed.  Coerce to a i8/i16/i32 instead of a i64.
+    switch (Context.getTypeSizeInChars(Ty).getQuantity()) {
+    default: break;
+    case 1: CoerceTo = llvm::Type::getInt8Ty(CoerceTo->getContext()); break;
+    case 2: CoerceTo = llvm::Type::getInt16Ty(CoerceTo->getContext()); break;
+    case 4: CoerceTo = llvm::Type::getInt32Ty(CoerceTo->getContext()); break;
+    }
     
   } else if (CoerceTo->isDoubleTy()) {
     assert(Ty.isCanonical() && "should always have a canonical type here");

Modified: cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp?rev=107078&r1=107077&r2=107078&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp Mon Jun 28 16:59:07 2010
@@ -39,6 +39,6 @@
   // CHECK: define weak_odr void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE
   template void static_<4>(void*);
 
-  // CHECK: define weak_odr i64 @_ZN5Casts1fILi6EEENS_1TIXT_EEEv
+  // CHECK: define weak_odr i8 @_ZN5Casts1fILi6EEENS_1TIXT_EEEv
   template T<6> f<6>();
 }

Modified: cfe/trunk/test/CodeGenCXX/member-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/member-functions.cpp?rev=107078&r1=107077&r2=107078&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/member-functions.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/member-functions.cpp Mon Jun 28 16:59:07 2010
@@ -58,6 +58,6 @@
 void test3() {
   T t1, t2;
   
-  // RUN: grep "call i64 @_ZN1TplERKS_" %t
+  // RUN: grep "call i8 @_ZN1TplERKS_" %t
   T result = t1 + t2;
 }





More information about the cfe-commits mailing list