llvm-utils.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
  4. * Copyright (C) 2015, Huawei Inc.
  5. */
  6. #ifndef __LLVM_UTILS_H
  7. #define __LLVM_UTILS_H
  8. #include <stdbool.h>
  9. struct llvm_param {
  10. /* Path of clang executable */
  11. const char *clang_path;
  12. /* Path of llc executable */
  13. const char *llc_path;
  14. /*
  15. * Template of clang bpf compiling. 5 env variables
  16. * can be used:
  17. * $CLANG_EXEC: Path to clang.
  18. * $CLANG_OPTIONS: Extra options to clang.
  19. * $KERNEL_INC_OPTIONS: Kernel include directories.
  20. * $WORKING_DIR: Kernel source directory.
  21. * $CLANG_SOURCE: Source file to be compiled.
  22. */
  23. const char *clang_bpf_cmd_template;
  24. /* Will be filled in $CLANG_OPTIONS */
  25. const char *clang_opt;
  26. /*
  27. * If present it'll add -emit-llvm to $CLANG_OPTIONS to pipe
  28. * the clang output to llc, useful for new llvm options not
  29. * yet selectable via 'clang -mllvm option', such as -mattr=dwarfris
  30. * in clang 6.0/llvm 7
  31. */
  32. const char *opts;
  33. /* Where to find kbuild system */
  34. const char *kbuild_dir;
  35. /*
  36. * Arguments passed to make, like 'ARCH=arm' if doing cross
  37. * compiling. Should not be used for dynamic compiling.
  38. */
  39. const char *kbuild_opts;
  40. /*
  41. * Default is false. If set to true, write compiling result
  42. * to object file.
  43. */
  44. bool dump_obj;
  45. /*
  46. * Default is false. If one of the above fields is set by user
  47. * explicitly then user_set_llvm is set to true. This is used
  48. * for perf test. If user doesn't set anything in .perfconfig
  49. * and clang is not found, don't trigger llvm test.
  50. */
  51. bool user_set_param;
  52. };
  53. extern struct llvm_param llvm_param;
  54. int perf_llvm_config(const char *var, const char *value);
  55. int llvm__compile_bpf(const char *path, void **p_obj_buf, size_t *p_obj_buf_sz);
  56. /* This function is for test__llvm() use only */
  57. int llvm__search_clang(void);
  58. /* Following functions are reused by builtin clang support */
  59. void llvm__get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts);
  60. int llvm__get_nr_cpus(void);
  61. void llvm__dump_obj(const char *path, void *obj_buf, size_t size);
  62. #endif