summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2015-06-10 22:38:41 +0000
committerPete Cooper <peter_cooper@apple.com>2015-06-10 22:38:41 +0000
commit93f9ff5781978963f2252ec36d402a1ef23a0500 (patch)
treee1b7772496c018cfd705ee657bbb7cd48fd8099d /llvm
parent178dcc29382d8bbe96467d4fca03d16c858496d3 (diff)
downloadbcm5719-llvm-93f9ff5781978963f2252ec36d402a1ef23a0500.tar.gz
bcm5719-llvm-93f9ff5781978963f2252ec36d402a1ef23a0500.zip
Add User::growHungoffUses and use it to grow the hung off uses. NFC.
PhiNode, SwitchInst, LandingPad and IndirectBr all had virtually identical logic for growing the hung off uses. Move it to User so that they can all call a single shared implementation. Their destructors were all empty after this change and were deleted. They all have virtual clone_impl methods which can be used as vtable anchors. Reviewed by Duncan Exon Smith. llvm-svn: 239492
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/IR/User.h5
-rw-r--r--llvm/lib/IR/Instructions.cpp34
-rw-r--r--llvm/lib/IR/User.cpp27
3 files changed, 36 insertions, 30 deletions
diff --git a/llvm/include/llvm/IR/User.h b/llvm/include/llvm/IR/User.h
index b68dcf9cc24..998e93a6a94 100644
--- a/llvm/include/llvm/IR/User.h
+++ b/llvm/include/llvm/IR/User.h
@@ -58,6 +58,11 @@ protected:
/// \param IsPhi identifies callers which are phi nodes and which need
/// N BasicBlock* allocated along with N
Use *allocHungoffUses(unsigned N, bool IsPhi = false);
+
+ /// \brief Grow the number of hung off uses. Note that allocHungoffUses
+ /// should be called if there are no uses.
+ void growHungoffUses(unsigned N, bool IsPhi = false);
+
public:
~User() override {
// drop the hung off uses.
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 9c8f66c11de..5fb51156638 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -128,16 +128,8 @@ void PHINode::growOperands() {
unsigned NumOps = e + e / 2;
if (NumOps < 2) NumOps = 2; // 2 op PHI nodes are VERY common.
- Use *OldOps = op_begin();
- BasicBlock **OldBlocks = block_begin();
-
ReservedSpace = NumOps;
- OperandList = allocHungoffUses(ReservedSpace);
-
- std::copy(OldOps, OldOps + e, op_begin());
- std::copy(OldBlocks, OldBlocks + e, block_begin());
-
- Use::zap(OldOps, OldOps + e, true);
+ growHungoffUses(ReservedSpace, /* IsPhi */ true);
}
/// hasConstantValue - If the specified PHI node always merges together the same
@@ -218,14 +210,7 @@ void LandingPadInst::growOperands(unsigned Size) {
unsigned e = getNumOperands();
if (ReservedSpace >= e + Size) return;
ReservedSpace = (e + Size / 2) * 2;
-
- Use *NewOps = allocHungoffUses(ReservedSpace);
- Use *OldOps = OperandList;
- for (unsigned i = 0; i != e; ++i)
- NewOps[i] = OldOps[i];
-
- OperandList = NewOps;
- Use::zap(OldOps, OldOps + e, true);
+ growHungoffUses(ReservedSpace);
}
void LandingPadInst::addClause(Constant *Val) {
@@ -3363,13 +3348,7 @@ void SwitchInst::growOperands() {
unsigned NumOps = e*3;
ReservedSpace = NumOps;
- Use *NewOps = allocHungoffUses(NumOps);
- Use *OldOps = OperandList;
- for (unsigned i = 0; i != e; ++i) {
- NewOps[i] = OldOps[i];
- }
- OperandList = NewOps;
- Use::zap(OldOps, OldOps + e, true);
+ growHungoffUses(ReservedSpace);
}
@@ -3406,12 +3385,7 @@ void IndirectBrInst::growOperands() {
unsigned NumOps = e*2;
ReservedSpace = NumOps;
- Use *NewOps = allocHungoffUses(NumOps);
- Use *OldOps = OperandList;
- for (unsigned i = 0; i != e; ++i)
- NewOps[i] = OldOps[i];
- OperandList = NewOps;
- Use::zap(OldOps, OldOps + e, true);
+ growHungoffUses(ReservedSpace);
}
IndirectBrInst::IndirectBrInst(Value *Address, unsigned NumCases,
diff --git a/llvm/lib/IR/User.cpp b/llvm/lib/IR/User.cpp
index e5450946006..8035989f1dc 100644
--- a/llvm/lib/IR/User.cpp
+++ b/llvm/lib/IR/User.cpp
@@ -56,6 +56,33 @@ Use *User::allocHungoffUses(unsigned N, bool IsPhi) {
return Uses;
}
+void User::growHungoffUses(unsigned NewNumUses, bool IsPhi) {
+ assert(HasHungOffUses && "realloc must have hung off uses");
+
+ unsigned OldNumUses = getNumOperands();
+
+ // We don't support shrinking the number of uses. We wouldn't have enough
+ // space to copy the old uses in to the new space.
+ assert(NewNumUses > OldNumUses && "realloc must grow num uses");
+
+ Use *OldOps = OperandList;
+ allocHungoffUses(NewNumUses, IsPhi);
+ Use *NewOps = OperandList;
+
+ // Now copy from the old operands list to the new one.
+ std::copy(OldOps, OldOps + OldNumUses, NewOps);
+
+ // If this is a Phi, then we need to copy the BB pointers too.
+ if (IsPhi) {
+ auto *OldPtr =
+ reinterpret_cast<char *>(OldOps + OldNumUses) + sizeof(Use::UserRef);
+ auto *NewPtr =
+ reinterpret_cast<char *>(NewOps + NewNumUses) + sizeof(Use::UserRef);
+ std::copy(OldPtr, OldPtr + (OldNumUses * sizeof(BasicBlock *)), NewPtr);
+ }
+ Use::zap(OldOps, OldOps + OldNumUses, true);
+}
+
//===----------------------------------------------------------------------===//
// User operator new Implementations
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud