diff options
author | John McCall <rjmccall@apple.com> | 2010-09-15 10:14:12 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-09-15 10:14:12 +0000 |
commit | 558d2abc7f9fd6801cc7677200992313ae90b5d8 (patch) | |
tree | 7624495cd37a259daceff9065f500f9522cbd775 /lib/CodeGen/CGValue.h | |
parent | 8f3b834471b158d65d490e3458fa16ba659ec105 (diff) |
one piece of code is responsible for the lifetime of every aggregate
slot. The easiest way to do that was to bundle up the information
we care about for aggregate slots into a new structure which demands
that its creators at least consider the question.
I could probably be convinced that the ObjC 'needs GC' bit should
be rolled into this structure.
Implement generalized copy elision. The main obstacle here is that
IR-generation must be much more careful about making sure that exactly
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113962 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGValue.h')
-rw-r--r-- | lib/CodeGen/CGValue.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/CodeGen/CGValue.h b/lib/CodeGen/CGValue.h index f57ecd245f..42b8335ecd 100644 --- a/lib/CodeGen/CGValue.h +++ b/lib/CodeGen/CGValue.h @@ -321,6 +321,69 @@ public: } }; +/// An aggregate value slot. +class AggValueSlot { + /// The address and associated flags. + uintptr_t AddrAndFlags; + + static const uintptr_t VolatileFlag = 0x1; + static const uintptr_t LifetimeFlag = 0x2; + static const uintptr_t AddrMask = ~(VolatileFlag | LifetimeFlag); + +public: + /// ignored - Returns an aggregate value slot indicating that the + /// aggregate value is being ignored. + static AggValueSlot ignored() { + AggValueSlot AV; + AV.AddrAndFlags = 0; + return AV; + } + + /// forAddr - Make a slot for an aggregate value. + /// + /// \param Volatile - true if the slot should be volatile-initialized + /// \param LifetimeExternallyManaged - true if the slot's lifetime + /// is being externally managed; false if a destructor should be + /// registered for any temporaries evaluated into the slot + static AggValueSlot forAddr(llvm::Value *Addr, bool Volatile, + bool LifetimeExternallyManaged) { + AggValueSlot AV; + AV.AddrAndFlags = reinterpret_cast<uintptr_t>(Addr); + if (Volatile) AV.AddrAndFlags |= VolatileFlag; + if (LifetimeExternallyManaged) AV.AddrAndFlags |= LifetimeFlag; + return AV; + } + + static AggValueSlot forLValue(LValue LV, bool LifetimeExternallyManaged) { + return forAddr(LV.getAddress(), LV.isVolatileQualified(), + LifetimeExternallyManaged); + } + + bool isLifetimeExternallyManaged() const { + return AddrAndFlags & LifetimeFlag; + } + void setLifetimeExternallyManaged() { + AddrAndFlags |= LifetimeFlag; + } + + bool isVolatile() const { + return AddrAndFlags & VolatileFlag; + } + + llvm::Value *getAddr() const { + return reinterpret_cast<llvm::Value*>(AddrAndFlags & AddrMask); + } + + bool isIgnored() const { + return AddrAndFlags == 0; + } + + RValue asRValue() const { + return RValue::getAggregate(getAddr(), isVolatile()); + } + +}; + } // end namespace CodeGen } // end namespace clang |