• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef COMPILER_OPTIMIZER_OPTIMIZATIONS_NATIVE_CALL_OPTIMIZATION_H
17 #define COMPILER_OPTIMIZER_OPTIMIZATIONS_NATIVE_CALL_OPTIMIZATION_H
18 
19 #include "optimizer/ir/graph.h"
20 #include "optimizer/ir/graph_visitor.h"
21 #include "optimizer/pass.h"
22 
23 namespace ark::compiler {
24 
25 // NOLINTNEXTLINE(fuchsia-multiple-inheritance)
26 class PANDA_PUBLIC_API NativeCallOptimization : public Optimization, public GraphVisitor {
27     using Optimization::Optimization;
28 
29 public:
NativeCallOptimization(Graph * graph)30     explicit NativeCallOptimization(Graph *graph) : Optimization(graph) {}
31 
32     NO_MOVE_SEMANTIC(NativeCallOptimization);
33     NO_COPY_SEMANTIC(NativeCallOptimization);
34     ~NativeCallOptimization() override = default;
35 
36     bool RunImpl() override;
37 
GetPassName()38     const char *GetPassName() const override
39     {
40         return "NativeCallOptimization";
41     }
42 
SetIsApplied()43     void SetIsApplied()
44     {
45         isApplied_ = true;
46     }
47 
IsApplied()48     bool IsApplied() const
49     {
50         return isApplied_;
51     }
52 
53     void InvalidateAnalyses() override;
54 
GetBlocksToVisit()55     const ArenaVector<BasicBlock *> &GetBlocksToVisit() const override
56     {
57         return GetGraph()->GetBlocksRPO();
58     }
59 
60     static void VisitCallStatic(GraphVisitor *v, Inst *inst);
61 
62 #include "optimizer/ir/visitor.inc"
63 
64 private:
65     static void OptimizePrimitiveNativeCall(GraphVisitor *v, CallInst *callInst);
66     static void OptimizeNativeCallWithObjects(GraphVisitor *v, CallInst *callInst);
67 
68     IntrinsicInst *CreateNativeApiIntrinsic(DataType::Type type, uint32_t pc, RuntimeInterface::IntrinsicId id,
69                                             const MethodDataMixin *methodData);
70 
71     bool isApplied_ {false};
72 };
73 
74 }  // namespace ark::compiler
75 
76 #endif  // COMPILER_OPTIMIZER_OPTIMIZATIONS_NATIVE_CALL_OPTIMIZATION_H
77