diff --git a/llvm/test/CodeGen/NVPTX/access-non-generic.ll b/llvm/test/CodeGen/NVPTX/access-non-generic.ll --- a/llvm/test/CodeGen/NVPTX/access-non-generic.ll +++ b/llvm/test/CodeGen/NVPTX/access-non-generic.ll @@ -1,5 +1,14 @@ -; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s --check-prefix PTX -; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s --check-prefix PTX +; RUN: llc < %s -march=nvptx -mcpu=sm_20 -o %t-nvptx.ptx +; RUN: FileCheck %s --input-file %t-nvptx.ptx --check-prefix PTX +; RUN: ptxas-verify %t-nvptx.ptx +; RUN: %(when ptxas ptxas -c %t-nvptx.ptx -o /dev/null) +; RUN: %(when ptxas-11.4 ptxas -c %t-nvptx.ptx -o /dev/null) +; RUN: %(when unsupported this command will never execute) + +; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -o %t-nvptx64.ptx +; RUN: FileCheck %s --input-file %t-nvptx64.ptx --check-prefix PTX +; RUN: ptxas-verify %t-nvptx64.ptx + ; RUN: opt -mtriple=nvptx-- < %s -S -infer-address-spaces | FileCheck %s --check-prefix IR ; RUN: opt -mtriple=nvptx64-- < %s -S -infer-address-spaces | FileCheck %s --check-prefix IR diff --git a/llvm/test/lit.cfg.py b/llvm/test/lit.cfg.py --- a/llvm/test/lit.cfg.py +++ b/llvm/test/lit.cfg.py @@ -191,6 +191,39 @@ ToolSubst('OrcV2CBindingsLazy', unresolved='ignore'), ToolSubst('OrcV2CBindingsVeryLazy', unresolved='ignore')]) +# Find (major, minor) version of ptxas +def ptxas_version(ptxas): + ptxas_cmd = subprocess.Popen([ptxas, '--version'], stdout=subprocess.PIPE) + ptxas_out = ptxas_cmd.stdout.read().decode('ascii') + ptxas_cmd.wait() + match = re.search('release (\d+)\.(\d+)', ptxas_out) + if match: + return (int(match.group(1)), int(match.group(2))) + print('couldn\'t determine ptxas version') + return None + +ptxas_executable = 'true' +ptxas_known_versions = [(11, 4)] +if config.ptxas_executable: + ptxas_executable = config.ptxas_executable + version = ptxas_version(ptxas_executable) + if version: + # ptxas is supposed to be backward compatible with previous + # versions, so add a feature for every known version prior to + # the current one. + for known_major, known_minor in ptxas_known_versions: + if known_major <= version[0] and known_minor <= version[1]: + config.available_features.add( + 'ptxas-{}.{}'.format(known_major, known_minor)) + + config.available_features.add("ptxas") + tools.extend([ToolSubst('ptxas', ptxas_executable)]) + +# verify PTX with ptxas, or substitute to 'true' if it is not +# available +tools.extend([ + ToolSubst('ptxas-verify', '{} -c -o /dev/null'.format(ptxas_executable))]) + llvm_config.add_tool_substitutions(tools, config.llvm_tools_dir) # Targets diff --git a/llvm/test/lit.site.cfg.py.in b/llvm/test/lit.site.cfg.py.in --- a/llvm/test/lit.site.cfg.py.in +++ b/llvm/test/lit.site.cfg.py.in @@ -23,6 +23,7 @@ config.ocaml_flags = "@OCAMLFLAGS@" config.include_go_tests = @LLVM_INCLUDE_GO_TESTS@ config.go_executable = "@GO_EXECUTABLE@" +config.ptxas_executable = "@PXTAS_EXECUTABLE@" config.enable_shared = @ENABLE_SHARED@ config.enable_assertions = @ENABLE_ASSERTIONS@ config.targets_to_build = "@TARGETS_TO_BUILD@" diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -1345,7 +1345,7 @@ return (not line.strip() or output) @staticmethod - def _handleCommand(line_number, line, output, keyword): + def _handleCommand(line_number, line, output, keyword, conditions=[]): """A helper for parsing COMMAND type keywords""" # Trim trailing whitespace. line = line.rstrip() @@ -1358,6 +1358,15 @@ if match.group(1) == '-': return str(line_number - int(match.group(2))) line = re.sub(r'%\(line *([\+-]) *(\d+)\)', replace_line_number, line) + + match = re.search(r'%\(when ([\w\-_]+) (.*)\)', line) + if match: + cond = match.group(1) + if conditions.get(cond, False): + line = match.group(2) + else: + line = 'true' + # Collapse lines with trailing '\\'. if output and output[-1][-1] == '\\': output[-1] = output[-1][:-1] + line @@ -1414,7 +1423,7 @@ def _parseKeywords(sourcepath, additional_parsers=[], - require_script=True): + require_script=True, conditions=[]): """_parseKeywords Scan an LLVM/Clang style integrated test script and extract all the lines @@ -1427,8 +1436,13 @@ """ # Install the built-in keyword parsers. script = [] + run_parser = lambda line_number, line, output: \ + IntegratedTestKeywordParser._handleCommand(line_number, line, output, + 'RUN:', + conditions=conditions) builtin_parsers = [ - IntegratedTestKeywordParser('RUN:', ParserKind.COMMAND, initial_value=script), + IntegratedTestKeywordParser('RUN:', ParserKind.CUSTOM, run_parser, + initial_value=script), IntegratedTestKeywordParser('XFAIL:', ParserKind.BOOLEAN_EXPR), IntegratedTestKeywordParser('REQUIRES:', ParserKind.BOOLEAN_EXPR), IntegratedTestKeywordParser('UNSUPPORTED:', ParserKind.BOOLEAN_EXPR), @@ -1495,10 +1509,14 @@ may be returned. This can be used for test formats where the actual script is optional or ignored. """ + # Parse the test sources and extract test properties try: + conditions = { + feature: True for feature in test.config.available_features + } parsed = _parseKeywords(test.getSourcePath(), additional_parsers, - require_script) + require_script, conditions=conditions) except ValueError as e: return lit.Test.Result(Test.UNRESOLVED, str(e)) script = parsed['RUN:'] or []