1 # This test generates all variants of load/store instructions and verifies that
2 # LLVM generates correct PTX for them.
4 # RUN: %python %s > %t.ll
5 # RUN: llc < %t.ll -march=nvptx -mcpu=sm_30 | FileCheck -check-prefixes=CHECK,CHECK_P32 %t.ll
6 # RUN: llc < %t.ll -march=nvptx64 -mcpu=sm_30 | FileCheck -check-prefixes=CHECK,CHECK_P64 %t.ll
7 # RUN: %if ptxas && !ptxas-12.0 %{ llc < %t.ll -march=nvptx -mcpu=sm_30 | %ptxas-verify %}
8 # RUN: %if ptxas %{ llc < %t.ll -march=nvptx64 -mcpu=sm_30 | %ptxas-verify %}
10 from __future__
import print_function
12 from itertools
import product
13 from string
import Template
15 llvm_type_to_ptx_type
= {
26 llvm_type_to_ptx_reg
= {
49 define ${type} @${testname}(${type} addrspace(${asid})* %ptr) {
51 ; CHECK_P32: ld${_volatile}${_volatile_as}.${ptx_type} %${ptx_reg}{{[0-9]+}}, [%r{{[0-9]+}}]
52 ; CHECK_P64: ld${_volatile}${_volatile_as}.${ptx_type} %${ptx_reg}{{[0-9]+}}, [%rd{{[0-9]+}}]
55 %a = load ${volatile} ${type}, ${type}* %p
59 for op_type
, volatile
, space
in product(
60 ["i8", "i16", "i32", "i64", "half", "float", "double", "<2 x half>"],
61 [True, False], # volatile
62 ["", ".shared", ".global", ".const", ".local", ".param"],
65 # Volatile is only supported for global, shared and generic.
66 if volatile
and not space
in ["", ".global", ".shared"]:
69 # Volatile is only supported for global, shared and generic.
70 # All other volatile accesses are done in generic AS.
71 if volatile
and not space
in ["", ".global", ".shared"]:
78 "volatile": "volatile" if volatile
else "",
79 "_volatile": ".volatile" if volatile
else "",
80 "_volatile_as": volatile_as
,
82 "ptx_reg": llvm_type_to_ptx_reg
[op_type
],
83 "ptx_type": llvm_type_to_ptx_type
[op_type
],
84 "asid": addrspace_id
[space
],
87 testname
= Template("ld_${_volatile}${_space}.${ptx_type}").substitute(params
)
88 params
["testname"] = testname
.replace(".", "_")
90 # LLVM does not accept "addrspacecast Type* addrspace(0) to Type*", so we
91 # need to avoid it for generic pointer tests.
93 generic_ptr_template
= (
94 "addrspacecast ${type} addrspace(${asid})* %ptr " "to ${type}*"
97 generic_ptr_template
= "select i1 true, ${type}* %ptr, ${type}* %ptr"
98 params
["generic_ptr"] = Template(generic_ptr_template
).substitute(params
)
100 print(Template(load_template
).substitute(params
))