blob: 9efd5aeb4030324ac16d7918615c90d41f1b6f16 [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 {
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070035 kOptimizationBasicBlockChange = 1, /**< @brief Has there been a change to a BasicBlock? */
36 kOptimizationDefUsesChange = 2, /**< @brief Has there been a change to a def-use? */
37 kLoopStructureChange = 4, /**< @brief Has there been a loop structural change? */
James C Scott4f596682014-05-01 05:52:04 -070038};
39
40// Data holder class.
41class PassMEDataHolder: public PassDataHolder {
42 public:
43 CompilationUnit* c_unit;
44 BasicBlock* bb;
45};
46
47enum DataFlowAnalysisMode {
48 kAllNodes = 0, /**< @brief All nodes. */
49 kPreOrderDFSTraversal, /**< @brief Depth-First-Search / Pre-Order. */
50 kRepeatingPreOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Pre-Order. */
51 kReversePostOrderDFSTraversal, /**< @brief Depth-First-Search / Reverse Post-Order. */
52 kRepeatingPostOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Post-Order. */
53 kRepeatingReversePostOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Reverse Post-Order. */
54 kPostOrderDOMTraversal, /**< @brief Dominator tree / Post-Order. */
Jean Christophe Beyler44e5bde2014-04-29 14:40:41 -070055 kTopologicalSortTraversal, /**< @brief Topological Order traversal. */
56 kRepeatingTopologicalSortTraversal, /**< @brief Repeating Topological Order traversal. */
James C Scott4f596682014-05-01 05:52:04 -070057 kNoNodes, /**< @brief Skip BasicBlock traversal. */
58};
59
60/**
61 * @class Pass
62 * @brief Pass is the Pass structure for the optimizations.
63 * @details The following structure has the different optimization passes that we are going to do.
64 */
65class PassME: public Pass {
66 public:
67 explicit PassME(const char* name, DataFlowAnalysisMode type = kAllNodes,
68 unsigned int flags = 0u, const char* dump = "")
69 : Pass(name), traversal_type_(type), flags_(flags), dump_cfg_folder_(dump) {
70 }
71
72 PassME(const char* name, DataFlowAnalysisMode type, const char* dump)
73 : Pass(name), traversal_type_(type), flags_(0), dump_cfg_folder_(dump) {
74 }
75
76 PassME(const char* name, const char* dump)
77 : Pass(name), traversal_type_(kAllNodes), flags_(0), dump_cfg_folder_(dump) {
78 }
79
80 ~PassME() {
81 }
82
83 virtual DataFlowAnalysisMode GetTraversal() const {
84 return traversal_type_;
85 }
86
87 const char* GetDumpCFGFolder() const {
88 return dump_cfg_folder_;
89 }
90
91 bool GetFlag(OptimizationFlag flag) const {
92 return (flags_ & flag);
93 }
94
95 protected:
96 /** @brief Type of traversal: determines the order to execute the pass on the BasicBlocks. */
97 const DataFlowAnalysisMode traversal_type_;
98
Jean Christophe Beyler2469e602014-05-06 20:36:55 -070099 /** @brief Flags for additional directives: used to determine if a particular post-optimization pass is necessary. */
James C Scott4f596682014-05-01 05:52:04 -0700100 const unsigned int flags_;
101
102 /** @brief CFG Dump Folder: what sub-folder to use for dumping the CFGs post pass. */
103 const char* const dump_cfg_folder_;
104};
105} // namespace art
106#endif // ART_COMPILER_DEX_PASS_ME_H_