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