@@ -19,6 +19,7 @@ along with GCC; see the file COPYING3. If not see
19
19
<http://www.gnu.org/licenses/>. */
20
20
21
21
#include " config.h"
22
+ #include " libgccjit.h"
22
23
#include " system.h"
23
24
#include " coretypes.h"
24
25
#include " target.h"
@@ -505,6 +506,16 @@ new_param (location *loc,
505
506
return new param (this , inner);
506
507
}
507
508
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
+
508
519
/* Construct a playback::function instance. */
509
520
510
521
playback::function *
@@ -516,7 +527,8 @@ new_function (location *loc,
516
527
const auto_vec<param *> *params,
517
528
int is_variadic,
518
529
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)
520
532
{
521
533
int i;
522
534
param *param;
@@ -609,6 +621,23 @@ new_function (location *loc,
609
621
DECL_ATTRIBUTES (fndecl));
610
622
}
611
623
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
+
612
641
function *func = new function (this , fndecl, kind);
613
642
m_functions.safe_push (func);
614
643
return func;
0 commit comments