From 827454e6e28cfed93db990b03b720ef7c23e6917 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Mon, 17 Oct 2011 17:17:43 +0000 Subject: [PATCH] svn mv Target/ARM/ARMGlobalMerge.cpp Transforms/Scalar/GlobalMerge.cpp There is no reason to have simple IR level pass in lib/Target. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142200 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/InitializePasses.h | 1 + include/llvm/Transforms/Scalar.h | 2 ++ lib/Target/ARM/ARMTargetMachine.cpp | 3 +- .../Scalar/GlobalMerge.cpp} | 33 +++++++++++-------- 4 files changed, 25 insertions(+), 14 deletions(-) rename lib/{Target/ARM/ARMGlobalMerge.cpp => Transforms/Scalar/GlobalMerge.cpp} (88%) diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index c91fbf8de81..3a926dbbc7c 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -136,6 +136,7 @@ void initializeLoopRotatePass(PassRegistry&); void initializeLoopSimplifyPass(PassRegistry&); void initializeLoopSplitterPass(PassRegistry&); void initializeLoopStrengthReducePass(PassRegistry&); +void initializeGlobalMergePass(PassRegistry&); void initializeLoopUnrollPass(PassRegistry&); void initializeLoopUnswitchPass(PassRegistry&); void initializeLoopIdiomRecognizePass(PassRegistry&); diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h index b1536f906d8..5c0e9c66fba 100644 --- a/include/llvm/Transforms/Scalar.h +++ b/include/llvm/Transforms/Scalar.h @@ -112,6 +112,8 @@ Pass *createLICMPass(); // Pass *createLoopStrengthReducePass(const TargetLowering *TLI = 0); +Pass *createGlobalMergePass(const TargetLowering *TLI = 0); + //===----------------------------------------------------------------------===// // // LoopUnswitch - This pass is a simple loop unswitching pass. diff --git a/lib/Target/ARM/ARMTargetMachine.cpp b/lib/Target/ARM/ARMTargetMachine.cpp index 96b1e89b0df..cf1432d64f2 100644 --- a/lib/Target/ARM/ARMTargetMachine.cpp +++ b/lib/Target/ARM/ARMTargetMachine.cpp @@ -20,6 +20,7 @@ #include "llvm/Support/FormattedStream.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Target/TargetOptions.h" +#include "llvm/Transforms/Scalar.h" using namespace llvm; static cl::opt @@ -97,7 +98,7 @@ ThumbTargetMachine::ThumbTargetMachine(const Target &T, StringRef TT, bool ARMBaseTargetMachine::addPreISel(PassManagerBase &PM, CodeGenOpt::Level OptLevel) { if (OptLevel != CodeGenOpt::None && EnableGlobalMerge) - PM.add(createARMGlobalMergePass(getTargetLowering())); + PM.add(createGlobalMergePass(getTargetLowering())); return false; } diff --git a/lib/Target/ARM/ARMGlobalMerge.cpp b/lib/Transforms/Scalar/GlobalMerge.cpp similarity index 88% rename from lib/Target/ARM/ARMGlobalMerge.cpp rename to lib/Transforms/Scalar/GlobalMerge.cpp index 5f863ea241c..0772b487293 100644 --- a/lib/Target/ARM/ARMGlobalMerge.cpp +++ b/lib/Transforms/Scalar/GlobalMerge.cpp @@ -1,4 +1,4 @@ -//===-- ARMGlobalMerge.cpp - Internal globals merging --------------------===// +//===-- GlobalMerge.cpp - Internal globals merging -----------------------===// // // The LLVM Compiler Infrastructure // @@ -51,9 +51,8 @@ // note that we saved 2 registers here almostly "for free". // ===---------------------------------------------------------------------===// -#define DEBUG_TYPE "arm-global-merge" -#include "ARM.h" -#include "llvm/CodeGen/Passes.h" +#define DEBUG_TYPE "global-merge" +#include "llvm/Transforms/Scalar.h" #include "llvm/Attributes.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" @@ -66,10 +65,12 @@ #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/ADT/Statistic.h" using namespace llvm; +STATISTIC(NumMerged , "Number of globals merged"); namespace { - class ARMGlobalMerge : public FunctionPass { + class GlobalMerge : public FunctionPass { /// TLI - Keep a pointer of a TargetLowering to consult for determining /// target type sizes. const TargetLowering *TLI; @@ -79,8 +80,10 @@ namespace { public: static char ID; // Pass identification, replacement for typeid. - explicit ARMGlobalMerge(const TargetLowering *tli) - : FunctionPass(ID), TLI(tli) {} + explicit GlobalMerge(const TargetLowering *tli = 0) + : FunctionPass(ID), TLI(tli) { + initializeGlobalMergePass(*PassRegistry::getPassRegistry()); + } virtual bool doInitialization(Module &M); virtual bool runOnFunction(Function &F); @@ -109,9 +112,12 @@ namespace { }; } // end anonymous namespace -char ARMGlobalMerge::ID = 0; +char GlobalMerge::ID = 0; +INITIALIZE_PASS(GlobalMerge, "global-merge", + "Global Merge", false, false) -bool ARMGlobalMerge::doMerge(SmallVectorImpl &Globals, + +bool GlobalMerge::doMerge(SmallVectorImpl &Globals, Module &M, bool isConst) const { const TargetData *TD = TLI->getTargetData(); @@ -153,6 +159,7 @@ bool ARMGlobalMerge::doMerge(SmallVectorImpl &Globals, Constant *GEP = ConstantExpr::getInBoundsGetElementPtr(MergedGV, Idx); Globals[k]->replaceAllUsesWith(GEP); Globals[k]->eraseFromParent(); + NumMerged++; } i = j; } @@ -161,7 +168,7 @@ bool ARMGlobalMerge::doMerge(SmallVectorImpl &Globals, } -bool ARMGlobalMerge::doInitialization(Module &M) { +bool GlobalMerge::doInitialization(Module &M) { SmallVector Globals, ConstGlobals, BSSGlobals; const TargetData *TD = TLI->getTargetData(); unsigned MaxOffset = TLI->getMaximalGlobalOffset(); @@ -210,10 +217,10 @@ bool ARMGlobalMerge::doInitialization(Module &M) { return Changed; } -bool ARMGlobalMerge::runOnFunction(Function &F) { +bool GlobalMerge::runOnFunction(Function &F) { return false; } -FunctionPass *llvm::createARMGlobalMergePass(const TargetLowering *tli) { - return new ARMGlobalMerge(tli); +Pass *llvm::createGlobalMergePass(const TargetLowering *tli) { + return new GlobalMerge(tli); }