utils.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* GCC-StarPU
  2. Copyright (C) 2012 INRIA
  3. GCC-StarPU is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. GCC-StarPU is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with GCC-StarPU. If not, see <http://www.gnu.org/licenses/>. */
  13. /* Various utilities. */
  14. #pragma once
  15. #include <starpu-gcc/config.h>
  16. #include <unistd.h>
  17. /* GCC 4.7 requires compilation with `g++', and C++ lacks a number of GNU C
  18. features, so work around that. */
  19. #ifdef __cplusplus
  20. /* G++ doesn't implement nested functions, so use C++11 lambdas instead. */
  21. # include <functional>
  22. # define local_define(ret, name, parms) auto name = [=]parms
  23. # define function_parm(ret, name, parms) std::function<ret parms> name
  24. /* G++ lacks designated initializers. */
  25. # define designated_field_init(name, value) value /* XXX: cross fingers */
  26. #else /* !__cplusplus */
  27. /* GNU C nested functions. */
  28. # define local_define(ret, name, parms) ret name parms
  29. # define function_parm(ret, name, parms) ret (*name) parms
  30. /* Designated field initializer. */
  31. # define designated_field_init(name, value) .name = value
  32. #endif /* !__cplusplus */
  33. /* List and vector utilities, à la SRFI-1. */
  34. extern tree chain_trees (tree t, ...)
  35. __attribute__ ((sentinel));
  36. extern tree filter (function_parm (bool, pred, (const_tree)), tree t);
  37. extern tree list_remove (function_parm (bool, pred, (const_tree)), tree t);
  38. extern tree map (function_parm (tree, func, (const_tree)), tree t);
  39. extern void for_each (function_parm (void, func, (tree)), tree t);
  40. extern size_t count (function_parm (bool, pred, (const_tree)), const_tree t);
  41. /* Compatibility tricks & workarounds. */
  42. #include <tree.h>
  43. #include <vec.h>
  44. /* This declaration is from `c-tree.h', but that header doesn't get
  45. installed. */
  46. extern tree xref_tag (enum tree_code, tree);
  47. #if !HAVE_DECL_BUILTIN_DECL_EXPLICIT
  48. /* This function was introduced in GCC 4.7 as a replacement for the
  49. `built_in_decls' array. */
  50. static inline tree
  51. builtin_decl_explicit (enum built_in_function fncode)
  52. {
  53. return built_in_decls[fncode];
  54. }
  55. #endif
  56. #if !HAVE_DECL_BUILD_CALL_EXPR_LOC_ARRAY
  57. extern tree build_call_expr_loc_array (location_t loc, tree fndecl, int n,
  58. tree *argarray);
  59. #endif
  60. #if !HAVE_DECL_BUILD_CALL_EXPR_LOC_VEC
  61. extern tree build_call_expr_loc_vec (location_t loc, tree fndecl,
  62. VEC(tree,gc) *vec);
  63. #endif
  64. #if !HAVE_DECL_BUILD_ZERO_CST
  65. extern tree build_zero_cst (tree type);
  66. #endif
  67. #ifndef VEC_qsort
  68. /* This macro is missing in GCC 4.5. */
  69. # define VEC_qsort(T,V,CMP) qsort(VEC_address (T,V), VEC_length(T,V), \
  70. sizeof (T), CMP)
  71. #endif
  72. /* Helpers. */
  73. extern bool verbose_output_p;
  74. extern tree build_pointer_lookup (tree pointer);
  75. extern tree build_starpu_error_string (tree error_var);
  76. extern tree build_constructor_from_unsorted_list (tree type, tree vals);
  77. extern tree read_pragma_expressions (const char *pragma, location_t loc);
  78. extern tree type_decl_for_struct_tag (const char *tag);
  79. extern tree build_function_arguments (tree fn);
  80. extern tree build_error_statements (location_t, tree,
  81. function_parm (tree, f, (tree)),
  82. const char *, ...)
  83. __attribute__ ((format (printf, 4, 5)));
  84. extern bool void_type_p (const_tree lst);
  85. extern bool pointer_type_p (const_tree lst);
  86. /* Lookup the StarPU function NAME in the global scope and store the result
  87. in VAR (this can't be done from `lower_starpu'.) */
  88. #define LOOKUP_STARPU_FUNCTION(var, name) \
  89. if ((var) == NULL_TREE) \
  90. { \
  91. (var) = lookup_name (get_identifier (name)); \
  92. gcc_assert ((var) != NULL_TREE && TREE_CODE (var) == FUNCTION_DECL); \
  93. }
  94. /* Don't warn about the unused `gcc_version' variable, from
  95. <plugin-version.h>. */
  96. static const struct plugin_gcc_version *starpu_gcc_version
  97. __attribute__ ((__unused__)) = &gcc_version;