pass_me.h revision 1fd4821f6b3ac57a44c2ce91025686da4641d197
1/*
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  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? */
38};
39
40// Data holder class.
41class PassMEDataHolder: public PassDataHolder {
42  public:
43    CompilationUnit* c_unit;
44    BasicBlock* bb;
45    void* data;
46};
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. */
56  kTopologicalSortTraversal,               /**< @brief Topological Order traversal. */
57  kRepeatingTopologicalSortTraversal,      /**< @brief Repeating Topological Order traversal. */
58  kLoopRepeatingTopologicalSortTraversal,  /**< @brief Loop-repeating Topological Order traversal. */
59  kNoNodes,                                /**< @brief Skip BasicBlock traversal. */
60};
61
62/**
63 * @class Pass
64 * @brief Pass is the Pass structure for the optimizations.
65 * @details The following structure has the different optimization passes that we are going to do.
66 */
67class PassME: public Pass {
68 public:
69  explicit PassME(const char* name, DataFlowAnalysisMode type = kAllNodes,
70          unsigned int flags = 0u, const char* dump = "")
71    : Pass(name), traversal_type_(type), flags_(flags), dump_cfg_folder_(dump) {
72  }
73
74  PassME(const char* name, DataFlowAnalysisMode type, const char* dump)
75    : Pass(name), traversal_type_(type), flags_(0), dump_cfg_folder_(dump) {
76  }
77
78  PassME(const char* name, const char* dump)
79    : Pass(name), traversal_type_(kAllNodes), flags_(0), dump_cfg_folder_(dump) {
80  }
81
82  ~PassME() {
83  }
84
85  virtual DataFlowAnalysisMode GetTraversal() const {
86    return traversal_type_;
87  }
88
89  const char* GetDumpCFGFolder() const {
90    return dump_cfg_folder_;
91  }
92
93  bool GetFlag(OptimizationFlag flag) const {
94    return (flags_ & flag);
95  }
96
97 protected:
98  /** @brief Type of traversal: determines the order to execute the pass on the BasicBlocks. */
99  const DataFlowAnalysisMode traversal_type_;
100
101  /** @brief Flags for additional directives: used to determine if a particular post-optimization pass is necessary. */
102  const unsigned int flags_;
103
104  /** @brief CFG Dump Folder: what sub-folder to use for dumping the CFGs post pass. */
105  const char* const dump_cfg_folder_;
106};
107}  // namespace art
108#endif  // ART_COMPILER_DEX_PASS_ME_H_
109