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

Represents a conditional if-else control flow node with multiple cases. More...

#include <sdfg/structured_control_flow/if_else.h>

Inheritance diagram for sdfg::structured_control_flow::IfElse:
[legend]

Public Member Functions

 IfElse (const IfElse &node)=delete
IfElse & operator= (const IfElse &)=delete
ElementType type_id () const override
 Returns the type of the element.
bool accept (visitor::ActualStructuredSDFGVisitor &visitor) override
void validate (const Function &function) const override
 Validates the element.
size_t size () const
 Returns the number of cases (if/else-if branches) in this IfElse.
std::pair< const Sequence &, const symbolic::Condition > at (size_t i) const
 Access a case by index (const version).
std::pair< Sequence &, const symbolic::Condition > at (size_t i)
 Access a case by index (non-const version).
int index (const Sequence &child) const
 Find the index of a child sequence (the root seq of one of our branches).
bool is_complete () const
 Checks if this IfElse is complete (all cases are covered).
void replace (const symbolic::Expression old_expression, const symbolic::Expression new_expression) override
 Replace occurrences of an expression in all conditions and sequences.
void replace (const symbolic::ExpressionMapping &replacements) override
Public Member Functions inherited from sdfg::structured_control_flow::ControlFlowNode
virtual ~ControlFlowNode ()=default
ControlFlowNode * get_parent ()
const ControlFlowNode * get_parent () const
 ControlFlowNode (const ControlFlowNode &node)=delete
ControlFlowNode & operator= (const ControlFlowNode &)=delete
Public Member Functions inherited from sdfg::Element
 Element (size_t element_id, const DebugInfo &debug_info)
virtual ~Element ()=default
size_t element_id () const
const DebugInfo & debug_info () const
void set_debug_info (const DebugInfo &debug_info)
void add_metadata (const std::string &key, const std::string &value)
void remove_metadata (const std::string &key)
const std::string & metadata (const std::string &key) const
const std::string * metadata_if_exists (const std::string &key) const
const std::unordered_map< std::string, std::string > & metadata () const
std::string_view element_type () const
 Returns the type of the element as a human-readable string.

Static Public Member Functions

static bool classof (const Element &element)
Static Public Member Functions inherited from sdfg::structured_control_flow::ControlFlowNode
static bool classof (const Element &element)
 LLVM-style RTTI predicate: true if element is a ControlFlowNode.
static std::vector< ControlFlowNode * > parent_chain (ControlFlowNode &child)

Friends

class sdfg::builder::StructuredSDFGBuilder

Additional Inherited Members

Static Public Attributes inherited from sdfg::structured_control_flow::ControlFlowNode
static constexpr ElementType TypeGroup
 Bitmask of all concrete ElementTypes that are ControlFlowNodes.
Protected Member Functions inherited from sdfg::structured_control_flow::ControlFlowNode
 ControlFlowNode (size_t element_id, const DebugInfo &debug_info, ControlFlowNode *parent)
 Protected constructor for control flow nodes with parent.
Protected Attributes inherited from sdfg::structured_control_flow::ControlFlowNode
ControlFlowNode * parent_
Protected Attributes inherited from sdfg::Element
size_t element_id_
DebugInfo debug_info_
std::unordered_map< std::string, std::string > metadata_

Detailed Description

Represents a conditional if-else control flow node with multiple cases.

The IfElse node represents structured conditional branching in a StructuredSDFG. It consists of one or more cases, each with:

  • A condition (boolean expression) that determines when the case executes
  • A sequence (control flow body) that executes when the condition is true

Cases are evaluated in order. At runtime, the first case whose condition evaluates to true will be executed. This is similar to if-else-if chains in programming languages.

Completeness:

An IfElse is considered "complete" if its conditions exhaustively cover all possible cases. This means that at least one condition will always be true at runtime. The is_complete() method uses conjunctive normal form (CNF) analysis to determine if the disjunction (OR) of all conditions is a tautology (always true).

Complete examples:

  • if (x > 0) ... else if (x <= 0) ... - covers all values of x
  • if (condition) ... else if (!condition) ... - complementary conditions
  • if (true) ... - always executes

Incomplete examples:

  • if (x > 0) ... - doesn't handle x <= 0
  • if (x > 10) ... else if (x < 5) ... - gap between 5 and 10
See also
is_complete()
Sequence

Constructor & Destructor Documentation

◆ IfElse()

sdfg::structured_control_flow::IfElse::IfElse ( const IfElse & node)
delete

Member Function Documentation

◆ accept()

bool sdfg::structured_control_flow::IfElse::accept ( visitor::ActualStructuredSDFGVisitor & visitor)
overridevirtual

◆ at() [1/2]

std::pair< Sequence &, const symbolic::Condition > sdfg::structured_control_flow::IfElse::at ( size_t i)

Access a case by index (non-const version).

Parameters
iIndex of the case to access (0-based)
Returns
Pair of (sequence, condition) for the case at index i
Exceptions
std::out_of_rangeif i >= size()

◆ at() [2/2]

std::pair< const Sequence &, const symbolic::Condition > sdfg::structured_control_flow::IfElse::at ( size_t i) const

Access a case by index (const version).

Parameters
iIndex of the case to access (0-based)
Returns
Pair of (sequence, condition) for the case at index i
Exceptions
std::out_of_rangeif i >= size()

◆ classof()

bool sdfg::structured_control_flow::IfElse::classof ( const Element & element)
inlinestatic

◆ index()

int sdfg::structured_control_flow::IfElse::index ( const Sequence & child) const

Find the index of a child sequence (the root seq of one of our branches).

Parameters
childChild node to search for
Returns
Index of the child, or -1 if not found

◆ is_complete()

bool sdfg::structured_control_flow::IfElse::is_complete ( ) const

Checks if this IfElse is complete (all cases are covered).

An IfElse is complete if the disjunction (OR) of all its conditions is a tautology, meaning at least one condition will always be true regardless of variable values.

This method uses conjunctive normal form (CNF) conversion to analyze whether the combined conditions form a tautology. Each clause in the CNF must be a tautology for the entire expression to be one.

Examples of complete IfElse nodes:

  • if (x > 0) { ... } else if (x <= 0) { ... } - True, covers all x
  • if (x > 0 || y > 0) { ... } else if (x <= 0 && y <= 0) { ... } - True
  • if (true) { ... } - True, always executes

Examples of incomplete IfElse nodes:

  • if (x > 0) { ... } - False, missing x <= 0 case
  • if (x > 10) { ... } else if (x < 5) { ... } - False, gap for 5 <= x <= 10
  • if (x > 0 && y > 0) { ... } else if (x < 0 && y < 0) { ... } - False, missing mixed signs
Returns
true if all possible cases are covered, false otherwise

◆ operator=()

IfElse & sdfg::structured_control_flow::IfElse::operator= ( const IfElse & )
delete

◆ replace() [1/2]

void sdfg::structured_control_flow::IfElse::replace ( const symbolic::Expression old_expression,
const symbolic::Expression new_expression )
overridevirtual

Replace occurrences of an expression in all conditions and sequences.

Parameters
old_expressionExpression to replace
new_expressionExpression to replace with

Implements sdfg::Element.

◆ replace() [2/2]

void sdfg::structured_control_flow::IfElse::replace ( const symbolic::ExpressionMapping & replacements)
overridevirtual

Reimplemented from sdfg::Element.

◆ size()

size_t sdfg::structured_control_flow::IfElse::size ( ) const

Returns the number of cases (if/else-if branches) in this IfElse.

Returns
Number of cases

◆ type_id()

ElementType sdfg::structured_control_flow::IfElse::type_id ( ) const
inlineoverridevirtual

Returns the type of the element.

Implements sdfg::Element.

◆ validate()

void sdfg::structured_control_flow::IfElse::validate ( const Function & function) const
overridevirtual

Validates the element.

Exceptions
InvalidSDFGExceptionif the element is invalid

Implements sdfg::Element.

◆ sdfg::builder::StructuredSDFGBuilder


The documentation for this class was generated from the following file:
  • sdfg/include/sdfg/structured_control_flow/if_else.h