[llvm] 4e43ba2 - [NFC][AMDGPULowerModuleLDSPass] Use shorter APIs in markUsedByKernel

Juan Manuel MARTINEZ CAAMAÑO via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 00:55:13 PDT 2023


Author: Juan Manuel MARTINEZ CAAMAÑO
Date: 2023-07-19T09:54:53+02:00
New Revision: 4e43ba25998075c5facd98675e75268e72259d71

URL: https://github.com/llvm/llvm-project/commit/4e43ba25998075c5facd98675e75268e72259d71
DIFF: https://github.com/llvm/llvm-project/commit/4e43ba25998075c5facd98675e75268e72259d71.diff

LOG: [NFC][AMDGPULowerModuleLDSPass] Use shorter APIs in markUsedByKernel

* Use shorter versions of the LLVM API

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D155589

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 c766f977e0345a..e3a645977f9268 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -270,8 +270,7 @@ class AMDGPULowerModuleLDS : public ModulePass {
       LocalVar->removeDeadConstantUsers();
   }
 
-  static void markUsedByKernel(IRBuilder<> &Builder, Function *Func,
-                               GlobalVariable *SGV) {
+  static void markUsedByKernel(Function *Func, GlobalVariable *SGV) {
     // The llvm.amdgcn.module.lds instance is implicitly used by all kernels
     // that might call a function which accesses a field within it. This is
     // presently approximated to 'all kernels' if there are any such functions
@@ -292,22 +291,16 @@ class AMDGPULowerModuleLDS : public ModulePass {
     // equivalent target specific intrinsic which lasts until immediately after
     // codegen would suffice for that, but one would still need to ensure that
     // the variables are allocated in the anticpated order.
-
-    LLVMContext &Ctx = Func->getContext();
-
-    Builder.SetInsertPoint(Func->getEntryBlock().getFirstNonPHI());
-
-    FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), {});
+    IRBuilder<> Builder(Func->getEntryBlock().getFirstNonPHI());
 
     Function *Decl =
         Intrinsic::getDeclaration(Func->getParent(), Intrinsic::donothing, {});
 
-    Value *UseInstance[1] = {Builder.CreateInBoundsGEP(
-        SGV->getValueType(), SGV, ConstantInt::get(Type::getInt32Ty(Ctx), 0))};
+    Value *UseInstance[1] = {
+        Builder.CreateConstInBoundsGEP1_32(SGV->getValueType(), SGV, 0)};
 
-    Builder.CreateCall(FTy, Decl, {},
-                       {OperandBundleDefT<Value *>("ExplicitUse", UseInstance)},
-                       "");
+    Builder.CreateCall(
+        Decl, {}, {OperandBundleDefT<Value *>("ExplicitUse", UseInstance)});
   }
 
   static bool eliminateConstantExprUsesOfLDSFromAllInstructions(Module &M) {
@@ -884,8 +877,6 @@ class AMDGPULowerModuleLDS : public ModulePass {
     // allocate the module scope variable, otherwise leave them unchanged
     // Record on each kernel whether the module scope global is used by it
 
-    IRBuilder<> Builder(Ctx);
-
     for (Function &Func : M.functions()) {
       if (Func.isDeclaration() || !isKernelLDS(&Func))
         continue;
@@ -901,7 +892,7 @@ class AMDGPULowerModuleLDS : public ModulePass {
               return F == &Func;
             });
 
-        markUsedByKernel(Builder, &Func, ModuleScopeReplacement.SGV);
+        markUsedByKernel(&Func, ModuleScopeReplacement.SGV);
       }
     }
 
@@ -917,7 +908,6 @@ class AMDGPULowerModuleLDS : public ModulePass {
 
     // Create a struct for each kernel for the non-module-scope variables.
 
-    IRBuilder<> Builder(M.getContext());
     DenseMap<Function *, LDSVariableReplacement> KernelToReplacement;
     for (Function &Func : M.functions()) {
       if (Func.isDeclaration() || !isKernelLDS(&Func))
@@ -976,7 +966,7 @@ class AMDGPULowerModuleLDS : public ModulePass {
       auto Accesses = LDSUsesInfo.indirect_access.find(&Func);
       if ((Accesses != LDSUsesInfo.indirect_access.end()) &&
           !Accesses->second.empty())
-        markUsedByKernel(Builder, &Func, Replacement.SGV);
+        markUsedByKernel(&Func, Replacement.SGV);
 
       // remove preserves existing codegen
       removeLocalVarsFromUsedLists(M, KernelUsedVariables);
@@ -1065,7 +1055,7 @@ class AMDGPULowerModuleLDS : public ModulePass {
 
           KernelToCreatedDynamicLDS[func] = N;
 
-          markUsedByKernel(Builder, func, N);
+          markUsedByKernel(func, N);
 
           auto emptyCharArray = ArrayType::get(Type::getInt8Ty(Ctx), 0);
           auto GEP = ConstantExpr::getGetElementPtr(


        


More information about the llvm-commits mailing list