1111import lit .util
1212import lit .formats
1313from lit .llvm import llvm_config
14- from lit .llvm import ToolFilter
14+ from lit .llvm .subst import FindTool
15+ from lit .llvm .subst import ToolSubst
1516
1617# name: The name of this test suite.
1718config .name = 'LLVM'
@@ -82,31 +83,30 @@ def get_asan_rtlib():
8283 return found_dylibs [0 ]
8384
8485
85- lli = 'lli'
86+ llvm_config .use_default_substitutions ()
87+
88+ # Add site-specific substitutions.
89+ config .substitutions .append (('%llvmshlibdir' , config .llvm_shlib_dir ))
90+ config .substitutions .append (('%shlibext' , config .llvm_shlib_ext ))
91+ config .substitutions .append (('%exeext' , config .llvm_exe_ext ))
92+ config .substitutions .append (('%host_cc' , config .host_cc ))
93+
94+
95+ lli_args = []
8696# The target triple used by default by lli is the process target triple (some
8797# triple appropriate for generating code for the current process) but because
8898# we don't support COFF in MCJIT well enough for the tests, force ELF format on
8999# Windows. FIXME: the process target triple should be used here, but this is
90100# difficult to obtain on Windows.
91101if re .search (r'cygwin|mingw32|windows-gnu|windows-msvc|win32' , config .host_triple ):
92- lli += ' -mtriple=' + config .host_triple + '-elf'
93- config .substitutions .append (('%lli' , lli ))
102+ lli_args = ['-mtriple=' + config .host_triple + '-elf' ]
103+
104+ llc_args = []
94105
95106# Similarly, have a macro to use llc with DWARF even when the host is win32.
96- llc_dwarf = 'llc'
97107if re .search (r'win32' , config .target_triple ):
98- llc_dwarf += ' -mtriple=' + \
99- config .target_triple .replace ('-win32' , '-mingw32' )
100- config .substitutions .append (('%llc_dwarf' , llc_dwarf ))
101-
102- # Add site-specific substitutions.
103- config .substitutions .append (('%gold' , config .gold_executable ))
104- config .substitutions .append (('%go' , config .go_executable ))
105- config .substitutions .append (('%llvmshlibdir' , config .llvm_shlib_dir ))
106- config .substitutions .append (('%shlibext' , config .llvm_shlib_ext ))
107- config .substitutions .append (('%exeext' , config .llvm_exe_ext ))
108- config .substitutions .append (('%python' , config .python_executable ))
109- config .substitutions .append (('%host_cc' , config .host_cc ))
108+ llc_args = [' -mtriple=' +
109+ config .target_triple .replace ('-win32' , '-mingw32' )]
110110
111111# Provide the path to asan runtime lib if available. On darwin, this lib needs
112112# to be loaded via DYLD_INSERT_LIBRARIES before libLTO.dylib in case the files
@@ -115,65 +115,50 @@ def get_asan_rtlib():
115115asan_rtlib = get_asan_rtlib ()
116116if asan_rtlib :
117117 ld64_cmd = 'DYLD_INSERT_LIBRARIES={} {}' .format (asan_rtlib , ld64_cmd )
118- config .substitutions .append (('%ld64' , ld64_cmd ))
119118
120- # OCaml substitutions.
121- # Support tests for both native and bytecode builds.
122- config .substitutions .append (('%ocamlc' ,
123- '%s ocamlc -cclib -L%s %s' %
124- (config .ocamlfind_executable , config .llvm_lib_dir , config .ocaml_flags )))
119+ ocamlc_command = '%s ocamlc -cclib -L%s %s' % (
120+ config .ocamlfind_executable , config .llvm_lib_dir , config .ocaml_flags )
121+ ocamlopt_command = 'true'
125122if config .have_ocamlopt :
126- config .substitutions .append (('%ocamlopt' ,
127- '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' %
128- (config .ocamlfind_executable , config .llvm_lib_dir , config .llvm_lib_dir , config .ocaml_flags )))
129- else :
130- config .substitutions .append (('%ocamlopt' , 'true' ))
131-
132- # For each occurrence of an llvm tool name as its own word, replace it
133- # with the full path to the build directory holding that tool. This
134- # ensures that we are testing the tools just built and not some random
135- # tools that might happen to be in the user's PATH. Thus this list
136- # includes every tool placed in $(LLVM_OBJ_ROOT)/$(BuildMode)/bin
137- # (llvm_tools_dir in lit parlance).
138-
139- # Avoid matching RUN line fragments that are actually part of
140- # path names or options or whatever.
141- # The regex is a pre-assertion to avoid matching a preceding
142- # dot, hyphen, carat, or slash (.foo, -foo, etc.). Some patterns
143- # also have a post-assertion to not match a trailing hyphen (foo-).
144- JUNKCHARS = r".-^/<"
145-
146- required_tools = [
147- 'lli' , 'llvm-ar' , 'llvm-as' , 'llvm-bcanalyzer' , 'llvm-config' , 'llvm-cov' ,
123+ ocamlopt_command = '%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s' % (
124+ config .ocamlfind_executable , config .llvm_lib_dir , config .llvm_lib_dir , config .ocaml_flags )
125+
126+
127+ tools = [
128+ ToolSubst ('%lli' , FindTool ('lli' ), post = '.' , extra_args = lli_args ),
129+ ToolSubst ('%llc_dwarf' , FindTool ('llc' ), extra_args = llc_args ),
130+ ToolSubst ('%go' , config .go_executable , unresolved = 'ignore' ),
131+ ToolSubst ('%gold' , config .gold_executable , unresolved = 'ignore' ),
132+ ToolSubst ('%ld64' , ld64_cmd , unresolved = 'ignore' ),
133+ ToolSubst ('%ocamlc' , ocamlc_command , unresolved = 'ignore' ),
134+ ToolSubst ('%ocamlopt' , ocamlopt_command , unresolved = 'ignore' ),
135+ ]
136+
137+ # FIXME: Why do we have both `lli` and `%lli` that do slightly different things?
138+ tools .extend ([
139+ 'lli' , 'lli-child-target' , 'llvm-ar' , 'llvm-as' , 'llvm-bcanalyzer' , 'llvm-config' , 'llvm-cov' ,
148140 'llvm-cxxdump' , 'llvm-cvtres' , 'llvm-diff' , 'llvm-dis' , 'llvm-dsymutil' ,
149141 'llvm-dwarfdump' , 'llvm-extract' , 'llvm-isel-fuzzer' , 'llvm-lib' ,
150142 'llvm-link' , 'llvm-lto' , 'llvm-lto2' , 'llvm-mc' , 'llvm-mcmarkup' ,
151143 'llvm-modextract' , 'llvm-nm' , 'llvm-objcopy' , 'llvm-objdump' ,
152144 'llvm-pdbutil' , 'llvm-profdata' , 'llvm-ranlib' , 'llvm-readobj' ,
153145 'llvm-rtdyld' , 'llvm-size' , 'llvm-split' , 'llvm-strings' , 'llvm-tblgen' ,
154146 'llvm-c-test' , 'llvm-cxxfilt' , 'llvm-xray' , 'yaml2obj' , 'obj2yaml' ,
155- 'FileCheck' , 'yaml-bench' , 'verify-uselistorder' ,
156- ToolFilter ('bugpoint' , post = '-' ),
157- ToolFilter ('llc' , pre = JUNKCHARS ),
158- ToolFilter ('llvm-symbolizer' , pre = JUNKCHARS ),
159- ToolFilter ('opt' , JUNKCHARS ),
160- ToolFilter ('sancov' , pre = JUNKCHARS ),
161- ToolFilter ('sanstats' , pre = JUNKCHARS ),
162- # Handle these specially as they are strings searched for during testing.
163- ToolFilter (r'\| \bcount\b' , verbatim = True ),
164- ToolFilter (r'\| \bnot\b' , verbatim = True )]
165-
166- llvm_config .add_tool_substitutions (required_tools , config .llvm_tools_dir )
167-
168- # For tools that are optional depending on the config, we won't warn
169- # if they're missing.
170-
171- optional_tools = [
172- 'llvm-go' , 'llvm-mt' , 'Kaleidoscope-Ch3' , 'Kaleidoscope-Ch4' ,
173- 'Kaleidoscope-Ch5' , 'Kaleidoscope-Ch6' , 'Kaleidoscope-Ch7' ,
174- 'Kaleidoscope-Ch8' ]
175- llvm_config .add_tool_substitutions (optional_tools , config .llvm_tools_dir ,
176- warn_missing = False )
147+ 'yaml-bench' , 'verify-uselistorder' ,
148+ 'bugpoint' , 'llc' , 'llvm-symbolizer' , 'opt' , 'sancov' , 'sanstats' ])
149+
150+ # The following tools are optional
151+ tools .extend ([
152+ ToolSubst ('llvm-go' , unresolved = 'ignore' ),
153+ ToolSubst ('llvm-mt' , unresolved = 'ignore' ),
154+ ToolSubst ('Kaleidoscope-Ch3' , unresolved = 'ignore' ),
155+ ToolSubst ('Kaleidoscope-Ch4' , unresolved = 'ignore' ),
156+ ToolSubst ('Kaleidoscope-Ch5' , unresolved = 'ignore' ),
157+ ToolSubst ('Kaleidoscope-Ch6' , unresolved = 'ignore' ),
158+ ToolSubst ('Kaleidoscope-Ch7' , unresolved = 'ignore' ),
159+ ToolSubst ('Kaleidoscope-Ch8' , unresolved = 'ignore' )])
160+
161+ llvm_config .add_tool_substitutions (tools , config .llvm_tools_dir )
177162
178163# Targets
179164
0 commit comments