1 //===- EarlyCSE.cpp - Simple and fast CSE pass ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This pass performs a simple dominator tree walk that eliminates trivially
11 // redundant instructions.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "early-cse"
16 #include "llvm/Transforms/Scalar.h"
17 #include "llvm/Analysis/Dominators.h"
18 #include "llvm/Pass.h"
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
28 class EarlyCSE : public FunctionPass {
33 initializeEarlyCSEPass(*PassRegistry::getPassRegistry());
36 bool runOnFunction(Function &F);
39 // This transformation requires dominator postdominator info
40 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
41 AU.addRequired<DominatorTree>();
47 char EarlyCSE::ID = 0;
49 // createEarlyCSEPass - The public interface to this file.
50 FunctionPass *llvm::createEarlyCSEPass() {
51 return new EarlyCSE();
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)
58 bool EarlyCSE::runOnFunction(Function &F) {
59 DominatorTree &DT = getAnalysis<DominatorTree>();