• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 MAPLE_IR_INCLUDE_INTRINSICS_H
17 #define MAPLE_IR_INCLUDE_INTRINSICS_H
18 #include "prim_types.h"
19 #include "intrinsic_op.h"
20 
21 namespace maple {
22 enum IntrinProperty {
23     kIntrnUndef,
24     kIntrnIsJs,
25     kIntrnIsJsUnary,
26     kIntrnIsJsBinary,
27     kIntrnIsReturnStruct,
28     kIntrnNoSideEffect,
29     kIntrnIsLoadMem,
30     kIntrnIsPure,
31     kIntrnNeverReturn,
32     kIntrnIsAtomic,
33     kIntrnIsRC,
34     kIntrnIsSpecial,
35     kIntrnIsVector
36 };
37 
38 enum IntrinArgType {
39     kArgTyUndef,
40     kArgTyVoid,
41     kArgTyI8,
42     kArgTyI16,
43     kArgTyI32,
44     kArgTyI64,
45     kArgTyU8,
46     kArgTyU16,
47     kArgTyU32,
48     kArgTyU64,
49     kArgTyU1,
50     kArgTyPtr,
51     kArgTyRef,
52     kArgTyA32,
53     kArgTyA64,
54     kArgTyF32,
55     kArgTyF64,
56     kArgTyF128,
57     kArgTyC64,
58     kArgTyC128,
59     kArgTyAgg,
60     kArgTyV2I64,
61     kArgTyV4I32,
62     kArgTyV8I16,
63     kArgTyV16I8,
64     kArgTyV2U64,
65     kArgTyV4U32,
66     kArgTyV8U16,
67     kArgTyV16U8,
68     kArgTyV2F64,
69     kArgTyV4F32,
70     kArgTyV1I64,
71     kArgTyV2I32,
72     kArgTyV4I16,
73     kArgTyV8I8,
74     kArgTyV1U64,
75     kArgTyV2U32,
76     kArgTyV4U16,
77     kArgTyV8U8,
78     kArgTyV1F64,
79     kArgTyV2F32,
80 #ifdef DYNAMICLANG
81     kArgTyDynany,
82     kArgTyDynu32,
83     kArgTyDyni32,
84     kArgTyDynundef,
85     kArgTyDynnull,
86     kArgTyDynhole,
87     kArgTyDynbool,
88     kArgTyDynf64,
89     kArgTyDynf32,
90     kArgTySimplestr,
91     kArgTyDynstr,
92     kArgTySimpleobj,
93     kArgTyDynobj
94 #endif
95 };
96 
97 constexpr uint32 INTRNISJS = 1U << kIntrnIsJs;
98 constexpr uint32 INTRNISJSUNARY = 1U << kIntrnIsJsUnary;
99 constexpr uint32 INTRNISJSBINARY = 1U << kIntrnIsJsBinary;
100 constexpr uint32 INTRNNOSIDEEFFECT = 1U << kIntrnNoSideEffect;
101 constexpr uint32 INTRNRETURNSTRUCT = 1U << kIntrnIsReturnStruct;
102 constexpr uint32 INTRNLOADMEM = 1U << kIntrnIsLoadMem;
103 constexpr uint32 INTRNISPURE = 1U << kIntrnIsPure;
104 constexpr uint32 INTRNNEVERRETURN = 1U << kIntrnNeverReturn;
105 constexpr uint32 INTRNATOMIC = 1U << kIntrnIsAtomic;
106 constexpr uint32 INTRNISRC = 1U << kIntrnIsRC;
107 constexpr uint32 INTRNISSPECIAL = 1U << kIntrnIsSpecial;
108 constexpr uint32 INTRNISVECTOR = 1U << kIntrnIsVector;
109 class MIRType;    // circular dependency exists, no other choice
110 class MIRModule;  // circular dependency exists, no other choice
111 struct IntrinDesc {
112     static constexpr int kMaxArgsNum = 7;
113     const char *name;
114     uint32 properties;
115     IntrinArgType argTypes[1 + kMaxArgsNum];  // argTypes[0] is the return type
IsJSIntrinDesc116     bool IsJS() const
117     {
118         return static_cast<bool>(properties & INTRNISJS);
119     }
120 
IsJsUnaryIntrinDesc121     bool IsJsUnary() const
122     {
123         return static_cast<bool>(properties & INTRNISJSUNARY);
124     }
125 
IsJsBinaryIntrinDesc126     bool IsJsBinary() const
127     {
128         return static_cast<bool>(properties & INTRNISJSBINARY);
129     }
130 
IsJsOpIntrinDesc131     bool IsJsOp() const
132     {
133         return static_cast<bool>(properties & INTRNISJSUNARY) || static_cast<bool>(properties & INTRNISJSBINARY);
134     }
135 
IsLoadMemIntrinDesc136     bool IsLoadMem() const
137     {
138         return static_cast<bool>(properties & INTRNLOADMEM);
139     }
140 
IsJsReturnStructIntrinDesc141     bool IsJsReturnStruct() const
142     {
143         return static_cast<bool>(properties & INTRNRETURNSTRUCT);
144     }
145 
IsPureIntrinDesc146     bool IsPure() const
147     {
148         return static_cast<bool>(properties & INTRNISPURE);
149     }
150 
IsNeverReturnIntrinDesc151     bool IsNeverReturn() const
152     {
153         return static_cast<bool>(properties & INTRNNEVERRETURN);
154     }
155 
IsAtomicIntrinDesc156     bool IsAtomic() const
157     {
158         return static_cast<bool>(properties & INTRNATOMIC);
159     }
160 
IsRCIntrinDesc161     bool IsRC() const
162     {
163         return static_cast<bool>(properties & INTRNISRC);
164     }
165 
IsSpecialIntrinDesc166     bool IsSpecial() const
167     {
168         return static_cast<bool>(properties & INTRNISSPECIAL);
169     }
170 
HasNoSideEffectIntrinDesc171     bool HasNoSideEffect() const
172     {
173         return properties & INTRNNOSIDEEFFECT;
174     }
175 
IsVectorOpIntrinDesc176     bool IsVectorOp() const
177     {
178         return static_cast<bool>(properties & INTRNISVECTOR);
179     }
180 
181     MIRType *GetReturnType() const;
182     MIRType *GetArgType(uint32 index) const;
183     MIRType *GetTypeFromArgTy(IntrinArgType argType) const;
184     static MIRType *jsValueType;
185     static MIRModule *mirModule;
186     static void InitMIRModule(MIRModule *mirModule);
187     static MIRType *GetOrCreateJSValueType();
188     static IntrinDesc intrinTable[INTRN_LAST + 1];
189 };
190 }  // namespace maple
191 #endif  // MAPLE_IR_INCLUDE_INTRINSICS_H
192