2
0

Sym.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. class Lifetime;
  7. namespace IR
  8. {
  9. class Instr;
  10. class Opnd;
  11. }
  12. class StackSym;
  13. class PropertySym;
  14. typedef JsUtil::BaseDictionary<StackSym*, StackSym*, JitArenaAllocator, PrimeSizePolicy> StackSymMap;
  15. typedef JsUtil::BaseDictionary<StackSym*, IR::Instr*, JitArenaAllocator, PrimeSizePolicy> SymInstrMap;
  16. enum SymKind : BYTE
  17. {
  18. SymKindInvalid,
  19. SymKindStack,
  20. SymKindProperty
  21. };
  22. typedef uint32 SymID;
  23. ///---------------------------------------------------------------------------
  24. ///
  25. /// class Sym
  26. /// StackSym
  27. /// PropertySym
  28. ///
  29. ///---------------------------------------------------------------------------
  30. class Sym
  31. {
  32. public:
  33. bool IsStackSym() const;
  34. StackSym * AsStackSym();
  35. bool IsPropertySym() const;
  36. PropertySym * AsPropertySym();
  37. #if DBG_DUMP || defined(ENABLE_IR_VIEWER)
  38. void Dump(IRDumpFlags flags, const ValueType valueType = ValueType::Uninitialized);
  39. void Dump(const ValueType valueType = ValueType::Uninitialized);
  40. void DumpSimple();
  41. #endif
  42. #if DBG_DUMP
  43. // Having a VTable helps the VS debugger determine which derived class we have
  44. void virtual DummyVirtualFunc() {};
  45. #endif
  46. public:
  47. Sym * m_next;
  48. SymID m_id;
  49. SymKind m_kind;
  50. };
  51. class ObjectSymInfo
  52. {
  53. public:
  54. static ObjectSymInfo * New(Func * func);
  55. static ObjectSymInfo * New(StackSym * typeSym, Func * func);
  56. ObjectSymInfo(): m_typeSym(nullptr), m_propertySymList(nullptr) {};
  57. public:
  58. StackSym * m_typeSym;
  59. PropertySym * m_propertySymList;
  60. };
  61. ///---------------------------------------------------------------------------
  62. ///
  63. /// class StackSym
  64. ///
  65. /// Used for stack symbols. These are the register candidates.
  66. ///
  67. ///---------------------------------------------------------------------------
  68. class StackSym: public Sym
  69. {
  70. private:
  71. static StackSym * New(SymID id, IRType type, Js::RegSlot byteCodeRegSlot, Func *func);
  72. public:
  73. static StackSym * NewArgSlotSym(Js::ArgSlot argSlotNum, Func * func, IRType = TyVar);
  74. static StackSym * NewArgSlotRegSym(Js::ArgSlot argSlotNum, Func * func, IRType = TyVar);
  75. static StackSym * NewParamSlotSym(Js::ArgSlot argSlotNum, Func * func);
  76. static StackSym * NewParamSlotSym(Js::ArgSlot argSlotNum, Func * func, IRType type);
  77. static StackSym *NewImplicitParamSym(Js::ArgSlot paramSlotNum, Func * func);
  78. static StackSym * New(IRType type, Func *func);
  79. static StackSym * New(Func *func);
  80. static StackSym * FindOrCreate(SymID id, Js::RegSlot byteCodeRegSlot, Func *func, IRType type = TyVar);
  81. IRType GetType() const { return this->m_type; }
  82. bool IsArgSlotSym() const;
  83. bool IsParamSlotSym() const;
  84. bool IsImplicitParamSym() const { return this->m_isImplicitParamSym; }
  85. bool IsAllocated() const;
  86. int32 GetIntConstValue() const;
  87. Js::Var GetFloatConstValueAsVar_PostGlobOpt() const;
  88. void * GetConstAddress(bool useLocal = false) const;
  89. StackSym * CloneDef(Func *func);
  90. StackSym * CloneUse(Func *func);
  91. void CopySymAttrs(StackSym *symSrc);
  92. bool IsSingleDef() const { return this->m_isSingleDef && this->m_instrDef; }
  93. bool IsConst() const;
  94. bool IsIntConst() const;
  95. bool IsInt64Const() const;
  96. bool IsTaggableIntConst() const;
  97. bool IsFloatConst() const;
  98. // SIMD_JS
  99. bool IsSimd128Const() const;
  100. void SetIsConst();
  101. void SetIsIntConst(IntConstType value);
  102. void SetIsInt64Const();
  103. void SetIsFloatConst();
  104. // SIMD_JS
  105. void SetIsSimd128Const();
  106. intptr_t GetLiteralConstValue_PostGlobOpt() const;
  107. IR::Opnd * GetConstOpnd() const;
  108. BailoutConstantValue GetConstValueForBailout() const;
  109. // SIMD_JS
  110. StackSym * GetSimd128EquivSym(IRType type, Func *func);
  111. StackSym * GetSimd128F4EquivSym(Func *func);
  112. StackSym * GetSimd128I4EquivSym(Func *func);
  113. StackSym * GetSimd128I16EquivSym(Func *func);
  114. StackSym * GetSimd128D2EquivSym(Func *func);
  115. bool IsSimd128() const { return IRType_IsSimd128(this->GetType()); }
  116. bool IsSimd128F4() const { return this->GetType() == TySimd128F4; }
  117. bool IsSimd128I4() const { return this->GetType() == TySimd128I4; }
  118. bool IsSimd128I8() const { return this->GetType() == TySimd128I8; }
  119. bool IsSimd128I16() const { return this->GetType() == TySimd128I16; }
  120. bool IsSimd128U4() const { return this->GetType() == TySimd128U4; }
  121. bool IsSimd128U8() const { return this->GetType() == TySimd128U8; }
  122. bool IsSimd128U16() const { return this->GetType() == TySimd128U16; }
  123. bool IsSimd128B4() const { return this->GetType() == TySimd128B4; }
  124. bool IsSimd128B8() const { return this->GetType() == TySimd128B8; }
  125. bool IsSimd128B16() const { return this->GetType() == TySimd128B16; }
  126. bool IsSimd128D2() const { return this->GetType() == TySimd128D2; }
  127. StackSym * GetFloat64EquivSym(Func *func);
  128. bool IsFloat64() const { return this->GetType() == TyFloat64; }
  129. bool IsFloat32() const { return this->GetType() == TyFloat32; }
  130. StackSym * GetInt32EquivSym(Func *func);
  131. bool IsInt32() const { return this->GetType() == TyInt32; }
  132. bool IsUInt32() const { return this->GetType() == TyUint32; }
  133. bool IsInt64() const { return this->GetType() == TyInt64; }
  134. bool IsUint64() const { return this->GetType() == TyUint64; }
  135. StackSym * GetVarEquivSym(Func *func);
  136. bool IsVar() const { return this->GetType() == TyVar; }
  137. bool IsTypeSpec() const { return this->m_isTypeSpec; }
  138. static StackSym *GetVarEquivStackSym_NoCreate(Sym *const sym);
  139. bool HasByteCodeRegSlot() const { return m_hasByteCodeRegSlot; }
  140. Func * GetByteCodeFunc() const;
  141. Js::RegSlot GetByteCodeRegSlot() const;
  142. bool IsTempReg(Func *const func) const;
  143. bool IsFromByteCodeConstantTable() const { return m_isFromByteCodeConstantTable; }
  144. void SetIsFromByteCodeConstantTable() { this->m_isFromByteCodeConstantTable = true; }
  145. Js::ArgSlot GetArgSlotNum() const { Assert(HasArgSlotNum()); return m_slotNum; }
  146. bool HasArgSlotNum() const { return !!(m_isArgSlotSym | m_isArgSlotRegSym); }
  147. void IncrementArgSlotNum();
  148. void DecrementArgSlotNum();
  149. Js::ArgSlot GetParamSlotNum() const { Assert(IsParamSlotSym()); return m_slotNum; }
  150. IR::Instr * GetInstrDef() const { return this->IsSingleDef() ? this->m_instrDef : nullptr; }
  151. bool HasObjectInfo() const { Assert(!IsTypeSpec()); return this->m_objectInfo != nullptr; };
  152. ObjectSymInfo * GetObjectInfo() const { Assert(this->m_objectInfo); return this->m_objectInfo; }
  153. void SetObjectInfo(ObjectSymInfo * value) { this->m_objectInfo = value; }
  154. ObjectSymInfo * EnsureObjectInfo(Func * func);
  155. bool HasObjectTypeSym() const { return HasObjectInfo() && GetObjectInfo()->m_typeSym; }
  156. StackSym * GetObjectTypeSym() const { Assert(HasObjectTypeSym()); return GetObjectInfo()->m_typeSym; }
  157. int GetSymSize(){ return TySize[m_type]; }
  158. void FixupStackOffset(Func * currentFunc);
  159. private:
  160. StackSym * GetTypeEquivSym(IRType type, Func *func);
  161. #if DBG
  162. void VerifyConstFlags() const;
  163. #endif
  164. private:
  165. Js::ArgSlot m_slotNum;
  166. public:
  167. uint8 m_isSingleDef:1; // the symbol only has a single definition in the IR
  168. uint8 m_isNotInt:1;
  169. uint8 m_isSafeThis : 1;
  170. uint8 m_isConst : 1; // single def and it is a constant
  171. uint8 m_isIntConst : 1; // a constant and it's value is an Int32
  172. uint8 m_isTaggableIntConst : 1; // a constant and it's value is taggable (Int31 in 32-bit, Int32 in x64)
  173. uint8 m_isEncodedConstant : 1; // the constant has
  174. uint8 m_isInt64Const: 1;
  175. uint8 m_isFltConst: 1;
  176. uint8 m_isSimd128Const : 1;
  177. uint8 m_isStrConst:1;
  178. uint8 m_isStrEmpty:1;
  179. uint8 m_allocated:1;
  180. uint8 m_hasByteCodeRegSlot:1;
  181. uint8 m_isInlinedArgSlot:1;
  182. uint8 m_isOrphanedArg :1;
  183. uint8 m_isTypeSpec:1;
  184. uint8 m_requiresBailOnNotNumber:1;
  185. uint8 m_isFromByteCodeConstantTable:1;
  186. uint8 m_mayNotBeTempLastUse:1;
  187. uint8 m_isArgSlotSym: 1; // When set this implies an argument stack slot with no lifetime for register allocation
  188. uint8 m_isArgSlotRegSym : 1;
  189. uint8 m_isParamSym : 1;
  190. uint8 m_isImplicitParamSym : 1;
  191. uint8 m_isBailOutReferenced: 1; // argument sym referenced by bailout
  192. uint8 m_isArgCaptured: 1; // True if there is a ByteCodeArgOutCapture for this symbol
  193. uint8 m_nonEscapingArgObjAlias : 1;
  194. uint8 m_isCatchObjectSym : 1; // a catch object sym (used while jitting loop bodies)
  195. IRType m_type;
  196. Js::BuiltinFunction m_builtInIndex;
  197. int32 m_offset;
  198. #ifdef _M_AMD64
  199. // Only for AsmJs on x64. Argument position for ArgSyms.
  200. int32 m_argPosition;
  201. #endif
  202. union
  203. {
  204. IR::Instr * m_instrDef; // m_isSingleDef
  205. size_t constantValue; // !m_isSingleDef && m_isEncodedConstant
  206. };
  207. StackSym * m_tempNumberSym;
  208. StackSym * m_equivNext;
  209. ObjectSymInfo * m_objectInfo;
  210. union {
  211. struct GlobOpt
  212. {
  213. int numCompoundedAddSubUses;
  214. } globOpt;
  215. struct LinearScan
  216. {
  217. Lifetime * lifetime;
  218. } linearScan;
  219. struct Peeps
  220. {
  221. RegNum reg;
  222. } peeps;
  223. }scratch;
  224. static const Js::ArgSlot InvalidSlot;
  225. };
  226. class ByteCodeStackSym : public StackSym
  227. {
  228. private:
  229. ByteCodeStackSym(Js::RegSlot byteCodeRegSlot, Func * byteCodeFunc)
  230. : byteCodeRegSlot(byteCodeRegSlot), byteCodeFunc(byteCodeFunc) {}
  231. Js::RegSlot byteCodeRegSlot;
  232. Func * byteCodeFunc;
  233. friend class StackSym;
  234. };
  235. ///---------------------------------------------------------------------------
  236. ///
  237. /// class PropertySym
  238. ///
  239. /// Used for field symbols. Property syms for a given objects are linked
  240. /// together.
  241. ///
  242. ///---------------------------------------------------------------------------
  243. enum PropertyKind : BYTE
  244. {
  245. PropertyKindData,
  246. PropertyKindSlots,
  247. PropertyKindLocalSlots,
  248. PropertyKindSlotArray,
  249. PropertyKindWriteGuard
  250. };
  251. class PropertySym: public Sym
  252. {
  253. friend class Sym;
  254. public:
  255. static PropertySym * New(SymID stackSymID, int32 propertyId, uint32 propertyIdIndex, uint inlineCacheIndex, PropertyKind fieldKind, Func *func);
  256. static PropertySym * New(StackSym *stackSym, int32 propertyId, uint32 propertyIdIndex, uint inlineCacheIndex, PropertyKind fieldKind, Func *func);
  257. static PropertySym * Find(SymID stackSymID, int32 propertyId, Func *func);
  258. static PropertySym * FindOrCreate(SymID stackSymID, int32 propertyId, uint32 propertyIdIndex, uint inlineCacheIndex, PropertyKind fieldKind, Func *func);
  259. Func *GetFunc() { return m_func; }
  260. bool HasPropertyIdIndex() { return m_propertyIdIndex != -1; }
  261. int32 GetPropertyIdIndex() { return m_propertyIdIndex; }
  262. bool HasInlineCacheIndex() { return m_inlineCacheIndex != -1; }
  263. int32 GetInlineCacheIndex() { return m_inlineCacheIndex; }
  264. bool HasObjectTypeSym() const { return this->m_stackSym->HasObjectTypeSym(); }
  265. bool HasWriteGuardSym() const { return this->m_writeGuardSym != nullptr; }
  266. StackSym * GetObjectTypeSym() const { return this->m_stackSym->GetObjectTypeSym(); }
  267. public:
  268. PropertyKind m_fieldKind;
  269. int32 m_propertyId;
  270. StackSym * m_stackSym;
  271. BVSparse<JitArenaAllocator> *m_propertyEquivSet; // Bit vector of all propertySyms with same propertyId
  272. PropertySym * m_nextInStackSymList;
  273. PropertySym * m_writeGuardSym;
  274. Func * m_func;
  275. Func * m_loadInlineCacheFunc;
  276. uint m_loadInlineCacheIndex;
  277. private:
  278. uint32 m_propertyIdIndex;
  279. uint m_inlineCacheIndex;
  280. };