[cfe-commits] r79288 - /cfe/trunk/lib/CodeGen/TargetABIInfo.cpp

David Chisnall csdavec at swan.ac.uk
Mon Aug 17 16:08:21 PDT 2009


Author: theraven
Date: Mon Aug 17 18:08:21 2009
New Revision: 79288

URL: http://llvm.org/viewvc/llvm-project?rev=79288&view=rev
Log:
Changes to TargetABIInfo to (hopefully) select the correct calling convention.  This has been tested on FreeBSD, and now correctly generates GCC-compatible code for functions returning small structures.  Please test it on other platforms!


Modified:
    cfe/trunk/lib/CodeGen/TargetABIInfo.cpp

Modified: cfe/trunk/lib/CodeGen/TargetABIInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetABIInfo.cpp?rev=79288&r1=79287&r2=79288&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/TargetABIInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetABIInfo.cpp Mon Aug 17 18:08:21 2009
@@ -206,7 +206,8 @@
 /// X86_32ABIInfo - The X86-32 ABI information.
 class X86_32ABIInfo : public ABIInfo {
   ASTContext &Context;
-  bool IsDarwin;
+  bool IsDarwinVectorABI;
+  bool IsSmallStructInRegABI;
 
   static bool isRegisterSize(unsigned Size) {
     return (Size == 8 || Size == 16 || Size == 32 || Size == 64);
@@ -238,8 +239,9 @@
   virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
                                  CodeGenFunction &CGF) const;
 
-  X86_32ABIInfo(ASTContext &Context, bool d)
-    : ABIInfo(), Context(Context), IsDarwin(d) {}
+  X86_32ABIInfo(ASTContext &Context, bool d, bool p)
+    : ABIInfo(), Context(Context), IsDarwinVectorABI(d), 
+      IsSmallStructInRegABI(p) {}
 };
 }
 
@@ -300,7 +302,7 @@
     return ABIArgInfo::getIgnore();
   } else if (const VectorType *VT = RetTy->getAsVectorType()) {
     // On Darwin, some vectors are returned in registers.
-    if (IsDarwin) {
+    if (IsDarwinVectorABI) {
       uint64_t Size = Context.getTypeSize(RetTy);
 
       // 128-bit vectors are a special case; they are returned in
@@ -326,8 +328,8 @@
       if (RT->getDecl()->hasFlexibleArrayMember())
         return ABIArgInfo::getIndirect(0);
 
-    // Outside of Darwin, structs and unions are always indirect.
-    if (!IsDarwin && !RetTy->isAnyComplexType())
+    // If specified, structs and unions are always indirect.
+    if (!IsSmallStructInRegABI && !RetTy->isAnyComplexType())
       return ABIArgInfo::getIndirect(0);
 
     // Classify "single element" structs as their element type.
@@ -1524,9 +1526,16 @@
   const char *TargetPrefix = getContext().Target.getTargetPrefix();
   if (strcmp(TargetPrefix, "x86") == 0) {
     bool IsDarwin = strstr(getContext().Target.getTargetTriple(), "darwin");
+    bool isPPCStructReturnABI = IsDarwin ||
+       strstr(getContext().Target.getTargetTriple(), "cygwin") ||
+       strstr(getContext().Target.getTargetTriple(), "mingw") ||
+       strstr(getContext().Target.getTargetTriple(), "netware") ||
+       strstr(getContext().Target.getTargetTriple(), "freebsd") ||
+       strstr(getContext().Target.getTargetTriple(), "openbsd");
     switch (getContext().Target.getPointerWidth(0)) {
     case 32:
-      return *(TheABIInfo = new X86_32ABIInfo(Context, IsDarwin));
+      return *(TheABIInfo = 
+          new X86_32ABIInfo(Context, IsDarwin, isPPCStructReturnABI));
     case 64:
       return *(TheABIInfo = new X86_64ABIInfo());
     }





More information about the cfe-commits mailing list