blob: 4dab5cba83efb464694372bb76cf4cc8a2201291 [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
Dragos Sbirleabfaf44f2013-08-06 15:41:44 -070017#ifndef ART_COMPILER_SEA_IR_IR_SEA_NODE_H_
18#define ART_COMPILER_SEA_IR_IR_SEA_NODE_H_
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070019
Dragos Sbirleadb063062013-07-23 16:29:09 -070020#include "base/stringprintf.h"
Dragos Sbirlea81f79a62013-07-23 14:31:47 -070021
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070022namespace sea_ir {
23class Region;
24class IRVisitor;
25
26class 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 Sbirlea6bee4452013-07-26 12:05:03 -070033// we want each SEA IR element to have.
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070034// 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.
40class SeaNode: public IVisitable {
41 public:
42 explicit SeaNode():id_(GetNewId()), string_id_() {
Dragos Sbirleadb063062013-07-23 16:29:09 -070043 string_id_ = art::StringPrintf("%d", id_);
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070044 }
Dragos Sbirlea6bee4452013-07-26 12:05:03 -070045
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070046 // 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 Sbirlea0e260a32013-06-21 09:20:34 -070059
Dragos Sbirleaa86acf72013-07-23 14:11:37 -070060 virtual ~SeaNode() { }
Dragos Sbirlea0e260a32013-06-21 09:20:34 -070061
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 Sbirleadb063062013-07-23 16:29:09 -070071 static int current_max_node_id_;
Dragos Sbirleaa86acf72013-07-23 14:11:37 -070072 // 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 Sbirlea0e260a32013-06-21 09:20:34 -070075};
Brian Carlstrom7934ac22013-07-26 10:54:15 -070076} // namespace sea_ir
Dragos Sbirleabfaf44f2013-08-06 15:41:44 -070077#endif // ART_COMPILER_SEA_IR_IR_SEA_NODE_H_