[llvm] r228550 - Metadata: Use <algorithm> to simplify code. NFC.
Benjamin Kramer
benny.kra at googlemail.com
Sun Feb 8 13:56:09 PST 2015
Author: d0k
Date: Sun Feb 8 15:56:09 2015
New Revision: 228550
URL: http://llvm.org/viewvc/llvm-project?rev=228550&view=rev
Log:
Metadata: Use <algorithm> to simplify code. NFC.
Modified:
llvm/trunk/lib/IR/Metadata.cpp
Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=228550&r1=228549&r2=228550&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Sun Feb 8 15:56:09 2015
@@ -84,8 +84,7 @@ MetadataAsValue *MetadataAsValue::getIfE
Metadata *MD) {
MD = canonicalizeMetadataForValue(Context, MD);
auto &Store = Context.pImpl->MetadataAsValues;
- auto I = Store.find(MD);
- return I == Store.end() ? nullptr : I->second;
+ return Store.lookup(MD);
}
void MetadataAsValue::handleChangedMetadata(Metadata *MD) {
@@ -439,8 +438,7 @@ static bool isOperandUnresolved(Metadata
unsigned MDNode::countUnresolvedOperands() {
assert(NumUnresolved == 0 && "Expected unresolved ops to be uncounted");
- for (const auto &Op : operands())
- NumUnresolved += unsigned(isOperandUnresolved(Op));
+ NumUnresolved = std::count_if(op_begin(), op_end(), isOperandUnresolved);
return NumUnresolved;
}
@@ -750,13 +748,10 @@ MDNode *MDNode::concatenate(MDNode *A, M
if (!B)
return A;
- SmallVector<Metadata *, 4> MDs(A->getNumOperands() + B->getNumOperands());
-
- unsigned j = 0;
- for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i)
- MDs[j++] = A->getOperand(i);
- for (unsigned i = 0, ie = B->getNumOperands(); i != ie; ++i)
- MDs[j++] = B->getOperand(i);
+ SmallVector<Metadata *, 4> MDs;
+ MDs.reserve(A->getNumOperands() + B->getNumOperands());
+ MDs.append(A->op_begin(), A->op_end());
+ MDs.append(B->op_begin(), B->op_end());
// FIXME: This preserves long-standing behaviour, but is it really the right
// behaviour? Or was that an unintended side-effect of node uniquing?
@@ -768,14 +763,9 @@ MDNode *MDNode::intersect(MDNode *A, MDN
return nullptr;
SmallVector<Metadata *, 4> MDs;
- for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i) {
- Metadata *MD = A->getOperand(i);
- for (unsigned j = 0, je = B->getNumOperands(); j != je; ++j)
- if (MD == B->getOperand(j)) {
- MDs.push_back(MD);
- break;
- }
- }
+ for (Metadata *MD : A->operands())
+ if (std::find(B->op_begin(), B->op_end(), MD) != B->op_end())
+ MDs.push_back(MD);
// FIXME: This preserves long-standing behaviour, but is it really the right
// behaviour? Or was that an unintended side-effect of node uniquing?
@@ -787,17 +777,9 @@ MDNode *MDNode::getMostGenericAliasScope
return nullptr;
SmallVector<Metadata *, 4> MDs(B->op_begin(), B->op_end());
- for (unsigned i = 0, ie = A->getNumOperands(); i != ie; ++i) {
- Metadata *MD = A->getOperand(i);
- bool insert = true;
- for (unsigned j = 0, je = B->getNumOperands(); j != je; ++j)
- if (MD == B->getOperand(j)) {
- insert = false;
- break;
- }
- if (insert)
- MDs.push_back(MD);
- }
+ for (Metadata *MD : A->operands())
+ if (std::find(B->op_begin(), B->op_end(), MD) == B->op_end())
+ MDs.push_back(MD);
// FIXME: This preserves long-standing behaviour, but is it really the right
// behaviour? Or was that an unintended side-effect of node uniquing?
More information about the llvm-commits
mailing list