blob: af39e092c7c4e27e4dac7b371d1a7e34f5a7b3e2 [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
Roland Levillain75be2832014-10-17 17:02:00 +010020#include "nodes.h"
Calin Juravleacf735c2015-02-12 15:25:22 +000021#include "optimizing_compiler_stats.h"
Roland Levillain75be2832014-10-17 17:02:00 +010022
23namespace art {
24
David Brazdil5e8b1372015-01-23 14:39:08 +000025static const char* kBuilderPassName = "builder";
26static const char* kSsaBuilderPassName = "ssa_builder";
Nicolas Geoffray82091da2015-01-26 10:02:45 +000027static const char* kLivenessPassName = "liveness";
28static const char* kRegisterAllocatorPassName = "register";
29static const char* kLoopInvariantCodeMotionPassName = "licm";
30
Roland Levillain75be2832014-10-17 17:02:00 +010031/**
32 * Abstraction to implement an optimization pass.
33 */
34class HOptimization : public ValueObject {
35 public:
36 HOptimization(HGraph* graph,
37 bool is_in_ssa_form,
Calin Juravleacf735c2015-02-12 15:25:22 +000038 const char* pass_name,
39 OptimizingCompilerStats* stats = nullptr)
Roland Levillain75be2832014-10-17 17:02:00 +010040 : graph_(graph),
Calin Juravleacf735c2015-02-12 15:25:22 +000041 stats_(stats),
Roland Levillain75be2832014-10-17 17:02:00 +010042 is_in_ssa_form_(is_in_ssa_form),
Nicolas Geoffray5e6916c2014-11-18 16:53:35 +000043 pass_name_(pass_name) {}
Roland Levillain75be2832014-10-17 17:02:00 +010044
45 virtual ~HOptimization() {}
46
Roland Levillain75be2832014-10-17 17:02:00 +010047 // Return the name of the pass.
48 const char* GetPassName() const { return pass_name_; }
49
50 // Peform the analysis itself.
51 virtual void Run() = 0;
52
Roland Levillain75be2832014-10-17 17:02:00 +010053 // Verify the graph; abort if it is not valid.
54 void Check();
55
56 protected:
Calin Juravleacf735c2015-02-12 15:25:22 +000057 void MaybeRecordStat(MethodCompilationStat compilation_stat) const;
58
Roland Levillain75be2832014-10-17 17:02:00 +010059 HGraph* const graph_;
Calin Juravleacf735c2015-02-12 15:25:22 +000060 // Used to record stats about the optimization.
61 OptimizingCompilerStats* const stats_;
Roland Levillain75be2832014-10-17 17:02:00 +010062
63 private:
64 // Does the analyzed graph use the SSA form?
65 const bool is_in_ssa_form_;
66 // Optimization pass name.
67 const char* pass_name_;
Roland Levillain75be2832014-10-17 17:02:00 +010068
69 DISALLOW_COPY_AND_ASSIGN(HOptimization);
70};
71
72} // namespace art
73
74#endif // ART_COMPILER_OPTIMIZING_OPTIMIZATION_H_