Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Dragos Sbirlea | bfaf44f | 2013-08-06 15:41:44 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_SEA_IR_IR_VISITOR_H_ |
| 18 | #define ART_COMPILER_SEA_IR_IR_VISITOR_H_ |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 19 | |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 20 | namespace sea_ir { |
| 21 | |
| 22 | class SeaGraph; |
| 23 | class Region; |
| 24 | class InstructionNode; |
| 25 | class PhiInstructionNode; |
| 26 | class SignatureNode; |
Dragos Sbirlea | 6547fa9 | 2013-08-05 18:33:30 -0700 | [diff] [blame] | 27 | class UnnamedConstInstructionNode; |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 28 | class ConstInstructionNode; |
| 29 | class ReturnInstructionNode; |
| 30 | class IfNeInstructionNode; |
| 31 | class AddIntLit8InstructionNode; |
| 32 | class MoveResultInstructionNode; |
| 33 | class InvokeStaticInstructionNode; |
| 34 | class AddIntInstructionNode; |
| 35 | class AddIntLitInstructionNode; |
| 36 | class GotoInstructionNode; |
| 37 | class IfEqzInstructionNode; |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | class IRVisitor { |
| 43 | public: |
Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 44 | explicit IRVisitor(): ordered_regions_() { } |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 45 | virtual void Initialize(SeaGraph* graph) = 0; |
| 46 | virtual void Visit(SeaGraph* graph) = 0; |
| 47 | virtual void Visit(Region* region) = 0; |
| 48 | virtual void Visit(PhiInstructionNode* region) = 0; |
| 49 | virtual void Visit(SignatureNode* region) = 0; |
| 50 | |
| 51 | virtual void Visit(InstructionNode* region) = 0; |
| 52 | virtual void Visit(ConstInstructionNode* instruction) = 0; |
Dragos Sbirlea | 6547fa9 | 2013-08-05 18:33:30 -0700 | [diff] [blame] | 53 | virtual void Visit(UnnamedConstInstructionNode* instruction) = 0; |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 54 | virtual void Visit(ReturnInstructionNode* instruction) = 0; |
| 55 | virtual void Visit(IfNeInstructionNode* instruction) = 0; |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 56 | virtual void Visit(MoveResultInstructionNode* instruction) = 0; |
| 57 | virtual void Visit(InvokeStaticInstructionNode* instruction) = 0; |
| 58 | virtual void Visit(AddIntInstructionNode* instruction) = 0; |
| 59 | virtual void Visit(GotoInstructionNode* instruction) = 0; |
| 60 | virtual void Visit(IfEqzInstructionNode* instruction) = 0; |
| 61 | |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 62 | // Note: This flavor of visitor separates the traversal functions from the actual visiting part |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 63 | // so that the Visitor subclasses don't duplicate code and can't get the traversal wrong. |
| 64 | // The disadvantage is the increased number of functions (and calls). |
| 65 | virtual void Traverse(SeaGraph* graph); |
| 66 | virtual void Traverse(Region* region); |
| 67 | // The following functions are meant to be empty and not pure virtual, |
| 68 | // because the parameter classes have no children to traverse. |
| 69 | virtual void Traverse(InstructionNode* region) { } |
| 70 | virtual void Traverse(ConstInstructionNode* instruction) { } |
| 71 | virtual void Traverse(ReturnInstructionNode* instruction) { } |
| 72 | virtual void Traverse(IfNeInstructionNode* instruction) { } |
| 73 | virtual void Traverse(AddIntLit8InstructionNode* instruction) { } |
| 74 | virtual void Traverse(MoveResultInstructionNode* instruction) { } |
| 75 | virtual void Traverse(InvokeStaticInstructionNode* instruction) { } |
| 76 | virtual void Traverse(AddIntInstructionNode* instruction) { } |
| 77 | virtual void Traverse(GotoInstructionNode* instruction) { } |
| 78 | virtual void Traverse(IfEqzInstructionNode* instruction) { } |
| 79 | virtual void Traverse(PhiInstructionNode* phi) { } |
| 80 | virtual void Traverse(SignatureNode* sig) { } |
| 81 | virtual ~IRVisitor() { } |
| 82 | |
| 83 | protected: |
| 84 | std::vector<Region*> ordered_regions_; |
| 85 | }; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 86 | } // namespace sea_ir |
Dragos Sbirlea | bfaf44f | 2013-08-06 15:41:44 -0700 | [diff] [blame] | 87 | #endif // ART_COMPILER_SEA_IR_IR_VISITOR_H_ |