[llvm] r267271 - ValueEnumerator: Use std::find_if, NFC
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 22 21:22:38 PDT 2016
Author: dexonsmith
Date: Fri Apr 22 23:22:38 2016
New Revision: 267271
URL: http://llvm.org/viewvc/llvm-project?rev=267271&view=rev
Log:
ValueEnumerator: Use std::find_if, NFC
Mehdi's pattern recognition pulled this one out. This is cleaner with
std::find_if than with the strange helper function that took an iterator
by reference and updated it.
Modified:
llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h
Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp?rev=267271&r1=267270&r2=267271&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.cpp Fri Apr 22 23:22:38 2016
@@ -575,11 +575,15 @@ void ValueEnumerator::EnumerateMetadata(
while (!Worklist.empty()) {
const MDNode *N = Worklist.back().first;
- MDNode::op_iterator &I = Worklist.back().second;
- // Enumerate operands until the worklist changes. We need to traverse new
- // nodes before visiting the rest of N's operands.
- if (const MDNode *Op = enumerateMetadataOperands(F, I, N->op_end())) {
+ // Enumerate operands until we hit a new node. We need to traverse these
+ // nodes' operands before visiting the rest of N's operands.
+ MDNode::op_iterator I = std::find_if(
+ Worklist.back().second, N->op_end(),
+ [&](const Metadata *MD) { return enumerateMetadataImpl(F, MD); });
+ if (I != N->op_end()) {
+ auto *Op = cast<MDNode>(*I);
+ Worklist.back().second = ++I;
Worklist.push_back(std::make_pair(Op, Op->op_begin()));
continue;
}
@@ -591,15 +595,6 @@ void ValueEnumerator::EnumerateMetadata(
}
}
-const MDNode *
-ValueEnumerator::enumerateMetadataOperands(unsigned F, MDNode::op_iterator &I,
- MDNode::op_iterator E) {
- while (I != E)
- if (const MDNode *N = enumerateMetadataImpl(F, *I++)) // Always increment I.
- return N;
- return nullptr;
-}
-
const MDNode *ValueEnumerator::enumerateMetadataImpl(unsigned F, const Metadata *MD) {
if (!MD)
return nullptr;
Modified: llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h?rev=267271&r1=267270&r2=267271&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h (original)
+++ llvm/trunk/lib/Bitcode/Writer/ValueEnumerator.h Fri Apr 22 23:22:38 2016
@@ -246,16 +246,6 @@ private:
/// function.
void incorporateFunctionMetadata(const Function &F);
- /// Enumerate operands with the given function tag.
- ///
- /// Enumerate the Metadata operands between \c I and \c E, returning the
- /// first newly-enumerated MDNode without assigning it an ID.
- ///
- /// \post If a node was found, \c I points just past the node.
- /// \post If no node was found, \c I is equal to \c E.
- const MDNode *enumerateMetadataOperands(unsigned F, const MDOperand *&I,
- const MDOperand *E);
-
/// Enumerate a single instance of metadata with the given function tag.
///
/// If \c MD has already been enumerated, check that \c F matches its
More information about the llvm-commits
mailing list