pass_driver.h revision 75ba13f244098f42584637b8fd3f6d74d2fc291a
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_DRIVER_H_
18#define ART_COMPILER_DEX_PASS_DRIVER_H_
19
20#include <vector>
21#include "pass.h"
22#include "safe_map.h"
23
24// Forward Declarations.
25class CompilationUnit;
26class Pass;
27
28namespace art {
29
30/**
31 * @class PassDriver
32 * @brief PassDriver is the wrapper around all Pass instances in order to execute them from the Middle-End
33 */
34class PassDriver {
35 public:
36  explicit PassDriver(CompilationUnit* cu, bool create_default_passes = true);
37
38  ~PassDriver();
39
40  /**
41   * @brief Insert a Pass: can warn if multiple passes have the same name.
42   * @param new_pass the new Pass to insert in the map and list.
43   * @param warn_override warn if the name of the Pass is already used.
44   */
45  void InsertPass(const Pass* new_pass);
46
47  /**
48   * @brief Run a pass using the name as key.
49   * @param c_unit the considered CompilationUnit.
50   * @param pass_name the Pass name.
51   * @return whether the pass was applied.
52   */
53  bool RunPass(CompilationUnit* c_unit, const char* pass_name);
54
55  /**
56   * @brief Run a pass using the Pass itself.
57   * @param time_split do we want a time split request(default: false)?
58   * @return whether the pass was applied.
59   */
60  bool RunPass(CompilationUnit* c_unit, const Pass* pass, bool time_split = false);
61
62  void Launch();
63
64  void HandlePassFlag(CompilationUnit* c_unit, const Pass* pass);
65
66  /**
67   * @brief Apply a patch: perform start/work/end functions.
68   */
69  void ApplyPass(CompilationUnit* c_unit, const Pass* pass);
70
71  /**
72   * @brief Dispatch a patch: walk the BasicBlocks depending on the traversal mode
73   */
74  void DispatchPass(CompilationUnit* c_unit, const Pass* pass);
75
76  void PrintPassNames() const;
77
78  const Pass* GetPass(const char* name) const;
79
80  const char* GetDumpCFGFolder() const {
81    return dump_cfg_folder_;
82  }
83
84 protected:
85  void CreatePasses();
86
87  /** @brief List of passes: provides the order to execute the passes. */
88  std::vector<const Pass*> pass_list_;
89
90  /** @brief The CompilationUnit on which to execute the passes on. */
91  CompilationUnit* const cu_;
92
93  /** @brief Dump CFG base folder: where is the base folder for dumping CFGs. */
94  const char* dump_cfg_folder_;
95};
96
97}  // namespace art
98#endif  // ART_COMPILER_DEX_PASS_DRIVER_H_
99