Skip to content

Commit

Permalink
Reorder Value and User fields to save 8 bytes of padding on 64-bit
Browse files Browse the repository at this point in the history
Reviewered by: rafael

Differential Revision: http://reviews.llvm.org/D4073

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210501 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rnk committed Jun 9, 2014
1 parent f31ecd3 commit 9de6eef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
10 changes: 5 additions & 5 deletions include/llvm/IR/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@ class User : public Value {
friend struct HungoffOperandTraits;
virtual void anchor();
protected:
/// NumOperands - The number of values used by this User.
///
unsigned NumOperands;

/// OperandList - This is a pointer to the array of Uses for this User.
/// For nodes of fixed arity (e.g. a binary operator) this array will live
/// prefixed to some derived class instance. For nodes of resizable variable
/// arity (e.g. PHINodes, SwitchInst etc.), this memory will be dynamically
/// allocated and should be destroyed by the classes' virtual dtor.
Use *OperandList;

/// NumOperands - The number of values used by this User.
///
unsigned NumOperands;

void *operator new(size_t s, unsigned Us);
User(Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
: Value(ty, vty), OperandList(OpList), NumOperands(NumOps) {}
: Value(ty, vty), NumOperands(NumOps), OperandList(OpList) {}
Use *allocHungoffUses(unsigned) const;
void dropHungoffUses() {
Use::zap(OperandList, OperandList + NumOperands, true);
Expand Down
24 changes: 12 additions & 12 deletions include/llvm/IR/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ typedef StringMapEntry<Value*> ValueName;
///
/// @brief LLVM Value Representation
class Value {
Type *VTy;
Use *UseList;

friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name.
friend class ValueHandleBase;
ValueName *Name;

const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast)
unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?
protected:
Expand All @@ -77,6 +84,11 @@ class Value {
unsigned char SubclassOptionalData : 7;

private:
/// SubclassData - This member is defined by this class, but is not used for
/// anything. Subclasses can use it to hold whatever state they find useful.
/// This field is initialized to zero by the ctor.
unsigned short SubclassData;

template <typename UseT> // UseT == 'Use' or 'const Use'
class use_iterator_impl
: public std::iterator<std::forward_iterator_tag, UseT *, ptrdiff_t> {
Expand Down Expand Up @@ -167,18 +179,6 @@ class Value {
unsigned getOperandNo() const { return UI->getOperandNo(); }
};

/// SubclassData - This member is defined by this class, but is not used for
/// anything. Subclasses can use it to hold whatever state they find useful.
/// This field is initialized to zero by the ctor.
unsigned short SubclassData;

Type *VTy;
Use *UseList;

friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name.
friend class ValueHandleBase;
ValueName *Name;

void operator=(const Value &) LLVM_DELETED_FUNCTION;
Value(const Value &) LLVM_DELETED_FUNCTION;

Expand Down
7 changes: 3 additions & 4 deletions lib/IR/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ using namespace llvm;

static inline Type *checkType(Type *Ty) {
assert(Ty && "Value defined with a null type: Error!");
return const_cast<Type*>(Ty);
return Ty;
}

Value::Value(Type *ty, unsigned scid)
: SubclassID(scid), HasValueHandle(0),
SubclassOptionalData(0), SubclassData(0), VTy((Type*)checkType(ty)),
UseList(nullptr), Name(nullptr) {
: VTy(checkType(ty)), UseList(nullptr), Name(nullptr), SubclassID(scid),
HasValueHandle(0), SubclassOptionalData(0), SubclassData(0) {
// FIXME: Why isn't this in the subclass gunk??
// Note, we cannot call isa<CallInst> before the CallInst has been
// constructed.
Expand Down

0 comments on commit 9de6eef

Please sign in to comment.