@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
1919<http://www.gnu.org/licenses/>. */
2020
2121#include " config.h"
22+ #include " libgccjit.h"
2223#include " system.h"
2324#include " coretypes.h"
2425#include " target.h"
@@ -505,6 +506,16 @@ new_param (location *loc,
505506 return new param (this , inner);
506507}
507508
509+ const char * fn_attribute_to_string (gcc_jit_fn_attribute attr)
510+ {
511+ switch (attr)
512+ {
513+ case GCC_JIT_FN_ATTRIBUTE_TARGET:
514+ return " target" ;
515+ }
516+ return NULL ;
517+ }
518+
508519/* Construct a playback::function instance. */
509520
510521playback::function *
@@ -516,7 +527,8 @@ new_function (location *loc,
516527 const auto_vec<param *> *params,
517528 int is_variadic,
518529 enum built_in_function builtin_id,
519- int is_target_builtin)
530+ int is_target_builtin,
531+ const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &attributes)
520532{
521533 int i;
522534 param *param;
@@ -609,6 +621,23 @@ new_function (location *loc,
609621 DECL_ATTRIBUTES (fndecl));
610622 }
611623
624+ for (auto attr: attributes)
625+ {
626+ gcc_jit_fn_attribute& name = std::get<0 >(attr);
627+ std::string& value = std::get<1 >(attr);
628+ tree attribute_value = build_tree_list (NULL_TREE, ::build_string (value.length () + 1 , value.c_str ()));
629+ tree ident = get_identifier (fn_attribute_to_string (name));
630+
631+ /* See handle_target_attribute in gcc/c-family/c-attribs.cc. */
632+ if (name == GCC_JIT_FN_ATTRIBUTE_TARGET)
633+ /* We need to call valid_attribute_p so that the hook set-up some internal options. */
634+ if (!targetm.target_option .valid_attribute_p (fndecl, ident, attribute_value, 0 ))
635+ continue ;
636+
637+ DECL_ATTRIBUTES (fndecl) =
638+ tree_cons (ident, attribute_value, DECL_ATTRIBUTES (fndecl));
639+ }
640+
612641 function *func = new function (this , fndecl, kind);
613642 m_functions.safe_push (func);
614643 return func;
0 commit comments