2017-08-09 07:53:55 +08:00
|
|
|
//===- AMDGPUAliasAnalysis ------------------------------------------------===//
|
2017-03-18 07:56:58 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-03-18 07:56:58 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This is the AMGPU address space based alias analysis pass.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPUAliasAnalysis.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "AMDGPU.h"
|
2017-08-09 07:53:55 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2017-03-18 07:56:58 +08:00
|
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
2017-08-09 07:53:55 +08:00
|
|
|
#include "llvm/Analysis/MemoryLocation.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/Analysis/ValueTracking.h"
|
2017-08-09 07:53:55 +08:00
|
|
|
#include "llvm/IR/Argument.h"
|
|
|
|
#include "llvm/IR/Attributes.h"
|
|
|
|
#include "llvm/IR/CallingConv.h"
|
2017-03-18 07:56:58 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2017-08-09 07:53:55 +08:00
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
|
|
|
#include "llvm/IR/Type.h"
|
|
|
|
#include "llvm/IR/Value.h"
|
2017-03-18 07:56:58 +08:00
|
|
|
#include "llvm/Pass.h"
|
2017-08-09 07:53:55 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include <cassert>
|
2017-03-18 07:56:58 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "amdgpu-aa"
|
|
|
|
|
|
|
|
// Register this pass...
|
|
|
|
char AMDGPUAAWrapperPass::ID = 0;
|
2018-11-08 04:26:42 +08:00
|
|
|
char AMDGPUExternalAAWrapper::ID = 0;
|
2017-08-09 07:53:55 +08:00
|
|
|
|
2017-03-18 07:56:58 +08:00
|
|
|
INITIALIZE_PASS(AMDGPUAAWrapperPass, "amdgpu-aa",
|
|
|
|
"AMDGPU Address space based Alias Analysis", false, true)
|
|
|
|
|
2018-11-08 04:26:42 +08:00
|
|
|
INITIALIZE_PASS(AMDGPUExternalAAWrapper, "amdgpu-aa-wrapper",
|
|
|
|
"AMDGPU Address space based Alias Analysis Wrapper", false, true)
|
|
|
|
|
2017-03-18 07:56:58 +08:00
|
|
|
ImmutablePass *llvm::createAMDGPUAAWrapperPass() {
|
|
|
|
return new AMDGPUAAWrapperPass();
|
|
|
|
}
|
|
|
|
|
2018-11-08 04:26:42 +08:00
|
|
|
ImmutablePass *llvm::createAMDGPUExternalAAWrapperPass() {
|
|
|
|
return new AMDGPUExternalAAWrapper();
|
|
|
|
}
|
|
|
|
|
2017-03-18 07:56:58 +08:00
|
|
|
void AMDGPUAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2019-03-18 22:44:28 +08:00
|
|
|
// These arrays are indexed by address space value enum elements 0 ... to 7
|
|
|
|
static const AliasResult ASAliasRules[8][8] = {
|
|
|
|
/* Flat Global Region Group Constant Private Constant 32-bit Buffer Fat Ptr */
|
2019-07-17 19:22:19 +08:00
|
|
|
/* Flat */ {MayAlias, MayAlias, NoAlias, MayAlias, MayAlias, MayAlias, MayAlias, MayAlias},
|
2019-03-18 22:44:28 +08:00
|
|
|
/* Global */ {MayAlias, MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , MayAlias, MayAlias},
|
2019-07-17 19:22:19 +08:00
|
|
|
/* Region */ {NoAlias, NoAlias , MayAlias, NoAlias , NoAlias, NoAlias , NoAlias, NoAlias},
|
2019-03-18 22:44:28 +08:00
|
|
|
/* Group */ {MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , NoAlias , NoAlias , NoAlias},
|
2019-07-17 19:22:19 +08:00
|
|
|
/* Constant */ {MayAlias, MayAlias, NoAlias, NoAlias , NoAlias , NoAlias , MayAlias, MayAlias},
|
2019-03-18 22:44:28 +08:00
|
|
|
/* Private */ {MayAlias, NoAlias , NoAlias , NoAlias , NoAlias , MayAlias, NoAlias , NoAlias},
|
2019-07-17 19:22:19 +08:00
|
|
|
/* Constant 32-bit */ {MayAlias, MayAlias, NoAlias, NoAlias , MayAlias, NoAlias , NoAlias , MayAlias},
|
2019-03-18 22:44:28 +08:00
|
|
|
/* Buffer Fat Ptr */ {MayAlias, MayAlias, NoAlias , NoAlias , MayAlias, NoAlias , MayAlias, MayAlias}
|
2018-09-11 12:00:49 +08:00
|
|
|
};
|
2018-08-31 13:49:54 +08:00
|
|
|
|
2018-09-11 12:00:49 +08:00
|
|
|
static AliasResult getAliasResult(unsigned AS1, unsigned AS2) {
|
2019-03-18 22:44:28 +08:00
|
|
|
static_assert(AMDGPUAS::MAX_AMDGPU_ADDRESS <= 7, "Addr space out of range");
|
2018-08-31 13:49:54 +08:00
|
|
|
|
2018-09-11 12:00:49 +08:00
|
|
|
if (AS1 > AMDGPUAS::MAX_AMDGPU_ADDRESS || AS2 > AMDGPUAS::MAX_AMDGPU_ADDRESS)
|
|
|
|
return MayAlias;
|
2017-04-01 03:26:23 +08:00
|
|
|
|
2018-09-11 12:00:49 +08:00
|
|
|
return ASAliasRules[AS1][AS2];
|
2017-03-27 22:04:01 +08:00
|
|
|
}
|
|
|
|
|
2017-03-18 07:56:58 +08:00
|
|
|
AliasResult AMDGPUAAResult::alias(const MemoryLocation &LocA,
|
[AliasAnalysis] Second prototype to cache BasicAA / anyAA state.
Summary:
Adding contained caching to AliasAnalysis. BasicAA is currently the only one using it.
AA changes:
- This patch is pulling the caches from BasicAAResults to AAResults, meaning the getModRefInfo call benefits from the IsCapturedCache as well when in "batch mode".
- All AAResultBase implementations add the QueryInfo member to all APIs. AAResults APIs maintain wrapper APIs such that all alias()/getModRefInfo call sites are unchanged.
- AA now provides a BatchAAResults type as a wrapper to AAResults. It keeps the AAResults instance and a QueryInfo instantiated to batch mode. It delegates all work to the AAResults instance with the batched QueryInfo. More API wrappers may be needed in BatchAAResults; only the minimum needed is currently added.
MemorySSA changes:
- All walkers are now templated on the AA used (AliasAnalysis=AAResults or BatchAAResults).
- At build time, we optimize uses; now we create a local walker (lives only as long as OptimizeUses does) using BatchAAResults.
- All Walkers have an internal AA and only use that now, never the AA in MemorySSA. The Walkers receive the AA they will use when built.
- The walker we use for queries after the build is instantiated on AliasAnalysis and is built after building MemorySSA and setting AA.
- All static methods doing walking are now templated on AliasAnalysisType if they are used both during build and after. If used only during build, the method now only takes a BatchAAResults. If used only after build, the method now takes an AliasAnalysis.
Subscribers: sanjoy, arsenm, jvesely, nhaehnle, jlebar, george.burgess.iv, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59315
llvm-svn: 356783
2019-03-23 01:22:19 +08:00
|
|
|
const MemoryLocation &LocB,
|
|
|
|
AAQueryInfo &AAQI) {
|
2017-03-18 07:56:58 +08:00
|
|
|
unsigned asA = LocA.Ptr->getType()->getPointerAddressSpace();
|
|
|
|
unsigned asB = LocB.Ptr->getType()->getPointerAddressSpace();
|
|
|
|
|
2018-09-11 12:00:49 +08:00
|
|
|
AliasResult Result = getAliasResult(asA, asB);
|
|
|
|
if (Result == NoAlias)
|
|
|
|
return Result;
|
2017-03-18 07:56:58 +08:00
|
|
|
|
|
|
|
// Forward the query to the next alias analysis.
|
[AliasAnalysis] Second prototype to cache BasicAA / anyAA state.
Summary:
Adding contained caching to AliasAnalysis. BasicAA is currently the only one using it.
AA changes:
- This patch is pulling the caches from BasicAAResults to AAResults, meaning the getModRefInfo call benefits from the IsCapturedCache as well when in "batch mode".
- All AAResultBase implementations add the QueryInfo member to all APIs. AAResults APIs maintain wrapper APIs such that all alias()/getModRefInfo call sites are unchanged.
- AA now provides a BatchAAResults type as a wrapper to AAResults. It keeps the AAResults instance and a QueryInfo instantiated to batch mode. It delegates all work to the AAResults instance with the batched QueryInfo. More API wrappers may be needed in BatchAAResults; only the minimum needed is currently added.
MemorySSA changes:
- All walkers are now templated on the AA used (AliasAnalysis=AAResults or BatchAAResults).
- At build time, we optimize uses; now we create a local walker (lives only as long as OptimizeUses does) using BatchAAResults.
- All Walkers have an internal AA and only use that now, never the AA in MemorySSA. The Walkers receive the AA they will use when built.
- The walker we use for queries after the build is instantiated on AliasAnalysis and is built after building MemorySSA and setting AA.
- All static methods doing walking are now templated on AliasAnalysisType if they are used both during build and after. If used only during build, the method now only takes a BatchAAResults. If used only after build, the method now takes an AliasAnalysis.
Subscribers: sanjoy, arsenm, jvesely, nhaehnle, jlebar, george.burgess.iv, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59315
llvm-svn: 356783
2019-03-23 01:22:19 +08:00
|
|
|
return AAResultBase::alias(LocA, LocB, AAQI);
|
2017-03-18 07:56:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMDGPUAAResult::pointsToConstantMemory(const MemoryLocation &Loc,
|
[AliasAnalysis] Second prototype to cache BasicAA / anyAA state.
Summary:
Adding contained caching to AliasAnalysis. BasicAA is currently the only one using it.
AA changes:
- This patch is pulling the caches from BasicAAResults to AAResults, meaning the getModRefInfo call benefits from the IsCapturedCache as well when in "batch mode".
- All AAResultBase implementations add the QueryInfo member to all APIs. AAResults APIs maintain wrapper APIs such that all alias()/getModRefInfo call sites are unchanged.
- AA now provides a BatchAAResults type as a wrapper to AAResults. It keeps the AAResults instance and a QueryInfo instantiated to batch mode. It delegates all work to the AAResults instance with the batched QueryInfo. More API wrappers may be needed in BatchAAResults; only the minimum needed is currently added.
MemorySSA changes:
- All walkers are now templated on the AA used (AliasAnalysis=AAResults or BatchAAResults).
- At build time, we optimize uses; now we create a local walker (lives only as long as OptimizeUses does) using BatchAAResults.
- All Walkers have an internal AA and only use that now, never the AA in MemorySSA. The Walkers receive the AA they will use when built.
- The walker we use for queries after the build is instantiated on AliasAnalysis and is built after building MemorySSA and setting AA.
- All static methods doing walking are now templated on AliasAnalysisType if they are used both during build and after. If used only during build, the method now only takes a BatchAAResults. If used only after build, the method now takes an AliasAnalysis.
Subscribers: sanjoy, arsenm, jvesely, nhaehnle, jlebar, george.burgess.iv, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59315
llvm-svn: 356783
2019-03-23 01:22:19 +08:00
|
|
|
AAQueryInfo &AAQI, bool OrLocal) {
|
2017-03-18 07:56:58 +08:00
|
|
|
const Value *Base = GetUnderlyingObject(Loc.Ptr, DL);
|
2018-08-31 13:49:54 +08:00
|
|
|
unsigned AS = Base->getType()->getPointerAddressSpace();
|
|
|
|
if (AS == AMDGPUAS::CONSTANT_ADDRESS ||
|
|
|
|
AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT) {
|
2017-03-18 07:56:58 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
|
|
|
|
if (GV->isConstant())
|
|
|
|
return true;
|
|
|
|
} else if (const Argument *Arg = dyn_cast<Argument>(Base)) {
|
|
|
|
const Function *F = Arg->getParent();
|
|
|
|
|
|
|
|
// Only assume constant memory for arguments on kernels.
|
|
|
|
switch (F->getCallingConv()) {
|
|
|
|
default:
|
[AliasAnalysis] Second prototype to cache BasicAA / anyAA state.
Summary:
Adding contained caching to AliasAnalysis. BasicAA is currently the only one using it.
AA changes:
- This patch is pulling the caches from BasicAAResults to AAResults, meaning the getModRefInfo call benefits from the IsCapturedCache as well when in "batch mode".
- All AAResultBase implementations add the QueryInfo member to all APIs. AAResults APIs maintain wrapper APIs such that all alias()/getModRefInfo call sites are unchanged.
- AA now provides a BatchAAResults type as a wrapper to AAResults. It keeps the AAResults instance and a QueryInfo instantiated to batch mode. It delegates all work to the AAResults instance with the batched QueryInfo. More API wrappers may be needed in BatchAAResults; only the minimum needed is currently added.
MemorySSA changes:
- All walkers are now templated on the AA used (AliasAnalysis=AAResults or BatchAAResults).
- At build time, we optimize uses; now we create a local walker (lives only as long as OptimizeUses does) using BatchAAResults.
- All Walkers have an internal AA and only use that now, never the AA in MemorySSA. The Walkers receive the AA they will use when built.
- The walker we use for queries after the build is instantiated on AliasAnalysis and is built after building MemorySSA and setting AA.
- All static methods doing walking are now templated on AliasAnalysisType if they are used both during build and after. If used only during build, the method now only takes a BatchAAResults. If used only after build, the method now takes an AliasAnalysis.
Subscribers: sanjoy, arsenm, jvesely, nhaehnle, jlebar, george.burgess.iv, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59315
llvm-svn: 356783
2019-03-23 01:22:19 +08:00
|
|
|
return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
|
2017-09-29 17:51:22 +08:00
|
|
|
case CallingConv::AMDGPU_LS:
|
|
|
|
case CallingConv::AMDGPU_HS:
|
|
|
|
case CallingConv::AMDGPU_ES:
|
2017-03-18 07:56:58 +08:00
|
|
|
case CallingConv::AMDGPU_GS:
|
2017-09-29 17:51:22 +08:00
|
|
|
case CallingConv::AMDGPU_VS:
|
2017-03-18 07:56:58 +08:00
|
|
|
case CallingConv::AMDGPU_PS:
|
|
|
|
case CallingConv::AMDGPU_CS:
|
|
|
|
case CallingConv::AMDGPU_KERNEL:
|
|
|
|
case CallingConv::SPIR_KERNEL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ArgNo = Arg->getArgNo();
|
|
|
|
/* On an argument, ReadOnly attribute indicates that the function does
|
|
|
|
not write through this pointer argument, even though it may write
|
|
|
|
to the memory that the pointer points to.
|
|
|
|
On an argument, ReadNone attribute indicates that the function does
|
|
|
|
not dereference that pointer argument, even though it may read or write
|
|
|
|
the memory that the pointer points to if accessed through other pointers.
|
|
|
|
*/
|
2017-04-14 07:12:13 +08:00
|
|
|
if (F->hasParamAttribute(ArgNo, Attribute::NoAlias) &&
|
|
|
|
(F->hasParamAttribute(ArgNo, Attribute::ReadNone) ||
|
|
|
|
F->hasParamAttribute(ArgNo, Attribute::ReadOnly))) {
|
2017-03-18 07:56:58 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
[AliasAnalysis] Second prototype to cache BasicAA / anyAA state.
Summary:
Adding contained caching to AliasAnalysis. BasicAA is currently the only one using it.
AA changes:
- This patch is pulling the caches from BasicAAResults to AAResults, meaning the getModRefInfo call benefits from the IsCapturedCache as well when in "batch mode".
- All AAResultBase implementations add the QueryInfo member to all APIs. AAResults APIs maintain wrapper APIs such that all alias()/getModRefInfo call sites are unchanged.
- AA now provides a BatchAAResults type as a wrapper to AAResults. It keeps the AAResults instance and a QueryInfo instantiated to batch mode. It delegates all work to the AAResults instance with the batched QueryInfo. More API wrappers may be needed in BatchAAResults; only the minimum needed is currently added.
MemorySSA changes:
- All walkers are now templated on the AA used (AliasAnalysis=AAResults or BatchAAResults).
- At build time, we optimize uses; now we create a local walker (lives only as long as OptimizeUses does) using BatchAAResults.
- All Walkers have an internal AA and only use that now, never the AA in MemorySSA. The Walkers receive the AA they will use when built.
- The walker we use for queries after the build is instantiated on AliasAnalysis and is built after building MemorySSA and setting AA.
- All static methods doing walking are now templated on AliasAnalysisType if they are used both during build and after. If used only during build, the method now only takes a BatchAAResults. If used only after build, the method now takes an AliasAnalysis.
Subscribers: sanjoy, arsenm, jvesely, nhaehnle, jlebar, george.burgess.iv, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59315
llvm-svn: 356783
2019-03-23 01:22:19 +08:00
|
|
|
return AAResultBase::pointsToConstantMemory(Loc, AAQI, OrLocal);
|
2017-03-18 07:56:58 +08:00
|
|
|
}
|