Move the IsVolatile and SVOffset fields into the MemSDNode base

class, and store IsVolatile and Alignment in a more compact form.
This makes AtomicSDNode slightly larger, but it shrinks LoadSDNode
and StoreSDNode, which are much more common and are the largest of
the SDNode subclasses. Also, this lets the isVolatile() and
getAlignment() accessors be non-virtual.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53361 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2008-07-09 21:23:02 +00:00
parent f2452c5f48
commit 492f276cbc
2 changed files with 28 additions and 28 deletions

View File

@ -1440,23 +1440,25 @@ private:
//! SrcValue - Memory location for alias analysis. //! SrcValue - Memory location for alias analysis.
const Value *SrcValue; const Value *SrcValue;
//! Alignment - Alignment of memory location in bytes. //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
unsigned Alignment; int SVOffset;
/// Flags - the low bit indicates whether this is a volatile reference;
/// the remainder is a log2 encoding of the alignment in bytes.
unsigned Flags;
public: public:
MemSDNode(unsigned Opc, SDVTList VTs, const Value *srcValue, MemSDNode(unsigned Opc, SDVTList VTs,
unsigned alignment) const Value *srcValue, int SVOff,
: SDNode(Opc, VTs), SrcValue(srcValue), Alignment(alignment) {} unsigned alignment, bool isvolatile);
virtual ~MemSDNode() {}
/// Returns alignment and volatility of the memory access /// Returns alignment and volatility of the memory access
unsigned getAlignment() const { return Alignment; } unsigned getAlignment() const { return (1u << (Flags >> 1)) >> 1; }
virtual bool isVolatile() const = 0; bool isVolatile() const { return Flags & 1; }
/// Returns the SrcValue and offset that describes the location of the access /// Returns the SrcValue and offset that describes the location of the access
const Value *getSrcValue() const { return SrcValue; } const Value *getSrcValue() const { return SrcValue; }
virtual int getSrcValueOffset() const = 0; int getSrcValueOffset() const { return SVOffset; }
/// getMemOperand - Return a MachineMemOperand object describing the memory /// getMemOperand - Return a MachineMemOperand object describing the memory
/// reference performed by operation. /// reference performed by operation.
@ -1499,7 +1501,8 @@ class AtomicSDNode : public MemSDNode {
AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
SDOperand Cmp, SDOperand Swp, const Value* SrcVal, SDOperand Cmp, SDOperand Swp, const Value* SrcVal,
unsigned Align=0) unsigned Align=0)
: MemSDNode(Opc, VTL, SrcVal, Align) { : MemSDNode(Opc, VTL, SrcVal, /*SVOffset=*/0,
Align, /*isVolatile=*/true) {
Ops[0] = Chain; Ops[0] = Chain;
Ops[1] = Ptr; Ops[1] = Ptr;
Ops[2] = Swp; Ops[2] = Swp;
@ -1508,7 +1511,8 @@ class AtomicSDNode : public MemSDNode {
} }
AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
SDOperand Val, const Value* SrcVal, unsigned Align=0) SDOperand Val, const Value* SrcVal, unsigned Align=0)
: MemSDNode(Opc, VTL, SrcVal, Align) { : MemSDNode(Opc, VTL, SrcVal, /*SVOffset=*/0,
Align, /*isVolatile=*/true) {
Ops[0] = Chain; Ops[0] = Chain;
Ops[1] = Ptr; Ops[1] = Ptr;
Ops[2] = Val; Ops[2] = Val;
@ -1521,10 +1525,6 @@ class AtomicSDNode : public MemSDNode {
bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_CMP_SWAP; } bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_CMP_SWAP; }
// Implementation for MemSDNode
virtual int getSrcValueOffset() const { return 0; }
virtual bool isVolatile() const { return true; }
/// getMemOperand - Return a MachineMemOperand object describing the memory /// getMemOperand - Return a MachineMemOperand object describing the memory
/// reference performed by this atomic load/store. /// reference performed by this atomic load/store.
virtual MachineMemOperand getMemOperand() const; virtual MachineMemOperand getMemOperand() const;
@ -2055,12 +2055,6 @@ private:
// MemoryVT - VT of in-memory value. // MemoryVT - VT of in-memory value.
MVT MemoryVT; MVT MemoryVT;
//! SVOffset - Memory location offset. Note that base is defined in MemSDNode
int SVOffset;
//! IsVolatile - True if the load/store is volatile.
bool IsVolatile;
protected: protected:
//! Operand array for load and store //! Operand array for load and store
/*! /*!
@ -2073,8 +2067,7 @@ public:
LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned numOperands, LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned numOperands,
SDVTList VTs, ISD::MemIndexedMode AM, MVT VT, SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
const Value *SV, int SVO, unsigned Align, bool Vol) const Value *SV, int SVO, unsigned Align, bool Vol)
: MemSDNode(NodeTy, VTs, SV, Align), AddrMode(AM), MemoryVT(VT), : MemSDNode(NodeTy, VTs, SV, SVO, Align, Vol), AddrMode(AM), MemoryVT(VT) {
SVOffset(SVO), IsVolatile(Vol) {
for (unsigned i = 0; i != numOperands; ++i) for (unsigned i = 0; i != numOperands; ++i)
Ops[i] = Operands[i]; Ops[i] = Operands[i];
InitOperands(Ops, numOperands); InitOperands(Ops, numOperands);
@ -2101,10 +2094,6 @@ public:
/// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store. /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; } bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
// Implementation for MemSDNode
virtual int getSrcValueOffset() const { return SVOffset; }
virtual bool isVolatile() const { return IsVolatile; }
/// getMemOperand - Return a MachineMemOperand object describing the memory /// getMemOperand - Return a MachineMemOperand object describing the memory
/// reference performed by this load or store. /// reference performed by this load or store.
virtual MachineMemOperand getMemOperand() const; virtual MachineMemOperand getMemOperand() const;

View File

@ -4331,6 +4331,17 @@ GlobalAddressSDNode::GlobalAddressSDNode(bool isTarget, const GlobalValue *GA,
TheGlobal = const_cast<GlobalValue*>(GA); TheGlobal = const_cast<GlobalValue*>(GA);
} }
MemSDNode::MemSDNode(unsigned Opc, SDVTList VTs,
const Value *srcValue, int SVO,
unsigned alignment, bool vol)
: SDNode(Opc, VTs), SrcValue(srcValue), SVOffset(SVO),
Flags(vol | ((Log2_32(alignment) + 1) << 1)) {
assert(isPowerOf2_32(alignment) && "Alignment is not a power of 2!");
assert(getAlignment() == alignment && "Alignment representation error!");
assert(isVolatile() == vol && "Volatile representation error!");
}
/// getMemOperand - Return a MachineMemOperand object describing the memory /// getMemOperand - Return a MachineMemOperand object describing the memory
/// reference performed by this atomic. /// reference performed by this atomic.
MachineMemOperand AtomicSDNode::getMemOperand() const { MachineMemOperand AtomicSDNode::getMemOperand() const {