llvm-project/polly/unittests/Isl/IslTest.cpp

1122 lines
42 KiB
C++
Raw Normal View History

//===- IslTest.cpp ----------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "polly/Support/GICHelper.h"
#include "polly/Support/ISLOperators.h"
#include "polly/Support/ISLTools.h"
#include "gtest/gtest.h"
#include "isl/stream.h"
#include "isl/val.h"
using namespace llvm;
using namespace polly;
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
static isl::space parseSpace(isl_ctx *Ctx, const char *Str) {
isl_stream *Stream = isl_stream_new_str(Ctx, Str);
auto Obj = isl_stream_read_obj(Stream);
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
isl::space Result;
if (Obj.type == isl_obj_set)
Result = isl::manage(isl_set_get_space(static_cast<isl_set *>(Obj.v)));
else if (Obj.type == isl_obj_map)
Result = isl::manage(isl_map_get_space(static_cast<isl_map *>(Obj.v)));
isl_stream_free(Stream);
if (Obj.type)
Obj.type->free(Obj.v);
return Result;
}
#define SPACE(Str) parseSpace(Ctx.get(), Str)
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
#define SET(Str) isl::set(Ctx.get(), Str)
#define MAP(Str) isl::map(Ctx.get(), Str)
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
#define USET(Str) isl::union_set(Ctx.get(), Str)
#define UMAP(Str) isl::union_map(Ctx.get(), Str)
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
namespace isl {
inline namespace noexceptions {
static bool operator==(const isl::space &LHS, const isl::space &RHS) {
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
return bool(LHS.is_equal(RHS));
}
static bool operator==(const isl::basic_set &LHS, const isl::basic_set &RHS) {
return bool(LHS.is_equal(RHS));
}
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
static bool operator==(const isl::set &LHS, const isl::set &RHS) {
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
return bool(LHS.is_equal(RHS));
}
static bool operator==(const isl::basic_map &LHS, const isl::basic_map &RHS) {
return bool(LHS.is_equal(RHS));
}
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
static bool operator==(const isl::map &LHS, const isl::map &RHS) {
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
return bool(LHS.is_equal(RHS));
}
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
static bool operator==(const isl::union_set &LHS, const isl::union_set &RHS) {
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
return bool(LHS.is_equal(RHS));
}
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
static bool operator==(const isl::union_map &LHS, const isl::union_map &RHS) {
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
return bool(LHS.is_equal(RHS));
}
static bool operator==(const isl::val &LHS, const isl::val &RHS) {
return bool(LHS.eq(RHS));
}
static bool operator==(const isl::pw_aff &LHS, const isl::pw_aff &RHS) {
return bool(LHS.is_equal(RHS));
}
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
} // namespace noexceptions
} // namespace isl
namespace {
TEST(Isl, APIntToIslVal) {
isl_ctx *IslCtx = isl_ctx_alloc();
{
APInt APZero(1, 0, true);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslZero = valFromAPInt(IslCtx, APZero, true);
EXPECT_TRUE(IslZero.is_zero());
}
{
APInt APNOne(1, -1, true);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslNOne = valFromAPInt(IslCtx, APNOne, true);
EXPECT_TRUE(IslNOne.is_negone());
}
{
APInt APZero(1, 0, false);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslZero = valFromAPInt(IslCtx, APZero, false);
EXPECT_TRUE(IslZero.is_zero());
}
{
APInt APOne(1, 1, false);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslOne = valFromAPInt(IslCtx, APOne, false);
EXPECT_TRUE(IslOne.is_one());
}
{
APInt APNTwo(2, -2, true);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslNTwo = valFromAPInt(IslCtx, APNTwo, true);
auto IslNTwoCmp = isl::val(IslCtx, -2);
EXPECT_EQ(IslNTwo, IslNTwoCmp);
}
{
APInt APNOne(32, -1, true);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslNOne = valFromAPInt(IslCtx, APNOne, true);
EXPECT_TRUE(IslNOne.is_negone());
}
{
APInt APZero(32, 0, false);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslZero = valFromAPInt(IslCtx, APZero, false);
EXPECT_TRUE(IslZero.is_zero());
}
{
APInt APOne(32, 1, false);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslOne = valFromAPInt(IslCtx, APOne, false);
EXPECT_TRUE(IslOne.is_one());
}
{
APInt APTwo(32, 2, false);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslTwo = valFromAPInt(IslCtx, APTwo, false);
EXPECT_EQ(0, IslTwo.cmp_si(2));
}
{
APInt APNOne(32, (1ull << 32) - 1, false);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslNOne = valFromAPInt(IslCtx, APNOne, false);
auto IslRef = isl::val(IslCtx, 32).pow2().sub_ui(1);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
EXPECT_EQ(IslNOne, IslRef);
}
{
APInt APLarge(130, 2, false);
APLarge = APLarge.shl(70);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslLarge = valFromAPInt(IslCtx, APLarge, false);
auto IslRef = isl::val(IslCtx, 71);
IslRef = IslRef.pow2();
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
EXPECT_EQ(IslLarge, IslRef);
}
isl_ctx_free(IslCtx);
}
TEST(Isl, IslValToAPInt) {
isl_ctx *IslCtx = isl_ctx_alloc();
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslNOne = isl::val(IslCtx, -1);
auto APNOne = APIntFromVal(IslNOne);
// Compare with the two's complement of -1 in a 1-bit integer.
EXPECT_EQ(1, APNOne);
EXPECT_EQ(1u, APNOne.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslNTwo = isl::val(IslCtx, -2);
auto APNTwo = APIntFromVal(IslNTwo);
// Compare with the two's complement of -2 in a 2-bit integer.
EXPECT_EQ(2, APNTwo);
EXPECT_EQ(2u, APNTwo.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslNThree = isl::val(IslCtx, -3);
auto APNThree = APIntFromVal(IslNThree);
// Compare with the two's complement of -3 in a 3-bit integer.
EXPECT_EQ(5, APNThree);
EXPECT_EQ(3u, APNThree.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslNFour = isl::val(IslCtx, -4);
auto APNFour = APIntFromVal(IslNFour);
// Compare with the two's complement of -4 in a 3-bit integer.
EXPECT_EQ(4, APNFour);
EXPECT_EQ(3u, APNFour.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslZero = isl::val(IslCtx, 0);
auto APZero = APIntFromVal(IslZero);
EXPECT_EQ(0, APZero);
EXPECT_EQ(1u, APZero.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslOne = isl::val(IslCtx, 1);
auto APOne = APIntFromVal(IslOne);
EXPECT_EQ(1, APOne);
EXPECT_EQ(2u, APOne.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslTwo = isl::val(IslCtx, 2);
auto APTwo = APIntFromVal(IslTwo);
EXPECT_EQ(2, APTwo);
EXPECT_EQ(3u, APTwo.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslThree = isl::val(IslCtx, 3);
auto APThree = APIntFromVal(IslThree);
EXPECT_EQ(3, APThree);
EXPECT_EQ(3u, APThree.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslFour = isl::val(IslCtx, 4);
auto APFour = APIntFromVal(IslFour);
EXPECT_EQ(4, APFour);
EXPECT_EQ(4u, APFour.getBitWidth());
}
{
auto IslNOne = isl::val(IslCtx, 32).pow2().sub_ui(1);
auto APNOne = APIntFromVal(IslNOne);
EXPECT_EQ((1ull << 32) - 1, APNOne);
EXPECT_EQ(33u, APNOne.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslLargeNum = isl::val(IslCtx, 60);
IslLargeNum = IslLargeNum.pow2();
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
IslLargeNum = IslLargeNum.sub_ui(1);
auto APLargeNum = APIntFromVal(IslLargeNum);
EXPECT_EQ((1ull << 60) - 1, APLargeNum);
EXPECT_EQ(61u, APLargeNum.getBitWidth());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslExp = isl::val(IslCtx, 500);
auto IslLargePow2 = IslExp.pow2();
auto APLargePow2 = APIntFromVal(IslLargePow2);
EXPECT_TRUE(APLargePow2.isPowerOf2());
EXPECT_EQ(502u, APLargePow2.getBitWidth());
EXPECT_EQ(502u, APLargePow2.getMinSignedBits());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslExp = isl::val(IslCtx, 500);
auto IslLargeNPow2 = IslExp.pow2().neg();
auto APLargeNPow2 = APIntFromVal(IslLargeNPow2);
EXPECT_EQ(501u, APLargeNPow2.getBitWidth());
EXPECT_EQ(501u, APLargeNPow2.getMinSignedBits());
EXPECT_EQ(500, (-APLargeNPow2).exactLogBase2());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslExp = isl::val(IslCtx, 512);
auto IslLargePow2 = IslExp.pow2();
auto APLargePow2 = APIntFromVal(IslLargePow2);
EXPECT_TRUE(APLargePow2.isPowerOf2());
EXPECT_EQ(514u, APLargePow2.getBitWidth());
EXPECT_EQ(514u, APLargePow2.getMinSignedBits());
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto IslExp = isl::val(IslCtx, 512);
auto IslLargeNPow2 = IslExp.pow2().neg();
auto APLargeNPow2 = APIntFromVal(IslLargeNPow2);
EXPECT_EQ(513u, APLargeNPow2.getBitWidth());
EXPECT_EQ(513u, APLargeNPow2.getMinSignedBits());
EXPECT_EQ(512, (-APLargeNPow2).exactLogBase2());
}
isl_ctx_free(IslCtx);
}
TEST(Isl, Operators) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> IslCtx(isl_ctx_alloc(),
&isl_ctx_free);
isl::val ValOne = isl::val(IslCtx.get(), 1);
isl::val ValTwo = isl::val(IslCtx.get(), 2);
isl::val ValThree = isl::val(IslCtx.get(), 3);
isl::val ValFour = isl::val(IslCtx.get(), 4);
isl::val ValNegOne = isl::val(IslCtx.get(), -1);
isl::val ValNegTwo = isl::val(IslCtx.get(), -2);
isl::val ValNegThree = isl::val(IslCtx.get(), -3);
isl::val ValNegFour = isl::val(IslCtx.get(), -4);
isl::space Space = isl::space(IslCtx.get(), 0, 0);
isl::local_space LS = isl::local_space(Space);
isl::pw_aff AffOne = isl::aff(LS, ValOne);
isl::pw_aff AffTwo = isl::aff(LS, ValTwo);
isl::pw_aff AffThree = isl::aff(LS, ValThree);
isl::pw_aff AffFour = isl::aff(LS, ValFour);
isl::pw_aff AffNegOne = isl::aff(LS, ValNegOne);
isl::pw_aff AffNegTwo = isl::aff(LS, ValNegTwo);
isl::pw_aff AffNegThree = isl::aff(LS, ValNegThree);
isl::pw_aff AffNegFour = isl::aff(LS, ValNegFour);
// Addition
{
EXPECT_EQ(AffOne + AffOne, AffTwo);
EXPECT_EQ(AffOne + 1, AffTwo);
EXPECT_EQ(1 + AffOne, AffTwo);
EXPECT_EQ(AffOne + ValOne, AffTwo);
EXPECT_EQ(ValOne + AffOne, AffTwo);
}
// Multiplication
{
EXPECT_EQ(AffTwo * AffTwo, AffFour);
EXPECT_EQ(AffTwo * 2, AffFour);
EXPECT_EQ(2 * AffTwo, AffFour);
EXPECT_EQ(AffTwo * ValTwo, AffFour);
EXPECT_EQ(ValTwo * AffTwo, AffFour);
}
// Subtraction
{
EXPECT_EQ(AffTwo - AffOne, AffOne);
EXPECT_EQ(AffTwo - 1, AffOne);
EXPECT_EQ(2 - AffOne, AffOne);
EXPECT_EQ(AffTwo - ValOne, AffOne);
EXPECT_EQ(ValTwo - AffOne, AffOne);
}
// Division
{
EXPECT_EQ(AffFour / AffTwo, AffTwo);
EXPECT_EQ(AffFour / 2, AffTwo);
EXPECT_EQ(4 / AffTwo, AffTwo);
EXPECT_EQ(AffFour / ValTwo, AffTwo);
EXPECT_EQ(AffFour / 2, AffTwo);
// Dividend is negative (should be rounded towards zero)
EXPECT_EQ(AffNegFour / AffThree, AffNegOne);
EXPECT_EQ(AffNegFour / 3, AffNegOne);
EXPECT_EQ((-4) / AffThree, AffNegOne);
EXPECT_EQ(AffNegFour / ValThree, AffNegOne);
EXPECT_EQ(AffNegFour / 3, AffNegOne);
// Divisor is negative (should be rounded towards zero)
EXPECT_EQ(AffFour / AffNegThree, AffNegOne);
EXPECT_EQ(AffFour / -3, AffNegOne);
EXPECT_EQ(4 / AffNegThree, AffNegOne);
EXPECT_EQ(AffFour / ValNegThree, AffNegOne);
EXPECT_EQ(AffFour / -3, AffNegOne);
}
// Remainder
{
EXPECT_EQ(AffThree % AffTwo, AffOne);
EXPECT_EQ(AffThree % 2, AffOne);
EXPECT_EQ(3 % AffTwo, AffOne);
EXPECT_EQ(AffThree % ValTwo, AffOne);
EXPECT_EQ(ValThree % AffTwo, AffOne);
// Dividend is negative (should be rounded towards zero)
EXPECT_EQ(AffNegFour % AffThree, AffNegOne);
EXPECT_EQ(AffNegFour % 3, AffNegOne);
EXPECT_EQ((-4) % AffThree, AffNegOne);
EXPECT_EQ(AffNegFour % ValThree, AffNegOne);
EXPECT_EQ(AffNegFour % 3, AffNegOne);
// Divisor is negative (should be rounded towards zero)
EXPECT_EQ(AffFour % AffNegThree, AffOne);
EXPECT_EQ(AffFour % -3, AffOne);
EXPECT_EQ(4 % AffNegThree, AffOne);
EXPECT_EQ(AffFour % ValNegThree, AffOne);
EXPECT_EQ(AffFour % -3, AffOne);
}
}
TEST(Isl, Foreach) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto MapSpace = isl::space(Ctx.get(), 0, 1, 1);
auto TestBMap = isl::basic_map::universe(MapSpace);
TestBMap = TestBMap.fix_si(isl::dim::out, 0, 0);
TestBMap = TestBMap.fix_si(isl::dim::out, 0, 0);
isl::map TestMap = TestBMap;
isl::union_map TestUMap = TestMap;
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto SetSpace = isl::space(Ctx.get(), 0, 1);
isl::basic_set TestBSet = isl::point(SetSpace);
isl::set TestSet = TestBSet;
isl::union_set TestUSet = TestSet;
{
auto NumBMaps = 0;
isl::stat Stat =
TestMap.foreach_basic_map([&](isl::basic_map BMap) -> isl::stat {
EXPECT_EQ(BMap, TestBMap);
NumBMaps++;
return isl::stat::ok();
});
EXPECT_TRUE(Stat.is_ok());
EXPECT_EQ(1, NumBMaps);
}
{
auto NumBSets = 0;
isl::stat Stat =
TestSet.foreach_basic_set([&](isl::basic_set BSet) -> isl::stat {
EXPECT_EQ(BSet, TestBSet);
NumBSets++;
return isl::stat::ok();
});
EXPECT_TRUE(Stat.is_ok());
EXPECT_EQ(1, NumBSets);
}
{
auto NumMaps = 0;
isl::stat Stat = TestUMap.foreach_map([&](isl::map Map) -> isl::stat {
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
EXPECT_EQ(Map, TestMap);
NumMaps++;
return isl::stat::ok();
});
EXPECT_TRUE(Stat.is_ok());
EXPECT_EQ(1, NumMaps);
}
{
auto NumSets = 0;
isl::stat Stat = TestUSet.foreach_set([&](isl::set Set) -> isl::stat {
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
EXPECT_EQ(Set, TestSet);
NumSets++;
return isl::stat::ok();
});
EXPECT_TRUE(Stat.is_ok());
EXPECT_EQ(1, NumSets);
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto UPwAff = isl::union_pw_aff(TestUSet, isl::val::zero(Ctx.get()));
auto NumPwAffs = 0;
isl::stat Stat = UPwAff.foreach_pw_aff([&](isl::pw_aff PwAff) -> isl::stat {
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
EXPECT_TRUE(PwAff.is_cst());
NumPwAffs++;
return isl::stat::ok();
});
EXPECT_TRUE(Stat.is_ok());
EXPECT_EQ(1, NumPwAffs);
}
{
auto NumBMaps = 0;
EXPECT_TRUE(TestMap
.foreach_basic_map([&](isl::basic_map BMap) -> isl::stat {
EXPECT_EQ(BMap, TestBMap);
NumBMaps++;
return isl::stat::error();
})
.is_error());
Introduce isl C++ bindings, Part 1: value_ptr style interface Over the last couple of months several authors of independent isl C++ bindings worked together to jointly design an official set of isl C++ bindings which combines their experience in developing isl C++ bindings. The new bindings have been designed around a value pointer style interface and remove the need for explicit pointer managenent and instead use C++ language features to manage isl objects. This commit introduces the smart-pointer part of the isl C++ bindings and replaces the current IslPtr<T> classes, which served the very same purpose, but had to be manually maintained. Instead, we now rely on automatically generated classes for each isl object, which provide value_ptr semantics. An isl object has the following smart pointer interface: inline set manage(__isl_take isl_set *ptr); class set { friend inline set manage(__isl_take isl_set *ptr); isl_set *ptr = nullptr; inline explicit set(__isl_take isl_set *ptr); public: inline set(); inline set(const set &obj); inline set &operator=(set obj); inline ~set(); inline __isl_give isl_set *copy() const &; inline __isl_give isl_set *copy() && = delete; inline __isl_keep isl_set *get() const; inline __isl_give isl_set *release(); inline bool is_null() const; } The interface and behavior of the new value pointer style classes is inspired by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3339.pdf, which proposes a std::value_ptr, a smart pointer that applies value semantics to its pointee. We currently only provide a limited set of public constructors and instead require provide a global overloaded type constructor method "isl::obj isl::manage(isl_obj *)", which allows to convert an isl_set* to an isl::set by calling 'S = isl::manage(s)'. This pattern models the make_unique() constructor for unique pointers. The next two functions isl::obj::get() and isl::obj::release() are taken directly from the std::value_ptr proposal: S.get() extracts the raw pointer of the object managed by S. S.release() extracts the raw pointer of the object managed by S and sets the object in S to null. We additionally add std::obj::copy(). S.copy() returns a raw pointer refering to a copy of S, which is a shortcut for "isl::obj(oldobj).release()", a functionality commonly needed when interacting directly with the isl C interface where all methods marked with __isl_take require consumable raw pointers. S.is_null() checks if S manages a pointer or if the managed object is currently null. We add this function to provide a more explicit way to check if the pointer is empty compared to a direct conversion to bool. This commit also introduces a couple of polly-specific extensions that cover features currently not handled by the official isl C++ bindings draft, but which have been provided by IslPtr<T> and are consequently added to avoid code churn. These extensions include: - operator bool() : Conversion from objects to bool - construction from nullptr_t - get_ctx() method - take/keep/give methods, which match the currently used naming convention of IslPtr<T> in Polly. They just forward to (release/get/manage). - raw_ostream printers We expect that these extensions are over time either removed or upstreamed to the official isl bindings. We also export a couple of classes that have not yet been exported in isl (e.g., isl::space) As part of the code review, the following two questions were asked: - Why do we not use a standard smart pointer? std::value_ptr was a proposal that has not been accepted. It is consequently not available in the standard library. Even if it would be available, we want to expand this interface with a complete method interface that is conveniently available from each managed pointer. The most direct way to achieve this is to generate a specialiced value style pointer class for each isl object type and add any additional methods to this class. The relevant changes follow in subsequent commits. - Why do we not use templates or macros to avoid code duplication? It is certainly possible to use templates or macros, but as this code is auto-generated there is no need to make writing this code more efficient. Also, most of these classes will be specialized with individual member functions in subsequent commits, such that there will be little code reuse to exploit. Hence, we decided to do so at the moment. These bindings are not yet officially part of isl, but the draft is already very stable. The smart pointer interface itself did not change since serveral months. Adding this code to Polly is against our normal policy of only importing official isl code. In this case however, we make an exception to showcase a non-trivial use case of these bindings which should increase confidence in these bindings and will help upstreaming them to isl. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30325 llvm-svn: 297452
2017-03-10 19:41:03 +08:00
EXPECT_EQ(1, NumBMaps);
}
{
auto NumMaps = 0;
EXPECT_TRUE(TestUMap
.foreach_map([&](isl::map Map) -> isl::stat {
EXPECT_EQ(Map, TestMap);
NumMaps++;
return isl::stat::error();
})
.is_error());
EXPECT_EQ(1, NumMaps);
}
{
[unittest] Translate isl tests to C++ bindings 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::boolean (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::boolean, we can just cast the isl::boolean to 'bool' or simply use the isl::boolean 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::boolean provides checks such as boolean::is_true_or_error() or boolean::is_true_no_error() 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. Tags: #polly Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D30618 llvm-svn: 297464
2017-03-10 22:58:50 +08:00
auto TestPwAff = isl::pw_aff(TestSet, isl::val::zero(Ctx.get()));
auto NumPieces = 0;
isl::stat Stat = TestPwAff.foreach_piece(
[&](isl::set Domain, isl::aff Aff) -> isl::stat {
EXPECT_EQ(Domain, TestSet);
EXPECT_TRUE(Aff.is_cst());
NumPieces++;
return isl::stat::error();
});
EXPECT_TRUE(Stat.is_error());
EXPECT_EQ(1, NumPieces);
}
}
TEST(ISLTools, beforeScatter) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage with isl_map
EXPECT_EQ(MAP("{ [] -> [i] : i <= 0 }"),
beforeScatter(MAP("{ [] -> [0] }"), false));
EXPECT_EQ(MAP("{ [] -> [i] : i < 0 }"),
beforeScatter(MAP("{ [] -> [0] }"), true));
// Basic usage with isl_union_map
EXPECT_EQ(UMAP("{ A[] -> [i] : i <= 0; B[] -> [i] : i <= 0 }"),
beforeScatter(UMAP("{ A[] -> [0]; B[] -> [0] }"), false));
EXPECT_EQ(UMAP("{ A[] -> [i] : i < 0; B[] -> [i] : i < 0 }"),
beforeScatter(UMAP("{ A[] -> [0]; B[] -> [0] }"), true));
// More than one dimension
EXPECT_EQ(UMAP("{ [] -> [i, j] : i < 0; [] -> [i, j] : i = 0 and j <= 0 }"),
beforeScatter(UMAP("{ [] -> [0, 0] }"), false));
EXPECT_EQ(UMAP("{ [] -> [i, j] : i < 0; [] -> [i, j] : i = 0 and j < 0 }"),
beforeScatter(UMAP("{ [] -> [0, 0] }"), true));
// Functional
EXPECT_EQ(UMAP("{ [i] -> [j] : j <= i }"),
beforeScatter(UMAP("{ [i] -> [i] }"), false));
EXPECT_EQ(UMAP("{ [i] -> [j] : j < i }"),
beforeScatter(UMAP("{ [i] -> [i] }"), true));
// Parametrized
EXPECT_EQ(UMAP("[i] -> { [] -> [j] : j <= i }"),
beforeScatter(UMAP("[i] -> { [] -> [i] }"), false));
EXPECT_EQ(UMAP("[i] -> { [] -> [j] : j < i }"),
beforeScatter(UMAP("[i] -> { [] -> [i] }"), true));
// More than one range
EXPECT_EQ(UMAP("{ [] -> [i] : i <= 10 }"),
beforeScatter(UMAP("{ [] -> [0]; [] -> [10] }"), false));
EXPECT_EQ(UMAP("{ [] -> [i] : i < 10 }"),
beforeScatter(UMAP("{ [] -> [0]; [] -> [10] }"), true));
// Edge case: empty
EXPECT_EQ(UMAP("{ [] -> [i] : 1 = 0 }"),
beforeScatter(UMAP("{ [] -> [i] : 1 = 0 }"), false));
EXPECT_EQ(UMAP("{ [] -> [i] : 1 = 0 }"),
beforeScatter(UMAP("{ [] -> [i] : 1 = 0 }"), true));
}
TEST(ISLTools, afterScatter) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage with isl_map
EXPECT_EQ(MAP("{ [] -> [i] : i >= 0 }"),
afterScatter(MAP("{ [] -> [0] }"), false));
EXPECT_EQ(MAP("{ [] -> [i] : i > 0 }"),
afterScatter(MAP("{ [] -> [0] }"), true));
// Basic usage with isl_union_map
EXPECT_EQ(UMAP("{ A[] -> [i] : i >= 0; B[] -> [i] : i >= 0 }"),
afterScatter(UMAP("{ A[] -> [0]; B[] -> [0] }"), false));
EXPECT_EQ(UMAP("{ A[] -> [i] : i > 0; B[] -> [i] : i > 0 }"),
afterScatter(UMAP("{ A[] -> [0]; B[] -> [0] }"), true));
// More than one dimension
EXPECT_EQ(UMAP("{ [] -> [i, j] : i > 0; [] -> [i, j] : i = 0 and j >= 0 }"),
afterScatter(UMAP("{ [] -> [0, 0] }"), false));
EXPECT_EQ(UMAP("{ [] -> [i, j] : i > 0; [] -> [i, j] : i = 0 and j > 0 }"),
afterScatter(UMAP("{ [] -> [0, 0] }"), true));
// Functional
EXPECT_EQ(UMAP("{ [i] -> [j] : j >= i }"),
afterScatter(UMAP("{ [i] -> [i] }"), false));
EXPECT_EQ(UMAP("{ [i] -> [j] : j > i }"),
afterScatter(UMAP("{ [i] -> [i] }"), true));
// Parametrized
EXPECT_EQ(UMAP("[i] -> { [] -> [j] : j >= i }"),
afterScatter(UMAP("[i] -> { [] -> [i] }"), false));
EXPECT_EQ(UMAP("[i] -> { [] -> [j] : j > i }"),
afterScatter(UMAP("[i] -> { [] -> [i] }"), true));
// More than one range
EXPECT_EQ(UMAP("{ [] -> [i] : i >= 0 }"),
afterScatter(UMAP("{ [] -> [0]; [] -> [10] }"), false));
EXPECT_EQ(UMAP("{ [] -> [i] : i > 0 }"),
afterScatter(UMAP("{ [] -> [0]; [] -> [10] }"), true));
// Edge case: empty
EXPECT_EQ(UMAP("{ }"), afterScatter(UMAP("{ }"), false));
EXPECT_EQ(UMAP("{ }"), afterScatter(UMAP("{ }"), true));
}
TEST(ISLTools, betweenScatter) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage with isl_map
EXPECT_EQ(MAP("{ [] -> [i] : 0 < i < 10 }"),
betweenScatter(MAP("{ [] -> [0] }"), MAP("{ [] -> [10] }"), false,
false));
EXPECT_EQ(
MAP("{ [] -> [i] : 0 <= i < 10 }"),
betweenScatter(MAP("{ [] -> [0] }"), MAP("{ [] -> [10] }"), true, false));
EXPECT_EQ(
MAP("{ [] -> [i] : 0 < i <= 10 }"),
betweenScatter(MAP("{ [] -> [0] }"), MAP("{ [] -> [10] }"), false, true));
EXPECT_EQ(
MAP("{ [] -> [i] : 0 <= i <= 10 }"),
betweenScatter(MAP("{ [] -> [0] }"), MAP("{ [] -> [10] }"), true, true));
// Basic usage with isl_union_map
EXPECT_EQ(UMAP("{ A[] -> [i] : 0 < i < 10; B[] -> [i] : 0 < i < 10 }"),
betweenScatter(UMAP("{ A[] -> [0]; B[] -> [0] }"),
UMAP("{ A[] -> [10]; B[] -> [10] }"), false, false));
EXPECT_EQ(UMAP("{ A[] -> [i] : 0 <= i < 10; B[] -> [i] : 0 <= i < 10 }"),
betweenScatter(UMAP("{ A[] -> [0]; B[] -> [0] }"),
UMAP("{ A[] -> [10]; B[] -> [10] }"), true, false));
EXPECT_EQ(UMAP("{ A[] -> [i] : 0 < i <= 10; B[] -> [i] : 0 < i <= 10 }"),
betweenScatter(UMAP("{ A[] -> [0]; B[] -> [0] }"),
UMAP("{ A[] -> [10]; B[] -> [10] }"), false, true));
EXPECT_EQ(UMAP("{ A[] -> [i] : 0 <= i <= 10; B[] -> [i] : 0 <= i <= 10 }"),
betweenScatter(UMAP("{ A[] -> [0]; B[] -> [0] }"),
UMAP("{ A[] -> [10]; B[] -> [10] }"), true, true));
}
TEST(ISLTools, singleton) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// No element found
EXPECT_EQ(SET("{ [] : 1 = 0 }"), singleton(USET("{ }"), SPACE("{ [] }")));
EXPECT_EQ(MAP("{ [] -> [] : 1 = 0 }"),
singleton(UMAP("{ }"), SPACE("{ [] -> [] }")));
// One element found
EXPECT_EQ(SET("{ [] }"), singleton(USET("{ [] }"), SPACE("{ [] }")));
EXPECT_EQ(MAP("{ [] -> [] }"),
singleton(UMAP("{ [] -> [] }"), SPACE("{ [] -> [] }")));
// Many elements found
EXPECT_EQ(SET("{ [i] : 0 <= i < 10 }"),
singleton(USET("{ [i] : 0 <= i < 10 }"), SPACE("{ [i] }")));
EXPECT_EQ(
MAP("{ [i] -> [i] : 0 <= i < 10 }"),
singleton(UMAP("{ [i] -> [i] : 0 <= i < 10 }"), SPACE("{ [i] -> [j] }")));
// Different parameters
EXPECT_EQ(SET("[i] -> { [i] }"),
singleton(USET("[i] -> { [i] }"), SPACE("{ [i] }")));
EXPECT_EQ(MAP("[i] -> { [i] -> [i] }"),
singleton(UMAP("[i] -> { [i] -> [i] }"), SPACE("{ [i] -> [j] }")));
}
TEST(ISLTools, getNumScatterDims) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(0u, getNumScatterDims(UMAP("{ [] -> [] }")));
EXPECT_EQ(1u, getNumScatterDims(UMAP("{ [] -> [i] }")));
EXPECT_EQ(2u, getNumScatterDims(UMAP("{ [] -> [i,j] }")));
EXPECT_EQ(3u, getNumScatterDims(UMAP("{ [] -> [i,j,k] }")));
// Different scatter spaces
EXPECT_EQ(0u, getNumScatterDims(UMAP("{ A[] -> []; [] -> []}")));
EXPECT_EQ(1u, getNumScatterDims(UMAP("{ A[] -> []; [] -> [i] }")));
EXPECT_EQ(2u, getNumScatterDims(UMAP("{ A[] -> [i]; [] -> [i,j] }")));
EXPECT_EQ(3u, getNumScatterDims(UMAP("{ A[] -> [i]; [] -> [i,j,k] }")));
}
TEST(ISLTools, getScatterSpace) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(SPACE("{ [] }"), getScatterSpace(UMAP("{ [] -> [] }")));
EXPECT_EQ(SPACE("{ [i] }"), getScatterSpace(UMAP("{ [] -> [i] }")));
EXPECT_EQ(SPACE("{ [i,j] }"), getScatterSpace(UMAP("{ [] -> [i,j] }")));
EXPECT_EQ(SPACE("{ [i,j,k] }"), getScatterSpace(UMAP("{ [] -> [i,j,k] }")));
// Different scatter spaces
EXPECT_EQ(SPACE("{ [] }"), getScatterSpace(UMAP("{ A[] -> []; [] -> [] }")));
EXPECT_EQ(SPACE("{ [i] }"),
getScatterSpace(UMAP("{ A[] -> []; [] -> [i] }")));
EXPECT_EQ(SPACE("{ [i,j] }"),
getScatterSpace(UMAP("{ A[] -> [i]; [] -> [i,j] }")));
EXPECT_EQ(SPACE("{ [i,j,k] }"),
getScatterSpace(UMAP("{ A[] -> [i]; [] -> [i,j,k] }")));
}
TEST(ISLTools, makeIdentityMap) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(UMAP("{ [i] -> [i] }"), makeIdentityMap(USET("{ [0] }"), false));
EXPECT_EQ(UMAP("{ [0] -> [0] }"), makeIdentityMap(USET("{ [0] }"), true));
// Multiple spaces
EXPECT_EQ(UMAP("{ [] -> []; [i] -> [i] }"),
makeIdentityMap(USET("{ []; [0] }"), false));
EXPECT_EQ(UMAP("{ [] -> []; [0] -> [0] }"),
makeIdentityMap(USET("{ []; [0] }"), true));
// Edge case: empty
EXPECT_EQ(UMAP("{ }"), makeIdentityMap(USET("{ }"), false));
EXPECT_EQ(UMAP("{ }"), makeIdentityMap(USET("{ }"), true));
}
TEST(ISLTools, reverseDomain) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(MAP("{ [B[] -> A[]] -> [] }"),
reverseDomain(MAP("{ [A[] -> B[]] -> [] }")));
EXPECT_EQ(UMAP("{ [B[] -> A[]] -> [] }"),
reverseDomain(UMAP("{ [A[] -> B[]] -> [] }")));
}
TEST(ISLTools, shiftDim) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(SET("{ [1] }"), shiftDim(SET("{ [0] }"), 0, 1));
EXPECT_EQ(USET("{ [1] }"), shiftDim(USET("{ [0] }"), 0, 1));
// From-end indexing
EXPECT_EQ(USET("{ [0,0,1] }"), shiftDim(USET("{ [0,0,0] }"), -1, 1));
EXPECT_EQ(USET("{ [0,1,0] }"), shiftDim(USET("{ [0,0,0] }"), -2, 1));
EXPECT_EQ(USET("{ [1,0,0] }"), shiftDim(USET("{ [0,0,0] }"), -3, 1));
// Parametrized
EXPECT_EQ(USET("[n] -> { [n+1] }"), shiftDim(USET("[n] -> { [n] }"), 0, 1));
// Union maps
EXPECT_EQ(MAP("{ [1] -> [] }"),
shiftDim(MAP("{ [0] -> [] }"), isl::dim::in, 0, 1));
EXPECT_EQ(UMAP("{ [1] -> [] }"),
shiftDim(UMAP("{ [0] -> [] }"), isl::dim::in, 0, 1));
EXPECT_EQ(MAP("{ [] -> [1] }"),
shiftDim(MAP("{ [] -> [0] }"), isl::dim::out, 0, 1));
EXPECT_EQ(UMAP("{ [] -> [1] }"),
shiftDim(UMAP("{ [] -> [0] }"), isl::dim::out, 0, 1));
}
TEST(DeLICM, computeReachingWrite) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[] : 0 < i }"),
computeReachingWrite(UMAP("{ Dom[] -> [0] }"),
UMAP("{ Dom[] -> Elt[] }"), false, false,
false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[] : 0 < i }"),
computeReachingWrite(UMAP("{ Dom[] -> [0] }"),
UMAP("{ Dom[] -> Elt[] }"), false, false,
true));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[] : 0 <= i }"),
computeReachingWrite(UMAP("{ Dom[] -> [0] }"),
UMAP("{ Dom[] -> Elt[] }"), false, true,
false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[] : 0 <= i }"),
computeReachingWrite(UMAP("{ Dom[] -> [0] }"),
UMAP("{ Dom[] -> Elt[] }"), false, true,
false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[] : i < 0 }"),
computeReachingWrite(UMAP("{ Dom[] -> [0] }"),
UMAP("{ Dom[] -> Elt[] }"), true, false,
false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[] : i <= 0 }"),
computeReachingWrite(UMAP("{ Dom[] -> [0] }"),
UMAP("{ Dom[] -> Elt[] }"), true, false,
true));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[] : i < 0 }"),
computeReachingWrite(UMAP("{ Dom[] -> [0] }"),
UMAP("{ Dom[] -> Elt[] }"), true, true,
false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[] : i <= 0 }"),
computeReachingWrite(UMAP("{ Dom[] -> [0] }"),
UMAP("{ Dom[] -> Elt[] }"), true, true, true));
// Two writes
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom1[] : 0 < i < 10; [Elt[] -> [i]] -> "
"Dom2[] : 10 < i }"),
computeReachingWrite(UMAP("{ Dom1[] -> [0]; Dom2[] -> [10] }"),
UMAP("{ Dom1[] -> Elt[]; Dom2[] -> Elt[] }"),
false, false, false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom1[] : 0 <= i < 10; [Elt[] -> [i]] -> "
"Dom2[] : 10 <= i }"),
computeReachingWrite(UMAP("{ Dom1[] -> [0]; Dom2[] -> [10] }"),
UMAP("{ Dom1[] -> Elt[]; Dom2[] -> Elt[] }"),
false, true, false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom1[] : 0 < i <= 10; [Elt[] -> [i]] -> "
"Dom2[] : 10 < i }"),
computeReachingWrite(UMAP("{ Dom1[] -> [0]; Dom2[] -> [10] }"),
UMAP("{ Dom1[] -> Elt[]; Dom2[] -> Elt[] }"),
false, false, true));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom1[] : 0 <= i <= 10; [Elt[] -> [i]] -> "
"Dom2[] : 10 <= i }"),
computeReachingWrite(UMAP("{ Dom1[] -> [0]; Dom2[] -> [10] }"),
UMAP("{ Dom1[] -> Elt[]; Dom2[] -> Elt[] }"),
false, true, true));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom2[] : 0 < i < 10; [Elt[] -> [i]] -> "
"Dom1[] : i < 0 }"),
computeReachingWrite(UMAP("{ Dom1[] -> [0]; Dom2[] -> [10] }"),
UMAP("{ Dom1[] -> Elt[]; Dom2[] -> Elt[] }"),
true, false, false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom2[] : 0 <= i < 10; [Elt[] -> [i]] -> "
"Dom1[] : i < 0 }"),
computeReachingWrite(UMAP("{ Dom1[] -> [0]; Dom2[] -> [10] }"),
UMAP("{ Dom1[] -> Elt[]; Dom2[] -> Elt[] }"),
true, true, false));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom2[] : 0 < i <= 10; [Elt[] -> [i]] -> "
"Dom1[] : i <= 0 }"),
computeReachingWrite(UMAP("{ Dom1[] -> [0]; Dom2[] -> [10] }"),
UMAP("{ Dom1[] -> Elt[]; Dom2[] -> Elt[] }"),
true, false, true));
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom2[] : 0 <= i <= 10; [Elt[] -> [i]] -> "
"Dom1[] : i <= 0 }"),
computeReachingWrite(UMAP("{ Dom1[] -> [0]; Dom2[] -> [10] }"),
UMAP("{ Dom1[] -> Elt[]; Dom2[] -> Elt[] }"),
true, true, true));
// Domain in same space
EXPECT_EQ(UMAP("{ [Elt[] -> [i]] -> Dom[1] : 0 < i <= 10; [Elt[] -> [i]] -> "
"Dom[2] : 10 < i }"),
computeReachingWrite(UMAP("{ Dom[i] -> [10i - 10] }"),
UMAP("{ Dom[1] -> Elt[]; Dom[2] -> Elt[] }"),
false, false, true));
// Parametric
EXPECT_EQ(UMAP("[p] -> { [Elt[] -> [i]] -> Dom[] : p < i }"),
computeReachingWrite(UMAP("[p] -> { Dom[] -> [p] }"),
UMAP("{ Dom[] -> Elt[] }"), false, false,
false));
// More realistic example (from reduction_embedded.ll)
EXPECT_EQ(
UMAP("{ [Elt[] -> [i]] -> Dom[0] : 0 < i <= 3; [Elt[] -> [i]] -> Dom[1] "
": 3 < i <= 6; [Elt[] -> [i]] -> Dom[2] : 6 < i <= 9; [Elt[] -> "
"[i]] -> Dom[3] : 9 < i <= 12; [Elt[] -> [i]] -> Dom[4] : 12 < i }"),
computeReachingWrite(UMAP("{ Dom[i] -> [3i] : 0 <= i <= 4 }"),
UMAP("{ Dom[i] -> Elt[] : 0 <= i <= 4 }"), false,
false, true));
}
TEST(DeLICM, computeArrayUnused) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// The ReadEltInSameInst parameter doesn't matter in simple cases. To also
// cover the parameter without duplicating the tests, this loops runs over
// other in both settings.
for (bool ReadEltInSameInst = false, Done = false; !Done;
Done = ReadEltInSameInst, ReadEltInSameInst = true) {
// Basic usage: one read, one write
EXPECT_EQ(UMAP("{ Elt[] -> [i] : 0 < i < 10 }"),
computeArrayUnused(UMAP("{ Read[] -> [0]; Write[] -> [10] }"),
UMAP("{ Write[] -> Elt[] }"),
UMAP("{ Read[] -> Elt[] }"), ReadEltInSameInst,
false, false));
EXPECT_EQ(UMAP("{ Elt[] -> [i] : 0 < i <= 10 }"),
computeArrayUnused(UMAP("{ Read[] -> [0]; Write[] -> [10] }"),
UMAP("{ Write[] -> Elt[] }"),
UMAP("{ Read[] -> Elt[] }"), ReadEltInSameInst,
false, true));
EXPECT_EQ(UMAP("{ Elt[] -> [i] : 0 <= i < 10 }"),
computeArrayUnused(UMAP("{ Read[] -> [0]; Write[] -> [10] }"),
UMAP("{ Write[] -> Elt[] }"),
UMAP("{ Read[] -> Elt[] }"), ReadEltInSameInst,
true, false));
EXPECT_EQ(UMAP("{ Elt[] -> [i] : 0 <= i <= 10 }"),
computeArrayUnused(UMAP("{ Read[] -> [0]; Write[] -> [10] }"),
UMAP("{ Write[] -> Elt[] }"),
UMAP("{ Read[] -> Elt[] }"), ReadEltInSameInst,
true, true));
// Two reads
EXPECT_EQ(UMAP("{ Elt[] -> [i] : 0 < i <= 10 }"),
computeArrayUnused(
UMAP("{ Read[0] -> [-10]; Read[1] -> [0]; Write[] -> [10] }"),
UMAP("{ Write[] -> Elt[] }"), UMAP("{ Read[i] -> Elt[] }"),
ReadEltInSameInst, false, true));
// Corner case: no writes
EXPECT_EQ(UMAP("{}"),
computeArrayUnused(UMAP("{ Read[] -> [0] }"), UMAP("{}"),
UMAP("{ Read[] -> Elt[] }"), ReadEltInSameInst,
false, false));
// Corner case: no reads
EXPECT_EQ(UMAP("{ Elt[] -> [i] : i <= 0 }"),
computeArrayUnused(UMAP("{ Write[] -> [0] }"),
UMAP("{ Write[] -> Elt[] }"), UMAP("{}"),
ReadEltInSameInst, false, true));
// Two writes
EXPECT_EQ(
UMAP("{ Elt[] -> [i] : i <= 10 }"),
computeArrayUnused(UMAP("{ WriteA[] -> [0]; WriteB[] -> [10] }"),
UMAP("{ WriteA[] -> Elt[]; WriteB[] -> Elt[] }"),
UMAP("{}"), ReadEltInSameInst, false, true));
// Two unused zones
// read,write,read,write
EXPECT_EQ(
UMAP("{ Elt[] -> [i] : 0 < i <= 10; Elt[] -> [i] : 20 < i <= 30 }"),
computeArrayUnused(UMAP("{ ReadA[] -> [0]; WriteA[] -> [10]; ReadB[] "
"-> [20]; WriteB[] -> [30] }"),
UMAP("{ WriteA[] -> Elt[]; WriteB[] -> Elt[] }"),
UMAP("{ ReadA[] -> Elt[]; ReadB[] -> Elt[] }"),
ReadEltInSameInst, false, true));
// write, write
EXPECT_EQ(
UMAP("{ Elt[] -> [i] : i <= 10 }"),
computeArrayUnused(
UMAP("{ WriteA[] -> [0]; WriteB[] -> [10]; Read[] -> [20] }"),
UMAP("{ WriteA[] -> Elt[]; WriteB[] -> Elt[] }"),
UMAP("{ Read[] -> Elt[] }"), ReadEltInSameInst, false, true));
// write, read
EXPECT_EQ(UMAP("{ Elt[] -> [i] : i <= 0 }"),
computeArrayUnused(UMAP("{ Write[] -> [0]; Read[] -> [10] }"),
UMAP("{ Write[] -> Elt[] }"),
UMAP("{ Read[] -> Elt[] }"), ReadEltInSameInst,
false, true));
// read, write, read
EXPECT_EQ(UMAP("{ Elt[] -> [i] : 0 < i <= 10 }"),
computeArrayUnused(
UMAP("{ ReadA[] -> [0]; Write[] -> [10]; ReadB[] -> [20] }"),
UMAP("{ Write[] -> Elt[] }"),
UMAP("{ ReadA[] -> Elt[]; ReadB[] -> Elt[] }"),
ReadEltInSameInst, false, true));
// read, write, write
EXPECT_EQ(
UMAP("{ Elt[] -> [i] : 0 < i <= 20 }"),
computeArrayUnused(
UMAP("{ Read[] -> [0]; WriteA[] -> [10]; WriteB[] -> [20] }"),
UMAP("{ WriteA[] -> Elt[]; WriteB[] -> Elt[] }"),
UMAP("{ Read[] -> Elt[] }"), ReadEltInSameInst, false, true));
// read, write, write, read
EXPECT_EQ(
UMAP("{ Elt[] -> [i] : 0 < i <= 20 }"),
computeArrayUnused(UMAP("{ ReadA[] -> [0]; WriteA[] -> [10]; WriteB[] "
"-> [20]; ReadB[] -> [30] }"),
UMAP("{ WriteA[] -> Elt[]; WriteB[] -> Elt[] }"),
UMAP("{ ReadA[] -> Elt[]; ReadB[] -> Elt[] }"),
ReadEltInSameInst, false, true));
}
// Read and write in same statement
EXPECT_EQ(UMAP("{ Elt[] -> [i] : i < 0 }"),
computeArrayUnused(UMAP("{ RW[] -> [0] }"),
UMAP("{ RW[] -> Elt[] }"),
UMAP("{ RW[] -> Elt[] }"), true, false, false));
EXPECT_EQ(UMAP("{ Elt[] -> [i] : i <= 0 }"),
computeArrayUnused(UMAP("{ RW[] -> [0] }"),
UMAP("{ RW[] -> Elt[] }"),
UMAP("{ RW[] -> Elt[] }"), true, false, true));
EXPECT_EQ(UMAP("{ Elt[] -> [0] }"),
computeArrayUnused(UMAP("{ RW[] -> [0] }"),
UMAP("{ RW[] -> Elt[] }"),
UMAP("{ RW[] -> Elt[] }"), false, true, true));
}
TEST(DeLICM, convertZoneToTimepoints) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Corner case: empty set
EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{}"), false, false));
EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{}"), true, false));
EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{}"), false, true));
EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{}"), true, true));
// Basic usage
EXPECT_EQ(USET("{}"), convertZoneToTimepoints(USET("{ [1] }"), false, false));
EXPECT_EQ(USET("{ [0] }"),
convertZoneToTimepoints(USET("{ [1] }"), true, false));
EXPECT_EQ(USET("{ [1] }"),
convertZoneToTimepoints(USET("{ [1] }"), false, true));
EXPECT_EQ(USET("{ [0]; [1] }"),
convertZoneToTimepoints(USET("{ [1] }"), true, true));
// Non-adjacent ranges
EXPECT_EQ(USET("{}"),
convertZoneToTimepoints(USET("{ [1]; [11] }"), false, false));
EXPECT_EQ(USET("{ [0]; [10] }"),
convertZoneToTimepoints(USET("{ [1]; [11] }"), true, false));
EXPECT_EQ(USET("{ [1]; [11] }"),
convertZoneToTimepoints(USET("{ [1]; [11] }"), false, true));
EXPECT_EQ(USET("{ [0]; [1]; [10]; [11] }"),
convertZoneToTimepoints(USET("{ [1]; [11] }"), true, true));
// Adjacent unit ranges
EXPECT_EQ(
USET("{ [i] : 0 < i < 10 }"),
convertZoneToTimepoints(USET("{ [i] : 0 < i <= 10 }"), false, false));
EXPECT_EQ(
USET("{ [i] : 0 <= i < 10 }"),
convertZoneToTimepoints(USET("{ [i] : 0 < i <= 10 }"), true, false));
EXPECT_EQ(
USET("{ [i] : 0 < i <= 10 }"),
convertZoneToTimepoints(USET("{ [i] : 0 < i <= 10 }"), false, true));
EXPECT_EQ(USET("{ [i] : 0 <= i <= 10 }"),
convertZoneToTimepoints(USET("{ [i] : 0 < i <= 10 }"), true, true));
// More than one dimension
EXPECT_EQ(USET("{}"),
convertZoneToTimepoints(USET("{ [0,1] }"), false, false));
EXPECT_EQ(USET("{ [0,0] }"),
convertZoneToTimepoints(USET("{ [0,1] }"), true, false));
EXPECT_EQ(USET("{ [0,1] }"),
convertZoneToTimepoints(USET("{ [0,1] }"), false, true));
EXPECT_EQ(USET("{ [0,0]; [0,1] }"),
convertZoneToTimepoints(USET("{ [0,1] }"), true, true));
// Map domains
EXPECT_EQ(UMAP("{}"), convertZoneToTimepoints(UMAP("{ [1] -> [] }"),
isl::dim::in, false, false));
EXPECT_EQ(UMAP("{ [0] -> [] }"),
convertZoneToTimepoints(UMAP("{ [1] -> [] }"), isl::dim::in, true,
false));
EXPECT_EQ(UMAP("{ [1] -> [] }"),
convertZoneToTimepoints(UMAP("{ [1] -> [] }"), isl::dim::in, false,
true));
EXPECT_EQ(
UMAP("{ [0] -> []; [1] -> [] }"),
convertZoneToTimepoints(UMAP("{ [1] -> [] }"), isl::dim::in, true, true));
// Map ranges
EXPECT_EQ(UMAP("{}"), convertZoneToTimepoints(UMAP("{ [] -> [1] }"),
isl::dim::out, false, false));
EXPECT_EQ(UMAP("{ [] -> [0] }"),
convertZoneToTimepoints(UMAP("{ [] -> [1] }"), isl::dim::out, true,
false));
EXPECT_EQ(UMAP("{ [] -> [1] }"),
convertZoneToTimepoints(UMAP("{ [] -> [1] }"), isl::dim::out, false,
true));
EXPECT_EQ(UMAP("{ [] -> [0]; [] -> [1] }"),
convertZoneToTimepoints(UMAP("{ [] -> [1] }"), isl::dim::out, true,
true));
}
TEST(DeLICM, distribute) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(MAP("{ [Domain[] -> Range1[]] -> [Domain[] -> Range2[]] }"),
distributeDomain(MAP("{ Domain[] -> [Range1[] -> Range2[]] }")));
EXPECT_EQ(
MAP("{ [Domain[i,j] -> Range1[i,k]] -> [Domain[i,j] -> Range2[j,k]] }"),
distributeDomain(MAP("{ Domain[i,j] -> [Range1[i,k] -> Range2[j,k]] }")));
// Union maps
EXPECT_EQ(
UMAP(
"{ [DomainA[i,j] -> RangeA1[i,k]] -> [DomainA[i,j] -> RangeA2[j,k]];"
"[DomainB[i,j] -> RangeB1[i,k]] -> [DomainB[i,j] -> RangeB2[j,k]] }"),
distributeDomain(
UMAP("{ DomainA[i,j] -> [RangeA1[i,k] -> RangeA2[j,k]];"
"DomainB[i,j] -> [RangeB1[i,k] -> RangeB2[j,k]] }")));
}
TEST(DeLICM, lift) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(UMAP("{ [Factor[] -> Domain[]] -> [Factor[] -> Range[]] }"),
liftDomains(UMAP("{ Domain[] -> Range[] }"), USET("{ Factor[] }")));
EXPECT_EQ(UMAP("{ [Factor[l] -> Domain[i,k]] -> [Factor[l] -> Range[j,k]] }"),
liftDomains(UMAP("{ Domain[i,k] -> Range[j,k] }"),
USET("{ Factor[l] }")));
// Multiple maps in union
EXPECT_EQ(
UMAP("{ [FactorA[] -> DomainA[]] -> [FactorA[] -> RangeA[]];"
"[FactorB[] -> DomainA[]] -> [FactorB[] -> RangeA[]];"
"[FactorA[] -> DomainB[]] -> [FactorA[] -> RangeB[]];"
"[FactorB[] -> DomainB[]] -> [FactorB[] -> RangeB[]] }"),
liftDomains(UMAP("{ DomainA[] -> RangeA[]; DomainB[] -> RangeB[] }"),
USET("{ FactorA[]; FactorB[] }")));
}
TEST(DeLICM, apply) {
std::unique_ptr<isl_ctx, decltype(&isl_ctx_free)> Ctx(isl_ctx_alloc(),
&isl_ctx_free);
// Basic usage
EXPECT_EQ(
UMAP("{ [DomainDomain[] -> NewDomainRange[]] -> Range[] }"),
applyDomainRange(UMAP("{ [DomainDomain[] -> DomainRange[]] -> Range[] }"),
UMAP("{ DomainRange[] -> NewDomainRange[] }")));
EXPECT_EQ(
UMAP("{ [DomainDomain[i,k] -> NewDomainRange[j,k,l]] -> Range[i,j] }"),
applyDomainRange(
UMAP("{ [DomainDomain[i,k] -> DomainRange[j,k]] -> Range[i,j] }"),
UMAP("{ DomainRange[j,k] -> NewDomainRange[j,k,l] }")));
// Multiple maps in union
EXPECT_EQ(UMAP("{ [DomainDomainA[] -> NewDomainRangeA[]] -> RangeA[];"
"[DomainDomainB[] -> NewDomainRangeB[]] -> RangeB[] }"),
applyDomainRange(
UMAP("{ [DomainDomainA[] -> DomainRangeA[]] -> RangeA[];"
"[DomainDomainB[] -> DomainRangeB[]] -> RangeB[] }"),
UMAP("{ DomainRangeA[] -> NewDomainRangeA[];"
"DomainRangeB[] -> NewDomainRangeB[] }")));
}
} // anonymous namespace