r207894 - CodeGen: Cleanup ABIArgInfo

David Majnemer david.majnemer at gmail.com
Fri May 2 19:23:35 PDT 2014


Author: majnemer
Date: Fri May  2 21:23:35 2014
New Revision: 207894

URL: http://llvm.org/viewvc/llvm-project?rev=207894&view=rev
Log:
CodeGen: Cleanup ABIArgInfo

ABIArgInfo was pretty hard to grok, it had data members with names like
"BoolData0" and "UIntData".  Constructors with lots of bool arguments.
Reusing the same data member for multiple purposes.

It was also wasteful with memory, this new layout is 8 bytes smaller.

Modified:
    cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h

Modified: cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h?rev=207894&r1=207893&r2=207894&view=diff
==============================================================================
--- cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h (original)
+++ cfe/trunk/include/clang/CodeGen/CGFunctionInfo.h Fri May  2 21:23:35 2014
@@ -35,7 +35,7 @@ namespace CodeGen {
 /// specific C type should be passed to or returned from a function.
 class ABIArgInfo {
 public:
-  enum Kind {
+  enum Kind : uint8_t {
     /// Direct - Pass the argument directly using the normal converted LLVM
     /// type, or by coercing to another specified type stored in
     /// 'CoerceToType').  If an offset is specified (in UIntData), then the
@@ -68,65 +68,90 @@ public:
     /// type, it means the value is returned indirectly via an implicit sret
     /// parameter stored in the argument struct.
     InAlloca,
-
     KindFirst = Direct,
     KindLast = InAlloca
   };
 
 private:
-  Kind TheKind;
-  llvm::Type *TypeData;
+  llvm::Type *TypeData; // isDirect() || isExtend()
   llvm::Type *PaddingType;
-  unsigned UIntData;
-  bool BoolData0;
-  bool BoolData1;
-  bool InReg;
-  bool PaddingInReg;
-
-  ABIArgInfo(Kind K, llvm::Type *TD, unsigned UI, bool B0, bool B1, bool IR,
-             bool PIR, llvm::Type* P)
-    : TheKind(K), TypeData(TD), PaddingType(P), UIntData(UI), BoolData0(B0),
-      BoolData1(B1), InReg(IR), PaddingInReg(PIR) {}
+  union {
+    unsigned DirectOffset;     // isDirect() || isExtend()
+    unsigned IndirectAlign;    // isIndirect()
+    unsigned AllocaFieldIndex; // isInAlloca()
+  };
+  Kind TheKind;
+  bool PaddingInReg : 1;
+  bool InAllocaSRet : 1;    // isInAlloca
+  bool IndirectByVal : 1;   // isIndirect()
+  bool IndirectRealign : 1; // isIndirect()
+  bool InReg : 1;           // isDirect() || isExtend() || isIndirect()
 
-public:
-  ABIArgInfo() : TheKind(Direct), TypeData(0), UIntData(0) {}
+  ABIArgInfo(Kind K)
+      : PaddingType(nullptr), TheKind(K), PaddingInReg(false), InReg(false) {}
 
-  static ABIArgInfo getDirect(llvm::Type *T = 0, unsigned Offset = 0,
-                              llvm::Type *Padding = 0) {
-    return ABIArgInfo(Direct, T, Offset, false, false, false, false, Padding);
-  }
-  static ABIArgInfo getDirectInReg(llvm::Type *T = 0) {
-    return ABIArgInfo(Direct, T, 0, false, false, true, false, 0);
-  }
-  static ABIArgInfo getExtend(llvm::Type *T = 0) {
-    return ABIArgInfo(Extend, T, 0, false, false, false, false, 0);
-  }
-  static ABIArgInfo getExtendInReg(llvm::Type *T = 0) {
-    return ABIArgInfo(Extend, T, 0, false, false, true, false, 0);
+public:
+  ABIArgInfo()
+      : TypeData(nullptr), PaddingType(nullptr), DirectOffset(0),
+        TheKind(Direct), PaddingInReg(false), InReg(false) {}
+
+  static ABIArgInfo getDirect(llvm::Type *T = nullptr, unsigned Offset = 0,
+                              llvm::Type *Padding = nullptr) {
+    auto AI = ABIArgInfo(Direct);
+    AI.setCoerceToType(T);
+    AI.setDirectOffset(Offset);
+    AI.setPaddingType(Padding);
+    return AI;
+  }
+  static ABIArgInfo getDirectInReg(llvm::Type *T = nullptr) {
+    auto AI = getDirect(T);
+    AI.setInReg(true);
+    return AI;
+  }
+  static ABIArgInfo getExtend(llvm::Type *T = nullptr) {
+    auto AI = ABIArgInfo(Extend);
+    AI.setCoerceToType(T);
+    AI.setDirectOffset(0);
+    return AI;
+  }
+  static ABIArgInfo getExtendInReg(llvm::Type *T = nullptr) {
+    auto AI = getExtend(T);
+    AI.setInReg(true);
+    return AI;
   }
   static ABIArgInfo getIgnore() {
-    return ABIArgInfo(Ignore, 0, 0, false, false, false, false, 0);
+    return ABIArgInfo(Ignore);
   }
-  static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true
-                                , bool Realign = false
-                                , llvm::Type *Padding = 0) {
-    return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, false, false,
-                      Padding);
+  static ABIArgInfo getIndirect(unsigned Alignment, bool ByVal = true,
+                                bool Realign = false,
+                                llvm::Type *Padding = nullptr) {
+    auto AI = ABIArgInfo(Indirect);
+    AI.setIndirectAlign(Alignment);
+    AI.setIndirectByVal(ByVal);
+    AI.setIndirectRealign(Realign);
+    AI.setPaddingType(Padding);
+    return AI;
+  }
+  static ABIArgInfo getIndirectInReg(unsigned Alignment, bool ByVal = true,
+                                     bool Realign = false) {
+    auto AI = getIndirect(Alignment, ByVal, Realign);
+    AI.setInReg(true);
+    return AI;
   }
   static ABIArgInfo getInAlloca(unsigned FieldIndex) {
-    return ABIArgInfo(InAlloca, 0, FieldIndex, false, false, false, false, 0);
-  }
-  static ABIArgInfo getIndirectInReg(unsigned Alignment, bool ByVal = true
-                                , bool Realign = false) {
-    return ABIArgInfo(Indirect, 0, Alignment, ByVal, Realign, true, false, 0);
+    auto AI = ABIArgInfo(InAlloca);
+    AI.setInAllocaFieldIndex(FieldIndex);
+    return AI;
   }
   static ABIArgInfo getExpand() {
-    return ABIArgInfo(Expand, 0, 0, false, false, false, false, 0);
+    return ABIArgInfo(Expand);
   }
   static ABIArgInfo getExpandWithPadding(bool PaddingInReg,
                                          llvm::Type *Padding) {
-   return ABIArgInfo(Expand, 0, 0, false, false, false, PaddingInReg,
-                     Padding);
+    auto AI = getExpand();
+    AI.setPaddingInReg(PaddingInReg);
+    AI.setPaddingType(Padding);
+    return AI;
   }
 
   Kind getKind() const { return TheKind; }
@@ -137,27 +162,28 @@ public:
   bool isIndirect() const { return TheKind == Indirect; }
   bool isExpand() const { return TheKind == Expand; }
 
-  bool canHaveCoerceToType() const {
-    return TheKind == Direct || TheKind == Extend;
-  }
+  bool canHaveCoerceToType() const { return isDirect() || isExtend(); }
 
   // Direct/Extend accessors
   unsigned getDirectOffset() const {
     assert((isDirect() || isExtend()) && "Not a direct or extend kind");
-    return UIntData;
+    return DirectOffset;
   }
-
-  llvm::Type *getPaddingType() const {
-    return PaddingType;
+  void setDirectOffset(unsigned Offset) {
+    assert((isDirect() || isExtend()) && "Not a direct or extend kind");
+    DirectOffset = Offset;
   }
 
-  void setPaddingType(llvm::Type *T) {
-    PaddingType = T;
-  }
+  llvm::Type *getPaddingType() const { return PaddingType; }
+
+  void setPaddingType(llvm::Type *T) { PaddingType = T; }
 
   bool getPaddingInReg() const {
     return PaddingInReg;
   }
+  void setPaddingInReg(bool PIR) {
+    PaddingInReg = PIR;
+  }
 
   llvm::Type *getCoerceToType() const {
     assert(canHaveCoerceToType() && "Invalid kind!");
@@ -174,37 +200,58 @@ public:
     return InReg;
   }
 
+  void setInReg(bool IR) {
+    assert((isDirect() || isExtend() || isIndirect()) && "Invalid kind!");
+    InReg = IR;
+  }
+
   // Indirect accessors
   unsigned getIndirectAlign() const {
-    assert(TheKind == Indirect && "Invalid kind!");
-    return UIntData;
+    assert(isIndirect() && "Invalid kind!");
+    return IndirectAlign;
+  }
+  void setIndirectAlign(unsigned IA) {
+    assert(isIndirect() && "Invalid kind!");
+    IndirectAlign = IA;
   }
 
   bool getIndirectByVal() const {
-    assert(TheKind == Indirect && "Invalid kind!");
-    return BoolData0;
+    assert(isIndirect() && "Invalid kind!");
+    return IndirectByVal;
+  }
+  void setIndirectByVal(unsigned IBV) {
+    assert(isIndirect() && "Invalid kind!");
+    IndirectByVal = IBV;
   }
 
   bool getIndirectRealign() const {
-    assert(TheKind == Indirect && "Invalid kind!");
-    return BoolData1;
+    assert(isIndirect() && "Invalid kind!");
+    return IndirectRealign;
+  }
+  void setIndirectRealign(bool IR) {
+    assert(isIndirect() && "Invalid kind!");
+    IndirectRealign = IR;
   }
 
   unsigned getInAllocaFieldIndex() const {
-    assert(TheKind == InAlloca && "Invalid kind!");
-    return UIntData;
+    assert(isInAlloca() && "Invalid kind!");
+    return AllocaFieldIndex;
+  }
+  void setInAllocaFieldIndex(unsigned FieldIndex) {
+    assert(isInAlloca() && "Invalid kind!");
+    AllocaFieldIndex = FieldIndex;
   }
 
   /// \brief Return true if this field of an inalloca struct should be returned
   /// to implement a struct return calling convention.
   bool getInAllocaSRet() const {
-    assert(TheKind == InAlloca && "Invalid kind!");
-    return BoolData0;
+    assert(isInAlloca() && "Invalid kind!");
+    return InAllocaSRet;
   }
 
   void setInAllocaSRet(bool SRet) {
-    assert(TheKind == InAlloca && "Invalid kind!");
-    BoolData0 = SRet;
+    assert(isInAlloca() && "Invalid kind!");
+    InAllocaSRet = SRet;
   }
 
   void dump() const;





More information about the cfe-commits mailing list