86943ebd8555568fb7dc4eee6712e01bb313def6
[oota-llvm.git] / include / llvm / Transforms / Scalar / DCE.h
1 //===-- DCE.h - Functions that perform Dead Code Elimination -----*- C++ -*--=//
2 //
3 // This family of functions is useful for performing dead code elimination of 
4 // various sorts.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_OPT_DCE_H
9 #define LLVM_OPT_DCE_H
10
11 #include "llvm/Pass.h"
12 #include "llvm/BasicBlock.h"
13
14 namespace opt {
15
16 struct DeadCodeElimination : public Pass {
17   // External Interface:
18   //
19   static bool doDCE(Method *M);
20
21   // dceInstruction - Inspect the instruction at *BBI and figure out if it's
22   // [trivially] dead.  If so, remove the instruction and update the iterator
23   // to point to the instruction that immediately succeeded the original
24   // instruction.
25   //
26   static bool dceInstruction(BasicBlock::InstListType &BBIL,
27                              BasicBlock::iterator &BBI);
28
29   // Remove unused global values - This removes unused global values of no
30   // possible value.  This currently includes unused method prototypes and
31   // unitialized global variables.
32   //
33   static bool RemoveUnusedGlobalValues(Module *M);
34
35   // Pass Interface...
36   virtual bool doPassInitialization(Module *M) {
37     return RemoveUnusedGlobalValues(M);
38   }
39   virtual bool doPerMethodWork(Method *M) { return doDCE(M); }
40   virtual bool doPassFinalization(Module *M) {
41     return RemoveUnusedGlobalValues(M);
42   }
43 };
44
45
46
47 struct AgressiveDCE : public Pass {
48   // DoADCE - Execute the Agressive Dead Code Elimination Algorithm
49   //
50   static bool doADCE(Method *M);                        // Defined in ADCE.cpp
51
52   virtual bool doPerMethodWork(Method *M) {
53     return doADCE(M);
54   }
55 };
56
57
58 // SimplifyCFG - This function is used to do simplification of a CFG.  For
59 // example, it adjusts branches to branches to eliminate the extra hop, it
60 // eliminates unreachable basic blocks, and does other "peephole" optimization
61 // of the CFG.  It returns true if a modification was made, and returns an 
62 // iterator that designates the first element remaining after the block that
63 // was deleted.
64 //
65 // WARNING:  The entry node of a method may not be simplified.
66 //
67 bool SimplifyCFG(Method::iterator &BBIt);
68
69 }  // End namespace opt
70
71 #endif