Jlm
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 namespace jlm::rvsdg
12 {
13 class GammaNode;
14 class ThetaNode;
15 
23 {
24 public:
25  virtual ~OutputTracer();
26 
31 
40  [[nodiscard]] bool
42  {
44  }
45 
51  void
52  setTraceThroughStructuralNodes(bool value) noexcept
53  {
55  }
56 
64  [[nodiscard]] bool
65  isEnteringPhiNodes() const noexcept
66  {
67  return enterPhiNodes_;
68  }
69 
75  void
76  setEnterPhiNodes(bool value) noexcept
77  {
78  enterPhiNodes_ = value;
79  }
80 
87  [[nodiscard]] bool
88  isInterprocedural() const noexcept
89  {
90  return isInterprocedural_;
91  }
92 
98  void
99  setInterprocedural(bool value) noexcept
100  {
101  isInterprocedural_ = value;
102  }
103 
108  [[nodiscard]] Output &
109  trace(Output & output);
110 
122  [[nodiscard]] Output *
123  tryTraceThroughGamma(GammaNode & gammaNode, Output & output);
124 
135  [[nodiscard]] Output *
136  tryTraceThroughTheta(ThetaNode & thetaNode, Output & output);
137 
138 protected:
144  [[nodiscard]] Output &
145  trace(Output & output, bool mayLeaveRegion);
146 
154  [[nodiscard]] virtual Output &
155  traceStep(Output & output, bool mayLeaveRegion);
156 
157  // When true, tracing enters subregions of structural nodes to check if the value is invariant.
158  // When false, values are only considered invariant if they are directly connected to arguments.
160 
161  // When true, tracing can go from the output of a Phi node into its subregion.
162  // When false, tracing will stop at the Phi output.
163  bool enterPhiNodes_ = true;
164 
165  // When true, tracing is allowed to continue outside of lambda nodes.
166  // When false, tracing will stop at the lambda's context arguments.
167  bool isInterprocedural_ = true;
168 };
169 
183 Output &
185 
186 inline const Output &
188 {
189  return traceOutputIntraProcedurally(const_cast<Output &>(output));
190 }
191 
207 Output &
208 traceOutput(Output & output);
209 
210 inline const Output &
211 traceOutput(const Output & output)
212 {
213  return traceOutput(const_cast<Output &>(output));
214 }
215 
216 }
217 
218 #endif // JLM_RVSDG_TRACE_HPP
Conditional operator / pattern matching.
Definition: gamma.hpp:99
bool isTracingThroughStructuralNodes() const noexcept
Definition: Trace.hpp:41
void setEnterPhiNodes(bool value) noexcept
Definition: Trace.hpp:76
Output * tryTraceThroughGamma(GammaNode &gammaNode, Output &output)
Definition: Trace.cpp:64
void setTraceThroughStructuralNodes(bool value) noexcept
Definition: Trace.hpp:52
void setInterprocedural(bool value) noexcept
Definition: Trace.hpp:99
bool isInterprocedural() const noexcept
Definition: Trace.hpp:88
Output & trace(Output &output)
Definition: Trace.cpp:20
bool isEnteringPhiNodes() const noexcept
Definition: Trace.hpp:65
virtual Output & traceStep(Output &output, bool mayLeaveRegion)
Definition: Trace.cpp:124
bool traceThroughStrucutalNodes_
Definition: Trace.hpp:159
Output * tryTraceThroughTheta(ThetaNode &thetaNode, Output &output)
Definition: Trace.cpp:104
Output & traceOutput(Output &output)
Definition: Trace.cpp:231
Output & traceOutputIntraProcedurally(Output &output)
Definition: Trace.cpp:223