Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -288,7 +288,7 @@ void initializeRenameIndependentSubregsPass(PassRegistry&); void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry&); void initializeRewriteStatepointsForGCPass(PassRegistry&); -void initializeRewriteSymbolsPass(PassRegistry&); +void initializeRewriteSymbolsLegacyPassPass(PassRegistry&); void initializeSCCPLegacyPassPass(PassRegistry &); void initializeSCEVAAWrapperPassPass(PassRegistry&); void initializeSLPVectorizerPass(PassRegistry&); Index: include/llvm/Transforms/Utils/SymbolRewriter.h =================================================================== --- include/llvm/Transforms/Utils/SymbolRewriter.h +++ include/llvm/Transforms/Utils/SymbolRewriter.h @@ -34,6 +34,7 @@ #define LLVM_TRANSFORMS_UTILS_SYMBOLREWRITER_H #include "llvm/IR/Module.h" +#include "llvm/IR/PassManager.h" #include namespace llvm { @@ -111,6 +112,24 @@ ModulePass *createRewriteSymbolsPass(); ModulePass *createRewriteSymbolsPass(SymbolRewriter::RewriteDescriptorList &); + +class RewriteSymbolPass : public PassInfoMixin { +public: + RewriteSymbolPass() { loadAndParseMapFiles(); } + RewriteSymbolPass(SymbolRewriter::RewriteDescriptorList &DL) { + Descriptors.splice(Descriptors.begin(), DL); + } + + PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); + + // Glue for old PM + bool runImpl(Module &M); + +private: + void loadAndParseMapFiles(); + + SymbolRewriter::RewriteDescriptorList Descriptors; +}; } #endif //LLVM_TRANSFORMS_UTILS_SYMBOLREWRITER_H Index: lib/Passes/PassBuilder.cpp =================================================================== --- lib/Passes/PassBuilder.cpp +++ lib/Passes/PassBuilder.cpp @@ -119,6 +119,7 @@ #include "llvm/Transforms/Utils/Mem2Reg.h" #include "llvm/Transforms/Utils/MemorySSA.h" #include "llvm/Transforms/Utils/SimplifyInstructions.h" +#include "llvm/Transforms/Utils/SymbolRewriter.h" #include "llvm/Transforms/Vectorize/LoopVectorize.h" #include "llvm/Transforms/Vectorize/SLPVectorizer.h" Index: lib/Passes/PassRegistry.def =================================================================== --- lib/Passes/PassRegistry.def +++ lib/Passes/PassRegistry.def @@ -63,6 +63,7 @@ MODULE_PASS("print", PrintModulePass(dbgs())) MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs())) MODULE_PASS("print-lcg-dot", LazyCallGraphDOTPrinterPass(dbgs())) +MODULE_PASS("rewrite-symbols", RewriteSymbolPass()) MODULE_PASS("rpo-functionattrs", ReversePostOrderFunctionAttrsPass()) MODULE_PASS("sample-profile", SampleProfileLoaderPass()) MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass()) Index: lib/Transforms/Utils/SymbolRewriter.cpp =================================================================== --- lib/Transforms/Utils/SymbolRewriter.cpp +++ lib/Transforms/Utils/SymbolRewriter.cpp @@ -58,6 +58,7 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "symbol-rewriter" +#include "llvm/Transforms/Utils/SymbolRewriter.h" #include "llvm/Pass.h" #include "llvm/ADT/SmallString.h" #include "llvm/IR/LegacyPassManager.h" @@ -68,7 +69,6 @@ #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/Utils/SymbolRewriter.h" using namespace llvm; using namespace SymbolRewriter; @@ -497,34 +497,43 @@ } namespace { -class RewriteSymbols : public ModulePass { +class RewriteSymbolsLegacyPass : public ModulePass { public: static char ID; // Pass identification, replacement for typeid - RewriteSymbols(); - RewriteSymbols(SymbolRewriter::RewriteDescriptorList &DL); + RewriteSymbolsLegacyPass(); + RewriteSymbolsLegacyPass(SymbolRewriter::RewriteDescriptorList &DL); bool runOnModule(Module &M) override; private: - void loadAndParseMapFiles(); - - SymbolRewriter::RewriteDescriptorList Descriptors; + RewriteSymbolPass Impl; }; -char RewriteSymbols::ID = 0; +char RewriteSymbolsLegacyPass::ID = 0; -RewriteSymbols::RewriteSymbols() : ModulePass(ID) { - initializeRewriteSymbolsPass(*PassRegistry::getPassRegistry()); - loadAndParseMapFiles(); +RewriteSymbolsLegacyPass::RewriteSymbolsLegacyPass() : ModulePass(ID), Impl() { + initializeRewriteSymbolsLegacyPassPass(*PassRegistry::getPassRegistry()); } -RewriteSymbols::RewriteSymbols(SymbolRewriter::RewriteDescriptorList &DL) - : ModulePass(ID) { - Descriptors.splice(Descriptors.begin(), DL); +RewriteSymbolsLegacyPass::RewriteSymbolsLegacyPass( + SymbolRewriter::RewriteDescriptorList &DL) + : ModulePass(ID), Impl(DL) {} + +bool RewriteSymbolsLegacyPass::runOnModule(Module &M) { + return Impl.runImpl(M); +} } -bool RewriteSymbols::runOnModule(Module &M) { +namespace llvm { +PreservedAnalyses RewriteSymbolPass::run(Module &M, ModuleAnalysisManager &AM) { + if (!runImpl(M)) + return PreservedAnalyses::all(); + + return PreservedAnalyses::none(); +} + +bool RewriteSymbolPass::runImpl(Module &M) { bool Changed; Changed = false; @@ -534,21 +543,23 @@ return Changed; } -void RewriteSymbols::loadAndParseMapFiles() { +void RewriteSymbolPass::loadAndParseMapFiles() { const std::vector MapFiles(RewriteMapFiles); - SymbolRewriter::RewriteMapParser parser; + SymbolRewriter::RewriteMapParser Parser; for (const auto &MapFile : MapFiles) - parser.parse(MapFile, &Descriptors); + Parser.parse(MapFile, &Descriptors); } } -INITIALIZE_PASS(RewriteSymbols, "rewrite-symbols", "Rewrite Symbols", false, - false) +INITIALIZE_PASS(RewriteSymbolsLegacyPass, "rewrite-symbols", "Rewrite Symbols", + false, false) -ModulePass *llvm::createRewriteSymbolsPass() { return new RewriteSymbols(); } +ModulePass *llvm::createRewriteSymbolsPass() { + return new RewriteSymbolsLegacyPass(); +} ModulePass * llvm::createRewriteSymbolsPass(SymbolRewriter::RewriteDescriptorList &DL) { - return new RewriteSymbols(DL); + return new RewriteSymbolsLegacyPass(DL); } Index: test/SymbolRewriter/rewrite.ll =================================================================== --- test/SymbolRewriter/rewrite.ll +++ test/SymbolRewriter/rewrite.ll @@ -1,5 +1,7 @@ ; RUN: opt -mtriple i686-win32 -rewrite-symbols -rewrite-map-file %p/rewrite.map \ ; RUN: %s -o - | llvm-dis | FileCheck %s +; RUN: opt -mtriple i686-win32 -passes='rewrite-symbols' -rewrite-map-file %p/rewrite.map \ +; RUN: %s -o - | llvm-dis | FileCheck %s declare void @source_function() @source_variable = external global i32 Index: tools/opt/opt.cpp =================================================================== --- tools/opt/opt.cpp +++ tools/opt/opt.cpp @@ -361,7 +361,7 @@ // supported. initializeCodeGenPreparePass(Registry); initializeAtomicExpandPass(Registry); - initializeRewriteSymbolsPass(Registry); + initializeRewriteSymbolsLegacyPassPass(Registry); initializeWinEHPreparePass(Registry); initializeDwarfEHPreparePass(Registry); initializeSafeStackPass(Registry);