/// Abstract Attribute helper functions.
namespace AA {
+/// Return true if \p I is a `nosync` instruction. Use generic reasoning and
+/// potentially the corresponding AANoSync.
+bool isNoSyncInst(Attributor &A, const Instruction &I,
+ const AbstractAttribute &QueryingAA);
+
/// Return true if \p V is dynamically unique, that is, there are no two
/// "instances" of \p V at runtime with different values.
bool isDynamicallyUnique(Attributor &A, const AbstractAttribute &QueryingAA,
/// Returns true if "nosync" is known.
bool isKnownNoSync() const { return getKnown(); }
+ /// Helper function used to determine whether an instruction is non-relaxed
+ /// atomic. In other words, if an atomic instruction does not have unordered
+ /// or monotonic ordering
+ static bool isNonRelaxedAtomic(const Instruction *I);
+
+ /// Helper function specific for intrinsics which are potentially volatile.
+ static bool isNoSyncIntrinsic(const Instruction *I);
+
/// Create an abstract attribute view for the position \p IRP.
static AANoSync &createForPosition(const IRPosition &IRP, Attributor &A);
}
///}
+bool AA::isNoSyncInst(Attributor &A, const Instruction &I,
+ const AbstractAttribute &QueryingAA) {
+ // We are looking for volatile instructions or non-relaxed atomics.
+ if (const auto *CB = dyn_cast<CallBase>(&I)) {
+ if (CB->hasFnAttr(Attribute::NoSync))
+ return true;
+
+ // Non-convergent and readnone imply nosync.
+ if (!CB->isConvergent() && !CB->mayReadOrWriteMemory())
+ return true;
+
+ if (AANoSync::isNoSyncIntrinsic(&I))
+ return true;
+
+ const auto &NoSyncAA = A.getAAFor<AANoSync>(
+ QueryingAA, IRPosition::callsite_function(*CB), DepClassTy::OPTIONAL);
+ return NoSyncAA.isAssumedNoSync();
+ }
+
+ if (!I.mayReadOrWriteMemory())
+ return true;
+
+ return !I.isVolatile() && !AANoSync::isNonRelaxedAtomic(&I);
+}
+
bool AA::isDynamicallyUnique(Attributor &A, const AbstractAttribute &QueryingAA,
const Value &V) {
if (auto *C = dyn_cast<Constant>(&V))
/// See AbstractAttribute::updateImpl(...).
ChangeStatus updateImpl(Attributor &A) override;
-
- /// Helper function used to determine whether an instruction is non-relaxed
- /// atomic. In other words, if an atomic instruction does not have unordered
- /// or monotonic ordering
- static bool isNonRelaxedAtomic(Instruction *I);
-
- /// Helper function specific for intrinsics which are potentially volatile
- static bool isNoSyncIntrinsic(Instruction *I);
};
-bool AANoSyncImpl::isNonRelaxedAtomic(Instruction *I) {
+bool AANoSync::isNonRelaxedAtomic(const Instruction *I) {
if (!I->isAtomic())
return false;
if (auto *FI = dyn_cast<FenceInst>(I))
// All legal orderings for fence are stronger than monotonic.
return FI->getSyncScopeID() != SyncScope::SingleThread;
- else if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I)) {
+ if (auto *AI = dyn_cast<AtomicCmpXchgInst>(I)) {
// Unordered is not a legal ordering for cmpxchg.
return (AI->getSuccessOrdering() != AtomicOrdering::Monotonic ||
AI->getFailureOrdering() != AtomicOrdering::Monotonic);
/// Return true if this intrinsic is nosync. This is only used for intrinsics
/// which would be nosync except that they have a volatile flag. All other
/// intrinsics are simply annotated with the nosync attribute in Intrinsics.td.
-bool AANoSyncImpl::isNoSyncIntrinsic(Instruction *I) {
+bool AANoSync::isNoSyncIntrinsic(const Instruction *I) {
if (auto *MI = dyn_cast<MemIntrinsic>(I))
return !MI->isVolatile();
return false;
ChangeStatus AANoSyncImpl::updateImpl(Attributor &A) {
auto CheckRWInstForNoSync = [&](Instruction &I) {
- /// We are looking for volatile instructions or Non-Relaxed atomics.
-
- if (const auto *CB = dyn_cast<CallBase>(&I)) {
- if (CB->hasFnAttr(Attribute::NoSync))
- return true;
-
- if (isNoSyncIntrinsic(&I))
- return true;
-
- const auto &NoSyncAA = A.getAAFor<AANoSync>(
- *this, IRPosition::callsite_function(*CB), DepClassTy::REQUIRED);
- return NoSyncAA.isAssumedNoSync();
- }
-
- if (!I.isVolatile() && !isNonRelaxedAtomic(&I))
- return true;
-
- return false;
+ return AA::isNoSyncInst(A, I, *this);
};
auto CheckForNoSync = [&](Instruction &I) {