aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-03-24 16:55:58 +0000
committerDan Gohman <gohman@apple.com>2008-03-24 16:55:58 +0000
commitf51704839e8a5c477379525c2d6dbab18b7e96ce (patch)
tree38f03b52ed39827af8d73afa9270ab117ef4b5fd
parent452b4ce4d8ec5ac79706f7811fc8f4405aaa650c (diff)
downloadexternal_llvm-f51704839e8a5c477379525c2d6dbab18b7e96ce.zip
external_llvm-f51704839e8a5c477379525c2d6dbab18b7e96ce.tar.gz
external_llvm-f51704839e8a5c477379525c2d6dbab18b7e96ce.tar.bz2
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
-rw-r--r--include/llvm/Instructions.h9
-rw-r--r--lib/VMCore/Instructions.cpp14
2 files changed, 13 insertions, 10 deletions
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h
index c80154c..2e234bd 100644
--- a/include/llvm/Instructions.h
+++ b/include/llvm/Instructions.h
@@ -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 @@ class APInt;
/// 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 @@ public:
/// 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;
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index df5a2fc..33ab1c6 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -677,8 +677,8 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
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 @@ AllocationInst::AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy,
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(const Type *Ty, Value *ArraySize, unsigned iTy,
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;