summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-02-13 03:48:38 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-02-13 03:48:38 +0000
commit8c86375a10fb569709f2fc3ef1d58d3eac221d74 (patch)
treee67043f02257bc17440ffce529e0b56204dffe20 /llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
parent8e19879f5a81c7a14ad9bdf77f495448f8c76a1c (diff)
downloadbcm5719-llvm-8c86375a10fb569709f2fc3ef1d58d3eac221d74.tar.gz
bcm5719-llvm-8c86375a10fb569709f2fc3ef1d58d3eac221d74.zip
[unroll] Use a small set to de-duplicate operands prior to putting them
into the worklist. This avoids allocating lots of worklist memory for them when there are large numbers of repeated operands. llvm-svn: 229052
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index bffaec01336..e4771dbc89b 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -503,6 +503,12 @@ public:
SmallVector<Instruction *, 8> Worklist;
SmallPtrSet<Instruction *, 16> DeadInstructions;
+ // We keep a very small set of operands that we use to de-duplicate things
+ // when inserting into the worklist. This lets us handle duplicates within
+ // a single instruction's operands without buring lots of memory on the
+ // worklist.
+ SmallPtrSet<Instruction *, 4> OperandSet;
+
// Start by initializing worklist with simplified instructions.
for (auto &FoldedKeyValue : SimplifiedValues)
if (auto *FoldedInst = dyn_cast<Instruction>(FoldedKeyValue.first)) {
@@ -510,9 +516,11 @@ public:
// Add each instruction operand of this dead instruction to the
// worklist.
+ OperandSet.clear();
for (auto *Op : FoldedInst->operand_values())
if (auto *OpI = dyn_cast<Instruction>(Op))
- Worklist.push_back(OpI);
+ if (OperandSet.insert(OpI).second)
+ Worklist.push_back(OpI);
}
// If a definition of an insn is only used by simplified or dead
@@ -537,9 +545,11 @@ public:
if (AllUsersFolded) {
NumberOfOptimizedInstructions += TTI.getUserCost(I);
DeadInstructions.insert(I);
+ OperandSet.clear();
for (auto *Op : I->operand_values())
if (auto *OpI = dyn_cast<Instruction>(Op))
- Worklist.push_back(OpI);
+ if (OperandSet.insert(OpI).second)
+ Worklist.push_back(OpI);
}
}
return NumberOfOptimizedInstructions;
OpenPOWER on IntegriCloud