1 // SPDX-License-Identifier: GPL-2.0
7 #include "llvm/IR/Function.h"
8 #include "llvm/IR/LLVMContext.h"
10 #include <tests/llvm.h>
13 class perf_clang_scope
{
15 explicit perf_clang_scope() {perf_clang__init();}
16 ~perf_clang_scope() {perf_clang__cleanup();}
19 static std::unique_ptr
<llvm::Module
>
20 __test__clang_to_IR(void)
22 unsigned int kernel_version
;
24 if (fetch_kernel_version(&kernel_version
, NULL
, 0))
25 return std::unique_ptr
<llvm::Module
>(nullptr);
27 std::string
cflag_kver("-DLINUX_VERSION_CODE=" +
28 std::to_string(kernel_version
));
30 std::unique_ptr
<llvm::Module
> M
=
31 perf::getModuleFromSource({cflag_kver
.c_str()},
33 test_llvm__bpf_base_prog
);
38 int test__clang_to_IR(void)
40 perf_clang_scope _scope
;
42 auto M
= __test__clang_to_IR();
45 for (llvm::Function
& F
: *M
)
46 if (F
.getName() == "bpf_func__SyS_epoll_pwait")
51 int test__clang_to_obj(void)
53 perf_clang_scope _scope
;
55 auto M
= __test__clang_to_IR();
59 auto Buffer
= perf::getBPFObjectFromModule(&*M
);