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());
325 auto ConstantGepIt = LDSVarsToConstantGEP.
find(GV);
326 if (ConstantGepIt != LDSVarsToConstantGEP.
end()) {
328 Elements.push_back(elt);
340 if (Variables.
empty()) {
345 const size_t NumberVariables = Variables.
size();
346 const size_t NumberKernels = kernels.
size();
352 ArrayType::get(KernelOffsetsType, NumberKernels);
355 std::vector<Constant *> overallConstantExprElts(NumberKernels);
356 for (
size_t i = 0; i < NumberKernels; i++) {
357 auto Replacement = KernelToReplacement.
find(kernels[i]);
358 overallConstantExprElts[i] =
359 (Replacement == KernelToReplacement.
end())
361 : getAddressesOfVariablesInKernel(
362 Ctx, Variables, Replacement->second.LDSVarsToConstantGEP);
377 Value *OptionalIndex) {
381 auto *
I = cast<Instruction>(U.getUser());
383 Value *tableKernelIndex = getTableLookupKernelIndex(M,
I->getFunction());
385 if (
auto *Phi = dyn_cast<PHINode>(
I)) {
393 ConstantInt::get(I32, 0),
400 LookupTable->getValueType(), LookupTable, GEPIdx, GV->
getName());
410 void replaceUsesInInstructionsWithTableLookup(
419 auto *GV = ModuleScopeVariables[
Index];
422 auto *
I = dyn_cast<Instruction>(U.getUser());
426 replaceUseWithTableLookup(M, Builder, LookupTable, GV, U,
427 ConstantInt::get(I32,
Index));
438 if (VariableSet.
empty())
441 for (
Function &Func : M.functions()) {
446 KernelSet.insert(&Func);
456 chooseBestVariableForModuleStrategy(
const DataLayout &
DL,
462 size_t UserCount = 0;
465 CandidateTy() =
default;
468 : GV(GV), UserCount(UserCount),
Size(AllocSize) {}
472 if (UserCount <
Other.UserCount) {
475 if (UserCount >
Other.UserCount) {
493 CandidateTy MostUsed;
495 for (
auto &K : LDSVars) {
497 if (K.second.size() <= 1) {
502 CandidateTy Candidate(
505 if (MostUsed < Candidate)
506 MostUsed = Candidate;
530 auto [It, Inserted] = tableKernelIndexCache.
try_emplace(
F);
535 auto InsertAt =
F->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
544 static std::vector<Function *> assignLDSKernelIDToEachKernel(
552 std::vector<Function *> OrderedKernels;
553 if (!KernelsThatAllocateTableLDS.
empty() ||
554 !KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
556 for (
Function &Func : M->functions()) {
557 if (Func.isDeclaration())
562 if (KernelsThatAllocateTableLDS.
contains(&Func) ||
563 KernelsThatIndirectlyAllocateDynamicLDS.
contains(&Func)) {
565 OrderedKernels.push_back(&Func);
570 OrderedKernels = sortByName(std::move(OrderedKernels));
576 if (OrderedKernels.size() > UINT32_MAX) {
581 for (
size_t i = 0; i < OrderedKernels.size(); i++) {
585 OrderedKernels[i]->setMetadata(
"llvm.amdgcn.lds.kernel.id",
589 return OrderedKernels;
592 static void partitionVariablesIntoIndirectStrategies(
601 LoweringKindLoc != LoweringKind::hybrid
603 : chooseBestVariableForModuleStrategy(
604 M.getDataLayout(), LDSToKernelsThatNeedToAccessItIndirectly);
609 ? LDSToKernelsThatNeedToAccessItIndirectly[HybridModuleRoot]
612 for (
auto &K : LDSToKernelsThatNeedToAccessItIndirectly) {
618 assert(K.second.size() != 0);
621 DynamicVariables.
insert(GV);
625 switch (LoweringKindLoc) {
626 case LoweringKind::module:
627 ModuleScopeVariables.insert(GV);
630 case LoweringKind::table:
631 TableLookupVariables.
insert(GV);
634 case LoweringKind::kernel:
635 if (K.second.size() == 1) {
636 KernelAccessVariables.
insert(GV);
639 "cannot lower LDS '" + GV->
getName() +
640 "' to kernel access as it is reachable from multiple kernels");
644 case LoweringKind::hybrid: {
645 if (GV == HybridModuleRoot) {
646 assert(K.second.size() != 1);
647 ModuleScopeVariables.insert(GV);
648 }
else if (K.second.size() == 1) {
649 KernelAccessVariables.
insert(GV);
650 }
else if (
set_is_subset(K.second, HybridModuleRootKernels)) {
651 ModuleScopeVariables.insert(GV);
653 TableLookupVariables.
insert(GV);
662 assert(ModuleScopeVariables.
size() + TableLookupVariables.
size() +
663 KernelAccessVariables.
size() + DynamicVariables.
size() ==
664 LDSToKernelsThatNeedToAccessItIndirectly.size());
677 if (ModuleScopeVariables.
empty()) {
683 LDSVariableReplacement ModuleScopeReplacement =
684 createLDSVariableReplacement(M,
"llvm.amdgcn.module.lds",
685 ModuleScopeVariables);
689 cast<Constant>(ModuleScopeReplacement.SGV),
690 PointerType::getUnqual(Ctx)))});
693 recordLDSAbsoluteAddress(&M, ModuleScopeReplacement.SGV, 0);
696 removeLocalVarsFromUsedLists(M, ModuleScopeVariables);
699 replaceLDSVariablesWithStruct(
700 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
713 for (
Function &Func : M.functions()) {
717 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
718 replaceLDSVariablesWithStruct(
719 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
728 markUsedByKernel(&Func, ModuleScopeReplacement.SGV);
732 return ModuleScopeReplacement.SGV;
736 lowerKernelScopeStructVariables(
745 for (
Function &Func : M.functions()) {
754 KernelUsedVariables.
insert(v);
762 KernelUsedVariables.
insert(v);
768 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
770 KernelUsedVariables.
erase(v);
774 if (KernelUsedVariables.
empty()) {
786 if (!Func.hasName()) {
790 std::string VarName =
791 (
Twine(
"llvm.amdgcn.kernel.") + Func.getName() +
".lds").str();
794 createLDSVariableReplacement(M, VarName, KernelUsedVariables);
801 !Accesses->second.empty())
802 markUsedByKernel(&Func, Replacement.SGV);
805 removeLocalVarsFromUsedLists(M, KernelUsedVariables);
806 KernelToReplacement[&Func] = Replacement;
809 replaceLDSVariablesWithStruct(
810 M, KernelUsedVariables, Replacement, [&Func](
Use &U) {
812 return I &&
I->getFunction() == &Func;
815 return KernelToReplacement;
835 Align MaxDynamicAlignment(1);
839 MaxDynamicAlignment =
845 UpdateMaxAlignment(GV);
849 UpdateMaxAlignment(GV);
858 N->setAlignment(MaxDynamicAlignment);
868 std::vector<Function *>
const &OrderedKernels) {
870 if (!KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
875 std::vector<Constant *> newDynamicLDS;
878 for (
auto &func : OrderedKernels) {
880 if (KernelsThatIndirectlyAllocateDynamicLDS.
contains(func)) {
887 buildRepresentativeDynamicLDSInstance(M, LDSUsesInfo, func);
889 KernelToCreatedDynamicLDS[func] =
N;
891 markUsedByKernel(func,
N);
895 emptyCharArray,
N, ConstantInt::get(I32, 0),
true);
901 assert(OrderedKernels.size() == newDynamicLDS.size());
903 ArrayType *t = ArrayType::get(I32, newDynamicLDS.size());
907 "llvm.amdgcn.dynlds.offset.table",
nullptr,
912 auto *
I = dyn_cast<Instruction>(U.getUser());
918 replaceUseWithTableLookup(M, Builder, table, GV, U,
nullptr);
922 return KernelToCreatedDynamicLDS;
925 bool runOnModule(
Module &M) {
927 bool Changed = superAlignLDSGlobals(M);
943 LDSToKernelsThatNeedToAccessItIndirectly[GV].
insert(
F);
952 partitionVariablesIntoIndirectStrategies(
953 M, LDSUsesInfo, LDSToKernelsThatNeedToAccessItIndirectly,
954 ModuleScopeVariables, TableLookupVariables, KernelAccessVariables,
961 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
962 ModuleScopeVariables);
964 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
965 TableLookupVariables);
968 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
971 GlobalVariable *MaybeModuleScopeStruct = lowerModuleScopeStructVariables(
972 M, ModuleScopeVariables, KernelsThatAllocateModuleLDS);
975 lowerKernelScopeStructVariables(M, LDSUsesInfo, ModuleScopeVariables,
976 KernelsThatAllocateModuleLDS,
977 MaybeModuleScopeStruct);
980 for (
auto &GV : KernelAccessVariables) {
981 auto &funcs = LDSToKernelsThatNeedToAccessItIndirectly[GV];
982 assert(funcs.size() == 1);
983 LDSVariableReplacement Replacement =
984 KernelToReplacement[*(funcs.begin())];
989 replaceLDSVariablesWithStruct(M, Vec, Replacement, [](
Use &U) {
990 return isa<Instruction>(U.getUser());
995 std::vector<Function *> OrderedKernels =
996 assignLDSKernelIDToEachKernel(&M, KernelsThatAllocateTableLDS,
997 KernelsThatIndirectlyAllocateDynamicLDS);
999 if (!KernelsThatAllocateTableLDS.
empty()) {
1005 auto TableLookupVariablesOrdered =
1006 sortByName(std::vector<GlobalVariable *>(TableLookupVariables.
begin(),
1007 TableLookupVariables.
end()));
1010 M, TableLookupVariablesOrdered, OrderedKernels, KernelToReplacement);
1011 replaceUsesInInstructionsWithTableLookup(M, TableLookupVariablesOrdered,
1018 for (
Function *
F : KernelsThatAllocateTableLDS)
1023 lowerDynamicLDSVariables(M, LDSUsesInfo,
1024 KernelsThatIndirectlyAllocateDynamicLDS,
1025 DynamicVariables, OrderedKernels);
1032 for (
Function &Func : M.functions()) {
1047 const bool AllocateModuleScopeStruct =
1048 MaybeModuleScopeStruct &&
1049 KernelsThatAllocateModuleLDS.
contains(&Func);
1051 auto Replacement = KernelToReplacement.
find(&Func);
1052 const bool AllocateKernelScopeStruct =
1053 Replacement != KernelToReplacement.
end();
1055 const bool AllocateDynamicVariable =
1056 KernelToCreatedDynamicLDS.
contains(&Func);
1060 if (AllocateModuleScopeStruct) {
1066 if (AllocateKernelScopeStruct) {
1069 recordLDSAbsoluteAddress(&M, KernelStruct,
Offset);
1077 if (AllocateDynamicVariable) {
1078 GlobalVariable *DynamicVariable = KernelToCreatedDynamicLDS[&Func];
1080 recordLDSAbsoluteAddress(&M, DynamicVariable,
Offset);
1095 if (AllocateDynamicVariable)
1098 Func.addFnAttr(
"amdgpu-lds-size", Buffer);
1117 static bool superAlignLDSGlobals(
Module &M) {
1119 bool Changed =
false;
1120 if (!SuperAlignLDSGlobals) {
1124 for (
auto &GV : M.globals()) {
1139 Alignment = std::max(Alignment,
Align(16));
1140 }
else if (GVSize > 4) {
1142 Alignment = std::max(Alignment,
Align(8));
1143 }
else if (GVSize > 2) {
1145 Alignment = std::max(Alignment,
Align(4));
1146 }
else if (GVSize > 1) {
1148 Alignment = std::max(Alignment,
Align(2));
1159 static LDSVariableReplacement createLDSVariableReplacement(
1160 Module &M, std::string VarName,
1177 auto Sorted = sortByName(std::vector<GlobalVariable *>(
1178 LDSVarsToTransform.
begin(), LDSVarsToTransform.
end()));
1190 std::vector<GlobalVariable *> LocalVars;
1193 IsPaddingField.
reserve(LDSVarsToTransform.
size());
1196 for (
auto &
F : LayoutFields) {
1199 Align DataAlign =
F.Alignment;
1202 if (
uint64_t Rem = CurrentOffset % DataAlignV) {
1203 uint64_t Padding = DataAlignV - Rem;
1215 CurrentOffset += Padding;
1218 LocalVars.push_back(FGV);
1220 CurrentOffset +=
F.Size;
1224 std::vector<Type *> LocalVarTypes;
1225 LocalVarTypes.reserve(LocalVars.size());
1227 LocalVars.cbegin(), LocalVars.cend(), std::back_inserter(LocalVarTypes),
1242 for (
size_t I = 0;
I < LocalVars.size();
I++) {
1244 Constant *GEPIdx[] = {ConstantInt::get(I32, 0), ConstantInt::get(I32,
I)};
1246 if (IsPaddingField[
I]) {
1253 assert(Map.size() == LDSVarsToTransform.
size());
1254 return {SGV, std::move(Map)};
1257 template <
typename PredicateTy>
1258 static void replaceLDSVariablesWithStruct(
1260 const LDSVariableReplacement &Replacement, PredicateTy Predicate) {
1267 auto LDSVarsToTransform = sortByName(std::vector<GlobalVariable *>(
1268 LDSVarsToTransformArg.
begin(), LDSVarsToTransformArg.
end()));
1274 const size_t NumberVars = LDSVarsToTransform.
size();
1275 if (NumberVars > 1) {
1277 AliasScopes.
reserve(NumberVars);
1279 for (
size_t I = 0;
I < NumberVars;
I++) {
1283 NoAliasList.
append(&AliasScopes[1], AliasScopes.
end());
1288 for (
size_t I = 0;
I < NumberVars;
I++) {
1290 Constant *
GEP = Replacement.LDSVarsToConstantGEP.at(GV);
1294 APInt APOff(
DL.getIndexTypeSizeInBits(
GEP->getType()), 0);
1295 GEP->stripAndAccumulateInBoundsConstantOffsets(
DL, APOff);
1302 NoAliasList[
I - 1] = AliasScopes[
I - 1];
1308 refineUsesAlignmentAndAA(
GEP,
A,
DL, AliasScope, NoAlias);
1315 if (!
MaxDepth || (
A == 1 && !AliasScope))
1318 for (
User *U :
Ptr->users()) {
1319 if (
auto *
I = dyn_cast<Instruction>(U)) {
1320 if (AliasScope &&
I->mayReadOrWriteMemory()) {
1321 MDNode *AS =
I->getMetadata(LLVMContext::MD_alias_scope);
1324 I->setMetadata(LLVMContext::MD_alias_scope, AS);
1326 MDNode *NA =
I->getMetadata(LLVMContext::MD_noalias);
1328 I->setMetadata(LLVMContext::MD_noalias, NA);
1332 if (
auto *LI = dyn_cast<LoadInst>(U)) {
1333 LI->setAlignment(std::max(
A, LI->getAlign()));
1336 if (
auto *SI = dyn_cast<StoreInst>(U)) {
1337 if (SI->getPointerOperand() ==
Ptr)
1338 SI->setAlignment(std::max(
A, SI->getAlign()));
1341 if (
auto *AI = dyn_cast<AtomicRMWInst>(U)) {
1344 if (AI->getPointerOperand() ==
Ptr)
1345 AI->setAlignment(std::max(
A, AI->getAlign()));
1348 if (
auto *AI = dyn_cast<AtomicCmpXchgInst>(U)) {
1349 if (AI->getPointerOperand() ==
Ptr)
1350 AI->setAlignment(std::max(
A, AI->getAlign()));
1353 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(U)) {
1354 unsigned BitWidth =
DL.getIndexTypeSizeInBits(
GEP->getType());
1356 if (
GEP->getPointerOperand() ==
Ptr) {
1358 if (
GEP->accumulateConstantOffset(
DL, Off))
1360 refineUsesAlignmentAndAA(
GEP, GA,
DL, AliasScope, NoAlias,
1365 if (
auto *
I = dyn_cast<Instruction>(U)) {
1366 if (
I->getOpcode() == Instruction::BitCast ||
1367 I->getOpcode() == Instruction::AddrSpaceCast)
1368 refineUsesAlignmentAndAA(
I,
A,
DL, AliasScope, NoAlias,
MaxDepth - 1);
1374class AMDGPULowerModuleLDSLegacy :
public ModulePass {
1391 auto &TPC = getAnalysis<TargetPassConfig>();
1395 return AMDGPULowerModuleLDS(*TM).runOnModule(M);
1400char AMDGPULowerModuleLDSLegacy::ID = 0;
1405 "Lower uses of LDS variables from non-kernel functions",
1414 return new AMDGPULowerModuleLDSLegacy(TM);
Lower uses of LDS variables from non kernel functions
The AMDGPU TargetMachine interface definition for hw codegen targets.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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...
#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.