18#include "llvm/IR/IntrinsicsAMDGPU.h"
21#define DEBUG_TYPE "amdgpu-memory-utils"
37 if (
F && GV.
getName() ==
"llvm.amdgcn.module.lds")
46 while (!Stack.empty()) {
47 const User *V = Stack.pop_back_val();
50 if (isa<GlobalValue>(V)) {
57 if (
auto *
I = dyn_cast<Instruction>(V)) {
71 assert(isa<Constant>(V) &&
"Expected a constant.");
105 std::vector<llvm::GlobalVariable *> LocalVars;
106 for (
auto &GV : M.globals()) {
113 LocalVars.push_back(&GV);
121 if (isa<FenceInst>(DefInst))
124 if (
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(DefInst)) {
125 switch (II->getIntrinsicID()) {
126 case Intrinsic::amdgcn_s_barrier:
127 case Intrinsic::amdgcn_wave_barrier:
128 case Intrinsic::amdgcn_sched_barrier:
129 case Intrinsic::amdgcn_sched_group_barrier:
138 const auto checkNoAlias = [AA,
Ptr](
auto I) ->
bool {
142 if (checkNoAlias(dyn_cast<AtomicCmpXchgInst>(DefInst)) ||
143 checkNoAlias(dyn_cast<AtomicRMWInst>(DefInst)))
156 LLVM_DEBUG(
dbgs() <<
"Checking clobbering of: " << *Load <<
'\n');
166 while (!WorkList.empty()) {
168 if (!Visited.
insert(MA).second)
174 if (
MemoryDef *Def = dyn_cast<MemoryDef>(MA)) {
187 const MemoryPhi *Phi = cast<MemoryPhi>(MA);
189 WorkList.push_back(cast<MemoryAccess>(&
Use));
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallSet class.
bool isNoAlias(const MemoryLocation &LocA, const MemoryLocation &LocB)
A trivial helper function to check to see if the specified pointers are no-alias.
A parsed version of the target data layout string in and methods for querying it.
PointerType * getType() const
Global values are always pointers.
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
A wrapper class for inspecting calls to intrinsic functions.
An instruction for reading from memory.
Represents a read-write access to memory, whether it is a must-alias, or a may-alias.
Representation for a specific memory location.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
Represents phi nodes for memory accesses.
op_range incoming_values()
This is the generic walker interface for walkers of MemorySSA.
MemoryAccess * getClobberingMemoryAccess(const Instruction *I, BatchAAResults &AA)
Given a memory Mod/Ref/ModRef'ing instruction, calling this will give you the nearest dominating Memo...
Encapsulates MemorySSA, including all data associated with memory accesses.
MemorySSAWalker * getWalker()
bool isLiveOnEntryDef(const MemoryAccess *MA) const
Return true if MA represents the live on entry value.
A Module instance is used to store all the information related to an LLVM module.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
iterator_range< user_iterator > users()
Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
StringRef getName() const
Return a constant reference to the value's name.
@ LOCAL_ADDRESS
Address space for local memory.
std::vector< GlobalVariable * > findLDSVariablesToLower(Module &M, const Function *F)
static bool shouldLowerLDSToStruct(const GlobalVariable &GV, const Function *F)
Align getAlign(DataLayout const &DL, const GlobalVariable *GV)
bool isReallyAClobber(const Value *Ptr, MemoryDef *Def, AAResults *AA)
Given a Def clobbering a load from Ptr according to the MSSA check if this is actually a memory updat...
bool isKernelCC(const Function *Func)
bool isLDSVariableToLower(const GlobalVariable &GV)
bool isClobberedInFunction(const LoadInst *Load, MemorySSA *MSSA, AAResults *AA)
Check is a Load is clobbered in its function.
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
This struct is a compact representation of a valid (non-zero power of two) alignment.