1 //===-- DCE.h - Functions that perform Dead Code Elimination -----*- C++ -*--=//
3 // This family of functions is useful for performing dead code elimination of
6 //===----------------------------------------------------------------------===//
11 #include "llvm/Pass.h"
12 #include "llvm/BasicBlock.h"
14 struct DeadCodeElimination : public MethodPass {
15 // External Interface:
17 static bool doDCE(Method *M);
19 // dceInstruction - Inspect the instruction at *BBI and figure out if it's
20 // [trivially] dead. If so, remove the instruction and update the iterator
21 // to point to the instruction that immediately succeeded the original
24 static bool dceInstruction(BasicBlock::InstListType &BBIL,
25 BasicBlock::iterator &BBI);
27 // Remove unused global values - This removes unused global values of no
28 // possible value. This currently includes unused method prototypes and
29 // unitialized global variables.
31 static bool RemoveUnusedGlobalValues(Module *M);
34 virtual bool doInitialization(Module *M) {
35 return RemoveUnusedGlobalValues(M);
37 virtual bool runOnMethod(Method *M) { return doDCE(M); }
38 virtual bool doFinalization(Module *M) {
39 return RemoveUnusedGlobalValues(M);
45 struct AgressiveDCE : public MethodPass {
46 // DoADCE - Execute the Agressive Dead Code Elimination Algorithm
48 static bool doADCE(Method *M); // Defined in ADCE.cpp
50 virtual bool runOnMethod(Method *M) {
56 // SimplifyCFG - This function is used to do simplification of a CFG. For
57 // example, it adjusts branches to branches to eliminate the extra hop, it
58 // eliminates unreachable basic blocks, and does other "peephole" optimization
59 // of the CFG. It returns true if a modification was made, and returns an
60 // iterator that designates the first element remaining after the block that
63 // WARNING: The entry node of a method may not be simplified.
65 bool SimplifyCFG(Method::iterator &BBIt);