summaryrefslogtreecommitdiff
path: root/compiler/sea_ir/visitor.h
blob: 985900856fb2b297cb08313eb0f3cf2e7106e0e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ART_COMPILER_SEA_IR_VISITOR_H_
#define ART_COMPILER_SEA_IR_VISITOR_H_

#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Analysis/Verifier.h"
// TODO: Separating the root visitor from the code_gen visitor
// would allow me to not include llvm headers here.


namespace sea_ir {

class SeaGraph;
class Region;
class InstructionNode;
class PhiInstructionNode;
class SignatureNode;
class ConstInstructionNode;
class ReturnInstructionNode;
class IfNeInstructionNode;
class AddIntLit8InstructionNode;
class MoveResultInstructionNode;
class InvokeStaticInstructionNode;
class AddIntInstructionNode;
class AddIntLitInstructionNode;
class GotoInstructionNode;
class IfEqzInstructionNode;




class IRVisitor {
 public:
  explicit IRVisitor():ordered_regions_() { }
  virtual void Initialize(SeaGraph* graph) = 0;
  virtual void Visit(SeaGraph* graph) = 0;
  virtual void Visit(Region* region) = 0;
  virtual void Visit(PhiInstructionNode* region) = 0;
  virtual void Visit(SignatureNode* region) = 0;

  virtual void Visit(InstructionNode* region) = 0;
  virtual void Visit(ConstInstructionNode* instruction) = 0;
  virtual void Visit(ReturnInstructionNode* instruction) = 0;
  virtual void Visit(IfNeInstructionNode* instruction) = 0;
  //virtual void Visit(AddIntLitInstructionNode* instruction) = 0;
  virtual void Visit(MoveResultInstructionNode* instruction) = 0;
  virtual void Visit(InvokeStaticInstructionNode* instruction) = 0;
  virtual void Visit(AddIntInstructionNode* instruction) = 0;
  virtual void Visit(GotoInstructionNode* instruction) = 0;
  virtual void Visit(IfEqzInstructionNode* instruction) = 0;

  // Note: This favor of visitor separates the traversal functions from the actual visiting part
  //       so that the Visitor subclasses don't duplicate code and can't get the traversal wrong.
  //       The disadvantage is the increased number of functions (and calls).
  virtual void Traverse(SeaGraph* graph);
  virtual void Traverse(Region* region);
  // The following functions are meant to be empty and not pure virtual,
  // because the parameter classes have no children to traverse.
  virtual void Traverse(InstructionNode* region) { }
  virtual void Traverse(ConstInstructionNode* instruction) { }
  virtual void Traverse(ReturnInstructionNode* instruction) { }
  virtual void Traverse(IfNeInstructionNode* instruction) { }
  virtual void Traverse(AddIntLit8InstructionNode* instruction) { }
  virtual void Traverse(MoveResultInstructionNode* instruction) { }
  virtual void Traverse(InvokeStaticInstructionNode* instruction) { }
  virtual void Traverse(AddIntInstructionNode* instruction) { }
  virtual void Traverse(GotoInstructionNode* instruction) { }
  virtual void Traverse(IfEqzInstructionNode* instruction) { }
  virtual void Traverse(PhiInstructionNode* phi) { }
  virtual void Traverse(SignatureNode* sig) { }
  virtual ~IRVisitor() { }

 protected:
  std::vector<Region*> ordered_regions_;
};
} // end namespace sea_ir
#endif  // ART_COMPILER_SEA_IR_VISITOR_H_