2022-07-13 13:02:32 -07:00
|
|
|
#!/usr/bin/env python3
|
[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-02 17:37:04 +00: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 12:50:10 +00:00
|
|
|
% utils/update_cc_test_checks.py --clang=release/bin/clang /tmp/c/a.cc
|
2023-05-15 11:02:42 +02:00
|
|
|
"""
|
[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-02 17:37:04 +00:00
|
|
|
|
2020-01-02 13:44:54 -05: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-02 17:37:04 +00:00
|
|
|
import argparse
|
|
|
|
import collections
|
2019-11-15 12:50:10 +00: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-02 17:37:04 +00:00
|
|
|
import os
|
2020-07-08 10:59:50 +01:00
|
|
|
import re
|
[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-02 17:37:04 +00:00
|
|
|
import shlex
|
2022-09-21 10:55:33 -07:00
|
|
|
import shutil
|
[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-02 17:37:04 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
|
2020-07-08 10:59:50 +01:00
|
|
|
from UpdateTestChecks import common
|
[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-02 17:37:04 +00:00
|
|
|
|
|
|
|
SUBST = {
|
|
|
|
"%clang": [],
|
|
|
|
"%clang_cc1": ["-cc1"],
|
|
|
|
"%clangxx": ["--driver-mode=g++"],
|
|
|
|
}
|
|
|
|
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2025-01-13 11:24:05 +00:00
|
|
|
def get_line2func_list(args, clang_args, globals_name_prefix):
|
2021-07-28 14:49:17 +01:00
|
|
|
ret = collections.defaultdict(list)
|
2019-11-15 12:50:10 +00:00
|
|
|
# Use clang's JSON AST dump to get the mangled name
|
2020-01-02 13:44:54 -05:00
|
|
|
json_dump_args = [args.clang] + clang_args + ["-fsyntax-only", "-o", "-"]
|
2019-11-15 12:50:10 +00: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 10:50:23 +00:00
|
|
|
common.debug("Running", " ".join(json_dump_args))
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-01-02 13:44:54 -05: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 12:50:10 +00:00
|
|
|
sys.stderr.write("Failed to run " + " ".join(json_dump_args) + "\n")
|
2020-01-02 13:44:54 -05:00
|
|
|
sys.stderr.write(stderr)
|
|
|
|
sys.stderr.write(stdout)
|
2019-11-15 12:50:10 +00:00
|
|
|
sys.exit(2)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2019-12-02 10:53:57 +00:00
|
|
|
# Parse the clang JSON and add all children of type FunctionDecl.
|
2019-11-15 12:50:10 +00:00
|
|
|
# TODO: Should we add checks for global variables being emitted?
|
2021-07-28 14:49:17 +01:00
|
|
|
def parse_clang_ast_json(node, loc, search):
|
2019-12-02 10:53:57 +00:00
|
|
|
node_kind = node["kind"]
|
|
|
|
# Recurse for the following nodes that can contain nested function decls:
|
2020-06-18 15:11:08 +01:00
|
|
|
if node_kind in (
|
|
|
|
"NamespaceDecl",
|
|
|
|
"LinkageSpecDecl",
|
|
|
|
"TranslationUnitDecl",
|
2021-07-28 14:49:17 +01:00
|
|
|
"CXXRecordDecl",
|
|
|
|
"ClassTemplateSpecializationDecl",
|
|
|
|
):
|
|
|
|
# Specializations must use the loc from the specialization, not the
|
|
|
|
# template, and search for the class's spelling as the specialization
|
|
|
|
# does not mention the method names in the source.
|
|
|
|
if node_kind == "ClassTemplateSpecializationDecl":
|
|
|
|
inner_loc = node["loc"]
|
|
|
|
inner_search = node["name"]
|
|
|
|
else:
|
|
|
|
inner_loc = None
|
|
|
|
inner_search = None
|
2020-06-18 15:11:08 +01:00
|
|
|
if "inner" in node:
|
|
|
|
for inner in node["inner"]:
|
2021-07-28 14:49:17 +01:00
|
|
|
parse_clang_ast_json(inner, inner_loc, inner_search)
|
2019-12-02 10:53:57 +00:00
|
|
|
# Otherwise we ignore everything except functions:
|
2020-06-18 15:11:08 +01:00
|
|
|
if node_kind not in (
|
|
|
|
"FunctionDecl",
|
|
|
|
"CXXMethodDecl",
|
|
|
|
"CXXConstructorDecl",
|
|
|
|
"CXXDestructorDecl",
|
|
|
|
"CXXConversionDecl",
|
|
|
|
):
|
2019-12-02 10:53:57 +00:00
|
|
|
return
|
2021-07-28 14:49:17 +01:00
|
|
|
if loc is None:
|
|
|
|
loc = node["loc"]
|
2019-11-15 12:50:10 +00:00
|
|
|
if node.get("isImplicit") is True and node.get("storageClass") == "extern":
|
2021-07-28 14:49:17 +01:00
|
|
|
common.debug("Skipping builtin function:", node["name"], "@", loc)
|
2019-12-02 10:53:57 +00:00
|
|
|
return
|
2021-07-28 14:49:17 +01:00
|
|
|
common.debug("Found function:", node["kind"], node["name"], "@", loc)
|
|
|
|
line = loc.get("line")
|
2019-11-15 12:50:10 +00:00
|
|
|
# If there is no line it is probably a builtin function -> skip
|
|
|
|
if line is None:
|
2021-07-28 14:49:17 +01:00
|
|
|
common.debug(
|
|
|
|
"Skipping function without line number:", node["name"], "@", loc
|
|
|
|
)
|
2019-12-02 10:53:57 +00:00
|
|
|
return
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-06-18 15:10:54 +01:00
|
|
|
# If there is no 'inner' object, it is a function declaration and we can
|
|
|
|
# skip it. However, function declarations may also contain an 'inner' list,
|
|
|
|
# but in that case it will only contains ParmVarDecls. If we find an entry
|
|
|
|
# that is not a ParmVarDecl, we know that this is a function definition.
|
|
|
|
has_body = False
|
|
|
|
if "inner" in node:
|
|
|
|
for i in node["inner"]:
|
|
|
|
if i.get("kind", "ParmVarDecl") != "ParmVarDecl":
|
|
|
|
has_body = True
|
|
|
|
break
|
|
|
|
if not has_body:
|
2021-07-28 14:49:17 +01:00
|
|
|
common.debug("Skipping function without body:", node["name"], "@", loc)
|
2020-02-04 08:40:56 +00:00
|
|
|
return
|
2019-11-15 12:50:10 +00:00
|
|
|
spell = node["name"]
|
2021-07-28 14:49:17 +01:00
|
|
|
if search is None:
|
|
|
|
search = spell
|
2019-11-15 12:50:10 +00:00
|
|
|
mangled = node.get("mangledName", spell)
|
2025-01-13 11:24:05 +00:00
|
|
|
# Clang's AST dump includes the globals prefix, but when Clang emits
|
|
|
|
# LLVM IR this is not included and instead added as part of the asm
|
|
|
|
# output. Strip it from the mangled name of globals when needed
|
|
|
|
# (see DataLayout::getGlobalPrefix()).
|
|
|
|
if globals_name_prefix:
|
|
|
|
storage = node.get("storageClass", None)
|
|
|
|
if storage != "static" and mangled[0] == globals_name_prefix:
|
|
|
|
mangled = mangled[1:]
|
2021-07-28 14:49:17 +01:00
|
|
|
ret[int(line) - 1].append((spell, mangled, search))
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-01-02 13:44:54 -05:00
|
|
|
ast = json.loads(stdout)
|
2019-12-02 10:53:57 +00:00
|
|
|
if ast["kind"] != "TranslationUnitDecl":
|
|
|
|
common.error("Clang AST dump JSON format changed?")
|
|
|
|
sys.exit(2)
|
2021-07-28 14:49:17 +01:00
|
|
|
parse_clang_ast_json(ast, None, None)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2021-07-28 14:49:17 +01:00
|
|
|
for line, funcs in sorted(ret.items()):
|
|
|
|
for func in funcs:
|
|
|
|
common.debug(
|
|
|
|
"line {}: found function {}".format(line + 1, func), file=sys.stderr
|
|
|
|
)
|
2019-11-15 12:50:10 +00: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-02 17:37:04 +00:00
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2020-07-08 10:59:50 +01:00
|
|
|
def str_to_commandline(value):
|
|
|
|
if not value:
|
|
|
|
return []
|
|
|
|
return shlex.split(value)
|
|
|
|
|
2020-08-03 11:18:01 +01:00
|
|
|
|
|
|
|
def infer_dependent_args(args):
|
|
|
|
if not args.clang:
|
|
|
|
if not args.llvm_bin:
|
|
|
|
args.clang = "clang"
|
|
|
|
else:
|
|
|
|
args.clang = os.path.join(args.llvm_bin, "clang")
|
|
|
|
if not args.opt:
|
|
|
|
if not args.llvm_bin:
|
|
|
|
args.opt = "opt"
|
|
|
|
else:
|
|
|
|
args.opt = os.path.join(args.llvm_bin, "opt")
|
|
|
|
|
|
|
|
|
2022-09-21 10:55:33 -07:00
|
|
|
def find_executable(executable):
|
|
|
|
_, ext = os.path.splitext(executable)
|
|
|
|
if sys.platform == "win32" and ext != ".exe":
|
|
|
|
executable = executable + ".exe"
|
|
|
|
|
|
|
|
return shutil.which(executable)
|
|
|
|
|
|
|
|
|
[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-02 17:37:04 +00:00
|
|
|
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'
|
|
|
|
)
|
2020-07-08 10:59:50 +01:00
|
|
|
parser.add_argument(
|
|
|
|
"--clang-args",
|
|
|
|
default=[],
|
|
|
|
type=str_to_commandline,
|
[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-02 17:37:04 +00:00
|
|
|
help="Space-separated extra args to clang, e.g. --clang-args=-v",
|
|
|
|
)
|
2019-10-10 08:25:34 +00: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-02 17:37:04 +00: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 13:20:15 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--function-signature",
|
|
|
|
action="store_true",
|
|
|
|
help="Keep function signature information around for the check line",
|
|
|
|
)
|
2020-07-11 21:53:50 +02:00
|
|
|
parser.add_argument(
|
|
|
|
"--check-attributes",
|
|
|
|
action="store_true",
|
|
|
|
help='Check "Function Attributes" for functions',
|
|
|
|
)
|
2021-06-25 12:40:04 -04:00
|
|
|
parser.add_argument(
|
|
|
|
"--check-globals",
|
2023-11-13 14:45:27 +01:00
|
|
|
nargs="?",
|
|
|
|
const="all",
|
|
|
|
default="default",
|
|
|
|
choices=["none", "smart", "all"],
|
2021-06-25 12:40:04 -04:00
|
|
|
help="Check global entries (global variables, metadata, attribute sets, ...) for functions",
|
|
|
|
)
|
[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-02 17:37:04 +00:00
|
|
|
parser.add_argument("tests", nargs="+")
|
2019-11-20 13:19:48 +00:00
|
|
|
args = common.parse_commandline_args(parser)
|
2020-08-03 11:18:01 +01:00
|
|
|
infer_dependent_args(args)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-09-21 10:55:33 -07:00
|
|
|
if not find_executable(args.clang):
|
[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-02 17:37:04 +00:00
|
|
|
print("Please specify --llvm-bin or --clang", file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2019-10-31 21:18:32 +00: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()
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2019-10-31 21:18:32 +00:00
|
|
|
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."
|
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-09-21 10:55:33 -07:00
|
|
|
if not find_executable(args.opt):
|
2019-10-10 08:25:34 +00:00
|
|
|
# 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
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-07-08 10:59:50 +01:00
|
|
|
return args, parser
|
2023-05-15 11:02:42 +02:00
|
|
|
|
|
|
|
|
2025-01-13 11:24:05 +00:00
|
|
|
def get_function_body(
|
|
|
|
builder, args, filename, clang_args, extra_commands, prefixes, raw_tool_output
|
|
|
|
):
|
[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-02 17:37:04 +00:00
|
|
|
# TODO Clean up duplication of asm/common build_function_body_dictionary
|
2019-10-10 08:25:34 +00: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-02 17:37:04 +00:00
|
|
|
if "-emit-llvm" in clang_args:
|
2020-12-16 10:20:12 -08:00
|
|
|
builder.process_run_line(
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
common.OPT_FUNCTION_RE, common.scrub_body, raw_tool_output, prefixes
|
2021-07-29 12:55:34 +02:00
|
|
|
)
|
2022-07-19 09:43:58 +02:00
|
|
|
builder.processed_prefixes(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-02 17:37:04 +00: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)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
[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-02 17:37:04 +00:00
|
|
|
|
2021-02-19 10:45:40 -08:00
|
|
|
def exec_run_line(exe):
|
|
|
|
popen = subprocess.Popen(
|
|
|
|
exe, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
|
|
|
|
)
|
|
|
|
stdout, stderr = popen.communicate()
|
|
|
|
if popen.returncode != 0:
|
|
|
|
sys.stderr.write("Failed to run " + " ".join(exe) + "\n")
|
|
|
|
sys.stderr.write(stderr)
|
|
|
|
sys.stderr.write(stdout)
|
|
|
|
sys.exit(3)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
[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-02 17:37:04 +00:00
|
|
|
|
|
|
|
def main():
|
2020-07-08 10:59:50 +01:00
|
|
|
initial_args, parser = config()
|
2019-08-07 14:44:50 +00:00
|
|
|
script_name = os.path.basename(__file__)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-07-08 10:59:50 +01:00
|
|
|
for ti in common.itertests(
|
|
|
|
initial_args.tests,
|
|
|
|
parser,
|
|
|
|
"utils/" + script_name,
|
2020-08-03 11:18:01 +01:00
|
|
|
comment_prefix="//",
|
|
|
|
argparse_callback=infer_dependent_args,
|
|
|
|
):
|
2021-04-30 21:48:32 -07:00
|
|
|
# Build a list of filechecked and non-filechecked RUN 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-02 17:37:04 +00:00
|
|
|
run_list = []
|
2021-07-28 14:49:17 +01:00
|
|
|
line2func_list = collections.defaultdict(list)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2021-03-16 07:41:39 -07:00
|
|
|
subs = {
|
|
|
|
"%s": ti.path,
|
|
|
|
"%t": tempfile.NamedTemporaryFile().name,
|
2022-03-21 13:20:32 +01:00
|
|
|
"%S": os.path.dirname(ti.path),
|
2021-03-16 07:41:39 -07:00
|
|
|
}
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-07-08 10:59:50 +01:00
|
|
|
for l in ti.run_lines:
|
2019-10-10 08:25:34 +00:00
|
|
|
commands = [cmd.strip() for cmd in l.split("|")]
|
2023-05-15 11:02:42 +02:00
|
|
|
|
[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-02 17:37:04 +00:00
|
|
|
triple_in_cmd = None
|
|
|
|
m = common.TRIPLE_ARG_RE.search(commands[0])
|
|
|
|
if m:
|
|
|
|
triple_in_cmd = m.groups()[0]
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2021-02-19 10:45:40 -08:00
|
|
|
# Parse executable args.
|
|
|
|
exec_args = shlex.split(commands[0])
|
|
|
|
# Execute non-clang runline.
|
|
|
|
if exec_args[0] not in SUBST:
|
2021-03-16 07:41:39 -07:00
|
|
|
# Do lit-like substitutions.
|
|
|
|
for s in subs:
|
|
|
|
exec_args = [
|
|
|
|
i.replace(s, subs[s]) if s in i else i for i in exec_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-02 17:37:04 +00:00
|
|
|
]
|
2021-04-30 21:48:32 -07:00
|
|
|
run_list.append((None, exec_args, None, 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-02 17:37:04 +00:00
|
|
|
continue
|
2021-03-16 07:41:39 -07:00
|
|
|
# This is a clang runline, apply %clang substitution rule, do lit-like substitutions,
|
2021-02-19 10:45:40 -08:00
|
|
|
# and append args.clang_args
|
2023-02-04 09:35:32 +08:00
|
|
|
clang_args = exec_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-02 17:37:04 +00:00
|
|
|
clang_args[0:1] = SUBST[clang_args[0]]
|
2021-03-16 07:41:39 -07:00
|
|
|
for s in subs:
|
2021-02-19 10:45:40 -08:00
|
|
|
clang_args = [
|
2021-03-16 07:41:39 -07:00
|
|
|
i.replace(s, subs[s]) if s in i else i for i in clang_args
|
2023-05-15 11:02:42 +02:00
|
|
|
]
|
2021-03-16 07:41:39 -07:00
|
|
|
clang_args += ti.args.clang_args
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2023-02-04 09:35:32 +08:00
|
|
|
# Extract -check-prefix in FileCheck args
|
|
|
|
filecheck_cmd = commands[-1]
|
|
|
|
common.verify_filecheck_prefixes(filecheck_cmd)
|
2019-10-10 08:25:34 +00:00
|
|
|
if not filecheck_cmd.startswith("FileCheck "):
|
2021-04-30 21:48:32 -07:00
|
|
|
# Execute non-filechecked clang runline.
|
2020-12-16 10:20:12 -08:00
|
|
|
exe = [ti.args.clang] + clang_args
|
2021-04-30 21:48:32 -07:00
|
|
|
run_list.append((None, exe, None, None))
|
|
|
|
continue
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2021-04-30 21:48:32 -07:00
|
|
|
check_prefixes = common.get_check_prefixes(filecheck_cmd)
|
|
|
|
run_list.append((check_prefixes, clang_args, commands[1:-1], triple_in_cmd))
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2021-03-16 07:41:39 -07:00
|
|
|
# Execute clang, generate LLVM IR, and extract functions.
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2019-11-15 12:50:10 +00:00
|
|
|
# Store only filechecked runlines.
|
|
|
|
filecheck_run_list = [i for i in run_list if i[0]]
|
2025-02-19 20:29:51 -05:00
|
|
|
ginfo = common.make_ir_generalizer(
|
|
|
|
ti.args.version, ti.args.check_globals == "none"
|
|
|
|
)
|
2021-07-28 14:49:17 +01:00
|
|
|
builder = common.FunctionTestBuilder(
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
run_list=filecheck_run_list,
|
|
|
|
flags=ti.args,
|
|
|
|
scrubber_args=[],
|
|
|
|
path=ti.path,
|
|
|
|
ginfo=ginfo,
|
2021-07-28 14:49:17 +01:00
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2021-04-30 21:48:32 -07:00
|
|
|
for prefixes, args, extra_commands, triple_in_cmd in run_list:
|
|
|
|
# Execute non-filechecked runline.
|
|
|
|
if not prefixes:
|
|
|
|
print(
|
|
|
|
"NOTE: Executing non-FileChecked RUN line: " + " ".join(args),
|
|
|
|
file=sys.stderr,
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2021-04-30 21:48:32 -07:00
|
|
|
exec_run_line(args)
|
2023-05-15 11:02:42 +02:00
|
|
|
continue
|
|
|
|
|
2021-04-30 21:48:32 -07:00
|
|
|
clang_args = args
|
2019-12-02 10:50:23 +00:00
|
|
|
common.debug("Extracted clang cmd: clang {}".format(clang_args))
|
2021-04-30 21:48:32 -07:00
|
|
|
common.debug("Extracted FileCheck prefixes: {}".format(prefixes))
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2025-01-13 11:24:05 +00:00
|
|
|
# Invoke external tool and extract function bodies.
|
|
|
|
raw_tool_output = common.invoke_tool(ti.args.clang, clang_args, ti.path)
|
2021-06-25 12:40:04 -04:00
|
|
|
get_function_body(
|
2025-01-13 11:24:05 +00:00
|
|
|
builder,
|
|
|
|
ti.args,
|
|
|
|
ti.path,
|
|
|
|
clang_args,
|
|
|
|
extra_commands,
|
|
|
|
prefixes,
|
|
|
|
raw_tool_output,
|
2020-01-13 12:16:35 -06:00
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-01-13 12:16:35 -06:00
|
|
|
# Invoke clang -Xclang -ast-dump=json to get mapping from start lines to
|
|
|
|
# mangled names. Forward all clang args for now.
|
2025-01-13 11:24:05 +00:00
|
|
|
for k, v in get_line2func_list(
|
|
|
|
ti.args, clang_args, common.get_globals_name_prefix(raw_tool_output)
|
|
|
|
).items():
|
[UpdateTestChecks] Auto-generate stub bodies for unused prefixes
This is scoped to autogenerated tests.
The goal is to support having each RUN line specify a list of
check-prefixes where one can specify potentially redundant prefixes. For example,
for X86, if one specified prefixes for both AVX1 and AVX2, and the codegen happened to
match today, one of the prefixes would be used and the onther one not.
If the unused prefix were dropped, and later, codegen differences were
introduced, one would have to go figure out where to add what prefix
(paraphrasing
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
To avoid getting errors due to unused prefixes, whole directories can be
opted out (as discussed on that thread), but that means that tests that
aren't autogenerated in such directories could have undetected unused
prefix bugs.
This patch proposes an alternative that both avoids the above, dir-level
optout, and supports the main autogen scenario discussed first. The autogen
tool appends at the end of the test file the list of unused prefixes,
together with a note explaining that is the case. Each prefix is set up
to always pass.
This way, unexpected unused prefixes are easily discoverable, and
expected cases "just work".
Differential Revision: https://reviews.llvm.org/D124306
2022-04-22 12:49:15 -07:00
|
|
|
line2func_list[k].extend(v)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
[UpdateTestChecks] Auto-generate stub bodies for unused prefixes
This is scoped to autogenerated tests.
The goal is to support having each RUN line specify a list of
check-prefixes where one can specify potentially redundant prefixes. For example,
for X86, if one specified prefixes for both AVX1 and AVX2, and the codegen happened to
match today, one of the prefixes would be used and the onther one not.
If the unused prefix were dropped, and later, codegen differences were
introduced, one would have to go figure out where to add what prefix
(paraphrasing
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
To avoid getting errors due to unused prefixes, whole directories can be
opted out (as discussed on that thread), but that means that tests that
aren't autogenerated in such directories could have undetected unused
prefix bugs.
This patch proposes an alternative that both avoids the above, dir-level
optout, and supports the main autogen scenario discussed first. The autogen
tool appends at the end of the test file the list of unused prefixes,
together with a note explaining that is the case. Each prefix is set up
to always pass.
This way, unexpected unused prefixes are easily discoverable, and
expected cases "just work".
Differential Revision: https://reviews.llvm.org/D124306
2022-04-22 12:49:15 -07:00
|
|
|
func_dict = builder.finish_and_get_func_dict()
|
|
|
|
global_vars_seen_dict = {}
|
|
|
|
prefix_set = set([prefix for p in filecheck_run_list for prefix in p[0]])
|
|
|
|
output_lines = []
|
|
|
|
has_checked_pre_function_globals = False
|
2023-05-15 11:02:42 +02:00
|
|
|
|
[UpdateTestChecks] Auto-generate stub bodies for unused prefixes
This is scoped to autogenerated tests.
The goal is to support having each RUN line specify a list of
check-prefixes where one can specify potentially redundant prefixes. For example,
for X86, if one specified prefixes for both AVX1 and AVX2, and the codegen happened to
match today, one of the prefixes would be used and the onther one not.
If the unused prefix were dropped, and later, codegen differences were
introduced, one would have to go figure out where to add what prefix
(paraphrasing
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
To avoid getting errors due to unused prefixes, whole directories can be
opted out (as discussed on that thread), but that means that tests that
aren't autogenerated in such directories could have undetected unused
prefix bugs.
This patch proposes an alternative that both avoids the above, dir-level
optout, and supports the main autogen scenario discussed first. The autogen
tool appends at the end of the test file the list of unused prefixes,
together with a note explaining that is the case. Each prefix is set up
to always pass.
This way, unexpected unused prefixes are easily discoverable, and
expected cases "just work".
Differential Revision: https://reviews.llvm.org/D124306
2022-04-22 12:49:15 -07:00
|
|
|
include_generated_funcs = common.find_arg_in_test(
|
2023-05-15 11:02:42 +02:00
|
|
|
ti,
|
2021-06-25 12:40:04 -04:00
|
|
|
lambda args: ti.args.include_generated_funcs,
|
2022-11-28 10:02:14 -08:00
|
|
|
"--include-generated-funcs",
|
2023-05-15 11:02:42 +02:00
|
|
|
True,
|
|
|
|
)
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes = []
|
|
|
|
if include_generated_funcs:
|
|
|
|
# Generate the appropriate checks for each function. We need to emit
|
|
|
|
# these in the order according to the generated output so that CHECK-LABEL
|
|
|
|
# works properly. func_order provides that.
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-11-28 10:02:14 -08:00
|
|
|
# It turns out that when clang generates functions (for example, with
|
|
|
|
# -fopenmp), it can sometimes cause functions to be re-ordered in the
|
|
|
|
# output, even functions that exist in the source file. Therefore we
|
|
|
|
# can't insert check lines before each source function and instead have to
|
2020-01-13 12:16:35 -06:00
|
|
|
# put them at the end. So the first thing to do is dump out the source
|
2023-05-15 11:02:42 +02:00
|
|
|
# lines.
|
2022-11-28 10:02:14 -08:00
|
|
|
common.dump_input_lines(output_lines, ti, prefix_set, "//")
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2022-11-28 10:02:14 -08:00
|
|
|
# Now generate all the checks.
|
|
|
|
def check_generator(my_output_lines, prefixes, func):
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
return common.add_ir_checks(
|
|
|
|
my_output_lines,
|
|
|
|
"//",
|
|
|
|
prefixes,
|
|
|
|
func_dict,
|
|
|
|
func,
|
|
|
|
False,
|
|
|
|
ti.args.function_signature,
|
|
|
|
ginfo,
|
|
|
|
global_vars_seen_dict,
|
|
|
|
is_filtered=builder.is_filtered(),
|
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2023-11-13 14:45:27 +01:00
|
|
|
if ti.args.check_globals != 'none':
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes.extend(
|
|
|
|
common.add_global_checks(
|
|
|
|
builder.global_var_dict(),
|
|
|
|
"//",
|
|
|
|
run_list,
|
|
|
|
output_lines,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2022-11-28 10:02:14 -08:00
|
|
|
global_vars_seen_dict,
|
2023-11-13 14:45:27 +01:00
|
|
|
False,
|
2022-11-28 10:02:14 -08:00
|
|
|
True,
|
2023-11-13 14:45:27 +01:00
|
|
|
ti.args.check_globals,
|
2022-11-28 10:02:14 -08:00
|
|
|
)
|
2020-01-13 12:16:35 -06:00
|
|
|
)
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes.extend(
|
|
|
|
common.add_checks_at_end(
|
2020-01-13 12:16:35 -06:00
|
|
|
output_lines,
|
2021-04-30 21:48:32 -07:00
|
|
|
filecheck_run_list,
|
2020-12-16 10:20:12 -08:00
|
|
|
builder.func_order(),
|
2023-05-15 11:02:42 +02:00
|
|
|
"//",
|
2022-11-28 10:02:14 -08:00
|
|
|
lambda my_output_lines, prefixes, func: check_generator(
|
2020-01-13 12:16:35 -06:00
|
|
|
my_output_lines, prefixes, func
|
2023-05-15 11:02:42 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
2020-01-13 12:16:35 -06:00
|
|
|
# Normal mode. Put checks before each source function.
|
|
|
|
for line_info in ti.iterlines(output_lines):
|
|
|
|
idx = line_info.line_number
|
|
|
|
line = line_info.line
|
|
|
|
args = line_info.args
|
|
|
|
include_line = True
|
|
|
|
m = common.CHECK_RE.match(line)
|
|
|
|
if m and m.group(1) in prefix_set:
|
|
|
|
continue # Don't append the existing CHECK lines
|
2021-06-25 12:40:04 -04:00
|
|
|
# Skip special separator comments added by commmon.add_global_checks.
|
|
|
|
if line.strip() == "//" + common.SEPARATOR:
|
2023-05-15 11:02:42 +02:00
|
|
|
continue
|
2021-07-28 14:49:17 +01:00
|
|
|
if idx in line2func_list:
|
2020-01-13 12:16:35 -06:00
|
|
|
added = set()
|
2021-07-28 14:49:17 +01:00
|
|
|
for spell, mangled, search in line2func_list[idx]:
|
2020-01-13 12:16:35 -06:00
|
|
|
# One line may contain multiple function declarations.
|
|
|
|
# Skip if the mangled name has been added before.
|
2021-07-28 14:49:17 +01:00
|
|
|
# The line number may come from an included file, we simply require
|
|
|
|
# the search string (normally the function's spelling name, but is
|
|
|
|
# the class's spelling name for class specializations) to appear on
|
|
|
|
# the line to exclude functions from other files.
|
|
|
|
if mangled in added or search not in line:
|
2023-05-15 11:02:42 +02:00
|
|
|
continue
|
2020-01-13 12:16:35 -06:00
|
|
|
if args.functions is None or any(
|
|
|
|
re.search(regex, spell) for regex in args.functions
|
2023-05-15 11:02:42 +02:00
|
|
|
):
|
2020-01-13 12:16:35 -06:00
|
|
|
last_line = output_lines[-1].strip()
|
|
|
|
while last_line == "//":
|
|
|
|
# Remove the comment line since we will generate a new comment
|
2022-11-28 10:02:14 -08:00
|
|
|
# line as part of common.add_ir_checks()
|
|
|
|
output_lines.pop()
|
|
|
|
last_line = output_lines[-1].strip()
|
2023-05-15 11:02:42 +02:00
|
|
|
if (
|
2023-11-13 14:45:27 +01:00
|
|
|
ti.args.check_globals != 'none'
|
2022-11-28 10:02:14 -08:00
|
|
|
and not has_checked_pre_function_globals
|
2023-05-15 11:02:42 +02:00
|
|
|
):
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes.extend(
|
2023-01-24 15:32:31 +01:00
|
|
|
common.add_global_checks(
|
|
|
|
builder.global_var_dict(),
|
2023-05-15 11:02:42 +02:00
|
|
|
"//",
|
2021-04-30 21:48:32 -07:00
|
|
|
run_list,
|
2020-01-13 12:16:35 -06:00
|
|
|
output_lines,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2022-11-28 10:02:14 -08:00
|
|
|
global_vars_seen_dict,
|
2023-11-13 14:45:27 +01:00
|
|
|
False,
|
2023-05-15 11:02:42 +02:00
|
|
|
True,
|
2023-11-13 14:45:27 +01:00
|
|
|
ti.args.check_globals,
|
2022-11-28 10:02:14 -08:00
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2022-11-28 10:02:14 -08:00
|
|
|
has_checked_pre_function_globals = True
|
|
|
|
if added:
|
2020-01-13 12:16:35 -06:00
|
|
|
output_lines.append("//")
|
|
|
|
added.add(mangled)
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes.extend(
|
[UpdateTestChecks] Auto-generate stub bodies for unused prefixes
This is scoped to autogenerated tests.
The goal is to support having each RUN line specify a list of
check-prefixes where one can specify potentially redundant prefixes. For example,
for X86, if one specified prefixes for both AVX1 and AVX2, and the codegen happened to
match today, one of the prefixes would be used and the onther one not.
If the unused prefix were dropped, and later, codegen differences were
introduced, one would have to go figure out where to add what prefix
(paraphrasing
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
To avoid getting errors due to unused prefixes, whole directories can be
opted out (as discussed on that thread), but that means that tests that
aren't autogenerated in such directories could have undetected unused
prefix bugs.
This patch proposes an alternative that both avoids the above, dir-level
optout, and supports the main autogen scenario discussed first. The autogen
tool appends at the end of the test file the list of unused prefixes,
together with a note explaining that is the case. Each prefix is set up
to always pass.
This way, unexpected unused prefixes are easily discoverable, and
expected cases "just work".
Differential Revision: https://reviews.llvm.org/D124306
2022-04-22 12:49:15 -07:00
|
|
|
common.add_ir_checks(
|
2020-01-13 12:16:35 -06:00
|
|
|
output_lines,
|
2023-05-15 11:02:42 +02:00
|
|
|
"//",
|
2021-04-30 21:48:32 -07:00
|
|
|
filecheck_run_list,
|
2020-01-13 12:16:35 -06:00
|
|
|
func_dict,
|
2023-05-15 11:02:42 +02:00
|
|
|
mangled,
|
2020-01-13 12:16:35 -06:00
|
|
|
False,
|
[UpdateTestChecks] Auto-generate stub bodies for unused prefixes
This is scoped to autogenerated tests.
The goal is to support having each RUN line specify a list of
check-prefixes where one can specify potentially redundant prefixes. For example,
for X86, if one specified prefixes for both AVX1 and AVX2, and the codegen happened to
match today, one of the prefixes would be used and the onther one not.
If the unused prefix were dropped, and later, codegen differences were
introduced, one would have to go figure out where to add what prefix
(paraphrasing
https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html)
To avoid getting errors due to unused prefixes, whole directories can be
opted out (as discussed on that thread), but that means that tests that
aren't autogenerated in such directories could have undetected unused
prefix bugs.
This patch proposes an alternative that both avoids the above, dir-level
optout, and supports the main autogen scenario discussed first. The autogen
tool appends at the end of the test file the list of unused prefixes,
together with a note explaining that is the case. Each prefix is set up
to always pass.
This way, unexpected unused prefixes are easily discoverable, and
expected cases "just work".
Differential Revision: https://reviews.llvm.org/D124306
2022-04-22 12:49:15 -07:00
|
|
|
args.function_signature,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2020-08-10 13:59:07 -05:00
|
|
|
global_vars_seen_dict,
|
2020-01-13 12:16:35 -06:00
|
|
|
is_filtered=builder.is_filtered(),
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
|
|
|
)
|
2020-01-13 12:16:35 -06:00
|
|
|
if line.rstrip("\n") == "//":
|
|
|
|
include_line = False
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2020-01-13 12:16:35 -06:00
|
|
|
if include_line:
|
|
|
|
output_lines.append(line.rstrip("\n"))
|
2023-05-15 11:02:42 +02:00
|
|
|
|
2023-11-13 14:45:27 +01:00
|
|
|
if ti.args.check_globals != 'none':
|
2022-11-28 10:02:14 -08:00
|
|
|
generated_prefixes.extend(
|
|
|
|
common.add_global_checks(
|
|
|
|
builder.global_var_dict(),
|
|
|
|
"//",
|
|
|
|
run_list,
|
|
|
|
output_lines,
|
update_test_checks: match IR basic block labels (#88979)
Labels are matched using a regexp of the form '^(pattern):', which
requires the addition of a "suffix" concept to NamelessValue.
Aside from that, the key challenge is that block labels are values, and
we typically capture values including the prefix '%'. However, when
labels appear at the start of a basic block, the prefix '%' is not
included, so we must capture block label values *without* the prefix
'%'.
We don't know ahead of time whether an IR value is a label or not. In
most cases, they are prefixed by the word "label" (their type), but this
isn't the case in phi nodes. We solve this issue by leveraging the
two-phase nature of variable generalization: the first pass finds all
occurences of a variable and determines whether the '%' prefix can be
included or not. The second pass does the actual substitution.
This change also unifies the generalization path for assembly with that
for IR and analysis, in the hope that any future changes avoid diverging
those cases future.
I also considered the alternative of trying to detect the phi node case
using more regular expression special cases but ultimately decided
against that because it seemed more fragile, and perhaps the approach of
keeping a tentative prefix that may later be discarded could also be
eventually applied to some metadata and attribute cases.
Note that an early version of this change was reviewed as
https://reviews.llvm.org/D142452, before version numbers were
introduced. This is a substantially updated version of that change.
2024-05-19 01:39:47 +02:00
|
|
|
ginfo,
|
2022-11-28 10:02:14 -08:00
|
|
|
global_vars_seen_dict,
|
|
|
|
False,
|
2023-11-13 14:45:27 +01:00
|
|
|
False,
|
|
|
|
ti.args.check_globals,
|
2022-11-28 10:02:14 -08:00
|
|
|
)
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2022-11-28 10:02:14 -08:00
|
|
|
if ti.args.gen_unused_prefix_body:
|
|
|
|
output_lines.extend(
|
|
|
|
ti.get_checks_for_unused_prefixes(run_list, generated_prefixes)
|
2023-05-15 11:02:42 +02:00
|
|
|
)
|
2020-07-08 10:59:50 +01:00
|
|
|
common.debug("Writing %d lines to %s..." % (len(output_lines), ti.path))
|
|
|
|
with open(ti.path, "wb") as f:
|
2020-02-14 15:17:27 +00:00
|
|
|
f.writelines(["{}\n".format(l).encode("utf-8") for l in output_lines])
|
2023-05-15 11:02:42 +02:00
|
|
|
|
[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-02 17:37:04 +00:00
|
|
|
return 0
|
2023-05-15 11:02:42 +02:00
|
|
|
|
|
|
|
|
[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-02 17:37:04 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|