[llvm] r321048 - update_mir_test_checks: Accept IR as input as well as MIR

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 16:49:04 PST 2017


Author: bogner
Date: Mon Dec 18 16:49:04 2017
New Revision: 321048

URL: http://llvm.org/viewvc/llvm-project?rev=321048&view=rev
Log:
update_mir_test_checks: Accept IR as input as well as MIR

We need to handle IR for tests that want to do lowering (or just
-stop-after with IR as input). I've run this on one AArch64 test to
demonstrate what it looks like.

Modified:
    llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll
    llvm/trunk/utils/update_mir_test_checks.py

Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll?rev=321048&r1=321047&r2=321048&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/translate-gep.ll Mon Dec 18 16:49:04 2017
@@ -1,85 +1,104 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
 ; RUN: llc -mtriple=aarch64-linux-gnu -O0 -global-isel -stop-after=irtranslator -o - %s | FileCheck %s
 
 %type = type [4 x {i8, i32}]
 
 define %type* @first_offset_const(%type* %addr) {
-; CHECK-LABEL: name: first_offset_const
-; CHECK: [[BASE:%[0-9]+]]:_(p0) = COPY %x0
-; CHECK: [[OFFSET:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
-; CHECK: [[RES:%[0-9]+]]:_(p0) = G_GEP [[BASE]], [[OFFSET]](s64)
-; CHECK: %x0 = COPY [[RES]](p0)
 
+  ; CHECK-LABEL: name: first_offset_const
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: %x0
+  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY %x0
+  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
+  ; CHECK:   [[GEP:%[0-9]+]]:_(p0) = G_GEP [[COPY]], [[C]](s64)
+  ; CHECK:   %x0 = COPY [[GEP]](p0)
+  ; CHECK:   RET_ReallyLR implicit %x0
   %res = getelementptr %type, %type* %addr, i32 1
   ret %type* %res
 }
 
 define %type* @first_offset_trivial(%type* %addr) {
-; CHECK-LABEL: name: first_offset_trivial
-; CHECK: [[BASE:%[0-9]+]]:_(p0) = COPY %x0
-; CHECK: [[TRIVIAL:%[0-9]+]]:_(p0) = COPY [[BASE]](p0)
-; CHECK: %x0 = COPY [[TRIVIAL]](p0)
 
+  ; CHECK-LABEL: name: first_offset_trivial
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: %x0
+  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY %x0
+  ; CHECK:   [[COPY1:%[0-9]+]]:_(p0) = COPY [[COPY]](p0)
+  ; CHECK:   %x0 = COPY [[COPY1]](p0)
+  ; CHECK:   RET_ReallyLR implicit %x0
   %res = getelementptr %type, %type* %addr, i32 0
   ret %type* %res
 }
 
 define %type* @first_offset_variable(%type* %addr, i64 %idx) {
-; CHECK-LABEL: name: first_offset_variable
-; CHECK: [[BASE:%[0-9]+]]:_(p0) = COPY %x0
-; CHECK: [[IDX:%[0-9]+]]:_(s64) = COPY %x1
-; CHECK: [[SIZE:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
-; CHECK: [[OFFSET:%[0-9]+]]:_(s64) = G_MUL [[SIZE]], [[IDX]]
-; CHECK: [[STEP0:%[0-9]+]]:_(p0) = G_GEP [[BASE]], [[OFFSET]](s64)
-; CHECK: [[RES:%[0-9]+]]:_(p0) = COPY [[STEP0]](p0)
-; CHECK: %x0 = COPY [[RES]](p0)
 
+  ; CHECK-LABEL: name: first_offset_variable
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: %x0, %x1
+  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY %x0
+  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY %x1
+  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
+  ; CHECK:   [[MUL:%[0-9]+]]:_(s64) = G_MUL [[C]], [[COPY1]]
+  ; CHECK:   [[GEP:%[0-9]+]]:_(p0) = G_GEP [[COPY]], [[MUL]](s64)
+  ; CHECK:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[GEP]](p0)
+  ; CHECK:   %x0 = COPY [[COPY2]](p0)
+  ; CHECK:   RET_ReallyLR implicit %x0
   %res = getelementptr %type, %type* %addr, i64 %idx
   ret %type* %res
 }
 
 define %type* @first_offset_ext(%type* %addr, i32 %idx) {
-; CHECK-LABEL: name: first_offset_ext
-; CHECK: [[BASE:%[0-9]+]]:_(p0) = COPY %x0
-; CHECK: [[IDX32:%[0-9]+]]:_(s32) = COPY %w1
-; CHECK: [[SIZE:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
-; CHECK: [[IDX64:%[0-9]+]]:_(s64) = G_SEXT [[IDX32]](s32)
-; CHECK: [[OFFSET:%[0-9]+]]:_(s64) = G_MUL [[SIZE]], [[IDX64]]
-; CHECK: [[STEP0:%[0-9]+]]:_(p0) = G_GEP [[BASE]], [[OFFSET]](s64)
-; CHECK: [[RES:%[0-9]+]]:_(p0) = COPY [[STEP0]](p0)
-; CHECK: %x0 = COPY [[RES]](p0)
 
+  ; CHECK-LABEL: name: first_offset_ext
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: %w1, %x0
+  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY %x0
+  ; CHECK:   [[COPY1:%[0-9]+]]:_(s32) = COPY %w1
+  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
+  ; CHECK:   [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY1]](s32)
+  ; CHECK:   [[MUL:%[0-9]+]]:_(s64) = G_MUL [[C]], [[SEXT]]
+  ; CHECK:   [[GEP:%[0-9]+]]:_(p0) = G_GEP [[COPY]], [[MUL]](s64)
+  ; CHECK:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[GEP]](p0)
+  ; CHECK:   %x0 = COPY [[COPY2]](p0)
+  ; CHECK:   RET_ReallyLR implicit %x0
   %res = getelementptr %type, %type* %addr, i32 %idx
   ret %type* %res
 }
 
 %type1 = type [4 x [4 x i32]]
 define i32* @const_then_var(%type1* %addr, i64 %idx) {
-; CHECK-LABEL: name: const_then_var
-; CHECK: [[BASE:%[0-9]+]]:_(p0) = COPY %x0
-; CHECK: [[IDX:%[0-9]+]]:_(s64) = COPY %x1
-; CHECK: [[OFFSET1:%[0-9]+]]:_(s64) = G_CONSTANT i64 272
-; CHECK: [[SIZE:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
-; CHECK: [[BASE1:%[0-9]+]]:_(p0) = G_GEP [[BASE]], [[OFFSET1]](s64)
-; CHECK: [[OFFSET2:%[0-9]+]]:_(s64) = G_MUL [[SIZE]], [[IDX]]
-; CHECK: [[BASE2:%[0-9]+]]:_(p0) = G_GEP [[BASE1]], [[OFFSET2]](s64)
-; CHECK: [[RES:%[0-9]+]]:_(p0) = COPY [[BASE2]](p0)
-; CHECK: %x0 = COPY [[RES]](p0)
 
+  ; CHECK-LABEL: name: const_then_var
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: %x0, %x1
+  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY %x0
+  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY %x1
+  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 272
+  ; CHECK:   [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
+  ; CHECK:   [[GEP:%[0-9]+]]:_(p0) = G_GEP [[COPY]], [[C]](s64)
+  ; CHECK:   [[MUL:%[0-9]+]]:_(s64) = G_MUL [[C1]], [[COPY1]]
+  ; CHECK:   [[GEP1:%[0-9]+]]:_(p0) = G_GEP [[GEP]], [[MUL]](s64)
+  ; CHECK:   [[COPY2:%[0-9]+]]:_(p0) = COPY [[GEP1]](p0)
+  ; CHECK:   %x0 = COPY [[COPY2]](p0)
+  ; CHECK:   RET_ReallyLR implicit %x0
   %res = getelementptr %type1, %type1* %addr, i32 4, i32 1, i64 %idx
   ret i32* %res
 }
 
 define i32* @var_then_const(%type1* %addr, i64 %idx) {
-; CHECK-LABEL: name: var_then_const
-; CHECK: [[BASE:%[0-9]+]]:_(p0) = COPY %x0
-; CHECK: [[IDX:%[0-9]+]]:_(s64) = COPY %x1
-; CHECK: [[SIZE:%[0-9]+]]:_(s64) = G_CONSTANT i64 64
-; CHECK: [[OFFSET2:%[0-9]+]]:_(s64) = G_CONSTANT i64 40
-; CHECK: [[OFFSET1:%[0-9]+]]:_(s64) = G_MUL [[SIZE]], [[IDX]]
-; CHECK: [[BASE1:%[0-9]+]]:_(p0) = G_GEP [[BASE]], [[OFFSET1]](s64)
-; CHECK: [[BASE2:%[0-9]+]]:_(p0) = G_GEP [[BASE1]], [[OFFSET2]](s64)
-; CHECK: %x0 = COPY [[BASE2]](p0)
 
+  ; CHECK-LABEL: name: var_then_const
+  ; CHECK: bb.1 (%ir-block.0):
+  ; CHECK:   liveins: %x0, %x1
+  ; CHECK:   [[COPY:%[0-9]+]]:_(p0) = COPY %x0
+  ; CHECK:   [[COPY1:%[0-9]+]]:_(s64) = COPY %x1
+  ; CHECK:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 64
+  ; CHECK:   [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 40
+  ; CHECK:   [[MUL:%[0-9]+]]:_(s64) = G_MUL [[C]], [[COPY1]]
+  ; CHECK:   [[GEP:%[0-9]+]]:_(p0) = G_GEP [[COPY]], [[MUL]](s64)
+  ; CHECK:   [[GEP1:%[0-9]+]]:_(p0) = G_GEP [[GEP]], [[C1]](s64)
+  ; CHECK:   %x0 = COPY [[GEP1]](p0)
+  ; CHECK:   RET_ReallyLR implicit %x0
   %res = getelementptr %type1, %type1* %addr, i64 %idx, i32 2, i32 2
   ret i32* %res
 }

Modified: llvm/trunk/utils/update_mir_test_checks.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/update_mir_test_checks.py?rev=321048&r1=321047&r2=321048&view=diff
==============================================================================
--- llvm/trunk/utils/update_mir_test_checks.py (original)
+++ llvm/trunk/utils/update_mir_test_checks.py Mon Dec 18 16:49:04 2017
@@ -43,6 +43,10 @@ VREG_DEF_RE = re.compile(
 MIR_PREFIX_DATA_RE = re.compile(r'^ *(;|bb.[0-9].*: *$|[a-z]+:( |$)|$)')
 VREG_CLASS_RE = re.compile(r'^ *- *{ id: ([0-9]+), class: ([a-z0-9_]+)', re.M)
 
+IR_FUNC_NAME_RE = re.compile(
+    r'^\s*define\s+(?:internal\s+)?[^@]*@(?P<func>\w+)\s*\(')
+IR_PREFIX_DATA_RE = re.compile(r'^ *(;|$)')
+
 MIR_FUNC_RE = re.compile(
     r'^---$'
     r'\n'
@@ -340,8 +344,10 @@ def update_test_file(llc, test, remove_c
         warn('Ignoring common prefixes: {}'.format(common_prefixes),
              test_file=test)
 
-    autogenerated_note = ('# NOTE: Assertions have been autogenerated by '
-                          'utils/{}'.format(os.path.basename(__file__)))
+    comment_char = '#' if test.endswith('.mir') else ';'
+    autogenerated_note = ('{} NOTE: Assertions have been autogenerated by '
+                          'utils/{}'.format(comment_char,
+                                            os.path.basename(__file__)))
     output_lines = []
     output_lines.append(autogenerated_note)
 
@@ -350,6 +356,10 @@ def update_test_file(llc, test, remove_c
             continue
 
         if state == 'toplevel':
+            m = IR_FUNC_NAME_RE.match(input_line)
+            if m:
+                state = 'ir function prefix'
+                func_name = m.group('func')
             if input_line.strip() == '---':
                 state = 'document'
             output_lines.append(input_line)
@@ -392,6 +402,23 @@ def update_test_file(llc, test, remove_c
                 func_name = None
             if should_add_line_to_output(input_line, prefix_set):
                 output_lines.append(input_line)
+        elif state == 'ir function prefix':
+            m = IR_PREFIX_DATA_RE.match(input_line)
+            if not m:
+                state = 'ir function body'
+                add_checks_for_function(test, output_lines, run_list,
+                                        func_dict, func_name, add_vreg_checks,
+                                        single_bb=False, verbose=verbose)
+
+            if should_add_line_to_output(input_line, prefix_set):
+                output_lines.append(input_line)
+        elif state == 'ir function body':
+            if input_line.strip() == '}':
+                state = 'toplevel'
+                func_name = None
+            if should_add_line_to_output(input_line, prefix_set):
+                output_lines.append(input_line)
+
 
     log('Writing {} lines to {}...'.format(len(output_lines), test), verbose)
 




More information about the llvm-commits mailing list