llvm-utils.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 "debug.h"
  9. struct llvm_param {
  10. /* Path of clang executable */
  11. const char *clang_path;
  12. /*
  13. * Template of clang bpf compiling. 5 env variables
  14. * can be used:
  15. * $CLANG_EXEC: Path to clang.
  16. * $CLANG_OPTIONS: Extra options to clang.
  17. * $KERNEL_INC_OPTIONS: Kernel include directories.
  18. * $WORKING_DIR: Kernel source directory.
  19. * $CLANG_SOURCE: Source file to be compiled.
  20. */
  21. const char *clang_bpf_cmd_template;
  22. /* Will be filled in $CLANG_OPTIONS */
  23. const char *clang_opt;
  24. /* Where to find kbuild system */
  25. const char *kbuild_dir;
  26. /*
  27. * Arguments passed to make, like 'ARCH=arm' if doing cross
  28. * compiling. Should not be used for dynamic compiling.
  29. */
  30. const char *kbuild_opts;
  31. /*
  32. * Default is false. If set to true, write compiling result
  33. * to object file.
  34. */
  35. bool dump_obj;
  36. /*
  37. * Default is false. If one of the above fields is set by user
  38. * explicitly then user_set_llvm is set to true. This is used
  39. * for perf test. If user doesn't set anything in .perfconfig
  40. * and clang is not found, don't trigger llvm test.
  41. */
  42. bool user_set_param;
  43. };
  44. extern struct llvm_param llvm_param;
  45. int perf_llvm_config(const char *var, const char *value);
  46. int llvm__compile_bpf(const char *path, void **p_obj_buf, size_t *p_obj_buf_sz);
  47. /* This function is for test__llvm() use only */
  48. int llvm__search_clang(void);
  49. /* Following functions are reused by builtin clang support */
  50. void llvm__get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts);
  51. int llvm__get_nr_cpus(void);
  52. void llvm__dump_obj(const char *path, void *obj_buf, size_t size);
  53. #endif