@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3. If not see
20
20
21
21
#include " config.h"
22
22
#define INCLUDE_MUTEX
23
+ #include " libgccjit.h"
23
24
#include " system.h"
24
25
#include " coretypes.h"
25
26
#include " target.h"
@@ -507,6 +508,20 @@ new_param (location *loc,
507
508
return new param (this , inner);
508
509
}
509
510
511
+ const char * fn_attribute_to_string (gcc_jit_fn_attribute attr)
512
+ {
513
+ switch (attr)
514
+ {
515
+ case GCC_JIT_FN_ATTRIBUTE_TARGET:
516
+ return " target" ;
517
+ case GCC_JIT_FN_ATTRIBUTE_USED:
518
+ return " used" ;
519
+ case GCC_JIT_FN_ATTRIBUTE_VISIBILITY:
520
+ return " visibility" ;
521
+ }
522
+ return NULL ;
523
+ }
524
+
510
525
/* Construct a playback::function instance. */
511
526
512
527
playback::function *
@@ -518,7 +533,9 @@ new_function (location *loc,
518
533
const auto_vec<param *> *params,
519
534
int is_variadic,
520
535
enum built_in_function builtin_id,
521
- int is_target_builtin)
536
+ int is_target_builtin,
537
+ const std::vector<gcc_jit_fn_attribute> &attributes,
538
+ const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &string_attributes)
522
539
{
523
540
int i;
524
541
param *param;
@@ -611,6 +628,38 @@ new_function (location *loc,
611
628
DECL_ATTRIBUTES (fndecl));
612
629
}
613
630
631
+ for (auto attr: attributes)
632
+ {
633
+ tree ident = get_identifier (fn_attribute_to_string (attr));
634
+
635
+ /* See handle_used_attribute in gcc/c-family/c-attribs.cc. */
636
+ if (attr == GCC_JIT_FN_ATTRIBUTE_USED)
637
+ {
638
+ TREE_USED (fndecl) = 1 ;
639
+ DECL_PRESERVE_P (fndecl) = 1 ;
640
+ }
641
+
642
+ DECL_ATTRIBUTES (fndecl) =
643
+ tree_cons (ident, NULL_TREE, DECL_ATTRIBUTES (fndecl));
644
+ }
645
+
646
+ for (auto attr: string_attributes)
647
+ {
648
+ gcc_jit_fn_attribute& name = std::get<0 >(attr);
649
+ std::string& value = std::get<1 >(attr);
650
+ tree attribute_value = build_tree_list (NULL_TREE, ::build_string (value.length () + 1 , value.c_str ()));
651
+ tree ident = get_identifier (fn_attribute_to_string (name));
652
+
653
+ /* See handle_target_attribute in gcc/c-family/c-attribs.cc. */
654
+ if (name == GCC_JIT_FN_ATTRIBUTE_TARGET)
655
+ /* We need to call valid_attribute_p so that the hook set-up some internal options. */
656
+ if (!targetm.target_option .valid_attribute_p (fndecl, ident, attribute_value, 0 ))
657
+ continue ;
658
+
659
+ DECL_ATTRIBUTES (fndecl) =
660
+ tree_cons (ident, attribute_value, DECL_ATTRIBUTES (fndecl));
661
+ }
662
+
614
663
function *func = new function (this , fndecl, kind);
615
664
m_functions.safe_push (func);
616
665
return func;
0 commit comments