1#!/usr/bin/env python 2 3""" 4A wrapper for Clang specialized for gathering information about OpenMP programs. 5Simple replace calls to clang or clang++ with llvm-openmp-analyzer to run the 6analysis passes. 7""" 8 9import argparse 10import subprocess 11import yaml # PyYaml to save and load analysis information 12import sys 13import io 14 15from analyzer import getKernelUsage 16 17desc = '''A wrapper around clang that runs OpenMP Analysis passes and gathers 18information about OpenMP programs.''' 19 20default_args = ["-fopenmp", "-Rpass=openmp-opt", "-Rpass-missed=openmp-opt", "-Rpass-analysis=openmp-opt"] 21 22def main(): 23 compiler = ["clang++"] if sys.argv[0].endswith('++') else ["clang"] 24 parser = argparse.ArgumentParser(description=desc) 25 parser.add_argument('--usage-report-file', 26 metavar='filename', 27 default='usage.yaml', 28 help='Filename used for the OpenMP kernel usage reports in YAML format. "usage.yaml" by default.') 29 parser.add_argument('--no-usage-report', 30 action='store_true', 31 default=False, 32 help='Do not general a usage report for the OpenMP kernels.') 33 args, clang_args = parser.parse_known_args() 34 35 subprocess.run(compiler + default_args + clang_args, check=True) 36 output = subprocess.run(compiler + default_args + clang_args + ["-v"], stderr=subprocess.PIPE) 37 stderr = output.stderr.decode('utf-8') 38 39 if not args.no_usage_report: 40 usage = getKernelUsage(stderr, fname=args.usage_report_file) 41 with io.open(args.usage_report_file, 'w', encoding = 'utf-8') as f: 42 yaml.dump(usage, f) 43 44if __name__ == '__main__': 45 main() 46