diff options
author | Gabor Greif <ggreif@gmail.com> | 2009-03-12 18:34:49 +0000 |
---|---|---|
committer | Gabor Greif <ggreif@gmail.com> | 2009-03-12 18:34:49 +0000 |
commit | ae5a20a9177650525b40ed88c8326a398e6caa8a (patch) | |
tree | a9a55d209febc8db93b45efd3be22850d744366b /include | |
parent | a065200eaf71248133470caf03eefea449fff7b4 (diff) | |
download | llvm-ae5a20a9177650525b40ed88c8326a398e6caa8a.tar.gz llvm-ae5a20a9177650525b40ed88c8326a398e6caa8a.tar.bz2 llvm-ae5a20a9177650525b40ed88c8326a398e6caa8a.tar.xz |
Rearrange operands of the BranchInst, to be able to
access each with a fixed negative index from op_end().
This has two important implications:
- getUser() will work faster, because there are less iterations
for the waymarking algorithm to perform. This is important
when running various analyses that want to determine callers
of basic blocks.
- getSuccessor() now runs faster, because the indirection via OperandList
is not necessary: Uses corresponding to the successors are at fixed
offset to "this".
The price we pay is the slightly more complicated logic in the operator
User::delete, as it has to pick up the information whether it has to free
the memory of an original unconditional BranchInst or a BranchInst that
was originally conditional, but has been shortened to unconditional.
I was not able to come up with a nicer solution to this problem. (And
rest assured, I tried *a lot*).
Similar reorderings will follow for InvokeInst and CallInst. After that
some optimizations to pred_iterator and CallSite will fall out naturally.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66815 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Instructions.h | 35 | ||||
-rw-r--r-- | include/llvm/Use.h | 2 | ||||
-rw-r--r-- | include/llvm/User.h | 4 |
3 files changed, 20 insertions, 21 deletions
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 535333a9f5..4821155e46 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -2117,8 +2117,9 @@ DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value) /// class BranchInst : public TerminatorInst { /// Ops list - Branches are strange. The operands are ordered: - /// TrueDest, FalseDest, Cond. This makes some accessors faster because - /// they don't have to check for cond/uncond branchness. + /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because + /// they don't have to check for cond/uncond branchness. These are mostly + /// accessed relative from op_end(). BranchInst(const BranchInst &BI); void AssertOK(); // BranchInst constructors (where {B, T, F} are blocks, and C is a condition): @@ -2136,24 +2137,21 @@ class BranchInst : public TerminatorInst { BasicBlock *InsertAtEnd); public: static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) { - return new(1) BranchInst(IfTrue, InsertBefore); + return new(1, true) BranchInst(IfTrue, InsertBefore); } static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, Instruction *InsertBefore = 0) { return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore); } static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) { - return new(1) BranchInst(IfTrue, InsertAtEnd); + return new(1, true) BranchInst(IfTrue, InsertAtEnd); } static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, BasicBlock *InsertAtEnd) { return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd); } - ~BranchInst() { - if (NumOperands == 1) - NumOperands = (unsigned)((Use*)this - OperandList); - } + ~BranchInst(); /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); @@ -2165,23 +2163,24 @@ public: Value *getCondition() const { assert(isConditional() && "Cannot get condition of an uncond branch!"); - return getOperand(2); + return Op<-3>(); } void setCondition(Value *V) { assert(isConditional() && "Cannot set condition of unconditional branch!"); - setOperand(2, V); + Op<-3>() = V; } // setUnconditionalDest - Change the current branch to an unconditional branch // targeting the specified block. // FIXME: Eliminate this ugly method. void setUnconditionalDest(BasicBlock *Dest) { - Op<0>() = Dest; + Op<-1>() = Dest; if (isConditional()) { // Convert this to an uncond branch. - Op<1>().set(0); - Op<2>().set(0); + Op<-2>() = 0; + Op<-3>() = 0; NumOperands = 1; + OperandList = op_begin(); } } @@ -2189,12 +2188,12 @@ public: BasicBlock *getSuccessor(unsigned i) const { assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); - return cast_or_null<BasicBlock>(getOperand(i)); + return cast_or_null<BasicBlock>((&Op<-1>() - i)->get()); } void setSuccessor(unsigned idx, BasicBlock *NewSucc) { assert(idx < getNumSuccessors() && "Successor # out of range for Branch!"); - setOperand(idx, NewSucc); + *(&Op<-1>() - idx) = NewSucc; } // Methods for support type inquiry through isa, cast, and dyn_cast: @@ -2212,11 +2211,7 @@ private: }; template <> -struct OperandTraits<BranchInst> : HungoffOperandTraits<> { - // we need to access operands via OperandList, since - // the NumOperands may change from 3 to 1 - static inline void *allocate(unsigned); // FIXME -}; +struct OperandTraits<BranchInst> : VariadicOperandTraits<1> {}; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value) diff --git a/include/llvm/Use.h b/include/llvm/Use.h index a2774c802f..cde4366a5a 100644 --- a/include/llvm/Use.h +++ b/include/llvm/Use.h @@ -92,6 +92,8 @@ public: /// a User changes. static void zap(Use *Start, const Use *Stop, bool del = false); + /// getPrefix - Return deletable pointer if appropriate + Use *getPrefix(); private: const Use* getImpliedUser() const; static Use *initTags(Use *Start, Use *Stop, ptrdiff_t Done = 0); diff --git a/include/llvm/User.h b/include/llvm/User.h index 1a88ce0cce..69826c0d8c 100644 --- a/include/llvm/User.h +++ b/include/llvm/User.h @@ -62,6 +62,7 @@ protected: unsigned NumOperands; 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) : Value(ty, vty), OperandList(OpList), NumOperands(NumOps) {} Use *allocHungoffUses(unsigned) const; @@ -74,7 +75,8 @@ protected: } public: ~User() { - Use::zap(OperandList, OperandList + NumOperands); + if ((intptr_t(OperandList) & 1) == 0) + Use::zap(OperandList, OperandList + NumOperands); } /// operator delete - free memory allocated for User and Use objects void operator delete(void *Usr); |