• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "unit_test.h"
17 #include "panda_runner.h"
18 #include "runtime/jit/profiling_data.h"
19 
20 namespace panda::test {
21 class ProfilingRunnerTest : public testing::Test {
22 };
23 
24 static constexpr auto SOURCE = R"(
25 .function void main() <static> {
26   movi v0, 0x2
27   movi v1, 0x0
28   jump_label_1: lda v1
29   jge v0, jump_label_0
30   call.short foo
31   inci v1, 0x1
32   jmp jump_label_1
33   jump_label_0: return.void
34 }
35 
36 .function i32 foo() <static> {
37   movi v0, 0x64
38   movi v1, 0x0
39   mov v2, v1
40   jump_label_3: lda v2
41   jge v0, jump_label_0
42   lda v2
43   modi 0x3
44   jnez jump_label_1
45   lda v1
46   addi 0x2
47   sta v3
48   mov v1, v3
49   jmp jump_label_2
50   jump_label_1: lda v1
51   addi 0x3
52   sta v3
53   mov v1, v3
54   jump_label_2: inci v2, 0x1
55   jmp jump_label_3
56   jump_label_0: lda v1
57   return
58 }
59 )";
60 
TEST_F(ProfilingRunnerTest,BranchStatistics)61 TEST_F(ProfilingRunnerTest, BranchStatistics)
62 {
63     PandaRunner runner;
64     runner.GetRuntimeOptions().SetCompilerProfilingThreshold(1);
65     auto runtime = runner.CreateRuntime();
66     runner.Run(runtime, SOURCE, std::vector<std::string> {});
67     auto method = runner.GetMethod("foo");
68     auto profiling_data = method->GetProfilingData();
69     ASSERT_EQ(132, profiling_data->GetBranchTakenCounter(0x10));
70     ASSERT_EQ(199, profiling_data->GetBranchNotTakenCounter(0x09));
71     ASSERT_EQ(67, profiling_data->GetBranchNotTakenCounter(0x10));
72     Runtime::Destroy();
73 }
74 }  // namespace panda::test
75