[amdgpu][nfc] clang-format AMDGPULowerModuleLDS for easier merging
This commit is contained in:
parent
c49e56a295
commit
78e6818049
|
@ -315,11 +315,11 @@ public:
|
||||||
DenseSet<GlobalVariable *> VariablesReachableThroughFunctionPointer;
|
DenseSet<GlobalVariable *> VariablesReachableThroughFunctionPointer;
|
||||||
for (Function &F : M.functions()) {
|
for (Function &F : M.functions()) {
|
||||||
if (!isKernelLDS(&F))
|
if (!isKernelLDS(&F))
|
||||||
if (F.hasAddressTaken(nullptr,
|
if (F.hasAddressTaken(nullptr,
|
||||||
/* IgnoreCallbackUses */ false,
|
/* IgnoreCallbackUses */ false,
|
||||||
/* IgnoreAssumeLikeCalls */ false,
|
/* IgnoreAssumeLikeCalls */ false,
|
||||||
/* IgnoreLLVMUsed */ true,
|
/* IgnoreLLVMUsed */ true,
|
||||||
/* IgnoreArcAttachedCall */ false)) {
|
/* IgnoreArcAttachedCall */ false)) {
|
||||||
set_union(VariablesReachableThroughFunctionPointer,
|
set_union(VariablesReachableThroughFunctionPointer,
|
||||||
direct_map_function[&F]);
|
direct_map_function[&F]);
|
||||||
}
|
}
|
||||||
|
@ -476,7 +476,6 @@ public:
|
||||||
IRBuilder<> Builder(Ctx);
|
IRBuilder<> Builder(Ctx);
|
||||||
Type *I32 = Type::getInt32Ty(Ctx);
|
Type *I32 = Type::getInt32Ty(Ctx);
|
||||||
|
|
||||||
|
|
||||||
for (size_t Index = 0; Index < ModuleScopeVariables.size(); Index++) {
|
for (size_t Index = 0; Index < ModuleScopeVariables.size(); Index++) {
|
||||||
auto *GV = ModuleScopeVariables[Index];
|
auto *GV = ModuleScopeVariables[Index];
|
||||||
|
|
||||||
|
@ -503,7 +502,6 @@ public:
|
||||||
ConstantInt::get(I32, Index),
|
ConstantInt::get(I32, Index),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Value *Address = Builder.CreateInBoundsGEP(
|
Value *Address = Builder.CreateInBoundsGEP(
|
||||||
LookupTable->getValueType(), LookupTable, GEPIdx, GV->getName());
|
LookupTable->getValueType(), LookupTable, GEPIdx, GV->getName());
|
||||||
|
|
||||||
|
@ -523,7 +521,8 @@ public:
|
||||||
|
|
||||||
DenseSet<Function *> KernelSet;
|
DenseSet<Function *> KernelSet;
|
||||||
|
|
||||||
if (VariableSet.empty()) return KernelSet;
|
if (VariableSet.empty())
|
||||||
|
return KernelSet;
|
||||||
|
|
||||||
for (Function &Func : M.functions()) {
|
for (Function &Func : M.functions()) {
|
||||||
if (Func.isDeclaration() || !isKernelLDS(&Func))
|
if (Func.isDeclaration() || !isKernelLDS(&Func))
|
||||||
|
@ -586,8 +585,9 @@ public:
|
||||||
// strategy
|
// strategy
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CandidateTy Candidate(GV, K.second.size(),
|
CandidateTy Candidate(
|
||||||
DL.getTypeAllocSize(GV->getValueType()).getFixedValue());
|
GV, K.second.size(),
|
||||||
|
DL.getTypeAllocSize(GV->getValueType()).getFixedValue());
|
||||||
if (MostUsed < Candidate)
|
if (MostUsed < Candidate)
|
||||||
MostUsed = Candidate;
|
MostUsed = Candidate;
|
||||||
}
|
}
|
||||||
|
@ -638,44 +638,42 @@ public:
|
||||||
// the backend and lowered to a SGPR which can be read from using
|
// the backend and lowered to a SGPR which can be read from using
|
||||||
// amdgcn_lds_kernel_id.
|
// amdgcn_lds_kernel_id.
|
||||||
|
|
||||||
std::vector<Function *> OrderedKernels;
|
std::vector<Function *> OrderedKernels;
|
||||||
|
|
||||||
for (Function &Func : M->functions()) {
|
for (Function &Func : M->functions()) {
|
||||||
if (Func.isDeclaration())
|
if (Func.isDeclaration())
|
||||||
continue;
|
continue;
|
||||||
if (!isKernelLDS(&Func))
|
if (!isKernelLDS(&Func))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (KernelsThatAllocateTableLDS.contains(&Func)) {
|
if (KernelsThatAllocateTableLDS.contains(&Func)) {
|
||||||
assert(Func.hasName()); // else fatal error earlier
|
assert(Func.hasName()); // else fatal error earlier
|
||||||
OrderedKernels.push_back(&Func);
|
OrderedKernels.push_back(&Func);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put them in an arbitrary but reproducible order
|
// Put them in an arbitrary but reproducible order
|
||||||
llvm::sort(OrderedKernels.begin(), OrderedKernels.end(),
|
llvm::sort(OrderedKernels.begin(), OrderedKernels.end(),
|
||||||
[](const Function *lhs, const Function *rhs) -> bool {
|
[](const Function *lhs, const Function *rhs) -> bool {
|
||||||
return lhs->getName() < rhs->getName();
|
return lhs->getName() < rhs->getName();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Annotate the kernels with their order in this vector
|
// Annotate the kernels with their order in this vector
|
||||||
LLVMContext &Ctx = M->getContext();
|
LLVMContext &Ctx = M->getContext();
|
||||||
IRBuilder<> Builder(Ctx);
|
IRBuilder<> Builder(Ctx);
|
||||||
|
|
||||||
if (OrderedKernels.size() > UINT32_MAX) {
|
if (OrderedKernels.size() > UINT32_MAX) {
|
||||||
// 32 bit keeps it in one SGPR. > 2**32 kernels won't fit on the GPU
|
// 32 bit keeps it in one SGPR. > 2**32 kernels won't fit on the GPU
|
||||||
report_fatal_error("Unimplemented LDS lowering for > 2**32 kernels");
|
report_fatal_error("Unimplemented LDS lowering for > 2**32 kernels");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < OrderedKernels.size(); i++) {
|
|
||||||
Metadata *AttrMDArgs[1] = {
|
|
||||||
ConstantAsMetadata::get(Builder.getInt32(i)),
|
|
||||||
};
|
|
||||||
OrderedKernels[i]->setMetadata("llvm.amdgcn.lds.kernel.id",
|
|
||||||
MDNode::get(Ctx, AttrMDArgs));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (size_t i = 0; i < OrderedKernels.size(); i++) {
|
||||||
|
Metadata *AttrMDArgs[1] = {
|
||||||
|
ConstantAsMetadata::get(Builder.getInt32(i)),
|
||||||
|
};
|
||||||
|
OrderedKernels[i]->setMetadata("llvm.amdgcn.lds.kernel.id",
|
||||||
|
MDNode::get(Ctx, AttrMDArgs));
|
||||||
|
}
|
||||||
|
|
||||||
return OrderedKernels;
|
return OrderedKernels;
|
||||||
}
|
}
|
||||||
|
@ -979,22 +977,22 @@ public:
|
||||||
// TODO: Looks like a latent bug, Replacement may not be marked
|
// TODO: Looks like a latent bug, Replacement may not be marked
|
||||||
// UsedByKernel here
|
// UsedByKernel here
|
||||||
replaceLDSVariablesWithStruct(M, Vec, Replacement, [](Use &U) {
|
replaceLDSVariablesWithStruct(M, Vec, Replacement, [](Use &U) {
|
||||||
return isa<Instruction>(U.getUser());
|
return isa<Instruction>(U.getUser());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!KernelsThatAllocateTableLDS.empty()) {
|
if (!KernelsThatAllocateTableLDS.empty()) {
|
||||||
LLVMContext &Ctx = M.getContext();
|
LLVMContext &Ctx = M.getContext();
|
||||||
IRBuilder<> Builder(Ctx);
|
IRBuilder<> Builder(Ctx);
|
||||||
|
|
||||||
// The ith element of this vector is kernel id i
|
// The ith element of this vector is kernel id i
|
||||||
std::vector<Function *> OrderedKernels =
|
std::vector<Function *> OrderedKernels =
|
||||||
assignLDSKernelIDToEachKernel(&M, KernelsThatAllocateTableLDS);
|
assignLDSKernelIDToEachKernel(&M, KernelsThatAllocateTableLDS);
|
||||||
|
|
||||||
for (size_t i = 0; i < OrderedKernels.size(); i++) {
|
for (size_t i = 0; i < OrderedKernels.size(); i++) {
|
||||||
markUsedByKernel(Builder, OrderedKernels[i],
|
markUsedByKernel(Builder, OrderedKernels[i],
|
||||||
KernelToReplacement[OrderedKernels[i]].SGV);
|
KernelToReplacement[OrderedKernels[i]].SGV);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The order must be consistent between lookup table and accesses to
|
// The order must be consistent between lookup table and accesses to
|
||||||
// lookup table
|
// lookup table
|
||||||
|
|
Loading…
Reference in New Issue
Block a user