mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-30 23:20:54 +00:00
0aae8ce09f
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239490 91177308-0d34-0410-b5e6-96231b3b80d8
96 lines
3.5 KiB
C++
96 lines
3.5 KiB
C++
//===-- User.cpp - Implement the User class -------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/IR/User.h"
|
|
#include "llvm/IR/Constant.h"
|
|
#include "llvm/IR/GlobalValue.h"
|
|
#include "llvm/IR/Operator.h"
|
|
|
|
namespace llvm {
|
|
class BasicBlock;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// User Class
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void User::anchor() {}
|
|
|
|
void User::replaceUsesOfWith(Value *From, Value *To) {
|
|
if (From == To) return; // Duh what?
|
|
|
|
assert((!isa<Constant>(this) || isa<GlobalValue>(this)) &&
|
|
"Cannot call User::replaceUsesOfWith on a constant!");
|
|
|
|
for (unsigned i = 0, E = getNumOperands(); i != E; ++i)
|
|
if (getOperand(i) == From) { // Is This operand is pointing to oldval?
|
|
// The side effects of this setOperand call include linking to
|
|
// "To", adding "this" to the uses list of To, and
|
|
// most importantly, removing "this" from the use list of "From".
|
|
setOperand(i, To); // Fix it now...
|
|
}
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// User allocHungoffUses Implementation
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
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);
|
|
if (IsPhi)
|
|
size += N * sizeof(BasicBlock *);
|
|
Use *Begin = static_cast<Use*>(::operator new(size));
|
|
Use *End = Begin + N;
|
|
(void) new(End) Use::UserRef(const_cast<User*>(this), 1);
|
|
Use *Uses = Use::initTags(Begin, End);
|
|
OperandList = Uses;
|
|
// Tag this operand list as being a hung off.
|
|
HasHungOffUses = true;
|
|
return Uses;
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// User operator new Implementations
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void *User::operator new(size_t s, unsigned Us) {
|
|
void *Storage = ::operator new(s + sizeof(Use) * Us);
|
|
Use *Start = static_cast<Use*>(Storage);
|
|
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;
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// User operator delete Implementation
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
void User::operator delete(void *Usr) {
|
|
User *Start = static_cast<User*>(Usr);
|
|
Use *Storage = static_cast<Use*>(Usr) - Start->NumOperands;
|
|
// If there were hung-off uses, they will have been freed already and
|
|
// NumOperands reset to 0, so here we just free the User itself.
|
|
::operator delete(Storage);
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Operator Class
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
Operator::~Operator() {
|
|
llvm_unreachable("should never destroy an Operator");
|
|
}
|
|
|
|
} // End llvm namespace
|