Introduce a class to implement optimization passes.

- Add art::HOptimization.
- Rename art::ConstantPropagation to art::HConstantFolding in
  compiler/optimizing/constant_folding.h to avoid name
  clashes with a class of the same name in
  compiler/dex/post_opt_passes.h.
- Rename art::DeadCodeElimination to
  art::HDeadCodeElimination for consistency reasons.
- Have art::HDeadCodeElimination and art::HConstantFolding
  derive from art::HOptimization.
- Start to use these optimizations in
  art:OptimizingCompiler::TryCompile.

Change-Id: Iaab350c122d87b2333b3760312b15c0592d7e010
diff --git a/compiler/optimizing/graph_checker.h b/compiler/optimizing/graph_checker.h
index 34a770b..4fb07e0 100644
--- a/compiler/optimizing/graph_checker.h
+++ b/compiler/optimizing/graph_checker.h
@@ -19,15 +19,19 @@
 
 #include "nodes.h"
 
+#include <ostream>
+
 namespace art {
 
 // A control-flow graph visitor performing various checks.
 class GraphChecker : public HGraphVisitor {
  public:
-  GraphChecker(ArenaAllocator* allocator, HGraph* graph)
+  GraphChecker(ArenaAllocator* allocator, HGraph* graph,
+               const char* dump_prefix = "art::GraphChecker: ")
     : HGraphVisitor(graph),
       allocator_(allocator),
-      errors_(allocator, 0) {}
+      errors_(allocator, 0),
+      dump_prefix_(dump_prefix) {}
 
   // Check `block`.
   virtual void VisitBasicBlock(HBasicBlock* block) OVERRIDE;
@@ -45,6 +49,13 @@
     return errors_;
   }
 
+  // Print detected errors on output stream `os`.
+  void Dump(std::ostream& os) {
+    for (size_t i = 0, e = errors_.Size(); i < e; ++i) {
+      os << dump_prefix_ << errors_.Get(i) << std::endl;
+    }
+  }
+
  protected:
   ArenaAllocator* const allocator_;
   // The block currently visited.
@@ -53,6 +64,9 @@
   GrowableArray<std::string> errors_;
 
  private:
+  // String displayed before dumped errors.
+  const char* dump_prefix_;
+
   DISALLOW_COPY_AND_ASSIGN(GraphChecker);
 };
 
@@ -63,7 +77,7 @@
   typedef GraphChecker super_type;
 
   SSAChecker(ArenaAllocator* allocator, HGraph* graph)
-    : GraphChecker(allocator, graph) {}
+    : GraphChecker(allocator, graph, "art::SSAChecker: ") {}
 
   // Perform SSA form checks on `block`.
   virtual void VisitBasicBlock(HBasicBlock* block) OVERRIDE;