[llvm] 0c0387c - [NVPTX] Port GenericToNVVM to the new PM.

Pavel Kopyl via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 22 16:57:07 PDT 2023


Author: Pavel Kopyl
Date: 2023-03-23T00:56:14+01:00
New Revision: 0c0387c7a5e979d2dbf791404c7398856895f8fb

URL: https://github.com/llvm/llvm-project/commit/0c0387c7a5e979d2dbf791404c7398856895f8fb
DIFF: https://github.com/llvm/llvm-project/commit/0c0387c7a5e979d2dbf791404c7398856895f8fb.diff

LOG: [NVPTX] Port GenericToNVVM to the new PM.

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

Added: 
    

Modified: 
    llvm/lib/Target/NVPTX/NVPTX.h
    llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
    llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
    llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/NVPTX/NVPTX.h b/llvm/lib/Target/NVPTX/NVPTX.h
index 95184420f608..521a7843b114 100644
--- a/llvm/lib/Target/NVPTX/NVPTX.h
+++ b/llvm/lib/Target/NVPTX/NVPTX.h
@@ -38,7 +38,7 @@ enum CondCodes {
 FunctionPass *createNVPTXISelDag(NVPTXTargetMachine &TM,
                                  llvm::CodeGenOpt::Level OptLevel);
 ModulePass *createNVPTXAssignValidGlobalNamesPass();
-ModulePass *createGenericToNVVMPass();
+ModulePass *createGenericToNVVMLegacyPass();
 FunctionPass *createNVVMIntrRangePass(unsigned int SmVersion);
 FunctionPass *createNVVMReflectPass(unsigned int SmVersion);
 MachineFunctionPass *createNVPTXPrologEpilogPass();
@@ -67,6 +67,10 @@ struct NVVMReflectPass : PassInfoMixin<NVVMReflectPass> {
   unsigned SmVersion;
 };
 
+struct GenericToNVVMPass : PassInfoMixin<GenericToNVVMPass> {
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+};
+
 namespace NVPTX {
 enum DrvInterface {
   NVCL,

diff  --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
index d892023c6cb7..4f03e474edb4 100644
--- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp
@@ -29,19 +29,13 @@
 using namespace llvm;
 
 namespace llvm {
-void initializeGenericToNVVMPass(PassRegistry &);
+void initializeGenericToNVVMLegacyPassPass(PassRegistry &);
 }
 
 namespace {
-class GenericToNVVM : public ModulePass {
+class GenericToNVVM {
 public:
-  static char ID;
-
-  GenericToNVVM() : ModulePass(ID) {}
-
-  bool runOnModule(Module &M) override;
-
-  void getAnalysisUsage(AnalysisUsage &AU) const override {}
+  bool runOnModule(Module &M);
 
 private:
   Value *remapConstant(Module *M, Function *F, Constant *C,
@@ -59,15 +53,6 @@ class GenericToNVVM : public ModulePass {
 };
 } // end namespace
 
-char GenericToNVVM::ID = 0;
-
-ModulePass *llvm::createGenericToNVVMPass() { return new GenericToNVVM(); }
-
-INITIALIZE_PASS(
-    GenericToNVVM, "generic-to-nvvm",
-    "Ensure that the global variables are in the global address space", false,
-    false)
-
 bool GenericToNVVM::runOnModule(Module &M) {
   // Create a clone of each global variable that has the default address space.
   // The clone is created with the global address space  specifier, and the pair
@@ -293,3 +278,34 @@ Value *GenericToNVVM::remapConstantExpr(Module *M, Function *F, ConstantExpr *C,
     llvm_unreachable("GenericToNVVM encountered an unsupported ConstantExpr");
   }
 }
+
+namespace {
+class GenericToNVVMLegacyPass : public ModulePass {
+public:
+  static char ID;
+
+  GenericToNVVMLegacyPass() : ModulePass(ID) {}
+
+  bool runOnModule(Module &M) override;
+};
+} // namespace
+
+char GenericToNVVMLegacyPass::ID = 0;
+
+ModulePass *llvm::createGenericToNVVMLegacyPass() {
+  return new GenericToNVVMLegacyPass();
+}
+
+INITIALIZE_PASS(
+    GenericToNVVMLegacyPass, "generic-to-nvvm",
+    "Ensure that the global variables are in the global address space", false,
+    false)
+
+bool GenericToNVVMLegacyPass::runOnModule(Module &M) {
+  return GenericToNVVM().runOnModule(M);
+}
+
+PreservedAnalyses GenericToNVVMPass::run(Module &M, ModuleAnalysisManager &AM) {
+  return GenericToNVVM().runOnModule(M) ? PreservedAnalyses::none()
+                                        : PreservedAnalyses::all();
+}

diff  --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
index 5ff9b4df6d7f..3d1e4fcde90a 100644
--- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -64,7 +64,7 @@ static cl::opt<bool> UseShortPointersOpt(
 
 namespace llvm {
 
-void initializeGenericToNVVMPass(PassRegistry&);
+void initializeGenericToNVVMLegacyPassPass(PassRegistry &);
 void initializeNVPTXAllocaHoistingPass(PassRegistry &);
 void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry&);
 void initializeNVPTXAtomicLowerPass(PassRegistry &);
@@ -89,7 +89,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeNVPTXTarget() {
   // but it's very NVPTX-specific.
   initializeNVVMReflectPass(PR);
   initializeNVVMIntrRangePass(PR);
-  initializeGenericToNVVMPass(PR);
+  initializeGenericToNVVMLegacyPassPass(PR);
   initializeNVPTXAllocaHoistingPass(PR);
   initializeNVPTXAssignValidGlobalNamesPass(PR);
   initializeNVPTXAtomicLowerPass(PR);
@@ -246,6 +246,16 @@ void NVPTXTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
     return false;
   });
 
+  PB.registerPipelineParsingCallback(
+      [](StringRef PassName, ModulePassManager &PM,
+         ArrayRef<PassBuilder::PipelineElement>) {
+        if (PassName == "generic-to-nvvm") {
+          PM.addPass(GenericToNVVMPass());
+          return true;
+        }
+        return false;
+      });
+
   PB.registerPipelineStartEPCallback(
       [this](ModulePassManager &PM, OptimizationLevel Level) {
         FunctionPassManager FPM;
@@ -348,7 +358,7 @@ void NVPTXPassConfig::addIRPasses() {
   if (getOptLevel() != CodeGenOpt::None)
     addPass(createNVPTXImageOptimizerPass());
   addPass(createNVPTXAssignValidGlobalNamesPass());
-  addPass(createGenericToNVVMPass());
+  addPass(createGenericToNVVMLegacyPass());
 
   // NVPTXLowerArgs is required for correctness and should be run right
   // before the address space inference passes.

diff  --git a/llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll b/llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll
index 51344b474d29..daed7c1c98f0 100644
--- a/llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll
+++ b/llvm/test/CodeGen/NVPTX/generic-to-nvvm-ir.ll
@@ -1,6 +1,7 @@
 ; Verify functionality of NVPTXGenericToNVVM.cpp pass.
 ;
 ; RUN: opt < %s -march nvptx64 -S -generic-to-nvvm | FileCheck %s
+; RUN: opt < %s -march nvptx64 -S -passes='generic-to-nvvm' | FileCheck %s
 
 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
 target triple = "nvptx64-nvidia-cuda"


        


More information about the llvm-commits mailing list