|
| 1 | +# Copyright 2020 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +"""Extracts functions specified in a list from a corpus.""" |
| 15 | + |
| 16 | +import multiprocessing |
| 17 | + |
| 18 | +from absl import flags |
| 19 | +from absl import app |
| 20 | +from absl import logging |
| 21 | + |
| 22 | +from compiler_opt.tools.regalloc_trace import extract_functions_lib |
| 23 | + |
| 24 | +_CORPUS_PATH = flags.DEFINE_string( |
| 25 | + "optimized_corpus", None, |
| 26 | + "The path to the optimized bitcode corpus that has been run through the " |
| 27 | + "middle-end pipeline.") |
| 28 | +_FUNCTION_LIST = flags.DEFINE_string( |
| 29 | + "function_list", None, "The list of functions to extract", required=True) |
| 30 | +_OUTPUT_PATH = flags.DEFINE_string( |
| 31 | + "output_path", |
| 32 | + None, |
| 33 | + "The folder to place the extracted functions in.", |
| 34 | + required=True) |
| 35 | +_LLVM_NM_PATH = flags.DEFINE_string( |
| 36 | + "llvm_nm_path", None, "The path to llvm-nm", required=True) |
| 37 | +_LLVM_EXTRACT_PATH = flags.DEFINE_string( |
| 38 | + "llvm_extract_path", None, "The path to llvm-extract", required=True) |
| 39 | +_OPT_PATH = flags.DEFINE_string( |
| 40 | + "opt_path", None, "The path to opt", required=True) |
| 41 | +_THREAD_COUNT = flags.DEFINE_integer( |
| 42 | + "thread_count", multiprocessing.cpu_count(), |
| 43 | + "The number of threads to use when processing") |
| 44 | + |
| 45 | + |
| 46 | +def main(_): |
| 47 | + logging.info("Loading the function to module mapping.") |
| 48 | + function_to_module = extract_functions_lib.get_function_module_map( |
| 49 | + _CORPUS_PATH.value, _LLVM_NM_PATH.value) |
| 50 | + |
| 51 | + logging.info("Loading functions to extract.") |
| 52 | + with open(_FUNCTION_LIST.value, encoding="utf-8") as function_list_handle: |
| 53 | + functions_to_extract = [ |
| 54 | + function_name.strip() |
| 55 | + for function_name in function_list_handle.readlines() |
| 56 | + ] |
| 57 | + |
| 58 | + logging.info("Extracting functions.") |
| 59 | + extract_functions_lib.extract_functions(functions_to_extract, |
| 60 | + function_to_module, |
| 61 | + _LLVM_EXTRACT_PATH.value, |
| 62 | + _OPT_PATH.value, _THREAD_COUNT.value, |
| 63 | + _OUTPUT_PATH.value) |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == "__main__": |
| 67 | + app.run(main) |
0 commit comments