Skip to content

Commit a195205

Browse files
committed
libgccjit: Add support for Aarch64 CPU features
1 parent 0503f28 commit a195205

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

gcc/config.gcc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ aarch64*-*-*)
359359
c_target_objs="aarch64-c.o"
360360
cxx_target_objs="aarch64-c.o"
361361
d_target_objs="aarch64-d.o"
362+
jit_target_objs="aarch64-jit.o"
362363
extra_objs="aarch64-builtins.o aarch-common.o aarch64-sve-builtins.o aarch64-sve-builtins-shapes.o aarch64-sve-builtins-base.o aarch64-sve-builtins-sve2.o aarch64-sve-builtins-sme.o cortex-a57-fma-steering.o aarch64-speculation.o aarch-bti-insert.o aarch64-cc-fusion.o aarch64-early-ra.o aarch64-ldp-fusion.o"
363364
target_gtfiles="\$(srcdir)/config/aarch64/aarch64-protos.h \$(srcdir)/config/aarch64/aarch64-builtins.h \$(srcdir)/config/aarch64/aarch64-builtins.cc \$(srcdir)/config/aarch64/aarch64-sve-builtins.h \$(srcdir)/config/aarch64/aarch64-sve-builtins.cc"
364365
target_has_targetm_common=yes

gcc/config/aarch64/aarch64-jit.cc

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/* Subroutines for the jit front end on the AArch64 architecture.
2+
Copyright (C) 2024 Free Software Foundation, Inc.
3+
4+
GCC is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 3, or (at your option)
7+
any later version.
8+
9+
GCC is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with GCC; see the file COPYING3. If not see
16+
<http://www.gnu.org/licenses/>. */
17+
18+
#define IN_TARGET_CODE 1
19+
20+
#include "config.h"
21+
#include "system.h"
22+
#include "coretypes.h"
23+
#include "tm.h"
24+
#include "tm_jit.h"
25+
#include <sys/auxv.h>
26+
#include "jit/jit-target.h"
27+
#include "jit/jit-target-def.h"
28+
29+
/* Implement TARGET_JIT_REGISTER_CPU_TARGET_INFO. */
30+
31+
void
32+
aarch64_jit_register_target_info (void)
33+
{
34+
#define getCPUFeature(id, ftr) __asm__("mrs %0, " #id : "=r"(ftr))
35+
#define extractBits(val, start, number) \
36+
(val & ((1ULL << number) - 1ULL) << start) >> start
37+
38+
const char *params[] = {"arch"};
39+
const char* local_cpu = host_detect_local_cpu (2, params);
40+
std::string arch = local_cpu;
41+
free (const_cast <char *> (local_cpu));
42+
43+
const char* arg = "-march=";
44+
size_t arg_pos = arch.find (arg) + strlen (arg);
45+
size_t end_pos = arch.find (" ", arg_pos);
46+
47+
std::string cpu = arch.substr (arg_pos, end_pos - arg_pos);
48+
jit_target_set_arch (cpu);
49+
50+
if (TARGET_AES)
51+
jit_add_target_info ("target_feature", "aes");
52+
if (TARGET_BF16_FP)
53+
jit_add_target_info ("target_feature", "bf16");
54+
if (TARGET_BTI)
55+
jit_add_target_info ("target_feature", "bti");
56+
if (TARGET_COMPLEX)
57+
// TODO: check if this is the correct match.
58+
jit_add_target_info ("target_feature", "fcma");
59+
if (TARGET_CRC32)
60+
jit_add_target_info ("target_feature", "crc");
61+
if (TARGET_DOTPROD)
62+
jit_add_target_info ("target_feature", "dotprod");
63+
if (TARGET_SVE_F32MM)
64+
// TODO: check if this is the correct match.
65+
jit_add_target_info ("target_feature", "f32mm");
66+
if (TARGET_SVE_F64MM)
67+
// TODO: check if this is the correct match.
68+
jit_add_target_info ("target_feature", "f64mm");
69+
if (TARGET_F16FML)
70+
// TODO: check if this is the correct match.
71+
jit_add_target_info ("target_feature", "fhm");
72+
if (TARGET_FP_F16INST)
73+
// TODO: check if this is the correct match.
74+
jit_add_target_info ("target_feature", "fp16");
75+
if (TARGET_FRINT)
76+
// TODO: check if this is the correct match.
77+
jit_add_target_info ("target_feature", "frintts");
78+
if (TARGET_I8MM)
79+
jit_add_target_info ("target_feature", "i8mm");
80+
if (TARGET_JSCVT)
81+
// TODO: check if this is the correct match.
82+
jit_add_target_info ("target_feature", "jsconv");
83+
if (TARGET_LSE)
84+
jit_add_target_info ("target_feature", "lse");
85+
if (TARGET_MEMTAG)
86+
// TODO: check if this is the correct match.
87+
jit_add_target_info ("target_feature", "mte");
88+
if (TARGET_PAUTH)
89+
{
90+
jit_add_target_info ("target_feature", "paca");
91+
jit_add_target_info ("target_feature", "pacg");
92+
}
93+
if (TARGET_RNG)
94+
jit_add_target_info ("target_feature", "rand");
95+
if (TARGET_RCPC)
96+
jit_add_target_info ("target_feature", "rcpc");
97+
if (TARGET_RCPC2)
98+
jit_add_target_info ("target_feature", "rcpc2");
99+
if (TARGET_SIMD_RDMA)
100+
// TODO: check if this is the correct match.
101+
jit_add_target_info ("target_feature", "rdm");
102+
if (TARGET_SB)
103+
jit_add_target_info ("target_feature", "sb");
104+
if (TARGET_SHA2)
105+
jit_add_target_info ("target_feature", "sha2");
106+
if (TARGET_SHA3)
107+
jit_add_target_info ("target_feature", "sha3");
108+
if (TARGET_SIMD)
109+
jit_add_target_info ("target_feature", "neon");
110+
if (TARGET_SM4)
111+
jit_add_target_info ("target_feature", "sm4");
112+
if (TARGET_SVE)
113+
jit_add_target_info ("target_feature", "sve");
114+
if (TARGET_SVE2)
115+
jit_add_target_info ("target_feature", "sve2");
116+
if (TARGET_SVE2_AES)
117+
jit_add_target_info ("target_feature", "sve2-aes");
118+
if (TARGET_SVE2_BITPERM)
119+
jit_add_target_info ("target_feature", "sve2-bitperm");
120+
if (TARGET_SVE2_SHA3)
121+
jit_add_target_info ("target_feature", "sve2-sha3");
122+
if (TARGET_SVE2_SM4)
123+
jit_add_target_info ("target_feature", "sve2-sm4");
124+
if (TARGET_TME)
125+
jit_add_target_info ("target_feature", "tme");
126+
// TODO: features dit, dpb, dpb2, flagm, lor, pan, pmuv3, ras, spe, ssbs, vh
127+
128+
if (AARCH64_ISA_V8_1A)
129+
jit_add_target_info ("target_feature", "v8.1a");
130+
if (AARCH64_ISA_V8_2A)
131+
jit_add_target_info ("target_feature", "v8.2a");
132+
if (AARCH64_ISA_V8_3A)
133+
jit_add_target_info ("target_feature", "v8.3a");
134+
if (AARCH64_ISA_V8_4A)
135+
jit_add_target_info ("target_feature", "v8.4a");
136+
if (AARCH64_ISA_V8_5A)
137+
jit_add_target_info ("target_feature", "v8.5a");
138+
if (AARCH64_ISA_V8_6A)
139+
jit_add_target_info ("target_feature", "v8.6a");
140+
if (AARCH64_ISA_V8_7A)
141+
jit_add_target_info ("target_feature", "v8.7a");
142+
}

gcc/config/aarch64/aarch64-jit.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Definitions for the jit front end on the AArch64 architecture.
2+
Copyright (C) 2024 Free Software Foundation, Inc.
3+
4+
GCC is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; either version 3, or (at your option)
7+
any later version.
8+
9+
GCC is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with GCC; see the file COPYING3. If not see
16+
<http://www.gnu.org/licenses/>. */
17+
18+
/* Defined in aarch64-jit.cc */
19+
extern void aarch64_jit_register_target_info (void);
20+
21+
/* Target hooks for jit language. */
22+
#define TARGET_JIT_REGISTER_CPU_TARGET_INFO aarch64_jit_register_target_info

gcc/config/aarch64/t-aarch64

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ aarch64-d.o: $(srcdir)/config/aarch64/aarch64-d.cc
148148
$(COMPILE) $<
149149
$(POSTCOMPILE)
150150

151+
aarch64-jit.o: $(srcdir)/config/aarch64/aarch64-jit.cc
152+
$(COMPILE) $<
153+
$(POSTCOMPILE)
154+
151155
PASSES_EXTRA += $(srcdir)/config/aarch64/aarch64-passes.def
152156

153157
cortex-a57-fma-steering.o: $(srcdir)/config/aarch64/cortex-a57-fma-steering.cc \

0 commit comments

Comments
 (0)