Skip to content

Commit 00eaaa7

Browse files
authored
Merge pull request #18 from GuillaumeGomez/cold-attr
fixup! WIP: Add support for function attributes
2 parents cd0ce51 + ad06312 commit 00eaaa7

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

gcc/jit/jit-playback.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
526526
return "used";
527527
case GCC_JIT_FN_ATTRIBUTE_VISIBILITY:
528528
return "visibility";
529+
case GCC_JIT_FN_ATTRIBUTE_COLD:
530+
return "cold";
529531
}
530532
return NULL;
531533
}

gcc/jit/libgccjit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,7 @@ enum gcc_jit_fn_attribute
20842084
GCC_JIT_FN_ATTRIBUTE_TARGET,
20852085
GCC_JIT_FN_ATTRIBUTE_USED,
20862086
GCC_JIT_FN_ATTRIBUTE_VISIBILITY,
2087+
GCC_JIT_FN_ATTRIBUTE_COLD,
20872088
};
20882089

20892090
/* Add an attribute to a function. */
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* { dg-do compile { target x86_64-*-* } } */
2+
3+
#include <stdlib.h>
4+
#include <stdio.h>
5+
6+
#include "libgccjit.h"
7+
8+
/* We don't want set_options() in harness.h to set -O2 to see that the cold
9+
attribute affects the optimizations. */
10+
#define TEST_ESCHEWS_SET_OPTIONS
11+
static void set_options (gcc_jit_context *ctxt, const char *argv0)
12+
{
13+
// Set "-O2".
14+
gcc_jit_context_set_int_option(ctxt, GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL, 2);
15+
}
16+
17+
#define TEST_COMPILING_TO_FILE
18+
#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_ASSEMBLER
19+
#define OUTPUT_FILENAME "output-of-test-cold-attribute.c.s"
20+
#include "harness.h"
21+
22+
void
23+
create_code (gcc_jit_context *ctxt, void *user_data)
24+
{
25+
/* Let's try to inject the equivalent of:
26+
int
27+
__attribute__ ((cold))
28+
t()
29+
{
30+
return -1;
31+
}
32+
33+
*/
34+
gcc_jit_type *int_type =
35+
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
36+
37+
gcc_jit_function *func_t =
38+
gcc_jit_context_new_function (ctxt, NULL,
39+
GCC_JIT_FUNCTION_EXPORTED,
40+
int_type,
41+
"t",
42+
0, NULL,
43+
0);
44+
gcc_jit_function_add_attribute(func_t, GCC_JIT_FN_ATTRIBUTE_COLD);
45+
gcc_jit_block *block = gcc_jit_function_new_block (func_t, NULL);
46+
gcc_jit_rvalue *ret = gcc_jit_context_new_rvalue_from_int (ctxt,
47+
int_type,
48+
-1);
49+
50+
gcc_jit_block_end_with_return (block, NULL, ret);
51+
}
52+
53+
/* { dg-final { jit-verify-output-file-was-created "" } } */
54+
/* { dg-final { jit-verify-assembler-output "orl" } } */

0 commit comments

Comments
 (0)