195#include "llvm/IR/IntrinsicsAMDGPU.h"
213#define DEBUG_TYPE "amdgpu-lower-module-lds"
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")));
249template <
typename T> std::vector<T> sortByName(std::vector<T> &&V) {
250 llvm::sort(V.begin(), V.end(), [](
const auto *L,
const auto *R) {
251 return L->getName() < R->getName();
253 return {std::move(V)};
256class AMDGPULowerModuleLDS {
260 removeLocalVarsFromUsedLists(
Module &M,
266 LocalVarsSet.
insert(cast<Constant>(LocalVar->stripPointerCasts()));
272 LocalVar->removeDeadConstantUsers();
297 IRBuilder<> Builder(Entry, Entry->getFirstNonPHIIt());
302 Value *UseInstance[1] = {
309 static bool eliminateConstantExprUsesOfLDSFromAllInstructions(
Module &M) {
324 for (
auto &GV : M.globals())
339 FunctionVariableMap &kernels,
344 for (
auto &GV : M.globals()) {
349 if (GV.isAbsoluteSymbolRef()) {
351 "LDS variables with absolute addresses are unimplemented.");
354 for (
User *V : GV.users()) {
355 if (
auto *
I = dyn_cast<Instruction>(V)) {
357 if (isKernelLDS(
F)) {
358 kernels[
F].insert(&GV);
367 struct LDSUsesInfoTy {
368 FunctionVariableMap direct_access;
369 FunctionVariableMap indirect_access;
372 static LDSUsesInfoTy getTransitiveUsesOfLDS(
CallGraph const &CG,
Module &M) {
374 FunctionVariableMap direct_map_kernel;
375 FunctionVariableMap direct_map_function;
376 getUsesOfLDSByFunction(CG, M, direct_map_kernel, direct_map_function);
381 if (!isKernelLDS(&
F))
382 if (
F.hasAddressTaken(
nullptr,
387 set_union(VariablesReachableThroughFunctionPointer,
388 direct_map_function[&
F]);
392 auto functionMakesUnknownCall = [&](
const Function *
F) ->
bool {
395 if (!R.second->getFunction()) {
403 FunctionVariableMap transitive_map_function = direct_map_function;
408 if (!
F.isDeclaration() && functionMakesUnknownCall(&
F)) {
409 if (!isKernelLDS(&
F)) {
411 VariablesReachableThroughFunctionPointer);
418 for (
Function &Func : M.functions()) {
419 if (Func.isDeclaration() || isKernelLDS(&Func))
425 while (!wip.empty()) {
430 set_union(transitive_map_function[&Func], direct_map_function[
F]);
433 Function *ith = R.second->getFunction();
446 FunctionVariableMap indirect_map_kernel;
448 for (
Function &Func : M.functions()) {
449 if (Func.isDeclaration() || !isKernelLDS(&Func))
453 Function *ith = R.second->getFunction();
455 set_union(indirect_map_kernel[&Func], transitive_map_function[ith]);
458 VariablesReachableThroughFunctionPointer);
463 return {std::move(direct_map_kernel), std::move(indirect_map_kernel)};
466 struct LDSVariableReplacement {
476 static Constant *getAddressesOfVariablesInKernel(
486 ArrayType *KernelOffsetsType = ArrayType::get(I32, Variables.
size());
489 for (
size_t i = 0; i < Variables.
size(); i++) {
491 auto ConstantGepIt = LDSVarsToConstantGEP.
find(GV);
492 if (ConstantGepIt != LDSVarsToConstantGEP.
end()) {
494 Elements.push_back(elt);
506 if (Variables.
empty()) {
511 const size_t NumberVariables = Variables.
size();
512 const size_t NumberKernels = kernels.size();
518 ArrayType::get(KernelOffsetsType, NumberKernels);
521 std::vector<Constant *> overallConstantExprElts(NumberKernels);
522 for (
size_t i = 0; i < NumberKernels; i++) {
523 auto Replacement = KernelToReplacement.
find(kernels[i]);
524 overallConstantExprElts[i] =
525 (Replacement == KernelToReplacement.
end())
527 : getAddressesOfVariablesInKernel(
528 Ctx, Variables, Replacement->second.LDSVarsToConstantGEP);
543 Value *OptionalIndex) {
547 auto *
I = cast<Instruction>(U.getUser());
549 Value *tableKernelIndex = getTableLookupKernelIndex(M,
I->getFunction());
551 if (
auto *Phi = dyn_cast<PHINode>(
I)) {
566 LookupTable->getValueType(), LookupTable, GEPIdx, GV->
getName());
576 void replaceUsesInInstructionsWithTableLookup(
585 auto *GV = ModuleScopeVariables[
Index];
588 auto *
I = dyn_cast<Instruction>(U.getUser());
592 replaceUseWithTableLookup(M, Builder, LookupTable, GV, U,
599 Module &M, LDSUsesInfoTy &LDSUsesInfo,
604 if (VariableSet.
empty())
607 for (
Function &Func : M.functions()) {
608 if (Func.isDeclaration() || !isKernelLDS(&Func))
612 KernelSet.insert(&Func);
622 chooseBestVariableForModuleStrategy(
const DataLayout &
DL,
623 VariableFunctionMap &LDSVars) {
628 size_t UserCount = 0;
631 CandidateTy() =
default;
634 : GV(GV), UserCount(UserCount),
Size(AllocSize) {}
638 if (UserCount <
Other.UserCount) {
641 if (UserCount >
Other.UserCount) {
659 CandidateTy MostUsed;
661 for (
auto &K : LDSVars) {
663 if (K.second.size() <= 1) {
668 CandidateTy Candidate(
671 if (MostUsed < Candidate)
672 MostUsed = Candidate;
696 auto [It, Inserted] = tableKernelIndexCache.
try_emplace(
F);
701 auto InsertAt =
F->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
710 static std::vector<Function *> assignLDSKernelIDToEachKernel(
718 std::vector<Function *> OrderedKernels;
719 if (!KernelsThatAllocateTableLDS.
empty() ||
720 !KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
722 for (
Function &Func : M->functions()) {
723 if (Func.isDeclaration())
725 if (!isKernelLDS(&Func))
728 if (KernelsThatAllocateTableLDS.
contains(&Func) ||
729 KernelsThatIndirectlyAllocateDynamicLDS.
contains(&Func)) {
731 OrderedKernels.push_back(&Func);
736 OrderedKernels = sortByName(std::move(OrderedKernels));
742 if (OrderedKernels.size() > UINT32_MAX) {
747 for (
size_t i = 0; i < OrderedKernels.size(); i++) {
751 OrderedKernels[i]->setMetadata(
"llvm.amdgcn.lds.kernel.id",
755 return OrderedKernels;
758 static void partitionVariablesIntoIndirectStrategies(
759 Module &M, LDSUsesInfoTy
const &LDSUsesInfo,
760 VariableFunctionMap &LDSToKernelsThatNeedToAccessItIndirectly,
767 LoweringKindLoc != LoweringKind::hybrid
769 : chooseBestVariableForModuleStrategy(
770 M.getDataLayout(), LDSToKernelsThatNeedToAccessItIndirectly);
775 ? LDSToKernelsThatNeedToAccessItIndirectly[HybridModuleRoot]
778 for (
auto &K : LDSToKernelsThatNeedToAccessItIndirectly) {
784 assert(K.second.size() != 0);
787 DynamicVariables.
insert(GV);
791 switch (LoweringKindLoc) {
792 case LoweringKind::module:
793 ModuleScopeVariables.insert(GV);
796 case LoweringKind::table:
797 TableLookupVariables.
insert(GV);
800 case LoweringKind::kernel:
801 if (K.second.size() == 1) {
802 KernelAccessVariables.
insert(GV);
805 "cannot lower LDS '" + GV->
getName() +
806 "' to kernel access as it is reachable from multiple kernels");
810 case LoweringKind::hybrid: {
811 if (GV == HybridModuleRoot) {
812 assert(K.second.size() != 1);
813 ModuleScopeVariables.insert(GV);
814 }
else if (K.second.size() == 1) {
815 KernelAccessVariables.
insert(GV);
816 }
else if (
set_is_subset(K.second, HybridModuleRootKernels)) {
817 ModuleScopeVariables.insert(GV);
819 TableLookupVariables.
insert(GV);
828 assert(ModuleScopeVariables.
size() + TableLookupVariables.
size() +
829 KernelAccessVariables.
size() + DynamicVariables.
size() ==
830 LDSToKernelsThatNeedToAccessItIndirectly.size());
843 if (ModuleScopeVariables.
empty()) {
849 LDSVariableReplacement ModuleScopeReplacement =
850 createLDSVariableReplacement(M,
"llvm.amdgcn.module.lds",
851 ModuleScopeVariables);
855 cast<Constant>(ModuleScopeReplacement.SGV),
856 PointerType::getUnqual(Ctx)))});
859 recordLDSAbsoluteAddress(&M, ModuleScopeReplacement.SGV, 0);
862 removeLocalVarsFromUsedLists(M, ModuleScopeVariables);
865 replaceLDSVariablesWithStruct(
866 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
872 return !isKernelLDS(
F);
879 for (
Function &Func : M.functions()) {
880 if (Func.isDeclaration() || !isKernelLDS(&Func))
883 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
884 replaceLDSVariablesWithStruct(
885 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
894 markUsedByKernel(&Func, ModuleScopeReplacement.SGV);
898 return ModuleScopeReplacement.SGV;
902 lowerKernelScopeStructVariables(
903 Module &M, LDSUsesInfoTy &LDSUsesInfo,
911 for (
Function &Func : M.functions()) {
912 if (Func.isDeclaration() || !isKernelLDS(&Func))
918 for (
auto &v : LDSUsesInfo.direct_access[&Func]) {
920 KernelUsedVariables.
insert(v);
926 for (
auto &v : LDSUsesInfo.indirect_access[&Func]) {
928 KernelUsedVariables.
insert(v);
934 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
936 KernelUsedVariables.
erase(v);
940 if (KernelUsedVariables.
empty()) {
952 if (!Func.hasName()) {
956 std::string VarName =
957 (
Twine(
"llvm.amdgcn.kernel.") + Func.getName() +
".lds").str();
960 createLDSVariableReplacement(M, VarName, KernelUsedVariables);
965 auto Accesses = LDSUsesInfo.indirect_access.find(&Func);
966 if ((Accesses != LDSUsesInfo.indirect_access.end()) &&
967 !Accesses->second.empty())
968 markUsedByKernel(&Func, Replacement.SGV);
971 removeLocalVarsFromUsedLists(M, KernelUsedVariables);
972 KernelToReplacement[&Func] = Replacement;
975 replaceLDSVariablesWithStruct(
976 M, KernelUsedVariables, Replacement, [&Func](
Use &U) {
978 return I &&
I->getFunction() == &Func;
981 return KernelToReplacement;
985 buildRepresentativeDynamicLDSInstance(
Module &M, LDSUsesInfoTy &LDSUsesInfo,
997 assert(isKernelLDS(func));
1001 Align MaxDynamicAlignment(1);
1003 auto UpdateMaxAlignment = [&MaxDynamicAlignment, &
DL](
GlobalVariable *GV) {
1005 MaxDynamicAlignment =
1011 UpdateMaxAlignment(GV);
1015 UpdateMaxAlignment(GV);
1024 N->setAlignment(MaxDynamicAlignment);
1031 Module &M, LDSUsesInfoTy &LDSUsesInfo,
1034 std::vector<Function *>
const &OrderedKernels) {
1036 if (!KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
1041 std::vector<Constant *> newDynamicLDS;
1044 for (
auto &func : OrderedKernels) {
1046 if (KernelsThatIndirectlyAllocateDynamicLDS.
contains(func)) {
1047 assert(isKernelLDS(func));
1053 buildRepresentativeDynamicLDSInstance(M, LDSUsesInfo, func);
1055 KernelToCreatedDynamicLDS[func] =
N;
1057 markUsedByKernel(func,
N);
1067 assert(OrderedKernels.size() == newDynamicLDS.size());
1069 ArrayType *t = ArrayType::get(I32, newDynamicLDS.size());
1073 "llvm.amdgcn.dynlds.offset.table",
nullptr,
1078 auto *
I = dyn_cast<Instruction>(U.getUser());
1081 if (isKernelLDS(
I->getFunction()))
1084 replaceUseWithTableLookup(M, Builder, table, GV, U,
nullptr);
1088 return KernelToCreatedDynamicLDS;
1091 bool runOnModule(
Module &M) {
1093 bool Changed = superAlignLDSGlobals(M);
1095 Changed |= eliminateConstantExprUsesOfLDSFromAllInstructions(M);
1101 LDSUsesInfoTy LDSUsesInfo = getTransitiveUsesOfLDS(CG, M);
1104 VariableFunctionMap LDSToKernelsThatNeedToAccessItIndirectly;
1105 for (
auto &K : LDSUsesInfo.indirect_access) {
1109 LDSToKernelsThatNeedToAccessItIndirectly[GV].insert(
F);
1118 partitionVariablesIntoIndirectStrategies(
1119 M, LDSUsesInfo, LDSToKernelsThatNeedToAccessItIndirectly,
1120 ModuleScopeVariables, TableLookupVariables, KernelAccessVariables,
1127 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1128 ModuleScopeVariables);
1130 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1131 TableLookupVariables);
1134 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1137 GlobalVariable *MaybeModuleScopeStruct = lowerModuleScopeStructVariables(
1138 M, ModuleScopeVariables, KernelsThatAllocateModuleLDS);
1141 lowerKernelScopeStructVariables(M, LDSUsesInfo, ModuleScopeVariables,
1142 KernelsThatAllocateModuleLDS,
1143 MaybeModuleScopeStruct);
1146 for (
auto &GV : KernelAccessVariables) {
1147 auto &funcs = LDSToKernelsThatNeedToAccessItIndirectly[GV];
1148 assert(funcs.size() == 1);
1149 LDSVariableReplacement Replacement =
1150 KernelToReplacement[*(funcs.begin())];
1155 replaceLDSVariablesWithStruct(M, Vec, Replacement, [](
Use &U) {
1156 return isa<Instruction>(U.getUser());
1161 std::vector<Function *> OrderedKernels =
1162 assignLDSKernelIDToEachKernel(&M, KernelsThatAllocateTableLDS,
1163 KernelsThatIndirectlyAllocateDynamicLDS);
1165 if (!KernelsThatAllocateTableLDS.
empty()) {
1171 auto TableLookupVariablesOrdered =
1172 sortByName(std::vector<GlobalVariable *>(TableLookupVariables.
begin(),
1173 TableLookupVariables.
end()));
1176 M, TableLookupVariablesOrdered, OrderedKernels, KernelToReplacement);
1177 replaceUsesInInstructionsWithTableLookup(M, TableLookupVariablesOrdered,
1182 lowerDynamicLDSVariables(M, LDSUsesInfo,
1183 KernelsThatIndirectlyAllocateDynamicLDS,
1184 DynamicVariables, OrderedKernels);
1191 for (
Function &Func : M.functions()) {
1192 if (Func.isDeclaration() || !isKernelLDS(&Func))
1206 const bool AllocateModuleScopeStruct =
1207 MaybeModuleScopeStruct &&
1208 KernelsThatAllocateModuleLDS.
contains(&Func);
1210 auto Replacement = KernelToReplacement.
find(&Func);
1211 const bool AllocateKernelScopeStruct =
1212 Replacement != KernelToReplacement.
end();
1214 const bool AllocateDynamicVariable =
1215 KernelToCreatedDynamicLDS.
contains(&Func);
1219 if (AllocateModuleScopeStruct) {
1225 if (AllocateKernelScopeStruct) {
1228 recordLDSAbsoluteAddress(&M, KernelStruct,
Offset);
1236 if (AllocateDynamicVariable) {
1237 GlobalVariable *DynamicVariable = KernelToCreatedDynamicLDS[&Func];
1239 recordLDSAbsoluteAddress(&M, DynamicVariable,
Offset);
1254 if (AllocateDynamicVariable)
1257 Func.addFnAttr(
"amdgpu-lds-size", Buffer);
1276 static bool superAlignLDSGlobals(
Module &M) {
1278 bool Changed =
false;
1279 if (!SuperAlignLDSGlobals) {
1283 for (
auto &GV : M.globals()) {
1298 Alignment = std::max(Alignment,
Align(16));
1299 }
else if (GVSize > 4) {
1301 Alignment = std::max(Alignment,
Align(8));
1302 }
else if (GVSize > 2) {
1304 Alignment = std::max(Alignment,
Align(4));
1305 }
else if (GVSize > 1) {
1307 Alignment = std::max(Alignment,
Align(2));
1318 static LDSVariableReplacement createLDSVariableReplacement(
1319 Module &M, std::string VarName,
1336 auto Sorted = sortByName(std::vector<GlobalVariable *>(
1337 LDSVarsToTransform.
begin(), LDSVarsToTransform.
end()));
1349 std::vector<GlobalVariable *> LocalVars;
1352 IsPaddingField.
reserve(LDSVarsToTransform.
size());
1355 for (
size_t I = 0;
I < LayoutFields.
size();
I++) {
1357 const_cast<void *
>(LayoutFields[
I].Id));
1358 Align DataAlign = LayoutFields[
I].Alignment;
1361 if (
uint64_t Rem = CurrentOffset % DataAlignV) {
1362 uint64_t Padding = DataAlignV - Rem;
1374 CurrentOffset += Padding;
1377 LocalVars.push_back(FGV);
1379 CurrentOffset += LayoutFields[
I].
Size;
1383 std::vector<Type *> LocalVarTypes;
1384 LocalVarTypes.reserve(LocalVars.size());
1386 LocalVars.cbegin(), LocalVars.cend(), std::back_inserter(LocalVarTypes),
1401 for (
size_t I = 0;
I < LocalVars.size();
I++) {
1405 if (IsPaddingField[
I]) {
1412 assert(Map.size() == LDSVarsToTransform.
size());
1413 return {SGV, std::move(Map)};
1416 template <
typename PredicateTy>
1417 static void replaceLDSVariablesWithStruct(
1419 const LDSVariableReplacement &Replacement, PredicateTy Predicate) {
1426 auto LDSVarsToTransform = sortByName(std::vector<GlobalVariable *>(
1427 LDSVarsToTransformArg.
begin(), LDSVarsToTransformArg.
end()));
1433 const size_t NumberVars = LDSVarsToTransform.
size();
1434 if (NumberVars > 1) {
1436 AliasScopes.
reserve(NumberVars);
1438 for (
size_t I = 0;
I < NumberVars;
I++) {
1442 NoAliasList.
append(&AliasScopes[1], AliasScopes.
end());
1447 for (
size_t I = 0;
I < NumberVars;
I++) {
1449 Constant *
GEP = Replacement.LDSVarsToConstantGEP.at(GV);
1453 APInt APOff(
DL.getIndexTypeSizeInBits(
GEP->getType()), 0);
1454 GEP->stripAndAccumulateInBoundsConstantOffsets(
DL, APOff);
1461 NoAliasList[
I - 1] = AliasScopes[
I - 1];
1467 refineUsesAlignmentAndAA(
GEP,
A,
DL, AliasScope, NoAlias);
1474 if (!
MaxDepth || (
A == 1 && !AliasScope))
1477 for (
User *U :
Ptr->users()) {
1478 if (
auto *
I = dyn_cast<Instruction>(U)) {
1479 if (AliasScope &&
I->mayReadOrWriteMemory()) {
1480 MDNode *AS =
I->getMetadata(LLVMContext::MD_alias_scope);
1483 I->setMetadata(LLVMContext::MD_alias_scope, AS);
1485 MDNode *NA =
I->getMetadata(LLVMContext::MD_noalias);
1487 I->setMetadata(LLVMContext::MD_noalias, NA);
1491 if (
auto *LI = dyn_cast<LoadInst>(U)) {
1492 LI->setAlignment(std::max(
A, LI->getAlign()));
1495 if (
auto *SI = dyn_cast<StoreInst>(U)) {
1496 if (SI->getPointerOperand() ==
Ptr)
1497 SI->setAlignment(std::max(
A, SI->getAlign()));
1500 if (
auto *AI = dyn_cast<AtomicRMWInst>(U)) {
1503 if (AI->getPointerOperand() ==
Ptr)
1504 AI->setAlignment(std::max(
A, AI->getAlign()));
1507 if (
auto *AI = dyn_cast<AtomicCmpXchgInst>(U)) {
1508 if (AI->getPointerOperand() ==
Ptr)
1509 AI->setAlignment(std::max(
A, AI->getAlign()));
1512 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(U)) {
1513 unsigned BitWidth =
DL.getIndexTypeSizeInBits(
GEP->getType());
1515 if (
GEP->getPointerOperand() ==
Ptr) {
1517 if (
GEP->accumulateConstantOffset(
DL, Off))
1519 refineUsesAlignmentAndAA(
GEP, GA,
DL, AliasScope, NoAlias,
1524 if (
auto *
I = dyn_cast<Instruction>(U)) {
1525 if (
I->getOpcode() == Instruction::BitCast ||
1526 I->getOpcode() == Instruction::AddrSpaceCast)
1527 refineUsesAlignmentAndAA(
I,
A,
DL, AliasScope, NoAlias,
MaxDepth - 1);
1533class AMDGPULowerModuleLDSLegacy :
public ModulePass {
1550 auto &TPC = getAnalysis<TargetPassConfig>();
1554 return AMDGPULowerModuleLDS(*TM).runOnModule(M);
1559char AMDGPULowerModuleLDSLegacy::ID = 0;
1564 "Lower uses of LDS variables from non-kernel functions",
1573 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...
std::pair< std::optional< WeakTrackingVH >, CallGraphNode * > CallRecord
A pair of the calling instruction (a call or invoke) and the call graph node being called.
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, bool InBounds=false, std::optional< unsigned > InRangeIndex=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
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.
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).
LLVM_READNONE bool isKernel(CallingConv::ID CC)
bool isDynamicLDS(const GlobalVariable &GV)
Align getAlign(DataLayout const &DL, const GlobalVariable *GV)
bool isLDSVariableToLower(const GlobalVariable &GV)
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 convertUsersOfConstantsToInstructions(ArrayRef< Constant * > Consts)
Replace constant expressions users of the given constants with instructions.
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
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
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
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.