Skip to content

Commit 0e345f3

Browse files
frasercrmckjsji
authored andcommitted
[NVPTX] Restore patterns for some atomic intrinsics
This commit adds back support for NVPTX NVVM intrinsics with semantics and address spaces, notably excluding those for ld/st: * add, and, or, xor, exch, min, max, inc, dec, cas. Support for ld/st will follow. This change was dropped during the pulldown.
1 parent 9e9082c commit 0e345f3

File tree

1 file changed

+60
-12
lines changed

1 file changed

+60
-12
lines changed

llvm/lib/Target/NVPTX/NVPTXIntrinsics.td

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,29 +2131,33 @@ defm INT_PTX_ATOM_CAS_16 : F_ATOMIC_3_AS<I16RT, atomic_cmp_swap_i16, "", "cas.b1
21312131

21322132
// Constructs intrinsic name and instruction asm strings.
21332133
multiclass ATOM2N_impl<string OpStr, string IntTypeStr, string TypeStr,
2134-
string ScopeStr, string SpaceStr,
2134+
string ScopeStr, string SpaceStr, string SemStr,
21352135
RegTyInfo t, list<Predicate> Preds> {
21362136
defm "" : F_ATOMIC_2<t,
2137-
as_str = !if(!eq(ScopeStr, "gpu"), "", "." # ScopeStr),
2137+
as_str = !if(!empty(SemStr), "", "." # SemStr)
2138+
# !if(!eq(ScopeStr, "gpu"), "", "." # ScopeStr),
21382139
sem_str = !if(!eq(SpaceStr, "gen"), "", "." # SpaceStr),
21392140
op_str = OpStr # "." # TypeStr,
21402141
op = !cast<Intrinsic>(
21412142
"int_nvvm_atomic_" # OpStr
21422143
# "_" # SpaceStr # "_" # IntTypeStr
2143-
# !if(!empty(ScopeStr), "", "_" # ScopeStr)),
2144+
# !if(!empty(SemStr), "", "_" # SemStr)
2145+
# !if(!eq(ScopeStr, "gpu"), "", "_" # ScopeStr)),
21442146
preds = Preds>;
21452147
}
21462148
multiclass ATOM3N_impl<string OpStr, string IntTypeStr, string TypeStr,
2147-
string ScopeStr, string SpaceStr,
2149+
string ScopeStr, string SpaceStr, string SemStr,
21482150
RegTyInfo t, list<Predicate> Preds> {
21492151
defm "" : F_ATOMIC_3<t,
2150-
as_str = !if(!eq(SpaceStr, "gen"), "", "." # SpaceStr),
2152+
as_str = !if(!empty(SemStr), "", "." # SemStr)
2153+
# !if(!eq(SpaceStr, "gen"), "", "." # SpaceStr),
21512154
sem_str = !if(!eq(ScopeStr, "gpu"), "", "." # ScopeStr),
21522155
op_str = OpStr # "." # TypeStr,
21532156
op = !cast<Intrinsic>(
21542157
"int_nvvm_atomic_" # OpStr
21552158
# "_" # SpaceStr # "_" # IntTypeStr
2156-
# !if(!empty(ScopeStr), "", "_" # ScopeStr)),
2159+
# !if(!empty(SemStr), "", "_" # SemStr)
2160+
# !if(!eq(ScopeStr, "gpu"), "", "_" # ScopeStr)),
21572161
preds = Preds>;
21582162
}
21592163

@@ -2162,24 +2166,67 @@ multiclass ATOM2S_impl<string OpStr, string IntTypeStr, string TypeStr,
21622166
// .gpu scope is default and is currently covered by existing
21632167
// atomics w/o explicitly specified scope.
21642168
foreach scope = ["cta", "sys"] in {
2165-
// For now we only need variants for generic space pointers.
2166-
foreach space = ["gen"] in {
2167-
defm _#scope#space : ATOM2N_impl<OpStr, IntTypeStr, TypeStr, scope, space,
2169+
foreach space = ["gen", "global", "shared"] in {
2170+
defm _#scope#space : ATOM2N_impl<OpStr, IntTypeStr, TypeStr, scope, space, "",
21682171
t, !listconcat(Preds, [hasAtomScope])>;
21692172
}
21702173
}
2174+
2175+
// .gpu scope is default as is "gen" space. Add unscoped intrinsics with
2176+
// explicit address spaces.
2177+
foreach scope = ["gpu"] in {
2178+
foreach space = ["gen", "global", "shared"] in {
2179+
defm _#scope#space : ATOM2N_impl<OpStr, IntTypeStr, TypeStr, scope, space,
2180+
"", t, Preds>;
2181+
}
2182+
}
2183+
2184+
// Intrinsics with semantics, in all scopes and address spaces. Note the
2185+
// separate predicates which keep these loops apart.
2186+
foreach sem = ["acquire", "release", "acq_rel"] in {
2187+
foreach scope = ["gpu", "cta", "sys"] in {
2188+
// For now we only need variants for generic space pointers.
2189+
foreach space = ["gen", "global", "shared"] in {
2190+
defm _#sem#scope#space :
2191+
ATOM2N_impl<OpStr, IntTypeStr, TypeStr, scope, space, sem,
2192+
t, !listconcat(Preds, [hasAtomScope, hasAtomSemantics])>;
2193+
}
2194+
}
2195+
}
21712196
}
2197+
21722198
multiclass ATOM3S_impl<string OpStr, string IntTypeStr, string TypeStr,
21732199
RegTyInfo t, list<Predicate> Preds> {
21742200
// No need to define ".gpu"-scoped atomics. They do the same thing
21752201
// as the regular, non-scoped atomics defined elsewhere.
21762202
foreach scope = ["cta", "sys"] in {
2177-
// For now we only need variants for generic space pointers.
2178-
foreach space = ["gen"] in {
2179-
defm _#scope#space : ATOM3N_impl<OpStr, IntTypeStr, TypeStr, scope, space,
2203+
foreach space = ["gen", "global", "shared"] in {
2204+
defm _#scope#space : ATOM3N_impl<OpStr, IntTypeStr, TypeStr, scope, space, "",
21802205
t, !listconcat(Preds,[hasAtomScope])>;
21812206
}
21822207
}
2208+
2209+
// .gpu scope is default as is "gen" space. Add unscoped intrinsics with
2210+
// explicit address spaces.
2211+
foreach scope = ["gpu"] in {
2212+
foreach space = ["gen", "global", "shared"] in {
2213+
defm _#scope#space : ATOM3N_impl<OpStr, IntTypeStr, TypeStr, scope, space,
2214+
"", t, Preds>;
2215+
}
2216+
}
2217+
2218+
// Intrinsics with semantics, in all scopes and address spaces. Note the
2219+
// separate predicates which keep these loops apart.
2220+
foreach sem = ["acquire", "release", "acq_rel"] in {
2221+
foreach scope = ["gpu", "cta", "sys"] in {
2222+
// For now we only need variants for generic space pointers.
2223+
foreach space = ["gen", "global", "shared"] in {
2224+
defm _#sem#scope#space :
2225+
ATOM3N_impl<OpStr, IntTypeStr, TypeStr, scope, space, sem,
2226+
t, !listconcat(Preds, [hasAtomScope, hasAtomSemantics])>;
2227+
}
2228+
}
2229+
}
21832230
}
21842231

21852232
// atom.add
@@ -2216,6 +2263,7 @@ multiclass ATOM2_minmax_impl<string OpStr> {
22162263
// atom.{inc,dec}
22172264
multiclass ATOM2_incdec_impl<string OpStr> {
22182265
defm _u32 : ATOM2S_impl<OpStr, "i", "u32", I32RT, []>;
2266+
defm _u64 : ATOM2S_impl<OpStr, "i", "u64", I64RT, []>;
22192267
}
22202268

22212269
// atom.cas

0 commit comments

Comments
 (0)