Skip to content

Commit 947c916

Browse files
authored
Introduce IDs for regions (phate#1494)
1 parent cb121a6 commit 947c916

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
193602
1+
193558

jlm/rvsdg/graph.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ GraphExport::Create(Output & origin, std::string name)
7171
Graph::~Graph() noexcept = default;
7272

7373
Graph::Graph()
74-
: RootRegion_(new Region(nullptr, this))
74+
: nextRegionId_(0),
75+
RootRegion_(new Region(nullptr, this))
7576
{}
7677

7778
std::unique_ptr<Graph>

jlm/rvsdg/graph.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ class Graph final
7878

7979
Graph();
8080

81+
/**
82+
* @return A unique identifier for a region within this graph.
83+
*
84+
* @note This method is automatically invoked when a region is created.
85+
* The identifier is only unique within this graph.
86+
*/
87+
[[nodiscard]] Region::Id
88+
generateRegionId() noexcept
89+
{
90+
const auto regionId = nextRegionId_;
91+
nextRegionId_++;
92+
return regionId;
93+
}
94+
8195
/**
8296
* @return The root region of the graph.
8397
*/
@@ -117,6 +131,7 @@ class Graph final
117131
ExtractTailNodes(const Graph & rvsdg);
118132

119133
private:
134+
Region::Id nextRegionId_;
120135
std::unique_ptr<Region> RootRegion_;
121136
};
122137

jlm/rvsdg/region.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ Region::~Region() noexcept
145145
}
146146

147147
Region::Region(Region *, Graph * graph)
148-
: index_(0),
148+
: id_(graph->generateRegionId()),
149+
index_(0),
149150
graph_(graph),
150151
nextNodeId_(0),
151152
node_(nullptr),
@@ -154,8 +155,9 @@ Region::Region(Region *, Graph * graph)
154155
numNodes_(0)
155156
{}
156157

157-
Region::Region(rvsdg::StructuralNode * node, size_t index)
158-
: index_(index),
158+
Region::Region(StructuralNode * node, const size_t index)
159+
: id_(node->graph()->generateRegionId()),
160+
index_(index),
159161
graph_(node->graph()),
160162
nextNodeId_(0),
161163
node_(node),

jlm/rvsdg/region.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ class Region
241241
using BottomNodeConstRange = util::IteratorRange<BottomNodeConstIterator>;
242242

243243
public:
244+
using Id = uint64_t;
245+
244246
~Region() noexcept;
245247

246248
Region(rvsdg::Region * parent, Graph * graph);
@@ -252,6 +254,17 @@ class Region
252254
Region &
253255
operator=(const Region &) = delete;
254256

257+
/**
258+
* @return The unique identifier of the region instance within the graph.
259+
*
260+
* \see Graph::generateRegionId()
261+
*/
262+
[[nodiscard]] Id
263+
getRegionId() const noexcept
264+
{
265+
return id_;
266+
}
267+
255268
/**
256269
* @return Returns an iterator range for iterating through the arguments of the region.
257270
*/
@@ -733,6 +746,7 @@ class Region
733746
[[nodiscard]] static std::string
734747
ToString(const util::Annotation & annotation, char labelValueSeparator);
735748

749+
Id id_;
736750
size_t index_;
737751
Graph * graph_;
738752
Node::Id nextNodeId_;

0 commit comments

Comments
 (0)