unroll analysis into a lambda and call it. That's much simpler than
duplicating all the code.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229053
91177308-0d34-0410-b5e6-
96231b3b80d8
// worklist.
SmallPtrSet<Instruction *, 4> OperandSet;
// worklist.
SmallPtrSet<Instruction *, 4> OperandSet;
+ // Lambda to enque operands onto the worklist.
+ auto EnqueueOperands = [&](Instruction &I) {
+ OperandSet.clear();
+ for (auto *Op : I.operand_values())
+ if (auto *OpI = dyn_cast<Instruction>(Op))
+ if (OperandSet.insert(OpI).second)
+ Worklist.push_back(OpI);
+ };
+
// Start by initializing worklist with simplified instructions.
for (auto &FoldedKeyValue : SimplifiedValues)
if (auto *FoldedInst = dyn_cast<Instruction>(FoldedKeyValue.first)) {
// Start by initializing worklist with simplified instructions.
for (auto &FoldedKeyValue : SimplifiedValues)
if (auto *FoldedInst = dyn_cast<Instruction>(FoldedKeyValue.first)) {
// Add each instruction operand of this dead instruction to the
// worklist.
// 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))
- if (OperandSet.insert(OpI).second)
- Worklist.push_back(OpI);
+ EnqueueOperands(*FoldedInst);
}
// If a definition of an insn is only used by simplified or dead
}
// If a definition of an insn is only used by simplified or dead
if (AllUsersFolded) {
NumberOfOptimizedInstructions += TTI.getUserCost(I);
DeadInstructions.insert(I);
if (AllUsersFolded) {
NumberOfOptimizedInstructions += TTI.getUserCost(I);
DeadInstructions.insert(I);
- OperandSet.clear();
- for (auto *Op : I->operand_values())
- if (auto *OpI = dyn_cast<Instruction>(Op))
- if (OperandSet.insert(OpI).second)
- Worklist.push_back(OpI);
}
}
return NumberOfOptimizedInstructions;
}
}
return NumberOfOptimizedInstructions;