[llvm] r239490 - Make User track whether a class has 'hung off uses' and delete them in its destructor.
Pete Cooper
peter_cooper at apple.com
Wed Jun 10 15:38:34 PDT 2015
Author: pete
Date: Wed Jun 10 17:38:34 2015
New Revision: 239490
URL: http://llvm.org/viewvc/llvm-project?rev=239490&view=rev
Log:
Make User track whether a class has 'hung off uses' and delete them in its destructor.
Currently all of the logic for deleting hung off uses, which PHI/switch/etc use,
is in their classes.
This adds a bit to Value which tracks whether that user had hung off uses,
then User can be responsible for clearing them instead of the sub classes.
Note, the bit used here was taken from NumOperands which was 30-bits.
Given the reduction to 29 bits, and the average User being just over 100 bytes,
a single User with 29-bits of num operands would need 50GB of RAM for itself
so its reasonable to assume that 29-bits is enough for now.
This is a step towards hiding all the hung off uses logic in the User.
Reviewed by Duncan Exon Smith.
Modified:
llvm/trunk/include/llvm/IR/Instructions.h
llvm/trunk/include/llvm/IR/User.h
llvm/trunk/include/llvm/IR/Value.h
llvm/trunk/lib/IR/User.cpp
Modified: llvm/trunk/include/llvm/IR/Instructions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instructions.h?rev=239490&r1=239489&r2=239490&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instructions.h (original)
+++ llvm/trunk/include/llvm/IR/Instructions.h Wed Jun 10 17:38:34 2015
@@ -2248,7 +2248,7 @@ protected:
// allocHungoffUses - this is more complicated than the generic
// User::allocHungoffUses, because we have to allocate Uses for the incoming
// values and pointers to the incoming blocks, all in one allocation.
- Use *allocHungoffUses(unsigned N) const {
+ Use *allocHungoffUses(unsigned N) {
return User::allocHungoffUses(N, /* IsPhi */ true);
}
Modified: llvm/trunk/include/llvm/IR/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/User.h?rev=239490&r1=239489&r2=239490&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/User.h (original)
+++ llvm/trunk/include/llvm/IR/User.h Wed Jun 10 17:38:34 2015
@@ -57,7 +57,7 @@ protected:
/// (with bottom bit set) to the User.
/// \param IsPhi identifies callers which are phi nodes and which need
/// N BasicBlock* allocated along with N
- Use *allocHungoffUses(unsigned N, bool IsPhi = false) const;
+ Use *allocHungoffUses(unsigned N, bool IsPhi = false);
void dropHungoffUses() {
Use::zap(OperandList, OperandList + NumOperands, true);
OperandList = nullptr;
Modified: llvm/trunk/include/llvm/IR/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Value.h?rev=239490&r1=239489&r2=239490&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Value.h (original)
+++ llvm/trunk/include/llvm/IR/Value.h Wed Jun 10 17:38:34 2015
@@ -100,10 +100,11 @@ protected:
/// This is stored here to save space in User on 64-bit hosts. Since most
/// instances of Value have operands, 32-bit hosts aren't significantly
/// affected.
- unsigned NumOperands : 30;
+ unsigned NumOperands : 29;
bool IsUsedByMD : 1;
bool HasName : 1;
+ bool HasHungOffUses : 1;
private:
template <typename UseT> // UseT == 'Use' or 'const Use'
Modified: llvm/trunk/lib/IR/User.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/User.cpp?rev=239490&r1=239489&r2=239490&view=diff
==============================================================================
--- llvm/trunk/lib/IR/User.cpp (original)
+++ llvm/trunk/lib/IR/User.cpp Wed Jun 10 17:38:34 2015
@@ -40,7 +40,7 @@ void User::replaceUsesOfWith(Value *From
// User allocHungoffUses Implementation
//===----------------------------------------------------------------------===//
-Use *User::allocHungoffUses(unsigned N, bool IsPhi) const {
+Use *User::allocHungoffUses(unsigned N, bool IsPhi) {
// Allocate the array of Uses, followed by a pointer (with bottom bit set) to
// the User.
size_t size = N * sizeof(Use) + sizeof(Use::UserRef);
@@ -49,7 +49,11 @@ Use *User::allocHungoffUses(unsigned N,
Use *Begin = static_cast<Use*>(::operator new(size));
Use *End = Begin + N;
(void) new(End) Use::UserRef(const_cast<User*>(this), 1);
- return Use::initTags(Begin, End);
+ Use *Uses = Use::initTags(Begin, End);
+ OperandList = Uses;
+ // Tag this operand list as being a hung off.
+ HasHungOffUses = true;
+ return Uses;
}
//===----------------------------------------------------------------------===//
@@ -62,6 +66,7 @@ void *User::operator new(size_t s, unsig
Use *End = Start + Us;
User *Obj = reinterpret_cast<User*>(End);
Obj->OperandList = Start;
+ Obj->HasHungOffUses = false;
Obj->NumOperands = Us;
Use::initTags(Start, End);
return Obj;
More information about the llvm-commits
mailing list