Skip to content

Commit a54f47f

Browse files
committed
[RFC][RISCV] Support RISC-V Profiles in -march option
This PR implements the draft riscv-non-isa/riscv-toolchain-conventions#36. Currently, we replace specified profile in `-march` with standard arch string.
1 parent ff66e9b commit a54f47f

File tree

7 files changed

+641
-0
lines changed

7 files changed

+641
-0
lines changed

clang/test/Driver/riscv-profiles.c

Lines changed: 324 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,324 @@
1+
// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck -check-prefix=RVI20U32 %s
2+
// RVI20U32: "-target-feature" "-a"
3+
// RVI20U32: "-target-feature" "-c"
4+
// RVI20U32: "-target-feature" "-d"
5+
// RVI20U32: "-target-feature" "-f"
6+
// RVI20U32: "-target-feature" "-m"
7+
// RVI20U32: "-target-feature" "+rvi20u32"
8+
9+
// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck -check-prefix=RVI20U64 %s
10+
// RVI20U64: "-target-feature" "-a"
11+
// RVI20U64: "-target-feature" "-c"
12+
// RVI20U64: "-target-feature" "-d"
13+
// RVI20U64: "-target-feature" "-f"
14+
// RVI20U64: "-target-feature" "-m"
15+
// RVI20U64: "-target-feature" "+rvi20u64"
16+
17+
// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck -check-prefix=RVA20U64 %s
18+
// RVA20U64: "-target-feature" "+m"
19+
// RVA20U64: "-target-feature" "+a"
20+
// RVA20U64: "-target-feature" "+f"
21+
// RVA20U64: "-target-feature" "+d"
22+
// RVA20U64: "-target-feature" "+c"
23+
// RVA20U64: "-target-feature" "+ziccamoa"
24+
// RVA20U64: "-target-feature" "+ziccif"
25+
// RVA20U64: "-target-feature" "+zicclsm"
26+
// RVA20U64: "-target-feature" "+ziccrse"
27+
// RVA20U64: "-target-feature" "+zicntr"
28+
// RVA20U64: "-target-feature" "+zicsr"
29+
// RVA20U64: "-target-feature" "+za128rs"
30+
// RVA20U64: "-target-feature" "+rva20u64"
31+
32+
// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck -check-prefix=RVA20S64 %s
33+
// RVA20S64: "-target-feature" "+m"
34+
// RVA20S64: "-target-feature" "+a"
35+
// RVA20S64: "-target-feature" "+f"
36+
// RVA20S64: "-target-feature" "+d"
37+
// RVA20S64: "-target-feature" "+c"
38+
// RVA20S64: "-target-feature" "+ziccamoa"
39+
// RVA20S64: "-target-feature" "+ziccif"
40+
// RVA20S64: "-target-feature" "+zicclsm"
41+
// RVA20S64: "-target-feature" "+ziccrse"
42+
// RVA20S64: "-target-feature" "+zicntr"
43+
// RVA20S64: "-target-feature" "+zicsr"
44+
// RVA20S64: "-target-feature" "+zifencei"
45+
// RVA20S64: "-target-feature" "+za128rs"
46+
// RVA20S64: "-target-feature" "+ssccptr"
47+
// RVA20S64: "-target-feature" "+sstvala"
48+
// RVA20S64: "-target-feature" "+sstvecd"
49+
// RVA20S64: "-target-feature" "+svade"
50+
// RVA20S64: "-target-feature" "+svbare"
51+
// RVA20S64: "-target-feature" "+rva20s64"
52+
53+
// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck -check-prefix=RVA22U64 %s
54+
// RVA22U64: "-target-feature" "+m"
55+
// RVA22U64: "-target-feature" "+a"
56+
// RVA22U64: "-target-feature" "+f"
57+
// RVA22U64: "-target-feature" "+d"
58+
// RVA22U64: "-target-feature" "+c"
59+
// RVA22U64: "-target-feature" "+zic64b"
60+
// RVA22U64: "-target-feature" "+zicbom"
61+
// RVA22U64: "-target-feature" "+zicbop"
62+
// RVA22U64: "-target-feature" "+zicboz"
63+
// RVA22U64: "-target-feature" "+ziccamoa"
64+
// RVA22U64: "-target-feature" "+ziccif"
65+
// RVA22U64: "-target-feature" "+zicclsm"
66+
// RVA22U64: "-target-feature" "+ziccrse"
67+
// RVA22U64: "-target-feature" "+zicntr"
68+
// RVA22U64: "-target-feature" "+zicsr"
69+
// RVA22U64: "-target-feature" "+zihintpause"
70+
// RVA22U64: "-target-feature" "+zihpm"
71+
// RVA22U64: "-target-feature" "+za64rs"
72+
// RVA22U64: "-target-feature" "+zfhmin"
73+
// RVA22U64: "-target-feature" "+zba"
74+
// RVA22U64: "-target-feature" "+zbb"
75+
// RVA22U64: "-target-feature" "+zbs"
76+
// RVA22U64: "-target-feature" "+zkt"
77+
// RVA22U64: "-target-feature" "+rva22u64"
78+
79+
// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck -check-prefix=RVA22S64 %s
80+
// RVA22S64: "-target-feature" "+m"
81+
// RVA22S64: "-target-feature" "+a"
82+
// RVA22S64: "-target-feature" "+f"
83+
// RVA22S64: "-target-feature" "+d"
84+
// RVA22S64: "-target-feature" "+c"
85+
// RVA22S64: "-target-feature" "+zic64b"
86+
// RVA22S64: "-target-feature" "+zicbom"
87+
// RVA22S64: "-target-feature" "+zicbop"
88+
// RVA22S64: "-target-feature" "+zicboz"
89+
// RVA22S64: "-target-feature" "+ziccamoa"
90+
// RVA22S64: "-target-feature" "+ziccif"
91+
// RVA22S64: "-target-feature" "+zicclsm"
92+
// RVA22S64: "-target-feature" "+ziccrse"
93+
// RVA22S64: "-target-feature" "+zicntr"
94+
// RVA22S64: "-target-feature" "+zicsr"
95+
// RVA22S64: "-target-feature" "+zifencei"
96+
// RVA22S64: "-target-feature" "+zihintpause"
97+
// RVA22S64: "-target-feature" "+zihpm"
98+
// RVA22S64: "-target-feature" "+za64rs"
99+
// RVA22S64: "-target-feature" "+zfhmin"
100+
// RVA22S64: "-target-feature" "+zba"
101+
// RVA22S64: "-target-feature" "+zbb"
102+
// RVA22S64: "-target-feature" "+zbs"
103+
// RVA22S64: "-target-feature" "+zkt"
104+
// RVA22S64: "-target-feature" "+ssccptr"
105+
// RVA22S64: "-target-feature" "+sscounterenw"
106+
// RVA22S64: "-target-feature" "+sstvala"
107+
// RVA22S64: "-target-feature" "+sstvecd"
108+
// RVA22S64: "-target-feature" "+svade"
109+
// RVA22S64: "-target-feature" "+svbare"
110+
// RVA22S64: "-target-feature" "+svinval"
111+
// RVA22S64: "-target-feature" "+svpbmt"
112+
// RVA22S64: "-target-feature" "+rva22s64"
113+
114+
// RUN: %clang -### -c %s 2>&1 -march=rva23u64 -menable-experimental-extensions | FileCheck -check-prefix=RVA23U64 %s
115+
// RVA23U64: "-target-feature" "+m"
116+
// RVA23U64: "-target-feature" "+a"
117+
// RVA23U64: "-target-feature" "+f"
118+
// RVA23U64: "-target-feature" "+d"
119+
// RVA23U64: "-target-feature" "+c"
120+
// RVA23U64: "-target-feature" "+v"
121+
// RVA23U64: "-target-feature" "+zic64b"
122+
// RVA23U64: "-target-feature" "+zicbom"
123+
// RVA23U64: "-target-feature" "+zicbop"
124+
// RVA23U64: "-target-feature" "+zicboz"
125+
// RVA23U64: "-target-feature" "+ziccamoa"
126+
// RVA23U64: "-target-feature" "+ziccif"
127+
// RVA23U64: "-target-feature" "+zicclsm"
128+
// RVA23U64: "-target-feature" "+ziccrse"
129+
// RVA23U64: "-target-feature" "+zicntr"
130+
// RVA23U64: "-target-feature" "+zicond"
131+
// RVA23U64: "-target-feature" "+zicsr"
132+
// RVA23U64: "-target-feature" "+zihintntl"
133+
// RVA23U64: "-target-feature" "+zihintpause"
134+
// RVA23U64: "-target-feature" "+zihpm"
135+
// RVA23U64: "-target-feature" "+experimental-zimop"
136+
// RVA23U64: "-target-feature" "+za64rs"
137+
// RVA23U64: "-target-feature" "+zawrs"
138+
// RVA23U64: "-target-feature" "+zfa"
139+
// RVA23U64: "-target-feature" "+zfhmin"
140+
// RVA23U64: "-target-feature" "+zcb"
141+
// RVA23U64: "-target-feature" "+experimental-zcmop"
142+
// RVA23U64: "-target-feature" "+zba"
143+
// RVA23U64: "-target-feature" "+zbb"
144+
// RVA23U64: "-target-feature" "+zbs"
145+
// RVA23U64: "-target-feature" "+zkt"
146+
// RVA23U64: "-target-feature" "+zvbb"
147+
// RVA23U64: "-target-feature" "+zvfhmin"
148+
// RVA23U64: "-target-feature" "+zvkt"
149+
// RVA23U64: "-target-feature" "+rva23u64"
150+
151+
// RUN: %clang -### -c %s 2>&1 -march=rva23s64 -menable-experimental-extensions | FileCheck -check-prefix=RVA23S64 %s
152+
// RVA23S64: "-target-feature" "+m"
153+
// RVA23S64: "-target-feature" "+a"
154+
// RVA23S64: "-target-feature" "+f"
155+
// RVA23S64: "-target-feature" "+d"
156+
// RVA23S64: "-target-feature" "+c"
157+
// RVA23S64: "-target-feature" "+v"
158+
// RVA23S64: "-target-feature" "+h"
159+
// RVA23S64: "-target-feature" "+zic64b"
160+
// RVA23S64: "-target-feature" "+zicbom"
161+
// RVA23S64: "-target-feature" "+zicbop"
162+
// RVA23S64: "-target-feature" "+zicboz"
163+
// RVA23S64: "-target-feature" "+ziccamoa"
164+
// RVA23S64: "-target-feature" "+ziccif"
165+
// RVA23S64: "-target-feature" "+zicclsm"
166+
// RVA23S64: "-target-feature" "+ziccrse"
167+
// RVA23S64: "-target-feature" "+zicntr"
168+
// RVA23S64: "-target-feature" "+zicond"
169+
// RVA23S64: "-target-feature" "+zicsr"
170+
// RVA23S64: "-target-feature" "+zifencei"
171+
// RVA23S64: "-target-feature" "+zihintntl"
172+
// RVA23S64: "-target-feature" "+zihintpause"
173+
// RVA23S64: "-target-feature" "+zihpm"
174+
// RVA23S64: "-target-feature" "+experimental-zimop"
175+
// RVA23S64: "-target-feature" "+za64rs"
176+
// RVA23S64: "-target-feature" "+zawrs"
177+
// RVA23S64: "-target-feature" "+zfa"
178+
// RVA23S64: "-target-feature" "+zfhmin"
179+
// RVA23S64: "-target-feature" "+zcb"
180+
// RVA23S64: "-target-feature" "+experimental-zcmop"
181+
// RVA23S64: "-target-feature" "+zba"
182+
// RVA23S64: "-target-feature" "+zbb"
183+
// RVA23S64: "-target-feature" "+zbs"
184+
// RVA23S64: "-target-feature" "+zkt"
185+
// RVA23S64: "-target-feature" "+zvbb"
186+
// RVA23S64: "-target-feature" "+zvfhmin"
187+
// RVA23S64: "-target-feature" "+zvkt"
188+
// RVA23S64: "-target-feature" "+shcounterenw"
189+
// RVA23S64: "-target-feature" "+shgatpa"
190+
// RVA23S64: "-target-feature" "+shtvala"
191+
// RVA23S64: "-target-feature" "+shvsatpa"
192+
// RVA23S64: "-target-feature" "+shvstvala"
193+
// RVA23S64: "-target-feature" "+shvstvecd"
194+
// RVA23S64: "-target-feature" "+ssccptr"
195+
// RVA23S64: "-target-feature" "+sscofpmf"
196+
// RVA23S64: "-target-feature" "+sscounterenw"
197+
// RVA23S64: "-target-feature" "+experimental-ssnpm"
198+
// RVA23S64: "-target-feature" "+ssstateen"
199+
// RVA23S64: "-target-feature" "+sstc"
200+
// RVA23S64: "-target-feature" "+sstvala"
201+
// RVA23S64: "-target-feature" "+sstvecd"
202+
// RVA23S64: "-target-feature" "+ssu64xl"
203+
// RVA23S64: "-target-feature" "+svade"
204+
// RVA23S64: "-target-feature" "+svbare"
205+
// RVA23S64: "-target-feature" "+svinval"
206+
// RVA23S64: "-target-feature" "+svnapot"
207+
// RVA23S64: "-target-feature" "+svpbmt"
208+
// RVA23S64: "-target-feature" "+rva23s64"
209+
210+
// RUN: %clang -### -c %s 2>&1 -march=rvb23u64 -menable-experimental-extensions | FileCheck -check-prefix=RVB23U64 %s
211+
// RVB23U64: "-target-feature" "+m"
212+
// RVB23U64: "-target-feature" "+a"
213+
// RVB23U64: "-target-feature" "+f"
214+
// RVB23U64: "-target-feature" "+d"
215+
// RVB23U64: "-target-feature" "+c"
216+
// RVB23U64: "-target-feature" "+zic64b"
217+
// RVB23U64: "-target-feature" "+zicbom"
218+
// RVB23U64: "-target-feature" "+zicbop"
219+
// RVB23U64: "-target-feature" "+zicboz"
220+
// RVB23U64: "-target-feature" "+ziccamoa"
221+
// RVB23U64: "-target-feature" "+ziccif"
222+
// RVB23U64: "-target-feature" "+zicclsm"
223+
// RVB23U64: "-target-feature" "+ziccrse"
224+
// RVB23U64: "-target-feature" "+zicntr"
225+
// RVB23U64: "-target-feature" "+zicond"
226+
// RVB23U64: "-target-feature" "+zicsr"
227+
// RVB23U64: "-target-feature" "+zihintntl"
228+
// RVB23U64: "-target-feature" "+zihintpause"
229+
// RVB23U64: "-target-feature" "+zihpm"
230+
// RVB23U64: "-target-feature" "+experimental-zimop"
231+
// RVB23U64: "-target-feature" "+za64rs"
232+
// RVB23U64: "-target-feature" "+zawrs"
233+
// RVB23U64: "-target-feature" "+zfa"
234+
// RVB23U64: "-target-feature" "+zcb"
235+
// RVB23U64: "-target-feature" "+experimental-zcmop"
236+
// RVB23U64: "-target-feature" "+zba"
237+
// RVB23U64: "-target-feature" "+zbb"
238+
// RVB23U64: "-target-feature" "+zbs"
239+
// RVB23U64: "-target-feature" "+zkt"
240+
// RVB23U64: "-target-feature" "+rvb23u64"
241+
242+
// RUN: %clang -### -c %s 2>&1 -march=rvb23s64 -menable-experimental-extensions | FileCheck -check-prefix=RVB23S64 %s
243+
// RVB23S64: "-target-feature" "+m"
244+
// RVB23S64: "-target-feature" "+a"
245+
// RVB23S64: "-target-feature" "+f"
246+
// RVB23S64: "-target-feature" "+d"
247+
// RVB23S64: "-target-feature" "+c"
248+
// RVB23S64: "-target-feature" "+zic64b"
249+
// RVB23S64: "-target-feature" "+zicbom"
250+
// RVB23S64: "-target-feature" "+zicbop"
251+
// RVB23S64: "-target-feature" "+zicboz"
252+
// RVB23S64: "-target-feature" "+ziccamoa"
253+
// RVB23S64: "-target-feature" "+ziccif"
254+
// RVB23S64: "-target-feature" "+zicclsm"
255+
// RVB23S64: "-target-feature" "+ziccrse"
256+
// RVB23S64: "-target-feature" "+zicntr"
257+
// RVB23S64: "-target-feature" "+zicond"
258+
// RVB23S64: "-target-feature" "+zicsr"
259+
// RVB23S64: "-target-feature" "+zifencei"
260+
// RVB23S64: "-target-feature" "+zihintntl"
261+
// RVB23S64: "-target-feature" "+zihintpause"
262+
// RVB23S64: "-target-feature" "+zihpm"
263+
// RVB23S64: "-target-feature" "+experimental-zimop"
264+
// RVB23S64: "-target-feature" "+za64rs"
265+
// RVB23S64: "-target-feature" "+zawrs"
266+
// RVB23S64: "-target-feature" "+zfa"
267+
// RVB23S64: "-target-feature" "+zcb"
268+
// RVB23S64: "-target-feature" "+experimental-zcmop"
269+
// RVB23S64: "-target-feature" "+zba"
270+
// RVB23S64: "-target-feature" "+zbb"
271+
// RVB23S64: "-target-feature" "+zbs"
272+
// RVB23S64: "-target-feature" "+zkt"
273+
// RVB23S64: "-target-feature" "+ssccptr"
274+
// RVB23S64: "-target-feature" "+sscofpmf"
275+
// RVB23S64: "-target-feature" "+sscounterenw"
276+
// RVB23S64: "-target-feature" "+sstc"
277+
// RVB23S64: "-target-feature" "+sstvala"
278+
// RVB23S64: "-target-feature" "+sstvecd"
279+
// RVB23S64: "-target-feature" "+ssu64xl"
280+
// RVB23S64: "-target-feature" "+svade"
281+
// RVB23S64: "-target-feature" "+svbare"
282+
// RVB23S64: "-target-feature" "+svinval"
283+
// RVB23S64: "-target-feature" "+svnapot"
284+
// RVB23S64: "-target-feature" "+svpbmt"
285+
// RVB23S64: "-target-feature" "+rvb23s64"
286+
287+
// RUN: %clang -### -c %s 2>&1 -march=rvm23u32 -menable-experimental-extensions | FileCheck -check-prefix=RVM23U32 %s
288+
// RVM23U32: "-target-feature" "+m"
289+
// RVM23U32: "-target-feature" "+zicbop"
290+
// RVM23U32: "-target-feature" "+zicond"
291+
// RVM23U32: "-target-feature" "+zicsr"
292+
// RVM23U32: "-target-feature" "+zihintntl"
293+
// RVM23U32: "-target-feature" "+zihintpause"
294+
// RVM23U32: "-target-feature" "+experimental-zimop"
295+
// RVM23U32: "-target-feature" "+zce"
296+
// RVM23U32: "-target-feature" "+experimental-zcmop"
297+
// RVM23U32: "-target-feature" "+zba"
298+
// RVM23U32: "-target-feature" "+zbb"
299+
// RVM23U32: "-target-feature" "+zbs"
300+
// RVM23U32: "-target-feature" "+rvm23u32"
301+
302+
// RUN: %clang -### -c %s 2>&1 -march=rva22u64_zfa | FileCheck -check-prefix=PROFILE-WITH-ADDITIONAL %s
303+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+m"
304+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+a"
305+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+f"
306+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+d"
307+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+c"
308+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zicbom"
309+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zicbop"
310+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zicboz"
311+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zihintpause"
312+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zfa"
313+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zfhmin"
314+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zba"
315+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zbb"
316+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zbs"
317+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zkt"
318+
// PROFILE-WITH-ADDITIONAL: "-target-feature" "+rva22u64"
319+
320+
// RUN: not %clang -### -c %s 2>&1 -march=rva19u64_zfa | FileCheck -check-prefix=INVALID-PROFILE %s
321+
// INVALID-PROFILE: error: invalid arch name 'rva19u64_zfa', unsupported profile
322+
323+
// RUN: not %clang -### -c %s 2>&1 -march=rva22u64zfa | FileCheck -check-prefix=INVALID-ADDITIONAL %s
324+
// INVALID-ADDITIONAL: error: invalid arch name 'rva22u64zfa', additional extensions must be after separator '_'

llvm/include/llvm/Support/RISCVISAInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class RISCVISAInfo {
8080
unsigned getMaxVLen() const { return 65536; }
8181
unsigned getMaxELen() const { return MaxELen; }
8282
unsigned getMaxELenFp() const { return MaxELenFp; }
83+
StringRef getProfile() const { return Profile; }
8384

8485
bool hasExtension(StringRef Ext) const;
8586
std::string toString() const;
@@ -102,6 +103,7 @@ class RISCVISAInfo {
102103
unsigned FLen;
103104
unsigned MinVLen;
104105
unsigned MaxELen, MaxELenFp;
106+
std::string Profile;
105107

106108
OrderedExtensionMap Exts;
107109

0 commit comments

Comments
 (0)