Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
0004  * Copyright (C) 2015, Huawei Inc.
0005  */
0006 #ifndef __LLVM_UTILS_H
0007 #define __LLVM_UTILS_H
0008 
0009 #include <stdbool.h>
0010 
0011 struct llvm_param {
0012     /* Path of clang executable */
0013     const char *clang_path;
0014     /* Path of llc executable */
0015     const char *llc_path;
0016     /*
0017      * Template of clang bpf compiling. 5 env variables
0018      * can be used:
0019      *   $CLANG_EXEC:       Path to clang.
0020      *   $CLANG_OPTIONS:        Extra options to clang.
0021      *   $KERNEL_INC_OPTIONS:   Kernel include directories.
0022      *   $WORKING_DIR:      Kernel source directory.
0023      *   $CLANG_SOURCE:     Source file to be compiled.
0024      */
0025     const char *clang_bpf_cmd_template;
0026     /* Will be filled in $CLANG_OPTIONS */
0027     const char *clang_opt;
0028     /*
0029      * If present it'll add -emit-llvm to $CLANG_OPTIONS to pipe
0030      * the clang output to llc, useful for new llvm options not
0031      * yet selectable via 'clang -mllvm option', such as -mattr=dwarfris
0032      * in clang 6.0/llvm 7
0033      */
0034     const char *opts;
0035     /* Where to find kbuild system */
0036     const char *kbuild_dir;
0037     /*
0038      * Arguments passed to make, like 'ARCH=arm' if doing cross
0039      * compiling. Should not be used for dynamic compiling.
0040      */
0041     const char *kbuild_opts;
0042     /*
0043      * Default is false. If set to true, write compiling result
0044      * to object file.
0045      */
0046     bool dump_obj;
0047     /*
0048      * Default is false. If one of the above fields is set by user
0049      * explicitly then user_set_llvm is set to true. This is used
0050      * for perf test. If user doesn't set anything in .perfconfig
0051      * and clang is not found, don't trigger llvm test.
0052      */
0053     bool user_set_param;
0054 };
0055 
0056 extern struct llvm_param llvm_param;
0057 int perf_llvm_config(const char *var, const char *value);
0058 
0059 int llvm__compile_bpf(const char *path, void **p_obj_buf, size_t *p_obj_buf_sz);
0060 
0061 /* This function is for test__llvm() use only */
0062 int llvm__search_clang(void);
0063 
0064 /* Following functions are reused by builtin clang support */
0065 void llvm__get_kbuild_opts(char **kbuild_dir, char **kbuild_include_opts);
0066 int llvm__get_nr_cpus(void);
0067 
0068 void llvm__dump_obj(const char *path, void *obj_buf, size_t size);
0069 #endif