195#include "llvm/IR/IntrinsicsAMDGPU.h"
208#define DEBUG_TYPE "amdgpu-lower-module-lds"
215template <
typename T> std::vector<T> sortByName(std::vector<T> &&
V) {
217 return L->getName() < R->getName();
219 return {std::move(
V)};
222class AMDGPULowerModuleLDS {
226 removeLocalVarsFromUsedLists(
Module &M,
238 LocalVar->removeDeadConstantUsers();
266 Func->getParent(), Intrinsic::donothing, {});
268 Value *UseInstance[] = {SGV};
277 struct LDSVariableReplacement {
287 static Constant *getAddressesOfVariablesInKernel(
299 auto ConstantGepIt = LDSVarsToConstantGEP.
find(GV);
300 if (ConstantGepIt != LDSVarsToConstantGEP.
end()) {
301 Elements.push_back(ConstantGepIt->second);
313 if (Variables.
empty()) {
318 const size_t NumberVariables = Variables.
size();
319 const size_t NumberKernels = kernels.
size();
328 std::vector<Constant *> overallConstantExprElts(NumberKernels);
329 for (
size_t i = 0; i < NumberKernels; i++) {
330 auto Replacement = KernelToReplacement.
find(kernels[i]);
331 overallConstantExprElts[i] =
332 (Replacement == KernelToReplacement.
end())
334 : getAddressesOfVariablesInKernel(
335 Ctx, Variables, Replacement->second.LDSVarsToConstantGEP);
350 Value *OptionalIndex) {
356 Value *tableKernelIndex = getTableLookupKernelIndex(M,
I->getFunction());
362 Builder.SetInsertPoint(
I);
366 ConstantInt::get(I32, 0),
372 Value *Address = Builder.CreateInBoundsGEP(
373 LookupTable->getValueType(), LookupTable, GEPIdx, GV->
getName());
375 Value *Loaded = Builder.CreateLoad(GV->
getType(), Address);
379 void replaceUsesInInstructionsWithTableLookup(
387 for (
size_t Index = 0; Index < ModuleScopeVariables.
size(); Index++) {
388 auto *GV = ModuleScopeVariables[Index];
395 replaceUseWithTableLookup(M, Builder, LookupTable, GV, U,
396 ConstantInt::get(I32, Index));
407 if (VariableSet.
empty())
410 for (
Function &Func : M.functions()) {
411 if (Func.isDeclaration() || !
isKernel(Func))
425 chooseBestVariableForModuleStrategy(
const DataLayout &
DL,
431 size_t UserCount = 0;
434 CandidateTy() =
default;
437 : GV(GV), UserCount(UserCount),
Size(AllocSize) {}
441 if (UserCount <
Other.UserCount) {
444 if (UserCount >
Other.UserCount) {
462 CandidateTy MostUsed;
464 for (
auto &
K : LDSVars) {
466 if (
K.second.size() <= 1) {
472 if (MostUsed < Candidate)
473 MostUsed = Candidate;
497 auto [It, Inserted] = tableKernelIndexCache.
try_emplace(
F);
499 auto InsertAt =
F->getEntryBlock().getFirstNonPHIOrAlloca();
502 It->second = Builder.CreateIntrinsic(Intrinsic::amdgcn_lds_kernel_id, {});
508 static std::vector<Function *> assignLDSKernelIDToEachKernel(
516 std::vector<Function *> OrderedKernels;
517 if (!KernelsThatAllocateTableLDS.
empty() ||
518 !KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
520 for (
Function &Func : M->functions()) {
521 if (Func.isDeclaration())
526 if (KernelsThatAllocateTableLDS.
contains(&Func) ||
527 KernelsThatIndirectlyAllocateDynamicLDS.
contains(&Func)) {
529 OrderedKernels.push_back(&Func);
534 OrderedKernels = sortByName(std::move(OrderedKernels));
540 if (OrderedKernels.size() > UINT32_MAX) {
545 for (
size_t i = 0; i < OrderedKernels.size(); i++) {
549 OrderedKernels[i]->setMetadata(
"llvm.amdgcn.lds.kernel.id",
553 return OrderedKernels;
556 void partitionVariablesIntoIndirectStrategies(
566 LoweringKind != LDSLoweringKind::hybrid
568 : chooseBestVariableForModuleStrategy(
569 M.getDataLayout(), LDSToKernelsThatNeedToAccessItIndirectly);
574 ? LDSToKernelsThatNeedToAccessItIndirectly[HybridModuleRoot]
577 for (
auto &
K : LDSToKernelsThatNeedToAccessItIndirectly) {
586 DynamicVariables.
insert(GV);
590 switch (LoweringKind) {
591 case LDSLoweringKind::module:
592 ModuleScopeVariables.insert(GV);
595 case LDSLoweringKind::table:
596 TableLookupVariables.
insert(GV);
599 case LDSLoweringKind::kernel:
600 if (
K.second.size() == 1) {
601 KernelAccessVariables.
insert(GV);
605 "cannot lower LDS '" + GV->
getName() +
606 "' to kernel access as it is reachable from multiple kernels");
610 case LDSLoweringKind::hybrid: {
611 if (GV == HybridModuleRoot) {
613 ModuleScopeVariables.insert(GV);
614 }
else if (
K.second.size() == 1) {
615 KernelAccessVariables.
insert(GV);
616 }
else if (
K.second == HybridModuleRootKernels) {
617 ModuleScopeVariables.insert(GV);
619 TableLookupVariables.
insert(GV);
628 assert(ModuleScopeVariables.
size() + TableLookupVariables.
size() +
629 KernelAccessVariables.
size() + DynamicVariables.
size() ==
630 LDSToKernelsThatNeedToAccessItIndirectly.size());
643 if (ModuleScopeVariables.
empty()) {
649 LDSVariableReplacement ModuleScopeReplacement =
650 createLDSVariableReplacement(M,
"llvm.amdgcn.module.lds",
651 ModuleScopeVariables);
659 recordLDSAbsoluteAddress(&M, ModuleScopeReplacement.SGV, 0);
662 removeLocalVarsFromUsedLists(M, ModuleScopeVariables);
665 replaceLDSVariablesWithStruct(
666 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
679 for (
Function &Func : M.functions()) {
680 if (Func.isDeclaration() || !
isKernel(Func))
683 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
684 replaceLDSVariablesWithStruct(
685 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
694 markUsedByKernel(&Func, ModuleScopeReplacement.SGV);
698 return ModuleScopeReplacement.SGV;
702 lowerKernelScopeStructVariables(
711 for (
Function &Func : M.functions()) {
712 if (Func.isDeclaration() || !
isKernel(Func))
720 KernelUsedVariables.
insert(v);
728 KernelUsedVariables.
insert(v);
734 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
736 KernelUsedVariables.
erase(v);
740 if (KernelUsedVariables.
empty()) {
752 if (!Func.hasName()) {
756 std::string VarName =
757 (
Twine(
"llvm.amdgcn.kernel.") + Func.getName() +
".lds").str();
760 createLDSVariableReplacement(M, VarName, KernelUsedVariables);
768 markUsedByKernel(&Func, Replacement.SGV);
771 removeLocalVarsFromUsedLists(M, KernelUsedVariables);
772 KernelToReplacement[&Func] = Replacement;
775 replaceLDSVariablesWithStruct(
776 M, KernelUsedVariables, Replacement, [&Func](
Use &U) {
778 return I &&
I->getFunction() == &Func;
781 return KernelToReplacement;
801 Align MaxDynamicAlignment(1);
805 MaxDynamicAlignment =
811 UpdateMaxAlignment(GV);
815 UpdateMaxAlignment(GV);
822 Twine(
"llvm.amdgcn." + func->
getName() +
".dynlds"),
nullptr,
824 N->setAlignment(MaxDynamicAlignment);
834 std::vector<Function *>
const &OrderedKernels) {
836 if (!KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
841 std::vector<Constant *> newDynamicLDS;
844 for (
auto &func : OrderedKernels) {
846 if (KernelsThatIndirectlyAllocateDynamicLDS.
contains(func)) {
853 buildRepresentativeDynamicLDSInstance(M, LDSUsesInfo, func);
855 KernelToCreatedDynamicLDS[func] =
N;
857 markUsedByKernel(func,
N);
859 newDynamicLDS.push_back(
N);
864 assert(OrderedKernels.size() == newDynamicLDS.size());
870 "llvm.amdgcn.dynlds.offset.table",
nullptr,
881 replaceUseWithTableLookup(M, Builder,
table, GV, U,
nullptr);
885 return KernelToCreatedDynamicLDS;
891 bool runOnModuleLinkTime(
Module &M) {
892 bool Changed = superAlignLDSGlobals(M);
901 if (KernelLDSUses.
empty() && FunctionLDSUses.
empty())
905 assert(!ModuleId.empty() &&
906 "modules with LDS variables should have a unique ID");
909 for (
auto &[
F, Vars] : KernelLDSUses)
910 AllLDSUses[
F].
insert(Vars.begin(), Vars.end());
911 for (
auto &[
F, Vars] : FunctionLDSUses)
912 AllLDSUses[
F].
insert(Vars.begin(), Vars.end());
916 for (
auto &[
F, Vars] : AllLDSUses) {
918 VarToFuncs[
V].push_back(
F);
927 for (
auto &[
V, Funcs] : VarToFuncs) {
928 if (!
V->hasLocalLinkage() || Funcs.size() > 1) {
930 if (
V->hasLocalLinkage())
931 InternalMultiUserVars.
insert(
V);
939 for (
auto &KV : AllLDSUses) {
943 if (!GlobalScopeVars.
count(
V))
947 if (FuncScopeVars.
empty())
952 ? (
"__amdgpu_lds." +
F->getName() +
"." + ModuleId).str()
953 : (
"__amdgpu_lds." +
F->getName()).str();
954 LDSVariableReplacement Replacement =
955 createLDSVariableReplacement(M,
StructName, FuncScopeVars);
959 SGV->setInitializer(
nullptr);
962 replaceLDSVariablesWithStruct(
963 M, FuncScopeVars, Replacement, [
F](
const Use &U) {
965 return I &&
I->getFunction() ==
F;
968 AllReplacedVars.
insert(FuncScopeVars.
begin(), FuncScopeVars.
end());
975 if (!InternalMultiUserVars.
empty()) {
976 std::string
StructName =
"__amdgpu_lds.__internal." + ModuleId;
977 LDSVariableReplacement Replacement =
978 createLDSVariableReplacement(M,
StructName, InternalMultiUserVars);
982 SGV->setInitializer(
nullptr);
984 replaceLDSVariablesWithStruct(
985 M, InternalMultiUserVars, Replacement,
991 FuncsUsingInternalVars.insert(
F);
993 for (
Function *
F : FuncsUsingInternalVars)
996 AllReplacedVars.
insert(InternalMultiUserVars.begin(),
997 InternalMultiUserVars.end());
1003 V->setInitializer(
nullptr);
1010 NamedMDNode *LdsMD = M.getOrInsertNamedMetadata(
"amdgpu.lds.uses");
1012 for (
auto &[
F, SGV] : FuncToLdsStruct)
1016 for (
auto &[
V, Funcs] : VarToFuncs) {
1017 if (GlobalScopeVars.
count(
V) && !InternalMultiUserVars.
count(
V)) {
1027 AllLDSVarsForCleanup.
insert(GlobalScopeVars.
begin(), GlobalScopeVars.
end());
1028 removeLocalVarsFromUsedLists(M, AllLDSVarsForCleanup);
1038 bool runOnModule(
Module &M) {
1040 return runOnModuleLinkTime(M);
1041 return runOnModuleNormal(M);
1044 bool runOnModuleNormal(
Module &M) {
1045 bool Changed = superAlignLDSGlobals(M);
1052 isNotYetLoweredLDSVariable);
1064 LDSToKernelsThatNeedToAccessItIndirectly[GV].insert(
F);
1073 partitionVariablesIntoIndirectStrategies(
1074 M, LDSUsesInfo, LDSToKernelsThatNeedToAccessItIndirectly,
1075 ModuleScopeVariables, TableLookupVariables, KernelAccessVariables,
1082 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1083 ModuleScopeVariables);
1085 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1086 TableLookupVariables);
1089 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1092 GlobalVariable *MaybeModuleScopeStruct = lowerModuleScopeStructVariables(
1093 M, ModuleScopeVariables, KernelsThatAllocateModuleLDS);
1096 lowerKernelScopeStructVariables(M, LDSUsesInfo, ModuleScopeVariables,
1097 KernelsThatAllocateModuleLDS,
1098 MaybeModuleScopeStruct);
1101 for (
auto &GV : KernelAccessVariables) {
1102 auto &funcs = LDSToKernelsThatNeedToAccessItIndirectly[GV];
1103 assert(funcs.size() == 1);
1104 LDSVariableReplacement Replacement =
1105 KernelToReplacement[*(funcs.begin())];
1110 replaceLDSVariablesWithStruct(M, Vec, Replacement, [](
Use &U) {
1116 std::vector<Function *> OrderedKernels =
1117 assignLDSKernelIDToEachKernel(&M, KernelsThatAllocateTableLDS,
1118 KernelsThatIndirectlyAllocateDynamicLDS);
1120 if (!KernelsThatAllocateTableLDS.
empty()) {
1123 auto TableLookupVariablesOrdered =
1124 sortByName(std::vector<GlobalVariable *>(TableLookupVariables.
begin(),
1125 TableLookupVariables.
end()));
1128 M, TableLookupVariablesOrdered, OrderedKernels, KernelToReplacement);
1129 replaceUsesInInstructionsWithTableLookup(M, TableLookupVariablesOrdered,
1134 lowerDynamicLDSVariables(M, LDSUsesInfo,
1135 KernelsThatIndirectlyAllocateDynamicLDS,
1136 DynamicVariables, OrderedKernels);
1141 for (
auto *KernelSet : {&KernelsThatIndirectlyAllocateDynamicLDS,
1142 &KernelsThatAllocateTableLDS})
1151 for (
Function &Func : M.functions()) {
1152 if (Func.isDeclaration() || !
isKernel(Func))
1166 const bool AllocateModuleScopeStruct =
1167 MaybeModuleScopeStruct &&
1168 KernelsThatAllocateModuleLDS.
contains(&Func);
1170 auto Replacement = KernelToReplacement.
find(&Func);
1171 const bool AllocateKernelScopeStruct =
1172 Replacement != KernelToReplacement.
end();
1174 const bool AllocateDynamicVariable =
1175 KernelToCreatedDynamicLDS.
contains(&Func);
1179 if (AllocateModuleScopeStruct) {
1185 if (AllocateKernelScopeStruct) {
1188 recordLDSAbsoluteAddress(&M, KernelStruct,
Offset);
1196 if (AllocateDynamicVariable) {
1197 GlobalVariable *DynamicVariable = KernelToCreatedDynamicLDS[&Func];
1199 recordLDSAbsoluteAddress(&M, DynamicVariable,
Offset);
1214 if (AllocateDynamicVariable)
1217 Func.addFnAttr(
"amdgpu-lds-size", Buffer);
1223 if (isNotYetLoweredLDSVariable(GV)) {
1235 static bool isNotYetLoweredLDSVariable(
const GlobalVariable &GV) {
1241 bool superAlignLDSGlobals(
Module &M) {
1244 if (!TM.
getCLOpts().super_align_lds_globals) {
1248 for (
auto &GV : M.globals()) {
1268 Alignment = std::max(Alignment,
Align(16));
1269 }
else if (GVSize > 4) {
1271 Alignment = std::max(Alignment,
Align(8));
1272 }
else if (GVSize > 2) {
1274 Alignment = std::max(Alignment,
Align(4));
1275 }
else if (GVSize > 1) {
1277 Alignment = std::max(Alignment,
Align(2));
1288 static LDSVariableReplacement createLDSVariableReplacement(
1289 Module &M, std::string VarName,
1306 auto Sorted = sortByName(std::vector<GlobalVariable *>(
1307 LDSVarsToTransform.
begin(), LDSVarsToTransform.
end()));
1318 std::vector<GlobalVariable *> LocalVars;
1320 LocalVars.reserve(LDSVarsToTransform.
size());
1321 IsPaddingField.
reserve(LDSVarsToTransform.
size());
1324 for (
auto &
F : LayoutFields) {
1327 Align DataAlign =
F.Alignment;
1330 if (
uint64_t Rem = CurrentOffset % DataAlignV) {
1331 uint64_t Padding = DataAlignV - Rem;
1343 CurrentOffset += Padding;
1346 LocalVars.push_back(FGV);
1348 CurrentOffset +=
F.Size;
1352 std::vector<Type *> LocalVarTypes;
1353 LocalVarTypes.reserve(LocalVars.size());
1355 LocalVars.cbegin(), LocalVars.cend(), std::back_inserter(LocalVarTypes),
1366 SGV->setAlignment(StructAlign);
1370 for (
size_t I = 0;
I < LocalVars.size();
I++) {
1372 Constant *GEPIdx[] = {ConstantInt::get(I32, 0), ConstantInt::get(I32,
I)};
1375 if (IsPaddingField[
I]) {
1382 assert(Map.size() == LDSVarsToTransform.
size());
1383 return {SGV, std::move(Map)};
1386 template <
typename PredicateTy>
1387 static void replaceLDSVariablesWithStruct(
1389 const LDSVariableReplacement &Replacement, PredicateTy
Predicate) {
1396 auto LDSVarsToTransform = sortByName(std::vector<GlobalVariable *>(
1397 LDSVarsToTransformArg.
begin(), LDSVarsToTransformArg.
end()));
1403 const size_t NumberVars = LDSVarsToTransform.
size();
1404 if (NumberVars > 1) {
1406 AliasScopes.
reserve(NumberVars);
1408 for (
size_t I = 0;
I < NumberVars;
I++) {
1412 NoAliasList.
append(&AliasScopes[1], AliasScopes.
end());
1417 for (
size_t I = 0;
I < NumberVars;
I++) {
1419 Constant *
GEP = Replacement.LDSVarsToConstantGEP.at(GV);
1423 APInt APOff(
DL.getIndexTypeSizeInBits(
GEP->getType()), 0);
1424 GEP->stripAndAccumulateInBoundsConstantOffsets(
DL, APOff);
1431 NoAliasList[
I - 1] = AliasScopes[
I - 1];
1437 refineUsesAlignmentAndAA(
GEP,
A,
DL, AliasScope, NoAlias);
1441 static void refineUsesAlignmentAndAA(
Value *Ptr,
Align A,
1443 MDNode *NoAlias,
unsigned MaxDepth = 5) {
1444 if (!MaxDepth || (
A == 1 && !AliasScope))
1449 if (AliasScope &&
I->mayReadOrWriteMemory()) {
1450 MDNode *AS =
I->getMetadata(LLVMContext::MD_alias_scope);
1453 I->setMetadata(LLVMContext::MD_alias_scope, AS);
1455 MDNode *NA =
I->getMetadata(LLVMContext::MD_noalias);
1479 if (Intersection.empty()) {
1484 I->setMetadata(LLVMContext::MD_noalias, NA);
1489 LI->setAlignment(std::max(
A, LI->getAlign()));
1493 if (
SI->getPointerOperand() == Ptr)
1494 SI->setAlignment(std::max(
A,
SI->getAlign()));
1500 if (AI->getPointerOperand() == Ptr)
1501 AI->setAlignment(std::max(
A, AI->getAlign()));
1505 if (AI->getPointerOperand() == Ptr)
1506 AI->setAlignment(std::max(
A, AI->getAlign()));
1510 unsigned BitWidth =
DL.getIndexTypeSizeInBits(
GEP->getType());
1512 if (
GEP->getPointerOperand() == Ptr) {
1514 if (
GEP->accumulateConstantOffset(
DL,
Off))
1516 refineUsesAlignmentAndAA(
GEP, GA,
DL, AliasScope, NoAlias,
1522 if (
I->getOpcode() == Instruction::BitCast ||
1523 I->getOpcode() == Instruction::AddrSpaceCast)
1524 refineUsesAlignmentAndAA(
I,
A,
DL, AliasScope, NoAlias, MaxDepth - 1);
1530class AMDGPULowerModuleLDSLegacy :
public ModulePass {
1543 bool runOnModule(
Module &M)
override {
1545 auto &TPC = getAnalysis<TargetPassConfig>();
1554char AMDGPULowerModuleLDSLegacy::ID = 0;
1559 "Lower uses of LDS variables from non-kernel functions",
1563 "Lower uses of LDS variables from non-kernel functions",
1568 return new AMDGPULowerModuleLDSLegacy(TM);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
The AMDGPU TargetMachine interface definition for hw codegen targets.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file implements the BitVector class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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 ...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
DXIL Forward Handle Accesses
const std::string FatArchTraits< MachO::fat_arch >::StructName
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)
This is the interface for a metadata-based scoped no-alias analysis.
This file defines generic set operations that may be used on set's of different types,...
Target-Independent Code Generator Pass Configuration Options pass.
const AMDGPUOptions & getCLOpts() const
static bool EnableObjectLinking
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
bool empty() const
Check if the array is empty.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM Basic Block Representation.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
void reserve(unsigned N)
Reserve space for atleast N bits in the bitvector.
The basic data container for the call graph of a Module of IR.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH 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.
LLVM_ABI 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.
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Implements a dense probed hash-table based set.
static GEPNoWrapFlags inBounds()
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
LLVM_ABI bool isAbsoluteSymbolRef() const
Returns whether this is a reference to an absolute symbol.
PointerType * getType() const
Global values are always pointers.
@ InternalLinkage
Rename collisions when linking (static functions).
@ ExternalLinkage
Externally visible function.
bool hasInitializer() const
Definitions have initializers, declarations don't.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
LLVM_ABI void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
void setAlignment(Align Align)
Sets the alignment attribute of the GlobalVariable.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
bool runOnModule(Module &) override
ImmutablePasses are never run.
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.
LLVM_ABI MDNode * createAnonymousAliasScopeDomain(StringRef Description=StringRef(), bool DisjointScopes=false)
Return metadata appropriate for an alias scope domain node, described by Description,...
static LLVM_ABI MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
static LLVM_ABI MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI MDNode * intersect(MDNode *A, MDNode *B)
iterator find(const KeyT &Key)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
LLVM_ABI void addOperand(MDNode *M)
A container for an operand bundle being viewed as a set of values rather than a set of uses.
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
static LLVM_ABI PointerType * get(LLVMContext &C, unsigned AddressSpace)
This constructs an opaque pointer to an object in a numbered address space.
static LLVM_ABI 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.
static LLVM_ABI void collectScopedDomains(const MDNode *NoAlias, SmallPtrSetImpl< const MDNode * > &Domains, bool DisjointOnly=false)
Collect the set of scoped domains relevant to the noalias scopes.
bool insert(const value_type &X)
Insert a new element into the SetVector.
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 LLVM_ABI 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.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
iterator_range< user_iterator > users()
LLVM_ABI bool 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()
LLVM_ABI 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)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
A raw_ostream that writes to an std::string.
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
GVUsesInfoTy getTransitiveUsesOfLDSForLowering(const CallGraph &CG, Module &M)
Collects all uses of LDS Global Variables in M using getUsesOfGVByFunction, with isLDSVariableToLower...
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.
bool eliminateGVConstantExprUsesFromAllInstructions(Module &M, function_ref< bool(const GlobalVariable &)> Filter)
Iterates over all GlobalVariables in M, and whenever Filter returns true, replace all constant users ...
LLVM_READNONE constexpr bool isKernel(CallingConv::ID CC)
void getUsesOfGVByFunction(const CallGraph &CG, Module &M, function_ref< bool(const GlobalVariable &)> Filter, FunctionVariableMap &Kernels, FunctionVariableMap &Functions)
Finds uses of Global Variables on a per-function basis.
MapVector< Function *, DenseSet< GlobalVariable * > > FunctionVariableMap
bool isLDSVariableToLower(const GlobalVariable &GV)
Align getAlign(const DataLayout &DL, const GlobalVariable *GV)
DenseMap< GlobalVariable *, DenseSet< Function * > > VariableFunctionMap
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
void sort(IteratorTy Start, IteratorTy End)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
char & AMDGPULowerModuleLDSLegacyPassID
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
S1Ty set_intersection(const S1Ty &S1, const S2Ty &S2)
set_intersection(A, B) - Return A ^ B
LLVM_ABI 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)
LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)
Adds global values to the llvm.compiler.used list.
LLVM_ABI 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...
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const AMDGPUTargetMachine & TM
FunctionVariableMap DirectAccess
FunctionVariableMap IndirectAccess
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.