Skip to content

Commit 72f1516

Browse files
committed
SASS cleanup tests
1 parent 76f463e commit 72f1516

5 files changed

Lines changed: 890 additions & 26 deletions

File tree

src/cleanup/cleanup.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ include("typed_ir.jl")
2626
include("llvm_ir.jl")
2727
include("native.jl")
2828
include("ptx.jl")
29+
include("sass.jl")
2930
include("gcn.jl")
3031
include("agx.jl")
3132
include("spirv.jl")

src/cleanup/ptx.jl

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
# The PTX output of LLVM's NVPTX backend has a comment with the mangled function name
33
const PTX_FUNC_NAME_COMMENT_REGEX = r"// -- Begin function "m * MANGLED_NAME_REGEX * r"$"m
44

5-
# Same with SASS but the name is surrounded by a lot of dashes
6-
const SASS_FUNC_NAME_COMMENT_REGEX = r"//-{5,} .text."m * MANGLED_NAME_REGEX * r" -{5,}$"m
7-
85

96
function cleanup_code(::Val{:ptx}, c, dbinfo, cleanup_opts)
107
c = clean_function_name(PTX_FUNC_NAME_COMMENT_REGEX, c)
@@ -60,28 +57,6 @@ function cleanup_code(::Val{:ptx}, c, dbinfo, cleanup_opts)
6057
end
6158

6259

63-
function cleanup_code(::Val{:sass}, c, dbinfo, cleanup_opts)
64-
# SASS problems:
65-
# Registers seem to be assigned randomly, changing from one call to another with the
66-
# same input, as well as some immediate values (maybe related to the functions order in PTX?).
67-
# Some instructions (only `MOV` from what I saw) might be ordered differently, or even
68-
# in different numbers (max of what I could see is 1, but still surprising).
69-
c = replace_llvm_module_name(c)
70-
c = clean_function_name(SASS_FUNC_NAME_COMMENT_REGEX, c)
71-
72-
extra_patterns = []
73-
if get(cleanup_opts, :demangle, true)
74-
# Demangle only names which aren't the function's name
75-
push!(extra_patterns, demangle_all())
76-
end
77-
if !dbinfo
78-
push!(extra_patterns, r"; Location .+\R" => "") # Remove location comments
79-
end
80-
81-
return replace(c, extra_patterns...)
82-
end
83-
84-
8560
function find_main_ptx_function(c)
8661
# Matches any declaration of the form ".a1 .a2 some_name ( ..." and extracts ".a1 .a2" in group
8762
# "attrs" and "some_name" in group "name".

src/cleanup/sass.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# SASS is the same as PTX, but the name is surrounded by a lot of dashes
3+
const SASS_FUNC_NAME_COMMENT_REGEX = r"//-{5,} \.text\."m * MANGLED_NAME_REGEX * r" -{5,}$"m
4+
5+
6+
function cleanup_code(::Val{:sass}, c, dbinfo, cleanup_opts)
7+
# TODO: SASS problems:
8+
# Registers seem to be assigned randomly, changing from one call to another with the
9+
# same input, as well as some immediate values (maybe related to the functions order in PTX?).
10+
# Some instructions (only `MOV` from what I saw) might be ordered differently, or even
11+
# in different numbers (max of what I could see is 1, but still surprising).
12+
c = replace_llvm_module_name(c)
13+
c = clean_function_name(SASS_FUNC_NAME_COMMENT_REGEX, c)
14+
15+
extra_patterns = []
16+
if get(cleanup_opts, :demangle, true)
17+
# Demangle only names which aren't the function's name
18+
push!(extra_patterns, demangle_all())
19+
end
20+
if !dbinfo
21+
push!(extra_patterns, r"; Location .+\R" => "") # Remove location comments
22+
end
23+
24+
return replace(c, extra_patterns...)
25+
end

test/cleanup.jl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,28 @@ end
256256

257257

258258
@testset "SASS" begin
259-
# TODO
259+
@testset "Sample 1" begin
260+
sass_sample = readchomp("./samples/extern_func_with_no_params.sass")
261+
cleaned_sass = CDC.cleanup_code(Val(:sass), sass_sample)
262+
263+
println(TEST_IO, "\nCleaned SASS sample 1:")
264+
println(TEST_IO, cleaned_sass)
265+
266+
# No mangled names
267+
@test is_removed(CDC.MANGLED_NAME_REGEX, sass_sample, cleaned_sass)
268+
269+
# Make sure we didn't remove any instruction by mistake
270+
@test count(r";$"m, sass_sample) == count(r";$"m, cleaned_sass)
271+
272+
# Others
273+
@test !has_trailing_spaces(cleaned_sass)
274+
@test !endswith(cleaned_sass, r"\R") # no trailing newlines
275+
276+
# Location comments should be removed with `dbinfo=false`
277+
cleaned_sass_no_loc = CDC.cleanup_code(Val(:sass), sass_sample, false)
278+
@test is_removed("; Location", cleaned_sass, cleaned_sass_no_loc)
279+
@test count(r"\R{2,}", cleaned_sass) == count(r"\R{2,}", cleaned_sass_no_loc) # no empty lines were added
280+
end
260281
end
261282

262283

0 commit comments

Comments
 (0)