summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-08-19 02:24:46 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-08-19 02:24:46 +0000
commit687744d0114c46529def899ee6c67428cbdf3d92 (patch)
tree70fb98b95b1471239cd3a77a5ff0c6ddfe6bea6b
parentb11cd6fbc583be97371d9cc6d95eec70de074630 (diff)
downloadbcm5719-llvm-687744d0114c46529def899ee6c67428cbdf3d92.tar.gz
bcm5719-llvm-687744d0114c46529def899ee6c67428cbdf3d92.zip
IR: Reduce RAUW traffic in ConstantVector
Avoid creating a new `ConstantVector` on an RAUW of one of its members. This reduces RAUW traffic on any containing constant. This is part of PR20515. llvm-svn: 215966
-rw-r--r--llvm/lib/IR/Constants.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index c2c3c40df1c..cb7c9e63059 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -2810,17 +2810,41 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
void ConstantVector::replaceUsesOfWithOnConstant(Value *From, Value *To,
Use *U) {
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
+ Constant *ToC = cast<Constant>(To);
SmallVector<Constant*, 8> Values;
Values.reserve(getNumOperands()); // Build replacement array...
+ unsigned NumUpdated = 0;
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
Constant *Val = getOperand(i);
- if (Val == From) Val = cast<Constant>(To);
+ if (Val == From) {
+ ++NumUpdated;
+ Val = ToC;
+ }
Values.push_back(Val);
}
- Constant *Replacement = get(Values);
- replaceUsesOfWithOnConstantImpl(Replacement);
+ if (Constant *C = getImpl(Values)) {
+ replaceUsesOfWithOnConstantImpl(C);
+ return;
+ }
+
+ // Update to the new value. Optimize for the case when we have a single
+ // operand that we're changing, but handle bulk updates efficiently.
+ auto &pImpl = getType()->getContext().pImpl;
+ pImpl->VectorConstants.remove(this);
+
+ if (NumUpdated == 1) {
+ unsigned OperandToUpdate = U - OperandList;
+ assert(getOperand(OperandToUpdate) == From && "ReplaceAllUsesWith broken!");
+ setOperand(OperandToUpdate, ToC);
+ } else {
+ for (unsigned I = 0, E = getNumOperands(); I != E; ++I)
+ if (getOperand(I) == From)
+ setOperand(I, ToC);
+ }
+
+ pImpl->VectorConstants.insert(this);
}
void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV,
OpenPOWER on IntegriCloud