optimization.h revision a3a3c5943522e7325d60cfcbdd17aff1e138f53d
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_
18#define ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_
19
20#include "base/arena_object.h"
21#include "nodes.h"
22#include "optimizing_compiler_stats.h"
23
24namespace art {
25
26/**
27 * Abstraction to implement an optimization pass.
28 */
29class HOptimization : public ArenaObject<kArenaAllocMisc> {
30 public:
31  HOptimization(HGraph* graph,
32                bool is_in_ssa_form,
33                const char* pass_name,
34                OptimizingCompilerStats* stats = nullptr)
35      : graph_(graph),
36        stats_(stats),
37        is_in_ssa_form_(is_in_ssa_form),
38        pass_name_(pass_name) {}
39
40  virtual ~HOptimization() {}
41
42  // Return the name of the pass.
43  const char* GetPassName() const { return pass_name_; }
44
45  // Peform the analysis itself.
46  virtual void Run() = 0;
47
48  // Verify the graph; abort if it is not valid.
49  void Check();
50
51 protected:
52  void MaybeRecordStat(MethodCompilationStat compilation_stat, size_t count = 1) const;
53
54  HGraph* const graph_;
55  // Used to record stats about the optimization.
56  OptimizingCompilerStats* const stats_;
57
58 private:
59  // Does the analyzed graph use the SSA form?
60  const bool is_in_ssa_form_;
61  // Optimization pass name.
62  const char* pass_name_;
63
64  DISALLOW_COPY_AND_ASSIGN(HOptimization);
65};
66
67}  // namespace art
68
69#endif  // ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_
70