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=nvptx64 -mcpu=sm_30 | FileCheck -check-prefixes=CHECK,CHECK_P64 %t.ll
6 # RUN: llc < %t.ll -march=nvptx -mcpu=sm_30 | FileCheck -check-prefixes=CHECK,CHECK_P32 %t.ll
8 from __future__
import print_function
10 from itertools
import product
11 from string
import Template
13 llvm_type_to_ptx_type
= {
24 llvm_type_to_ptx_reg
= {
47 define ${type} @ld${_volatile}${_space}.${ptx_type}(${type} addrspace(${asid})* %ptr) {
48 ; CHECK_P32: ld${_volatile}${_volatile_as}.${ptx_type} %${ptx_reg}{{[0-9]+}}, [%r{{[0-9]+}}]
49 ; CHECK_P64: ld${_volatile}${_volatile_as}.${ptx_type} %${ptx_reg}{{[0-9]+}}, [%rd{{[0-9]+}}]
52 %a = load ${volatile} ${type}, ${type}* %p
56 for op_type
, volatile
, space
in product(
57 ["i8", "i16", "i32", "i64", "half", "float", "double", "<2 x half>"],
58 [True, False], # volatile
59 ["", ".shared", ".global", ".const", ".local", ".param"]):
61 # Volatile is only supported for global, shared and generic.
62 if volatile
and not space
in ["", ".global", ".shared"]:
65 # Volatile is only supported for global, shared and generic.
66 # All other volatile accesses are done in generic AS.
67 if volatile
and not space
in ["", ".global", ".shared"]:
74 "volatile": "volatile" if volatile
else "",
75 "_volatile": ".volatile" if volatile
else "",
76 "_volatile_as": volatile_as
,
78 "ptx_reg": llvm_type_to_ptx_reg
[op_type
],
79 "ptx_type": llvm_type_to_ptx_type
[op_type
],
80 "asid": addrspace_id
[space
],
83 # LLVM does not accept "addrspacecast Type* addrspace(0) to Type*", so we
84 # need to avoid it for generic pointer tests.
86 generic_ptr_template
= ("addrspacecast ${type} addrspace(${asid})* %ptr "
89 generic_ptr_template
= "select i1 true, ${type}* %ptr, ${type}* %ptr"
90 params
["generic_ptr"] = Template(generic_ptr_template
).substitute(params
)
92 print(Template(load_template
).substitute(params
))