Skip to content

Commit

Permalink
Add isl_pw_aff_val_from_si
Browse files Browse the repository at this point in the history
This function constructs a new piecewise affine expression defined over
a zero-dimensional parameter space. The value of the piecewise affine
expression is the constant value passed to this function.

This function simplifies the construction of parameter expressions.
Specifically, there is no need to talk about set dimensions or even set
spaces in case parameter only expressions are constructed. Constant
piecewise expressions with zero parameter dimensions can be combined
with other parameter-space only dimensions thanks to isl auto-alignment
of parameter dimensions.

Signed-off-by: Tobias Grosser <[email protected]>
  • Loading branch information
tobiasgrosser committed May 28, 2018
1 parent af2ba14 commit 0ba9251
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/user.pod
Original file line number Diff line number Diff line change
Expand Up @@ -3109,6 +3109,8 @@ value is constructed.
#include <isl/aff.h>
__isl_give isl_pw_aff *isl_pw_aff_param_from_id(__isl_take isl_id *id);
__isl_give isl_pw_aff *isl_pw_aff_val_from_val(__isl_take isl_val *val);
__isl_give isl_pw_aff *isl_pw_aff_val_from_si(__isl_keep isl_ctx *ctx,
int val);

The following convenience functions first create a base expression and
then create a piecewise expression over a given domain.
Expand Down
1 change: 1 addition & 0 deletions include/isl/aff.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ __isl_give isl_pw_aff *isl_pw_aff_var_on_domain(__isl_take isl_local_space *ls,

__isl_give isl_pw_aff *isl_pw_aff_param_from_id(__isl_take isl_id *id);
__isl_give isl_pw_aff *isl_pw_aff_val_from_val(__isl_take isl_val *val);
__isl_give isl_pw_aff *isl_pw_aff_val_from_si(__isl_keep isl_ctx *ctx, int val);

__isl_give isl_pw_aff *isl_pw_aff_nan_on_domain(__isl_take isl_local_space *ls);
__isl_give isl_pw_aff *isl_pw_aff_val_on_domain(__isl_take isl_set *domain,
Expand Down
15 changes: 15 additions & 0 deletions isl_aff.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ __isl_give isl_pw_aff *isl_pw_aff_val_from_val(__isl_take isl_val *val)
return isl_pw_aff_val_on_domain(isl_set_universe(space), val);
}

/* Return a piecewise affine expression defined over a zero dimensional
* parameter space. The value of the affine expression is "val".
*/
__isl_give isl_pw_aff *isl_pw_aff_val_from_si(__isl_keep isl_ctx *ctx, int val)
{
isl_val *v;

if (!ctx)
return NULL;

v = isl_val_int_from_si(ctx, v);

return isl_pw_aff_val_from_val(v);
}

/* Return a piecewise affine expression that is equal to
* the specified dimension in "ls".
*/
Expand Down
17 changes: 15 additions & 2 deletions isl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4765,8 +4765,8 @@ static isl_bool union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff *upa,

/* Basic tests on isl_pw_aff.
*
* In particular test the construction of a single-parameter pw_aff from an id
* or an isl val.
* In particular test the construction of a single-parameter pw_aff from an id,
* an isl val, or a signed integer.
*/
static isl_stat test_pa(isl_ctx *ctx) {
isl_id *id;
Expand Down Expand Up @@ -4805,6 +4805,19 @@ static isl_stat test_pa(isl_ctx *ctx) {
isl_die(ctx, isl_error_unknown, "can not construct pw from val",
return isl_stat_error);

pwa = isl_pw_aff_val_from_si(ctx, 10);
pwa2 = isl_pw_aff_read_from_str(ctx, "{ [(10)] }");

equal = isl_pw_aff_plain_is_equal(pwa, pwa2);

isl_pw_aff_free(pwa);
isl_pw_aff_free(pwa2);

if (equal < 0)
return isl_stat_error;
if (!equal)
isl_die(ctx, isl_error_unknown, "can not construct pw from val",
return isl_stat_error);

return isl_stat_ok;
}
Expand Down

0 comments on commit 0ba9251

Please sign in to comment.