Skip to content

Commit 7cfbde4

Browse files
committed
fixup! WIP: Add support for function attributes
1 parent 6da8bbb commit 7cfbde4

File tree

7 files changed

+53
-11
lines changed

7 files changed

+53
-11
lines changed

gcc/jit/jit-playback.cc

+19-1
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
512512
{
513513
case GCC_JIT_FN_ATTRIBUTE_TARGET:
514514
return "target";
515+
case GCC_JIT_FN_ATTRIBUTE_USED:
516+
return "used";
515517
case GCC_JIT_FN_ATTRIBUTE_VISIBILITY:
516518
return "visibility";
517519
}
@@ -540,7 +542,8 @@ new_function (location *loc,
540542
int is_variadic,
541543
enum built_in_function builtin_id,
542544
int is_target_builtin,
543-
const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &attributes)
545+
const std::vector<gcc_jit_fn_attribute> &attributes,
546+
const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &string_attributes)
544547
{
545548
int i;
546549
param *param;
@@ -634,6 +637,21 @@ new_function (location *loc,
634637
}
635638

636639
for (auto attr: attributes)
640+
{
641+
tree ident = get_identifier (fn_attribute_to_string (attr));
642+
643+
/* See handle_used_attribute in gcc/c-family/c-attribs.cc. */
644+
if (attr == GCC_JIT_FN_ATTRIBUTE_USED)
645+
{
646+
TREE_USED (fndecl) = 1;
647+
DECL_PRESERVE_P (fndecl) = 1;
648+
}
649+
650+
DECL_ATTRIBUTES (fndecl) =
651+
tree_cons (ident, NULL_TREE, DECL_ATTRIBUTES (fndecl));
652+
}
653+
654+
for (auto attr: string_attributes)
637655
{
638656
gcc_jit_fn_attribute& name = std::get<0>(attr);
639657
std::string& value = std::get<1>(attr);

gcc/jit/jit-playback.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class context : public log_user
112112
int is_variadic,
113113
enum built_in_function builtin_id,
114114
int is_target_builtin,
115-
const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &attributes);
115+
const std::vector<gcc_jit_fn_attribute> &attributes,
116+
const std::vector<std::pair<gcc_jit_fn_attribute, std::string>> &string_attributes);
116117

117118
lvalue *
118119
new_global (location *loc,

gcc/jit/jit-recording.cc

+12-4
Original file line numberDiff line numberDiff line change
@@ -4182,7 +4182,8 @@ recording::function::function (context *ctxt,
41824182
m_blocks (),
41834183
m_fn_ptr_type (NULL),
41844184
m_is_target_builtin (is_target_builtin),
4185-
m_attributes()
4185+
m_attributes(),
4186+
m_string_attributes()
41864187
{
41874188
for (int i = 0; i< num_params; i++)
41884189
{
@@ -4243,7 +4244,8 @@ recording::function::replay_into (replayer *r)
42434244
m_is_variadic,
42444245
m_builtin_id,
42454246
m_is_target_builtin,
4246-
m_attributes));
4247+
m_attributes,
4248+
m_string_attributes));
42474249
}
42484250

42494251
/* Create a recording::local instance and add it to
@@ -4488,9 +4490,15 @@ recording::function::get_address (recording::location *loc)
44884490
}
44894491

44904492
void
4491-
recording::function::add_attribute (gcc_jit_fn_attribute attribute, const char* value)
4493+
recording::function::add_attribute (gcc_jit_fn_attribute attribute)
44924494
{
4493-
m_attributes.push_back (std::make_pair (attribute, std::string (value)));
4495+
m_attributes.push_back (attribute);
4496+
}
4497+
4498+
void
4499+
recording::function::add_string_attribute (gcc_jit_fn_attribute attribute, const char* value)
4500+
{
4501+
m_string_attributes.push_back (std::make_pair (attribute, std::string (value)));
44944502
}
44954503

44964504
/* Implementation of recording::memento::make_debug_string for

gcc/jit/jit-recording.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,8 @@ class function : public memento
14341434

14351435
rvalue *get_address (location *loc);
14361436

1437-
void add_attribute (gcc_jit_fn_attribute attribute, const char* value);
1437+
void add_attribute (gcc_jit_fn_attribute attribute);
1438+
void add_string_attribute (gcc_jit_fn_attribute attribute, const char* value);
14381439

14391440
private:
14401441
string * make_debug_string () FINAL OVERRIDE;
@@ -1452,7 +1453,8 @@ class function : public memento
14521453
auto_vec<block *> m_blocks;
14531454
type *m_fn_ptr_type;
14541455
int m_is_target_builtin;
1455-
std::vector<std::pair<gcc_jit_fn_attribute, std::string>> m_attributes;
1456+
std::vector<gcc_jit_fn_attribute> m_attributes;
1457+
std::vector<std::pair<gcc_jit_fn_attribute, std::string>> m_string_attributes;
14561458
};
14571459

14581460
class block : public memento

gcc/jit/libgccjit.cc

+10-2
Original file line numberDiff line numberDiff line change
@@ -4084,11 +4084,19 @@ gcc_jit_type_set_packed (gcc_jit_type *type)
40844084
}
40854085

40864086
void
4087-
gcc_jit_function_add_attribute (gcc_jit_function *func, gcc_jit_fn_attribute attribute, const char* value)
4087+
gcc_jit_function_add_attribute (gcc_jit_function *func, gcc_jit_fn_attribute attribute)
40884088
{
40894089
RETURN_IF_FAIL (func, NULL, NULL, "NULL func");
40904090

4091-
func->add_attribute (attribute, value);
4091+
func->add_attribute (attribute);
4092+
}
4093+
4094+
void
4095+
gcc_jit_function_add_string_attribute (gcc_jit_function *func, gcc_jit_fn_attribute attribute, const char* value)
4096+
{
4097+
RETURN_IF_FAIL (func, NULL, NULL, "NULL func");
4098+
4099+
func->add_string_attribute (attribute, value);
40924100
}
40934101

40944102
void

gcc/jit/libgccjit.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -2041,13 +2041,17 @@ gcc_jit_type_set_packed (gcc_jit_type *type);
20412041
enum gcc_jit_fn_attribute
20422042
{
20432043
GCC_JIT_FN_ATTRIBUTE_TARGET,
2044+
GCC_JIT_FN_ATTRIBUTE_USED,
20442045
GCC_JIT_FN_ATTRIBUTE_VISIBILITY,
20452046
};
20462047

20472048
/* Add an attribute to a function. */
20482049
// TODO: also support integer values.
20492050
extern void
2050-
gcc_jit_function_add_attribute (gcc_jit_function *func, gcc_jit_fn_attribute attribute, const char* value);
2051+
gcc_jit_function_add_attribute (gcc_jit_function *func, gcc_jit_fn_attribute attribute);
2052+
2053+
extern void
2054+
gcc_jit_function_add_string_attribute (gcc_jit_function *func, gcc_jit_fn_attribute attribute, const char* value);
20512055

20522056
/* Variable attributes. */
20532057
enum gcc_jit_variable_attribute

gcc/jit/libgccjit.map

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ LIBGCCJIT_ABI_29 {
302302
LIBGCCJIT_ABI_30 {
303303
global:
304304
gcc_jit_function_add_attribute;
305+
gcc_jit_function_add_string_attribute;
305306
} LIBGCCJIT_ABI_29;
306307

307308
LIBGCCJIT_ABI_31 {

0 commit comments

Comments
 (0)