[llvm] fcbafc0 - [NFC][AMDGPULowerModuleLDSPass] Cleanup of getTableLookupKernelIndex
Juan Manuel MARTINEZ CAAMAÑO via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 19 00:55:11 PDT 2023
Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2023-07-19T09:54:53+02:00
New Revision: fcbafc066cc56e7dbb61929962d942288432242d
URL: https://github.com/llvm/llvm-project/commit/fcbafc066cc56e7dbb61929962d942288432242d
DIFF: https://github.com/llvm/llvm-project/commit/fcbafc066cc56e7dbb61929962d942288432242d.diff
LOG: [NFC][AMDGPULowerModuleLDSPass] Cleanup of getTableLookupKernelIndex
* Do a single lookup when querying the map
* Use shorter versions of the LLVM API
Reviewed By: JonChesterfield
Differential Revision: https://reviews.llvm.org/D155588
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index 0df07d342f94e1..c766f977e0345a 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -701,22 +701,18 @@ class AMDGPULowerModuleLDS : public ModulePass {
// Accesses from a function use the amdgcn_lds_kernel_id intrinsic which
// lowers to a read from a live in register. Emit it once in the entry
// block to spare deduplicating it later.
- if (tableKernelIndexCache.count(F) == 0) {
- LLVMContext &Ctx = M.getContext();
- IRBuilder<> Builder(Ctx);
- FunctionType *FTy = FunctionType::get(Type::getInt32Ty(Ctx), {});
+ auto [It, Inserted] = tableKernelIndexCache.try_emplace(F);
+ if (Inserted) {
Function *Decl =
Intrinsic::getDeclaration(&M, Intrinsic::amdgcn_lds_kernel_id, {});
- BasicBlock::iterator it =
- F->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
- Instruction &i = *it;
- Builder.SetInsertPoint(&i);
+ auto InsertAt = F->getEntryBlock().getFirstNonPHIOrDbgOrAlloca();
+ IRBuilder<> Builder(&*InsertAt);
- tableKernelIndexCache[F] = Builder.CreateCall(FTy, Decl, {});
+ It->second = Builder.CreateCall(Decl, {});
}
- return tableKernelIndexCache[F];
+ return It->second;
}
static std::vector<Function *> assignLDSKernelIDToEachKernel(
More information about the llvm-commits
mailing list