1 // SPDX-License-Identifier: GPL-2.0
4 #include "llvm/IR/Function.h"
5 #include "llvm/IR/LLVMContext.h"
8 #include <tests/llvm.h>
11 class perf_clang_scope
{
13 explicit perf_clang_scope() {perf_clang__init();}
14 ~perf_clang_scope() {perf_clang__cleanup();}
17 static std::unique_ptr
<llvm::Module
>
18 __test__clang_to_IR(void)
20 unsigned int kernel_version
;
22 if (fetch_kernel_version(&kernel_version
, NULL
, 0))
23 return std::unique_ptr
<llvm::Module
>(nullptr);
25 std::string
cflag_kver("-DLINUX_VERSION_CODE=" +
26 std::to_string(kernel_version
));
28 std::unique_ptr
<llvm::Module
> M
=
29 perf::getModuleFromSource({cflag_kver
.c_str()},
31 test_llvm__bpf_base_prog
);
36 int test__clang_to_IR(void)
38 perf_clang_scope _scope
;
40 auto M
= __test__clang_to_IR();
43 for (llvm::Function
& F
: *M
)
44 if (F
.getName() == "bpf_func__SyS_epoll_pwait")
49 int test__clang_to_obj(void)
51 perf_clang_scope _scope
;
53 auto M
= __test__clang_to_IR();
57 auto Buffer
= perf::getBPFObjectFromModule(&*M
);