195#include "llvm/IR/IntrinsicsAMDGPU.h"
212#define DEBUG_TYPE "amdgpu-lower-module-lds"
215using namespace AMDGPU;
220 "amdgpu-super-align-lds-globals",
221 cl::desc(
"Increase alignment of LDS if it is not on align boundary"),
224enum class LoweringKind { module, table, kernel, hybrid };
226 "amdgpu-lower-module-lds-strategy",
230 clEnumValN(LoweringKind::table,
"table",
"Lower via table lookup"),
231 clEnumValN(LoweringKind::module,
"module",
"Lower via module struct"),
233 LoweringKind::kernel,
"kernel",
234 "Lower variables reachable from one kernel, otherwise abort"),
236 "Lower via mixture of above strategies")));
238template <
typename T> std::vector<T> sortByName(std::vector<T> &&V) {
239 llvm::sort(V.begin(), V.end(), [](
const auto *L,
const auto *R) {
240 return L->getName() < R->getName();
242 return {std::move(V)};
245class AMDGPULowerModuleLDS {
249 removeLocalVarsFromUsedLists(
Module &M,
255 LocalVarsSet.
insert(cast<Constant>(LocalVar->stripPointerCasts()));
261 LocalVar->removeDeadConstantUsers();
286 IRBuilder<> Builder(Entry, Entry->getFirstNonPHIIt());
291 Value *UseInstance[1] = {
301 struct LDSVariableReplacement {
311 static Constant *getAddressesOfVariablesInKernel(
321 ArrayType *KernelOffsetsType = ArrayType::get(I32, Variables.
size());
324 for (
size_t i = 0; i < Variables.
size(); i++) {
326 auto ConstantGepIt = LDSVarsToConstantGEP.
find(GV);
327 if (ConstantGepIt != LDSVarsToConstantGEP.
end()) {
329 Elements.push_back(elt);
341 if (Variables.
empty()) {
346 const size_t NumberVariables = Variables.
size();
347 const size_t NumberKernels = kernels.
size();
353 ArrayType::get(KernelOffsetsType, NumberKernels);
356 std::vector<Constant *> overallConstantExprElts(NumberKernels);
357 for (
size_t i = 0; i < NumberKernels; i++) {
358 auto Replacement = KernelToReplacement.
find(kernels[i]);
359 overallConstantExprElts[i] =
360 (Replacement == KernelToReplacement.
end())
362 : getAddressesOfVariablesInKernel(
363 Ctx, Variables, Replacement->second.LDSVarsToConstantGEP);
378 Value *OptionalIndex) {
382 auto *
I = cast<Instruction>(U.getUser());
384 Value *tableKernelIndex = getTableLookupKernelIndex(M,
I->getFunction());
386 if (
auto *Phi = dyn_cast<PHINode>(
I)) {
394 ConstantInt::get(I32, 0),
401 LookupTable->getValueType(), LookupTable, GEPIdx, GV->
getName());
411 void replaceUsesInInstructionsWithTableLookup(
420 auto *GV = ModuleScopeVariables[
Index];
423 auto *
I = dyn_cast<Instruction>(U.getUser());
427 replaceUseWithTableLookup(M, Builder, LookupTable, GV, U,
428 ConstantInt::get(I32,
Index));
439 if (VariableSet.
empty())
442 for (
Function &Func : M.functions()) {
447 KernelSet.insert(&Func);
457 chooseBestVariableForModuleStrategy(
const DataLayout &
DL,
463 size_t UserCount = 0;
466 CandidateTy() =
default;
469 : GV(GV), UserCount(UserCount),
Size(AllocSize) {}
473 if (UserCount <
Other.UserCount) {
476 if (UserCount >
Other.UserCount) {
494 CandidateTy MostUsed;
496 for (
auto &K : LDSVars) {
498 if (K.second.size() <= 1) {
503 CandidateTy Candidate(
506 if (MostUsed < Candidate)
507 MostUsed = Candidate;
531 auto [It, Inserted] = tableKernelIndexCache.
try_emplace(
F);
536 auto InsertAt =
F->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
545 static std::vector<Function *> assignLDSKernelIDToEachKernel(
553 std::vector<Function *> OrderedKernels;
554 if (!KernelsThatAllocateTableLDS.
empty() ||
555 !KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
557 for (
Function &Func : M->functions()) {
558 if (Func.isDeclaration())
563 if (KernelsThatAllocateTableLDS.
contains(&Func) ||
564 KernelsThatIndirectlyAllocateDynamicLDS.
contains(&Func)) {
566 OrderedKernels.push_back(&Func);
571 OrderedKernels = sortByName(std::move(OrderedKernels));
577 if (OrderedKernels.size() > UINT32_MAX) {
582 for (
size_t i = 0; i < OrderedKernels.size(); i++) {
586 OrderedKernels[i]->setMetadata(
"llvm.amdgcn.lds.kernel.id",
590 return OrderedKernels;
593 static void partitionVariablesIntoIndirectStrategies(
602 LoweringKindLoc != LoweringKind::hybrid
604 : chooseBestVariableForModuleStrategy(
605 M.getDataLayout(), LDSToKernelsThatNeedToAccessItIndirectly);
610 ? LDSToKernelsThatNeedToAccessItIndirectly[HybridModuleRoot]
613 for (
auto &K : LDSToKernelsThatNeedToAccessItIndirectly) {
619 assert(K.second.size() != 0);
622 DynamicVariables.
insert(GV);
626 switch (LoweringKindLoc) {
627 case LoweringKind::module:
628 ModuleScopeVariables.insert(GV);
631 case LoweringKind::table:
632 TableLookupVariables.
insert(GV);
635 case LoweringKind::kernel:
636 if (K.second.size() == 1) {
637 KernelAccessVariables.
insert(GV);
640 "cannot lower LDS '" + GV->
getName() +
641 "' to kernel access as it is reachable from multiple kernels");
645 case LoweringKind::hybrid: {
646 if (GV == HybridModuleRoot) {
647 assert(K.second.size() != 1);
648 ModuleScopeVariables.insert(GV);
649 }
else if (K.second.size() == 1) {
650 KernelAccessVariables.
insert(GV);
651 }
else if (
set_is_subset(K.second, HybridModuleRootKernels)) {
652 ModuleScopeVariables.insert(GV);
654 TableLookupVariables.
insert(GV);
663 assert(ModuleScopeVariables.
size() + TableLookupVariables.
size() +
664 KernelAccessVariables.
size() + DynamicVariables.
size() ==
665 LDSToKernelsThatNeedToAccessItIndirectly.size());
678 if (ModuleScopeVariables.
empty()) {
684 LDSVariableReplacement ModuleScopeReplacement =
685 createLDSVariableReplacement(M,
"llvm.amdgcn.module.lds",
686 ModuleScopeVariables);
690 cast<Constant>(ModuleScopeReplacement.SGV),
691 PointerType::getUnqual(Ctx)))});
694 recordLDSAbsoluteAddress(&M, ModuleScopeReplacement.SGV, 0);
697 removeLocalVarsFromUsedLists(M, ModuleScopeVariables);
700 replaceLDSVariablesWithStruct(
701 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
714 for (
Function &Func : M.functions()) {
718 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
719 replaceLDSVariablesWithStruct(
720 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
729 markUsedByKernel(&Func, ModuleScopeReplacement.SGV);
733 return ModuleScopeReplacement.SGV;
737 lowerKernelScopeStructVariables(
746 for (
Function &Func : M.functions()) {
755 KernelUsedVariables.
insert(v);
763 KernelUsedVariables.
insert(v);
769 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
771 KernelUsedVariables.
erase(v);
775 if (KernelUsedVariables.
empty()) {
787 if (!Func.hasName()) {
791 std::string VarName =
792 (
Twine(
"llvm.amdgcn.kernel.") + Func.getName() +
".lds").str();
795 createLDSVariableReplacement(M, VarName, KernelUsedVariables);
802 !Accesses->second.empty())
803 markUsedByKernel(&Func, Replacement.SGV);
806 removeLocalVarsFromUsedLists(M, KernelUsedVariables);
807 KernelToReplacement[&Func] = Replacement;
810 replaceLDSVariablesWithStruct(
811 M, KernelUsedVariables, Replacement, [&Func](
Use &U) {
813 return I &&
I->getFunction() == &Func;
816 return KernelToReplacement;
836 Align MaxDynamicAlignment(1);
840 MaxDynamicAlignment =
846 UpdateMaxAlignment(GV);
850 UpdateMaxAlignment(GV);
859 N->setAlignment(MaxDynamicAlignment);
869 std::vector<Function *>
const &OrderedKernels) {
871 if (!KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
876 std::vector<Constant *> newDynamicLDS;
879 for (
auto &func : OrderedKernels) {
881 if (KernelsThatIndirectlyAllocateDynamicLDS.
contains(func)) {
888 buildRepresentativeDynamicLDSInstance(M, LDSUsesInfo, func);
890 KernelToCreatedDynamicLDS[func] =
N;
892 markUsedByKernel(func,
N);
896 emptyCharArray,
N, ConstantInt::get(I32, 0),
true);
902 assert(OrderedKernels.size() == newDynamicLDS.size());
904 ArrayType *t = ArrayType::get(I32, newDynamicLDS.size());
908 "llvm.amdgcn.dynlds.offset.table",
nullptr,
913 auto *
I = dyn_cast<Instruction>(U.getUser());
919 replaceUseWithTableLookup(M, Builder, table, GV, U,
nullptr);
923 return KernelToCreatedDynamicLDS;
926 bool runOnModule(
Module &M) {
928 bool Changed = superAlignLDSGlobals(M);
944 LDSToKernelsThatNeedToAccessItIndirectly[GV].
insert(
F);
953 partitionVariablesIntoIndirectStrategies(
954 M, LDSUsesInfo, LDSToKernelsThatNeedToAccessItIndirectly,
955 ModuleScopeVariables, TableLookupVariables, KernelAccessVariables,
962 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
963 ModuleScopeVariables);
965 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
966 TableLookupVariables);
969 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
972 GlobalVariable *MaybeModuleScopeStruct = lowerModuleScopeStructVariables(
973 M, ModuleScopeVariables, KernelsThatAllocateModuleLDS);
976 lowerKernelScopeStructVariables(M, LDSUsesInfo, ModuleScopeVariables,
977 KernelsThatAllocateModuleLDS,
978 MaybeModuleScopeStruct);
981 for (
auto &GV : KernelAccessVariables) {
982 auto &funcs = LDSToKernelsThatNeedToAccessItIndirectly[GV];
983 assert(funcs.size() == 1);
984 LDSVariableReplacement Replacement =
985 KernelToReplacement[*(funcs.begin())];
990 replaceLDSVariablesWithStruct(M, Vec, Replacement, [](
Use &U) {
991 return isa<Instruction>(U.getUser());
996 std::vector<Function *> OrderedKernels =
997 assignLDSKernelIDToEachKernel(&M, KernelsThatAllocateTableLDS,
998 KernelsThatIndirectlyAllocateDynamicLDS);
1000 if (!KernelsThatAllocateTableLDS.
empty()) {
1006 auto TableLookupVariablesOrdered =
1007 sortByName(std::vector<GlobalVariable *>(TableLookupVariables.
begin(),
1008 TableLookupVariables.
end()));
1011 M, TableLookupVariablesOrdered, OrderedKernels, KernelToReplacement);
1012 replaceUsesInInstructionsWithTableLookup(M, TableLookupVariablesOrdered,
1019 for (
Function *
F : KernelsThatAllocateTableLDS)
1024 lowerDynamicLDSVariables(M, LDSUsesInfo,
1025 KernelsThatIndirectlyAllocateDynamicLDS,
1026 DynamicVariables, OrderedKernels);
1033 for (
Function &Func : M.functions()) {
1048 const bool AllocateModuleScopeStruct =
1049 MaybeModuleScopeStruct &&
1050 KernelsThatAllocateModuleLDS.
contains(&Func);
1052 auto Replacement = KernelToReplacement.
find(&Func);
1053 const bool AllocateKernelScopeStruct =
1054 Replacement != KernelToReplacement.
end();
1056 const bool AllocateDynamicVariable =
1057 KernelToCreatedDynamicLDS.
contains(&Func);
1061 if (AllocateModuleScopeStruct) {
1067 if (AllocateKernelScopeStruct) {
1070 recordLDSAbsoluteAddress(&M, KernelStruct,
Offset);
1078 if (AllocateDynamicVariable) {
1079 GlobalVariable *DynamicVariable = KernelToCreatedDynamicLDS[&Func];
1081 recordLDSAbsoluteAddress(&M, DynamicVariable,
Offset);
1096 if (AllocateDynamicVariable)
1099 Func.addFnAttr(
"amdgpu-lds-size", Buffer);
1118 static bool superAlignLDSGlobals(
Module &M) {
1120 bool Changed =
false;
1121 if (!SuperAlignLDSGlobals) {
1125 for (
auto &GV : M.globals()) {
1140 Alignment = std::max(Alignment,
Align(16));
1141 }
else if (GVSize > 4) {
1143 Alignment = std::max(Alignment,
Align(8));
1144 }
else if (GVSize > 2) {
1146 Alignment = std::max(Alignment,
Align(4));
1147 }
else if (GVSize > 1) {
1149 Alignment = std::max(Alignment,
Align(2));
1160 static LDSVariableReplacement createLDSVariableReplacement(
1161 Module &M, std::string VarName,
1178 auto Sorted = sortByName(std::vector<GlobalVariable *>(
1179 LDSVarsToTransform.
begin(), LDSVarsToTransform.
end()));
1191 std::vector<GlobalVariable *> LocalVars;
1194 IsPaddingField.
reserve(LDSVarsToTransform.
size());
1197 for (
size_t I = 0;
I < LayoutFields.
size();
I++) {
1199 const_cast<void *
>(LayoutFields[
I].Id));
1200 Align DataAlign = LayoutFields[
I].Alignment;
1203 if (
uint64_t Rem = CurrentOffset % DataAlignV) {
1204 uint64_t Padding = DataAlignV - Rem;
1216 CurrentOffset += Padding;
1219 LocalVars.push_back(FGV);
1221 CurrentOffset += LayoutFields[
I].
Size;
1225 std::vector<Type *> LocalVarTypes;
1226 LocalVarTypes.reserve(LocalVars.size());
1228 LocalVars.cbegin(), LocalVars.cend(), std::back_inserter(LocalVarTypes),
1243 for (
size_t I = 0;
I < LocalVars.size();
I++) {
1245 Constant *GEPIdx[] = {ConstantInt::get(I32, 0), ConstantInt::get(I32,
I)};
1247 if (IsPaddingField[
I]) {
1254 assert(Map.size() == LDSVarsToTransform.
size());
1255 return {SGV, std::move(Map)};
1258 template <
typename PredicateTy>
1259 static void replaceLDSVariablesWithStruct(
1261 const LDSVariableReplacement &Replacement, PredicateTy Predicate) {
1268 auto LDSVarsToTransform = sortByName(std::vector<GlobalVariable *>(
1269 LDSVarsToTransformArg.
begin(), LDSVarsToTransformArg.
end()));
1275 const size_t NumberVars = LDSVarsToTransform.
size();
1276 if (NumberVars > 1) {
1278 AliasScopes.
reserve(NumberVars);
1280 for (
size_t I = 0;
I < NumberVars;
I++) {
1284 NoAliasList.
append(&AliasScopes[1], AliasScopes.
end());
1289 for (
size_t I = 0;
I < NumberVars;
I++) {
1291 Constant *
GEP = Replacement.LDSVarsToConstantGEP.at(GV);
1295 APInt APOff(
DL.getIndexTypeSizeInBits(
GEP->getType()), 0);
1296 GEP->stripAndAccumulateInBoundsConstantOffsets(
DL, APOff);
1303 NoAliasList[
I - 1] = AliasScopes[
I - 1];
1309 refineUsesAlignmentAndAA(
GEP,
A,
DL, AliasScope, NoAlias);
1316 if (!
MaxDepth || (
A == 1 && !AliasScope))
1319 for (
User *U :
Ptr->users()) {
1320 if (
auto *
I = dyn_cast<Instruction>(U)) {
1321 if (AliasScope &&
I->mayReadOrWriteMemory()) {
1322 MDNode *AS =
I->getMetadata(LLVMContext::MD_alias_scope);
1325 I->setMetadata(LLVMContext::MD_alias_scope, AS);
1327 MDNode *NA =
I->getMetadata(LLVMContext::MD_noalias);
1329 I->setMetadata(LLVMContext::MD_noalias, NA);
1333 if (
auto *LI = dyn_cast<LoadInst>(U)) {
1334 LI->setAlignment(std::max(
A, LI->getAlign()));
1337 if (
auto *SI = dyn_cast<StoreInst>(U)) {
1338 if (SI->getPointerOperand() ==
Ptr)
1339 SI->setAlignment(std::max(
A, SI->getAlign()));
1342 if (
auto *AI = dyn_cast<AtomicRMWInst>(U)) {
1345 if (AI->getPointerOperand() ==
Ptr)
1346 AI->setAlignment(std::max(
A, AI->getAlign()));
1349 if (
auto *AI = dyn_cast<AtomicCmpXchgInst>(U)) {
1350 if (AI->getPointerOperand() ==
Ptr)
1351 AI->setAlignment(std::max(
A, AI->getAlign()));
1354 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(U)) {
1355 unsigned BitWidth =
DL.getIndexTypeSizeInBits(
GEP->getType());
1357 if (
GEP->getPointerOperand() ==
Ptr) {
1359 if (
GEP->accumulateConstantOffset(
DL, Off))
1361 refineUsesAlignmentAndAA(
GEP, GA,
DL, AliasScope, NoAlias,
1366 if (
auto *
I = dyn_cast<Instruction>(U)) {
1367 if (
I->getOpcode() == Instruction::BitCast ||
1368 I->getOpcode() == Instruction::AddrSpaceCast)
1369 refineUsesAlignmentAndAA(
I,
A,
DL, AliasScope, NoAlias,
MaxDepth - 1);
1375class AMDGPULowerModuleLDSLegacy :
public ModulePass {
1392 auto &TPC = getAnalysis<TargetPassConfig>();
1396 return AMDGPULowerModuleLDS(*TM).runOnModule(M);
1401char AMDGPULowerModuleLDSLegacy::ID = 0;
1406 "Lower uses of LDS variables from non-kernel functions",
1415 return new AMDGPULowerModuleLDSLegacy(
TM);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Lower uses of LDS variables from non kernel functions
The AMDGPU TargetMachine interface definition for hw codegen targets.
This file implements the BitVector class.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Given that RA is a live propagate it s liveness to any other values it uses(according to Uses). void DeadArgumentEliminationPass
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
std::optional< std::vector< StOtherPiece > > Other
static const unsigned MaxDepth
This file provides an interface for laying out a sequence of fields as a struct in a way that attempt...
const char LLVMTargetMachineRef TM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines generic set operations that may be used on set's of different types,...
Target-Independent Code Generator Pass Configuration Options pass.
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
LLVM Basic Block Representation.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
The basic data container for the call graph of a Module of IR.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
This is an important base class in LLVM.
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
A parsed version of the target data layout string in and methods for querying it.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalObject.
PointerType * getType() const
Global values are always pointers.
@ InternalLinkage
Rename collisions when linking (static functions).
@ ExternalLinkage
Externally visible function.
Type * getValueType() const
bool hasInitializer() const
Definitions have initializers, declarations don't.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Value * CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0, const Twine &Name="")
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=std::nullopt, const Twine &Name="", MDNode *FPMathTag=nullptr)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This is an important class for using LLVM in a threaded context.
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
MDNode * createAnonymousAliasScopeDomain(StringRef Name=StringRef())
Return metadata appropriate for an alias scope domain node.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDNode * intersect(MDNode *A, MDNode *B)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
A container for an operand bundle being viewed as a set of values rather than a set of uses.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
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.
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Class to represent struct types.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Target-Independent Code Generator Pass Configuration Options.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
iterator_range< use_iterator > uses()
StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
bool erase(const ValueT &V)
A raw_ostream that writes to an std::string.
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
bool isDynamicLDS(const GlobalVariable &GV)
void removeFnAttrFromReachable(CallGraph &CG, Function *KernelRoot, ArrayRef< StringRef > FnAttrs)
Strip FnAttr attribute from any functions where we may have introduced its use.
LDSUsesInfoTy getTransitiveUsesOfLDS(const CallGraph &CG, Module &M)
bool isLDSVariableToLower(const GlobalVariable &GV)
bool eliminateConstantExprUsesOfLDSFromAllInstructions(Module &M)
Align getAlign(const DataLayout &DL, const GlobalVariable *GV)
bool isKernelLDS(const Function *F)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
bool set_is_subset(const S1Ty &S1, const S2Ty &S2)
set_is_subset(A, B) - Return true iff A in B
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
void initializeAMDGPULowerModuleLDSLegacyPass(PassRegistry &)
void sort(IteratorTy Start, IteratorTy End)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
char & AMDGPULowerModuleLDSLegacyPassID
void removeFromUsedLists(Module &M, function_ref< bool(Constant *)> ShouldRemove)
Removes global values from the llvm.used and llvm.compiler.used arrays.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
ModulePass * createAMDGPULowerModuleLDSLegacyPass(const AMDGPUTargetMachine *TM=nullptr)
void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
std::pair< uint64_t, Align > performOptimizedStructLayout(MutableArrayRef< OptimizedStructLayoutField > Fields)
Compute a layout for a struct containing the given fields, making a best-effort attempt to minimize t...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr unsigned BitWidth
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const AMDGPUTargetMachine & TM
FunctionVariableMap direct_access
FunctionVariableMap indirect_access
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.