Chris Lattner | 12be936 | 2011-01-02 21:47:05 +0000 | [diff] [blame^] | 1 | //===- EarlyCSE.cpp - Simple and fast CSE pass ----------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This pass performs a simple dominator tree walk that eliminates trivially |
| 11 | // redundant instructions. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "early-cse" |
| 16 | #include "llvm/Transforms/Scalar.h" |
| 17 | #include "llvm/Analysis/Dominators.h" |
| 18 | #include "llvm/Pass.h" |
| 19 | using namespace llvm; |
| 20 | |
| 21 | namespace { |
| 22 | /// EarlyCSE - This pass does a simple depth-first walk over the dominator |
| 23 | /// tree, eliminating trivially redundant instructions and using instsimplify |
| 24 | /// to canonicalize things as it goes. It is intended to be fast and catch |
| 25 | /// obvious cases so that instcombine and other passes are more effective. It |
| 26 | /// is expected that a later pass of GVN will catch the interesting/hard |
| 27 | /// cases. |
| 28 | class EarlyCSE : public FunctionPass { |
| 29 | public: |
| 30 | static char ID; |
| 31 | explicit EarlyCSE() |
| 32 | : FunctionPass(ID) { |
| 33 | initializeEarlyCSEPass(*PassRegistry::getPassRegistry()); |
| 34 | } |
| 35 | |
| 36 | bool runOnFunction(Function &F); |
| 37 | |
| 38 | private: |
| 39 | // This transformation requires dominator postdominator info |
| 40 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 41 | AU.addRequired<DominatorTree>(); |
| 42 | AU.setPreservesCFG(); |
| 43 | } |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | char EarlyCSE::ID = 0; |
| 48 | |
| 49 | // createEarlyCSEPass - The public interface to this file. |
| 50 | FunctionPass *llvm::createEarlyCSEPass() { |
| 51 | return new EarlyCSE(); |
| 52 | } |
| 53 | |
| 54 | INITIALIZE_PASS_BEGIN(EarlyCSE, "early-cse", "Early CSE", false, false) |
| 55 | INITIALIZE_PASS_DEPENDENCY(DominatorTree) |
| 56 | INITIALIZE_PASS_END(EarlyCSE, "early-cse", "Early CSE", false, false) |
| 57 | |
| 58 | bool EarlyCSE::runOnFunction(Function &F) { |
| 59 | DominatorTree &DT = getAnalysis<DominatorTree>(); |
| 60 | (void)DT; |
| 61 | return false; |
| 62 | } |