mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-07-21 18:29:45 +00:00
Simplify the allocation and freeing of Users' operand lists, now that
every BranchInst has a fixed number of operands. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123027 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
43eaadeea5
commit
8e3914d12e
@ -2068,22 +2068,20 @@ protected:
|
|||||||
virtual BranchInst *clone_impl() const;
|
virtual BranchInst *clone_impl() const;
|
||||||
public:
|
public:
|
||||||
static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
|
static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
|
||||||
return new(1, true) BranchInst(IfTrue, InsertBefore);
|
return new(1) BranchInst(IfTrue, InsertBefore);
|
||||||
}
|
}
|
||||||
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
|
||||||
Value *Cond, Instruction *InsertBefore = 0) {
|
Value *Cond, Instruction *InsertBefore = 0) {
|
||||||
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
|
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
|
||||||
}
|
}
|
||||||
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
|
||||||
return new(1, true) BranchInst(IfTrue, InsertAtEnd);
|
return new(1) BranchInst(IfTrue, InsertAtEnd);
|
||||||
}
|
}
|
||||||
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
|
static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
|
||||||
Value *Cond, BasicBlock *InsertAtEnd) {
|
Value *Cond, BasicBlock *InsertAtEnd) {
|
||||||
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
|
return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
~BranchInst();
|
|
||||||
|
|
||||||
/// Transparently provide more efficient getOperand methods.
|
/// Transparently provide more efficient getOperand methods.
|
||||||
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
|
||||||
|
|
||||||
|
@ -112,8 +112,6 @@ public:
|
|||||||
/// a User changes.
|
/// a User changes.
|
||||||
static void zap(Use *Start, const Use *Stop, bool del = false);
|
static void zap(Use *Start, const Use *Stop, bool del = false);
|
||||||
|
|
||||||
/// getPrefix - Return deletable pointer if appropriate
|
|
||||||
Use *getPrefix();
|
|
||||||
private:
|
private:
|
||||||
const Use* getImpliedUser() const;
|
const Use* getImpliedUser() const;
|
||||||
static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0);
|
static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0);
|
||||||
|
@ -61,7 +61,6 @@ protected:
|
|||||||
unsigned NumOperands;
|
unsigned NumOperands;
|
||||||
|
|
||||||
void *operator new(size_t s, unsigned Us);
|
void *operator new(size_t s, unsigned Us);
|
||||||
void *operator new(size_t s, unsigned Us, bool Prefix);
|
|
||||||
User(const Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
|
User(const Type *ty, unsigned vty, Use *OpList, unsigned NumOps)
|
||||||
: Value(ty, vty), OperandList(OpList), NumOperands(NumOps) {}
|
: Value(ty, vty), OperandList(OpList), NumOperands(NumOps) {}
|
||||||
Use *allocHungoffUses(unsigned) const;
|
Use *allocHungoffUses(unsigned) const;
|
||||||
@ -74,8 +73,7 @@ protected:
|
|||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
~User() {
|
~User() {
|
||||||
if ((intptr_t(OperandList) & 1) == 0)
|
Use::zap(OperandList, OperandList + NumOperands);
|
||||||
Use::zap(OperandList, OperandList + NumOperands);
|
|
||||||
}
|
}
|
||||||
/// operator delete - free memory allocated for User and Use objects
|
/// operator delete - free memory allocated for User and Use objects
|
||||||
void operator delete(void *Usr);
|
void operator delete(void *Usr);
|
||||||
|
@ -730,31 +730,6 @@ BranchInst::BranchInst(const BranchInst &BI) :
|
|||||||
SubclassOptionalData = BI.SubclassOptionalData;
|
SubclassOptionalData = BI.SubclassOptionalData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Use* Use::getPrefix() {
|
|
||||||
PointerIntPair<Use**, 2, PrevPtrTag> &PotentialPrefix(this[-1].Prev);
|
|
||||||
if (PotentialPrefix.getOpaqueValue())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return reinterpret_cast<Use*>((char*)&PotentialPrefix + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
BranchInst::~BranchInst() {
|
|
||||||
if (NumOperands == 1) {
|
|
||||||
if (Use *Prefix = OperandList->getPrefix()) {
|
|
||||||
Op<-1>() = 0;
|
|
||||||
//
|
|
||||||
// mark OperandList to have a special value for scrutiny
|
|
||||||
// by baseclass destructors and operator delete
|
|
||||||
OperandList = Prefix;
|
|
||||||
} else {
|
|
||||||
NumOperands = 3;
|
|
||||||
OperandList = op_begin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BasicBlock *BranchInst::getSuccessorV(unsigned idx) const {
|
BasicBlock *BranchInst::getSuccessorV(unsigned idx) const {
|
||||||
return getSuccessor(idx);
|
return getSuccessor(idx);
|
||||||
}
|
}
|
||||||
@ -3329,8 +3304,7 @@ ReturnInst *ReturnInst::clone_impl() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BranchInst *BranchInst::clone_impl() const {
|
BranchInst *BranchInst::clone_impl() const {
|
||||||
unsigned Ops(getNumOperands());
|
return new(getNumOperands()) BranchInst(*this);
|
||||||
return new(Ops, Ops == 1) BranchInst(*this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitchInst *SwitchInst::clone_impl() const {
|
SwitchInst *SwitchInst::clone_impl() const {
|
||||||
|
@ -191,31 +191,6 @@ void *User::operator new(size_t s, unsigned Us) {
|
|||||||
return Obj;
|
return Obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prefixed allocation - just before the first Use, allocate a NULL pointer.
|
|
||||||
/// The destructor can detect its presence and readjust the OperandList
|
|
||||||
/// for deletition.
|
|
||||||
///
|
|
||||||
void *User::operator new(size_t s, unsigned Us, bool Prefix) {
|
|
||||||
// currently prefixed allocation only admissible for
|
|
||||||
// unconditional branch instructions
|
|
||||||
if (!Prefix)
|
|
||||||
return operator new(s, Us);
|
|
||||||
|
|
||||||
assert(Us == 1 && "Other than one Use allocated?");
|
|
||||||
typedef PointerIntPair<void*, 2, Use::PrevPtrTag> TaggedPrefix;
|
|
||||||
void *Raw = ::operator new(s + sizeof(TaggedPrefix) + sizeof(Use) * Us);
|
|
||||||
TaggedPrefix *Pre = static_cast<TaggedPrefix*>(Raw);
|
|
||||||
Pre->setFromOpaqueValue(0);
|
|
||||||
void *Storage = Pre + 1; // skip over prefix
|
|
||||||
Use *Start = static_cast<Use*>(Storage);
|
|
||||||
Use *End = Start + Us;
|
|
||||||
User *Obj = reinterpret_cast<User*>(End);
|
|
||||||
Obj->OperandList = Start;
|
|
||||||
Obj->NumOperands = Us;
|
|
||||||
Use::initTags(Start, End);
|
|
||||||
return Obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// User operator delete Implementation
|
// User operator delete Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -230,14 +205,6 @@ void User::operator delete(void *Usr) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// check for the flag whether the destructor has detected a prefixed
|
|
||||||
// allocation, in which case we remove the flag and delete starting
|
|
||||||
// at OperandList
|
|
||||||
if (reinterpret_cast<intptr_t>(Start->OperandList) & 1) {
|
|
||||||
::operator delete(reinterpret_cast<char*>(Start->OperandList) - 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// in all other cases just delete the nullary User (covers hung-off
|
// in all other cases just delete the nullary User (covers hung-off
|
||||||
// uses also
|
// uses also
|
||||||
::operator delete(Usr);
|
::operator delete(Usr);
|
||||||
|
Loading…
Reference in New Issue
Block a user