[llvm] fa2b1cb - [NFC][AMDGPULowerKernelAttributes] Factorize repeated code into function
Juan Manuel MARTINEZ CAAMAÑO via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 5 07:42:00 PDT 2022
Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2022-10-05T09:26:39-05:00
New Revision: fa2b1cb8c910cdb83104eb4c8c83d696c6f55df4
URL: https://github.com/llvm/llvm-project/commit/fa2b1cb8c910cdb83104eb4c8c83d696c6f55df4
DIFF: https://github.com/llvm/llvm-project/commit/fa2b1cb8c910cdb83104eb4c8c83d696c6f55df4.diff
LOG: [NFC][AMDGPULowerKernelAttributes] Factorize repeated code into function
Differential Revision: https://reviews.llvm.org/D135266
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
index 763593b45dd1..56e5e0708492 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerKernelAttributes.cpp
@@ -74,6 +74,13 @@ class AMDGPULowerKernelAttributes : public ModulePass {
}
};
+Function *getBasePtrIntrinsic(Module &M, bool IsV5OrAbove) {
+ auto IntrinsicId = IsV5OrAbove ? Intrinsic::amdgcn_implicitarg_ptr
+ : Intrinsic::amdgcn_dispatch_ptr;
+ StringRef Name = Intrinsic::getName(IntrinsicId);
+ return M.getFunction(Name);
+}
+
} // end anonymous namespace
static bool processUse(CallInst *CI, bool IsV5OrAbove) {
@@ -315,17 +322,8 @@ static bool processUse(CallInst *CI, bool IsV5OrAbove) {
// TargetPassConfig for subtarget.
bool AMDGPULowerKernelAttributes::runOnModule(Module &M) {
bool MadeChange = false;
- Function *BasePtr = nullptr;
bool IsV5OrAbove = AMDGPU::getAmdhsaCodeObjectVersion() >= 5;
- if (IsV5OrAbove) {
- StringRef ImplicitArgPtrName =
- Intrinsic::getName(Intrinsic::amdgcn_implicitarg_ptr);
- BasePtr = M.getFunction(ImplicitArgPtrName);
- } else { // Pre-V5.
- StringRef DispatchPtrName =
- Intrinsic::getName(Intrinsic::amdgcn_dispatch_ptr);
- BasePtr = M.getFunction(DispatchPtrName);
- }
+ Function *BasePtr = getBasePtrIntrinsic(M, IsV5OrAbove);
if (!BasePtr) // ImplicitArgPtr/DispatchPtr not used.
return false;
@@ -356,17 +354,8 @@ ModulePass *llvm::createAMDGPULowerKernelAttributesPass() {
PreservedAnalyses
AMDGPULowerKernelAttributesPass::run(Function &F, FunctionAnalysisManager &AM) {
- Function *BasePtr = nullptr;
bool IsV5OrAbove = AMDGPU::getAmdhsaCodeObjectVersion() >= 5;
- if (IsV5OrAbove) {
- StringRef ImplicitArgPtrName =
- Intrinsic::getName(Intrinsic::amdgcn_implicitarg_ptr);
- BasePtr = F.getParent()->getFunction(ImplicitArgPtrName);
- } else { // Pre_V5.
- StringRef DispatchPtrName =
- Intrinsic::getName(Intrinsic::amdgcn_dispatch_ptr);
- BasePtr = F.getParent()->getFunction(DispatchPtrName);
- }
+ Function *BasePtr = getBasePtrIntrinsic(*F.getParent(), IsV5OrAbove);
if (!BasePtr) // ImplicitArgPtr/DispatchPtr not used.
return PreservedAnalyses::all();
More information about the llvm-commits
mailing list