From 29e00cf519d5861ac0aefa1c5f48ae10cf637dc5 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 13 Feb 2015 03:49:41 +0000 Subject: [PATCH] [unroll] Extract the code to enqueue operansd for the worklist in the 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 --- lib/Transforms/Scalar/LoopUnrollPass.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/Transforms/Scalar/LoopUnrollPass.cpp b/lib/Transforms/Scalar/LoopUnrollPass.cpp index e4771dbc89b..63d3cc6f628 100644 --- a/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -509,6 +509,15 @@ public: // worklist. SmallPtrSet 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(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(FoldedKeyValue.first)) { @@ -516,11 +525,7 @@ 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(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 @@ -545,11 +550,7 @@ public: if (AllUsersFolded) { NumberOfOptimizedInstructions += TTI.getUserCost(I); DeadInstructions.insert(I); - OperandSet.clear(); - for (auto *Op : I->operand_values()) - if (auto *OpI = dyn_cast(Op)) - if (OperandSet.insert(OpI).second) - Worklist.push_back(OpI); + EnqueueOperands(*I); } } return NumberOfOptimizedInstructions; -- 2.34.1