18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com> 48c2ecf20Sopenharmony_ci * Copyright (C) 2015, Huawei Inc. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef __LLVM_UTILS_H 78c2ecf20Sopenharmony_ci#define __LLVM_UTILS_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <stdbool.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_cistruct llvm_param { 128c2ecf20Sopenharmony_ci /* Path of clang executable */ 138c2ecf20Sopenharmony_ci const char *clang_path; 148c2ecf20Sopenharmony_ci /* Path of llc executable */ 158c2ecf20Sopenharmony_ci const char *llc_path; 168c2ecf20Sopenharmony_ci /* 178c2ecf20Sopenharmony_ci * Template of clang bpf compiling. 5 env variables 188c2ecf20Sopenharmony_ci * can be used: 198c2ecf20Sopenharmony_ci * $CLANG_EXEC: Path to clang. 208c2ecf20Sopenharmony_ci * $CLANG_OPTIONS: Extra options to clang. 218c2ecf20Sopenharmony_ci * $KERNEL_INC_OPTIONS: Kernel include directories. 228c2ecf20Sopenharmony_ci * $WORKING_DIR: Kernel source directory. 238c2ecf20Sopenharmony_ci * $CLANG_SOURCE: Source file to be compiled. 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci const char *clang_bpf_cmd_template; 268c2ecf20Sopenharmony_ci /* Will be filled in $CLANG_OPTIONS */ 278c2ecf20Sopenharmony_ci const char *clang_opt; 288c2ecf20Sopenharmony_ci /* 298c2ecf20Sopenharmony_ci * If present it'll add -emit-llvm to $CLANG_OPTIONS to pipe 308c2ecf20Sopenharmony_ci * the clang output to llc, useful for new llvm options not 318c2ecf20Sopenharmony_ci * yet selectable via 'clang -mllvm option', such as -mattr=dwarfris 328c2ecf20Sopenharmony_ci * in clang 6.0/llvm 7 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci const char *opts; 358c2ecf20Sopenharmony_ci /* Where to find kbuild system */ 368c2ecf20Sopenharmony_ci const char *kbuild_dir; 378c2ecf20Sopenharmony_ci /* 388c2ecf20Sopenharmony_ci * Arguments passed to make, like 'ARCH=arm' if doing cross 398c2ecf20Sopenharmony_ci * compiling. Should not be used for dynamic compiling. 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_ci const char *kbuild_opts; 428c2ecf20Sopenharmony_ci /* 438c2ecf20Sopenharmony_ci * Default is false. If set to true, write compiling result 448c2ecf20Sopenharmony_ci * to object file. 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_ci bool dump_obj; 478c2ecf20Sopenharmony_ci /* 488c2ecf20Sopenharmony_ci * Default is false. If one of the above fields is set by user 498c2ecf20Sopenharmony_ci * explicitly then user_set_llvm is set to true. This is used 508c2ecf20Sopenharmony_ci * for perf test. If user doesn't set anything in .perfconfig 518c2ecf20Sopenharmony_ci * and clang is not found, don't trigger llvm test. 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_ci bool user_set_param; 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ciextern struct llvm_param llvm_param; 578c2ecf20Sopenharmony_ciint perf_llvm_config(const char *var, const char *value); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciint llvm__compile_bpf(const char *path, void **p_obj_buf, size_t *p_obj_buf_sz); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/* This function is for test__llvm() use only */ 628c2ecf20Sopenharmony_ciint llvm__search_clang(void); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* Following functions are reused by builtin clang support */ 658c2ecf20Sopenharmony_civoid llvm__get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts); 668c2ecf20Sopenharmony_ciint llvm__get_nr_cpus(void); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_civoid llvm__dump_obj(const char *path, void *obj_buf, size_t size); 698c2ecf20Sopenharmony_ci#endif 70