[llvm-commits] [llvm-gcc-4.2] r95519 - in /llvm-gcc-4.2/trunk/gcc: llvm-abi-linux-ppc.cpp llvm-abi.h

Rafael Espindola rafael.espindola at gmail.com
Sun Feb 7 05:31:53 PST 2010


Author: rafael
Date: Sun Feb  7 07:31:53 2010
New Revision: 95519

URL: http://llvm.org/viewvc/llvm-project?rev=95519&view=rev
Log:
Drop the NumGPR field in SVR4ABI and replace it with a function to count
register use in ScalarElts.

Tested with the llvm test-suite. Committing as this affects ppc linux only.


Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-abi-linux-ppc.cpp
    llvm-gcc-4.2/trunk/gcc/llvm-abi.h

Modified: llvm-gcc-4.2/trunk/gcc/llvm-abi-linux-ppc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-abi-linux-ppc.cpp?rev=95519&r1=95518&r2=95519&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-abi-linux-ppc.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-abi-linux-ppc.cpp Sun Feb  7 07:31:53 2010
@@ -1,6 +1,6 @@
 #include "llvm-abi.h"
 
-SVR4ABI::SVR4ABI(DefaultABIClient &c) : NumGPR(0), C(c) {}
+SVR4ABI::SVR4ABI(DefaultABIClient &c) : C(c) {}
 
 bool SVR4ABI::isShadowReturn() const { return C.isShadowReturn(); }
 
@@ -56,6 +56,33 @@
   }
 }
 
+static unsigned count_num_registers_uses(std::vector<const Type*> &ScalarElts) {
+  unsigned NumGPRs = 0;
+  for (unsigned i = 0, e = ScalarElts.size(); i != e; ++i) {
+    if (NumGPRs >= 8)
+      break;
+    const Type *Ty = ScalarElts[i];
+    if (const VectorType *VTy = dyn_cast<VectorType>(Ty)) {
+      abort();
+    } else if (isa<PointerType>(Ty)) {
+      NumGPRs++;
+    } else if (Ty->isInteger()) {
+      unsigned TypeSize = Ty->getPrimitiveSizeInBits();
+      unsigned NumRegs = (TypeSize + 31) / 32;
+
+      NumGPRs += NumRegs;
+    } else if (Ty->isVoidTy()) {
+      // Padding bytes that are not passed anywhere
+      ;
+    } else {
+      // Floating point scalar argument.
+      assert(Ty->isFloatingPoint() && Ty->isPrimitiveType() &&
+             "Expecting a floating point primitive type!");
+    }
+  }
+  return NumGPRs < 8 ? NumGPRs : 8;
+}
+
 /// HandleArgument - This is invoked by the target-independent code for each
 /// argument type passed into the function.  It potentially breaks down the
 /// argument and invokes methods on the client that indicate how its pieces
@@ -72,6 +99,7 @@
   bool DontCheckAlignment = false;
   // Eight GPR's are availabe for parameter passing.
   const unsigned NumArgRegs = 8;
+  unsigned NumGPR = count_num_registers_uses(ScalarElts);
   const Type *Ty = ConvertType(type);
   // Figure out if this field is zero bits wide, e.g. {} or [0 x int].  Do
   // not include variable sized fields here.
@@ -86,16 +114,6 @@
     const Type *PtrTy = Ty->getPointerTo();
     C.HandleByInvisibleReferenceArgument(PtrTy, type);
     ScalarElts.push_back(PtrTy);
-
-    unsigned Attr = Attribute::None;
-
-    if (NumGPR < NumArgRegs) {
-      NumGPR++;
-    }
-
-    if (Attributes) {
-      *Attributes |= Attr;
-    }
   } else if (isa<VectorType>(Ty)) {
     if (LLVM_SHOULD_PASS_VECTOR_IN_INTEGER_REGS(type)) {
       PassInIntegerRegisters(type, ScalarElts, 0, false);
@@ -111,8 +129,6 @@
       ScalarElts.push_back(Ty);
     }
   } else if (Ty->isSingleValueType()) {
-    unsigned Attr = Attribute::None;
-
     if (Ty->isInteger()) {
       unsigned TypeSize = Ty->getPrimitiveSizeInBits();
 
@@ -124,30 +140,22 @@
       // a register pair which starts with an odd register number.
       if (TypeSize == 64 && (NumGPR % 2) == 1) {
 	NumGPR++;
+	ScalarElts.push_back(Int32Ty);
 	C.HandlePad(Int32Ty);
       }
 
-      if (NumGPR <= (NumArgRegs - NumRegs)) {
-	NumGPR += NumRegs;
-      } else {
-	for (unsigned int i = 0; i < NumArgRegs - NumGPR; ++i)
+      if (NumGPR > (NumArgRegs - NumRegs)) {
+	for (unsigned int i = 0; i < NumArgRegs - NumGPR; ++i) {
+	  ScalarElts.push_back(Int32Ty);
 	  C.HandlePad(Int32Ty);
-	NumGPR = NumArgRegs;
-      }
-    } else if (isa<PointerType>(Ty)) {
-      if (NumGPR < NumArgRegs) {
-	NumGPR++;
+	}
       }
-      // We don't care about arguments passed in Floating-point or vector
-      // registers.
-    } else if (!(Ty->isFloatingPoint() || isa<VectorType>(Ty))) {
+    } else if (!(Ty->isFloatingPoint() ||
+		 isa<VectorType>(Ty)   ||
+		 isa<PointerType>(Ty))) {
       abort();
     }
 
-    if (Attributes) {
-      *Attributes |= Attr;
-    }
-
     C.HandleScalarArgument(Ty, type);
     ScalarElts.push_back(Ty);
   } else if (LLVM_SHOULD_PASS_AGGREGATE_AS_FCA(type, Ty)) {
@@ -161,31 +169,27 @@
     // are _Complex aggregates.
     assert(TREE_CODE(type) == COMPLEX_TYPE && "Not a _Complex type!");
 
-    unsigned Attr = Attribute::None;
-
     switch (SrcSize) {
     default:
       abort();
       break;
     case 32:
       // _Complex long double
-      if (NumGPR == 0) {
-	NumGPR += NumArgRegs;
-      } else {
-	for (unsigned int i = 0; i < NumArgRegs - NumGPR; ++i)
+      if (NumGPR != 0) {
+	for (unsigned int i = 0; i < NumArgRegs - NumGPR; ++i) {
+	  ScalarElts.push_back(Int32Ty);
 	  C.HandlePad(Int32Ty);
-	NumGPR = NumArgRegs;
+	}
       }
       break;
     case 16:
       // _Complex long long
       // _Complex double
-      if (NumGPR <= (NumArgRegs - 4)) {
-	NumGPR += 4;
-      } else {
-	for (unsigned int i = 0; i < NumArgRegs - NumGPR; ++i)
+      if (NumGPR > (NumArgRegs - 4)) {
+	for (unsigned int i = 0; i < NumArgRegs - NumGPR; ++i) {
+	  ScalarElts.push_back(Int32Ty);
 	  C.HandlePad(Int32Ty);
-	NumGPR = NumArgRegs;
+	}
       }
       break;
     case 8:
@@ -197,30 +201,24 @@
       // a register pair which starts with an odd register number.
       if (NumGPR % 2 == 1) {
 	NumGPR++;
+	ScalarElts.push_back(Int32Ty);
+	C.HandlePad(Int32Ty);
       }
 
-      if (NumGPR <= (NumArgRegs - 2)) {
-	NumGPR += 2;
-      } else {
-	for (unsigned int i = 0; i < NumArgRegs - NumGPR; ++i)
+      if (NumGPR > (NumArgRegs - 2)) {
+	for (unsigned int i = 0; i < NumArgRegs - NumGPR; ++i) {
+	  ScalarElts.push_back(Int32Ty);
 	  C.HandlePad(Int32Ty);
-	NumGPR = NumArgRegs;
+	}
       }
       break;
     case 4:
     case 2:
       // _Complex short
       // _Complex char
-      if (NumGPR < NumArgRegs) {
-	NumGPR++;
-      }
       break;
     }
 
-    if (Attributes) {
-      *Attributes |= Attr;
-    }
-
     PassInMixedRegisters(Ty, Elts, ScalarElts);
   } else if (LLVM_SHOULD_PASS_AGGREGATE_USING_BYVAL_ATTR(type, Ty)) {
     C.HandleByValArgument(Ty, type);
@@ -229,16 +227,6 @@
       *Attributes |= 
 	Attribute::constructAlignmentFromInt(LLVM_BYVAL_ALIGNMENT(type));
     }
-
-    unsigned Attr = Attribute::None;
-
-    if (NumGPR < NumArgRegs) {
-      NumGPR++;
-    }
-
-    if (Attributes) {
-      *Attributes |= Attr;
-    }
   } else if (LLVM_SHOULD_PASS_AGGREGATE_IN_INTEGER_REGS(type, &Size,
 							&DontCheckAlignment)) {
     PassInIntegerRegisters(type, ScalarElts, Size, DontCheckAlignment);

Modified: llvm-gcc-4.2/trunk/gcc/llvm-abi.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-abi.h?rev=95519&r1=95518&r2=95519&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-abi.h (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-abi.h Sun Feb  7 07:31:53 2010
@@ -425,7 +425,6 @@
   // Number of general purpose argument registers which have already been
   // assigned.
 protected:
-  unsigned NumGPR;
   DefaultABIClient &C;
 public:
   SVR4ABI(DefaultABIClient &c);





More information about the llvm-commits mailing list