blob: a4fec7b8a90398aef3ef781602d139d661e877a1 [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
20#include "llvm/IR/IRBuilder.h"
21#include "llvm/IR/LLVMContext.h"
22#include "llvm/IR/Module.h"
23#include "llvm/Analysis/Verifier.h"
24// TODO: Separating the root visitor from the code_gen visitor
25// would allow me to not include llvm headers here.
26
27
28namespace sea_ir {
29
30class SeaGraph;
31class Region;
32class InstructionNode;
33class PhiInstructionNode;
34class SignatureNode;
35class ConstInstructionNode;
36class ReturnInstructionNode;
37class IfNeInstructionNode;
38class AddIntLit8InstructionNode;
39class MoveResultInstructionNode;
40class InvokeStaticInstructionNode;
41class AddIntInstructionNode;
42class AddIntLitInstructionNode;
43class GotoInstructionNode;
44class IfEqzInstructionNode;
45
46
47
48
49class IRVisitor {
50 public:
51 explicit IRVisitor():ordered_regions_() { }
52 virtual void Initialize(SeaGraph* graph) = 0;
53 virtual void Visit(SeaGraph* graph) = 0;
54 virtual void Visit(Region* region) = 0;
55 virtual void Visit(PhiInstructionNode* region) = 0;
56 virtual void Visit(SignatureNode* region) = 0;
57
58 virtual void Visit(InstructionNode* region) = 0;
59 virtual void Visit(ConstInstructionNode* instruction) = 0;
60 virtual void Visit(ReturnInstructionNode* instruction) = 0;
61 virtual void Visit(IfNeInstructionNode* instruction) = 0;
Brian Carlstrom7934ac22013-07-26 10:54:15 -070062 // virtual void Visit(AddIntLitInstructionNode* instruction) = 0;
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070063 virtual void Visit(MoveResultInstructionNode* instruction) = 0;
64 virtual void Visit(InvokeStaticInstructionNode* instruction) = 0;
65 virtual void Visit(AddIntInstructionNode* instruction) = 0;
66 virtual void Visit(GotoInstructionNode* instruction) = 0;
67 virtual void Visit(IfEqzInstructionNode* instruction) = 0;
68
69 // Note: This favor of visitor separates the traversal functions from the actual visiting part
70 // so that the Visitor subclasses don't duplicate code and can't get the traversal wrong.
71 // The disadvantage is the increased number of functions (and calls).
72 virtual void Traverse(SeaGraph* graph);
73 virtual void Traverse(Region* region);
74 // The following functions are meant to be empty and not pure virtual,
75 // because the parameter classes have no children to traverse.
76 virtual void Traverse(InstructionNode* region) { }
77 virtual void Traverse(ConstInstructionNode* instruction) { }
78 virtual void Traverse(ReturnInstructionNode* instruction) { }
79 virtual void Traverse(IfNeInstructionNode* instruction) { }
80 virtual void Traverse(AddIntLit8InstructionNode* instruction) { }
81 virtual void Traverse(MoveResultInstructionNode* instruction) { }
82 virtual void Traverse(InvokeStaticInstructionNode* instruction) { }
83 virtual void Traverse(AddIntInstructionNode* instruction) { }
84 virtual void Traverse(GotoInstructionNode* instruction) { }
85 virtual void Traverse(IfEqzInstructionNode* instruction) { }
86 virtual void Traverse(PhiInstructionNode* phi) { }
87 virtual void Traverse(SignatureNode* sig) { }
88 virtual ~IRVisitor() { }
89
90 protected:
91 std::vector<Region*> ordered_regions_;
92};
Brian Carlstrom7934ac22013-07-26 10:54:15 -070093} // namespace sea_ir
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070094#endif // ART_COMPILER_SEA_IR_VISITOR_H_