diff options
author | Davide Italiano <davide@freebsd.org> | 2016-05-05 00:51:09 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2016-05-05 00:51:09 +0000 |
commit | 164b9bc6fe269b17808bc2827010abe242106cc9 (patch) | |
tree | 471ff3f07eb95fb26e2c9dabefed8627952ff5fa /llvm/lib/Transforms/IPO/ConstantMerge.cpp | |
parent | ad1482c6f1e4e8d8b2d8bc44bc9f6c6cca33477f (diff) | |
download | llvm-164b9bc6fe269b17808bc2827010abe242106cc9.zip llvm-164b9bc6fe269b17808bc2827010abe242106cc9.tar.gz llvm-164b9bc6fe269b17808bc2827010abe242106cc9.tar.bz2 |
[PM] Port ConstantMerge to the new pass manager.
llvm-svn: 268582
Diffstat (limited to 'llvm/lib/Transforms/IPO/ConstantMerge.cpp')
-rw-r--r-- | llvm/lib/Transforms/IPO/ConstantMerge.cpp | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/llvm/lib/Transforms/IPO/ConstantMerge.cpp b/llvm/lib/Transforms/IPO/ConstantMerge.cpp index 9489c75..11f40e8 100644 --- a/llvm/lib/Transforms/IPO/ConstantMerge.cpp +++ b/llvm/lib/Transforms/IPO/ConstantMerge.cpp @@ -17,7 +17,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Transforms/IPO.h" +#include "llvm/Transforms/IPO/ConstantMerge.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallPtrSet.h" @@ -28,33 +28,13 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" #include "llvm/Pass.h" +#include "llvm/Transforms/IPO.h" using namespace llvm; #define DEBUG_TYPE "constmerge" STATISTIC(NumMerged, "Number of global constants merged"); -namespace { - struct ConstantMerge : public ModulePass { - static char ID; // Pass identification, replacement for typeid - ConstantMerge() : ModulePass(ID) { - initializeConstantMergePass(*PassRegistry::getPassRegistry()); - } - - // For this pass, process all of the globals in the module, eliminating - // duplicate constants. - bool runOnModule(Module &M) override; - }; -} - -char ConstantMerge::ID = 0; -INITIALIZE_PASS(ConstantMerge, "constmerge", - "Merge Duplicate Global Constants", false, false) - -ModulePass *llvm::createConstantMergePass() { return new ConstantMerge(); } - - - /// Find values that are marked as llvm.used. static void FindUsedValues(GlobalVariable *LLVMUsed, SmallPtrSetImpl<const GlobalValue*> &UsedValues) { @@ -87,10 +67,7 @@ static unsigned getAlignment(GlobalVariable *GV) { return GV->getParent()->getDataLayout().getPreferredAlignment(GV); } -bool ConstantMerge::runOnModule(Module &M) { - if (skipModule(M)) - return false; - +static bool mergeConstants(Module &M) { // Find all the globals that are marked "used". These cannot be merged. SmallPtrSet<const GlobalValue*, 8> UsedGlobals; FindUsedValues(M.getGlobalVariable("llvm.used"), UsedGlobals); @@ -214,3 +191,34 @@ bool ConstantMerge::runOnModule(Module &M) { Replacements.clear(); } } + +PreservedAnalyses ConstantMergePass::run(Module &M) { + if (!mergeConstants(M)) + return PreservedAnalyses::all(); + return PreservedAnalyses::none(); +} + +namespace { +struct ConstantMergeLegacyPass : public ModulePass { + static char ID; // Pass identification, replacement for typeid + ConstantMergeLegacyPass() : ModulePass(ID) { + initializeConstantMergeLegacyPassPass(*PassRegistry::getPassRegistry()); + } + + // For this pass, process all of the globals in the module, eliminating + // duplicate constants. + bool runOnModule(Module &M) { + if (skipModule(M)) + return false; + return mergeConstants(M); + } +}; +} + +char ConstantMergeLegacyPass::ID = 0; +INITIALIZE_PASS(ConstantMergeLegacyPass, "constmerge", + "Merge Duplicate Global Constants", false, false) + +ModulePass *llvm::createConstantMergePass() { + return new ConstantMergeLegacyPass(); +} |