[llvm-branch-commits] [llvm] e1833e7 - [NewPM][AMDGPU] Port amdgpu-unify-metadata

Arthur Eubanks via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Jan 4 12:02:02 PST 2021


Author: Arthur Eubanks
Date: 2021-01-04T11:57:46-08:00
New Revision: e1833e7493aede34aaf9c1a4480848d60dad7f1d

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

LOG: [NewPM][AMDGPU] Port amdgpu-unify-metadata

And add to AMDGPU opt pipeline.

Reviewed By: arsenm

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

Added: 
    

Modified: 
    llvm/lib/Target/AMDGPU/AMDGPU.h
    llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
    llvm/lib/Target/AMDGPU/AMDGPUUnifyMetadata.cpp
    llvm/test/CodeGen/AMDGPU/unify-metadata.ll
    llvm/tools/opt/opt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index c06f9ad66009..ac8b0effbdab 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -264,6 +264,10 @@ ModulePass* createAMDGPUUnifyMetadataPass();
 void initializeAMDGPUUnifyMetadataPass(PassRegistry&);
 extern char &AMDGPUUnifyMetadataID;
 
+struct AMDGPUUnifyMetadataPass : PassInfoMixin<AMDGPUUnifyMetadataPass> {
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+};
+
 void initializeSIOptimizeExecMaskingPreRAPass(PassRegistry&);
 extern char &SIOptimizeExecMaskingPreRAID;
 

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 765ec045d5f1..0e3d6df0d6ae 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -498,6 +498,10 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB,
           PM.addPass(AMDGPUPropagateAttributesLatePass(*this));
           return true;
         }
+        if (PassName == "amdgpu-unify-metadata") {
+          PM.addPass(AMDGPUUnifyMetadataPass());
+          return true;
+        }
         return false;
       });
   PB.registerPipelineParsingCallback(
@@ -547,6 +551,8 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB,
         if (Level == PassBuilder::OptimizationLevel::O0)
           return;
 
+        PM.addPass(AMDGPUUnifyMetadataPass());
+
         if (InternalizeSymbols) {
           PM.addPass(InternalizePass(mustPreserveGV));
         }

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUUnifyMetadata.cpp b/llvm/lib/Target/AMDGPU/AMDGPUUnifyMetadata.cpp
index f898456203a1..f3c9add70357 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUUnifyMetadata.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUUnifyMetadata.cpp
@@ -17,6 +17,7 @@
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 #include <algorithm>
 #include <cassert>
@@ -45,6 +46,7 @@ namespace {
 
   private:
     bool runOnModule(Module &M) override;
+  };
 
     /// Unify version metadata.
     /// \return true if changes are made.
@@ -106,41 +108,42 @@ namespace {
 
     return true;
   }
-};
 
-} // end anonymous namespace
+  bool unifyMetadataImpl(Module &M) {
+    const char *Vers[] = {kOCLMD::SpirVer, kOCLMD::OCLVer};
+    const char *Exts[] = {kOCLMD::UsedExt, kOCLMD::UsedOptCoreFeat,
+                          kOCLMD::CompilerOptions, kOCLMD::LLVMIdent};
 
-char AMDGPUUnifyMetadata::ID = 0;
+    bool Changed = false;
 
-char &llvm::AMDGPUUnifyMetadataID = AMDGPUUnifyMetadata::ID;
+    for (auto &I : Vers)
+      Changed |= unifyVersionMD(M, I, true);
 
-INITIALIZE_PASS(AMDGPUUnifyMetadata, "amdgpu-unify-metadata",
-                "Unify multiple OpenCL metadata due to linking",
-                false, false)
+    for (auto &I : Exts)
+      Changed |= unifyExtensionMD(M, I);
 
-ModulePass* llvm::createAMDGPUUnifyMetadataPass() {
-  return new AMDGPUUnifyMetadata();
-}
+    return Changed;
+  }
 
-bool AMDGPUUnifyMetadata::runOnModule(Module &M) {
-  const char* Vers[] = {
-      kOCLMD::SpirVer,
-      kOCLMD::OCLVer
-  };
-  const char* Exts[] = {
-      kOCLMD::UsedExt,
-      kOCLMD::UsedOptCoreFeat,
-      kOCLMD::CompilerOptions,
-      kOCLMD::LLVMIdent
-  };
+  } // end anonymous namespace
 
-  bool Changed = false;
+  char AMDGPUUnifyMetadata::ID = 0;
 
-  for (auto &I : Vers)
-    Changed |= unifyVersionMD(M, I, true);
+  char &llvm::AMDGPUUnifyMetadataID = AMDGPUUnifyMetadata::ID;
 
-  for (auto &I : Exts)
-    Changed |= unifyExtensionMD(M, I);
+  INITIALIZE_PASS(AMDGPUUnifyMetadata, "amdgpu-unify-metadata",
+                  "Unify multiple OpenCL metadata due to linking", false, false)
 
-  return Changed;
-}
+  ModulePass *llvm::createAMDGPUUnifyMetadataPass() {
+    return new AMDGPUUnifyMetadata();
+  }
+
+  bool AMDGPUUnifyMetadata::runOnModule(Module &M) {
+    return unifyMetadataImpl(M);
+  }
+
+  PreservedAnalyses AMDGPUUnifyMetadataPass::run(Module &M,
+                                                 ModuleAnalysisManager &AM) {
+    return unifyMetadataImpl(M) ? PreservedAnalyses::none()
+                                : PreservedAnalyses::all();
+  }

diff  --git a/llvm/test/CodeGen/AMDGPU/unify-metadata.ll b/llvm/test/CodeGen/AMDGPU/unify-metadata.ll
index d96583e71f13..ecf18cc18e49 100644
--- a/llvm/test/CodeGen/AMDGPU/unify-metadata.ll
+++ b/llvm/test/CodeGen/AMDGPU/unify-metadata.ll
@@ -1,4 +1,5 @@
 ; RUN: opt -mtriple=amdgcn--amdhsa -amdgpu-unify-metadata -S < %s | FileCheck -check-prefix=ALL %s
+; RUN: opt -mtriple=amdgcn--amdhsa -passes=amdgpu-unify-metadata -S < %s | FileCheck -check-prefix=ALL %s
 
 ; This test check that we have a singe metadata value after linking several
 ; modules for records such as opencl.ocl.version, llvm.ident and similar.

diff  --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index a02b884996e9..eee4f2ae0bb5 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -469,7 +469,8 @@ static bool shouldPinPassToLegacyPM(StringRef Pass) {
       "amdgpu-promote-alloca-to-vector",
       "amdgpu-lower-kernel-attributes",
       "amdgpu-propagate-attributes-early",
-      "amdgpu-propagate-attributes-late"};
+      "amdgpu-propagate-attributes-late",
+      "amdgpu-unify-metadata"};
   for (const auto &P : PassNameExactToIgnore)
     if (Pass == P)
       return false;


        


More information about the llvm-branch-commits mailing list