Skip to content

Commit b0002f4

Browse files
committed
Reduce reliance on (greedy) wildcards.
1 parent 40402d0 commit b0002f4

File tree

5 files changed

+78
-71
lines changed

5 files changed

+78
-71
lines changed

test/gcn.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ end
4040
end
4141

4242
@test @filecheck begin
43-
check"CHECK-LABEL: {{.*kernel.*}}:"
43+
check"CHECK-LABEL: {{(julia|j)_kernel_[0-9]+}}:"
4444
check"CHECK: s_trap 2"
4545
GCN.code_native(mod.kernel, Tuple{})
4646
end
@@ -64,9 +64,9 @@ end
6464
end
6565

6666
@test @filecheck begin
67-
check"CHECK-LABEL: {{.*parent.*}}:"
68-
check"CHECK: s_add_u32{{.*(julia|j)_child_.*}}@rel32@"
69-
check"CHECK: s_addc_u32{{.*(julia|j)_child_.*}}@rel32@"
67+
check"CHECK-LABEL: {{(julia|j)_parent_[0-9]+}}:"
68+
check"CHECK: s_add_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
69+
check"CHECK: s_addc_u32 {{.+}} {{(julia|j)_child_[0-9]+}}@rel32@"
7070
GCN.code_native(mod.parent, Tuple{Int64}; dump_module=true)
7171
end
7272
end
@@ -82,9 +82,9 @@ end
8282
end
8383

8484
@test @filecheck begin
85-
check"CHECK-NOT: .amdhsa_kernel {{.*}}nonentry"
86-
check"CHECK: .type {{.*nonentry.*}},@function"
87-
check"CHECK: .amdhsa_kernel {{.*entry.*}}"
85+
check"CHECK-NOT: .amdhsa_kernel {{(julia|j)_nonentry_[0-9]+}}"
86+
check"CHECK: .type {{(julia|j)_nonentry_[0-9]+}},@function"
87+
check"CHECK: .amdhsa_kernel _Z5entry5Int64"
8888
GCN.code_native(mod.entry, Tuple{Int64}; dump_module=true, kernel=true)
8989
end
9090
end
@@ -107,12 +107,12 @@ end
107107
end
108108

109109
@test @filecheck begin
110-
check"CHECK: .type {{.*child.*}},@function"
110+
check"CHECK: .type {{(julia|j)_child_[0-9]+}},@function"
111111
GCN.code_native(mod.parent1, Tuple{Int}; dump_module=true)
112112
end
113113

114114
@test @filecheck begin
115-
check"CHECK: .type {{.*child.*}},@function"
115+
check"CHECK: .type {{(julia|j)_child_[0-9]+}},@function"
116116
GCN.code_native(mod.parent2, Tuple{Int}; dump_module=true)
117117
end
118118
end
@@ -136,14 +136,14 @@ end
136136
end
137137

138138
@test @filecheck begin
139-
check"CHECK-DAG: .type {{.*child1.*}},@function"
140-
check"CHECK-DAG: .type {{.*child2.*}},@function"
139+
check"CHECK-DAG: .type {{(julia|j)_child1_[0-9]+}},@function"
140+
check"CHECK-DAG: .type {{(julia|j)_child2_[0-9]+}},@function"
141141
GCN.code_native(mod.parent1, Tuple{Int}; dump_module=true)
142142
end
143143

144144
@test @filecheck begin
145-
check"CHECK-DAG: .type {{.*child1.*}},@function"
146-
check"CHECK-DAG: .type {{.*child2.*}},@function"
145+
check"CHECK-DAG: .type {{(julia|j)_child1_[0-9]+}},@function"
146+
check"CHECK-DAG: .type {{(julia|j)_child2_[0-9]+}},@function"
147147
GCN.code_native(mod.parent2, Tuple{Int}; dump_module=true)
148148
end
149149
end
@@ -163,7 +163,7 @@ end
163163
end
164164

165165
@test @filecheck begin
166-
check"CHECK-LABEL: {{.*kernel.*}}:"
166+
check"CHECK-LABEL: {{(julia|j)_kernel_[0-9]+}}:"
167167
check"CHECK-NOT: jl_throw"
168168
check"CHECK-NOT: jl_invoke"
169169
GCN.code_native(mod.kernel, Tuple{Ptr{Int32}})
@@ -256,7 +256,7 @@ end
256256
end
257257

258258
@test @filecheck begin
259-
check"CHECK-LABEL: define void @{{.*kernel.*}}"
259+
check"CHECK-LABEL: define void @{{(julia|j)_kernel_[0-9]+}}"
260260
check"CHECK: jl_box_float32"
261261
GCN.code_llvm(mod.kernel, Tuple{Float32,Ptr{Float32}})
262262
end

test/metal.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ end
8181

8282
@test @filecheck begin
8383
check"CHECK-LABEL: define void @{{(julia|j)_kernel_[0-9]+}}"
84-
check"TYPED-SAME: ({{.*}} addrspace(1)* %{{.+}})"
84+
check"TYPED-SAME: ({{.+}} addrspace(1)* %{{.+}})"
8585
check"OPAQUE-SAME: (ptr addrspace(1) %{{.+}})"
8686
check"CHECK: call i32 @julia.air.thread_position_in_threadgroup.i32"
8787
Metal.code_llvm(mod.kernel, Tuple{Core.LLVMPtr{Int,1}})
8888
end
8989

9090
@test @filecheck begin
9191
check"CHECK-LABEL: define void @_Z6kernel7LLVMPtrI5Int64Li1EE"
92-
check"TYPED-SAME: ({{.*}} addrspace(1)* %{{.+}}, i32 %thread_position_in_threadgroup)"
92+
check"TYPED-SAME: ({{.+}} addrspace(1)* %{{.+}}, i32 %thread_position_in_threadgroup)"
9393
check"OPAQUE-SAME: (ptr addrspace(1) %{{.+}}, i32 %thread_position_in_threadgroup)"
9494
check"CHECK-NOT: call i32 @julia.air.thread_position_in_threadgroup.i32"
9595
Metal.code_llvm(mod.kernel, Tuple{Core.LLVMPtr{Int,1}}; kernel=true)
@@ -174,7 +174,7 @@ end
174174
end
175175

176176
@test @filecheck begin
177-
check"CHECK: @{{.+}} = {{.*}} addrspace(2) constant [2 x float]"
177+
check"CHECK: @{{.+}} ={{.*}} addrspace(2) constant [2 x float]"
178178
check"CHECK: define void @_Z6kernel7LLVMPtrI7Float32Li1EE5Int64"
179179
Metal.code_llvm(mod.kernel, Tuple{Core.LLVMPtr{Float32,1}, Int};
180180
dump_module=true, kernel=true)

test/native.jl

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
end
1313

1414
@test @filecheck begin
15-
check"CHECK: {{.*identity.*}}"
15+
check"CHECK: @{{(julia|j)_identity_[0-9]+}}"
1616
GPUCompiler.code_llvm(job)
1717
end
1818

1919
@test @filecheck begin
20-
check"CHECK: {{.*identity.*}}"
20+
check"CHECK: @{{(julia|j)_identity_[0-9]+}}"
2121
GPUCompiler.code_native(job)
2222
end
2323
end
@@ -81,23 +81,24 @@ end
8181
end
8282

8383
@testset "cached compilation" begin
84-
@gensym child kernel unrelated
85-
@eval @noinline $child(i) = i
86-
@eval $kernel(i) = $child(i)+1
84+
mod = @eval module $(gensym())
85+
@noinline child(i) = i
86+
kernel(i) = child(i)+1
87+
end
8788

8889
# smoke test
89-
job, _ = Native.create_job(eval(kernel), (Int64,))
90+
job, _ = Native.create_job(mod.kernel, (Int64,))
9091
@test @filecheck begin
91-
check"CHECK-LABEL: define {{.*}} @{{.*kernel.*}}("
92+
check"CHECK-LABEL: define i64 @{{(julia|j)_kernel_[0-9]+}}"
9293
check"CHECK: add i64 %{{[0-9]+}}, 1"
9394
GPUCompiler.code_llvm(job)
9495
end
9596

9697
# basic redefinition
97-
@eval $kernel(i) = $child(i)+2
98-
job, _ = Native.create_job(eval(kernel), (Int64,))
98+
@eval mod kernel(i) = child(i)+2
99+
job, _ = Native.create_job(mod.kernel, (Int64,))
99100
@test @filecheck begin
100-
check"CHECK-LABEL: define {{.*}} @{{.*kernel.*}}("
101+
check"CHECK-LABEL: define i64 @{{(julia|j)_kernel_[0-9]+}}"
101102
check"CHECK: add i64 %{{[0-9]+}}, 2"
102103
GPUCompiler.code_llvm(job)
103104
end
@@ -113,51 +114,51 @@ end
113114
end
114115
linker(job, compiled) = compiled
115116
cache = Dict()
116-
ft = typeof(eval(kernel))
117+
ft = typeof(mod.kernel)
117118
tt = Tuple{Int64}
118119

119120
# initial compilation
120121
source = methodinstance(ft, tt, Base.get_world_counter())
121122
@test @filecheck begin
122-
check"CHECK-LABEL: define {{.*}} @{{.*kernel.*}}("
123+
check"CHECK-LABEL: define i64 @{{(julia|j)_kernel_[0-9]+}}"
123124
check"CHECK: add i64 %{{[0-9]+}}, 2"
124125
Base.invokelatest(GPUCompiler.cached_compilation, cache, source, job.config, compiler, linker)
125126
end
126127
@test invocations[] == 1
127128

128129
# cached compilation
129130
@test @filecheck begin
130-
check"CHECK-LABEL: define {{.*}} @{{.*kernel.*}}("
131+
check"CHECK-LABEL: define i64 @{{(julia|j)_kernel_[0-9]+}}"
131132
check"CHECK: add i64 %{{[0-9]+}}, 2"
132133
Base.invokelatest(GPUCompiler.cached_compilation, cache, source, job.config, compiler, linker)
133134
end
134135
@test invocations[] == 1
135136

136137
# redefinition
137-
@eval $kernel(i) = $child(i)+3
138+
@eval mod kernel(i) = child(i)+3
138139
source = methodinstance(ft, tt, Base.get_world_counter())
139140
@test @filecheck begin
140-
check"CHECK-LABEL: define {{.*}} @{{.*kernel.*}}("
141+
check"CHECK-LABEL: define i64 @{{(julia|j)_kernel_[0-9]+}}"
141142
check"CHECK: add i64 %{{[0-9]+}}, 3"
142143
Base.invokelatest(GPUCompiler.cached_compilation, cache, source, job.config, compiler, linker)
143144
end
144145
@test invocations[] == 2
145146

146147
# cached compilation
147148
@test @filecheck begin
148-
check"CHECK-LABEL: define {{.*}} @{{.*kernel.*}}("
149+
check"CHECK-LABEL: define i64 @{{(julia|j)_kernel_[0-9]+}}"
149150
check"CHECK: add i64 %{{[0-9]+}}, 3"
150151
Base.invokelatest(GPUCompiler.cached_compilation, cache, source, job.config, compiler, linker)
151152
end
152153
@test invocations[] == 2
153154

154155
# redefinition of an unrelated function
155-
@eval $unrelated(i) = 42
156+
@eval mod unrelated(i) = 42
156157
Base.invokelatest(GPUCompiler.cached_compilation, cache, source, job.config, compiler, linker)
157158
@test invocations[] == 2
158159

159160
# redefining child functions
160-
@eval @noinline $child(i) = i+1
161+
@eval mod @noinline child(i) = i+1
161162
Base.invokelatest(GPUCompiler.cached_compilation, cache, source, job.config, compiler, linker)
162163
@test invocations[] == 3
163164

@@ -168,7 +169,7 @@ end
168169
# change in configuration
169170
config = CompilerConfig(job.config; name="foobar")
170171
@test @filecheck begin
171-
check"CHECK: define {{.*}} @foobar"
172+
check"CHECK: define i64 @foobar"
172173
Base.invokelatest(GPUCompiler.cached_compilation, cache, source, config, compiler, linker)
173174
end
174175
@test invocations[] == 4
@@ -183,13 +184,13 @@ end
183184
end
184185
t = @async Base.invokelatest(background, job)
185186
wait(c1) # make sure the task has started
186-
@eval $kernel(i) = $child(i)+4
187+
@eval mod kernel(i) = child(i)+4
187188
source = methodinstance(ft, tt, Base.get_world_counter())
188189
ir = Base.invokelatest(GPUCompiler.cached_compilation, cache, source, job.config, compiler, linker)
189190
@test contains(ir, r"add i64 %\d+, 4")
190191
notify(c2) # wake up the task
191192
@test @filecheck begin
192-
check"CHECK-LABEL: define {{.*}} @{{.*kernel.*}}("
193+
check"CHECK-LABEL: define i64 @{{(julia|j)_kernel_[0-9]+}}"
193194
check"CHECK: add i64 %{{[0-9]+}}, 3"
194195
fetch(t)
195196
end
@@ -220,7 +221,7 @@ end
220221

221222
@test @filecheck begin
222223
# module should contain our function + a generic call wrapper
223-
check"CHECK: {{.*valid_kernel.*}}"
224+
check"CHECK: @{{(julia|j)_valid_kernel_[0-9]+}}"
224225
Native.code_llvm(mod.valid_kernel, Tuple{}; optimize=false, dump_module=true)
225226
end
226227

@@ -244,8 +245,8 @@ end
244245
end
245246

246247
@test @filecheck begin
247-
check"CHECK-LABEL: define {{.*}} @{{.*parent.*}}"
248-
check"CHECK: call {{.+}} @{{.*child.*}}"
248+
check"CHECK-LABEL: define i64 @{{(julia|j)_parent_[0-9]+}}"
249+
check"CHECK: call{{.*}} i64 @{{(julia|j)_child_[0-9]+}}"
249250
Native.code_llvm(mod.parent, Tuple{Int})
250251
end
251252
end
@@ -312,17 +313,17 @@ end
312313
f = () -> x+1
313314
end
314315
@test @filecheck begin
315-
check"CHECK: define internal fastcc {{.+}} @julia"
316+
check"CHECK: define {{.+}} @julia"
316317
check"TYPED: define nonnull {}* @jfptr"
317318
check"OPAQUE: define nonnull ptr @jfptr"
318-
check"CHECK: call fastcc {{.+}} @julia"
319+
check"CHECK: call {{.+}} @julia"
319320
Native.code_llvm(mod.f, Tuple{}; entry_abi=:func, dump_module=true)
320321
end
321322
end
322323

323324
@testset "function entry safepoint emission" begin
324325
@test @filecheck begin
325-
check"CHECK-LABEL: define {{.*}} @{{.*identity.*}}("
326+
check"CHECK-LABEL: define void @{{(julia|j)_identity_[0-9]+}}"
326327
check"CHECK-NOT: %safepoint"
327328
Native.code_llvm(identity, Tuple{Nothing}; entry_safepoint=false, optimize=false, dump_module=true)
328329
end
@@ -331,7 +332,7 @@ end
331332
# see https://github.com/JuliaLang/julia/pull/57010/files#r2079576894
332333
if VERSION < v"1.13.0-DEV.533"
333334
@test @filecheck begin
334-
check"CHECK-LABEL: define {{.*}} @{{.*identity.*}}("
335+
check"CHECK-LABEL: define void @{{(julia|j)_identity_[0-9]+}}"
335336
check"CHECK: %safepoint"
336337
Native.code_llvm(identity, Tuple{Nothing}; entry_safepoint=true, optimize=false, dump_module=true)
337338
end
@@ -342,34 +343,34 @@ end
342343
# XXX: broken by JuliaLang/julia#51599, see JuliaGPU/GPUCompiler.jl#527
343344
mod = @eval module $(gensym())
344345
import ..sink
345-
f_expensive(x) = $(foldl((e, _) -> :($sink($e) + $sink(x)), 1:100; init=:x))
346+
expensive(x) = $(foldl((e, _) -> :($sink($e) + $sink(x)), 1:100; init=:x))
346347
function g(x)
347-
f_expensive(x)
348+
expensive(x)
348349
return
349350
end
350351
function h(x)
351-
f_expensive(x)
352+
expensive(x)
352353
return
353354
end
354355
end
355356

356357
@test @filecheck begin
357-
check"CHECK: define {{.*f_expensive.*}}"
358+
check"CHECK: @{{(julia|j)_expensive_[0-9]+}}"
358359
Native.code_llvm(mod.g, Tuple{Int64}; dump_module=true, kernel=true)
359360
end
360361

361362
@test @filecheck begin
362-
check"CHECK-NOT: define {{.*f_expensive.*}}"
363+
check"CHECK-NOT: @{{(julia|j)_expensive_[0-9]+}}"
363364
Native.code_llvm(mod.g, Tuple{Int64}; dump_module=true, kernel=true, always_inline=true)
364365
end
365366

366367
@test @filecheck begin
367-
check"CHECK: define {{.*f_expensive.*}}"
368+
check"CHECK: @{{(julia|j)_expensive_[0-9]+}}"
368369
Native.code_llvm(mod.h, Tuple{Int64}; dump_module=true, kernel=true)
369370
end
370371

371372
@test @filecheck begin
372-
check"CHECK-NOT: define {{.*f_expensive.*}}"
373+
check"CHECK-NOT: @{{(julia|j)_expensive_[0-9]+}}"
373374
Native.code_llvm(mod.h, Tuple{Int64}; dump_module=true, kernel=true, always_inline=true)
374375
end
375376
end

0 commit comments

Comments
 (0)