diff options
author | Chris Lattner <sabre@nondot.org> | 2011-01-02 21:47:05 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-01-02 21:47:05 +0000 |
commit | 12be936cc912b1ff4d1c73c7f2c805a3462da1ab (patch) | |
tree | fa60d3ddd04810a992daf4cc95e26feeb4489a62 | |
parent | 63f9c3c49ac7011e6366fbec42716f3f70f1beee (diff) | |
download | external_llvm-12be936cc912b1ff4d1c73c7f2c805a3462da1ab.zip external_llvm-12be936cc912b1ff4d1c73c7f2c805a3462da1ab.tar.gz external_llvm-12be936cc912b1ff4d1c73c7f2c805a3462da1ab.tar.bz2 |
sketch out a new early cse pass. No functionality yet.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122713 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/InitializePasses.h | 1 | ||||
-rw-r--r-- | include/llvm/LinkAllPasses.h | 1 | ||||
-rw-r--r-- | include/llvm/Transforms/Scalar.h | 7 | ||||
-rw-r--r-- | lib/Transforms/Scalar/EarlyCSE.cpp | 62 | ||||
-rw-r--r-- | lib/Transforms/Scalar/Scalar.cpp | 1 |
5 files changed, 72 insertions, 0 deletions
diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index 604bd1a..8d3fa86 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -92,6 +92,7 @@ void initializeDomViewerPass(PassRegistry&); void initializeDominanceFrontierPass(PassRegistry&); void initializeDominatorTreePass(PassRegistry&); void initializeEdgeProfilerPass(PassRegistry&); +void initializeEarlyCSEPass(PassRegistry&); void initializeExpandISelPseudosPass(PassRegistry&); void initializeFindUsedTypesPass(PassRegistry&); void initializeFunctionAttrsPass(PassRegistry&); diff --git a/include/llvm/LinkAllPasses.h b/include/llvm/LinkAllPasses.h index 454d258..7dd8ebd 100644 --- a/include/llvm/LinkAllPasses.h +++ b/include/llvm/LinkAllPasses.h @@ -128,6 +128,7 @@ namespace { (void) llvm::createUnifyFunctionExitNodesPass(); (void) llvm::createInstCountPass(); (void) llvm::createCodeGenPreparePass(); + (void) llvm::createEarlyCSEPass(); (void) llvm::createGVNPass(); (void) llvm::createMemCpyOptPass(); (void) llvm::createLoopDeletionPass(); diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h index 4d0d3f6..f494586 100644 --- a/include/llvm/Transforms/Scalar.h +++ b/include/llvm/Transforms/Scalar.h @@ -260,6 +260,13 @@ extern char &LCSSAID; //===----------------------------------------------------------------------===// // +// EarlyCSE - This pass performs a simple and fast CSE pass over the dominator +// tree. +// +FunctionPass *createEarlyCSEPass(); + +//===----------------------------------------------------------------------===// +// // GVN - This pass performs global value numbering and redundant load // elimination cotemporaneously. // diff --git a/lib/Transforms/Scalar/EarlyCSE.cpp b/lib/Transforms/Scalar/EarlyCSE.cpp new file mode 100644 index 0000000..4445404 --- /dev/null +++ b/lib/Transforms/Scalar/EarlyCSE.cpp @@ -0,0 +1,62 @@ +//===- EarlyCSE.cpp - Simple and fast CSE pass ----------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This pass performs a simple dominator tree walk that eliminates trivially +// redundant instructions. +// +//===----------------------------------------------------------------------===// + +#define DEBUG_TYPE "early-cse" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Analysis/Dominators.h" +#include "llvm/Pass.h" +using namespace llvm; + +namespace { +/// EarlyCSE - This pass does a simple depth-first walk over the dominator +/// tree, eliminating trivially redundant instructions and using instsimplify +/// to canonicalize things as it goes. It is intended to be fast and catch +/// obvious cases so that instcombine and other passes are more effective. It +/// is expected that a later pass of GVN will catch the interesting/hard +/// cases. +class EarlyCSE : public FunctionPass { +public: + static char ID; + explicit EarlyCSE() + : FunctionPass(ID) { + initializeEarlyCSEPass(*PassRegistry::getPassRegistry()); + } + + bool runOnFunction(Function &F); + +private: + // This transformation requires dominator postdominator info + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired<DominatorTree>(); + AU.setPreservesCFG(); + } +}; +} + +char EarlyCSE::ID = 0; + +// createEarlyCSEPass - The public interface to this file. +FunctionPass *llvm::createEarlyCSEPass() { + return new EarlyCSE(); +} + +INITIALIZE_PASS_BEGIN(EarlyCSE, "early-cse", "Early CSE", false, false) +INITIALIZE_PASS_DEPENDENCY(DominatorTree) +INITIALIZE_PASS_END(EarlyCSE, "early-cse", "Early CSE", false, false) + +bool EarlyCSE::runOnFunction(Function &F) { + DominatorTree &DT = getAnalysis<DominatorTree>(); + (void)DT; + return false; +} diff --git a/lib/Transforms/Scalar/Scalar.cpp b/lib/Transforms/Scalar/Scalar.cpp index 0eaf289..27c1118 100644 --- a/lib/Transforms/Scalar/Scalar.cpp +++ b/lib/Transforms/Scalar/Scalar.cpp @@ -36,6 +36,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) { initializeDSEPass(Registry); initializeGEPSplitterPass(Registry); initializeGVNPass(Registry); + initializeEarlyCSEPass(Registry); initializeIndVarSimplifyPass(Registry); initializeJumpThreadingPass(Registry); initializeLICMPass(Registry); |