llvm.org GIT mirror llvm / b339184
[PM] Port SymbolRewriter to the new PM Differential Revision: https://reviews.llvm.org/D22703 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276687 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Kuperstein 3 years ago
7 changed file(s) with 68 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
287287 void initializeRenameIndependentSubregsPass(PassRegistry&);
288288 void initializeReversePostOrderFunctionAttrsLegacyPassPass(PassRegistry&);
289289 void initializeRewriteStatepointsForGCPass(PassRegistry&);
290 void initializeRewriteSymbolsPass(PassRegistry&);
290 void initializeRewriteSymbolsLegacyPassPass(PassRegistry&);
291291 void initializeSCCPLegacyPassPass(PassRegistry &);
292292 void initializeSCEVAAWrapperPassPass(PassRegistry&);
293293 void initializeSLPVectorizerPass(PassRegistry&);
3333 #define LLVM_TRANSFORMS_UTILS_SYMBOLREWRITER_H
3434
3535 #include "llvm/IR/Module.h"
36 #include "llvm/IR/PassManager.h"
3637 #include
3738
3839 namespace llvm {
110111
111112 ModulePass *createRewriteSymbolsPass();
112113 ModulePass *createRewriteSymbolsPass(SymbolRewriter::RewriteDescriptorList &);
114
115 class RewriteSymbolPass : public PassInfoMixin {
116 public:
117 RewriteSymbolPass() { loadAndParseMapFiles(); }
118 RewriteSymbolPass(SymbolRewriter::RewriteDescriptorList &DL) {
119 Descriptors.splice(Descriptors.begin(), DL);
120 }
121
122 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
123
124 // Glue for old PM
125 bool runImpl(Module &M);
126
127 private:
128 void loadAndParseMapFiles();
129
130 SymbolRewriter::RewriteDescriptorList Descriptors;
131 };
113132 }
114133
115134 #endif //LLVM_TRANSFORMS_UTILS_SYMBOLREWRITER_H
118118 #include "llvm/Transforms/Utils/Mem2Reg.h"
119119 #include "llvm/Transforms/Utils/MemorySSA.h"
120120 #include "llvm/Transforms/Utils/SimplifyInstructions.h"
121 #include "llvm/Transforms/Utils/SymbolRewriter.h"
121122 #include "llvm/Transforms/Vectorize/LoopVectorize.h"
122123 #include "llvm/Transforms/Vectorize/SLPVectorizer.h"
123124
6262 MODULE_PASS("print", PrintModulePass(dbgs()))
6363 MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
6464 MODULE_PASS("print-lcg-dot", LazyCallGraphDOTPrinterPass(dbgs()))
65 MODULE_PASS("rewrite-symbols", RewriteSymbolPass())
6566 MODULE_PASS("rpo-functionattrs", ReversePostOrderFunctionAttrsPass())
6667 MODULE_PASS("sample-profile", SampleProfileLoaderPass())
6768 MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass())
5757 //===----------------------------------------------------------------------===//
5858
5959 #define DEBUG_TYPE "symbol-rewriter"
60 #include "llvm/Transforms/Utils/SymbolRewriter.h"
6061 #include "llvm/Pass.h"
6162 #include "llvm/ADT/SmallString.h"
6263 #include "llvm/IR/LegacyPassManager.h"
6768 #include "llvm/Support/SourceMgr.h"
6869 #include "llvm/Support/YAMLParser.h"
6970 #include "llvm/Support/raw_ostream.h"
70 #include "llvm/Transforms/Utils/SymbolRewriter.h"
7171
7272 using namespace llvm;
7373 using namespace SymbolRewriter;
496496 }
497497
498498 namespace {
499 class RewriteSymbols : public ModulePass {
499 class RewriteSymbolsLegacyPass : public ModulePass {
500500 public:
501501 static char ID; // Pass identification, replacement for typeid
502502
503 RewriteSymbols();
504 RewriteSymbols(SymbolRewriter::RewriteDescriptorList &DL);
503 RewriteSymbolsLegacyPass();
504 RewriteSymbolsLegacyPass(SymbolRewriter::RewriteDescriptorList &DL);
505505
506506 bool runOnModule(Module &M) override;
507507
508508 private:
509 void loadAndParseMapFiles();
510
511 SymbolRewriter::RewriteDescriptorList Descriptors;
509 RewriteSymbolPass Impl;
512510 };
513511
514 char RewriteSymbols::ID = 0;
515
516 RewriteSymbols::RewriteSymbols() : ModulePass(ID) {
517 initializeRewriteSymbolsPass(*PassRegistry::getPassRegistry());
518 loadAndParseMapFiles();
519 }
520
521 RewriteSymbols::RewriteSymbols(SymbolRewriter::RewriteDescriptorList &DL)
522 : ModulePass(ID) {
523 Descriptors.splice(Descriptors.begin(), DL);
524 }
525
526 bool RewriteSymbols::runOnModule(Module &M) {
512 char RewriteSymbolsLegacyPass::ID = 0;
513
514 RewriteSymbolsLegacyPass::RewriteSymbolsLegacyPass() : ModulePass(ID), Impl() {
515 initializeRewriteSymbolsLegacyPassPass(*PassRegistry::getPassRegistry());
516 }
517
518 RewriteSymbolsLegacyPass::RewriteSymbolsLegacyPass(
519 SymbolRewriter::RewriteDescriptorList &DL)
520 : ModulePass(ID), Impl(DL) {}
521
522 bool RewriteSymbolsLegacyPass::runOnModule(Module &M) {
523 return Impl.runImpl(M);
524 }
525 }
526
527 namespace llvm {
528 PreservedAnalyses RewriteSymbolPass::run(Module &M, ModuleAnalysisManager &AM) {
529 if (!runImpl(M))
530 return PreservedAnalyses::all();
531
532 return PreservedAnalyses::none();
533 }
534
535 bool RewriteSymbolPass::runImpl(Module &M) {
527536 bool Changed;
528537
529538 Changed = false;
533542 return Changed;
534543 }
535544
536 void RewriteSymbols::loadAndParseMapFiles() {
545 void RewriteSymbolPass::loadAndParseMapFiles() {
537546 const std::vector MapFiles(RewriteMapFiles);
538 SymbolRewriter::RewriteMapParser parser;
547 SymbolRewriter::RewriteMapParser Parser;
539548
540549 for (const auto &MapFile : MapFiles)
541 parser.parse(MapFile, &Descriptors);
542 }
543 }
544
545 INITIALIZE_PASS(RewriteSymbols, "rewrite-symbols", "Rewrite Symbols", false,
546 false)
547
548 ModulePass *llvm::createRewriteSymbolsPass() { return new RewriteSymbols(); }
550 Parser.parse(MapFile, &Descriptors);
551 }
552 }
553
554 INITIALIZE_PASS(RewriteSymbolsLegacyPass, "rewrite-symbols", "Rewrite Symbols",
555 false, false)
556
557 ModulePass *llvm::createRewriteSymbolsPass() {
558 return new RewriteSymbolsLegacyPass();
559 }
549560
550561 ModulePass *
551562 llvm::createRewriteSymbolsPass(SymbolRewriter::RewriteDescriptorList &DL) {
552 return new RewriteSymbols(DL);
553 }
563 return new RewriteSymbolsLegacyPass(DL);
564 }
0 ; RUN: opt -mtriple i686-win32 -rewrite-symbols -rewrite-map-file %p/rewrite.map \
1 ; RUN: %s -o - | llvm-dis | FileCheck %s
2 ; RUN: opt -mtriple i686-win32 -passes='rewrite-symbols' -rewrite-map-file %p/rewrite.map \
13 ; RUN: %s -o - | llvm-dis | FileCheck %s
24
35 declare void @source_function()
360360 // supported.
361361 initializeCodeGenPreparePass(Registry);
362362 initializeAtomicExpandPass(Registry);
363 initializeRewriteSymbolsPass(Registry);
363 initializeRewriteSymbolsLegacyPassPass(Registry);
364364 initializeWinEHPreparePass(Registry);
365365 initializeDwarfEHPreparePass(Registry);
366366 initializeSafeStackPass(Registry);