Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp: export operators for isl::val, isl::aff, and isl::pw_aff #10

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tobiasgrosser
Copy link
Member

@tobiasgrosser tobiasgrosser commented Aug 1, 2017

Add operator overloads for isl::val, isl::aff, and isl::pw_aff. We currently only overload basic arithmetic functions and comparisons between values for which a direct mathematical correspondance exists and consequently confusion is unlikely. Here an example use for isl::val:

isl::val half(ctx, "1/2");
isl::val one(ctx, "1");
isl::val neg_one(ctx, "-1");
isl::val two(ctx, "2");
isl::val four(ctx, "4");

assert(-one == neg_one);
assert(one + one == two);
assert(two - one == one);
assert(two * two == four);
assert(one / two == half);
assert(one < two);
assert(one <= two);
assert(two > one );
assert(two >= one );
assert(one == one);
assert(one != two);

Signed-off-by: Tobias Grosser tobias@grosser.es

@tobiasgrosser
Copy link
Member Author

@nicolasvasilache, @ftynse, @chandangreddy: Here a first set of patches for operator overloading. A close review would be very much appreciated.

@tobiasgrosser tobiasgrosser changed the title cpp: add operator overloads for isl::val cpp: add operator overloads for isl::val, isl::aff, and isl::pw_aff Aug 3, 2017
@tobiasgrosser tobiasgrosser changed the title cpp: add operator overloads for isl::val, isl::aff, and isl::pw_aff cpp: operator overloads for isl::val, isl::aff, and isl::pw_aff Aug 3, 2017
@tobiasgrosser tobiasgrosser changed the title cpp: operator overloads for isl::val, isl::aff, and isl::pw_aff cpp: export operators for isl::val, isl::aff, and isl::pw_aff Aug 3, 2017
@@ -553,13 +553,42 @@ void cpp_generator::print_methods_impl(ostream &os, const isl_class &clazz)
}
}

/* Map isl function names to C++ operators.
*/
static const char *op_map[][2] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered an unordered_map instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sven prefers to not use C++11 in the generator yet (but the generated code is C++11). Hence, I use now a std::map, instead.

@ftynse
Copy link
Member

ftynse commented Aug 3, 2017 via email

@tobiasgrosser
Copy link
Member Author

You are right. This means I will need to move back to scanning the array. I think that's fine.

@ftynse
Copy link
Member

ftynse commented Aug 3, 2017

Sorry about the fuss.

Everything else looks fine. There are some randomly placed spaces in tests, though.

Any ideas on how overloaded operators can be exposed, e.g. isl_val_add_ui ?

This commit adds operators for:

	isl_val_neg

	isl_val_add
	isl_val_sub
	isl_val_mul
	isl_val_div

	isl_val_le
	isl_val_lt
	isl_val_ge
	isl_val_gt
	isl_val_eq
	isl_val_ne

This allows operations on isl_val to be written as:

	isl::val half(ctx, "1/2");
	isl::val one(ctx, "1");
	isl::val neg_one(ctx, "-1");
	isl::val two(ctx, "2");
	isl::val four(ctx, "4");

	assert(-one == neg_one);
	assert(one + one == two);
	assert(two - one == one);
	assert(two * two == four);
	assert(one / two == half);
	assert(one < two);
	assert(one <= two);
	assert(two > one );
	assert(two >= one );
	assert(one == one);
	assert(one != two);

This commit only exports operators which have a direct mathematical
counterpart and which consequently are unlikely to cause any confusion.

Signed-off-by: Tobias Grosser <tobias@grosser.es>
Export these two documented functions that allow to check if affine
expressions are obviously zero:

	isl_pw_aff_plain_is_zero
	isl_aff_plain_is_zero

These two functions are used in Polly to check for obviously empty
arrays and will also be useful for the regression tests in the next
commit.

Signed-off-by: Tobias Grosser <tobias@grosser.es>
This patch adds operators for:

	isl_aff_neg
	isl_aff_add
	isl_aff_sub
	isl_aff_mul
	isl_aff_div

We only export operators which have a direct mathematical counterpart
and which consequently are unlikely to cause any confusion.

Signed-off-by: Tobias Grosser <tobias@grosser.es>
This patch adds operators for:

	isl_pw_aff_neg
	isl_pw_aff_add
	isl_pw_aff_sub
	isl_pw_aff_mul
	isl_pw_aff_div

We only export operators which have a direct mathematical counterpart
and which consequently are unlikely to cause any confusion.

Signed-off-by: Tobias Grosser <tobias@grosser.es>
@tobiasgrosser
Copy link
Member Author

@ftynse : Thanks for the review. Please be as picky as possible. Finding such spaces and such is really imporant. Sven cares about this and any such issue faster to fix in a review here, than on the mailing list. Also, the hope is that these reviews take some of the review load from Sven, such that it is easier for him to have us upstream some of these patches. So again, be as picky as possible.

@tobiasgrosser
Copy link
Member Author

@ftynse : I leaft overloaded operators out on purpose. Doing so is likely requiring some discussions, which I wanted to avoid at this stage. The code snippets I gave to Nicolas should have some examples how to expose them (but not added to the generator yet). We can likely expose them just the way they are today by adding __isl_export, __isl_overload. However, I would like to also allow symmetric operations 42 + val, which requires some more codegen changes. I suggest to leave this to a future change.

@tobiasgrosser
Copy link
Member Author

Proposed for inclusion on the isl mailing list.

@aisoard
Copy link
Collaborator

aisoard commented Aug 4, 2017

I see you didn't add isl_val_mod as the % operator. Is that on purpose?

@tobiasgrosser
Copy link
Member Author

% does not count to the basic arithmetic operations for me. In fact, I mostly wanted to get the standard affine expressions with addition and multiplication to work. I expect that after this is in, other trivial extensions can be easily added. In general I aim to minimize the actual extensions when adding new functionality. % seems one of the first to add afterwards.

@aisoard
Copy link
Collaborator

aisoard commented Aug 4, 2017

Poor little %. Although you are right that it does not fit well yet, because the / is not an integer division here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants