docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
sdfg::transformations::LoopShift Class Reference

Loop shift transformation to change loop initialization value. More...

#include <sdfg/transformations/loop_shift.h>

Inheritance diagram for sdfg::transformations::LoopShift:
[legend]

Public Member Functions

 LoopShift (structured_control_flow::StructuredLoop &loop)
 Construct a LoopShift transformation to shift loop to start from 0.
 LoopShift (structured_control_flow::StructuredLoop &loop, const symbolic::Expression &offset)
 Construct a LoopShift transformation with a custom offset.
virtual std::string name () const override
 Get the name of this transformation.
virtual bool can_be_applied (builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
 Check if this transformation can be safely applied.
virtual void apply (builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager) override
 Apply this transformation to the SDFG.
virtual void to_json (nlohmann::json &j) const override
 Serialize this transformation to JSON.
const std::string & shifted_container_name () const
 Get the name of the container holding the shifted (original) value.
Public Member Functions inherited from sdfg::transformations::Transformation
virtual ~Transformation ()=default
virtual void set_report (PassReportConsumer *report)
 Set the report consumer for transformation feedback.
virtual bool try_apply (builder::StructuredSDFGBuilder &builder, analysis::AnalysisManager &analysis_manager)
 Attempt to apply the transformation if possible.

Static Public Member Functions

static LoopShift from_json (builder::StructuredSDFGBuilder &builder, const nlohmann::json &j)

Additional Inherited Members

Protected Attributes inherited from sdfg::transformations::Transformation
PassReportConsumer * report_ = nullptr

Detailed Description

Loop shift transformation to change loop initialization value.

This transformation shifts a loop's iteration space.

Original loop: for (i = init; i < bound; i += stride) body(i)

After LoopShift(target_init=0): for (i = 0; i < bound - init; i += stride) { __i_orig = i + init; } // Assignment in transition body(__i_orig) // Uses original value via propagation

Usage:

  1. Apply LoopShift transformation
  2. Run SymbolPropagation pass to propagate the assignment
  3. Run DeadCodeElimination to remove the temporary container if unused

Prerequisites:

  • Loop must have an integer init value (for condition adjustment)
  • Loop body must not be empty
Note
After applying this transformation, you should run SymbolPropagation to propagate the shifted value into the loop body.

Constructor & Destructor Documentation

◆ LoopShift() [1/2]

sdfg::transformations::LoopShift::LoopShift ( structured_control_flow::StructuredLoop & loop)
explicit

Construct a LoopShift transformation to shift loop to start from 0.

Parameters
loopThe loop to shift

◆ LoopShift() [2/2]

sdfg::transformations::LoopShift::LoopShift ( structured_control_flow::StructuredLoop & loop,
const symbolic::Expression & offset )

Construct a LoopShift transformation with a custom offset.

Parameters
loopThe loop to shift
offsetThe offset to apply to the loop's initial value (e.g., if offset = 1, then new_init = old_init - 1)

Member Function Documentation

◆ apply()

virtual void sdfg::transformations::LoopShift::apply ( builder::StructuredSDFGBuilder & builder,
analysis::AnalysisManager & analysis_manager )
overridevirtual

Apply this transformation to the SDFG.

Parameters
builderThe SDFG builder
analysis_managerThe analysis manager (may be invalidated)

Implements sdfg::transformations::Transformation.

◆ can_be_applied()

virtual bool sdfg::transformations::LoopShift::can_be_applied ( builder::StructuredSDFGBuilder & builder,
analysis::AnalysisManager & analysis_manager )
overridevirtual

Check if this transformation can be safely applied.

Parameters
builderThe SDFG builder
analysis_managerThe analysis manager providing necessary analyses
Returns
true if all preconditions are met

Implements sdfg::transformations::Transformation.

◆ from_json()

LoopShift sdfg::transformations::LoopShift::from_json ( builder::StructuredSDFGBuilder & builder,
const nlohmann::json & j )
static

◆ name()

virtual std::string sdfg::transformations::LoopShift::name ( ) const
overridevirtual

Get the name of this transformation.

Returns
The transformation name (e.g., "LoopInterchange")

Implements sdfg::transformations::Transformation.

◆ shifted_container_name()

const std::string & sdfg::transformations::LoopShift::shifted_container_name ( ) const
inline

Get the name of the container holding the shifted (original) value.

Returns
The container name, or empty string if not yet applied

◆ to_json()

virtual void sdfg::transformations::LoopShift::to_json ( nlohmann::json & j) const
overridevirtual

Serialize this transformation to JSON.

Parameters
jJSON object to populate with transformation description
Exceptions
std::logic_errorif not implemented

Implements sdfg::transformations::Transformation.


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