196#include "llvm/IR/IntrinsicsAMDGPU.h"
214#define DEBUG_TYPE "amdgpu-lower-module-lds"
221 "amdgpu-super-align-lds-globals",
222 cl::desc(
"Increase alignment of LDS if it is not on align boundary"),
225enum class LoweringKind { module, table, kernel, hybrid };
227 "amdgpu-lower-module-lds-strategy",
231 clEnumValN(LoweringKind::table,
"table",
"Lower via table lookup"),
232 clEnumValN(LoweringKind::module,
"module",
"Lower via module struct"),
234 LoweringKind::kernel,
"kernel",
235 "Lower variables reachable from one kernel, otherwise abort"),
237 "Lower via mixture of above strategies")));
250template <
typename T> std::vector<T> sortByName(std::vector<T> &&V) {
251 llvm::sort(V.begin(), V.end(), [](
const auto *L,
const auto *R) {
252 return L->getName() < R->getName();
254 return {std::move(V)};
257class AMDGPULowerModuleLDS {
261 removeLocalVarsFromUsedLists(
Module &M,
267 LocalVarsSet.
insert(cast<Constant>(LocalVar->stripPointerCasts()));
273 LocalVar->removeDeadConstantUsers();
303 Value *UseInstance[1] = {
310 static bool eliminateConstantExprUsesOfLDSFromAllInstructions(
Module &M) {
325 for (
auto &GV : M.globals())
340 FunctionVariableMap &kernels,
345 for (
auto &GV : M.globals()) {
350 if (GV.isAbsoluteSymbolRef()) {
352 "LDS variables with absolute addresses are unimplemented.");
355 for (
User *V : GV.users()) {
356 if (
auto *
I = dyn_cast<Instruction>(V)) {
358 if (isKernelLDS(
F)) {
359 kernels[
F].insert(&GV);
368 struct LDSUsesInfoTy {
369 FunctionVariableMap direct_access;
370 FunctionVariableMap indirect_access;
373 static LDSUsesInfoTy getTransitiveUsesOfLDS(
CallGraph const &CG,
Module &M) {
375 FunctionVariableMap direct_map_kernel;
376 FunctionVariableMap direct_map_function;
377 getUsesOfLDSByFunction(CG, M, direct_map_kernel, direct_map_function);
382 if (!isKernelLDS(&
F))
383 if (
F.hasAddressTaken(
nullptr,
388 set_union(VariablesReachableThroughFunctionPointer,
389 direct_map_function[&
F]);
393 auto functionMakesUnknownCall = [&](
const Function *
F) ->
bool {
396 if (!R.second->getFunction()) {
404 FunctionVariableMap transitive_map_function = direct_map_function;
409 if (!
F.isDeclaration() && functionMakesUnknownCall(&
F)) {
410 if (!isKernelLDS(&
F)) {
412 VariablesReachableThroughFunctionPointer);
419 for (
Function &Func : M.functions()) {
420 if (Func.isDeclaration() || isKernelLDS(&Func))
426 while (!wip.empty()) {
431 set_union(transitive_map_function[&Func], direct_map_function[
F]);
434 Function *ith = R.second->getFunction();
447 FunctionVariableMap indirect_map_kernel;
449 for (
Function &Func : M.functions()) {
450 if (Func.isDeclaration() || !isKernelLDS(&Func))
454 Function *ith = R.second->getFunction();
456 set_union(indirect_map_kernel[&Func], transitive_map_function[ith]);
459 VariablesReachableThroughFunctionPointer);
464 return {std::move(direct_map_kernel), std::move(indirect_map_kernel)};
467 struct LDSVariableReplacement {
477 static Constant *getAddressesOfVariablesInKernel(
487 ArrayType *KernelOffsetsType = ArrayType::get(I32, Variables.
size());
490 for (
size_t i = 0; i < Variables.
size(); i++) {
492 auto ConstantGepIt = LDSVarsToConstantGEP.
find(GV);
493 if (ConstantGepIt != LDSVarsToConstantGEP.
end()) {
495 Elements.push_back(elt);
507 if (Variables.
empty()) {
512 const size_t NumberVariables = Variables.
size();
513 const size_t NumberKernels = kernels.size();
519 ArrayType::get(KernelOffsetsType, NumberKernels);
522 std::vector<Constant *> overallConstantExprElts(NumberKernels);
523 for (
size_t i = 0; i < NumberKernels; i++) {
524 auto Replacement = KernelToReplacement.
find(kernels[i]);
525 overallConstantExprElts[i] =
526 (Replacement == KernelToReplacement.
end())
528 : getAddressesOfVariablesInKernel(
529 Ctx, Variables, Replacement->second.LDSVarsToConstantGEP);
544 Value *OptionalIndex) {
548 auto *
I = cast<Instruction>(U.getUser());
550 Value *tableKernelIndex = getTableLookupKernelIndex(M,
I->getFunction());
552 if (
auto *Phi = dyn_cast<PHINode>(
I)) {
567 LookupTable->getValueType(), LookupTable, GEPIdx, GV->
getName());
577 void replaceUsesInInstructionsWithTableLookup(
586 auto *GV = ModuleScopeVariables[
Index];
589 auto *
I = dyn_cast<Instruction>(U.getUser());
593 replaceUseWithTableLookup(M,
Builder, LookupTable, GV, U,
600 Module &M, LDSUsesInfoTy &LDSUsesInfo,
605 if (VariableSet.
empty())
608 for (
Function &Func : M.functions()) {
609 if (Func.isDeclaration() || !isKernelLDS(&Func))
613 KernelSet.insert(&Func);
623 chooseBestVariableForModuleStrategy(
const DataLayout &
DL,
624 VariableFunctionMap &LDSVars) {
629 size_t UserCount = 0;
632 CandidateTy() =
default;
635 : GV(GV), UserCount(UserCount),
Size(AllocSize) {}
639 if (UserCount <
Other.UserCount) {
642 if (UserCount >
Other.UserCount) {
660 CandidateTy MostUsed;
662 for (
auto &K : LDSVars) {
664 if (K.second.size() <= 1) {
669 CandidateTy Candidate(
672 if (MostUsed < Candidate)
673 MostUsed = Candidate;
697 auto [It, Inserted] = tableKernelIndexCache.
try_emplace(
F);
702 auto InsertAt =
F->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
705 It->second =
Builder.CreateCall(Decl, {});
711 static std::vector<Function *> assignLDSKernelIDToEachKernel(
719 std::vector<Function *> OrderedKernels;
720 if (!KernelsThatAllocateTableLDS.
empty() ||
721 !KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
723 for (
Function &Func : M->functions()) {
724 if (Func.isDeclaration())
726 if (!isKernelLDS(&Func))
729 if (KernelsThatAllocateTableLDS.
contains(&Func) ||
730 KernelsThatIndirectlyAllocateDynamicLDS.
contains(&Func)) {
732 OrderedKernels.push_back(&Func);
737 OrderedKernels = sortByName(std::move(OrderedKernels));
743 if (OrderedKernels.size() > UINT32_MAX) {
748 for (
size_t i = 0; i < OrderedKernels.size(); i++) {
752 OrderedKernels[i]->setMetadata(
"llvm.amdgcn.lds.kernel.id",
756 return OrderedKernels;
759 static void partitionVariablesIntoIndirectStrategies(
760 Module &M, LDSUsesInfoTy
const &LDSUsesInfo,
761 VariableFunctionMap &LDSToKernelsThatNeedToAccessItIndirectly,
768 LoweringKindLoc != LoweringKind::hybrid
770 : chooseBestVariableForModuleStrategy(
771 M.getDataLayout(), LDSToKernelsThatNeedToAccessItIndirectly);
776 ? LDSToKernelsThatNeedToAccessItIndirectly[HybridModuleRoot]
779 for (
auto &K : LDSToKernelsThatNeedToAccessItIndirectly) {
785 assert(K.second.size() != 0);
788 DynamicVariables.
insert(GV);
792 switch (LoweringKindLoc) {
793 case LoweringKind::module:
794 ModuleScopeVariables.insert(GV);
797 case LoweringKind::table:
798 TableLookupVariables.
insert(GV);
801 case LoweringKind::kernel:
802 if (K.second.size() == 1) {
803 KernelAccessVariables.
insert(GV);
806 "cannot lower LDS '" + GV->
getName() +
807 "' to kernel access as it is reachable from multiple kernels");
811 case LoweringKind::hybrid: {
812 if (GV == HybridModuleRoot) {
813 assert(K.second.size() != 1);
814 ModuleScopeVariables.insert(GV);
815 }
else if (K.second.size() == 1) {
816 KernelAccessVariables.
insert(GV);
817 }
else if (
set_is_subset(K.second, HybridModuleRootKernels)) {
818 ModuleScopeVariables.insert(GV);
820 TableLookupVariables.
insert(GV);
829 assert(ModuleScopeVariables.
size() + TableLookupVariables.
size() +
830 KernelAccessVariables.
size() + DynamicVariables.
size() ==
831 LDSToKernelsThatNeedToAccessItIndirectly.size());
844 if (ModuleScopeVariables.
empty()) {
850 LDSVariableReplacement ModuleScopeReplacement =
851 createLDSVariableReplacement(M,
"llvm.amdgcn.module.lds",
852 ModuleScopeVariables);
856 cast<Constant>(ModuleScopeReplacement.SGV),
860 recordLDSAbsoluteAddress(&M, ModuleScopeReplacement.SGV, 0);
863 removeLocalVarsFromUsedLists(M, ModuleScopeVariables);
866 replaceLDSVariablesWithStruct(
867 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
873 return !isKernelLDS(
F);
880 for (
Function &Func : M.functions()) {
881 if (Func.isDeclaration() || !isKernelLDS(&Func))
884 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
885 replaceLDSVariablesWithStruct(
886 M, ModuleScopeVariables, ModuleScopeReplacement, [&](
Use &U) {
895 markUsedByKernel(&Func, ModuleScopeReplacement.SGV);
899 return ModuleScopeReplacement.SGV;
903 lowerKernelScopeStructVariables(
904 Module &M, LDSUsesInfoTy &LDSUsesInfo,
912 for (
Function &Func : M.functions()) {
913 if (Func.isDeclaration() || !isKernelLDS(&Func))
919 for (
auto &v : LDSUsesInfo.direct_access[&Func]) {
921 KernelUsedVariables.
insert(v);
927 for (
auto &v : LDSUsesInfo.indirect_access[&Func]) {
929 KernelUsedVariables.
insert(v);
935 if (KernelsThatAllocateModuleLDS.
contains(&Func)) {
937 KernelUsedVariables.
erase(v);
941 if (KernelUsedVariables.
empty()) {
953 if (!Func.hasName()) {
957 std::string VarName =
958 (
Twine(
"llvm.amdgcn.kernel.") + Func.getName() +
".lds").str();
961 createLDSVariableReplacement(M, VarName, KernelUsedVariables);
966 auto Accesses = LDSUsesInfo.indirect_access.find(&Func);
967 if ((Accesses != LDSUsesInfo.indirect_access.end()) &&
968 !Accesses->second.empty())
969 markUsedByKernel(&Func, Replacement.SGV);
972 removeLocalVarsFromUsedLists(M, KernelUsedVariables);
973 KernelToReplacement[&Func] = Replacement;
976 replaceLDSVariablesWithStruct(
977 M, KernelUsedVariables, Replacement, [&Func](
Use &U) {
979 return I &&
I->getFunction() == &Func;
982 return KernelToReplacement;
986 buildRepresentativeDynamicLDSInstance(
Module &M, LDSUsesInfoTy &LDSUsesInfo,
998 assert(isKernelLDS(func));
1002 Align MaxDynamicAlignment(1);
1004 auto UpdateMaxAlignment = [&MaxDynamicAlignment, &
DL](
GlobalVariable *GV) {
1006 MaxDynamicAlignment =
1012 UpdateMaxAlignment(GV);
1016 UpdateMaxAlignment(GV);
1025 N->setAlignment(MaxDynamicAlignment);
1032 Module &M, LDSUsesInfoTy &LDSUsesInfo,
1035 std::vector<Function *>
const &OrderedKernels) {
1037 if (!KernelsThatIndirectlyAllocateDynamicLDS.
empty()) {
1042 std::vector<Constant *> newDynamicLDS;
1045 for (
auto &func : OrderedKernels) {
1047 if (KernelsThatIndirectlyAllocateDynamicLDS.
contains(func)) {
1048 assert(isKernelLDS(func));
1054 buildRepresentativeDynamicLDSInstance(M, LDSUsesInfo, func);
1056 KernelToCreatedDynamicLDS[func] =
N;
1058 markUsedByKernel(func,
N);
1068 assert(OrderedKernels.size() == newDynamicLDS.size());
1070 ArrayType *t = ArrayType::get(I32, newDynamicLDS.size());
1074 "llvm.amdgcn.dynlds.offset.table",
nullptr,
1079 auto *
I = dyn_cast<Instruction>(U.getUser());
1082 if (isKernelLDS(
I->getFunction()))
1085 replaceUseWithTableLookup(M,
Builder, table, GV, U,
nullptr);
1089 return KernelToCreatedDynamicLDS;
1092 bool runOnModule(
Module &M) {
1094 bool Changed = superAlignLDSGlobals(M);
1096 Changed |= eliminateConstantExprUsesOfLDSFromAllInstructions(M);
1102 LDSUsesInfoTy LDSUsesInfo = getTransitiveUsesOfLDS(CG, M);
1105 VariableFunctionMap LDSToKernelsThatNeedToAccessItIndirectly;
1106 for (
auto &K : LDSUsesInfo.indirect_access) {
1110 LDSToKernelsThatNeedToAccessItIndirectly[GV].insert(
F);
1119 partitionVariablesIntoIndirectStrategies(
1120 M, LDSUsesInfo, LDSToKernelsThatNeedToAccessItIndirectly,
1121 ModuleScopeVariables, TableLookupVariables, KernelAccessVariables,
1128 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1129 ModuleScopeVariables);
1131 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1132 TableLookupVariables);
1135 kernelsThatIndirectlyAccessAnyOfPassedVariables(M, LDSUsesInfo,
1138 GlobalVariable *MaybeModuleScopeStruct = lowerModuleScopeStructVariables(
1139 M, ModuleScopeVariables, KernelsThatAllocateModuleLDS);
1142 lowerKernelScopeStructVariables(M, LDSUsesInfo, ModuleScopeVariables,
1143 KernelsThatAllocateModuleLDS,
1144 MaybeModuleScopeStruct);
1147 for (
auto &GV : KernelAccessVariables) {
1148 auto &funcs = LDSToKernelsThatNeedToAccessItIndirectly[GV];
1149 assert(funcs.size() == 1);
1150 LDSVariableReplacement Replacement =
1151 KernelToReplacement[*(funcs.begin())];
1156 replaceLDSVariablesWithStruct(M, Vec, Replacement, [](
Use &U) {
1157 return isa<Instruction>(U.getUser());
1162 std::vector<Function *> OrderedKernels =
1163 assignLDSKernelIDToEachKernel(&M, KernelsThatAllocateTableLDS,
1164 KernelsThatIndirectlyAllocateDynamicLDS);
1166 if (!KernelsThatAllocateTableLDS.
empty()) {
1172 auto TableLookupVariablesOrdered =
1173 sortByName(std::vector<GlobalVariable *>(TableLookupVariables.
begin(),
1174 TableLookupVariables.
end()));
1177 M, TableLookupVariablesOrdered, OrderedKernels, KernelToReplacement);
1178 replaceUsesInInstructionsWithTableLookup(M, TableLookupVariablesOrdered,
1183 lowerDynamicLDSVariables(M, LDSUsesInfo,
1184 KernelsThatIndirectlyAllocateDynamicLDS,
1185 DynamicVariables, OrderedKernels);
1192 for (
Function &Func : M.functions()) {
1193 if (Func.isDeclaration() || !isKernelLDS(&Func))
1207 const bool AllocateModuleScopeStruct =
1208 MaybeModuleScopeStruct &&
1209 KernelsThatAllocateModuleLDS.
contains(&Func);
1211 auto Replacement = KernelToReplacement.
find(&Func);
1212 const bool AllocateKernelScopeStruct =
1213 Replacement != KernelToReplacement.
end();
1215 const bool AllocateDynamicVariable =
1216 KernelToCreatedDynamicLDS.
contains(&Func);
1220 if (AllocateModuleScopeStruct) {
1226 if (AllocateKernelScopeStruct) {
1229 recordLDSAbsoluteAddress(&M, KernelStruct,
Offset);
1237 if (AllocateDynamicVariable) {
1238 GlobalVariable *DynamicVariable = KernelToCreatedDynamicLDS[&Func];
1240 recordLDSAbsoluteAddress(&M, DynamicVariable,
Offset);
1255 if (AllocateDynamicVariable)
1258 Func.addFnAttr(
"amdgpu-lds-size", Buffer);
1277 static bool superAlignLDSGlobals(
Module &M) {
1279 bool Changed =
false;
1280 if (!SuperAlignLDSGlobals) {
1284 for (
auto &GV : M.globals()) {
1299 Alignment = std::max(Alignment,
Align(16));
1300 }
else if (GVSize > 4) {
1302 Alignment = std::max(Alignment,
Align(8));
1303 }
else if (GVSize > 2) {
1305 Alignment = std::max(Alignment,
Align(4));
1306 }
else if (GVSize > 1) {
1308 Alignment = std::max(Alignment,
Align(2));
1319 static LDSVariableReplacement createLDSVariableReplacement(
1320 Module &M, std::string VarName,
1337 auto Sorted = sortByName(std::vector<GlobalVariable *>(
1338 LDSVarsToTransform.
begin(), LDSVarsToTransform.
end()));
1350 std::vector<GlobalVariable *> LocalVars;
1353 IsPaddingField.
reserve(LDSVarsToTransform.
size());
1356 for (
size_t I = 0;
I < LayoutFields.
size();
I++) {
1358 const_cast<void *
>(LayoutFields[
I].Id));
1359 Align DataAlign = LayoutFields[
I].Alignment;
1362 if (
uint64_t Rem = CurrentOffset % DataAlignV) {
1363 uint64_t Padding = DataAlignV - Rem;
1375 CurrentOffset += Padding;
1378 LocalVars.push_back(FGV);
1380 CurrentOffset += LayoutFields[
I].
Size;
1384 std::vector<Type *> LocalVarTypes;
1385 LocalVarTypes.reserve(LocalVars.size());
1387 LocalVars.cbegin(), LocalVars.cend(), std::back_inserter(LocalVarTypes),
1402 for (
size_t I = 0;
I < LocalVars.size();
I++) {
1406 if (IsPaddingField[
I]) {
1413 assert(Map.size() == LDSVarsToTransform.
size());
1414 return {SGV, std::move(Map)};
1417 template <
typename PredicateTy>
1418 static void replaceLDSVariablesWithStruct(
1420 const LDSVariableReplacement &Replacement, PredicateTy Predicate) {
1427 auto LDSVarsToTransform = sortByName(std::vector<GlobalVariable *>(
1428 LDSVarsToTransformArg.
begin(), LDSVarsToTransformArg.
end()));
1434 const size_t NumberVars = LDSVarsToTransform.
size();
1435 if (NumberVars > 1) {
1437 AliasScopes.
reserve(NumberVars);
1439 for (
size_t I = 0;
I < NumberVars;
I++) {
1443 NoAliasList.
append(&AliasScopes[1], AliasScopes.
end());
1448 for (
size_t I = 0;
I < NumberVars;
I++) {
1450 Constant *
GEP = Replacement.LDSVarsToConstantGEP.at(GV);
1454 APInt APOff(
DL.getIndexTypeSizeInBits(
GEP->getType()), 0);
1455 GEP->stripAndAccumulateInBoundsConstantOffsets(
DL, APOff);
1462 NoAliasList[
I - 1] = AliasScopes[
I - 1];
1468 refineUsesAlignmentAndAA(
GEP,
A,
DL, AliasScope, NoAlias);
1475 if (!
MaxDepth || (
A == 1 && !AliasScope))
1478 for (
User *U :
Ptr->users()) {
1479 if (
auto *
I = dyn_cast<Instruction>(U)) {
1480 if (AliasScope &&
I->mayReadOrWriteMemory()) {
1481 MDNode *AS =
I->getMetadata(LLVMContext::MD_alias_scope);
1484 I->setMetadata(LLVMContext::MD_alias_scope, AS);
1486 MDNode *NA =
I->getMetadata(LLVMContext::MD_noalias);
1488 I->setMetadata(LLVMContext::MD_noalias, NA);
1492 if (
auto *LI = dyn_cast<LoadInst>(U)) {
1493 LI->setAlignment(std::max(
A, LI->getAlign()));
1496 if (
auto *SI = dyn_cast<StoreInst>(U)) {
1497 if (SI->getPointerOperand() ==
Ptr)
1498 SI->setAlignment(std::max(
A, SI->getAlign()));
1501 if (
auto *AI = dyn_cast<AtomicRMWInst>(U)) {
1504 if (AI->getPointerOperand() ==
Ptr)
1505 AI->setAlignment(std::max(
A, AI->getAlign()));
1508 if (
auto *AI = dyn_cast<AtomicCmpXchgInst>(U)) {
1509 if (AI->getPointerOperand() ==
Ptr)
1510 AI->setAlignment(std::max(
A, AI->getAlign()));
1513 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(U)) {
1514 unsigned BitWidth =
DL.getIndexTypeSizeInBits(
GEP->getType());
1516 if (
GEP->getPointerOperand() ==
Ptr) {
1518 if (
GEP->accumulateConstantOffset(
DL, Off))
1520 refineUsesAlignmentAndAA(
GEP, GA,
DL, AliasScope, NoAlias,
1525 if (
auto *
I = dyn_cast<Instruction>(U)) {
1526 if (
I->getOpcode() == Instruction::BitCast ||
1527 I->getOpcode() == Instruction::AddrSpaceCast)
1528 refineUsesAlignmentAndAA(
I,
A,
DL, AliasScope, NoAlias,
MaxDepth - 1);
1534class AMDGPULowerModuleLDSLegacy :
public ModulePass {
1551 auto &TPC = getAnalysis<TargetPassConfig>();
1555 return AMDGPULowerModuleLDS(*TM).runOnModule(M);
1560char AMDGPULowerModuleLDSLegacy::ID = 0;
1565 "Lower uses of LDS variables from non-kernel functions",
1574 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,...
This file implements a set that has insertion order iteration characteristics.
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.
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 PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
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.