1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_COMPILER_OPTIMIZING_PROFILING_INFO_BUILDER_H_
18 #define ART_COMPILER_OPTIMIZING_PROFILING_INFO_BUILDER_H_
19 
20 #include "base/macros.h"
21 #include "nodes.h"
22 
23 namespace art HIDDEN {
24 
25 class CodeGenerator;
26 class CompilerOptions;
27 class HInliner;
28 class InlineCache;
29 class ProfilingInfo;
30 
31 class ProfilingInfoBuilder final : public HGraphDelegateVisitor {
32  public:
33   ProfilingInfoBuilder(HGraph* graph,
34                        const CompilerOptions& compiler_options,
35                        CodeGenerator* codegen,
36                        OptimizingCompilerStats* stats = nullptr)
HGraphDelegateVisitor(graph,stats)37       : HGraphDelegateVisitor(graph, stats),
38         codegen_(codegen),
39         compiler_options_(compiler_options) {}
40 
41   void Run();
42 
43   static constexpr const char* kProfilingInfoBuilderPassName =
44       "profiling_info_builder";
45 
46   static InlineCache* GetInlineCache(ProfilingInfo* info,
47                                      const CompilerOptions& compiler_options,
48                                      HInvoke* invoke);
49   static bool IsInlineCacheUseful(HInvoke* invoke, CodeGenerator* codegen);
50   static uint32_t EncodeInlinedDexPc(
51       const HInliner* inliner, const CompilerOptions& compiler_options, HInvoke* invoke)
52       REQUIRES_SHARED(Locks::mutator_lock_);
53 
54  private:
55   void VisitInvokeVirtual(HInvokeVirtual* invoke) override;
56   void VisitInvokeInterface(HInvokeInterface* invoke) override;
57 
58   void HandleInvoke(HInvoke* invoke);
59 
60   CodeGenerator* codegen_;
61   const CompilerOptions& compiler_options_;
62   std::vector<uint32_t> inline_caches_;
63 
64   DISALLOW_COPY_AND_ASSIGN(ProfilingInfoBuilder);
65 };
66 
67 }  // namespace art
68 
69 
70 #endif  // ART_COMPILER_OPTIMIZING_PROFILING_INFO_BUILDER_H_
71