Skip to content

Commit c6c0439

Browse files
committed
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. llvm-svn: 239490
1 parent 87b925b commit c6c0439

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ class PHINode : public Instruction {
22482248
// allocHungoffUses - this is more complicated than the generic
22492249
// User::allocHungoffUses, because we have to allocate Uses for the incoming
22502250
// values and pointers to the incoming blocks, all in one allocation.
2251-
Use *allocHungoffUses(unsigned N) const {
2251+
Use *allocHungoffUses(unsigned N) {
22522252
return User::allocHungoffUses(N, /* IsPhi */ true);
22532253
}
22542254

llvm/include/llvm/IR/User.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class User : public Value {
5757
/// (with bottom bit set) to the User.
5858
/// \param IsPhi identifies callers which are phi nodes and which need
5959
/// N BasicBlock* allocated along with N
60-
Use *allocHungoffUses(unsigned N, bool IsPhi = false) const;
60+
Use *allocHungoffUses(unsigned N, bool IsPhi = false);
6161
void dropHungoffUses() {
6262
Use::zap(OperandList, OperandList + NumOperands, true);
6363
OperandList = nullptr;

llvm/include/llvm/IR/Value.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ class Value {
100100
/// This is stored here to save space in User on 64-bit hosts. Since most
101101
/// instances of Value have operands, 32-bit hosts aren't significantly
102102
/// affected.
103-
unsigned NumOperands : 30;
103+
unsigned NumOperands : 29;
104104

105105
bool IsUsedByMD : 1;
106106
bool HasName : 1;
107+
bool HasHungOffUses : 1;
107108

108109
private:
109110
template <typename UseT> // UseT == 'Use' or 'const Use'

llvm/lib/IR/User.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void User::replaceUsesOfWith(Value *From, Value *To) {
4040
// User allocHungoffUses Implementation
4141
//===----------------------------------------------------------------------===//
4242

43-
Use *User::allocHungoffUses(unsigned N, bool IsPhi) const {
43+
Use *User::allocHungoffUses(unsigned N, bool IsPhi) {
4444
// Allocate the array of Uses, followed by a pointer (with bottom bit set) to
4545
// the User.
4646
size_t size = N * sizeof(Use) + sizeof(Use::UserRef);
@@ -49,7 +49,11 @@ Use *User::allocHungoffUses(unsigned N, bool IsPhi) const {
4949
Use *Begin = static_cast<Use*>(::operator new(size));
5050
Use *End = Begin + N;
5151
(void) new(End) Use::UserRef(const_cast<User*>(this), 1);
52-
return Use::initTags(Begin, End);
52+
Use *Uses = Use::initTags(Begin, End);
53+
OperandList = Uses;
54+
// Tag this operand list as being a hung off.
55+
HasHungOffUses = true;
56+
return Uses;
5357
}
5458

5559
//===----------------------------------------------------------------------===//
@@ -62,6 +66,7 @@ void *User::operator new(size_t s, unsigned Us) {
6266
Use *End = Start + Us;
6367
User *Obj = reinterpret_cast<User*>(End);
6468
Obj->OperandList = Start;
69+
Obj->HasHungOffUses = false;
6570
Obj->NumOperands = Us;
6671
Use::initTags(Start, End);
6772
return Obj;

0 commit comments

Comments
 (0)