blob: 4ce040e9ab6d4016340cb1ee9e7918c97a2d88cc [file] [log] [blame]
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -08001/*
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_H_
18#define ART_COMPILER_DEX_PASS_H_
19
20#include <string>
21
James C Scott4f596682014-05-01 05:52:04 -070022#include "base/macros.h"
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080023namespace art {
24
Jean Christophe Beyler44e5bde2014-04-29 14:40:41 -070025// Forward declarations.
26struct BasicBlock;
27struct CompilationUnit;
28class Pass;
29
James C Scott4f596682014-05-01 05:52:04 -070030// Empty Pass Data Class, can be extended by any pass extending the base Pass class.
31class PassDataHolder {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080032};
33
34/**
35 * @class Pass
James C Scott4f596682014-05-01 05:52:04 -070036 * @brief Base Pass class, can be extended to perform a more defined way of doing the work call.
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080037 */
38class Pass {
39 public:
James C Scott4f596682014-05-01 05:52:04 -070040 explicit Pass(const char* name)
41 : pass_name_(name) {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080042 }
43
Vladimir Marko75ba13f2014-01-28 12:15:24 +000044 virtual ~Pass() {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080045 }
46
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080047 virtual const char* GetName() const {
48 return pass_name_;
49 }
50
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080051 /**
52 * @brief Gate for the pass: determines whether to execute the pass or not considering a CompilationUnit
James C Scott4f596682014-05-01 05:52:04 -070053 * @param data the PassDataHolder.
54 * @return whether or not to execute the pass.
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080055 */
James C Scott4f596682014-05-01 05:52:04 -070056 virtual bool Gate(const PassDataHolder* data) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080057 // Unused parameter.
James C Scott4f596682014-05-01 05:52:04 -070058 UNUSED(data);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080059
60 // Base class says yes.
61 return true;
62 }
63
64 /**
James C Scott4f596682014-05-01 05:52:04 -070065 * @brief Start of the pass: called before the Worker function.
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080066 */
James C Scott4f596682014-05-01 05:52:04 -070067 virtual void Start(const PassDataHolder* data) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080068 // Unused parameter.
James C Scott4f596682014-05-01 05:52:04 -070069 UNUSED(data);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080070 }
71
72 /**
James C Scott4f596682014-05-01 05:52:04 -070073 * @brief End of the pass: called after the WalkBasicBlocks function.
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080074 */
James C Scott4f596682014-05-01 05:52:04 -070075 virtual void End(const PassDataHolder* data) const {
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080076 // Unused parameter.
James C Scott4f596682014-05-01 05:52:04 -070077 UNUSED(data);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080078 }
79
80 /**
James C Scott4f596682014-05-01 05:52:04 -070081 * @param data the object containing data necessary for the pass.
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080082 * @return whether or not there is a change when walking the BasicBlock
83 */
James C Scott4f596682014-05-01 05:52:04 -070084 virtual bool Worker(const PassDataHolder* data) const {
85 // Unused parameter.
86 UNUSED(data);
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080087
88 // BasicBlock did not change.
89 return false;
90 }
91
92 protected:
93 /** @brief The pass name: used for searching for a pass when running a particular pass or debugging. */
94 const char* const pass_name_;
95
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080096 private:
97 // In order to make the all passes not copy-friendly.
98 DISALLOW_COPY_AND_ASSIGN(Pass);
99};
100} // namespace art
101#endif // ART_COMPILER_DEX_PASS_H_