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