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_INTRINSICS_RISCV64_H_
18 #define ART_COMPILER_OPTIMIZING_INTRINSICS_RISCV64_H_
19 
20 #include "base/macros.h"
21 #include "intrinsics.h"
22 #include "intrinsics_list.h"
23 
24 namespace art HIDDEN {
25 
26 class ArenaAllocator;
27 class HInvokeStaticOrDirect;
28 class HInvokeVirtual;
29 
30 namespace riscv64 {
31 
32 class CodeGeneratorRISCV64;
33 class Riscv64Assembler;
34 
35 class IntrinsicLocationsBuilderRISCV64 final : public IntrinsicVisitor {
36  public:
IntrinsicLocationsBuilderRISCV64(ArenaAllocator * allocator,CodeGeneratorRISCV64 * codegen)37   explicit IntrinsicLocationsBuilderRISCV64(ArenaAllocator* allocator,
38                                             CodeGeneratorRISCV64* codegen)
39       : allocator_(allocator), codegen_(codegen) {}
40 
41   // Define visitor methods.
42 
43 #define OPTIMIZING_INTRINSICS(Name, ...) \
44   void Visit##Name(HInvoke* invoke) override;
45   ART_INTRINSICS_WITH_HINVOKE_LIST(OPTIMIZING_INTRINSICS)
46 #undef OPTIMIZING_INTRINSICS
47 
48   // Check whether an invoke is an intrinsic, and if so, create a location summary. Returns whether
49   // a corresponding LocationSummary with the intrinsified_ flag set was generated and attached to
50   // the invoke.
51   bool TryDispatch(HInvoke* invoke);
52 
53  private:
54   ArenaAllocator* const allocator_;
55   CodeGeneratorRISCV64* const codegen_;
56 
57   DISALLOW_COPY_AND_ASSIGN(IntrinsicLocationsBuilderRISCV64);
58 };
59 
60 class IntrinsicCodeGeneratorRISCV64 final : public IntrinsicVisitor {
61  public:
IntrinsicCodeGeneratorRISCV64(CodeGeneratorRISCV64 * codegen)62   explicit IntrinsicCodeGeneratorRISCV64(CodeGeneratorRISCV64* codegen) : codegen_(codegen) {}
63 
64   // Define visitor methods.
65 
66 #define OPTIMIZING_INTRINSICS(Name, ...) \
67   void Visit##Name(HInvoke* invoke);
68   ART_INTRINSICS_WITH_HINVOKE_LIST(OPTIMIZING_INTRINSICS)
69 #undef OPTIMIZING_INTRINSICS
70 
71  private:
72   Riscv64Assembler* GetAssembler();
73   ArenaAllocator* GetAllocator();
74 
75   void HandleValueOf(HInvoke* invoke,
76                      const IntrinsicVisitor::ValueOfInfo& info,
77                      DataType::Type type);
78 
79   CodeGeneratorRISCV64* const codegen_;
80 
81   DISALLOW_COPY_AND_ASSIGN(IntrinsicCodeGeneratorRISCV64);
82 };
83 
84 }  // namespace riscv64
85 }  // namespace art
86 
87 #endif  // ART_COMPILER_OPTIMIZING_INTRINSICS_RISCV64_H_
88