[llvm] r276687 - [PM] Port SymbolRewriter to the new PM
Michael Kuperstein via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 25 13:52:00 PDT 2016
Author: mkuper
Date: Mon Jul 25 15:52:00 2016
New Revision: 276687
URL: http://llvm.org/viewvc/llvm-project?rev=276687&view=rev
Log:
[PM] Port SymbolRewriter to the new PM
Differential Revision: https://reviews.llvm.org/D22703
Modified:
llvm/trunk/include/llvm/InitializePasses.h
llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h
llvm/trunk/lib/Passes/PassBuilder.cpp
llvm/trunk/lib/Passes/PassRegistry.def
llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp
llvm/trunk/test/SymbolRewriter/rewrite.ll
llvm/trunk/tools/opt/opt.cpp
Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=276687&r1=276686&r2=276687&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Mon Jul 25 15:52:00 2016
@@ -288,7 +288,7 @@ void initializeRegisterCoalescerPass(Pas
void initializeRenameIndependentSubregsPass(PassRegistry&);
void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry&);
void initializeRewriteStatepointsForGCPass(PassRegistry&);
-void initializeRewriteSymbolsPass(PassRegistry&);
+void initializeRewriteSymbolsLegacyPassPass(PassRegistry&);
void initializeSCCPLegacyPassPass(PassRegistry &);
void initializeSCEVAAWrapperPassPass(PassRegistry&);
void initializeSLPVectorizerPass(PassRegistry&);
Modified: llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h?rev=276687&r1=276686&r2=276687&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/SymbolRewriter.h Mon Jul 25 15:52:00 2016
@@ -34,6 +34,7 @@
#define LLVM_TRANSFORMS_UTILS_SYMBOLREWRITER_H
#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
#include <list>
namespace llvm {
@@ -111,6 +112,24 @@ private:
ModulePass *createRewriteSymbolsPass();
ModulePass *createRewriteSymbolsPass(SymbolRewriter::RewriteDescriptorList &);
+
+class RewriteSymbolPass : public PassInfoMixin<RewriteSymbolPass> {
+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
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=276687&r1=276686&r2=276687&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Mon Jul 25 15:52:00 2016
@@ -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"
Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=276687&r1=276686&r2=276687&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Mon Jul 25 15:52:00 2016
@@ -63,6 +63,7 @@ MODULE_PASS("print-callgraph", CallGraph
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())
Modified: llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp?rev=276687&r1=276686&r2=276687&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SymbolRewriter.cpp Mon Jul 25 15:52:00 2016
@@ -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 @@ parseRewriteGlobalAliasDescriptor(yaml::
}
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 @@ bool RewriteSymbols::runOnModule(Module
return Changed;
}
-void RewriteSymbols::loadAndParseMapFiles() {
+void RewriteSymbolPass::loadAndParseMapFiles() {
const std::vector<std::string> 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);
}
Modified: llvm/trunk/test/SymbolRewriter/rewrite.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/SymbolRewriter/rewrite.ll?rev=276687&r1=276686&r2=276687&view=diff
==============================================================================
--- llvm/trunk/test/SymbolRewriter/rewrite.ll (original)
+++ llvm/trunk/test/SymbolRewriter/rewrite.ll Mon Jul 25 15:52:00 2016
@@ -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
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=276687&r1=276686&r2=276687&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Mon Jul 25 15:52:00 2016
@@ -361,7 +361,7 @@ int main(int argc, char **argv) {
// supported.
initializeCodeGenPreparePass(Registry);
initializeAtomicExpandPass(Registry);
- initializeRewriteSymbolsPass(Registry);
+ initializeRewriteSymbolsLegacyPassPass(Registry);
initializeWinEHPreparePass(Registry);
initializeDwarfEHPreparePass(Registry);
initializeSafeStackPass(Registry);
More information about the llvm-commits
mailing list