blob: ff698654cf021751f026d2a81f8a3f68dfa7612b [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;
Jean Christophe Beylere1f65bc2014-06-09 10:18:26 -070045 void* data;
James C Scott4f596682014-05-01 05:52:04 -070046};
47
48enum DataFlowAnalysisMode {
49 kAllNodes = 0, /**< @brief All nodes. */
50 kPreOrderDFSTraversal, /**< @brief Depth-First-Search / Pre-Order. */
51 kRepeatingPreOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Pre-Order. */
52 kReversePostOrderDFSTraversal, /**< @brief Depth-First-Search / Reverse Post-Order. */
53 kRepeatingPostOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Post-Order. */
54 kRepeatingReversePostOrderDFSTraversal, /**< @brief Depth-First-Search / Repeating Reverse Post-Order. */
55 kPostOrderDOMTraversal, /**< @brief Dominator tree / Post-Order. */
Jean Christophe Beyler44e5bde2014-04-29 14:40:41 -070056 kTopologicalSortTraversal, /**< @brief Topological Order traversal. */
57 kRepeatingTopologicalSortTraversal, /**< @brief Repeating Topological Order traversal. */
James C Scott4f596682014-05-01 05:52:04 -070058 kNoNodes, /**< @brief Skip BasicBlock traversal. */
59};
60
61/**
62 * @class Pass
63 * @brief Pass is the Pass structure for the optimizations.
64 * @details The following structure has the different optimization passes that we are going to do.
65 */
66class PassME: public Pass {
67 public:
68 explicit PassME(const char* name, DataFlowAnalysisMode type = kAllNodes,
69 unsigned int flags = 0u, const char* dump = "")
70 : Pass(name), traversal_type_(type), flags_(flags), dump_cfg_folder_(dump) {
71 }
72
73 PassME(const char* name, DataFlowAnalysisMode type, const char* dump)
74 : Pass(name), traversal_type_(type), flags_(0), dump_cfg_folder_(dump) {
75 }
76
77 PassME(const char* name, const char* dump)
78 : Pass(name), traversal_type_(kAllNodes), flags_(0), dump_cfg_folder_(dump) {
79 }
80
81 ~PassME() {
82 }
83
84 virtual DataFlowAnalysisMode GetTraversal() const {
85 return traversal_type_;
86 }
87
88 const char* GetDumpCFGFolder() const {
89 return dump_cfg_folder_;
90 }
91
92 bool GetFlag(OptimizationFlag flag) const {
93 return (flags_ & flag);
94 }
95
96 protected:
97 /** @brief Type of traversal: determines the order to execute the pass on the BasicBlocks. */
98 const DataFlowAnalysisMode traversal_type_;
99
Jean Christophe Beyler2469e602014-05-06 20:36:55 -0700100 /** @brief Flags for additional directives: used to determine if a particular post-optimization pass is necessary. */
James C Scott4f596682014-05-01 05:52:04 -0700101 const unsigned int flags_;
102
103 /** @brief CFG Dump Folder: what sub-folder to use for dumping the CFGs post pass. */
104 const char* const dump_cfg_folder_;
105};
106} // namespace art
107#endif // ART_COMPILER_DEX_PASS_ME_H_