summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/llvm-utils.c
blob: 472e8cd69361cc7afc92920c99a3502c0f47b6e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright (C) 2015, Wang Nan <wangnan0@huawei.com>
 * Copyright (C) 2015, Huawei Inc.
 */

#include <stdio.h>
#include "util.h"
#include "debug.h"
#include "llvm-utils.h"
#include "cache.h"

#define CLANG_BPF_CMD_DEFAULT_TEMPLATE				\
		"$CLANG_EXEC -D__KERNEL__ $CLANG_OPTIONS "	\
		"$KERNEL_INC_OPTIONS -Wno-unused-value "	\
		"-Wno-pointer-sign -working-directory "		\
		"$WORKING_DIR -c \"$CLANG_SOURCE\" -target bpf -O2 -o -"

struct llvm_param llvm_param = {
	.clang_path = "clang",
	.clang_bpf_cmd_template = CLANG_BPF_CMD_DEFAULT_TEMPLATE,
	.clang_opt = NULL,
	.kbuild_dir = NULL,
	.kbuild_opts = NULL,
};

int perf_llvm_config(const char *var, const char *value)
{
	if (prefixcmp(var, "llvm."))
		return 0;
	var += sizeof("llvm.") - 1;

	if (!strcmp(var, "clang-path"))
		llvm_param.clang_path = strdup(value);
	else if (!strcmp(var, "clang-bpf-cmd-template"))
		llvm_param.clang_bpf_cmd_template = strdup(value);
	else if (!strcmp(var, "clang-opt"))
		llvm_param.clang_opt = strdup(value);
	else if (!strcmp(var, "kbuild-dir"))
		llvm_param.kbuild_dir = strdup(value);
	else if (!strcmp(var, "kbuild-opts"))
		llvm_param.kbuild_opts = strdup(value);
	else
		return -1;
	return 0;
}
OpenPOWER on IntegriCloud