diff --git a/llvm/test/tools/UpdateTestChecks/lit.local.cfg b/llvm/test/tools/UpdateTestChecks/lit.local.cfg new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/lit.local.cfg @@ -0,0 +1,61 @@ +import os + +import lit.formats +import lit.util + +# python 2.7 backwards compatibility +try: + from shlex import quote as shell_quote +except ImportError: + from pipes import quote as shell_quote + + +def add_update_script_substition(name, python_exe=config.python_executable, + extra_args=''): + script_path = os.path.join(config.llvm_src_root, 'utils', name + '.py') + assert os.path.isfile(script_path) + config.substitutions.append( + ('%' + name, '\'%s\' %s %s' % (python_exe, script_path, extra_args))) + + +config.test_format = lit.formats.ShTest(execute_external=False) +config.suffixes = ['.test'] + +llc_path = os.path.join(config.llvm_tools_dir, 'llc') +if os.path.isfile(llc_path): + config.available_features.add('llc-binary') + llc_arg = '--llc-binary ' + shell_quote(llc_path) + add_update_script_substition('update_llc_test_checks', extra_args=llc_arg) + add_update_script_substition('update_mir_test_checks', extra_args=llc_arg) + +opt_path = os.path.join(config.llvm_tools_dir, 'opt') +if os.path.isfile(opt_path): + config.available_features.add('opt-binary') + opt_arg = '--opt-binary ' + shell_quote(opt_path) + add_update_script_substition('update_test_checks', extra_args=opt_arg) + add_update_script_substition('update_analyze_test_checks', + extra_args=opt_arg) + +llvm_mca_path = os.path.join(config.llvm_tools_dir, 'llvm-mca') +if os.path.isfile(llvm_mca_path): + config.available_features.add('llvm-mca-binary') + mca_arg = '--llvm-mca-binary ' + shell_quote(llvm_mca_path) + add_update_script_substition('update_test_checks', extra_args=mca_arg) + +# update_cc_test_checks requires python3 +py3_exe = lit.util.which('python3') +if py3_exe: + config.substitutions.append(('%python3', '\'' + py3_exe + '\'')) + config.available_features.add('python3') + +clang_path = os.path.join(config.llvm_tools_dir, 'clang') +if os.path.isfile(clang_path): + config.available_features.add('clang-binary') + if py3_exe: + # XXX: or use --llvm-bin? + extra_args = '--clang ' + shell_quote(clang_path) + if os.path.isfile(opt_path): + extra_args += ' --opt ' + shell_quote(opt_path) + add_update_script_substition('update_cc_test_checks', + python_exe=py3_exe, + extra_args=extra_args) diff --git a/llvm/test/tools/UpdateTestChecks/update_cc_tests/Inputs/mangled_names.c b/llvm/test/tools/UpdateTestChecks/update_cc_tests/Inputs/mangled_names.c new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_cc_tests/Inputs/mangled_names.c @@ -0,0 +1,16 @@ +// Example input for update_cc_test_checks +// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s + +long test(long a, int b) { + return a + b; +} + +// A function with a mangled name +__attribute__((overloadable)) long test(long a, int b, int c) { + return a + b + c; +} + + + + + diff --git a/llvm/test/tools/UpdateTestChecks/update_cc_tests/lit.local.cfg b/llvm/test/tools/UpdateTestChecks/update_cc_tests/lit.local.cfg new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_cc_tests/lit.local.cfg @@ -0,0 +1,3 @@ +# These tests require clang. +if 'clang-binary' not in config.available_features: + config.unsupported = True diff --git a/llvm/test/tools/UpdateTestChecks/update_cc_tests/mangled_names.test b/llvm/test/tools/UpdateTestChecks/update_cc_tests/mangled_names.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_cc_tests/mangled_names.test @@ -0,0 +1,54 @@ +# NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +# RUN: cp -f %S/Inputs/mangled_names.c %t.c +# RUN: cat %t.c +# RUN: %update_cc_test_checks -v %t.c +# RUN: FileCheck --input-file=%t.c --check-prefix=GENERATED %s +# +## Basic test checking that update_cc_test_checks.py works as expected for +## functions with mangled names + +# GENERATED: // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py +# GENERATED-NEXT: // Example input for update_cc_test_checks +## Note: We can't have RUN here since otherwise lit will attempt to execute it -> split across two lines +# GENERATED-NEXT: // R +# GENERATED-SAME: UN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s +# GENERATED-EMPTY: +# GENERATED-NEXT: // CHECK-LABEL: @test( +# GENERATED-NEXT: // CHECK-NEXT: entry: +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}A_ADDR:%.*]] = alloca i64, align 8 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}B_ADDR:%.*]] = alloca i32, align 4 +# GENERATED-NEXT: // CHECK-NEXT: store i64 {{\[\[}}A:%.*]], i64* {{\[\[}}A_ADDR]], align 8 +# GENERATED-NEXT: // CHECK-NEXT: store i32 {{\[\[}}B:%.*]], i32* {{\[\[}}B_ADDR]], align 4 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}TMP0:%.*]] = load i64, i64* {{\[\[}}A_ADDR]], align 8 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}TMP1:%.*]] = load i32, i32* {{\[\[}}B_ADDR]], align 4 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}CONV:%.*]] = sext i32 {{\[\[}}TMP1]] to i64 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}ADD:%.*]] = add nsw i64 {{\[\[}}TMP0]], {{\[\[}}CONV]] +# GENERATED-NEXT: // CHECK-NEXT: ret i64 {{\[\[}}ADD]] +# GENERATED-NEXT: // +# GENERATED-NEXT: long test(long a, int b) { +# GENERATED-NEXT: return a + b; +# GENERATED-NEXT: } +# GENERATED-EMPTY: +# GENERATED-NEXT: // A function with a mangled name +# GENERATED-NEXT: // CHECK-LABEL: @_Z4testlii( +# GENERATED-NEXT: // CHECK-NEXT: entry: +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}A_ADDR:%.*]] = alloca i64, align 8 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}B_ADDR:%.*]] = alloca i32, align 4 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}C_ADDR:%.*]] = alloca i32, align 4 +# GENERATED-NEXT: // CHECK-NEXT: store i64 {{\[\[}}A:%.*]], i64* {{\[\[}}A_ADDR]], align 8 +# GENERATED-NEXT: // CHECK-NEXT: store i32 {{\[\[}}B:%.*]], i32* {{\[\[}}B_ADDR]], align 4 +# GENERATED-NEXT: // CHECK-NEXT: store i32 {{\[\[}}C:%.*]], i32* {{\[\[}}C_ADDR]], align 4 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}TMP0:%.*]] = load i64, i64* {{\[\[}}A_ADDR]], align 8 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}TMP1:%.*]] = load i32, i32* {{\[\[}}B_ADDR]], align 4 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}CONV:%.*]] = sext i32 {{\[\[}}TMP1]] to i64 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}ADD:%.*]] = add nsw i64 {{\[\[}}TMP0]], {{\[\[}}CONV]] +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}TMP2:%.*]] = load i32, i32* {{\[\[}}C_ADDR]], align 4 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}CONV1:%.*]] = sext i32 {{\[\[}}TMP2]] to i64 +# GENERATED-NEXT: // CHECK-NEXT: {{\[\[}}ADD2:%.*]] = add nsw i64 {{\[\[}}ADD]], {{\[\[}}CONV1]] +# GENERATED-NEXT: // CHECK-NEXT: ret i64 {{\[\[}}ADD2]] +# GENERATED-NEXT: // +# GENERATED-NEXT: __attribute__((overloadable)) long test(long a, int b, int c) { +# GENERATED-NEXT: return a + b + c; +# GENERATED-NEXT: } +# GENERATED-EMPTY: + diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_tests/Inputs/basic.ll b/llvm/test/tools/UpdateTestChecks/update_llc_tests/Inputs/basic.ll new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_llc_tests/Inputs/basic.ll @@ -0,0 +1,32 @@ +; Example input for update_llc_test_checks (taken from CodeGen/X86/iabs.ll) +; RUN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefix=X86 --check-prefix=X86-NO-CMOV +; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+cmov | FileCheck %s --check-prefix=X86 --check-prefix=X86-CMOV +; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64 + +define i8 @test_i8(i8 %a) nounwind { + %tmp1neg = sub i8 0, %a + %b = icmp sgt i8 %a, -1 + %abs = select i1 %b, i8 %a, i8 %tmp1neg + ret i8 %abs +} + +define i16 @test_i16(i16 %a) nounwind { + %tmp1neg = sub i16 0, %a + %b = icmp sgt i16 %a, -1 + %abs = select i1 %b, i16 %a, i16 %tmp1neg + ret i16 %abs +} + +define i32 @test_i32(i32 %a) nounwind { + %tmp1neg = sub i32 0, %a + %b = icmp sgt i32 %a, -1 + %abs = select i1 %b, i32 %a, i32 %tmp1neg + ret i32 %abs +} + +define i64 @test_i64(i64 %a) nounwind { + %tmp1neg = sub i64 0, %a + %b = icmp sgt i64 %a, -1 + %abs = select i1 %b, i64 %a, i64 %tmp1neg + ret i64 %abs +} diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_tests/basic.test b/llvm/test/tools/UpdateTestChecks/update_llc_tests/basic.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_llc_tests/basic.test @@ -0,0 +1,135 @@ +# REQUIRES: x86-registered-target +## Basic test checking that update_llc_test_checks.py can update a file with multiple check prefixes + +# RUN: cp -f %S/Inputs/basic.ll %t.ll +# RUN: %update_llc_test_checks %t.ll +# RUN: FileCheck --input-file=%t.ll --check-prefix=GENERATED %s +## No difference for --extra_scrub +# RUN: cp -f %S/Inputs/basic.ll %t.ll +# RUN: %update_llc_test_checks --extra_scrub %t.ll +# RUN: FileCheck --input-file=%t.ll --check-prefix=GENERATED %s +## Or for --x86_scrub_rip +# RUN: cp -f %S/Inputs/basic.ll %t.ll +# RUN: %update_llc_test_checks --x86_scrub_rip %t.ll +# RUN: FileCheck --input-file=%t.ll --check-prefix=GENERATED %s + +# GENERATED: ; Example input for update_llc_test_checks +## Note: We can't have RUN here since otherwise lit will attempt to execute it -> split across two lines +# GENERATED-NEXT: ; R +# GENERATED-SAME: UN: llc < %s -mtriple=i686-unknown-unknown | FileCheck %s --check-prefix=X86 --check-prefix=X86-NO-CMOV +# GENERATED-NEXT: ; R +# GENERATED-SAME: UN: llc < %s -mtriple=i686-unknown-unknown -mattr=+cmov | FileCheck %s --check-prefix=X86 --check-prefix=X86-CMOV +# GENERATED-NEXT: ; R +# GENERATED-SAME: UN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s --check-prefix=X64 +# GENERATED-EMPTY: +# GENERATED-NEXT: define i8 @test_i8(i8 %a) nounwind { +# GENERATED-NEXT: ; X86-LABEL: test_i8: +# GENERATED-NEXT: ; X86: # %bb.0: +# GENERATED-NEXT: ; X86-NEXT: movb {{{{}}[0-9]+}}(%esp), %al +# GENERATED-NEXT: ; X86-NEXT: movl %eax, %ecx +# GENERATED-NEXT: ; X86-NEXT: sarb $7, %cl +# GENERATED-NEXT: ; X86-NEXT: addb %cl, %al +# GENERATED-NEXT: ; X86-NEXT: xorb %cl, %al +# GENERATED-NEXT: ; X86-NEXT: retl +# GENERATED-NEXT: ; +# GENERATED-NEXT: ; X64-LABEL: test_i8: +# GENERATED-NEXT: ; X64: # %bb.0: +# GENERATED-NEXT: ; X64-NEXT: # kill: def $edi killed $edi def $rdi +# GENERATED-NEXT: ; X64-NEXT: movl %edi, %ecx +# GENERATED-NEXT: ; X64-NEXT: sarb $7, %cl +# GENERATED-NEXT: ; X64-NEXT: leal (%rdi,%rcx), %eax +# GENERATED-NEXT: ; X64-NEXT: xorb %cl, %al +# GENERATED-NEXT: ; X64-NEXT: # kill: def $al killed $al killed $eax +# GENERATED-NEXT: ; X64-NEXT: retq +# GENERATED-NEXT: %tmp1neg = sub i8 0, %a +# GENERATED-NEXT: %b = icmp sgt i8 %a, -1 +# GENERATED-NEXT: %abs = select i1 %b, i8 %a, i8 %tmp1neg +# GENERATED-NEXT: ret i8 %abs +# GENERATED-NEXT: } +# GENERATED-EMPTY: +# GENERATED-NEXT: define i16 @test_i16(i16 %a) nounwind { +# GENERATED-NEXT: ; X86-NO-CMOV-LABEL: test_i16: +# GENERATED-NEXT: ; X86-NO-CMOV: # %bb.0: +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: movswl {{{{}}[0-9]+}}(%esp), %eax +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: movl %eax, %ecx +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: sarl $15, %ecx +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: addl %ecx, %eax +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: xorl %ecx, %eax +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: # kill: def $ax killed $ax killed $eax +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: retl +# GENERATED-NEXT: ; +# GENERATED-NEXT: ; X86-CMOV-LABEL: test_i16: +# GENERATED-NEXT: ; X86-CMOV: # %bb.0: +# GENERATED-NEXT: ; X86-CMOV-NEXT: movzwl {{{{}}[0-9]+}}(%esp), %ecx +# GENERATED-NEXT: ; X86-CMOV-NEXT: movl %ecx, %eax +# GENERATED-NEXT: ; X86-CMOV-NEXT: negw %ax +# GENERATED-NEXT: ; X86-CMOV-NEXT: cmovlw %cx, %ax +# GENERATED-NEXT: ; X86-CMOV-NEXT: retl +# GENERATED-NEXT: ; +# GENERATED-NEXT: ; X64-LABEL: test_i16: +# GENERATED-NEXT: ; X64: # %bb.0: +# GENERATED-NEXT: ; X64-NEXT: movl %edi, %eax +# GENERATED-NEXT: ; X64-NEXT: negw %ax +# GENERATED-NEXT: ; X64-NEXT: cmovlw %di, %ax +# GENERATED-NEXT: ; X64-NEXT: retq +# GENERATED-NEXT: %tmp1neg = sub i16 0, %a +# GENERATED-NEXT: %b = icmp sgt i16 %a, -1 +# GENERATED-NEXT: %abs = select i1 %b, i16 %a, i16 %tmp1neg +# GENERATED-NEXT: ret i16 %abs +# GENERATED-NEXT: } +# GENERATED-EMPTY: +# GENERATED-NEXT: define i32 @test_i32(i32 %a) nounwind { +# GENERATED-NEXT: ; X86-NO-CMOV-LABEL: test_i32: +# GENERATED-NEXT: ; X86-NO-CMOV: # %bb.0: +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: movl {{{{}}[0-9]+}}(%esp), %eax +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: movl %eax, %ecx +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: sarl $31, %ecx +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: addl %ecx, %eax +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: xorl %ecx, %eax +# GENERATED-NEXT: ; X86-NO-CMOV-NEXT: retl +# GENERATED-NEXT: ; +# GENERATED-NEXT: ; X86-CMOV-LABEL: test_i32: +# GENERATED-NEXT: ; X86-CMOV: # %bb.0: +# GENERATED-NEXT: ; X86-CMOV-NEXT: movl {{{{}}[0-9]+}}(%esp), %ecx +# GENERATED-NEXT: ; X86-CMOV-NEXT: movl %ecx, %eax +# GENERATED-NEXT: ; X86-CMOV-NEXT: negl %eax +# GENERATED-NEXT: ; X86-CMOV-NEXT: cmovll %ecx, %eax +# GENERATED-NEXT: ; X86-CMOV-NEXT: retl +# GENERATED-NEXT: ; +# GENERATED-NEXT: ; X64-LABEL: test_i32: +# GENERATED-NEXT: ; X64: # %bb.0: +# GENERATED-NEXT: ; X64-NEXT: movl %edi, %eax +# GENERATED-NEXT: ; X64-NEXT: negl %eax +# GENERATED-NEXT: ; X64-NEXT: cmovll %edi, %eax +# GENERATED-NEXT: ; X64-NEXT: retq +# GENERATED-NEXT: %tmp1neg = sub i32 0, %a +# GENERATED-NEXT: %b = icmp sgt i32 %a, -1 +# GENERATED-NEXT: %abs = select i1 %b, i32 %a, i32 %tmp1neg +# GENERATED-NEXT: ret i32 %abs +# GENERATED-NEXT: } +# GENERATED-EMPTY: +# GENERATED-NEXT: define i64 @test_i64(i64 %a) nounwind { +# GENERATED-NEXT: ; X86-LABEL: test_i64: +# GENERATED-NEXT: ; X86: # %bb.0: +# GENERATED-NEXT: ; X86-NEXT: movl {{{{}}[0-9]+}}(%esp), %edx +# GENERATED-NEXT: ; X86-NEXT: movl %edx, %ecx +# GENERATED-NEXT: ; X86-NEXT: sarl $31, %ecx +# GENERATED-NEXT: ; X86-NEXT: movl {{{{}}[0-9]+}}(%esp), %eax +# GENERATED-NEXT: ; X86-NEXT: addl %ecx, %eax +# GENERATED-NEXT: ; X86-NEXT: adcl %ecx, %edx +# GENERATED-NEXT: ; X86-NEXT: xorl %ecx, %edx +# GENERATED-NEXT: ; X86-NEXT: xorl %ecx, %eax +# GENERATED-NEXT: ; X86-NEXT: retl +# GENERATED-NEXT: ; +# GENERATED-NEXT: ; X64-LABEL: test_i64: +# GENERATED-NEXT: ; X64: # %bb.0: +# GENERATED-NEXT: ; X64-NEXT: movq %rdi, %rax +# GENERATED-NEXT: ; X64-NEXT: negq %rax +# GENERATED-NEXT: ; X64-NEXT: cmovlq %rdi, %rax +# GENERATED-NEXT: ; X64-NEXT: retq +# GENERATED-NEXT: %tmp1neg = sub i64 0, %a +# GENERATED-NEXT: %b = icmp sgt i64 %a, -1 +# GENERATED-NEXT: %abs = select i1 %b, i64 %a, i64 %tmp1neg +# GENERATED-NEXT: ret i64 %abs +# GENERATED-NEXT: } +# GENERATED-EMPTY: diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_tests/lit.local.cfg b/llvm/test/tools/UpdateTestChecks/update_llc_tests/lit.local.cfg new file mode 100644 --- /dev/null +++ b/llvm/test/tools/UpdateTestChecks/update_llc_tests/lit.local.cfg @@ -0,0 +1,3 @@ +# These tests require llc. +if 'llc-binary' not in config.available_features: + config.unsupported = True