Skip to content

Commit

Permalink
[Attributor] Cleanup intrinsic handling in nosync inference [mostly NFC]
Browse files Browse the repository at this point in the history
Mostly stylistic adjustment, but the old code didn't handle the memcpy.inline intrinsic.  By using the matcher class, we now do.
  • Loading branch information
preames committed Apr 1, 2021
1 parent 01aa9e1 commit 8e596f7
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,7 @@ struct AANoSyncImpl : AANoSync {
/// or monotonic ordering
static bool isNonRelaxedAtomic(Instruction *I);

/// Helper function uset to check if intrinsic is volatile (memcpy, memmove,
/// memset).
/// Helper function specific for intrinsics which are potentially volatile
static bool isNoSyncIntrinsic(Instruction *I);
};

Expand Down Expand Up @@ -1334,37 +1333,27 @@ bool AANoSyncImpl::isNonRelaxedAtomic(Instruction *I) {
return true;
}

/// Checks if an intrinsic is nosync. Currently only checks mem* intrinsics.
/// FIXME: We should ipmrove the handling of intrinsics.
/// 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) {
if (auto *II = dyn_cast<IntrinsicInst>(I)) {
switch (II->getIntrinsicID()) {
case Intrinsic::memset:
case Intrinsic::memmove:
case Intrinsic::memcpy:
if (!cast<MemIntrinsic>(II)->isVolatile())
return true;
return false;
default:
return false;
}
}
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.
/// FIXME: We should improve the handling of intrinsics.

if (isa<IntrinsicInst>(&I) && isNoSyncIntrinsic(&I))
return true;

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();
Expand Down

0 comments on commit 8e596f7

Please sign in to comment.