Jlm
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
jlm::rvsdg::OutputTracer Class Reference

#include <Trace.hpp>

Inheritance diagram for jlm::rvsdg::OutputTracer:
Inheritance graph
[legend]

Public Member Functions

virtual ~OutputTracer ()
 
 OutputTracer (bool enableCaching) noexcept
 
bool isTracingThroughStructuralNodes () const noexcept
 
void setTraceThroughStructuralNodes (bool value) noexcept
 
bool isEnteringPhiNodes () const noexcept
 
void setEnterPhiNodes (bool value) noexcept
 
bool isInterprocedural () const noexcept
 
void setInterprocedural (bool value) noexcept
 
Outputtrace (Output &output)
 
Outputtrace (Output &output, const rvsdg::Region *withinRegion)
 
OutputtryTraceThroughGamma (GammaNode &gammaNode, Output &output)
 
OutputtryTraceThroughTheta (ThetaNode &thetaNode, Output &output)
 
void clearCache ()
 

Protected Member Functions

virtual OutputtraceStep (Output &output, const rvsdg::Region *withinRegion)
 
OutputinsertInCache (const Output &output, Input *traceResult)
 
std::optional< Output * > lookupInCache (const Output &output)
 

Protected Attributes

bool traceThroughStrucutalNodes_ = true
 
bool enterPhiNodes_ = true
 
bool isInterprocedural_ = true
 
bool enableCaching_
 
std::unordered_map< const Output *, Input * > traceCache_ {}
 

Detailed Description

Helper class for tracing through RVSDG graphs to find the origins of outputs. Traces through simple nodes that do not affect the value, through structural nodes when the value is invariant, and out of structural nodes when the value is passed in.

It supports caching of traced values at gamma and theta outputs to avoid the retracing of a value through these structural nodes.

Definition at line 27 of file Trace.hpp.

Constructor & Destructor Documentation

◆ ~OutputTracer()

jlm::rvsdg::OutputTracer::~OutputTracer ( )
virtualdefault

◆ OutputTracer()

jlm::rvsdg::OutputTracer::OutputTracer ( bool  enableCaching)
explicitnoexcept

Creates an OutputTracer with the default configuration

Parameters
enableCachingDetermines whether the output tracer should cache traced results.

Definition at line 17 of file Trace.cpp.

Member Function Documentation

◆ clearCache()

void jlm::rvsdg::OutputTracer::clearCache ( )
inline

Clears the tracing cache.

Definition at line 162 of file Trace.hpp.

◆ insertInCache()

Output * jlm::rvsdg::OutputTracer::insertInCache ( const Output output,
Input traceResult 
)
protected

Inserts a traced value into the tracing cache.

Parameters
outputThe output that was traced.
traceResultThe input at which the tracing arrived.
Returns
The origin of traceResult for convenience.

Definition at line 258 of file Trace.cpp.

◆ isEnteringPhiNodes()

bool jlm::rvsdg::OutputTracer::isEnteringPhiNodes ( ) const
inlinenoexcept

Controls if tracing is allowed to enter the subregion of a phi node from its outputs. If true, tracing can go further and reach lambda or delta nodes inside of phi nodes. It does, however, mean that the result of tracing can end up inside a region that is not an ancestor of the starting region in the region tree.

Returns
true if tracing may enter phi nodes.

Definition at line 72 of file Trace.hpp.

◆ isInterprocedural()

bool jlm::rvsdg::OutputTracer::isInterprocedural ( ) const
inlinenoexcept

Controls if tracing is allowed to leave functions. If true, outputs can be traced out of functions via context arguments. If false, tracing stops if it reaches lambda context arguments.

Returns
true if interprocedural tracing is enabled.

Definition at line 95 of file Trace.hpp.

◆ isTracingThroughStructuralNodes()

bool jlm::rvsdg::OutputTracer::isTracingThroughStructuralNodes ( ) const
inlinenoexcept

When tracing reaches the output of a structural node, how much effort should be made to check if the output is an invariant copy of one of the node's inputs. If true, tracing is performed inside the subregion(s) of the node. If false, only a simple invariant check is performed, which only detects invariance if the region result is directly connected to a region argument.

Returns
true if tracing though the subregions of structural nodes is enabled.

Definition at line 48 of file Trace.hpp.

◆ lookupInCache()

std::optional< Output * > jlm::rvsdg::OutputTracer::lookupInCache ( const Output output)
protected

Loops up the tracing result for output.

Parameters
outputThe output that is traced.
Returns
The output at which tracing arrived, otherwise std::nullopt.

Definition at line 269 of file Trace.cpp.

◆ setEnterPhiNodes()

void jlm::rvsdg::OutputTracer::setEnterPhiNodes ( bool  value)
inlinenoexcept

Enables or disables tracing into phi nodes from the outside.

See also
isEnteringPhiNodes()
Parameters
valuethe new value

Definition at line 83 of file Trace.hpp.

◆ setInterprocedural()

void jlm::rvsdg::OutputTracer::setInterprocedural ( bool  value)
inlinenoexcept

Enables or disables interprocedural tracing.

See also
isInterprocedural()
Parameters
valuethe new value

Definition at line 106 of file Trace.hpp.

◆ setTraceThroughStructuralNodes()

void jlm::rvsdg::OutputTracer::setTraceThroughStructuralNodes ( bool  value)
inlinenoexcept

Enables or disables tracing through the subregions of structural nodes.

See also
isTracingThroughStructuralNodes
Parameters
valuethe new value

Definition at line 59 of file Trace.hpp.

◆ trace() [1/2]

Output & jlm::rvsdg::OutputTracer::trace ( Output output)

Traces from the given output to find the source of the output's value.

Parameters
outputthe output to trace from.

Definition at line 22 of file Trace.cpp.

◆ trace() [2/2]

Output & jlm::rvsdg::OutputTracer::trace ( Output output,
const rvsdg::Region withinRegion 
)

Traces from the given output to find the source of the output's value. The optional parameter withinRegion prevents values from being traced out of the region. If withinRegion is a nullptr, the tracing will continue until the output no longer changes.

Parameters
outputthe output to trace from.
withinRegionthe region where we stop tracing.

Definition at line 28 of file Trace.cpp.

◆ traceStep()

Output & jlm::rvsdg::OutputTracer::traceStep ( Output output,
const rvsdg::Region withinRegion 
)
protectedvirtual

The innermost body of the tracing loop. Should trace at least one step, if possible. If it is not possible to trace further, the same output is returned.

Parameters
outputthe output to trace from.
withinRegionif not nullptr, tracing stops if it reaches an argument of the region.
Returns
the result of tracing from the given output, if possible. Otherwise, output.

Reimplemented in jlm::llvm::OutputTracer.

Definition at line 145 of file Trace.cpp.

◆ tryTraceThroughGamma()

Output * jlm::rvsdg::OutputTracer::tryTraceThroughGamma ( GammaNode gammaNode,
Output output 
)

Attempts to trace the output of a gamma node through the node. This is only possible if the output can be traced to a gamma entry variable in all subregions, and these entry variables all share the same origin outside the gamma.

Precondition
the output is an output of the given gammaNode
Parameters
gammaNodethe gamma node to trace through
outputan output of the given gamma node
Returns
the origin of the output value on the input side of the gamma, or nullptr.

Definition at line 57 of file Trace.cpp.

◆ tryTraceThroughTheta()

Output * jlm::rvsdg::OutputTracer::tryTraceThroughTheta ( ThetaNode thetaNode,
Output output 
)

Attempts to trace the the given loop output through the theta node, resulting in the origin of one of the theta node's inputs if successful. This is only possible if the output belongs to an invariant loop variable, or if the loop variable's post result takes its value from another invariant loop variable.

Precondition
the output is an output of the given thetaNode
Parameters
thetaNodethe theta node to trace through
outputan output of the given theta node
Returns
the origin of the output value on the input side of the theta, or nullptr.

Definition at line 106 of file Trace.cpp.

Member Data Documentation

◆ enableCaching_

bool jlm::rvsdg::OutputTracer::enableCaching_
protected

Definition at line 210 of file Trace.hpp.

◆ enterPhiNodes_

bool jlm::rvsdg::OutputTracer::enterPhiNodes_ = true
protected

Definition at line 203 of file Trace.hpp.

◆ isInterprocedural_

bool jlm::rvsdg::OutputTracer::isInterprocedural_ = true
protected

Definition at line 207 of file Trace.hpp.

◆ traceCache_

std::unordered_map<const Output *, Input *> jlm::rvsdg::OutputTracer::traceCache_ {}
protected

Definition at line 211 of file Trace.hpp.

◆ traceThroughStrucutalNodes_

bool jlm::rvsdg::OutputTracer::traceThroughStrucutalNodes_ = true
protected

Definition at line 199 of file Trace.hpp.


The documentation for this class was generated from the following files: