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_SEA_NODE_H_ |
| 18 | #define ART_COMPILER_SEA_IR_IR_SEA_NODE_H_ |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 19 | |
Dragos Sbirlea | db06306 | 2013-07-23 16:29:09 -0700 | [diff] [blame] | 20 | #include "base/stringprintf.h" |
Dragos Sbirlea | 81f79a6 | 2013-07-23 14:31:47 -0700 | [diff] [blame] | 21 | |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 22 | namespace sea_ir { |
| 23 | class Region; |
| 24 | class IRVisitor; |
| 25 | |
| 26 | class IVisitable { |
| 27 | public: |
| 28 | virtual void Accept(IRVisitor* visitor) = 0; |
| 29 | virtual ~IVisitable() {} |
| 30 | }; |
| 31 | |
| 32 | // This abstract class provides the essential services that |
Dragos Sbirlea | 6bee445 | 2013-07-26 12:05:03 -0700 | [diff] [blame] | 33 | // we want each SEA IR element to have. |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 34 | // At the moment, these are: |
| 35 | // - an id and corresponding string representation. |
| 36 | // - a .dot graph language representation for .dot output. |
| 37 | // |
| 38 | // Note that SEA IR nodes could also be Regions, Projects |
| 39 | // which are not instructions. |
| 40 | class SeaNode: public IVisitable { |
| 41 | public: |
| 42 | explicit SeaNode():id_(GetNewId()), string_id_() { |
Dragos Sbirlea | db06306 | 2013-07-23 16:29:09 -0700 | [diff] [blame] | 43 | string_id_ = art::StringPrintf("%d", id_); |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 44 | } |
Dragos Sbirlea | 6bee445 | 2013-07-26 12:05:03 -0700 | [diff] [blame] | 45 | |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 46 | // Adds CFG predecessors and successors to each block. |
| 47 | void AddSuccessor(Region* successor); |
| 48 | void AddPredecessor(Region* predecesor); |
| 49 | |
| 50 | // Returns the id of the current block as string |
| 51 | const std::string& StringId() const { |
| 52 | return string_id_; |
| 53 | } |
| 54 | // Returns the id of this node as int. The id is supposed to be unique among |
| 55 | // all instances of all subclasses of this class. |
| 56 | int Id() const { |
| 57 | return id_; |
| 58 | } |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 59 | |
Dragos Sbirlea | a86acf7 | 2013-07-23 14:11:37 -0700 | [diff] [blame] | 60 | virtual ~SeaNode() { } |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 61 | |
| 62 | protected: |
| 63 | static int GetNewId() { |
| 64 | return current_max_node_id_++; |
| 65 | } |
| 66 | |
| 67 | const int id_; |
| 68 | std::string string_id_; |
| 69 | |
| 70 | private: |
Dragos Sbirlea | db06306 | 2013-07-23 16:29:09 -0700 | [diff] [blame] | 71 | static int current_max_node_id_; |
Dragos Sbirlea | a86acf7 | 2013-07-23 14:11:37 -0700 | [diff] [blame] | 72 | // Creating new instances of sea node objects should not be done through copy or assignment |
| 73 | // operators because that would lead to duplication of their unique ids. |
| 74 | DISALLOW_COPY_AND_ASSIGN(SeaNode); |
Dragos Sbirlea | 0e260a3 | 2013-06-21 09:20:34 -0700 | [diff] [blame] | 75 | }; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 76 | } // namespace sea_ir |
Dragos Sbirlea | bfaf44f | 2013-08-06 15:41:44 -0700 | [diff] [blame] | 77 | #endif // ART_COMPILER_SEA_IR_IR_SEA_NODE_H_ |