This is an archive of the discontinued LLVM Phabricator instance.

[Polly][unittest] Translate isl tests to C++ bindings
ClosedPublic

Authored by grosser on Mar 5 2017, 8:17 AM.

Details

Summary

For this translation we introduce two functions, valFromAPInt and APIntFromVal,
to convert between isl::Val and APInt. For now these are just proxies, but in
the future they will replace the current isl_val* based conversion functions.

The isl unit test cases benefit most from the new isl::Bool (from Michael
Kruse), which can be explicitly casted to bool and which -- as part of this cast

  • emits a check that no error condition has been triggered so far. This allows

us to simplify

EXPECT_EQ(isl_bool_true, isl_val_is_zero(IslZero));

to

EXPECT_TRUE(IslZero.is_zero());

This simplification also becomes very clear in operator==, which changes from

auto IsEqual = isl_set_is_equal(LHS.keep(), RHS.keep());
EXPECT_NE(isl_bool_error, IsEqual);
return IsEqual;

to just

return bool(LHS.is_equal(RHS));

Some background for non-isl users. The isl C interface has an isl_bool type,
which can be either true, false, or error. Hence, whenever a function returns
a value of type isl_bool, an explicit error check should be considered. By
using isl::Bool, we can just cast the isl::Bool to 'bool' or simply use the
isl::Bool in a context where it will automatically be casted to bool (e.g., in
an if-condition). When doing so, the C++ bindings automatically add code that
verifies that the return value is not an error code. If it is, the program will
warn about this and abort. For cases where errors are expected, isl::Bool
provides checks such as Bool::isTrueOrError() or Bool::isTrueNoError() to
explicitly control program behavior in case of error conditions.

Thanks to the new automatic memory management, we also can avoid many calls to
isl_*_free. For code that had previously been managed by IslPtr<>, many calls
to give/take/copy are eliminated.

Diff Detail

Repository
rL LLVM

Event Timeline

grosser created this revision.Mar 5 2017, 8:17 AM
grosser retitled this revision from [unittest] Translate isl tests to C++ bindings to [Polly][unittest] Translate isl tests to C++ bindings.Mar 5 2017, 8:21 AM
Meinersbur added inline comments.Mar 8 2017, 5:09 PM
include/polly/Support/GICHelper.h
73–76 ↗(On Diff #90612)

The function will look uncommented in Doxygen because it cannot associate the previous comment to both methods.

I don't really complain, just wondering whether our commenting policy is ok with this.

There is also [[http://www.stack.nl/~dimitri/doxygen/manual/commands.html#cmdoverload|\overload]]

unittests/Isl/IslTest.cpp
51 ↗(On Diff #90612)

is_equal in D30616 already returns bool.

285–286 ↗(On Diff #90612)

It would be nice to have something to replace this in the C++ binding, such as an owning isl_ctx.

303 ↗(On Diff #90612)

Not a literal translation, but very nice.

This revision is now accepted and ready to land.Mar 10 2017, 4:03 AM
This revision was automatically updated to reflect the committed changes.