blob: 4445404f6cc816892368ea336da26ea40416d5e5 [file] [log] [blame]
Chris Lattner12be9362011-01-02 21:47:05 +00001//===- 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"
19using namespace llvm;
20
21namespace {
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.
28class EarlyCSE : public FunctionPass {
29public:
30 static char ID;
31 explicit EarlyCSE()
32 : FunctionPass(ID) {
33 initializeEarlyCSEPass(*PassRegistry::getPassRegistry());
34 }
35
36 bool runOnFunction(Function &F);
37
38private:
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
47char EarlyCSE::ID = 0;
48
49// createEarlyCSEPass - The public interface to this file.
50FunctionPass *llvm::createEarlyCSEPass() {
51 return new EarlyCSE();
52}
53
54INITIALIZE_PASS_BEGIN(EarlyCSE, "early-cse", "Early CSE", false, false)
55INITIALIZE_PASS_DEPENDENCY(DominatorTree)
56INITIALIZE_PASS_END(EarlyCSE, "early-cse", "Early CSE", false, false)
57
58bool EarlyCSE::runOnFunction(Function &F) {
59 DominatorTree &DT = getAnalysis<DominatorTree>();
60 (void)DT;
61 return false;
62}