blob: 1132166a34f80b9281dedc32c3bb6870804fadfc [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. */
52 kNoNodes, /**< @brief Skip BasicBlock traversal. */
53};
54
55/**
56 * @class Pass
57 * @brief Pass is the Pass structure for the optimizations.
58 * @details The following structure has the different optimization passes that we are going to do.
59 */
60class PassME: public Pass {
61 public:
62 explicit PassME(const char* name, DataFlowAnalysisMode type = kAllNodes,
63 unsigned int flags = 0u, const char* dump = "")
64 : Pass(name), traversal_type_(type), flags_(flags), dump_cfg_folder_(dump) {
65 }
66
67 PassME(const char* name, DataFlowAnalysisMode type, const char* dump)
68 : Pass(name), traversal_type_(type), flags_(0), dump_cfg_folder_(dump) {
69 }
70
71 PassME(const char* name, const char* dump)
72 : Pass(name), traversal_type_(kAllNodes), flags_(0), dump_cfg_folder_(dump) {
73 }
74
75 ~PassME() {
76 }
77
78 virtual DataFlowAnalysisMode GetTraversal() const {
79 return traversal_type_;
80 }
81
82 const char* GetDumpCFGFolder() const {
83 return dump_cfg_folder_;
84 }
85
86 bool GetFlag(OptimizationFlag flag) const {
87 return (flags_ & flag);
88 }
89
90 protected:
91 /** @brief Type of traversal: determines the order to execute the pass on the BasicBlocks. */
92 const DataFlowAnalysisMode traversal_type_;
93
94 /** @brief Flags for additional directives: used to determine if a particular clean-up is necessary post pass. */
95 const unsigned int flags_;
96
97 /** @brief CFG Dump Folder: what sub-folder to use for dumping the CFGs post pass. */
98 const char* const dump_cfg_folder_;
99};
100} // namespace art
101#endif // ART_COMPILER_DEX_PASS_ME_H_