2020-01-03 02:44:54 +08:00
|
|
|
#!/usr/bin/env python
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
'''A utility to update LLVM IR CHECK lines in C/C++ FileCheck test files.
|
|
|
|
|
|
|
|
Example RUN lines in .c/.cc test files:
|
|
|
|
|
|
|
|
// RUN: %clang -emit-llvm -S %s -o - -O2 | FileCheck %s
|
|
|
|
// RUN: %clangxx -emit-llvm -S %s -o - -O2 | FileCheck -check-prefix=CHECK-A %s
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
|
2019-11-15 20:50:10 +08:00
|
|
|
% utils/update_cc_test_checks.py --clang=release/bin/clang /tmp/c/a.cc
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
'''
|
|
|
|
|
2020-01-03 02:44:54 +08:00
|
|
|
from __future__ import print_function
|
|
|
|
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
import argparse
|
|
|
|
import collections
|
|
|
|
import distutils.spawn
|
2019-11-15 20:50:10 +08:00
|
|
|
import json
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
import string
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
from UpdateTestChecks import asm, common
|
|
|
|
|
|
|
|
ADVERT = '// NOTE: Assertions have been autogenerated by '
|
|
|
|
|
|
|
|
SUBST = {
|
|
|
|
'%clang': [],
|
|
|
|
'%clang_cc1': ['-cc1'],
|
|
|
|
'%clangxx': ['--driver-mode=g++'],
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_line2spell_and_mangled(args, clang_args):
|
|
|
|
ret = {}
|
2019-11-15 20:50:10 +08:00
|
|
|
# Use clang's JSON AST dump to get the mangled name
|
2020-01-03 02:44:54 +08:00
|
|
|
json_dump_args = [args.clang] + clang_args + ['-fsyntax-only', '-o', '-']
|
2019-11-15 20:50:10 +08:00
|
|
|
if '-cc1' not in json_dump_args:
|
|
|
|
# For tests that invoke %clang instead if %clang_cc1 we have to use
|
|
|
|
# -Xclang -ast-dump=json instead:
|
|
|
|
json_dump_args.append('-Xclang')
|
|
|
|
json_dump_args.append('-ast-dump=json')
|
2019-12-02 18:50:23 +08:00
|
|
|
common.debug('Running', ' '.join(json_dump_args))
|
2020-01-03 02:44:54 +08:00
|
|
|
|
|
|
|
popen = subprocess.Popen(json_dump_args, stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE, universal_newlines=True)
|
|
|
|
stdout, stderr = popen.communicate()
|
|
|
|
if popen.returncode != 0:
|
2019-11-15 20:50:10 +08:00
|
|
|
sys.stderr.write('Failed to run ' + ' '.join(json_dump_args) + '\n')
|
2020-01-03 02:44:54 +08:00
|
|
|
sys.stderr.write(stderr)
|
|
|
|
sys.stderr.write(stdout)
|
2019-11-15 20:50:10 +08:00
|
|
|
sys.exit(2)
|
|
|
|
|
2019-12-02 18:53:57 +08:00
|
|
|
# Parse the clang JSON and add all children of type FunctionDecl.
|
2019-11-15 20:50:10 +08:00
|
|
|
# TODO: Should we add checks for global variables being emitted?
|
2019-12-02 18:53:57 +08:00
|
|
|
def parse_clang_ast_json(node):
|
|
|
|
node_kind = node['kind']
|
|
|
|
# Recurse for the following nodes that can contain nested function decls:
|
|
|
|
if node_kind in ('NamespaceDecl', 'LinkageSpecDecl', 'TranslationUnitDecl'):
|
|
|
|
for inner in node['inner']:
|
|
|
|
parse_clang_ast_json(inner)
|
|
|
|
# Otherwise we ignore everything except functions:
|
2019-11-15 20:50:10 +08:00
|
|
|
if node['kind'] != 'FunctionDecl':
|
2019-12-02 18:53:57 +08:00
|
|
|
return
|
2019-11-15 20:50:10 +08:00
|
|
|
if node.get('isImplicit') is True and node.get('storageClass') == 'extern':
|
2019-12-02 18:50:23 +08:00
|
|
|
common.debug('Skipping builtin function:', node['name'], '@', node['loc'])
|
2019-12-02 18:53:57 +08:00
|
|
|
return
|
2019-12-02 18:50:23 +08:00
|
|
|
common.debug('Found function:', node['kind'], node['name'], '@', node['loc'])
|
2019-11-15 20:50:10 +08:00
|
|
|
line = node['loc'].get('line')
|
|
|
|
# If there is no line it is probably a builtin function -> skip
|
|
|
|
if line is None:
|
2019-12-02 18:50:23 +08:00
|
|
|
common.debug('Skipping function without line number:', node['name'], '@', node['loc'])
|
2019-12-02 18:53:57 +08:00
|
|
|
return
|
2019-11-15 20:50:10 +08:00
|
|
|
spell = node['name']
|
|
|
|
mangled = node.get('mangledName', spell)
|
|
|
|
ret[int(line)-1] = (spell, mangled)
|
2019-12-02 18:53:57 +08:00
|
|
|
|
2020-01-03 02:44:54 +08:00
|
|
|
ast = json.loads(stdout)
|
2019-12-02 18:53:57 +08:00
|
|
|
if ast['kind'] != 'TranslationUnitDecl':
|
|
|
|
common.error('Clang AST dump JSON format changed?')
|
|
|
|
sys.exit(2)
|
|
|
|
parse_clang_ast_json(ast)
|
|
|
|
|
2019-12-02 18:50:23 +08:00
|
|
|
for line, func_name in sorted(ret.items()):
|
|
|
|
common.debug('line {}: found function {}'.format(line+1, func_name), file=sys.stderr)
|
2019-11-15 20:50:10 +08:00
|
|
|
if not ret:
|
|
|
|
common.warn('Did not find any functions using', ' '.join(json_dump_args))
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def config():
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description=__doc__,
|
|
|
|
formatter_class=argparse.RawTextHelpFormatter)
|
|
|
|
parser.add_argument('--llvm-bin', help='llvm $prefix/bin path')
|
|
|
|
parser.add_argument('--clang',
|
|
|
|
help='"clang" executable, defaults to $llvm_bin/clang')
|
|
|
|
parser.add_argument('--clang-args',
|
|
|
|
help='Space-separated extra args to clang, e.g. --clang-args=-v')
|
2019-10-10 16:25:34 +08:00
|
|
|
parser.add_argument('--opt',
|
|
|
|
help='"opt" executable, defaults to $llvm_bin/opt')
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
parser.add_argument(
|
|
|
|
'--functions', nargs='+', help='A list of function name regexes. '
|
|
|
|
'If specified, update CHECK lines for functions matching at least one regex')
|
|
|
|
parser.add_argument(
|
|
|
|
'--x86_extra_scrub', action='store_true',
|
|
|
|
help='Use more regex for x86 matching to reduce diffs between various subtargets')
|
2019-11-20 21:20:15 +08:00
|
|
|
parser.add_argument('--function-signature', action='store_true',
|
|
|
|
help='Keep function signature information around for the check line')
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
parser.add_argument('tests', nargs='+')
|
2019-11-20 21:19:48 +08:00
|
|
|
args = common.parse_commandline_args(parser)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
args.clang_args = shlex.split(args.clang_args or '')
|
|
|
|
|
|
|
|
if args.clang is None:
|
|
|
|
if args.llvm_bin is None:
|
|
|
|
args.clang = 'clang'
|
|
|
|
else:
|
|
|
|
args.clang = os.path.join(args.llvm_bin, 'clang')
|
|
|
|
if not distutils.spawn.find_executable(args.clang):
|
|
|
|
print('Please specify --llvm-bin or --clang', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2019-10-10 16:25:34 +08:00
|
|
|
|
2019-11-01 05:18:32 +08:00
|
|
|
# Determine the builtin includes directory so that we can update tests that
|
|
|
|
# depend on the builtin headers. See get_clang_builtin_include_dir() and
|
|
|
|
# use_clang() in llvm/utils/lit/lit/llvm/config.py.
|
|
|
|
try:
|
|
|
|
builtin_include_dir = subprocess.check_output(
|
|
|
|
[args.clang, '-print-file-name=include']).decode().strip()
|
|
|
|
SUBST['%clang_cc1'] = ['-cc1', '-internal-isystem', builtin_include_dir,
|
|
|
|
'-nostdsysteminc']
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
common.warn('Could not determine clang builtins directory, some tests '
|
|
|
|
'might not update correctly.')
|
|
|
|
|
2019-10-10 16:25:34 +08:00
|
|
|
if args.opt is None:
|
|
|
|
if args.llvm_bin is None:
|
|
|
|
args.opt = 'opt'
|
|
|
|
else:
|
|
|
|
args.opt = os.path.join(args.llvm_bin, 'opt')
|
|
|
|
if not distutils.spawn.find_executable(args.opt):
|
|
|
|
# Many uses of this tool will not need an opt binary, because it's only
|
|
|
|
# needed for updating a test that runs clang | opt | FileCheck. So we
|
|
|
|
# defer this error message until we find that opt is actually needed.
|
|
|
|
args.opt = None
|
|
|
|
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
return args
|
|
|
|
|
|
|
|
|
2019-10-10 16:25:34 +08:00
|
|
|
def get_function_body(args, filename, clang_args, extra_commands, prefixes, triple_in_cmd, func_dict):
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
# TODO Clean up duplication of asm/common build_function_body_dictionary
|
|
|
|
# Invoke external tool and extract function bodies.
|
|
|
|
raw_tool_output = common.invoke_tool(args.clang, clang_args, filename)
|
2019-10-10 16:25:34 +08:00
|
|
|
for extra_command in extra_commands:
|
|
|
|
extra_args = shlex.split(extra_command)
|
|
|
|
with tempfile.NamedTemporaryFile() as f:
|
|
|
|
f.write(raw_tool_output.encode())
|
|
|
|
f.flush()
|
|
|
|
if extra_args[0] == 'opt':
|
|
|
|
if args.opt is None:
|
|
|
|
print(filename, 'needs to run opt. '
|
|
|
|
'Please specify --llvm-bin or --opt', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
extra_args[0] = args.opt
|
|
|
|
raw_tool_output = common.invoke_tool(extra_args[0],
|
|
|
|
extra_args[1:], f.name)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
if '-emit-llvm' in clang_args:
|
|
|
|
common.build_function_body_dictionary(
|
|
|
|
common.OPT_FUNCTION_RE, common.scrub_body, [],
|
2019-11-20 21:20:15 +08:00
|
|
|
raw_tool_output, prefixes, func_dict, args.verbose, args.function_signature)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
else:
|
|
|
|
print('The clang command line should include -emit-llvm as asm tests '
|
|
|
|
'are discouraged in Clang testsuite.', file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
args = config()
|
2019-08-07 22:44:50 +08:00
|
|
|
script_name = os.path.basename(__file__)
|
|
|
|
autogenerated_note = (ADVERT + 'utils/' + script_name)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
|
|
|
|
for filename in args.tests:
|
|
|
|
with open(filename) as f:
|
|
|
|
input_lines = [l.rstrip() for l in f]
|
2019-11-02 00:17:27 +08:00
|
|
|
|
2019-08-07 22:44:50 +08:00
|
|
|
first_line = input_lines[0] if input_lines else ""
|
|
|
|
if 'autogenerated' in first_line and script_name not in first_line:
|
|
|
|
common.warn("Skipping test which wasn't autogenerated by " + script_name, filename)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if args.update_only:
|
|
|
|
if not first_line or 'autogenerated' not in first_line:
|
|
|
|
common.warn("Skipping test which isn't autogenerated: " + filename)
|
|
|
|
continue
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
|
|
|
|
# Extract RUN lines.
|
2019-12-02 18:50:23 +08:00
|
|
|
run_lines = common.find_run_lines(filename, input_lines)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
|
|
|
|
# Build a list of clang command lines and check prefixes from RUN lines.
|
|
|
|
run_list = []
|
|
|
|
line2spell_and_mangled_list = collections.defaultdict(list)
|
|
|
|
for l in run_lines:
|
2019-10-10 16:25:34 +08:00
|
|
|
commands = [cmd.strip() for cmd in l.split('|')]
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
|
|
|
|
triple_in_cmd = None
|
|
|
|
m = common.TRIPLE_ARG_RE.search(commands[0])
|
|
|
|
if m:
|
|
|
|
triple_in_cmd = m.groups()[0]
|
|
|
|
|
|
|
|
# Apply %clang substitution rule, replace %s by `filename`, and append args.clang_args
|
|
|
|
clang_args = shlex.split(commands[0])
|
|
|
|
if clang_args[0] not in SUBST:
|
|
|
|
print('WARNING: Skipping non-clang RUN line: ' + l, file=sys.stderr)
|
|
|
|
continue
|
|
|
|
clang_args[0:1] = SUBST[clang_args[0]]
|
|
|
|
clang_args = [filename if i == '%s' else i for i in clang_args] + args.clang_args
|
|
|
|
|
2019-10-10 16:25:34 +08:00
|
|
|
# Permit piping the output through opt
|
|
|
|
if not (len(commands) == 2 or
|
|
|
|
(len(commands) == 3 and commands[1].startswith('opt'))):
|
|
|
|
print('WARNING: Skipping non-clang RUN line: ' + l, file=sys.stderr)
|
|
|
|
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
# Extract -check-prefix in FileCheck args
|
|
|
|
filecheck_cmd = commands[-1]
|
[UpdateTestChecks] Emit warning when invalid value for -check-prefix(es) option
Summary:
The script is silent for the following issue:
FileCheck %s -check-prefix=CHECK,POPCOUNT
FileCheck will catch it later, but I think we can warn here too.
Now it warns:
./update_llc_test_checks.py file.ll
WARNING: Supplied prefix 'CHECK,POPCOUNT' is invalid. Prefix must contain only alphanumeric characters, hyphens and underscores. Did you mean --check-prefixes=CHECK,POPCOUNT?
Reviewers: lebedev.ri, spatel, RKSimon, craig.topper, nikic, gbedwell
Reviewed By: RKSimon
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64589
llvm-svn: 367244
2019-07-30 01:41:00 +08:00
|
|
|
common.verify_filecheck_prefixes(filecheck_cmd)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
if not filecheck_cmd.startswith('FileCheck '):
|
|
|
|
print('WARNING: Skipping non-FileChecked RUN line: ' + l, file=sys.stderr)
|
|
|
|
continue
|
|
|
|
check_prefixes = [item for m in common.CHECK_PREFIX_RE.finditer(filecheck_cmd)
|
|
|
|
for item in m.group(1).split(',')]
|
|
|
|
if not check_prefixes:
|
|
|
|
check_prefixes = ['CHECK']
|
2019-10-10 16:25:34 +08:00
|
|
|
run_list.append((check_prefixes, clang_args, commands[1:-1], triple_in_cmd))
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
|
|
|
|
# Strip CHECK lines which are in `prefix_set`, update test file.
|
|
|
|
prefix_set = set([prefix for p in run_list for prefix in p[0]])
|
|
|
|
input_lines = []
|
|
|
|
with open(filename, 'r+') as f:
|
|
|
|
for line in f:
|
2019-12-03 02:18:47 +08:00
|
|
|
m = common.CHECK_RE.match(line)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
if not (m and m.group(1) in prefix_set) and line != '//\n':
|
|
|
|
input_lines.append(line)
|
|
|
|
f.seek(0)
|
|
|
|
f.writelines(input_lines)
|
|
|
|
f.truncate()
|
|
|
|
|
|
|
|
# Execute clang, generate LLVM IR, and extract functions.
|
|
|
|
func_dict = {}
|
|
|
|
for p in run_list:
|
|
|
|
prefixes = p[0]
|
|
|
|
for prefix in prefixes:
|
|
|
|
func_dict.update({prefix: dict()})
|
2019-10-10 16:25:34 +08:00
|
|
|
for prefixes, clang_args, extra_commands, triple_in_cmd in run_list:
|
2019-12-02 18:50:23 +08:00
|
|
|
common.debug('Extracted clang cmd: clang {}'.format(clang_args))
|
|
|
|
common.debug('Extracted FileCheck prefixes: {}'.format(prefixes))
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
|
2019-10-10 16:25:34 +08:00
|
|
|
get_function_body(args, filename, clang_args, extra_commands, prefixes, triple_in_cmd, func_dict)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
|
2019-11-15 20:50:10 +08:00
|
|
|
# Invoke clang -Xclang -ast-dump=json to get mapping from start lines to
|
|
|
|
# mangled names. Forward all clang args for now.
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
for k, v in get_line2spell_and_mangled(args, clang_args).items():
|
|
|
|
line2spell_and_mangled_list[k].append(v)
|
|
|
|
|
|
|
|
output_lines = [autogenerated_note]
|
|
|
|
for idx, line in enumerate(input_lines):
|
|
|
|
# Discard any previous script advertising.
|
|
|
|
if line.startswith(ADVERT):
|
|
|
|
continue
|
|
|
|
if idx in line2spell_and_mangled_list:
|
|
|
|
added = set()
|
|
|
|
for spell, mangled in line2spell_and_mangled_list[idx]:
|
|
|
|
# One line may contain multiple function declarations.
|
|
|
|
# Skip if the mangled name has been added before.
|
|
|
|
# The line number may come from an included file,
|
|
|
|
# we simply require the spelling name to appear on the line
|
|
|
|
# to exclude functions from other files.
|
|
|
|
if mangled in added or spell not in line:
|
|
|
|
continue
|
|
|
|
if args.functions is None or any(re.search(regex, spell) for regex in args.functions):
|
|
|
|
if added:
|
|
|
|
output_lines.append('//')
|
|
|
|
added.add(mangled)
|
2019-11-20 21:20:15 +08:00
|
|
|
common.add_ir_checks(output_lines, '//', run_list, func_dict, mangled,
|
|
|
|
False, args.function_signature)
|
[utils] Add utils/update_cc_test_checks.py
A utility to update LLVM IR in C/C++ FileCheck test files.
Example RUN lines in .c/.cc test files:
// RUN: %clang -S -Os -DXX %s -o - | FileCheck %s
// RUN: %clangxx -S -Os %s -o - | FileCheck -check-prefix=IR %s
Usage:
% utils/update_cc_test_checks.py --llvm-bin=release/bin test/a.cc
% utils/update_cc_test_checks.py --c-index-test=release/bin/c-index-test --clang=release/bin/clang /tmp/c/a.cc
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang -emit-llvm -S -Os -DXX %s -o - | FileCheck -check-prefix=AA %s
// RUN: %clangxx -emit-llvm -S -Os %s -o - | FileCheck -check-prefix=BB %s
using T =
#ifdef XX
int __attribute__((vector_size(16)))
#else
short __attribute__((vector_size(16)))
#endif
;
// AA-LABEL: _Z3fooDv4_i:
// AA: entry:
// AA-NEXT: %add = shl <4 x i32> %a, <i32 1, i32 1, i32 1, i32 1>
// AA-NEXT: ret <4 x i32> %add
//
// BB-LABEL: _Z3fooDv8_s:
// BB: entry:
// BB-NEXT: %add = shl <8 x i16> %a, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
// BB-NEXT: ret <8 x i16> %add
T foo(T a) {
return a + a;
}
Differential Revision: https://reviews.llvm.org/D42712
llvm-svn: 326591
2018-03-03 01:37:04 +08:00
|
|
|
output_lines.append(line.rstrip('\n'))
|
|
|
|
|
|
|
|
# Update the test file.
|
|
|
|
with open(filename, 'w') as f:
|
|
|
|
for line in output_lines:
|
|
|
|
f.write(line + '\n')
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|