Jlm
Loading...
Searching...
No Matches
RegionPredicateTrace.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2026 Helge Bahmann <hcb@chaoticmind.net>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_RVSDG_REGIONPREDICATETRACE_HPP
7#define JLM_RVSDG_REGIONPREDICATETRACE_HPP
8
10#include <jlm/rvsdg/graph.hpp>
11#include <jlm/rvsdg/node.hpp>
12
13#include <unordered_map>
14
15namespace jlm::rvsdg
16{
17
24{
25public:
29 static inline PredicateValueRange
31 {
32 return PredicateValueRange(type.nalternatives(), false);
33 }
34
38 static inline PredicateValueRange
40 {
41 return PredicateValueRange(type.nalternatives(), true);
42 }
43
47 static inline PredicateValueRange
49 {
50 auto pred = PredicateValueRange(value.nalternatives(), false);
51 pred.values_[value.alternative()] = true;
52 return pred;
53 }
54
58 void
60 {
61 auto size = std::min(values_.size(), other.values_.size());
62 for (std::size_t n = 0; n < size; ++n)
63 {
64 values_[n] = values_[n] || other.values_[n];
65 }
66 }
67
71 bool
72 AllowsValue(std::size_t alternative) const noexcept
73 {
74 return values_.size() > alternative && values_[alternative];
75 }
76
77private:
78 inline PredicateValueRange(std::size_t nalternatives, bool init_value)
79 : values_(nalternatives, init_value)
80 {}
81
82 std::vector<bool> values_;
83};
84
94using PredicateSatRequired = std::vector<std::pair<Input *, std::size_t>>;
95
105{
106public:
108
110
138
157
188 bool
190
191private:
192 // For a given input, its RegionPredRange provides a map from regions to the
193 // set of values than can end up being routed to the input, from results of the region.
194 using RegionPredRange = std::unordered_map<Region *, PredicateValueRange>;
195 class Observer;
196
197 void
198 Clear();
199
200 void
201 ObserveRegion(Region & region);
202
210 const PredicateValueRange &
213 Input & input,
214 std::unordered_map<Input *, PredicateValueRange> & visitedInputs,
215 const ControlType & type);
216
221 Compute(
223 Input & input,
224 std::unordered_map<Input *, PredicateValueRange> & visitedInputs,
225 const ControlType & type);
226
227 // For a given input, gives the regions where we know which the set of values
228 // the region may provide to the input
229 std::unordered_map<Input *, RegionPredRange> predAssignment_;
230
231 // For a given target region, what predicates must be satisfied to reach it
232 std::unordered_map<Region *, PredicateSatRequired> predSat_;
233
234 // Observers registered on region to inform the tracer when caches must be invalidated
235 std::unordered_map<Region *, std::unique_ptr<Observer>> observers_;
236};
237
238}
239
240#endif // JLM_RVSDG_REGIONTRACE_HPP
size_t nalternatives() const noexcept
Definition control.hpp:42
size_t nalternatives() const noexcept
Definition control.hpp:89
size_t alternative() const noexcept
Definition control.hpp:83
Value range for a predicate.
bool AllowsValue(std::size_t alternative) const noexcept
Checks whether value range allows a specific value.
static PredicateValueRange CreateEmpty(const ControlType &type)
Constructs empty value range (unsatisfiable predicate range).
void UpdateUnion(const PredicateValueRange &other)
Takes union of two value ranges.
PredicateValueRange(std::size_t nalternatives, bool init_value)
static PredicateValueRange CreateSingleValue(const ControlValueRepresentation &value)
Definite value range (exactly one value possible).
static PredicateValueRange CreateUnknown(const ControlType &type)
Constructs full value range (every value possible).
Traces region reachability by predicate assertions.
PredicateValueRange GetRegionPredicateAssignConstraints(Region &region, Input &predUse)
Computes value range for a predicate when exiting a region.
PredicateSatRequired GetRegionSatRequired(Region &region)
Computes required predicate assignments for region.
std::unordered_map< Region *, PredicateSatRequired > predSat_
bool CheckPredicatesSatisfiable(Region &originRegion, Region &targetRegion)
Checks for dynamic reachability between two regions.
PredicateValueRange Compute(RegionPredRange &regionPredRange, Input &input, std::unordered_map< Input *, PredicateValueRange > &visitedInputs, const ControlType &type)
const PredicateValueRange & ComputeAndRecord(RegionPredRange &regionPredRange, Input &input, std::unordered_map< Input *, PredicateValueRange > &visitedInputs, const ControlType &type)
std::unordered_map< Region *, PredicateValueRange > RegionPredRange
std::unordered_map< Input *, RegionPredRange > predAssignment_
std::unordered_map< Region *, std::unique_ptr< Observer > > observers_
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
std::vector< std::pair< Input *, std::size_t > > PredicateSatRequired
Describes which predicates need to be satisfied.