diff options
author | Tobias Grosser <tobias@grosser.es> | 2018-08-07 05:51:21 +0000 |
---|---|---|
committer | Tobias Grosser <tobias@grosser.es> | 2018-08-07 05:51:21 +0000 |
commit | e1a59c78d647836ea57dd0c13762f0277e0db61b (patch) | |
tree | 92bf0c03ea20b12c345402927604de8a750c6614 /polly | |
parent | ac1ce9c80e32d4712208627271cf8c7afcb84068 (diff) |
Update isl to isl-0.20-48-g13eba5b5
This is a regular maintenance updated.
Diffstat (limited to 'polly')
19 files changed, 268 insertions, 170 deletions
diff --git a/polly/lib/External/isl/GIT_HEAD_ID b/polly/lib/External/isl/GIT_HEAD_ID index e22dafca602..0ad5ed47aab 100644 --- a/polly/lib/External/isl/GIT_HEAD_ID +++ b/polly/lib/External/isl/GIT_HEAD_ID @@ -1 +1 @@ -isl-0.20-35-ge0a98b62 +isl-0.20-48-g13eba5b5 diff --git a/polly/lib/External/isl/configure b/polly/lib/External/isl/configure index d4a3c15cff3..2b08755e511 100755 --- a/polly/lib/External/isl/configure +++ b/polly/lib/External/isl/configure @@ -19672,6 +19672,22 @@ rm -f conftest* cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ +#include <clang/Basic/SourceManager.h> + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "getImmediateExpansionRange" >/dev/null 2>&1; then : + +else + +$as_echo "#define getImmediateExpansionRange getImmediateInstantiationRange" >>confdefs.h + + +fi +rm -f conftest* + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ #include <clang/Basic/Diagnostic.h> _ACEOF diff --git a/polly/lib/External/isl/cpp/cpp.h.pre b/polly/lib/External/isl/cpp/cpp.h.pre index 0e72c2b064c..bf1fdf80971 100644 --- a/polly/lib/External/isl/cpp/cpp.h.pre +++ b/polly/lib/External/isl/cpp/cpp.h.pre @@ -67,9 +67,8 @@ public: exception(const char *what_arg) { what_str = std::make_shared<std::string>(what_arg); } - static inline exception create(enum isl_error error, const char *msg, + static inline void throw_error(enum isl_error error, const char *msg, const char *file, int line); - static inline exception create_from_last_error(ctx ctx); virtual const char *what() const noexcept { return what_str->c_str(); } @@ -84,14 +83,9 @@ public: /* Wrapper for throwing an exception on NULL input. */ static void throw_NULL_input(const char *file, int line) { - throw create(isl_error_invalid, "NULL input", file, line); - } - /* Wrapper for throwing an exception corresponding to the last - * error on "ctx". - */ - static void throw_last_error(ctx ctx) { - throw create_from_last_error(ctx); + throw_error(isl_error_invalid, "NULL input", file, line); } + static inline void throw_last_error(ctx ctx); }; /* Create an exception of a type described by "what_arg", with @@ -153,37 +147,37 @@ class exception_unsupported : public exception { exception("unsupported operation", msg, file, line) {} }; -/* Create an exception of the class that corresponds to "error", with +/* Throw an exception of the class that corresponds to "error", with * error message "msg" in line "line" of file "file". * * isl_error_none is treated as an invalid error type. */ -exception exception::create(enum isl_error error, const char *msg, +void exception::throw_error(enum isl_error error, const char *msg, const char *file, int line) { switch (error) { case isl_error_none: break; - case isl_error_abort: return exception_abort(msg, file, line); - case isl_error_alloc: return exception_alloc(msg, file, line); - case isl_error_unknown: return exception_unknown(msg, file, line); - case isl_error_internal: return exception_internal(msg, file, line); - case isl_error_invalid: return exception_invalid(msg, file, line); - case isl_error_quota: return exception_quota(msg, file, line); + case isl_error_abort: throw exception_abort(msg, file, line); + case isl_error_alloc: throw exception_alloc(msg, file, line); + case isl_error_unknown: throw exception_unknown(msg, file, line); + case isl_error_internal: throw exception_internal(msg, file, line); + case isl_error_invalid: throw exception_invalid(msg, file, line); + case isl_error_quota: throw exception_quota(msg, file, line); case isl_error_unsupported: - return exception_unsupported(msg, file, line); + throw exception_unsupported(msg, file, line); } throw exception_invalid("invalid error type", file, line); } -/* Create an exception from the last error that occurred on "ctx" and +/* Throw an exception corresponding to the last error on "ctx" and * reset the error. * * If "ctx" is NULL or if it is not in an error state at the start, * then an invalid argument exception is thrown. */ -exception exception::create_from_last_error(ctx ctx) +void exception::throw_last_error(ctx ctx) { enum isl_error error; const char *msg, *file; @@ -195,7 +189,7 @@ exception exception::create_from_last_error(ctx ctx) line = isl_ctx_last_error_line(ctx.get()); isl_ctx_reset_error(ctx.get()); - return create(error, msg, file, line); + throw_error(error, msg, file, line); } #else @@ -217,7 +211,7 @@ public: fprintf(stderr, "%s:%d: NULL input\n", file, line); abort(); } - /* Wrapper for throwing an exception corresponding to the last + /* Throw an exception corresponding to the last * error on "ctx". * isl should already abort when an error condition occurs, * so this function should never be called. diff --git a/polly/lib/External/isl/doc/user.pod b/polly/lib/External/isl/doc/user.pod index 319974c200c..18831d26838 100644 --- a/polly/lib/External/isl/doc/user.pod +++ b/polly/lib/External/isl/doc/user.pod @@ -767,7 +767,6 @@ The following unary operations are available on C<isl_val>s. __isl_give isl_val *isl_val_ceil(__isl_take isl_val *v); __isl_give isl_val *isl_val_trunc(__isl_take isl_val *v); __isl_give isl_val *isl_val_inv(__isl_take isl_val *v); - __isl_give isl_val *isl_val_2exp(__isl_take isl_val *v); The following binary operations are available on C<isl_val>s. diff --git a/polly/lib/External/isl/include/isl/cpp.h b/polly/lib/External/isl/include/isl/cpp.h index 2545b3574ff..3062d0fed7d 100644 --- a/polly/lib/External/isl/include/isl/cpp.h +++ b/polly/lib/External/isl/include/isl/cpp.h @@ -88,9 +88,8 @@ public: exception(const char *what_arg) { what_str = std::make_shared<std::string>(what_arg); } - static inline exception create(enum isl_error error, const char *msg, + static inline void throw_error(enum isl_error error, const char *msg, const char *file, int line); - static inline exception create_from_last_error(ctx ctx); virtual const char *what() const noexcept { return what_str->c_str(); } @@ -105,14 +104,9 @@ public: /* Wrapper for throwing an exception on NULL input. */ static void throw_NULL_input(const char *file, int line) { - throw create(isl_error_invalid, "NULL input", file, line); - } - /* Wrapper for throwing an exception corresponding to the last - * error on "ctx". - */ - static void throw_last_error(ctx ctx) { - throw create_from_last_error(ctx); + throw_error(isl_error_invalid, "NULL input", file, line); } + static inline void throw_last_error(ctx ctx); }; /* Create an exception of a type described by "what_arg", with @@ -174,37 +168,37 @@ class exception_unsupported : public exception { exception("unsupported operation", msg, file, line) {} }; -/* Create an exception of the class that corresponds to "error", with +/* Throw an exception of the class that corresponds to "error", with * error message "msg" in line "line" of file "file". * * isl_error_none is treated as an invalid error type. */ -exception exception::create(enum isl_error error, const char *msg, +void exception::throw_error(enum isl_error error, const char *msg, const char *file, int line) { switch (error) { case isl_error_none: break; - case isl_error_abort: return exception_abort(msg, file, line); - case isl_error_alloc: return exception_alloc(msg, file, line); - case isl_error_unknown: return exception_unknown(msg, file, line); - case isl_error_internal: return exception_internal(msg, file, line); - case isl_error_invalid: return exception_invalid(msg, file, line); - case isl_error_quota: return exception_quota(msg, file, line); + case isl_error_abort: throw exception_abort(msg, file, line); + case isl_error_alloc: throw exception_alloc(msg, file, line); + case isl_error_unknown: throw exception_unknown(msg, file, line); + case isl_error_internal: throw exception_internal(msg, file, line); + case isl_error_invalid: throw exception_invalid(msg, file, line); + case isl_error_quota: throw exception_quota(msg, file, line); case isl_error_unsupported: - return exception_unsupported(msg, file, line); + throw exception_unsupported(msg, file, line); } throw exception_invalid("invalid error type", file, line); } -/* Create an exception from the last error that occurred on "ctx" and +/* Throw an exception corresponding to the last error on "ctx" and * reset the error. * * If "ctx" is NULL or if it is not in an error state at the start, * then an invalid argument exception is thrown. */ -exception exception::create_from_last_error(ctx ctx) +void exception::throw_last_error(ctx ctx) { enum isl_error error; const char *msg, *file; @@ -216,7 +210,7 @@ exception exception::create_from_last_error(ctx ctx) line = isl_ctx_last_error_line(ctx.get()); isl_ctx_reset_error(ctx.get()); - return create(error, msg, file, line); + throw_error(error, msg, file, line); } #else @@ -238,7 +232,7 @@ public: fprintf(stderr, "%s:%d: NULL input\n", file, line); abort(); } - /* Wrapper for throwing an exception corresponding to the last + /* Throw an exception corresponding to the last * error on "ctx". * isl should already abort when an error condition occurs, * so this function should never be called. diff --git a/polly/lib/External/isl/interface/cpp.cc b/polly/lib/External/isl/interface/cpp.cc index 955f94415d7..67deece27ac 100644 --- a/polly/lib/External/isl/interface/cpp.cc +++ b/polly/lib/External/isl/interface/cpp.cc @@ -288,10 +288,8 @@ void cpp_generator::print_constructors_decl(ostream &os, for (in = constructors.begin(); in != constructors.end(); ++in) { FunctionDecl *cons = *in; - string fullname = cons->getName(); - function_kind kind = function_kind_constructor; - print_method_decl(os, clazz, fullname, cons, kind); + print_method_decl(os, clazz, cons, function_kind_constructor); } } @@ -379,39 +377,30 @@ void cpp_generator::print_methods_decl(ostream &os, const isl_class &clazz) map<string, set<FunctionDecl *> >::const_iterator it; for (it = clazz.methods.begin(); it != clazz.methods.end(); ++it) - print_method_group_decl(os, clazz, it->first, it->second); + print_method_group_decl(os, clazz, it->second); } -/* Print declarations for methods "methods" of name "fullname" in class "clazz" - * to "os". - * - * "fullname" is the name of the generated C++ method. It commonly corresponds - * to the isl name, with the object type prefix dropped. - * In case of overloaded methods, the result type suffix has also been removed. +/* Print declarations for methods "methods" in class "clazz" to "os". */ void cpp_generator::print_method_group_decl(ostream &os, const isl_class &clazz, - const string &fullname, const set<FunctionDecl *> &methods) + const set<FunctionDecl *> &methods) { set<FunctionDecl *>::const_iterator it; for (it = methods.begin(); it != methods.end(); ++it) { function_kind kind = get_method_kind(clazz, *it); - print_method_decl(os, clazz, fullname, *it, kind); + print_method_decl(os, clazz, *it, kind); } } /* Print declarations for "method" in class "clazz" to "os". * - * "fullname" is the name of the generated C++ method. It commonly corresponds - * to the isl name, with the object type prefix dropped. - * In case of overloaded methods, the result type suffix has also been removed. - * * "kind" specifies the kind of method that should be generated. */ void cpp_generator::print_method_decl(ostream &os, const isl_class &clazz, - const string &fullname, FunctionDecl *method, function_kind kind) + FunctionDecl *method, function_kind kind) { - print_method_header(os, clazz, method, fullname, true, kind); + print_method_header(os, clazz, method, true, kind); } /* Print implementations for class "clazz" to "os". @@ -562,10 +551,8 @@ void cpp_generator::print_constructors_impl(ostream &os, for (in = constructors.begin(); in != constructors.end(); ++in) { FunctionDecl *cons = *in; - string fullname = cons->getName(); - function_kind kind = function_kind_constructor; - print_method_impl(os, clazz, fullname, cons, kind); + print_method_impl(os, clazz, cons, function_kind_constructor); } } @@ -649,21 +636,16 @@ void cpp_generator::print_methods_impl(ostream &os, const isl_class &clazz) first = false; else osprintf(os, "\n"); - print_method_group_impl(os, clazz, it->first, it->second); + print_method_group_impl(os, clazz, it->second); } } -/* Print definitions for methods "methods" of name "fullname" in class "clazz" - * to "os". - * - * "fullname" is the name of the generated C++ method. It commonly corresponds - * to the isl name, with the object type prefix dropped. - * In case of overloaded methods, the result type suffix has also been removed. +/* Print definitions for methods "methods" in class "clazz" to "os". * * "kind" specifies the kind of method that should be generated. */ void cpp_generator::print_method_group_impl(ostream &os, const isl_class &clazz, - const string &fullname, const set<FunctionDecl *> &methods) + const set<FunctionDecl *> &methods) { set<FunctionDecl *>::const_iterator it; bool first = true; @@ -675,7 +657,7 @@ void cpp_generator::print_method_group_impl(ostream &os, const isl_class &clazz, else osprintf(os, "\n"); kind = get_method_kind(clazz, *it); - print_method_impl(os, clazz, fullname, *it, kind); + print_method_impl(os, clazz, *it, kind); } } @@ -899,10 +881,6 @@ void cpp_generator::print_exceptional_execution_check(ostream &os, /* Print definition for "method" in class "clazz" to "os". * - * "fullname" is the name of the generated C++ method. It commonly corresponds - * to the isl name, with the object type prefix dropped. - * In case of overloaded methods, the result type suffix has also been removed. - * * "kind" specifies the kind of method that should be generated. * * This method distinguishes three kinds of methods: member methods, static @@ -943,7 +921,7 @@ void cpp_generator::print_exceptional_execution_check(ostream &os, * because the error message is included in the exception. */ void cpp_generator::print_method_impl(ostream &os, const isl_class &clazz, - const string &fullname, FunctionDecl *method, function_kind kind) + FunctionDecl *method, function_kind kind) { string methodname = method->getName(); int num_params = method->getNumParams(); @@ -951,7 +929,7 @@ void cpp_generator::print_method_impl(ostream &os, const isl_class &clazz, string rettype_str = type2cpp(return_type); bool has_callback = false; - print_method_header(os, clazz, method, fullname, false, kind); + print_method_header(os, clazz, method, false, kind); osprintf(os, "{\n"); print_argument_validity_check(os, method, kind); print_save_ctx(os, method, kind); @@ -1008,10 +986,6 @@ void cpp_generator::print_method_impl(ostream &os, const isl_class &clazz, * Print the header of a declaration if "is_declaration" is set, otherwise print * the header of a method definition. * - * "fullname" is the name of the generated C++ method. It commonly corresponds - * to the isl name, with the object type prefix dropped. - * In case of overloaded methods, the result type suffix has also been removed. - * * "kind" specifies the kind of method that should be generated. * * This function prints headers for member methods, static methods, and @@ -1047,10 +1021,9 @@ void cpp_generator::print_method_impl(ostream &os, const isl_class &clazz, * know that implicit construction is allowed in absence of an explicit keyword. */ void cpp_generator::print_method_header(ostream &os, const isl_class &clazz, - FunctionDecl *method, const string &fullname, bool is_declaration, - function_kind kind) + FunctionDecl *method, bool is_declaration, function_kind kind) { - string cname = fullname.substr(clazz.name.length() + 1); + string cname = clazz.method_name(method); string rettype_str = type2cpp(method->getReturnType()); string classname = type2cpp(clazz); int num_params = method->getNumParams(); @@ -1280,6 +1253,9 @@ void cpp_generator::print_wrapped_call(ostream &os, const string &call) * * stat ret = (*data->func)(manage(arg_0)); * return isl_stat(ret); + * + * If the C callback does not take its arguments, then + * manage_copy is used instead of manage. */ void cpp_generator::print_callback_local(ostream &os, ParmVarDecl *param) { @@ -1303,7 +1279,11 @@ void cpp_generator::print_callback_local(ostream &os, ParmVarDecl *param) call = "(*data->func)("; for (long i = 0; i < num_params - 1; i++) { - call += "manage(arg_" + ::to_string(i) + ")"; + if (!callback_takes_argument(param, i)) + call += "manage_copy"; + else + call += "manage"; + call += "(arg_" + ::to_string(i) + ")"; if (i != num_params - 2) call += ", "; } diff --git a/polly/lib/External/isl/interface/cpp.h b/polly/lib/External/isl/interface/cpp.h index 32a378d8035..b46d37f4e52 100644 --- a/polly/lib/External/isl/interface/cpp.h +++ b/polly/lib/External/isl/interface/cpp.h @@ -12,11 +12,11 @@ class cpp_generator : public generator { protected: bool checked; public: - cpp_generator(set<RecordDecl *> &exported_types, + cpp_generator(SourceManager &SM, set<RecordDecl *> &exported_types, set<FunctionDecl *> exported_functions, set<FunctionDecl *> functions, bool checked = false) : - generator(exported_types, exported_functions, functions), + generator(SM, exported_types, exported_functions, functions), checked(checked) {} enum function_kind { @@ -45,10 +45,9 @@ private: void print_get_ctx_decl(ostream &os); void print_methods_decl(ostream &os, const isl_class &clazz); void print_method_group_decl(ostream &os, const isl_class &clazz, - const string &fullname, const set<FunctionDecl *> &methods); + const set<FunctionDecl *> &methods); void print_method_decl(ostream &os, const isl_class &clazz, - const string &fullname, FunctionDecl *method, - function_kind kind); + FunctionDecl *method, function_kind kind); void print_implementations(ostream &os); void print_class_impl(ostream &os, const isl_class &clazz); void print_class_factory_impl(ostream &os, const isl_class &clazz); @@ -63,7 +62,7 @@ private: void print_get_ctx_impl(ostream &os, const isl_class &clazz); void print_methods_impl(ostream &os, const isl_class &clazz); void print_method_group_impl(ostream &os, const isl_class &clazz, - const string &fullname, const set<FunctionDecl *> &methods); + const set<FunctionDecl *> &methods); void print_argument_validity_check(ostream &os, FunctionDecl *method, function_kind kind); void print_save_ctx(ostream &os, FunctionDecl *method, @@ -72,13 +71,11 @@ private: void print_exceptional_execution_check(ostream &os, FunctionDecl *method); void print_method_impl(ostream &os, const isl_class &clazz, - const string &fullname, FunctionDecl *method, - function_kind kind); + FunctionDecl *method, function_kind kind); void print_method_param_use(ostream &os, ParmVarDecl *param, bool load_from_this_ptr); void print_method_header(ostream &os, const isl_class &clazz, - FunctionDecl *method, const string &fullname, - bool is_declaration, function_kind kind); + FunctionDecl *method, bool is_declaration, function_kind kind); string generate_callback_args(QualType type, bool cpp); string generate_callback_type(QualType type); void print_wrapped_call_checked(std::ostream &os, diff --git a/polly/lib/External/isl/interface/cpp_conversion.h b/polly/lib/External/isl/interface/cpp_conversion.h index 8e10db72537..6fd09c5b876 100644 --- a/polly/lib/External/isl/interface/cpp_conversion.h +++ b/polly/lib/External/isl/interface/cpp_conversion.h @@ -2,9 +2,10 @@ class cpp_conversion_generator : public generator { public: - cpp_conversion_generator(set<RecordDecl *> &exported_types, + cpp_conversion_generator(SourceManager &SM, + set<RecordDecl *> &exported_types, set<FunctionDecl *> exported_functions, set<FunctionDecl *> functions) : - generator(exported_types, exported_functions, functions) {} + generator(SM, exported_types, exported_functions, functions) {} virtual void generate(); }; diff --git a/polly/lib/External/isl/interface/extract_interface.cc b/polly/lib/External/isl/interface/extract_interface.cc index 51e2387f1d3..1267c370f7a 100644 --- a/polly/lib/External/isl/interface/extract_interface.cc +++ b/polly/lib/External/isl/interface/extract_interface.cc @@ -399,21 +399,21 @@ static void set_invocation(CompilerInstance *Clang, /* Create an interface generator for the selected language and * then use it to generate the interface. */ -static void generate(MyASTConsumer &consumer) +static void generate(MyASTConsumer &consumer, SourceManager &SM) { generator *gen; if (Language.compare("python") == 0) { - gen = new python_generator(consumer.exported_types, + gen = new python_generator(SM, consumer.exported_types, consumer.exported_functions, consumer.functions); } else if (Language.compare("cpp") == 0) { - gen = new cpp_generator(consumer.exported_types, + gen = new cpp_generator(SM, consumer.exported_types, consumer.exported_functions, consumer.functions); } else if (Language.compare("cpp-checked") == 0) { - gen = new cpp_generator(consumer.exported_types, + gen = new cpp_generator(SM, consumer.exported_types, consumer.exported_functions, consumer.functions, true); } else if (Language.compare("cpp-checked-conversion") == 0) { - gen = new cpp_conversion_generator(consumer.exported_types, + gen = new cpp_conversion_generator(SM, consumer.exported_types, consumer.exported_functions, consumer.functions); } else { cerr << "Language '" << Language << "' not recognized." << endl @@ -476,7 +476,7 @@ int main(int argc, char *argv[]) ParseAST(*sema); Diags.getClient()->EndSourceFile(); - generate(consumer); + generate(consumer, Clang->getSourceManager()); delete sema; delete Clang; diff --git a/polly/lib/External/isl/interface/generator.cc b/polly/lib/External/isl/interface/generator.cc index 01704f881b1..c3572852d19 100644 --- a/polly/lib/External/isl/interface/generator.cc +++ b/polly/lib/External/isl/interface/generator.cc @@ -32,14 +32,23 @@ */ #include <stdio.h> +#include <string.h> #include <iostream> #include <clang/AST/Attr.h> +#include <clang/Basic/SourceManager.h> #include "isl_config.h" #include "extract_interface.h" #include "generator.h" +/* Compare the prefix of "s" to "prefix" up to the length of "prefix". + */ +static int prefixcmp(const char *s, const char *prefix) +{ + return strncmp(s, prefix, strlen(prefix)); +} + /* Should "method" be considered to be a static method? * That is, is the first argument something other than * an instance of the class? @@ -76,8 +85,9 @@ FunctionDecl *generator::find_by_name(const string &name, bool required) * functions, then they are grouped based on their name after removing the * argument type suffix. */ -generator::generator(set<RecordDecl *> &exported_types, - set<FunctionDecl *> exported_functions, set<FunctionDecl *> functions) +generator::generator(SourceManager &SM, set<RecordDecl *> &exported_types, + set<FunctionDecl *> exported_functions, set<FunctionDecl *> functions) : + SM(SM) { map<string, isl_class>::iterator ci; @@ -107,8 +117,7 @@ generator::generator(set<RecordDecl *> &exported_types, c->constructors.insert(*in); } else { FunctionDecl *method = *in; - string fullname = method->getName(); - fullname = drop_type_suffix(fullname, method); + string fullname = c->name_without_type_suffix(method); c->methods[fullname].insert(method); } } @@ -243,6 +252,82 @@ bool generator::first_arg_is_isl_ctx(FunctionDecl *fd) return is_isl_ctx(param->getOriginalType()); } +namespace { + +struct ClangAPI { + /* Return the first location in the range returned by + * clang::SourceManager::getImmediateExpansionRange. + * Older versions of clang return a pair of SourceLocation objects. + * More recent versions return a CharSourceRange. + */ + static SourceLocation range_begin( + const std::pair<SourceLocation,SourceLocation> &p) { + return p.first; + } + static SourceLocation range_begin(const CharSourceRange &range) { + return range.getBegin(); + } +}; + +} + +/* Does the callback argument "param" take its argument at position "pos"? + * + * The memory management annotations of arguments to function pointers + * are not recorded by clang, so the information cannot be extracted + * from the type of "param". + * Instead, go to the location in the source where the callback argument + * is declared, look for the right argument of the callback itself and + * then check if it has an "__isl_take" memory management annotation. + * + * If the return value of the function has a memory management annotation, + * then the spelling of "param" will point to the spelling + * of this memory management annotation. Since the macro is defined + * on the command line (in main), this location does not have a file entry. + * In this case, move up one level in the macro expansion to the location + * where the memory management annotation is used. + */ +bool generator::callback_takes_argument(ParmVarDecl *param, + int pos) +{ + SourceLocation loc; + const char *s, *end, *next; + bool takes, keeps; + + loc = param->getSourceRange().getBegin(); + if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(loc)))) + loc = ClangAPI::range_begin(SM.getImmediateExpansionRange(loc)); + s = SM.getCharacterData(loc); + if (!s) + die("No character data"); + s = strchr(s, '('); + if (!s) + die("Cannot find function pointer"); + s = strchr(s + 1, '('); + if (!s) + die("Cannot find function pointer arguments"); + end = strchr(s + 1, ')'); + if (!end) + die("Cannot find end of function pointer arguments"); + while (pos-- > 0) { + s = strchr(s + 1, ','); + if (!s || s > end) + die("Cannot find function pointer argument"); + } + next = strchr(s + 1, ','); + if (next && next < end) + end = next; + s = strchr(s + 1, '_'); + if (!s || s > end) + die("Cannot find function pointer argument annotation"); + takes = prefixcmp(s, "__isl_take") == 0; + keeps = prefixcmp(s, "__isl_keep") == 0; + if (!takes && !keeps) + die("Cannot find function pointer argument annotation"); + + return takes; +} + /* Is "type" that of a pointer to an isl_* structure? */ bool generator::is_isl_type(QualType type) @@ -327,24 +412,24 @@ string generator::extract_type(QualType type) die("Cannot extract type from non-pointer type"); } -/* If "method" is overloaded, then drop the suffix of "name" - * corresponding to the type of the final argument and - * return the modified name (or the original name if - * no modifications were made). +/* If "method" is overloaded, then return its name with the suffix + * corresponding to the type of the final argument removed. + * Otherwise, simply return the name of the function. */ -string generator::drop_type_suffix(string name, FunctionDecl *method) +string isl_class::name_without_type_suffix(FunctionDecl *method) { int num_params; ParmVarDecl *param; - string type; + string name, type; size_t name_len, type_len; - if (!is_overload(method)) + name = method->getName(); + if (!generator::is_overload(method)) return name; num_params = method->getNumParams(); param = method->getParamDecl(num_params - 1); - type = extract_type(param->getOriginalType()); + type = generator::extract_type(param->getOriginalType()); type = type.substr(4); name_len = name.length(); type_len = type.length(); diff --git a/polly/lib/External/isl/interface/generator.h b/polly/lib/External/isl/interface/generator.h index 63760845fd6..8195a36d960 100644 --- a/polly/lib/External/isl/interface/generator.h +++ b/polly/lib/External/isl/interface/generator.h @@ -26,17 +26,26 @@ struct isl_class { FunctionDecl *fn_to_str; FunctionDecl *fn_copy; FunctionDecl *fn_free; + + /* Return name of "fd" without type suffix, if any. */ + static string name_without_type_suffix(FunctionDecl *fd); + /* Extract the method name corresponding to "fd". */ + string method_name(FunctionDecl *fd) const { + string m_name = name_without_type_suffix(fd); + return m_name.substr(name.length() + 1); + } }; /* Base class for interface generators. */ class generator { protected: + SourceManager &SM; map<string,isl_class> classes; map<string, FunctionDecl *> functions_by_name; public: - generator(set<RecordDecl *> &exported_types, + generator(SourceManager &SM, set<RecordDecl *> &exported_types, set<FunctionDecl *> exported_functions, set<FunctionDecl *> functions); @@ -44,29 +53,28 @@ public: virtual ~generator() {}; protected: - void print_class_header(const isl_class &clazz, const string &name, - const vector<string> &super); - string drop_type_suffix(string name, FunctionDecl *method); - void die(const char *msg) __attribute__((noreturn)); - void die(string msg) __attribute__((noreturn)); - vector<string> find_superclasses(RecordDecl *decl); - bool is_overload(Decl *decl); - bool is_constructor(Decl *decl); - bool takes(Decl *decl); - bool keeps(Decl *decl); - bool gives(Decl *decl); isl_class *method2class(FunctionDecl *fd); - bool is_isl_ctx(QualType type); - bool first_arg_is_isl_ctx(FunctionDecl *fd); - bool is_isl_type(QualType type); - bool is_isl_bool(QualType type); - bool is_isl_stat(QualType type); - bool is_long(QualType type); - bool is_callback(QualType type); - bool is_string(QualType type); - bool is_static(const isl_class &clazz, FunctionDecl *method); - string extract_type(QualType type); + bool callback_takes_argument(ParmVarDecl *param, int pos); FunctionDecl *find_by_name(const string &name, bool required); +public: + static void die(const char *msg) __attribute__((noreturn)); + static void die(string msg) __attribute__((noreturn)); + static vector<string> find_superclasses(RecordDecl *decl); + static bool is_overload(Decl *decl); + static bool is_constructor(Decl *decl); + static bool takes(Decl *decl); + static bool keeps(Decl *decl); + static bool gives(Decl *decl); + static bool is_isl_ctx(QualType type); + static bool first_arg_is_isl_ctx(FunctionDecl *fd); + static bool is_isl_type(QualType type); + static bool is_isl_bool(QualType type); + static bool is_isl_stat(QualType type); + static bool is_long(QualType type); + static bool is_callback(QualType type); + static bool is_string(QualType type); + static bool is_static(const isl_class &clazz, FunctionDecl *method); + static string extract_type(QualType type); }; #endif /* ISL_INTERFACE_GENERATOR_H */ diff --git a/polly/lib/External/isl/interface/isl.py b/polly/lib/External/isl/interface/isl.py index b6607720e1b..e6bdc7560f5 100644 --- a/polly/lib/External/isl/interface/isl.py +++ b/polly/lib/External/isl/interface/isl.py @@ -1754,7 +1754,7 @@ class union_map(object): exc_info = [None] fn = CFUNCTYPE(c_int, c_void_p, c_void_p) def cb_func(cb_arg0, cb_arg1): - cb_arg0 = map(ctx=arg0.ctx, ptr=cb_arg0) + cb_arg0 = map(ctx=arg0.ctx, ptr=(cb_arg0)) try: arg1(cb_arg0) except: @@ -2464,7 +2464,7 @@ class map(union_map): exc_info = [None] fn = CFUNCTYPE(c_int, c_void_p, c_void_p) def cb_func(cb_arg0, cb_arg1): - cb_arg0 = basic_map(ctx=arg0.ctx, ptr=cb_arg0) + cb_arg0 = basic_map(ctx=arg0.ctx, ptr=(cb_arg0)) try: arg1(cb_arg0) except: @@ -3241,7 +3241,7 @@ class union_set(object): exc_info = [None] fn = CFUNCTYPE(c_int, c_void_p, c_void_p) def cb_func(cb_arg0, cb_arg1): - cb_arg0 = point(ctx=arg0.ctx, ptr=cb_arg0) + cb_arg0 = point(ctx=arg0.ctx, ptr=(cb_arg0)) try: arg1(cb_arg0) except: @@ -3264,7 +3264,7 @@ class union_set(object): exc_info = [None] fn = CFUNCTYPE(c_int, c_void_p, c_void_p) def cb_func(cb_arg0, cb_arg1): - cb_arg0 = set(ctx=arg0.ctx, ptr=cb_arg0) + cb_arg0 = set(ctx=arg0.ctx, ptr=(cb_arg0)) try: arg1(cb_arg0) except: @@ -3657,7 +3657,7 @@ class set(union_set): exc_info = [None] fn = CFUNCTYPE(c_int, c_void_p, c_void_p) def cb_func(cb_arg0, cb_arg1): - cb_arg0 = basic_set(ctx=arg0.ctx, ptr=cb_arg0) + cb_arg0 = basic_set(ctx=arg0.ctx, ptr=(cb_arg0)) try: arg1(cb_arg0) except: diff --git a/polly/lib/External/isl/interface/python.cc b/polly/lib/External/isl/interface/python.cc index 68fdbb88c4a..33a96c2d273 100644 --- a/polly/lib/External/isl/interface/python.cc +++ b/polly/lib/External/isl/interface/python.cc @@ -106,16 +106,27 @@ void python_generator::print_type_check(const string &type, int pos, printf(" raise\n"); } -/* Construct a wrapper for a callback argument (at position "arg"). +/* Print a call to the *_copy function corresponding to "type". + */ +void python_generator::print_copy(QualType type) +{ + string type_s = extract_type(type); + + printf("isl.%s_copy", type_s.c_str()); +} + +/* Construct a wrapper for callback argument "param" (at position "arg"). * Assign the wrapper to "cb". We assume here that a function call * has at most one callback argument. * - * The wrapper converts the arguments of the callback to python types. + * The wrapper converts the arguments of the callback to python types, + * taking a copy if the C callback does not take its arguments. * If any exception is thrown, the wrapper keeps track of it in exc_info[0] * and returns -1. Otherwise the wrapper returns 0. */ -void python_generator::print_callback(QualType type, int arg) +void python_generator::print_callback(ParmVarDecl *param, int arg) { + QualType type = param->getOriginalType()->getPointeeType(); const FunctionProtoType *fn = type->getAs<FunctionProtoType>(); unsigned n_arg = fn->getNumArgs(); @@ -137,8 +148,11 @@ void python_generator::print_callback(QualType type, int arg) for (unsigned i = 0; i < n_arg - 1; ++i) { string arg_type; arg_type = type2python(extract_type(fn->getArgType(i))); - printf(" cb_arg%d = %s(ctx=arg0.ctx, " - "ptr=cb_arg%d)\n", i, arg_type.c_str(), i); + printf(" cb_arg%d = %s(ctx=arg0.ctx, ptr=", + i, arg_type.c_str()); + if (!callback_takes_argument(param, i)) + print_copy(fn->getArgType(i)); + printf("(cb_arg%d))\n", i); } printf(" try:\n"); printf(" arg%d(", arg); @@ -175,8 +189,8 @@ void python_generator::print_arg_in_call(FunctionDecl *fd, int arg, int skip) if (is_callback(type)) { printf("cb"); } else if (takes(param)) { - string type_s = extract_type(type); - printf("isl.%s_copy(arg%d.ptr)", type_s.c_str(), arg - skip); + print_copy(type); + printf("(arg%d.ptr)", arg - skip); } else if (type->isPointerType()) { printf("arg%d.ptr", arg - skip); } else { @@ -256,7 +270,7 @@ void python_generator::print_method(const isl_class &clazz, FunctionDecl *method, vector<string> super) { string fullname = method->getName(); - string cname = fullname.substr(clazz.name.length() + 1); + string cname = clazz.method_name(method); int num_params = method->getNumParams(); int drop_user = 0; int drop_ctx = first_arg_is_isl_ctx(method); @@ -289,7 +303,7 @@ void python_generator::print_method(const isl_class &clazz, QualType type = param->getOriginalType(); if (!is_callback(type)) continue; - print_callback(type->getPointeeType(), i - drop_ctx); + print_callback(param, i - drop_ctx); } if (drop_ctx) printf(" ctx = Context.getDefaultInstance()\n"); @@ -383,7 +397,7 @@ void python_generator::print_method(const isl_class &clazz, return; } - cname = fullname.substr(clazz.name.length() + 1); + cname = clazz.method_name(any_method); num_params = any_method->getNumParams(); print_method_header(is_static(clazz, any_method), cname, num_params); @@ -409,7 +423,7 @@ void python_generator::print_constructor(const isl_class &clazz, FunctionDecl *cons) { string fullname = cons->getName(); - string cname = fullname.substr(clazz.name.length() + 1); + string cname = clazz.method_name(cons); int num_params = cons->getNumParams(); int drop_ctx = first_arg_is_isl_ctx(cons); @@ -439,13 +453,9 @@ void python_generator::print_constructor(const isl_class &clazz, if (i) printf(", "); if (is_isl_type(type)) { - if (takes(param)) { - string type; - type = extract_type(param->getOriginalType()); - printf("isl.%s_copy(args[%d].ptr)", - type.c_str(), i - drop_ctx); - } else - printf("args[%d].ptr", i - drop_ctx); + if (takes(param)) + print_copy(param->getOriginalType()); + printf("(args[%d].ptr)", i - drop_ctx); } else if (is_string(type)) { printf("args[%d].encode('ascii')", i - drop_ctx); } else { diff --git a/polly/lib/External/isl/interface/python.h b/polly/lib/External/isl/interface/python.h index 554e52fd7e5..27d8889b32e 100644 --- a/polly/lib/External/isl/interface/python.h +++ b/polly/lib/External/isl/interface/python.h @@ -10,10 +10,10 @@ private: set<string> done; public: - python_generator(set<RecordDecl *> &exported_types, + python_generator(SourceManager &SM, set<RecordDecl *> &exported_types, set<FunctionDecl *> exported_functions, set<FunctionDecl *> functions) : - generator(exported_types, exported_functions, functions) {} + generator(SM, exported_types, exported_functions, functions) {} virtual void generate(); @@ -24,7 +24,8 @@ private: const vector<string> &super); void print_type_check(const string &type, int pos, bool upcast, const string &super, const string &name, int n); - void print_callback(QualType type, int arg); + void print_copy(QualType type); + void print_callback(ParmVarDecl *param, int arg); void print_arg_in_call(FunctionDecl *fd, int arg, int skip); void print_argtypes(FunctionDecl *fd); void print_method_return(FunctionDecl *method); diff --git a/polly/lib/External/isl/isl_config.h.in b/polly/lib/External/isl/isl_config.h.in index 27b6f94ca5f..781c960eab2 100644 --- a/polly/lib/External/isl/isl_config.h.in +++ b/polly/lib/External/isl/isl_config.h.in @@ -205,6 +205,9 @@ /* Define to getInstantiationLineNumber for older versions of clang */ #undef getExpansionLineNumber +/* Define to getImmediateInstantiationRange for older versions of clang */ +#undef getImmediateExpansionRange + /* Define to getNumParams for newer versions of clang */ #undef getNumArgs diff --git a/polly/lib/External/isl/isl_test_cpp-checked.cc b/polly/lib/External/isl/isl_test_cpp-checked.cc index fd499293969..84bb01a953a 100644 --- a/polly/lib/External/isl/isl_test_cpp-checked.cc +++ b/polly/lib/External/isl/isl_test_cpp-checked.cc @@ -173,4 +173,6 @@ int main() test_foreach(ctx); isl_ctx_free(ctx); + + return EXIT_SUCCESS; } diff --git a/polly/lib/External/isl/isl_test_cpp.cc b/polly/lib/External/isl/isl_test_cpp.cc index e5580b444ee..929d69c4dd6 100644 --- a/polly/lib/External/isl/isl_test_cpp.cc +++ b/polly/lib/External/isl/isl_test_cpp.cc @@ -52,7 +52,7 @@ static void test_return_bool(isl::ctx ctx) try { null.is_empty(); die("no exception raised"); - } catch (const isl::exception &e) { + } catch (const isl::exception_invalid &e) { caught = true; } @@ -131,6 +131,8 @@ static void test_exception(isl::ctx ctx) try { auto umap = isl::union_map::from(mupa); + } catch (const isl::exception_unsupported &error) { + die("caught wrong exception"); } catch (const isl::exception &error) { assert(strstr(error.what(), "without explicit domain")); copy = error; diff --git a/polly/lib/External/isl/m4/ax_detect_clang.m4 b/polly/lib/External/isl/m4/ax_detect_clang.m4 index d3021e03056..fc16d72d7a4 100644 --- a/polly/lib/External/isl/m4/ax_detect_clang.m4 +++ b/polly/lib/External/isl/m4/ax_detect_clang.m4 @@ -43,6 +43,12 @@ AC_EGREP_HEADER([getDefaultTargetTriple], [llvm/Support/Host.h], [], AC_EGREP_HEADER([getExpansionLineNumber], [clang/Basic/SourceLocation.h], [], [AC_DEFINE([getExpansionLineNumber], [getInstantiationLineNumber], [Define to getInstantiationLineNumber for older versions of clang])]) +AC_EGREP_HEADER([getImmediateExpansionRange], [clang/Basic/SourceManager.h], + [], + [AC_DEFINE([getImmediateExpansionRange], + [getImmediateInstantiationRange], + [Define to getImmediateInstantiationRange for older versions of clang])] +) AC_EGREP_HEADER([DiagnosticsEngine], [clang/Basic/Diagnostic.h], [], [AC_DEFINE([DiagnosticsEngine], [Diagnostic], [Define to Diagnostic for older versions of clang])]) diff --git a/polly/lib/External/update-isl.sh b/polly/lib/External/update-isl.sh index c4b9da41d39..e588fa59cb3 100755 --- a/polly/lib/External/update-isl.sh +++ b/polly/lib/External/update-isl.sh @@ -19,7 +19,7 @@ fi (cd $GITDIR && ./autogen.sh) mkdir -p $BUILDDIR (cd $BUILDDIR && $GITDIR/configure --with-int=imath-32 --with-clang=system) -touch $GITDIR/gitversion.h +echo "#define GIT_HEAD_ID \"\"" > $GITDIR/gitversion.h (cd $BUILDDIR && make -j dist) for DISTFILE in "$BUILDDIR/isl*.tar.gz"; do break; done |