xref: /llvm-project/llvm/benchmarks/GetIntrinsicForClangBuiltin.cpp (revision b55c52c047a167f42abbde9a33356cfb96b82c7f)
1*389f339cSRahul Joshi #include "benchmark/benchmark.h"
2*389f339cSRahul Joshi #include "llvm/IR/Intrinsics.h"
3*389f339cSRahul Joshi 
4*389f339cSRahul Joshi using namespace llvm;
5*389f339cSRahul Joshi using namespace Intrinsic;
6*389f339cSRahul Joshi 
7*389f339cSRahul Joshi // Benchmark intrinsic lookup from a variety of targets.
8*389f339cSRahul Joshi static void BM_GetIntrinsicForClangBuiltin(benchmark::State &state) {
9*389f339cSRahul Joshi   static const char *Builtins[] = {
10*389f339cSRahul Joshi       "__builtin_adjust_trampoline",
11*389f339cSRahul Joshi       "__builtin_trap",
12*389f339cSRahul Joshi       "__builtin_arm_ttest",
13*389f339cSRahul Joshi       "__builtin_amdgcn_cubetc",
14*389f339cSRahul Joshi       "__builtin_amdgcn_udot2",
15*389f339cSRahul Joshi       "__builtin_arm_stc",
16*389f339cSRahul Joshi       "__builtin_bpf_compare",
17*389f339cSRahul Joshi       "__builtin_HEXAGON_A2_max",
18*389f339cSRahul Joshi       "__builtin_lasx_xvabsd_b",
19*389f339cSRahul Joshi       "__builtin_mips_dlsa",
20*389f339cSRahul Joshi       "__nvvm_floor_f",
21*389f339cSRahul Joshi       "__builtin_altivec_vslb",
22*389f339cSRahul Joshi       "__builtin_r600_read_tgid_x",
23*389f339cSRahul Joshi       "__builtin_riscv_aes64im",
24*389f339cSRahul Joshi       "__builtin_s390_vcksm",
25*389f339cSRahul Joshi       "__builtin_ve_vl_pvfmksge_Mvl",
26*389f339cSRahul Joshi       "__builtin_ia32_axor64",
27*389f339cSRahul Joshi       "__builtin_bitrev",
28*389f339cSRahul Joshi   };
29*389f339cSRahul Joshi   static const char *Targets[] = {"",     "aarch64", "amdgcn", "mips",
30*389f339cSRahul Joshi                                   "nvvm", "r600",    "riscv"};
31*389f339cSRahul Joshi 
32*389f339cSRahul Joshi   for (auto _ : state) {
33*389f339cSRahul Joshi     for (auto Builtin : Builtins)
34*389f339cSRahul Joshi       for (auto Target : Targets)
35*389f339cSRahul Joshi         getIntrinsicForClangBuiltin(Target, Builtin);
36*389f339cSRahul Joshi   }
37*389f339cSRahul Joshi }
38*389f339cSRahul Joshi 
39*389f339cSRahul Joshi static void
40*389f339cSRahul Joshi BM_GetIntrinsicForClangBuiltinHexagonFirst(benchmark::State &state) {
41*389f339cSRahul Joshi   // Exercise the worst case by looking for the first builtin for a target
42*389f339cSRahul Joshi   // that has a lot of builtins.
43*389f339cSRahul Joshi   for (auto _ : state)
44*389f339cSRahul Joshi     getIntrinsicForClangBuiltin("hexagon", "__builtin_HEXAGON_A2_abs");
45*389f339cSRahul Joshi }
46*389f339cSRahul Joshi 
47*389f339cSRahul Joshi BENCHMARK(BM_GetIntrinsicForClangBuiltin);
48*389f339cSRahul Joshi BENCHMARK(BM_GetIntrinsicForClangBuiltinHexagonFirst);
49*389f339cSRahul Joshi 
50*389f339cSRahul Joshi BENCHMARK_MAIN();
51