Add -disable-llvm-passes in compile_corpus.py (#519)
This makes it so that we do not have to remember to add it when running
training by making it correct at the time of construction. This would
have prevented me from spawning a bunch of training jobs while
forgetting the flag.
diff --git a/compiler_opt/tools/regalloc_trace/compile_corpus.py b/compiler_opt/tools/regalloc_trace/compile_corpus.py
index b2c037a..1a99291 100644
--- a/compiler_opt/tools/regalloc_trace/compile_corpus.py
+++ b/compiler_opt/tools/regalloc_trace/compile_corpus.py
@@ -14,7 +14,6 @@
"""Compiles a corpus for further downstream processing."""
import os
-import shutil
import time
from absl import app
@@ -56,14 +55,18 @@
# compiler is set up to do normally.
pass
elif _MODE.value == 'bc':
+ # We want to only run through the middle end pipeline, so we pass
+ # -emit-llvm-bc to emit bitcode after the optimization pipeline has run.
additional_compilation_flags = additional_compilation_flags + (
'-emit-llvm-bc',)
elif _MODE.value == 'asm':
- additional_compilation_flags = additional_compilation_flags + (
- '-disable-llvm-passes',)
# When compiling from bitcode to an object file, we also need to remove all
# the flags that can load profiles or ThinLTO indices as they are embedded
# within the BC at this stage of compilation.
+ # We additionally need to ensure that middle end optimizations are
+ # disabled. The flag to do this (-disable-llvm-passes) is added directly
+ # to each module command line in bc mode, so we do not need to handle it
+ # here.
delete_compilation_flags = delete_compilation_flags + (
'-fprofile-sample-use', '-fprofile-instrument-use-path',
'fthinlto-index')
@@ -92,9 +95,15 @@
if _MODE.value == 'bc':
for module in train_corpus.module_specs:
command_file = os.path.join(_CORPUS_PATH.value, module.name) + '.cmd'
- new_command_file_path = os.path.join(_OUTPUT_PATH.value,
- module.name) + '.cmd'
- shutil.copy(command_file, new_command_file_path)
+ with open(command_file, encoding='utf-8') as command_file_handle:
+ command_tuple = tuple(command_file_handle.read().split('\0')[:-1])
+ command_tuple = command_tuple + ('-disable-llvm-passes',)
+ new_command_file_path = (
+ os.path.join(_OUTPUT_PATH.value, module.name) + '.cmd')
+ with open(
+ new_command_file_path, 'w',
+ encoding='utf-8') as new_command_file_handle:
+ new_command_file_handle.write('\0'.join(command_tuple))
if __name__ == '__main__':