Jlm
Loading...
Searching...
No Matches
Trace.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 HÃ¥vard Krogstie <krogstie.havard@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_RVSDG_TRACE_HPP
7#define JLM_RVSDG_TRACE_HPP
8
9#include <jlm/rvsdg/node.hpp>
10
11#include <optional>
12
13namespace jlm::rvsdg
14{
15class GammaNode;
16class ThetaNode;
17
28{
29public:
30 virtual ~OutputTracer();
31
37 explicit OutputTracer(bool enableCaching) noexcept;
38
47 [[nodiscard]] bool
52
58 void
59 setTraceThroughStructuralNodes(bool value) noexcept
60 {
62 }
63
71 [[nodiscard]] bool
76
82 void
83 setEnterPhiNodes(bool value) noexcept
84 {
85 enterPhiNodes_ = value;
86 }
87
94 [[nodiscard]] bool
99
105 void
106 setInterprocedural(bool value) noexcept
107 {
108 isInterprocedural_ = value;
109 }
110
115 [[nodiscard]] Output &
116 trace(Output & output);
117
126 [[nodiscard]] Output &
127 trace(Output & output, const rvsdg::Region * withinRegion);
128
140 [[nodiscard]] Output *
141 tryTraceThroughGamma(GammaNode & gammaNode, Output & output);
142
155 [[nodiscard]] Output *
156 tryTraceThroughTheta(ThetaNode & thetaNode, Output & output);
157
161 void
163 {
164 traceCache_.clear();
165 }
166
167protected:
175 [[nodiscard]] virtual Output &
176 traceStep(Output & output, const rvsdg::Region * withinRegion);
177
185 Output *
186 insertInCache(const Output & output, Input * traceResult);
187
194 std::optional<Output *>
195 lookupInCache(const Output & output);
196
197 // When true, tracing enters subregions of structural nodes to check if the value is invariant.
198 // When false, values are only considered invariant if they are directly connected to arguments.
200
201 // When true, tracing can go from the output of a Phi node into its subregion.
202 // When false, tracing will stop at the Phi output.
203 bool enterPhiNodes_ = true;
204
205 // When true, tracing is allowed to continue outside of lambda nodes.
206 // When false, tracing will stop at the lambda's context arguments.
208
209 // When true, tracing is allowed to cache traced values.
211 std::unordered_map<const Output *, Input *> traceCache_{};
212};
213
227Output &
228traceOutputIntraProcedurally(Output & output);
229
230inline const Output &
232{
233 return traceOutputIntraProcedurally(const_cast<Output &>(output));
234}
235
253Output &
254traceOutput(Output & output, const rvsdg::Region * withinRegion = nullptr);
255
256inline const Output &
257traceOutput(const Output & output, const rvsdg::Region * withinRegion = nullptr)
258{
259 return traceOutput(const_cast<Output &>(output), withinRegion);
260}
261
262}
263
264#endif // JLM_RVSDG_TRACE_HPP
Conditional operator / pattern matching.
Definition gamma.hpp:99
bool isTracingThroughStructuralNodes() const noexcept
Definition Trace.hpp:48
void setEnterPhiNodes(bool value) noexcept
Definition Trace.hpp:83
Output * tryTraceThroughGamma(GammaNode &gammaNode, Output &output)
Definition Trace.cpp:57
void setTraceThroughStructuralNodes(bool value) noexcept
Definition Trace.hpp:59
void setInterprocedural(bool value) noexcept
Definition Trace.hpp:106
bool isInterprocedural() const noexcept
Definition Trace.hpp:95
Output * insertInCache(const Output &output, Input *traceResult)
Definition Trace.cpp:258
Output & trace(Output &output)
Definition Trace.cpp:22
virtual Output & traceStep(Output &output, const rvsdg::Region *withinRegion)
Definition Trace.cpp:145
bool isEnteringPhiNodes() const noexcept
Definition Trace.hpp:72
std::unordered_map< const Output *, Input * > traceCache_
Definition Trace.hpp:211
Output * tryTraceThroughTheta(ThetaNode &thetaNode, Output &output)
Definition Trace.cpp:106
std::optional< Output * > lookupInCache(const Output &output)
Definition Trace.cpp:269
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
Output & traceOutput(Output &output, const rvsdg::Region *withinRegion)
Definition Trace.cpp:292
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
Output & traceOutputIntraProcedurally(Output &output)
Definition Trace.cpp:283