aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/User.cpp
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/lib/IR/User.cpp
parent178dcc29382d8bbe96467d4fca03d16c858496d3 (diff)
downloadllvm-93f9ff5781978963f2252ec36d402a1ef23a0500.zip
llvm-93f9ff5781978963f2252ec36d402a1ef23a0500.tar.gz
llvm-93f9ff5781978963f2252ec36d402a1ef23a0500.tar.bz2
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/lib/IR/User.cpp')
-rw-r--r--llvm/lib/IR/User.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/IR/User.cpp b/llvm/lib/IR/User.cpp
index e545094..8035989 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
//===----------------------------------------------------------------------===//