Skip to content

Commit 4c7438a

Browse files
authored
Remove llc dependency. NFC (#18290)
clang now supports the `-print-targets` argument as of version 11 so we don't need to use llc here.
1 parent 0dc36f4 commit 4c7438a

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

test/test_sanity.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_basic_config():
6262
''' % (config.LLVM_ROOT, config.BINARYEN_ROOT, config.NODE_JS)
6363

6464

65-
def make_fake_tool(filename, version, report_name=None):
65+
def make_fake_tool(filename, version, report_name=None, extra_output=None):
6666
if not report_name:
6767
report_name = os.path.basename(filename)
6868
print('make_fake_tool: %s' % filename)
@@ -71,28 +71,19 @@ def make_fake_tool(filename, version, report_name=None):
7171
f.write('#!/bin/sh\n')
7272
f.write('echo "%s version %s"\n' % (report_name, version))
7373
f.write('echo "..."\n')
74+
if extra_output:
75+
f.write('echo "%s"' % extra_output)
7476
f.write('exit 0\n')
7577
make_executable(filename)
7678

7779

78-
def make_fake_clang(filename, version):
80+
def make_fake_clang(filename, version, targets='wasm32 - WebAssembly 32-bit'):
7981
"""Create a fake clang that only handles --version
8082
--version writes to stdout (unlike -v which writes to stderr)
8183
"""
82-
make_fake_tool(filename, version)
83-
make_fake_tool(filename + '++', version)
84-
85-
86-
def make_fake_llc(filename, targets):
87-
"""Create a fake llc that only handles --version and writes target
88-
list to stdout.
89-
"""
90-
print('make_fake_llc: %s' % filename)
91-
ensure_dir(os.path.dirname(filename))
92-
with open(filename, 'w') as f:
93-
f.write('#!/bin/sh\n')
94-
f.write('echo "llc fake output\nRegistered Targets:\n%s"' % targets)
95-
make_executable(filename)
84+
output = 'clang fake output\nRegistered Targets:\n%s' % targets
85+
make_fake_tool(filename, version, output)
86+
make_fake_tool(filename + '++', version, output)
9687

9788

9889
SANITY_MESSAGE = 'Emscripten: Running sanity checks'
@@ -248,7 +239,7 @@ def test_llvm(self):
248239
f.write('LLVM_ROOT = "' + self.in_dir('fake') + '"')
249240

250241
real_version_x, real_version_y = (int(x) for x in EXPECTED_LLVM_VERSION.split('.'))
251-
make_fake_llc(self.in_dir('fake', 'llc'), 'wasm32 - WebAssembly 32-bit')
242+
make_fake_clang(self.in_dir('fake', 'clang'), EXPECTED_LLVM_VERSION)
252243
make_fake_tool(self.in_dir('fake', 'wasm-ld'), EXPECTED_LLVM_VERSION)
253244

254245
for inc_x in range(-2, 3):
@@ -424,7 +415,6 @@ def test_cache_clearing_auto(self):
424415
restore_and_set_up()
425416
self.ensure_cache()
426417
make_fake_clang(self.in_dir('fake', 'bin', 'clang'), EXPECTED_LLVM_VERSION)
427-
make_fake_llc(self.in_dir('fake', 'bin', 'llc'), 'got wasm32 backend! WebAssembly 32-bit')
428418
with env_modify({'EM_LLVM_ROOT': self.in_dir('fake', 'bin')}):
429419
self.assertExists(cache.cachedir)
430420
output = self.do([EMCC])
@@ -660,8 +650,7 @@ def make_fake(report):
660650
# doesn't actually use it.
661651
f.write('BINARYEN_ROOT = "%s"\n' % self.in_dir('fake', 'bin'))
662652

663-
make_fake_clang(self.in_dir('fake', 'bin', 'clang'), EXPECTED_LLVM_VERSION)
664-
make_fake_llc(self.in_dir('fake', 'bin', 'llc'), report)
653+
make_fake_clang(self.in_dir('fake', 'bin', 'clang'), EXPECTED_LLVM_VERSION, report)
665654
make_fake_tool(self.in_dir('fake', 'bin', 'wasm-ld'), EXPECTED_LLVM_VERSION)
666655

667656
# fake llc output

tools/shared.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,22 @@ def check_llvm_version():
290290
return False
291291

292292

293-
def get_llc_targets():
294-
if not os.path.exists(LLVM_COMPILER):
295-
exit_with_error('llc executable not found at `%s`' % LLVM_COMPILER)
293+
def get_clang_targets():
294+
if not os.path.exists(CLANG_CC):
295+
exit_with_error('clang executable not found at `%s`' % CLANG_CC)
296296
try:
297-
llc_version_info = run_process([LLVM_COMPILER, '--version'], stdout=PIPE).stdout
298-
except subprocess.CalledProcessError:
299-
exit_with_error('error running `llc --version`. Check your llvm installation (%s)' % LLVM_COMPILER)
300-
if 'Registered Targets:' not in llc_version_info:
301-
exit_with_error('error parsing output of `llc --version`. Check your llvm installation (%s)' % LLVM_COMPILER)
302-
pre, targets = llc_version_info.split('Registered Targets:')
303-
return targets
297+
target_info = run_process([CLANG_CC, '-print-targets'], stdout=PIPE).stdout
298+
except subprocess.CalldProcessError:
299+
exit_with_error('error running `clang -print-targets`. Check your llvm installation (%s)' % CLANG_CC)
300+
if 'Registered Targets:' not in target_info:
301+
exit_with_error('error parsing output of `clang -print-targets`. Check your llvm installation (%s)' % CLANG_CC)
302+
return target_info.split('Registered Targets:')[1]
304303

305304

306305
def check_llvm():
307-
targets = get_llc_targets()
308-
if 'wasm32' not in targets and 'WebAssembly 32-bit' not in targets:
309-
logger.critical('LLVM has not been built with the WebAssembly backend, llc reports:')
306+
targets = get_clang_targets()
307+
if 'wasm32' not in targets:
308+
logger.critical('LLVM has not been built with the WebAssembly backend, clang reports:')
310309
print('===========================================================================', file=sys.stderr)
311310
print(targets, file=sys.stderr)
312311
print('===========================================================================', file=sys.stderr)
@@ -749,8 +748,6 @@ def get_llvm_target():
749748
LLVM_OPT = os.path.expanduser(build_llvm_tool_path(exe_suffix('opt')))
750749
LLVM_NM = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-nm')))
751750
LLVM_MC = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-mc')))
752-
LLVM_INTERPRETER = os.path.expanduser(build_llvm_tool_path(exe_suffix('lli')))
753-
LLVM_COMPILER = os.path.expanduser(build_llvm_tool_path(exe_suffix('llc')))
754751
LLVM_DWARFDUMP = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-dwarfdump')))
755752
LLVM_OBJCOPY = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-objcopy')))
756753
LLVM_STRIP = os.path.expanduser(build_llvm_tool_path(exe_suffix('llvm-strip')))

0 commit comments

Comments
 (0)