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