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 kIntrnIsJava, 28 kIntrnIsJavaUnary, 29 kIntrnIsJavaBinary, 30 kIntrnIsReturnStruct, 31 kIntrnNoSideEffect, 32 kIntrnIsLoadMem, 33 kIntrnIsPure, 34 kIntrnNeverReturn, 35 kIntrnIsAtomic, 36 kIntrnIsRC, 37 kIntrnIsSpecial, 38 kIntrnIsVector 39 }; 40 41 enum IntrinArgType { 42 kArgTyUndef, 43 kArgTyVoid, 44 kArgTyI8, 45 kArgTyI16, 46 kArgTyI32, 47 kArgTyI64, 48 kArgTyU8, 49 kArgTyU16, 50 kArgTyU32, 51 kArgTyU64, 52 kArgTyU1, 53 kArgTyPtr, 54 kArgTyRef, 55 kArgTyA32, 56 kArgTyA64, 57 kArgTyF32, 58 kArgTyF64, 59 kArgTyF128, 60 kArgTyC64, 61 kArgTyC128, 62 kArgTyAgg, 63 kArgTyV2I64, 64 kArgTyV4I32, 65 kArgTyV8I16, 66 kArgTyV16I8, 67 kArgTyV2U64, 68 kArgTyV4U32, 69 kArgTyV8U16, 70 kArgTyV16U8, 71 kArgTyV2F64, 72 kArgTyV4F32, 73 kArgTyV1I64, 74 kArgTyV2I32, 75 kArgTyV4I16, 76 kArgTyV8I8, 77 kArgTyV1U64, 78 kArgTyV2U32, 79 kArgTyV4U16, 80 kArgTyV8U8, 81 kArgTyV1F64, 82 kArgTyV2F32, 83 #ifdef DYNAMICLANG 84 kArgTyDynany, 85 kArgTyDynu32, 86 kArgTyDyni32, 87 kArgTyDynundef, 88 kArgTyDynnull, 89 kArgTyDynhole, 90 kArgTyDynbool, 91 kArgTyDynf64, 92 kArgTyDynf32, 93 kArgTySimplestr, 94 kArgTyDynstr, 95 kArgTySimpleobj, 96 kArgTyDynobj 97 #endif 98 }; 99 100 constexpr uint32 INTRNISJS = 1U << kIntrnIsJs; 101 constexpr uint32 INTRNISJSUNARY = 1U << kIntrnIsJsUnary; 102 constexpr uint32 INTRNISJSBINARY = 1U << kIntrnIsJsBinary; 103 constexpr uint32 INTRNISJAVA = 1U << kIntrnIsJava; 104 constexpr uint32 INTRNNOSIDEEFFECT = 1U << kIntrnNoSideEffect; 105 constexpr uint32 INTRNRETURNSTRUCT = 1U << kIntrnIsReturnStruct; 106 constexpr uint32 INTRNLOADMEM = 1U << kIntrnIsLoadMem; 107 constexpr uint32 INTRNISPURE = 1U << kIntrnIsPure; 108 constexpr uint32 INTRNNEVERRETURN = 1U << kIntrnNeverReturn; 109 constexpr uint32 INTRNATOMIC = 1U << kIntrnIsAtomic; 110 constexpr uint32 INTRNISRC = 1U << kIntrnIsRC; 111 constexpr uint32 INTRNISSPECIAL = 1U << kIntrnIsSpecial; 112 constexpr uint32 INTRNISVECTOR = 1U << kIntrnIsVector; 113 class MIRType; // circular dependency exists, no other choice 114 class MIRModule; // circular dependency exists, no other choice 115 struct IntrinDesc { 116 static constexpr int kMaxArgsNum = 7; 117 const char *name; 118 uint32 properties; 119 IntrinArgType argTypes[1 + kMaxArgsNum]; // argTypes[0] is the return type IsJSIntrinDesc120 bool IsJS() const 121 { 122 return static_cast<bool>(properties & INTRNISJS); 123 } 124 IsJavaIntrinDesc125 bool IsJava() const 126 { 127 return static_cast<bool>(properties & INTRNISJAVA); 128 } 129 IsJsUnaryIntrinDesc130 bool IsJsUnary() const 131 { 132 return static_cast<bool>(properties & INTRNISJSUNARY); 133 } 134 IsJsBinaryIntrinDesc135 bool IsJsBinary() const 136 { 137 return static_cast<bool>(properties & INTRNISJSBINARY); 138 } 139 IsJsOpIntrinDesc140 bool IsJsOp() const 141 { 142 return static_cast<bool>(properties & INTRNISJSUNARY) || static_cast<bool>(properties & INTRNISJSBINARY); 143 } 144 IsLoadMemIntrinDesc145 bool IsLoadMem() const 146 { 147 return static_cast<bool>(properties & INTRNLOADMEM); 148 } 149 IsJsReturnStructIntrinDesc150 bool IsJsReturnStruct() const 151 { 152 return static_cast<bool>(properties & INTRNRETURNSTRUCT); 153 } 154 IsPureIntrinDesc155 bool IsPure() const 156 { 157 return static_cast<bool>(properties & INTRNISPURE); 158 } 159 IsNeverReturnIntrinDesc160 bool IsNeverReturn() const 161 { 162 return static_cast<bool>(properties & INTRNNEVERRETURN); 163 } 164 IsAtomicIntrinDesc165 bool IsAtomic() const 166 { 167 return static_cast<bool>(properties & INTRNATOMIC); 168 } 169 IsRCIntrinDesc170 bool IsRC() const 171 { 172 return static_cast<bool>(properties & INTRNISRC); 173 } 174 IsSpecialIntrinDesc175 bool IsSpecial() const 176 { 177 return static_cast<bool>(properties & INTRNISSPECIAL); 178 } 179 HasNoSideEffectIntrinDesc180 bool HasNoSideEffect() const 181 { 182 return properties & INTRNNOSIDEEFFECT; 183 } 184 IsVectorOpIntrinDesc185 bool IsVectorOp() const 186 { 187 return static_cast<bool>(properties & INTRNISVECTOR); 188 } 189 190 MIRType *GetReturnType() const; 191 MIRType *GetArgType(uint32 index) const; 192 MIRType *GetTypeFromArgTy(IntrinArgType argType) const; 193 static MIRType *jsValueType; 194 static MIRModule *mirModule; 195 static void InitMIRModule(MIRModule *mirModule); 196 static MIRType *GetOrCreateJSValueType(); 197 static IntrinDesc intrinTable[INTRN_LAST + 1]; 198 }; 199 } // namespace maple 200 #endif // MAPLE_IR_INCLUDE_INTRINSICS_H 201