[llvm] r369767 - [Attributor][NFCI] Try to avoid potential non-deterministic behavior
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 23 08:23:49 PDT 2019
Author: jdoerfert
Date: Fri Aug 23 08:23:49 2019
New Revision: 369767
URL: http://llvm.org/viewvc/llvm-project?rev=369767&view=rev
Log:
[Attributor][NFCI] Try to avoid potential non-deterministic behavior
This commit replaces sets with set vectors in an effort to make the
behavior of the Attributor deterministic.
Modified:
llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
llvm/trunk/lib/Transforms/IPO/Attributor.cpp
Modified: llvm/trunk/include/llvm/Transforms/IPO/Attributor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO/Attributor.h?rev=369767&r1=369766&r2=369767&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO/Attributor.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO/Attributor.h Fri Aug 23 08:23:49 2019
@@ -675,7 +675,7 @@ struct Attributor {
/// matched with their respective return instructions. Returns true if \p Pred
/// holds on all of them.
bool checkForAllReturnedValuesAndReturnInsts(
- const function_ref<bool(Value &, const SmallPtrSetImpl<ReturnInst *> &)>
+ const function_ref<bool(Value &, const SmallSetVector<ReturnInst *, 4> &)>
&Pred,
const AbstractAttribute &QueryingAA);
@@ -1134,17 +1134,17 @@ struct AAReturnedValues
/// Note: Unlike the Attributor::checkForAllReturnedValuesAndReturnInsts
/// method, this one will not filter dead return instructions.
virtual bool checkForAllReturnedValuesAndReturnInsts(
- const function_ref<bool(Value &, const SmallPtrSetImpl<ReturnInst *> &)>
+ const function_ref<bool(Value &, const SmallSetVector<ReturnInst *, 4> &)>
&Pred) const = 0;
- using iterator = DenseMap<Value *, SmallPtrSet<ReturnInst *, 2>>::iterator;
+ using iterator = DenseMap<Value *, SmallSetVector<ReturnInst *, 4>>::iterator;
using const_iterator =
- DenseMap<Value *, SmallPtrSet<ReturnInst *, 2>>::const_iterator;
+ DenseMap<Value *, SmallSetVector<ReturnInst *, 4>>::const_iterator;
virtual llvm::iterator_range<iterator> returned_values() = 0;
virtual llvm::iterator_range<const_iterator> returned_values() const = 0;
virtual size_t getNumReturnValues() const = 0;
- virtual const SmallPtrSetImpl<CallBase *> &getUnresolvedCalls() const = 0;
+ virtual const SmallSetVector<CallBase *, 4> &getUnresolvedCalls() const = 0;
/// Create an abstract attribute view for the position \p IRP.
static AAReturnedValues &createForPosition(const IRPosition &IRP,
Modified: llvm/trunk/lib/Transforms/IPO/Attributor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Attributor.cpp?rev=369767&r1=369766&r2=369767&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Attributor.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Attributor.cpp Fri Aug 23 08:23:49 2019
@@ -17,7 +17,6 @@
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
@@ -681,9 +680,9 @@ class AAReturnedValuesImpl : public AARe
/// Mapping of values potentially returned by the associated function to the
/// return instructions that might return them.
- DenseMap<Value *, SmallPtrSet<ReturnInst *, 2>> ReturnedValues;
+ DenseMap<Value *, SmallSetVector<ReturnInst *, 4>> ReturnedValues;
- SmallPtrSet<CallBase *, 8> UnresolvedCalls;
+ SmallSetVector<CallBase *, 4> UnresolvedCalls;
/// State flags
///
@@ -744,7 +743,7 @@ public:
return llvm::make_range(ReturnedValues.begin(), ReturnedValues.end());
}
- const SmallPtrSetImpl<CallBase *> &getUnresolvedCalls() const override {
+ const SmallSetVector<CallBase *, 4> &getUnresolvedCalls() const override {
return UnresolvedCalls;
}
@@ -760,7 +759,7 @@ public:
/// See AbstractState::checkForAllReturnedValues(...).
bool checkForAllReturnedValuesAndReturnInsts(
- const function_ref<bool(Value &, const SmallPtrSetImpl<ReturnInst *> &)>
+ const function_ref<bool(Value &, const SmallSetVector<ReturnInst *, 4> &)>
&Pred) const override;
/// Pretty print the attribute similar to the IR representation.
@@ -852,7 +851,7 @@ AAReturnedValuesImpl::getAssumedUniqueRe
}
bool AAReturnedValuesImpl::checkForAllReturnedValuesAndReturnInsts(
- const function_ref<bool(Value &, const SmallPtrSetImpl<ReturnInst *> &)>
+ const function_ref<bool(Value &, const SmallSetVector<ReturnInst *, 4> &)>
&Pred) const {
if (!isValidState())
return false;
@@ -861,13 +860,12 @@ bool AAReturnedValuesImpl::checkForAllRe
// encountered an overdefined one during an update.
for (auto &It : ReturnedValues) {
Value *RV = It.first;
- const SmallPtrSetImpl<ReturnInst *> &RetInsts = It.second;
CallBase *CB = dyn_cast<CallBase>(RV);
if (CB && !UnresolvedCalls.count(CB))
continue;
- if (!Pred(*RV, RetInsts))
+ if (!Pred(*RV, It.second))
return false;
}
@@ -885,7 +883,7 @@ ChangeStatus AAReturnedValuesImpl::updat
// The flag to indicate a change.
bool &Changed;
// The return instrs we come from.
- SmallPtrSet<ReturnInst *, 2> RetInsts;
+ SmallSetVector<ReturnInst *, 4> RetInsts;
};
// Callback for a leaf value returned by the associated function.
@@ -1003,7 +1001,7 @@ ChangeStatus AAReturnedValuesImpl::updat
assert(!It.second.empty() && "Entry does not add anything.");
auto &ReturnInsts = ReturnedValues[It.first];
for (ReturnInst *RI : It.second)
- if (ReturnInsts.insert(RI).second) {
+ if (ReturnInsts.insert(RI)) {
LLVM_DEBUG(dbgs() << "[AAReturnedValues] Add new returned value "
<< *It.first << " => " << *RI << "\n");
Changed = true;
@@ -2263,7 +2261,7 @@ bool Attributor::checkForAllCallSites(co
}
bool Attributor::checkForAllReturnedValuesAndReturnInsts(
- const function_ref<bool(Value &, const SmallPtrSetImpl<ReturnInst *> &)>
+ const function_ref<bool(Value &, const SmallSetVector<ReturnInst *, 4> &)>
&Pred,
const AbstractAttribute &QueryingAA) {
@@ -2299,7 +2297,7 @@ bool Attributor::checkForAllReturnedValu
return false;
return AARetVal.checkForAllReturnedValuesAndReturnInsts(
- [&](Value &RV, const SmallPtrSetImpl<ReturnInst *> &) {
+ [&](Value &RV, const SmallSetVector<ReturnInst *, 4> &) {
return Pred(RV);
});
}
More information about the llvm-commits
mailing list