[llvm-commits] [llvm] r48727 - in /llvm/trunk: include/llvm/Instructions.h lib/VMCore/Instructions.cpp

Dan Gohman gohman at apple.com
Mon Mar 24 09:55:58 PDT 2008


Author: djg
Date: Mon Mar 24 11:55:58 2008
New Revision: 48727

URL: http://llvm.org/viewvc/llvm-project?rev=48727&view=rev
Log:
Shrink the size of AllocationInst by using its SubclassData
field to store the alignment value instead of haing a
separate field.

Modified:
    llvm/trunk/include/llvm/Instructions.h
    llvm/trunk/lib/VMCore/Instructions.cpp

Modified: llvm/trunk/include/llvm/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Instructions.h?rev=48727&r1=48726&r2=48727&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Instructions.h (original)
+++ llvm/trunk/include/llvm/Instructions.h Mon Mar 24 11:55:58 2008
@@ -21,6 +21,7 @@
 #include "llvm/InstrTypes.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/ParameterAttributes.h"
+#include "llvm/Support/MathExtras.h"
 
 namespace llvm {
 
@@ -39,7 +40,6 @@
 /// AllocaInst.
 ///
 class AllocationInst : public UnaryInstruction {
-  unsigned Alignment;
 protected:
   AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
                  const std::string &Name = "", Instruction *InsertBefore = 0);
@@ -74,11 +74,8 @@
   /// getAlignment - Return the alignment of the memory that is being allocated
   /// by the instruction.
   ///
-  unsigned getAlignment() const { return Alignment; }
-  void setAlignment(unsigned Align) {
-    assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
-    Alignment = Align;
-  }
+  unsigned getAlignment() const { return (1u << SubclassData) >> 1; }
+  void setAlignment(unsigned Align);
 
   virtual Instruction *clone() const = 0;
 

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=48727&r1=48726&r2=48727&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Mon Mar 24 11:55:58 2008
@@ -677,8 +677,8 @@
                                unsigned Align, const std::string &Name,
                                Instruction *InsertBefore)
   : UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(ArraySize),
-                     InsertBefore), Alignment(Align) {
-  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
+                     InsertBefore) {
+  setAlignment(Align);
   assert(Ty != Type::VoidTy && "Cannot allocate void!");
   setName(Name);
 }
@@ -687,8 +687,8 @@
                                unsigned Align, const std::string &Name,
                                BasicBlock *InsertAtEnd)
   : UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(ArraySize),
-                     InsertAtEnd), Alignment(Align) {
-  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
+                     InsertAtEnd) {
+  setAlignment(Align);
   assert(Ty != Type::VoidTy && "Cannot allocate void!");
   setName(Name);
 }
@@ -697,6 +697,12 @@
 AllocationInst::~AllocationInst() {
 }
 
+void AllocationInst::setAlignment(unsigned Align) {
+  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
+  SubclassData = Log2_32(Align) + 1;
+  assert(getAlignment() == Align && "Alignment representation error!");
+}
+
 bool AllocationInst::isArrayAllocation() const {
   if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0)))
     return CI->getZExtValue() != 1;





More information about the llvm-commits mailing list