Skip to content

Commit 0550e93

Browse files
committed
[C++11] Remove the completely unnecessary requirement on SetVector's
remove_if that its predicate is adaptable. We don't actually need this, we can write a generic adapter for any predicate. This lets us remove some very wrong std::function usages. We should never be using std::function for predicates to algorithms. This incurs an *indirect* call overhead for every evaluation of the predicate, and makes it very hard to inline through. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202742 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6f8c0c0 commit 0550e93

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

include/llvm/ADT/SetVector.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,10 @@ class SetVector {
195195
set_type &set_;
196196

197197
public:
198-
typedef typename UnaryPredicate::argument_type argument_type;
199-
200198
TestAndEraseFromSet(UnaryPredicate P, set_type &set_) : P(P), set_(set_) {}
201199

202-
bool operator()(argument_type Arg) {
200+
template <typename ArgumentT>
201+
bool operator()(const ArgumentT &Arg) {
203202
if (P(Arg)) {
204203
set_.erase(Arg);
205204
return true;

lib/Transforms/Scalar/DeadStoreElimination.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,13 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
803803

804804
// If the call might load from any of our allocas, then any store above
805805
// the call is live.
806-
std::function<bool(Value *)> Pred = [&](Value *I) {
806+
DeadStackObjects.remove_if([&](Value *I) {
807807
// See if the call site touches the value.
808808
AliasAnalysis::ModRefResult A =
809809
AA->getModRefInfo(CS, I, getPointerSize(I, *AA));
810810

811811
return A == AliasAnalysis::ModRef || A == AliasAnalysis::Ref;
812-
};
813-
DeadStackObjects.remove_if(Pred);
812+
});
814813

815814
// If all of the allocas were clobbered by the call then we're not going
816815
// to find anything else to process.

lib/Transforms/Scalar/SROA.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3640,7 +3640,7 @@ bool SROA::runOnFunction(Function &F) {
36403640
// Remove the deleted allocas from various lists so that we don't try to
36413641
// continue processing them.
36423642
if (!DeletedAllocas.empty()) {
3643-
std::function<bool(AllocaInst *)> IsInSet = [&](AllocaInst *AI) {
3643+
auto IsInSet = [&](AllocaInst *AI) {
36443644
return DeletedAllocas.count(AI);
36453645
};
36463646
Worklist.remove_if(IsInSet);

0 commit comments

Comments
 (0)