llvm_bc.py 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. import sys
  2. from _common import rootrel_arc_src, sort_by_keywords, skip_build_root, stripext
  3. def onllvm_bc(unit, *args):
  4. free_args, kwds = sort_by_keywords({'SYMBOLS': -1, 'NAME': 1, 'NO_COMPILE': 0}, args)
  5. name = kwds['NAME'][0]
  6. symbols = kwds.get('SYMBOLS')
  7. obj_suf = unit.get('OBJ_SUF')
  8. skip_compile_step = 'NO_COMPILE' in kwds
  9. merged_bc = name + '_merged' + obj_suf + '.bc'
  10. out_bc = name + '_optimized' + obj_suf + '.bc'
  11. bcs = []
  12. for x in free_args:
  13. rel_path = rootrel_arc_src(x, unit)
  14. bc_path = '${ARCADIA_BUILD_ROOT}/' + skip_build_root(rel_path) + obj_suf + '.bc'
  15. if not skip_compile_step:
  16. if x.endswith('.c'):
  17. llvm_compile = unit.onllvm_compile_c
  18. elif x.endswith('.ll'):
  19. llvm_compile = unit.onllvm_compile_ll
  20. else:
  21. llvm_compile = unit.onllvm_compile_cxx
  22. llvm_compile([rel_path, bc_path])
  23. bcs.append(bc_path)
  24. unit.onllvm_link([merged_bc] + bcs)
  25. opt_opts = ['-O2', '-globalopt', '-globaldce']
  26. if symbols:
  27. # XXX: '#' used instead of ',' to overcome ymake tendency to split everything by comma
  28. opt_opts += ['-internalize', '-internalize-public-api-list=' + '#'.join(symbols)]
  29. unit.onllvm_opt([merged_bc, out_bc] + opt_opts)
  30. unit.onresource([out_bc, '/llvm_bc/' + name])