[cfe-commits] r133924 - in /cfe/trunk/include/clang: AST/Type.h Basic/TargetInfo.h

Douglas Gregor dgregor at apple.com
Mon Jun 27 11:45:19 PDT 2011


Author: dgregor
Date: Mon Jun 27 13:45:19 2011
New Revision: 133924

URL: http://llvm.org/viewvc/llvm-project?rev=133924&view=rev
Log:
Reduce the size of the ExtInfo bitfield in FunctionType from 9 bits
down to 8 by restricting the maximum allowed regparm value to 6
(previously it was 7). I need the extra bit in Type to handle
instantiation-dependence.

Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/include/clang/Basic/TargetInfo.h

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=133924&r1=133923&r2=133924&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jun 27 13:45:19 2011
@@ -1139,7 +1139,7 @@
 
     /// Extra information which affects how the function is called, like
     /// regparm and the calling convention.
-    unsigned ExtInfo : 9;
+    unsigned ExtInfo : 8;
 
     /// Whether the function is variadic.  Only used by FunctionProtoType.
     unsigned Variadic : 1;
@@ -2474,18 +2474,19 @@
   // * AST read and write
   // * Codegen
   class ExtInfo {
-    // Feel free to rearrange or add bits, but if you go over 9,
+    // Feel free to rearrange or add bits, but if you go over 8,
     // you'll need to adjust both the Bits field below and
     // Type::FunctionTypeBitfields.
 
-    //   |  CC  |noreturn|produces|hasregparm|regparm
-    //   |0 .. 2|   3    |    4   |    5     |6 ..  8
+    //   |  CC  |noreturn|produces|regparm|
+    //   |0 .. 2|   3    |    4   | 5 .. 7|
+    //
+    // regparm is either 0 (no regparm attribute) or the regparm value+1.
     enum { CallConvMask = 0x7 };
     enum { NoReturnMask = 0x8 };
     enum { ProducesResultMask = 0x10 };
-    enum { HasRegParmMask = 0x20 };
     enum { RegParmMask = ~(CallConvMask | NoReturnMask | ProducesResultMask),
-           RegParmOffset = 6 }; // Assumed to be the last field
+           RegParmOffset = 5 }; // Assumed to be the last field
 
     uint16_t Bits;
 
@@ -2498,11 +2499,11 @@
     // have all the elements (when reading an AST file for example).
     ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc,
             bool producesResult) {
+      assert((!hasRegParm || regParm < 7) && "Invalid regparm value");
       Bits = ((unsigned) cc) |
              (noReturn ? NoReturnMask : 0) |
              (producesResult ? ProducesResultMask : 0) |
-             (hasRegParm ? HasRegParmMask : 0) |
-             (regParm << RegParmOffset);
+             (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0);
     }
 
     // Constructor with all defaults. Use when for example creating a
@@ -2511,8 +2512,13 @@
 
     bool getNoReturn() const { return Bits & NoReturnMask; }
     bool getProducesResult() const { return Bits & ProducesResultMask; }
-    bool getHasRegParm() const { return Bits & HasRegParmMask; }
-    unsigned getRegParm() const { return Bits >> RegParmOffset; }
+    bool getHasRegParm() const { return (Bits >> RegParmOffset) != 0; }
+    unsigned getRegParm() const { 
+      unsigned RegParm = Bits >> RegParmOffset;
+      if (RegParm > 0)
+        --RegParm;
+      return RegParm;
+    }
     CallingConv getCC() const { return CallingConv(Bits & CallConvMask); }
 
     bool operator==(ExtInfo Other) const {
@@ -2540,9 +2546,9 @@
     }
 
     ExtInfo withRegParm(unsigned RegParm) const {
+      assert(RegParm < 7 && "Invalid regparm value");
       return ExtInfo((Bits & ~RegParmMask) |
-                     (HasRegParmMask) |
-                     (RegParm << RegParmOffset));
+                     ((RegParm + 1) << RegParmOffset));
     }
 
     ExtInfo withCallingConv(CallingConv cc) const {

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=133924&r1=133923&r2=133924&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Mon Jun 27 13:45:19 2011
@@ -524,6 +524,7 @@
 
   // getRegParmMax - Returns maximal number of args passed in registers.
   unsigned getRegParmMax() const {
+    assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
     return RegParmMax;
   }
 





More information about the cfe-commits mailing list