diff options
author | Nikita Popov <npopov@redhat.com> | 2022-07-28 15:50:39 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-09-14 16:34:41 +0200 |
commit | b1cd393f9e3a547b315f98a73807d8eaccf600bf (patch) | |
tree | 9ea459187a4b26a24234e4418865f27e82364ef0 /polly | |
parent | efd3ec47d9648a1243ff36eeaf10c51a84d0fa3e (diff) | |
download | llvm-b1cd393f9e3a547b315f98a73807d8eaccf600bf.tar.gz |
[AA] Tracking per-location ModRef info in FunctionModRefBehavior (NFCI)
Currently, FunctionModRefBehavior tracks whether the function reads
or writes memory (ModRefInfo) and which locations it can access
(argmem, inaccessiblemem and other). This patch changes it to track
ModRef information per-location instead.
To give two examples of why this is useful:
* D117095 highlights a weakness of ModRef modelling in the presence
of operand bundles. For a memcpy call with deopt operand bundle,
we want to say that it can read any memory, but only write argument
memory. This would allow them to be treated like any other calls.
However, we currently can't express this and have to say that it
can read or write any memory.
* D127383 would ideally be modelled as a separate threadid location,
where threadid Refs outside pre-split coroutines can be ignored
(like other accesses to constant memory). The current representation
does not allow modelling this precisely.
The patch as implemented is intended to be NFC, but there are some
obvious opportunities for improvements and simplification. To fully
capitalize on this we would also want to change the way we represent
memory attributes on functions, but that's a larger change, and I
think it makes sense to separate out the FunctionModRefBehavior
refactoring.
Differential Revision: https://reviews.llvm.org/D130896
Diffstat (limited to 'polly')
-rw-r--r-- | polly/lib/Analysis/ScopBuilder.cpp | 36 | ||||
-rw-r--r-- | polly/lib/Analysis/ScopDetection.cpp | 36 |
2 files changed, 25 insertions, 47 deletions
diff --git a/polly/lib/Analysis/ScopBuilder.cpp b/polly/lib/Analysis/ScopBuilder.cpp index 1817797fc579..0f36d2423b5d 100644 --- a/polly/lib/Analysis/ScopBuilder.cpp +++ b/polly/lib/Analysis/ScopBuilder.cpp @@ -1634,31 +1634,16 @@ bool ScopBuilder::buildAccessCallInst(MemAccInst Inst, ScopStmt *Stmt) { if (CI->doesNotAccessMemory() || isIgnoredIntrinsic(CI) || isDebugCall(CI)) return true; - bool ReadOnly = false; auto *AF = SE.getConstant(IntegerType::getInt64Ty(CI->getContext()), 0); auto *CalledFunction = CI->getCalledFunction(); - switch (AA.getModRefBehavior(CalledFunction)) { - case FMRB_UnknownModRefBehavior: - llvm_unreachable("Unknown mod ref behaviour cannot be represented."); - case FMRB_DoesNotAccessMemory: + FunctionModRefBehavior FMRB = AA.getModRefBehavior(CalledFunction); + if (FMRB.doesNotAccessMemory()) return true; - case FMRB_OnlyWritesMemory: - case FMRB_OnlyWritesInaccessibleMem: - case FMRB_OnlyWritesInaccessibleOrArgMem: - case FMRB_OnlyAccessesInaccessibleMem: - case FMRB_OnlyAccessesInaccessibleOrArgMem: - return false; - case FMRB_OnlyReadsMemory: - case FMRB_OnlyReadsInaccessibleMem: - case FMRB_OnlyReadsInaccessibleOrArgMem: - GlobalReads.emplace_back(Stmt, CI); - return true; - case FMRB_OnlyReadsArgumentPointees: - ReadOnly = true; - [[fallthrough]]; - case FMRB_OnlyWritesArgumentPointees: - case FMRB_OnlyAccessesArgumentPointees: { - auto AccType = ReadOnly ? MemoryAccess::READ : MemoryAccess::MAY_WRITE; + + if (FMRB.onlyAccessesArgPointees()) { + ModRefInfo ArgMR = FMRB.getModRef(FunctionModRefBehavior::ArgMem); + auto AccType = + !isModSet(ArgMR) ? MemoryAccess::READ : MemoryAccess::MAY_WRITE; Loop *L = LI.getLoopFor(Inst->getParent()); for (const auto &Arg : CI->args()) { if (!Arg->getType()->isPointerTy()) @@ -1679,9 +1664,12 @@ bool ScopBuilder::buildAccessCallInst(MemAccInst Inst, ScopStmt *Stmt) { } return true; } - } - return true; + if (FMRB.onlyReadsMemory()) { + GlobalReads.emplace_back(Stmt, CI); + return true; + } + return false; } void ScopBuilder::buildAccessSingleDim(MemAccInst Inst, ScopStmt *Stmt) { diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index 99e93966b21e..7c80a74040c4 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -708,23 +708,8 @@ bool ScopDetection::isValidCallInst(CallInst &CI, } if (AllowModrefCall) { - switch (AA.getModRefBehavior(CalledFunction)) { - case FMRB_UnknownModRefBehavior: - return false; - case FMRB_DoesNotAccessMemory: - case FMRB_OnlyReadsMemory: - case FMRB_OnlyReadsInaccessibleMem: - case FMRB_OnlyReadsInaccessibleOrArgMem: - // Implicitly disable delinearization since we have an unknown - // accesses with an unknown access function. - Context.HasUnknownAccess = true; - // Explicitly use addUnknown so we don't put a loop-variant - // pointer into the alias set. - Context.AST.addUnknown(&CI); - return true; - case FMRB_OnlyReadsArgumentPointees: - case FMRB_OnlyAccessesArgumentPointees: - case FMRB_OnlyWritesArgumentPointees: + FunctionModRefBehavior FMRB = AA.getModRefBehavior(CalledFunction); + if (FMRB.onlyAccessesArgPointees()) { for (const auto &Arg : CI.args()) { if (!Arg->getType()->isPointerTy()) continue; @@ -748,13 +733,18 @@ bool ScopDetection::isValidCallInst(CallInst &CI, // pointer into the alias set. Context.AST.addUnknown(&CI); return true; - case FMRB_OnlyWritesMemory: - case FMRB_OnlyWritesInaccessibleMem: - case FMRB_OnlyWritesInaccessibleOrArgMem: - case FMRB_OnlyAccessesInaccessibleMem: - case FMRB_OnlyAccessesInaccessibleOrArgMem: - return false; } + + if (FMRB.onlyReadsMemory()) { + // Implicitly disable delinearization since we have an unknown + // accesses with an unknown access function. + Context.HasUnknownAccess = true; + // Explicitly use addUnknown so we don't put a loop-variant + // pointer into the alias set. + Context.AST.addUnknown(&CI); + return true; + } + return false; } return false; |