Linux Audio

Check our new training course

Loading...
v5.4
 1// SPDX-License-Identifier: GPL-2.0
 2#include "clang.h"
 3#include "clang-c.h"
 4extern "C" {
 5#include "../util.h"
 6}
 7#include "llvm/IR/Function.h"
 8#include "llvm/IR/LLVMContext.h"
 9
 
10#include <tests/llvm.h>
11#include <string>
12
13class perf_clang_scope {
14public:
15	explicit perf_clang_scope() {perf_clang__init();}
16	~perf_clang_scope() {perf_clang__cleanup();}
17};
18
19static std::unique_ptr<llvm::Module>
20__test__clang_to_IR(void)
21{
22	unsigned int kernel_version;
23
24	if (fetch_kernel_version(&kernel_version, NULL, 0))
25		return std::unique_ptr<llvm::Module>(nullptr);
26
27	std::string cflag_kver("-DLINUX_VERSION_CODE=" +
28				std::to_string(kernel_version));
29
30	std::unique_ptr<llvm::Module> M =
31		perf::getModuleFromSource({cflag_kver.c_str()},
32					  "perf-test.c",
33					  test_llvm__bpf_base_prog);
34	return M;
35}
36
37extern "C" {
38int test__clang_to_IR(void)
39{
40	perf_clang_scope _scope;
41
42	auto M = __test__clang_to_IR();
43	if (!M)
44		return -1;
45	for (llvm::Function& F : *M)
46		if (F.getName() == "bpf_func__SyS_epoll_pwait")
47			return 0;
48	return -1;
49}
50
51int test__clang_to_obj(void)
52{
53	perf_clang_scope _scope;
54
55	auto M = __test__clang_to_IR();
56	if (!M)
57		return -1;
58
59	auto Buffer = perf::getBPFObjectFromModule(&*M);
60	if (!Buffer)
61		return -1;
62	return 0;
63}
64
65}
v4.10.11
 
 1#include "clang.h"
 2#include "clang-c.h"
 
 
 
 3#include "llvm/IR/Function.h"
 4#include "llvm/IR/LLVMContext.h"
 5
 6#include <util-cxx.h>
 7#include <tests/llvm.h>
 8#include <string>
 9
10class perf_clang_scope {
11public:
12	explicit perf_clang_scope() {perf_clang__init();}
13	~perf_clang_scope() {perf_clang__cleanup();}
14};
15
16static std::unique_ptr<llvm::Module>
17__test__clang_to_IR(void)
18{
19	unsigned int kernel_version;
20
21	if (fetch_kernel_version(&kernel_version, NULL, 0))
22		return std::unique_ptr<llvm::Module>(nullptr);
23
24	std::string cflag_kver("-DLINUX_VERSION_CODE=" +
25				std::to_string(kernel_version));
26
27	std::unique_ptr<llvm::Module> M =
28		perf::getModuleFromSource({cflag_kver.c_str()},
29					  "perf-test.c",
30					  test_llvm__bpf_base_prog);
31	return M;
32}
33
34extern "C" {
35int test__clang_to_IR(void)
36{
37	perf_clang_scope _scope;
38
39	auto M = __test__clang_to_IR();
40	if (!M)
41		return -1;
42	for (llvm::Function& F : *M)
43		if (F.getName() == "bpf_func__SyS_epoll_wait")
44			return 0;
45	return -1;
46}
47
48int test__clang_to_obj(void)
49{
50	perf_clang_scope _scope;
51
52	auto M = __test__clang_to_IR();
53	if (!M)
54		return -1;
55
56	auto Buffer = perf::getBPFObjectFromModule(&*M);
57	if (!Buffer)
58		return -1;
59	return 0;
60}
61
62}