-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Conversation
cba27b4
to
08d1b28
Compare
@nicolasvasilache, @ftynse, @chandangreddy: Here a first set of patches for operator overloading. A close review would be very much appreciated. |
08d1b28
to
ca4f484
Compare
@@ -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] = { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
ca4f484
to
fcef1ab
Compare
But uniform initialization is C++11...
…On 03/08/17 23:42, Tobias Grosser wrote:
***@***.**** commented on this pull request.
------------------------------------------------------------------------
In interface/cpp.cc
<#10 (comment)>:
> @@ -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] = {
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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10 (comment)>, or
mute the thread
<https://github.com/notifications/unsubscribe-auth/ABcTa14kA4OEGLlqNyULqvijfp2NNmxkks5sUj6rgaJpZM4OqZYd>.
|
You are right. This means I will need to move back to scanning the array. I think that's fine. |
fcef1ab
to
48c13e4
Compare
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. |
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>
48c13e4
to
49db512
Compare
@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. |
@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. |
Proposed for inclusion on the isl mailing list. |
I see you didn't add |
% 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. |
Poor little |
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:
Signed-off-by: Tobias Grosser tobias@grosser.es