7 Generate the tests in llvm/test/CodeGen/AArch64/Atomics. Run from top level llvm-project.
17 class Type(enum
.Enum
):
18 # Value is the size in bytes
25 def align(self
, aligned
: bool) -> int:
26 return self
.value
if aligned
else 1
28 def __str__(self
) -> str:
32 # Is this an aligned or unaligned access?
33 class Aligned(enum
.Enum
):
37 def __str__(self
) -> str:
40 def __bool__(self
) -> bool:
44 class AtomicOrder(enum
.Enum
):
53 def __str__(self
) -> str:
58 AtomicOrder
.monotonic
,
65 ATOMIC_LOAD_ORDERS
= [
66 AtomicOrder
.unordered
,
67 AtomicOrder
.monotonic
,
72 ATOMIC_STORE_ORDERS
= [
73 AtomicOrder
.unordered
,
74 AtomicOrder
.monotonic
,
79 ATOMIC_FENCE_ORDERS
= [
86 CMPXCHG_SUCCESS_ORDERS
= [
87 AtomicOrder
.monotonic
,
94 CMPXCHG_FAILURE_ORDERS
= [
95 AtomicOrder
.monotonic
,
108 class Feature(enum
.Flag
):
109 # Feature names in filenames are determined by the spelling here:
111 v8_1a
= enum
.auto() # -mattr=+v8.1a, mandatory FEAT_LOR, FEAT_LSE
112 rcpc
= enum
.auto() # FEAT_LRCPC
113 lse2
= enum
.auto() # FEAT_LSE2
114 outline_atomics
= enum
.auto() # -moutline-atomics
115 rcpc3
= enum
.auto() # FEAT_LSE2 + FEAT_LRCPC3
116 lse2_lse128
= enum
.auto() # FEAT_LSE2 + FEAT_LSE128
120 if self
== Feature
.outline_atomics
:
121 return "+outline-atomics"
122 if self
== Feature
.v8_1a
:
124 if self
== Feature
.rcpc3
:
125 return "+lse2,+rcpc3"
126 if self
== Feature
.lse2_lse128
:
127 return "+lse2,+lse128"
128 return "+" + self
.name
146 def all_atomicrmw(f
):
147 for op
in ATOMICRMW_OPS
:
148 for aligned
in Aligned
:
150 for ordering
in ATOMICRMW_ORDERS
:
151 name
= f
"atomicrmw_{op}_{ty}_{aligned}_{ordering}"
156 define dso_local {ty} @{name}(ptr %ptr, {ty} %value) {{
157 %r = {instr} {op} ptr %ptr, {ty} %value {ordering}, align {ty.align(aligned)}
166 for aligned
in Aligned
:
168 for ordering
in ATOMIC_LOAD_ORDERS
:
169 for const
in [False, True]:
170 name
= f
"load_atomic_{ty}_{aligned}_{ordering}"
171 instr
= "load atomic"
174 arg
= "ptr readonly %ptr" if const
else "ptr %ptr"
178 define dso_local {ty} @{name}({arg}) {{
179 %r = {instr} {ty}, ptr %ptr {ordering}, align {ty.align(aligned)}
188 for aligned
in Aligned
:
190 for ordering
in ATOMIC_STORE_ORDERS
: # FIXME stores
191 name
= f
"store_atomic_{ty}_{aligned}_{ordering}"
192 instr
= "store atomic"
196 define dso_local void @{name}({ty} %value, ptr %ptr) {{
197 {instr} {ty} %value, ptr %ptr {ordering}, align {ty.align(aligned)}
206 for aligned
in Aligned
:
208 for success_ordering
in CMPXCHG_SUCCESS_ORDERS
:
209 for failure_ordering
in CMPXCHG_FAILURE_ORDERS
:
210 for weak
in [False, True]:
211 name
= f
"cmpxchg_{ty}_{aligned}_{success_ordering}_{failure_ordering}"
219 define dso_local {ty} @{name}({ty} %expected, {ty} %new, ptr %ptr) {{
220 %pair = {instr} ptr %ptr, {ty} %expected, {ty} %new {success_ordering} {failure_ordering}, align {ty.align(aligned)}
221 %r = extractvalue {{ {ty}, i1 }} %pair, 0
230 for ordering
in FENCE_ORDERS
:
231 name
= f
"fence_{ordering}"
235 define dso_local void @{name}() {{
244 def header(f
, triple
, features
, filter_args
: str):
246 "; NOTE: Assertions have been autogenerated by "
247 "utils/update_llc_test_checks.py UTC_ARGS: "
251 f
.write(f
"; The base test file was generated by {__file__}\n")
252 for feat
in features
:
253 for OptFlag
in ["-O0", "-O1"]:
263 "-verify-machineinstrs",
264 f
"-mtriple={triple}",
265 f
"-mattr={feat.mattr}",
270 f
"--check-prefixes=CHECK,{OptFlag}\n",
276 def write_lit_tests():
277 os
.chdir("llvm/test/CodeGen/AArch64/Atomics/")
278 for triple
in TRIPLES
:
279 # Feature has no effect on fence, so keep it to one file.
280 with
open(f
"{triple}-fence.ll", "w") as f
:
281 filter_args
= r
'--filter "^\s*(dmb)"'
282 header(f
, triple
, Feature
, filter_args
)
286 with
open(f
"{triple}-atomicrmw-{feat.name}.ll", "w") as f
:
287 filter_args
= r
'--filter-out "\b(sp)\b" --filter "^\s*(ld[^r]|st[^r]|swp|cas|bl|add|and|eor|orn|orr|sub|mvn|sxt|cmp|ccmp|csel|dmb)"'
288 header(f
, triple
, [feat
], filter_args
)
291 with
open(f
"{triple}-cmpxchg-{feat.name}.ll", "w") as f
:
292 filter_args
= r
'--filter-out "\b(sp)\b" --filter "^\s*(ld[^r]|st[^r]|swp|cas|bl|add|and|eor|orn|orr|sub|mvn|sxt|cmp|ccmp|csel|dmb)"'
293 header(f
, triple
, [feat
], filter_args
)
296 with
open(f
"{triple}-atomic-load-{feat.name}.ll", "w") as f
:
297 filter_args
= r
'--filter-out "\b(sp)\b" --filter "^\s*(ld|st[^r]|swp|cas|bl|add|and|eor|orn|orr|sub|mvn|sxt|cmp|ccmp|csel|dmb)"'
298 header(f
, triple
, [feat
], filter_args
)
301 with
open(f
"{triple}-atomic-store-{feat.name}.ll", "w") as f
:
302 filter_args
= r
'--filter-out "\b(sp)\b" --filter "^\s*(ld[^r]|st|swp|cas|bl|add|and|eor|orn|orr|sub|mvn|sxt|cmp|ccmp|csel|dmb)"'
303 header(f
, triple
, [feat
], filter_args
)
307 if __name__
== "__main__":
313 Testcases written. To update checks run:
314 $ ./llvm/utils/update_llc_test_checks.py -u llvm/test/CodeGen/AArch64/Atomics/*.ll
317 $ parallel ./llvm/utils/update_llc_test_checks.py -u ::: llvm/test/CodeGen/AArch64/Atomics/*.ll