Tiramisu Compiler
tiramisu::expr Class Reference

A class to represent tiramisu expressions. More...

#include <expr.h>

Inherited by tiramisu::sync, and tiramisu::var.

Public Member Functions

 expr ()
 Create an undefined expression. More...
 
 expr (tiramisu::op_t o, tiramisu::primitive_t dtype, tiramisu::expr expr0)
 Create a cast expression to type t (a unary operator). More...
 
 expr (tiramisu::op_t o, tiramisu::expr expr0)
 Create an expression for a unary operator. More...
 
 expr (tiramisu::op_t o, std::string name)
 Create an expression for a unary operator that applies on a variable. More...
 
 expr (tiramisu::op_t o, tiramisu::expr expr0, tiramisu::expr expr1)
 Construct an expression for a binary operator. More...
 
 expr (tiramisu::op_t o, tiramisu::expr expr0, tiramisu::expr expr1, tiramisu::expr expr2)
 Construct an expression for a ternary operator. More...
 
 expr (tiramisu::op_t o, std::string name, std::vector< tiramisu::expr > vec, tiramisu::primitive_t type)
 Construct an access or a call. More...
 
 expr (uint8_t val)
 Construct an unsigned 8-bit integer expression. More...
 
 expr (int8_t val)
 Construct a signed 8-bit integer expression. More...
 
 expr (uint16_t val)
 Construct an unsigned 16-bit integer expression. More...
 
 expr (int16_t val)
 Construct a signed 16-bit integer expression. More...
 
 expr (uint32_t val)
 Construct an unsigned 32-bit integer expression. More...
 
 expr (int32_t val)
 Construct a signed 32-bit integer expression. More...
 
 expr (uint64_t val)
 Construct an unsigned 64-bit integer expression. More...
 
 expr (int64_t val)
 Construct a signed 64-bit integer expression. More...
 
 expr (float val)
 Construct a 32-bit float expression. More...
 
tiramisu::expr copy () const
 Copy an expression. More...
 
 expr (double val)
 Construct a 64-bit float expression. More...
 
int64_t get_int_val () const
 
double get_double_val () const
 
const tiramisu::exprget_operand (int i) const
 Return the value of the i 'th operand of the expression. More...
 
int get_n_arg () const
 Return the number of arguments of the operator. More...
 
tiramisu::expr_t get_expr_type () const
 Return the type of the expression (tiramisu::expr_type). More...
 
tiramisu::primitive_t get_data_type () const
 Get the data type of the expression. More...
 
const std::string & get_name () const
 Get the name of the ID or the variable represented by this expressions. More...
 
void set_name (std::string &name)
 
tiramisu::expr replace_op_in_expr (const std::string &to_replace, const std::string &replace_with)
 
tiramisu::op_t get_op_type () const
 Get the type of the operator (tiramisu::op_t). More...
 
const std::vector< tiramisu::expr > & get_access () const
 Return a vector of the access of the computation or array. More...
 
const std::vector< tiramisu::expr > & get_arguments () const
 Return the arguments of an external function call. More...
 
int get_n_dim_access () const
 Get the number of dimensions in the access vector. More...
 
bool is_defined () const
 Return true if the expression is defined. More...
 
bool is_equal (tiramisu::expr e) const
 Return true if e is identical to this expression. More...
 
expr operator+ (tiramisu::expr other) const
 Addition. More...
 
expr operator- (tiramisu::expr other) const
 Subtraction. More...
 
expr operator/ (tiramisu::expr other) const
 Division. More...
 
expr operator* (tiramisu::expr other) const
 Multiplication. More...
 
expr operator% (tiramisu::expr other) const
 Modulo. More...
 
expr operator>> (tiramisu::expr other) const
 Right shift operator. More...
 
expr operator<< (tiramisu::expr other) const
 Left shift operator. More...
 
tiramisu::expr operator&& (tiramisu::expr e1) const
 Logical and of two expressions. More...
 
tiramisu::expr operator|| (tiramisu::expr e1) const
 Logical and of two expressions. More...
 
tiramisu::expr operator- () const
 Expression multiplied by (-1). More...
 
tiramisu::expr operator! () const
 Logical NOT of an expression. More...
 
tiramisu::exproperator= (tiramisu::expr const &)
 
tiramisu::expr operator< (tiramisu::expr e1) const
 Less than operator. More...
 
tiramisu::expr operator<= (tiramisu::expr e1) const
 Less than or equal operator. More...
 
tiramisu::expr operator> (tiramisu::expr e1) const
 Greater than operator. More...
 
tiramisu::expr operator>= (tiramisu::expr e1) const
 Greater than or equal operator. More...
 
void set_access (std::vector< tiramisu::expr > vector)
 Set the access of a computation or an array. More...
 
void set_access_dimension (int i, tiramisu::expr acc)
 Set an element of the vector of accesses of a computation. More...
 
void set_arguments (std::vector< tiramisu::expr > vector)
 Set the arguments of an external function call. More...
 
void dump (bool exhaustive) const
 Dump the object on standard output (dump most of the fields of the expression class). More...
 
bool is_constant () const
 Return true if this expression is a literal constant (i.e., 0, 1, 2, ...). More...
 
bool is_unbounded () const
 
tiramisu::expr simplify () const
 Simplify the expression. More...
 
std::string to_str () const
 
expr substitute (std::vector< std::pair< var, expr >> substitutions) const
 Returns a new expression where for every (var, sub) pair in substitutions, var in the original expression is replaced by sub. More...
 
expr substitute_access (std::string original, std::string substitute) const
 Returns an expression where every access to a computation named original is replaced with an access to a computation named substitute, with the same access indices. More...
 
expr apply_to_operands (std::function< expr(const expr &)> f) const
 
uint8_t get_uint8_value () const
 Return the actual value of the expression. More...
 
int8_t get_int8_value () const
 Return the actual value of the expression. More...
 
uint16_t get_uint16_value () const
 Return the actual value of the expression. More...
 
int16_t get_int16_value () const
 Return the actual value of the expression. More...
 
uint32_t get_uint32_value () const
 Return the actual value of the expression. More...
 
int32_t get_int32_value () const
 Return the actual value of the expression. More...
 
uint64_t get_uint64_value () const
 Return the actual value of the expression. More...
 
int64_t get_int64_value () const
 Return the actual value of the expression. More...
 
float get_float32_value () const
 Return the actual value of the expression. More...
 
double get_float64_value () const
 Return the actual value of the expression. More...
 
tiramisu::expr operator== (tiramisu::expr e1) const
 Comparison operator. More...
 
tiramisu::expr operator!= (tiramisu::expr e1) const
 Comparison operator. More...
 

Static Public Member Functions

static expr unbounded ()
 Create a variable that can be used that a dimension is unbounded. More...
 

Protected Attributes

std::string name
 Identifier name. More...
 
tiramisu::primitive_t dtype
 Data type. More...
 
tiramisu::expr_t etype
 The type of the expression. More...
 

Detailed Description

A class to represent tiramisu expressions.

Definition at line 150 of file expr.h.

Constructor & Destructor Documentation

tiramisu::expr::expr ( )
inline

Create an undefined expression.

Definition at line 231 of file expr.h.

References tiramisu::e_none, tiramisu::o_none, and tiramisu::p_none.

tiramisu::expr::expr ( tiramisu::op_t  o,
tiramisu::primitive_t  dtype,
tiramisu::expr  expr0 
)
inline

Create a cast expression to type t (a unary operator).

Definition at line 243 of file expr.h.

References tiramisu::e_op, and tiramisu::o_cast.

tiramisu::expr::expr ( tiramisu::op_t  o,
tiramisu::expr  expr0 
)
inline

Create an expression for a unary operator.

Definition at line 258 of file expr.h.

References tiramisu::e_op, get_data_type(), tiramisu::o_cast, tiramisu::o_floor, tiramisu::p_float32, and tiramisu::p_float64.

tiramisu::expr::expr ( tiramisu::op_t  o,
std::string  name 
)
inline

Create an expression for a unary operator that applies on a variable.

For example: allocate(A) or free(B).

Definition at line 277 of file expr.h.

References tiramisu::e_op, and tiramisu::p_none.

tiramisu::expr::expr ( tiramisu::op_t  o,
tiramisu::expr  expr0,
tiramisu::expr  expr1 
)
inline

Construct an expression for a binary operator.

Definition at line 290 of file expr.h.

References dump(), tiramisu::e_op, and get_data_type().

tiramisu::expr::expr ( tiramisu::op_t  o,
tiramisu::expr  expr0,
tiramisu::expr  expr1,
tiramisu::expr  expr2 
)
inline

Construct an expression for a ternary operator.

Definition at line 314 of file expr.h.

References tiramisu::e_op, and get_data_type().

tiramisu::expr::expr ( tiramisu::op_t  o,
std::string  name,
std::vector< tiramisu::expr vec,
tiramisu::primitive_t  type 
)
inline

Construct an access or a call.

Definition at line 332 of file expr.h.

References tiramisu::e_op, tiramisu::o_access, tiramisu::o_address_of, tiramisu::o_buffer, tiramisu::o_call, and tiramisu::o_lin_index.

tiramisu::expr::expr ( uint8_t  val)
inline

Construct an unsigned 8-bit integer expression.

Definition at line 368 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_uint8.

tiramisu::expr::expr ( int8_t  val)
inline

Construct a signed 8-bit integer expression.

Definition at line 381 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_int8.

tiramisu::expr::expr ( uint16_t  val)
inline

Construct an unsigned 16-bit integer expression.

Definition at line 394 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_uint16.

tiramisu::expr::expr ( int16_t  val)
inline

Construct a signed 16-bit integer expression.

Definition at line 407 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_int16.

tiramisu::expr::expr ( uint32_t  val)
inline

Construct an unsigned 32-bit integer expression.

Definition at line 420 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_uint32.

tiramisu::expr::expr ( int32_t  val)
inline

Construct a signed 32-bit integer expression.

Definition at line 433 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_int32.

tiramisu::expr::expr ( uint64_t  val)
inline

Construct an unsigned 64-bit integer expression.

Definition at line 446 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_uint64.

tiramisu::expr::expr ( int64_t  val)
inline

Construct a signed 64-bit integer expression.

Definition at line 459 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_int64.

tiramisu::expr::expr ( float  val)
inline

Construct a 32-bit float expression.

Definition at line 472 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_float32.

tiramisu::expr::expr ( double  val)
inline

Construct a 64-bit float expression.

Definition at line 490 of file expr.h.

References tiramisu::e_val, tiramisu::o_none, and tiramisu::p_float64.

Member Function Documentation

expr tiramisu::expr::apply_to_operands ( std::function< expr(const expr &)>  f) const
inline

Definition at line 1652 of file expr.h.

tiramisu::expr tiramisu::expr::copy ( ) const

Copy an expression.

void tiramisu::expr::dump ( bool  exhaustive) const
inline

Dump the object on standard output (dump most of the fields of the expression class).

This is mainly useful for debugging. If exhaustive is set to true, all the fields of the class are printed. This is useful to find potential initialization problems.

Definition at line 1021 of file expr.h.

References tiramisu::e_none, tiramisu::e_op, tiramisu::e_sync, tiramisu::e_val, tiramisu::e_var, tiramisu::o_access, tiramisu::o_address, tiramisu::o_address_of, tiramisu::o_allocate, tiramisu::o_call, tiramisu::o_free, tiramisu::o_lin_index, tiramisu::p_float32, tiramisu::p_float64, tiramisu::p_int16, tiramisu::p_int32, tiramisu::p_int64, tiramisu::p_int8, tiramisu::p_uint16, tiramisu::p_uint32, tiramisu::p_uint64, tiramisu::p_uint8, tiramisu::str_from_tiramisu_type_expr(), tiramisu::str_from_tiramisu_type_primitive(), and tiramisu::str_tiramisu_type_op().

Referenced by expr(), and tiramisu::computation::operator()().

const std::vector<tiramisu::expr>& tiramisu::expr::get_access ( ) const
inline

Return a vector of the access of the computation or array.

For example, for the computation C0(i,j), this function will return the vector {i, j} where i and j are both tiramisu expressions. For a buffer access A[i+1,j], it will return also {i+1, j}.

Definition at line 762 of file expr.h.

References tiramisu::e_op, tiramisu::o_access, tiramisu::o_address_of, tiramisu::o_buffer, tiramisu::o_dummy, and tiramisu::o_lin_index.

const std::vector<tiramisu::expr>& tiramisu::expr::get_arguments ( ) const
inline

Return the arguments of an external function call.

Definition at line 775 of file expr.h.

References tiramisu::e_op, and tiramisu::o_call.

tiramisu::primitive_t tiramisu::expr::get_data_type ( ) const
inline

Get the data type of the expression.

Definition at line 694 of file expr.h.

Referenced by expr(), tiramisu::operator*(), tiramisu::operator+(), and tiramisu::operator-().

double tiramisu::expr::get_double_val ( ) const
inline

Definition at line 639 of file expr.h.

References tiramisu::e_val, tiramisu::p_float32, tiramisu::p_float64, and result.

Referenced by is_equal().

tiramisu::expr_t tiramisu::expr::get_expr_type ( ) const
inline

Return the type of the expression (tiramisu::expr_type).

Definition at line 686 of file expr.h.

float tiramisu::expr::get_float32_value ( ) const
inline

Return the actual value of the expression.

Definition at line 568 of file expr.h.

References tiramisu::e_val, and tiramisu::p_float32.

double tiramisu::expr::get_float64_value ( ) const
inline

Return the actual value of the expression.

Definition at line 576 of file expr.h.

References tiramisu::e_val, and tiramisu::p_float64.

int16_t tiramisu::expr::get_int16_value ( ) const
inline

Return the actual value of the expression.

Definition at line 528 of file expr.h.

References tiramisu::e_val, and tiramisu::p_int16.

int32_t tiramisu::expr::get_int32_value ( ) const
inline

Return the actual value of the expression.

Definition at line 544 of file expr.h.

References tiramisu::e_val, and tiramisu::p_int32.

int64_t tiramisu::expr::get_int64_value ( ) const
inline

Return the actual value of the expression.

Definition at line 560 of file expr.h.

References tiramisu::e_val, and tiramisu::p_int64.

int8_t tiramisu::expr::get_int8_value ( ) const
inline

Return the actual value of the expression.

Definition at line 512 of file expr.h.

References tiramisu::e_val, and tiramisu::p_int8.

int tiramisu::expr::get_n_arg ( ) const
inline

Return the number of arguments of the operator.

Definition at line 676 of file expr.h.

References tiramisu::e_op.

int tiramisu::expr::get_n_dim_access ( ) const
inline

Get the number of dimensions in the access vector.

Definition at line 786 of file expr.h.

References tiramisu::e_op, and tiramisu::o_access.

const std::string& tiramisu::expr::get_name ( ) const
inline

Get the name of the ID or the variable represented by this expressions.

Definition at line 702 of file expr.h.

References tiramisu::e_var, tiramisu::o_access, tiramisu::o_address, tiramisu::o_address_of, tiramisu::o_allocate, tiramisu::o_buffer, tiramisu::o_call, tiramisu::o_dummy, tiramisu::o_free, and tiramisu::o_lin_index.

Referenced by tiramisu::computation::fuse_after().

tiramisu::op_t tiramisu::expr::get_op_type ( ) const
inline

Get the type of the operator (tiramisu::op_t).

Definition at line 749 of file expr.h.

const tiramisu::expr& tiramisu::expr::get_operand ( int  i) const
inline

Return the value of the i 'th operand of the expression.

i can be 0, 1 or 2.

Definition at line 665 of file expr.h.

References tiramisu::e_op.

uint16_t tiramisu::expr::get_uint16_value ( ) const
inline

Return the actual value of the expression.

Definition at line 520 of file expr.h.

References tiramisu::e_val, and tiramisu::p_uint16.

uint32_t tiramisu::expr::get_uint32_value ( ) const
inline

Return the actual value of the expression.

Definition at line 536 of file expr.h.

References tiramisu::e_val, and tiramisu::p_uint32.

uint64_t tiramisu::expr::get_uint64_value ( ) const
inline

Return the actual value of the expression.

Definition at line 552 of file expr.h.

References tiramisu::e_val, and tiramisu::p_uint64.

uint8_t tiramisu::expr::get_uint8_value ( ) const
inline

Return the actual value of the expression.

Definition at line 504 of file expr.h.

References tiramisu::e_val, and tiramisu::p_uint8.

bool tiramisu::expr::is_constant ( ) const
inline

Return true if this expression is a literal constant (i.e., 0, 1, 2, ...).

Definition at line 1160 of file expr.h.

References tiramisu::e_val.

bool tiramisu::expr::is_defined ( ) const
inline

Return true if the expression is defined.

Definition at line 797 of file expr.h.

bool tiramisu::expr::is_unbounded ( ) const
inline

Definition at line 1168 of file expr.h.

tiramisu::expr tiramisu::expr::operator! ( ) const
inline

Logical NOT of an expression.

Definition at line 930 of file expr.h.

References tiramisu::o_logical_not.

Comparison operator.

Definition at line 945 of file expr.h.

References tiramisu::o_ne.

expr tiramisu::expr::operator% ( tiramisu::expr  other) const

Modulo.

tiramisu::expr tiramisu::expr::operator&& ( tiramisu::expr  e1) const
inline

Logical and of two expressions.

Definition at line 906 of file expr.h.

References tiramisu::o_logical_and.

expr tiramisu::expr::operator* ( tiramisu::expr  other) const

Multiplication.

expr tiramisu::expr::operator+ ( tiramisu::expr  other) const

Addition.

expr tiramisu::expr::operator- ( tiramisu::expr  other) const

Subtraction.

tiramisu::expr tiramisu::expr::operator- ( ) const
inline

Expression multiplied by (-1).

Definition at line 922 of file expr.h.

References tiramisu::o_minus.

expr tiramisu::expr::operator/ ( tiramisu::expr  other) const

Division.

tiramisu::expr tiramisu::expr::operator< ( tiramisu::expr  e1) const
inline

Less than operator.

Definition at line 954 of file expr.h.

References tiramisu::o_lt.

expr tiramisu::expr::operator<< ( tiramisu::expr  other) const

Left shift operator.

tiramisu::expr tiramisu::expr::operator<= ( tiramisu::expr  e1) const
inline

Less than or equal operator.

Definition at line 962 of file expr.h.

References tiramisu::o_le.

tiramisu::expr& tiramisu::expr::operator= ( tiramisu::expr const &  )
tiramisu::expr tiramisu::expr::operator== ( tiramisu::expr  e1) const
inline

Comparison operator.

Definition at line 941 of file expr.h.

References tiramisu::o_eq.

tiramisu::expr tiramisu::expr::operator> ( tiramisu::expr  e1) const
inline

Greater than operator.

Definition at line 970 of file expr.h.

References tiramisu::o_gt.

tiramisu::expr tiramisu::expr::operator>= ( tiramisu::expr  e1) const
inline

Greater than or equal operator.

Definition at line 978 of file expr.h.

References tiramisu::o_ge.

expr tiramisu::expr::operator>> ( tiramisu::expr  other) const

Right shift operator.

tiramisu::expr tiramisu::expr::operator|| ( tiramisu::expr  e1) const
inline

Logical and of two expressions.

Definition at line 914 of file expr.h.

References tiramisu::o_logical_or.

tiramisu::expr tiramisu::expr::replace_op_in_expr ( const std::string &  to_replace,
const std::string &  replace_with 
)
inline

Definition at line 732 of file expr.h.

References replace_op_in_expr().

Referenced by replace_op_in_expr().

void tiramisu::expr::set_access ( std::vector< tiramisu::expr vector)
inline

Set the access of a computation or an array.

For example, for the computation C0, this function can set the vector {i, j} as an access vector. The result is that the computation C0 is accessed with C0(i,j).

Definition at line 990 of file expr.h.

void tiramisu::expr::set_access_dimension ( int  i,
tiramisu::expr  acc 
)
inline

Set an element of the vector of accesses of a computation.

This changes only one dimension of the access vector.

Definition at line 999 of file expr.h.

void tiramisu::expr::set_arguments ( std::vector< tiramisu::expr vector)
inline

Set the arguments of an external function call.

For example, for the call my_external(C0, 1, C1(i,j)), vector should be {C0, 1, C1(i,j)}.

Definition at line 1010 of file expr.h.

void tiramisu::expr::set_name ( std::string &  name)
inline
expr tiramisu::expr::substitute ( std::vector< std::pair< var, expr >>  substitutions) const

Returns a new expression where for every (var, sub) pair in substitutions, var in the original expression is replaced by sub.

For example: if substitutions is {(i, 5), (j, i)}, and the original expression is i + j * 2, then this method returns 5 + i * 2.

Referenced by tiramisu::computation::operator()().

expr tiramisu::expr::substitute_access ( std::string  original,
std::string  substitute 
) const

Returns an expression where every access to a computation named original is replaced with an access to a computation named substitute, with the same access indices.

An example where this is useful is when modifying a computation that was designed to work with a host buffer to work with a GPU buffer.

static expr tiramisu::expr::unbounded ( )
inlinestatic

Create a variable that can be used that a dimension is unbounded.

i < tiramisu::expr::unbounded() means that i does not have an upper bound. i > tiramisu::expr::unbounded() means that i does not have a lower bound.

Definition at line 1671 of file expr.h.

References dtype, tiramisu::e_val, etype, name, tiramisu::o_none, and tiramisu::p_none.

Member Data Documentation

tiramisu::primitive_t tiramisu::expr::dtype
protected

Data type.

Definition at line 219 of file expr.h.

Referenced by tiramisu::computation::computation(), is_equal(), and unbounded().

tiramisu::expr_t tiramisu::expr::etype
protected

The type of the expression.

Definition at line 224 of file expr.h.

Referenced by is_equal(), and unbounded().

float tiramisu::expr::float32_value

Definition at line 182 of file expr.h.

double tiramisu::expr::float64_value

Definition at line 183 of file expr.h.

int16_t tiramisu::expr::int16_value

Definition at line 177 of file expr.h.

int32_t tiramisu::expr::int32_value

Definition at line 179 of file expr.h.

int64_t tiramisu::expr::int64_value

Definition at line 181 of file expr.h.

int8_t tiramisu::expr::int8_value

Definition at line 175 of file expr.h.

std::string tiramisu::expr::name
protected

Identifier name.

Definition at line 214 of file expr.h.

Referenced by is_equal(), and unbounded().

uint16_t tiramisu::expr::uint16_value

Definition at line 176 of file expr.h.

uint32_t tiramisu::expr::uint32_value

Definition at line 178 of file expr.h.

uint64_t tiramisu::expr::uint64_value

Definition at line 180 of file expr.h.

uint8_t tiramisu::expr::uint8_value

Definition at line 174 of file expr.h.


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