summaryrefslogtreecommitdiff
path: root/tools/perf/util/c++/clang-test.cpp
blob: d84e760d2aabdd8bad30a4f4203d5e1867783483 (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
#include "clang.h"
#include "clang-c.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/LLVMContext.h"

#include <util-cxx.h>
#include <tests/llvm.h>
#include <string>

class perf_clang_scope {
public:
	explicit perf_clang_scope() {perf_clang__init();}
	~perf_clang_scope() {perf_clang__cleanup();}
};

extern "C" {

int test__clang_to_IR(void)
{
	perf_clang_scope _scope;
	unsigned int kernel_version;

	if (fetch_kernel_version(&kernel_version, NULL, 0))
		return -1;

	std::string cflag_kver("-DLINUX_VERSION_CODE=" +
				std::to_string(kernel_version));

	std::unique_ptr<llvm::Module> M =
		perf::getModuleFromSource({cflag_kver.c_str()},
					  "perf-test.c",
					  test_llvm__bpf_base_prog);

	if (!M)
		return -1;

	for (llvm::Function& F : *M)
		if (F.getName() == "bpf_func__SyS_epoll_wait")
			return 0;
	return -1;
}

}