blob: f4cecd8519e4ba01ec05421e8957282c8202f038 [file] [log] [blame]
Dragos Sbirlea0e260a32013-06-21 09:20:34 -07001/*
2 * Copyright (C) 2013 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_SEA_IR_VISITOR_H_
18#define ART_COMPILER_SEA_IR_VISITOR_H_
19
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070020namespace sea_ir {
21
22class SeaGraph;
23class Region;
24class InstructionNode;
25class PhiInstructionNode;
26class SignatureNode;
27class ConstInstructionNode;
28class ReturnInstructionNode;
29class IfNeInstructionNode;
30class AddIntLit8InstructionNode;
31class MoveResultInstructionNode;
32class InvokeStaticInstructionNode;
33class AddIntInstructionNode;
34class AddIntLitInstructionNode;
35class GotoInstructionNode;
36class IfEqzInstructionNode;
37
38
39
40
41class IRVisitor {
42 public:
43 explicit IRVisitor():ordered_regions_() { }
44 virtual void Initialize(SeaGraph* graph) = 0;
45 virtual void Visit(SeaGraph* graph) = 0;
46 virtual void Visit(Region* region) = 0;
47 virtual void Visit(PhiInstructionNode* region) = 0;
48 virtual void Visit(SignatureNode* region) = 0;
49
50 virtual void Visit(InstructionNode* region) = 0;
51 virtual void Visit(ConstInstructionNode* instruction) = 0;
52 virtual void Visit(ReturnInstructionNode* instruction) = 0;
53 virtual void Visit(IfNeInstructionNode* instruction) = 0;
Brian Carlstrom7934ac22013-07-26 10:54:15 -070054 // virtual void Visit(AddIntLitInstructionNode* instruction) = 0;
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070055 virtual void Visit(MoveResultInstructionNode* instruction) = 0;
56 virtual void Visit(InvokeStaticInstructionNode* instruction) = 0;
57 virtual void Visit(AddIntInstructionNode* instruction) = 0;
58 virtual void Visit(GotoInstructionNode* instruction) = 0;
59 virtual void Visit(IfEqzInstructionNode* instruction) = 0;
60
Dragos Sbirleab40eddf2013-07-31 13:37:31 -070061 // Note: This flavor of visitor separates the traversal functions from the actual visiting part
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070062 // so that the Visitor subclasses don't duplicate code and can't get the traversal wrong.
63 // The disadvantage is the increased number of functions (and calls).
64 virtual void Traverse(SeaGraph* graph);
65 virtual void Traverse(Region* region);
66 // The following functions are meant to be empty and not pure virtual,
67 // because the parameter classes have no children to traverse.
68 virtual void Traverse(InstructionNode* region) { }
69 virtual void Traverse(ConstInstructionNode* instruction) { }
70 virtual void Traverse(ReturnInstructionNode* instruction) { }
71 virtual void Traverse(IfNeInstructionNode* instruction) { }
72 virtual void Traverse(AddIntLit8InstructionNode* instruction) { }
73 virtual void Traverse(MoveResultInstructionNode* instruction) { }
74 virtual void Traverse(InvokeStaticInstructionNode* instruction) { }
75 virtual void Traverse(AddIntInstructionNode* instruction) { }
76 virtual void Traverse(GotoInstructionNode* instruction) { }
77 virtual void Traverse(IfEqzInstructionNode* instruction) { }
78 virtual void Traverse(PhiInstructionNode* phi) { }
79 virtual void Traverse(SignatureNode* sig) { }
80 virtual ~IRVisitor() { }
81
82 protected:
83 std::vector<Region*> ordered_regions_;
84};
Brian Carlstrom7934ac22013-07-26 10:54:15 -070085} // namespace sea_ir
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070086#endif // ART_COMPILER_SEA_IR_VISITOR_H_