[Utils] Replace llc with cat for tests
authorSebastian Neubauer <Sebastian.Neubauer@amd.com>
Tue, 21 Sep 2021 14:31:00 +0000 (16:31 +0200)
committerSebastian Neubauer <Sebastian.Neubauer@amd.com>
Wed, 22 Sep 2021 08:10:35 +0000 (10:10 +0200)
Make the update_llc_test_checks script test independant of llc behavior
by using cat with static files to simulate llc output.

This allows changing llc without breaking the script test case.

The update script is executed in a temporary directory, so the
llc-generated assembly files are copied there. %T is deprecated, but it
allows copying a file with a predictable filename.

Differential Revision: https://reviews.llvm.org/D110143

llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O0.s [new file with mode: 0644]
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O3.s [new file with mode: 0644]
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments.ll.expected
llvm/test/tools/UpdateTestChecks/update_llc_test_checks/amdgpu-no-merge-comments.test
llvm/utils/UpdateTestChecks/common.py

diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O0.s b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O0.s
new file mode 100644 (file)
index 0000000..0a089fb
--- /dev/null
@@ -0,0 +1,38 @@
+       .text
+       .section        .AMDGPU.config
+       .long   47176
+       .long   0
+       .long   47180
+       .long   0
+       .long   47200
+       .long   0
+       .long   4
+       .long   0
+       .long   8
+       .long   0
+       .text
+       .hidden main                            ; -- Begin function main
+       .globl  main
+       .p2align        2
+       .type   main,@function
+main:                                   ; @main
+; %bb.0:
+       s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+       v_add_u32_e64 v1, v0, v0
+                                        ; implicit-def: $sgpr4
+                                        ; implicit-def: $sgpr4
+       v_mul_lo_u32 v0, v1, v0
+       v_sub_u32_e64 v0, v0, v1
+       s_setpc_b64 s[30:31]
+.Lfunc_end0:
+       .size   main, .Lfunc_end0-main
+                                        ; -- End function
+       .section        .AMDGPU.csdata
+; Function info:
+; codeLenInByte = 32
+; NumSgprs: 36
+; NumVgprs: 2
+; ScratchSize: 0
+; MemoryBound: 0
+       .section        ".note.GNU-stack"
+       .amd_amdgpu_isa "amdgcn-unknown---gfx900"
diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O3.s b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_no_merge_comments-O3.s
new file mode 100644 (file)
index 0000000..8508f29
--- /dev/null
@@ -0,0 +1,36 @@
+       .text
+       .section        .AMDGPU.config
+       .long   47176
+       .long   0
+       .long   47180
+       .long   0
+       .long   47200
+       .long   0
+       .long   4
+       .long   0
+       .long   8
+       .long   0
+       .text
+       .hidden main                            ; -- Begin function main
+       .globl  main
+       .p2align        2
+       .type   main,@function
+main:                                   ; @main
+; %bb.0:
+       s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+       v_add_u32_e32 v1, v0, v0
+       v_mul_lo_u32 v0, v1, v0
+       v_sub_u32_e32 v0, v0, v1
+       s_setpc_b64 s[30:31]
+.Lfunc_end0:
+       .size   main, .Lfunc_end0-main
+                                        ; -- End function
+       .section        .AMDGPU.csdata
+; Function info:
+; codeLenInByte = 24
+; NumSgprs: 36
+; NumVgprs: 2
+; ScratchSize: 0
+; MemoryBound: 0
+       .section        ".note.GNU-stack"
+       .amd_amdgpu_isa "amdgcn-unknown---gfx900"
index 21d01f5..fa6e521 100644 (file)
@@ -1,5 +1,8 @@
-; RUN: llc -O0 -mtriple=amdgcn- -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9-O0 %s
-; RUN: llc -mtriple=amdgcn- -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9-O3 %s
+; llc is replaced with cat, we just simulate llc by printing text from these files
+; RUN: llc %S/amdgpu_no_merge_comments-O0.s | FileCheck -check-prefixes=GCN,GFX9-O0 %s
+; RUN: llc %S/amdgpu_no_merge_comments-O3.s | FileCheck -check-prefixes=GCN,GFX9-O3 %s
+
+target triple = "amdgcn--"
 
 define hidden i32 @main(i32 %a) {
   %add = add i32 %a, %a
index 645b5dd..a240941 100644 (file)
@@ -1,6 +1,9 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -O0 -mtriple=amdgcn- -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9-O0 %s
-; RUN: llc -mtriple=amdgcn- -mcpu=gfx900 < %s | FileCheck -check-prefixes=GCN,GFX9-O3 %s
+; llc is replaced with cat, we just simulate llc by printing text from these files
+; RUN: llc %S/amdgpu_no_merge_comments-O0.s | FileCheck -check-prefixes=GCN,GFX9-O0 %s
+; RUN: llc %S/amdgpu_no_merge_comments-O3.s | FileCheck -check-prefixes=GCN,GFX9-O3 %s
+
+target triple = "amdgcn--"
 
 define hidden i32 @main(i32 %a) {
 ; GFX9-O0-LABEL: main:
index 7d07877..6368451 100644 (file)
@@ -1,5 +1,8 @@
 # REQUIRES: amdgpu-registered-target
 ## Check that functions with different IR comments in the output are not merged
 
-# RUN: cp -f %S/Inputs/amdgpu_no_merge_comments.ll %t.ll && %update_llc_test_checks %t.ll
+# Replace llc with cat, so we can simulate hypothetical output without actually running llc.
+# Copy the simulated output to the temporary directory.
+# RUN: cp -f %S/Inputs/amdgpu_no_merge_comments-O0.s %T/ && cp -f %S/Inputs/amdgpu_no_merge_comments-O3.s %T/
+# RUN: cp -f %S/Inputs/amdgpu_no_merge_comments.ll %t.ll && %update_llc_test_checks --llc-binary cat %t.ll
 # RUN: diff -u %S/Inputs/amdgpu_no_merge_comments.ll.expected %t.ll
index bc4b073..3bc9089 100644 (file)
@@ -147,16 +147,31 @@ def should_add_line_to_output(input_line, prefix_set, skip_global_checks = False
 
   return True
 
+# Perform lit-like substitutions
+def getSubstitutions(sourcepath):
+  sourcedir = os.path.dirname(sourcepath)
+  return [('%s', sourcepath),
+          ('%S', sourcedir),
+          ('%p', sourcedir),
+          ('%{pathsep}', os.pathsep)]
+
+def applySubstitutions(s, substitutions):
+  for a,b in substitutions:
+    s = s.replace(a, b)
+  return s
+
 # Invoke the tool that is being tested.
 def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False):
   with open(ir) as ir_file:
+    substitutions = getSubstitutions(ir)
+
     # TODO Remove the str form which is used by update_test_checks.py and
     # update_llc_test_checks.py
     # The safer list form is used by update_cc_test_checks.py
     if preprocess_cmd:
       # Allow pre-processing the IR file (e.g. using sed):
       assert isinstance(preprocess_cmd, str)  # TODO: use a list instead of using shell
-      preprocess_cmd = preprocess_cmd.replace('%s', ir).strip()
+      preprocess_cmd = applySubstitutions(preprocess_cmd, substitutions).strip()
       if verbose:
         print('Pre-processing input file: ', ir, " with command '",
               preprocess_cmd, "'", sep="", file=sys.stderr)
@@ -165,10 +180,12 @@ def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False):
         pp = subprocess.Popen(preprocess_cmd, shell=True, stdin=devnull,
                               stdout=subprocess.PIPE)
         ir_file = pp.stdout
+
     if isinstance(cmd_args, list):
-      stdout = subprocess.check_output([exe] + cmd_args, stdin=ir_file)
+      args = [applySubstitutions(a, substitutions) for a in cmd_args]
+      stdout = subprocess.check_output([exe] + args, stdin=ir_file)
     else:
-      stdout = subprocess.check_output(exe + ' ' + cmd_args,
+      stdout = subprocess.check_output(exe + ' ' + applySubstitutions(cmd_args, substitutions),
                                        shell=True, stdin=ir_file)
     if sys.version_info[0] > 2:
       stdout = stdout.decode()