llvm-project/polly/lib/External/isl/cpp/cpp-checked.h.pre
Michael Kruse e8227804ac [Polly] Update ISL to isl-0.22.1-87-gfee05a13.
The primary motivation is to fix an assertion failure in
isl_basic_map_alloc_equality:

    isl_assert(ctx, room_for_con(bmap, 1), return -1);

Although the assertion does not occur anymore, I could not identify
which of ISL's commits fixed it.

Compared to the previous ISL version, Polly requires some changes for this update

 * Since ISL commit
   20d3574 "perform parameter alignment by modifying both arguments to function"
   isl_*_gist_* and similar functions do not always align the paramter
   list anymore. This caused the parameter lists in JScop files to
   become out-of-sync. Since many regression tests use JScop files with
   a fixed parameter list and order, we explicitly call align_params to
   ensure a predictable parameter list.

 * ISL changed some return types to isl_size, a typedef of (signed) int.
   This caused some issues where the return type was unsigned int before:
   - No overload for std::max(unsigned,isl_size)
   - It cause additional 'mixed signed/unsigned comparison' warnings.
     Since they do not break compilation, and sizes larger than 2^31
     were never supported, I am going to fix it separately.

 * With the change to isl_size, commit
   57d547 "isl_*_list_size: return isl_size"
   also changed the return value in case of an error from 0 to -1. This
   caused undefined looping over isl_iterator since the 'end iterator'
   got index -1, never reached from the 'begin iterator' with index 0.

 * Some internal changes in ISL caused the number of operations to
   increase when determining access ranges to determine aliasing
   overlaps. In one test, this caused exceeding the default limit of
   800000. The operations-limit was disabled for this test.
2020-02-10 19:03:08 -06:00

181 lines
3.9 KiB
Plaintext

#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <type_traits>
namespace isl {
namespace checked {
#define ISLPP_STRINGIZE_(X) #X
#define ISLPP_STRINGIZE(X) ISLPP_STRINGIZE_(X)
#define ISLPP_ASSERT(test, message) \
do { \
if (test) \
break; \
fputs("Assertion \"" #test "\" failed at " __FILE__ \
":" ISLPP_STRINGIZE(__LINE__) "\n " message "\n", \
stderr); \
abort(); \
} while (0)
/* Class used to check that isl::checked::boolean,
* isl::checked::stat and isl::checked::size values are checked for errors.
*/
struct checker {
bool checked = false;
~checker() {
ISLPP_ASSERT(checked, "IMPLEMENTATION ERROR: Unchecked state");
}
};
class boolean {
private:
mutable std::shared_ptr<checker> check = std::make_shared<checker>();
isl_bool val;
friend boolean manage(isl_bool val);
boolean(isl_bool val): val(val) {}
public:
static boolean error() {
return boolean(isl_bool_error);
}
boolean()
: val(isl_bool_error) {}
/* implicit */ boolean(bool val)
: val(val ? isl_bool_true : isl_bool_false) {}
isl_bool release() {
auto tmp = val;
val = isl_bool_error;
check->checked = true;
return tmp;
}
bool is_error() const { check->checked = true; return val == isl_bool_error; }
bool is_false() const { check->checked = true; return val == isl_bool_false; }
bool is_true() const { check->checked = true; return val == isl_bool_true; }
explicit operator bool() const {
ISLPP_ASSERT(check->checked, "IMPLEMENTATION ERROR: Unchecked error state");
ISLPP_ASSERT(!is_error(), "IMPLEMENTATION ERROR: Unhandled error state");
return is_true();
}
boolean negate() {
if (val == isl_bool_true)
val = isl_bool_false;
else if (val == isl_bool_false)
val = isl_bool_true;
return *this;
}
boolean operator!() const {
return boolean(*this).negate();
}
};
inline boolean manage(isl_bool val) {
return boolean(val);
}
class ctx {
isl_ctx *ptr;
public:
/* implicit */ ctx(isl_ctx *ctx)
: ptr(ctx) {}
isl_ctx *release() {
auto tmp = ptr;
ptr = nullptr;
return tmp;
}
isl_ctx *get() {
return ptr;
}
};
/* Class encapsulating an isl_stat value.
*/
class stat {
private:
mutable std::shared_ptr<checker> check = std::make_shared<checker>();
isl_stat val;
friend stat manage(isl_stat val);
stat(isl_stat val) : val(val) {}
public:
static stat ok() {
return stat(isl_stat_ok);
}
static stat error() {
return stat(isl_stat_error);
}
stat() : val(isl_stat_error) {}
isl_stat release() {
check->checked = true;
return val;
}
bool is_error() const {
check->checked = true;
return val == isl_stat_error;
}
bool is_ok() const {
check->checked = true;
return val == isl_stat_ok;
}
};
inline stat manage(isl_stat val)
{
return stat(val);
}
/* Class encapsulating an isl_size value.
*/
class size {
private:
mutable std::shared_ptr<checker> check = std::make_shared<checker>();
isl_size val;
friend size manage(isl_size val);
size(isl_size val) : val(val) {}
public:
size() : val(isl_size_error) {}
isl_size release() {
auto tmp = val;
val = isl_size_error;
check->checked = true;
return tmp;
}
bool is_error() const {
check->checked = true;
return val == isl_size_error;
}
explicit operator unsigned() const {
ISLPP_ASSERT(check->checked,
"IMPLEMENTATION ERROR: Unchecked error state");
ISLPP_ASSERT(!is_error(),
"IMPLEMENTATION ERROR: Unhandled error state");
return val;
}
};
inline size manage(isl_size val)
{
return size(val);
}
}
} // namespace isl