blob: 069fb45dc46d240c1aff238f0552635a94b7d9e4 [file] [log] [blame]
James C Scott4f596682014-05-01 05:52:04 -07001/*
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_DEX_PASS_ME_H_
18#define ART_COMPILER_DEX_PASS_ME_H_
19
20#include <string>
21#include "pass.h"
22
23namespace art {
24
25// Forward declarations.
26struct BasicBlock;
27struct CompilationUnit;
28class Pass;
29
30/**
31 * @brief OptimizationFlag is an enumeration to perform certain tasks for a given pass.
32 * @details Each enum should be a power of 2 to be correctly used.
33 */
34enum OptimizationFlag {
35};
36
37// Data holder class.
38class PassMEDataHolder: public PassDataHolder {
39 public:
40 CompilationUnit* c_unit;
41 BasicBlock* bb;
42};
43
44enum DataFlowAnalysisMode {
45 kAllNodes = 0, /**< @brief All nodes. */
46 kPreOrderDFSTraversal, /**< @brief Depth-First-Search / Pre-Order. */
47 kRepeatingPreOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Pre-Order. */
48 kReversePostOrderDFSTraversal, /**< @brief Depth-First-Search / Reverse Post-Order. */
49 kRepeatingPostOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Post-Order. */
50 kRepeatingReversePostOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Reverse Post-Order. */
51 kPostOrderDOMTraversal, /**< @brief Dominator tree / Post-Order. */
Jean Christophe Beyler44e5bde2014-04-29 14:40:41 -070052 kTopologicalSortTraversal, /**< @brief Topological Order traversal. */
53 kRepeatingTopologicalSortTraversal, /**< @brief Repeating Topological Order traversal. */
James C Scott4f596682014-05-01 05:52:04 -070054 kNoNodes, /**< @brief Skip BasicBlock traversal. */
55};
56
57/**
58 * @class Pass
59 * @brief Pass is the Pass structure for the optimizations.
60 * @details The following structure has the different optimization passes that we are going to do.
61 */
62class PassME: public Pass {
63 public:
64 explicit PassME(const char* name, DataFlowAnalysisMode type = kAllNodes,
65 unsigned int flags = 0u, const char* dump = "")
66 : Pass(name), traversal_type_(type), flags_(flags), dump_cfg_folder_(dump) {
67 }
68
69 PassME(const char* name, DataFlowAnalysisMode type, const char* dump)
70 : Pass(name), traversal_type_(type), flags_(0), dump_cfg_folder_(dump) {
71 }
72
73 PassME(const char* name, const char* dump)
74 : Pass(name), traversal_type_(kAllNodes), flags_(0), dump_cfg_folder_(dump) {
75 }
76
77 ~PassME() {
78 }
79
80 virtual DataFlowAnalysisMode GetTraversal() const {
81 return traversal_type_;
82 }
83
84 const char* GetDumpCFGFolder() const {
85 return dump_cfg_folder_;
86 }
87
88 bool GetFlag(OptimizationFlag flag) const {
89 return (flags_ & flag);
90 }
91
92 protected:
93 /** @brief Type of traversal: determines the order to execute the pass on the BasicBlocks. */
94 const DataFlowAnalysisMode traversal_type_;
95
96 /** @brief Flags for additional directives: used to determine if a particular clean-up is necessary post pass. */
97 const unsigned int flags_;
98
99 /** @brief CFG Dump Folder: what sub-folder to use for dumping the CFGs post pass. */
100 const char* const dump_cfg_folder_;
101};
102} // namespace art
103#endif // ART_COMPILER_DEX_PASS_ME_H_