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);
873 bool SeenUnknownCall =
false;
875 while (!WorkList.empty()) {
878 for (
auto &CallRecord : *CG[
F]) {
879 if (!CallRecord.second)
882 Function *Callee = CallRecord.second->getFunction();
884 if (!SeenUnknownCall) {
885 SeenUnknownCall =
true;
895 PotentialCallee->
removeFnAttr(
"amdgpu-no-lds-kernel-id");
899 Callee->removeFnAttr(
"amdgpu-no-lds-kernel-id");
900 if (Visited.
insert(Callee).second)
901 WorkList.push_back(Callee);
911 std::vector<Function *>
const &OrderedKernels) {
913 if (!KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
918 std::vector<Constant *> newDynamicLDS;
921 for (
auto &func : OrderedKernels) {
923 if (KernelsThatIndirectlyAllocateDynamicLDS.
contains(func)) {
930 buildRepresentativeDynamicLDSInstance(M, LDSUsesInfo, func);
932 KernelToCreatedDynamicLDS[func] =
N;
934 markUsedByKernel(func,
N);
938 emptyCharArray,
N, ConstantInt::get(I32, 0),
true);
944 assert(OrderedKernels.size() == newDynamicLDS.size());
946 ArrayType *t = ArrayType::get(I32, newDynamicLDS.size());
950 "llvm.amdgcn.dynlds.offset.table",
nullptr,
955 auto *
I = dyn_cast<Instruction>(U.getUser());
961 replaceUseWithTableLookup(M, Builder, table, GV, U,
nullptr);
965 return KernelToCreatedDynamicLDS;
968 bool runOnModule(
Module &M) {
970 bool Changed = superAlignLDSGlobals(M);
986 LDSToKernelsThatNeedToAccessItIndirectly[GV].
insert(
F);
995 partitionVariablesIntoIndirectStrategies(
996 M, LDSUsesInfo, LDSToKernelsThatNeedToAccessItIndirectly,
997 ModuleScopeVariables, TableLookupVariables, KernelAccessVariables,
1004 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1005 ModuleScopeVariables);
1007 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1008 TableLookupVariables);
1011 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1014 GlobalVariable *MaybeModuleScopeStruct = lowerModuleScopeStructVariables(
1015 M, ModuleScopeVariables, KernelsThatAllocateModuleLDS);
1018 lowerKernelScopeStructVariables(M, LDSUsesInfo, ModuleScopeVariables,
1019 KernelsThatAllocateModuleLDS,
1020 MaybeModuleScopeStruct);
1023 for (
auto &GV : KernelAccessVariables) {
1024 auto &funcs = LDSToKernelsThatNeedToAccessItIndirectly[GV];
1025 assert(funcs.size() == 1);
1026 LDSVariableReplacement Replacement =
1027 KernelToReplacement[*(funcs.begin())];
1032 replaceLDSVariablesWithStruct(M, Vec, Replacement, [](
Use &U) {
1033 return isa<Instruction>(U.getUser());
1038 std::vector<Function *> OrderedKernels =
1039 assignLDSKernelIDToEachKernel(&M, KernelsThatAllocateTableLDS,
1040 KernelsThatIndirectlyAllocateDynamicLDS);
1042 if (!KernelsThatAllocateTableLDS.
empty()) {
1048 auto TableLookupVariablesOrdered =
1049 sortByName(std::vector<GlobalVariable *>(TableLookupVariables.
begin(),
1050 TableLookupVariables.
end()));
1053 M, TableLookupVariablesOrdered, OrderedKernels, KernelToReplacement);
1054 replaceUsesInInstructionsWithTableLookup(M, TableLookupVariablesOrdered,
1061 for (
Function *
F : KernelsThatAllocateTableLDS)
1062 removeNoLdsKernelIdFromReachable(CG,
F);
1066 lowerDynamicLDSVariables(M, LDSUsesInfo,
1067 KernelsThatIndirectlyAllocateDynamicLDS,
1068 DynamicVariables, OrderedKernels);
1075 for (
Function &Func : M.functions()) {
1090 const bool AllocateModuleScopeStruct =
1091 MaybeModuleScopeStruct &&
1092 KernelsThatAllocateModuleLDS.
contains(&Func);
1094 auto Replacement = KernelToReplacement.
find(&Func);
1095 const bool AllocateKernelScopeStruct =
1096 Replacement != KernelToReplacement.
end();
1098 const bool AllocateDynamicVariable =
1099 KernelToCreatedDynamicLDS.
contains(&Func);
1103 if (AllocateModuleScopeStruct) {
1109 if (AllocateKernelScopeStruct) {
1112 recordLDSAbsoluteAddress(&M, KernelStruct,
Offset);
1120 if (AllocateDynamicVariable) {
1121 GlobalVariable *DynamicVariable = KernelToCreatedDynamicLDS[&Func];
1123 recordLDSAbsoluteAddress(&M, DynamicVariable,
Offset);
1138 if (AllocateDynamicVariable)
1141 Func.addFnAttr(
"amdgpu-lds-size", Buffer);
1160 static bool superAlignLDSGlobals(
Module &M) {
1162 bool Changed =
false;
1163 if (!SuperAlignLDSGlobals) {
1167 for (
auto &GV : M.globals()) {
1182 Alignment = std::max(Alignment,
Align(16));
1183 }
else if (GVSize > 4) {
1185 Alignment = std::max(Alignment,
Align(8));
1186 }
else if (GVSize > 2) {
1188 Alignment = std::max(Alignment,
Align(4));
1189 }
else if (GVSize > 1) {
1191 Alignment = std::max(Alignment,
Align(2));
1202 static LDSVariableReplacement createLDSVariableReplacement(
1203 Module &M, std::string VarName,
1220 auto Sorted = sortByName(std::vector<GlobalVariable *>(
1221 LDSVarsToTransform.
begin(), LDSVarsToTransform.
end()));
1233 std::vector<GlobalVariable *> LocalVars;
1236 IsPaddingField.
reserve(LDSVarsToTransform.
size());
1239 for (
size_t I = 0;
I < LayoutFields.
size();
I++) {
1241 const_cast<void *
>(LayoutFields[
I].Id));
1242 Align DataAlign = LayoutFields[
I].Alignment;
1245 if (
uint64_t Rem = CurrentOffset % DataAlignV) {
1246 uint64_t Padding = DataAlignV - Rem;
1258 CurrentOffset += Padding;
1261 LocalVars.push_back(FGV);
1263 CurrentOffset += LayoutFields[
I].
Size;
1267 std::vector<Type *> LocalVarTypes;
1268 LocalVarTypes.reserve(LocalVars.size());
1270 LocalVars.cbegin(), LocalVars.cend(), std::back_inserter(LocalVarTypes),
1285 for (
size_t I = 0;
I < LocalVars.size();
I++) {
1287 Constant *GEPIdx[] = {ConstantInt::get(I32, 0), ConstantInt::get(I32,
I)};
1289 if (IsPaddingField[
I]) {
1296 assert(Map.size() == LDSVarsToTransform.
size());
1297 return {SGV, std::move(Map)};
1300 template <
typename PredicateTy>
1301 static void replaceLDSVariablesWithStruct(
1303 const LDSVariableReplacement &Replacement, PredicateTy Predicate) {
1310 auto LDSVarsToTransform = sortByName(std::vector<GlobalVariable *>(
1311 LDSVarsToTransformArg.
begin(), LDSVarsToTransformArg.
end()));
1317 const size_t NumberVars = LDSVarsToTransform.
size();
1318 if (NumberVars > 1) {
1320 AliasScopes.
reserve(NumberVars);
1322 for (
size_t I = 0;
I < NumberVars;
I++) {
1326 NoAliasList.
append(&AliasScopes[1], AliasScopes.
end());
1331 for (
size_t I = 0;
I < NumberVars;
I++) {
1333 Constant *
GEP = Replacement.LDSVarsToConstantGEP.at(GV);
1337 APInt APOff(
DL.getIndexTypeSizeInBits(
GEP->getType()), 0);
1338 GEP->stripAndAccumulateInBoundsConstantOffsets(
DL, APOff);
1345 NoAliasList[
I - 1] = AliasScopes[
I - 1];
1351 refineUsesAlignmentAndAA(
GEP,
A,
DL, AliasScope, NoAlias);
1358 if (!
MaxDepth || (
A == 1 && !AliasScope))
1361 for (
User *U :
Ptr->users()) {
1362 if (
auto *
I = dyn_cast<Instruction>(U)) {
1363 if (AliasScope &&
I->mayReadOrWriteMemory()) {
1364 MDNode *AS =
I->getMetadata(LLVMContext::MD_alias_scope);
1367 I->setMetadata(LLVMContext::MD_alias_scope, AS);
1369 MDNode *NA =
I->getMetadata(LLVMContext::MD_noalias);
1371 I->setMetadata(LLVMContext::MD_noalias, NA);
1375 if (
auto *LI = dyn_cast<LoadInst>(U)) {
1376 LI->setAlignment(std::max(
A, LI->getAlign()));
1379 if (
auto *SI = dyn_cast<StoreInst>(U)) {
1380 if (SI->getPointerOperand() ==
Ptr)
1381 SI->setAlignment(std::max(
A, SI->getAlign()));
1384 if (
auto *AI = dyn_cast<AtomicRMWInst>(U)) {
1387 if (AI->getPointerOperand() ==
Ptr)
1388 AI->setAlignment(std::max(
A, AI->getAlign()));
1391 if (
auto *AI = dyn_cast<AtomicCmpXchgInst>(U)) {
1392 if (AI->getPointerOperand() ==
Ptr)
1393 AI->setAlignment(std::max(
A, AI->getAlign()));
1396 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(U)) {
1397 unsigned BitWidth =
DL.getIndexTypeSizeInBits(
GEP->getType());
1399 if (
GEP->getPointerOperand() ==
Ptr) {
1401 if (
GEP->accumulateConstantOffset(
DL, Off))
1403 refineUsesAlignmentAndAA(
GEP, GA,
DL, AliasScope, NoAlias,
1408 if (
auto *
I = dyn_cast<Instruction>(U)) {
1409 if (
I->getOpcode() == Instruction::BitCast ||
1410 I->getOpcode() == Instruction::AddrSpaceCast)
1411 refineUsesAlignmentAndAA(
I,
A,
DL, AliasScope, NoAlias,
MaxDepth - 1);
1417class AMDGPULowerModuleLDSLegacy :
public ModulePass {
1434 auto &TPC = getAnalysis<TargetPassConfig>();
1438 return AMDGPULowerModuleLDS(*TM).runOnModule(M);
1443char AMDGPULowerModuleLDSLegacy::ID = 0;
1448 "Lower uses of LDS variables from non-kernel functions",
1457 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.
CallGraphNode * getExternalCallingNode() const
Returns the CallGraphNode which is used to represent undetermined calls into the callgraph.
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, bool InBounds=false, 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.
const Function & getFunction() const
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
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.
iterator insert(iterator I, T &&Elt)
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)
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.