Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging verbosity level flag to extract_ir.py #278

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler_opt/tools/extract_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

In a local ThinLTO case, the compilation is assumedto have been performed
specifying -Wl,--save-temps=import -Wl,--thinlto-emit-index-files

To change the logging verbosity, pass an integer representing the desired
verbosity to the --verbosity flag. Use 0 for all logs, status information,
and detailed debug information, -1 for solely warnings, and -2 to not produce
any output.
"""

import json
Expand Down
60 changes: 34 additions & 26 deletions compiler_opt/tools/extract_ir_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,40 @@ def _extract_clang_artifacts(self, llvm_objcopy_path: str, cmd_filter: str,
logging.info('%s does not exist.', self.input_obj())
return None
os.makedirs(self.dest_dir(), exist_ok=True)
try:
subprocess.run(
self._get_extraction_cmd_command(llvm_objcopy_path, cmd_section_name),
check=True)
if cmd_filter is not None or is_thinlto:
with open(self.cmd_file(), encoding='utf-8') as f:
lines = f.readlines()
assert len(lines) == 1
cmdline = lines[0]
if not should_include_module(cmdline, cmd_filter):
logging.info(
'Excluding module %s because it does not match the filter',
self.input_obj())
os.remove(self.cmd_file())
return None
if is_thinlto:
index_file = get_thinlto_index(cmdline, self.obj_base_dir())
shutil.copy(index_file, self.thinlto_index_file())

subprocess.run(
self._get_extraction_bc_command(llvm_objcopy_path,
bitcode_section_name),
check=True)
except subprocess.CalledProcessError as e:
# This may happen if .o file was build from asm (.S source).
logging.warning('%s was not processed: %s', self.input_obj(), e)
cmd_objcopy_output = subprocess.run(
boomanaiden154 marked this conversation as resolved.
Show resolved Hide resolved
self._get_extraction_cmd_command(llvm_objcopy_path, cmd_section_name),
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
if cmd_objcopy_output.returncode != 0:
logging.warning('%s was not processed.', self.input_obj())
logging.info(cmd_objcopy_output.stdout)
return None
if cmd_filter is not None or is_thinlto:
with open(self.cmd_file(), encoding='utf-8') as f:
lines = f.readlines()
assert len(lines) == 1
cmdline = lines[0]
if not should_include_module(cmdline, cmd_filter):
logging.info('Excluding module %s because it does not match the filter',
self.input_obj())
os.remove(self.cmd_file())
return None
if is_thinlto:
index_file = get_thinlto_index(cmdline, self.obj_base_dir())
shutil.copy(index_file, self.thinlto_index_file())

bc_objcopy_output = subprocess.run(
self._get_extraction_bc_command(llvm_objcopy_path,
bitcode_section_name),
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True)
if bc_objcopy_output.returncode != 0:
boomanaiden154 marked this conversation as resolved.
Show resolved Hide resolved
logging.warning('%s was not processed.', self.input_obj())
logging.info(bc_objcopy_output.stdout)
return None
assert (os.path.exists(self.cmd_file()) and
os.path.exists(self.bc_file()) and
Expand Down