Shrink the size of AllocationInst by using its SubclassData

field to store the alignment value instead of haing a
separate field.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48727 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-03-24 16:55:58 +00:00
parent 4c931fc6e2
commit 52837078c7
2 changed files with 13 additions and 10 deletions

View File

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

View File

@ -677,8 +677,8 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
unsigned Align, const std::string &Name, unsigned Align, const std::string &Name,
Instruction *InsertBefore) Instruction *InsertBefore)
: UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(ArraySize), : UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(ArraySize),
InsertBefore), Alignment(Align) { InsertBefore) {
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); setAlignment(Align);
assert(Ty != Type::VoidTy && "Cannot allocate void!"); assert(Ty != Type::VoidTy && "Cannot allocate void!");
setName(Name); setName(Name);
} }
@ -687,8 +687,8 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
unsigned Align, const std::string &Name, unsigned Align, const std::string &Name,
BasicBlock *InsertAtEnd) BasicBlock *InsertAtEnd)
: UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(ArraySize), : UnaryInstruction(PointerType::getUnqual(Ty), iTy, getAISize(ArraySize),
InsertAtEnd), Alignment(Align) { InsertAtEnd) {
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); setAlignment(Align);
assert(Ty != Type::VoidTy && "Cannot allocate void!"); assert(Ty != Type::VoidTy && "Cannot allocate void!");
setName(Name); setName(Name);
} }
@ -697,6 +697,12 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
AllocationInst::~AllocationInst() { 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 { bool AllocationInst::isArrayAllocation() const {
if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0))) if (ConstantInt *CI = dyn_cast<ConstantInt>(getOperand(0)))
return CI->getZExtValue() != 1; return CI->getZExtValue() != 1;