31 std::shared_ptr<const rvsdg::Type>
type)
38 throw util::Error(
"Argument cannot be added to input.");
65 std::shared_ptr<const rvsdg::Type>
type)
80 std::shared_ptr<const rvsdg::Type>
type)
81 :
Input(*region, *origin, std::move(
type)),
87 throw util::Error(
"Result cannot be added to output.");
115 std::shared_ptr<const rvsdg::Type>
type)
124 for (
size_t n = 0; n <
nresults(); n++)
143 head->
next_ =
nullptr;
148 : id_(graph->generateRegionId()),
159 : id_(node->graph()->generateRegionId()),
161 graph_(node->graph()),
179 throw util::Error(
"Appending argument to wrong region.");
190 throw util::Error(
"Inserting argument to wrong region.");
193 throw util::Error(
"Inserting argument after end of region.");
216 size_t numLiveArguments = 0;
217 size_t numRemovedArguments = 0;
224 numRemovedArguments++;
234 return numRemovedArguments;
240 size_t numLiveArguments = 0;
241 size_t numRemovedArguments = 0;
248 numRemovedArguments++;
258 return numRemovedArguments;
264 const auto resultPtr =
result.release();
266 if (resultPtr->region() !=
this)
267 throw util::Error(
"Appending result to wrong region.");
283 size_t numLiveResults = 0;
284 size_t numRemovedResults = 0;
285 for (
size_t n = 0; n <
nresults(); n++)
302 return numRemovedResults;
335 for (
size_t n = 0; n < snode->nsubregions(); n++)
336 snode->subregion(n)->prune(recursive);
351 std::ofstream outputFile(outputFilePath.
to_str());
412 observer->onNodeCreate(
node);
421 observer->onNodeDestroy(
node);
430 observer->onInputCreate(input);
439 observer->onInputChange(input, old_origin, new_origin);
448 observer->onInputDestroy(input);
455 size_t numRegions = 1;
456 for (
auto & node : region.Nodes())
460 for (
size_t n = 0; n < structuralNode->nsubregions(); n++)
462 numRegions += NumRegions(*structuralNode->subregion(n));
473 std::stringstream stream;
474 ToTree(region, annotationMap, 0, stream);
481 std::stringstream stream;
483 ToTree(region, annotationMap, 0, stream);
491 size_t indentationDepth,
492 std::stringstream & stream) noexcept
494 static const char indentationChar =
'-';
495 static const char annotationSeparator =
' ';
496 static const char labelValueSeparator =
':';
499 auto indentationString = std::string(indentationDepth, indentationChar);
501 region.IsRootRegion() ?
"RootRegion" :
util::strfmt(
"Region[", region.index(),
"]");
502 auto regionAnnotationString =
503 GetAnnotationString(®ion, annotationMap, annotationSeparator, labelValueSeparator);
505 stream << indentationString << regionString << regionAnnotationString <<
'\n';
509 indentationString = std::string(indentationDepth, indentationChar);
510 for (
auto & node : region.Nodes())
514 auto nodeString = structuralNode->DebugString();
515 auto annotationString = GetAnnotationString(
519 labelValueSeparator);
520 stream << indentationString << nodeString << annotationString <<
'\n';
522 for (
size_t n = 0; n < structuralNode->nsubregions(); n++)
524 ToTree(*structuralNode->subregion(n), annotationMap, indentationDepth + 1, stream);
534 char annotationSeparator,
535 char labelValueSeparator)
541 return ToString(annotations, annotationSeparator, labelValueSeparator);
546 const std::vector<util::Annotation> & annotations,
547 char annotationSeparator,
548 char labelValueSeparator)
550 std::stringstream stream;
551 for (
auto & annotation : annotations)
553 auto annotationString =
ToString(annotation, labelValueSeparator);
554 stream << annotationSeparator << annotationString;
566 value = annotation.
Value<std::string>();
608 std::unordered_map<const Node *, size_t>
611 std::unordered_map<const Node *, size_t> depthMap;
615 for (
auto & input : node->Inputs())
617 if (
const auto owner = TryGetOwnerNode<Node>(*input.origin()))
619 depth = std::max(depth, depthMap[owner] + 1);
622 depthMap[node] = depth;
631 size_t n = region->numNodes();
632 for (
const auto & node : region->Nodes())
636 for (
size_t r = 0; r < snode->nsubregions(); r++)
637 n +=
nnodes(snode->subregion(r));
648 for (
const auto & node : region->Nodes())
652 for (
size_t r = 0; r < snode->nsubregions(); r++)
665 for (
const auto & node : region->Nodes())
669 for (
size_t r = 0; r < snode->nsubregions(); r++)
684 size_t n = region->nresults();
685 for (
const auto & node : region->Nodes())
689 for (
size_t r = 0; r < snode->nsubregions(); r++)
690 n +=
ninputs(snode->subregion(r));
util::graph::Graph & WriteGraph(util::graph::Writer &writer, const Region ®ion)
Region & GetRootRegion() const noexcept
bool IsDead() const noexcept
Determines whether the node is dead.
rvsdg::Region * region() const noexcept
size_t ninputs() const noexcept
virtual Node * copy(rvsdg::Region *region, const std::vector< jlm::rvsdg::Output * > &operands) const
rvsdg::Region * region() const noexcept
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
size_t index() const noexcept
bool IsDead() const noexcept
Represents the argument of a region.
RegionArgument(rvsdg::Region *region, StructuralInput *input, std::shared_ptr< const rvsdg::Type > type)
std::string debug_string() const override
virtual RegionArgument & Copy(Region ®ion, StructuralInput *input) const
StructuralInput * input() const noexcept
~RegionArgument() noexcept override
static RegionArgument & Create(rvsdg::Region ®ion, StructuralInput *input, std::shared_ptr< const rvsdg::Type > type)
Creates region entry argument.
Proxy object to observe changes to a region.
virtual ~RegionObserver() noexcept
RegionObserver(const Region ®ion)
Represents the result of a region.
RegionResult(rvsdg::Region *region, rvsdg::Output *origin, StructuralOutput *output, std::shared_ptr< const rvsdg::Type > type)
StructuralOutput * output() const noexcept
~RegionResult() noexcept override
virtual RegionResult & Copy(rvsdg::Output &origin, StructuralOutput *output) const
std::string debug_string() const override
static RegionResult & Create(rvsdg::Region ®ion, rvsdg::Output &origin, StructuralOutput *output, std::shared_ptr< const rvsdg::Type > type)
Create region exit result.
Represent acyclic RVSDG subgraphs.
RegionResult * result(size_t index) const noexcept
size_t RemoveResults(const util::HashSet< size_t > &indices)
RegionArgument & addArgument(std::unique_ptr< RegionArgument > argument)
void notifyNodeDestroy(Node *node)
void copy(Region *target, SubstitutionMap &smap) const
Copy a region with substitutions.
static std::string ToString(const std::vector< util::Annotation > &annotations, char annotationSeparator, char labelValueSeparator)
size_t numNodes() const noexcept
static std::string ToTree(const rvsdg::Region ®ion, const util::AnnotationMap &annotationMap) noexcept
void onNodeRemoved(Node &node)
rvsdg::StructuralNode * node() const noexcept
void onNodeAdded(Node &node)
Adds node to the list of nodes in the region.
Graph * graph() const noexcept
void notifyInputChange(Input *input, Output *old_origin, Output *new_origin)
size_t nresults() const noexcept
RegionObserver * observers_
std::vector< RegionResult * > results_
RegionResult & addResult(std::unique_ptr< RegionResult > result)
void prune(bool recursive)
std::vector< RegionArgument * > arguments_
void onBottomNodeRemoved(Node &node)
size_t index() const noexcept
static std::string GetAnnotationString(const void *key, const util::AnnotationMap &annotationMap, char annotationSeparator, char labelValueSeparator)
RegionArgument * argument(size_t index) const noexcept
void notifyNodeCreate(Node *node)
size_t numTopNodes() const noexcept
bool IsRootRegion() const noexcept
static size_t NumRegions(const rvsdg::Region ®ion) noexcept
void onTopNodeRemoved(Node &node)
size_t numBottomNodes() const noexcept
size_t RemoveArguments(const util::HashSet< size_t > &indices)
void removeNode(Node *node)
Region(rvsdg::Region *parent, Graph *graph)
region_top_node_list topNodes_
void onTopNodeAdded(Node &node)
Adds node to the top nodes of the region.
region_bottom_node_list bottomNodes_
NodeRange Nodes() noexcept
void notifyInputDestroy(Input *input)
void notifyInputCreate(Input *input)
RegionArgument & insertArgument(size_t index, std::unique_ptr< RegionArgument > argument)
size_t narguments() const noexcept
void onBottomNodeAdded(Node &node)
Adds node to the set of bottom nodes in the region.
StructuralNode * node() const noexcept
const std::vector< Annotation > & GetAnnotations(const void *key) const noexcept
bool HasAnnotations(const void *key) const noexcept
bool HasValueType() const noexcept
const TValue & Value() const
const std::string_view & Label() const noexcept
static FilePath createUniqueFileName(const FilePath &directory, const std::string &fileNamePrefix, const std::string &fileNameSuffix)
Generates a unique file in a given directory with a prefix and suffix.
static FilePath TempDirectoryPath()
const std::string & to_str() const noexcept
bool insert(ItemType item)
bool Contains(const ItemType &item) const noexcept
bool IsEmpty() const noexcept
void erase(ElementType *element) noexcept
ElementType * first() const noexcept
void push_back(ElementType *element) noexcept
void outputAllGraphs(std::ostream &out, OutputFormat format)
#define JLM_UNREACHABLE(msg)
size_t nsimpnodes(const rvsdg::Region *region) noexcept
size_t nstructnodes(const rvsdg::Region *region) noexcept
std::unordered_map< const Node *, size_t > computeDepthMap(const Region ®ion)
static std::string type(const Node *n)
detail::TopDownTraverserGeneric< true > TopDownConstTraverser
Traverser for visiting every node in a const region in a top down order.
size_t nnodes(const jlm::rvsdg::Region *region) noexcept
size_t ninputs(const rvsdg::Region *region) noexcept
std::string getDotViewer()
static std::string strfmt(Args... args)
int executeProgramAndWait(const std::string &programName, const std::vector< std::string > &programArguments)