blob: ce41a2e5128b41a430f9b5cbaa360b55bfcdaecc [file] [log] [blame]
Roland Levillain75be2832014-10-17 17:02:00 +01001/*
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
Vladimir Markoa3a3c592015-06-12 14:30:53 +010020#include "base/arena_object.h"
Roland Levillain75be2832014-10-17 17:02:00 +010021#include "nodes.h"
Calin Juravleacf735c2015-02-12 15:25:22 +000022#include "optimizing_compiler_stats.h"
Roland Levillain75be2832014-10-17 17:02:00 +010023
24namespace art {
25
26/**
27 * Abstraction to implement an optimization pass.
28 */
Vladimir Markof9f64412015-09-02 14:05:49 +010029class HOptimization : public ArenaObject<kArenaAllocOptimization> {
Roland Levillain75be2832014-10-17 17:02:00 +010030 public:
31 HOptimization(HGraph* graph,
Calin Juravleacf735c2015-02-12 15:25:22 +000032 const char* pass_name,
33 OptimizingCompilerStats* stats = nullptr)
Roland Levillain75be2832014-10-17 17:02:00 +010034 : graph_(graph),
Calin Juravleacf735c2015-02-12 15:25:22 +000035 stats_(stats),
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000036 pass_name_(pass_name) {}
Roland Levillain75be2832014-10-17 17:02:00 +010037
38 virtual ~HOptimization() {}
39
Wojciech Staszkiewicz5319d3c2016-08-01 17:48:59 -070040 // Return the name of the pass. Pass names for a single HOptimization should be of form
41 // <optimization_name> or <optimization_name>$<pass_name> for common <optimization_name> prefix.
42 // Example: 'instruction_simplifier', 'instruction_simplifier$after_bce',
43 // 'instruction_simplifier$before_codegen'.
Roland Levillain75be2832014-10-17 17:02:00 +010044 const char* GetPassName() const { return pass_name_; }
45
Aart Bik854a02b2015-07-14 16:07:00 -070046 // Perform the analysis itself.
Roland Levillain75be2832014-10-17 17:02:00 +010047 virtual void Run() = 0;
48
Roland Levillain75be2832014-10-17 17:02:00 +010049 protected:
50 HGraph* const graph_;
Calin Juravleacf735c2015-02-12 15:25:22 +000051 // Used to record stats about the optimization.
52 OptimizingCompilerStats* const stats_;
Roland Levillain75be2832014-10-17 17:02:00 +010053
54 private:
Roland Levillain75be2832014-10-17 17:02:00 +010055 // Optimization pass name.
56 const char* pass_name_;
Roland Levillain75be2832014-10-17 17:02:00 +010057
58 DISALLOW_COPY_AND_ASSIGN(HOptimization);
59};
60
61} // namespace art
62
63#endif // ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_