[llvm] r239489 - Move the special Phi logic for hung off uses in to User::allocHungOffUses. NFC.
Pete Cooper
peter_cooper at apple.com
Wed Jun 10 15:38:31 PDT 2015
Author: pete
Date: Wed Jun 10 17:38:30 2015
New Revision: 239489
URL: http://llvm.org/viewvc/llvm-project?rev=239489&view=rev
Log:
Move the special Phi logic for hung off uses in to User::allocHungOffUses. NFC.
PhiNode's need to allocate space for an array of Use[N] and then BasicBlock*[N].
They had their own allocHungOffUses to handle all of this. This moves the logic
in to User::allocHungOffUses and PhiNode passes in a bool to say to allocate
the BB* space too.
Reviewed by Duncan Exon Smith.
Modified:
llvm/trunk/include/llvm/IR/Instructions.h
llvm/trunk/include/llvm/IR/User.h
llvm/trunk/lib/IR/Instructions.cpp
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=239489&r1=239488&r2=239489&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instructions.h (original)
+++ llvm/trunk/include/llvm/IR/Instructions.h Wed Jun 10 17:38:30 2015
@@ -2248,7 +2248,9 @@ 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) const;
+ Use *allocHungoffUses(unsigned N) const {
+ return User::allocHungoffUses(N, /* IsPhi */ true);
+ }
PHINode *clone_impl() const override;
public:
Modified: llvm/trunk/include/llvm/IR/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/User.h?rev=239489&r1=239488&r2=239489&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/User.h (original)
+++ llvm/trunk/include/llvm/IR/User.h Wed Jun 10 17:38:30 2015
@@ -52,7 +52,12 @@ protected:
: Value(ty, vty), OperandList(OpList) {
NumOperands = NumOps;
}
- Use *allocHungoffUses(unsigned) const;
+
+ /// \brief Allocate the array of Uses, followed by a pointer
+ /// (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;
void dropHungoffUses() {
Use::zap(OperandList, OperandList + NumOperands, true);
OperandList = nullptr;
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=239489&r1=239488&r2=239489&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Wed Jun 10 17:38:30 2015
@@ -97,18 +97,6 @@ PHINode::~PHINode() {
dropHungoffUses();
}
-Use *PHINode::allocHungoffUses(unsigned N) const {
- // Allocate the array of Uses of the incoming values, followed by a pointer
- // (with bottom bit set) to the User, followed by the array of pointers to
- // the incoming basic blocks.
- size_t size = N * sizeof(Use) + sizeof(Use::UserRef)
- + N * sizeof(BasicBlock*);
- Use *Begin = static_cast<Use*>(::operator new(size));
- Use *End = Begin + N;
- (void) new(End) Use::UserRef(const_cast<PHINode*>(this), 1);
- return Use::initTags(Begin, End);
-}
-
// removeIncomingValue - Remove an incoming value. This is useful if a
// predecessor basic block is deleted.
Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
Modified: llvm/trunk/lib/IR/User.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/User.cpp?rev=239489&r1=239488&r2=239489&view=diff
==============================================================================
--- llvm/trunk/lib/IR/User.cpp (original)
+++ llvm/trunk/lib/IR/User.cpp Wed Jun 10 17:38:30 2015
@@ -13,6 +13,7 @@
#include "llvm/IR/Operator.h"
namespace llvm {
+class BasicBlock;
//===----------------------------------------------------------------------===//
// User Class
@@ -39,10 +40,12 @@ void User::replaceUsesOfWith(Value *From
// User allocHungoffUses Implementation
//===----------------------------------------------------------------------===//
-Use *User::allocHungoffUses(unsigned N) const {
+Use *User::allocHungoffUses(unsigned N, bool IsPhi) const {
// 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);
More information about the llvm-commits
mailing list