Opnd.inl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. 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. namespace IR {
  7. ///----------------------------------------------------------------------------
  8. ///
  9. /// Opnd::Use
  10. ///
  11. /// If this operand is not inUse, use it. Otherwise, make a copy.
  12. ///
  13. ///----------------------------------------------------------------------------
  14. inline Opnd *
  15. Opnd::Use(Func *func)
  16. {
  17. if (!m_inUse)
  18. {
  19. m_inUse = true;
  20. return this;
  21. }
  22. Opnd * newOpnd = this->Copy(func);
  23. newOpnd->m_inUse = true;
  24. return newOpnd;
  25. }
  26. ///----------------------------------------------------------------------------
  27. ///
  28. /// Opnd::UnUse
  29. ///
  30. ///----------------------------------------------------------------------------
  31. inline void
  32. Opnd::UnUse()
  33. {
  34. AssertMsg(m_inUse, "Expected inUse to be set...");
  35. m_inUse = false;
  36. }
  37. ///----------------------------------------------------------------------------
  38. ///
  39. /// Opnd::IsSymOpnd
  40. ///
  41. ///----------------------------------------------------------------------------
  42. inline bool
  43. Opnd::IsSymOpnd() const
  44. {
  45. return GetKind() == OpndKindSym;
  46. }
  47. ///----------------------------------------------------------------------------
  48. ///
  49. /// Opnd::AsSymOpnd
  50. ///
  51. /// Use this opnd as a SymOpnd.
  52. ///
  53. ///----------------------------------------------------------------------------
  54. inline SymOpnd *
  55. Opnd::AsSymOpnd()
  56. {
  57. AssertMsg(this->IsSymOpnd(), "Bad call to AsSymOpnd()");
  58. return reinterpret_cast<SymOpnd *>(this);
  59. }
  60. inline PropertySymOpnd *
  61. Opnd::AsPropertySymOpnd()
  62. {
  63. AssertMsg(this->IsSymOpnd() && this->AsSymOpnd()->IsPropertySymOpnd(), "Bad call to AsPropertySymOpnd()");
  64. return reinterpret_cast<PropertySymOpnd *>(this);
  65. }
  66. ///----------------------------------------------------------------------------
  67. ///
  68. /// Opnd::IsRegOpnd
  69. ///
  70. ///----------------------------------------------------------------------------
  71. inline bool
  72. Opnd::IsRegOpnd() const
  73. {
  74. return GetKind() == OpndKindReg;
  75. }
  76. ///----------------------------------------------------------------------------
  77. ///
  78. /// Opnd::AsRegOpnd
  79. ///
  80. /// Use this opnd as a RegOpnd.
  81. ///
  82. ///----------------------------------------------------------------------------
  83. inline const RegOpnd *
  84. Opnd::AsRegOpnd() const
  85. {
  86. AssertMsg(this->IsRegOpnd(), "Bad call to AsRegOpnd()");
  87. return reinterpret_cast<const RegOpnd *>(this);
  88. }
  89. ///----------------------------------------------------------------------------
  90. ///
  91. /// Opnd::AsRegOpnd
  92. ///
  93. /// Use this opnd as a RegOpnd.
  94. ///
  95. ///----------------------------------------------------------------------------
  96. inline RegOpnd *
  97. Opnd::AsRegOpnd()
  98. {
  99. AssertMsg(this->IsRegOpnd(), "Bad call to AsRegOpnd()");
  100. return reinterpret_cast<RegOpnd *>(this);
  101. }
  102. ///----------------------------------------------------------------------------
  103. ///
  104. /// Opnd::IsRegBVOpnd
  105. ///
  106. ///----------------------------------------------------------------------------
  107. inline bool
  108. Opnd::IsRegBVOpnd() const
  109. {
  110. return GetKind() == OpndKindRegBV;
  111. }
  112. ///----------------------------------------------------------------------------
  113. ///
  114. /// Opnd::AsRegBVOpnd
  115. ///
  116. /// Use this opnd as a RegBVOpnd.
  117. ///
  118. ///----------------------------------------------------------------------------
  119. inline RegBVOpnd *
  120. Opnd::AsRegBVOpnd()
  121. {
  122. AssertMsg(this->IsRegBVOpnd(), "Bad call to AsRegOpnd()");
  123. return reinterpret_cast<RegBVOpnd *>(this);
  124. }
  125. ///----------------------------------------------------------------------------
  126. ///
  127. /// Opnd::IsIntConstOpnd
  128. ///
  129. ///----------------------------------------------------------------------------
  130. inline bool
  131. Opnd::IsIntConstOpnd() const
  132. {
  133. return GetKind() == OpndKindIntConst;
  134. }
  135. ///----------------------------------------------------------------------------
  136. ///
  137. /// Opnd::AsIntConstOpnd
  138. ///
  139. /// Use this opnd as a IntConstOpnd.
  140. ///
  141. ///----------------------------------------------------------------------------
  142. inline IntConstOpnd *
  143. Opnd::AsIntConstOpnd()
  144. {
  145. AssertMsg(this->IsIntConstOpnd(), "Bad call to AsIntConstOpnd()");
  146. return reinterpret_cast<IntConstOpnd *>(this);
  147. }
  148. ///----------------------------------------------------------------------------
  149. ///
  150. /// Opnd::IsFloatConstOpnd
  151. ///
  152. ///----------------------------------------------------------------------------
  153. inline bool
  154. Opnd::IsFloatConstOpnd() const
  155. {
  156. return GetKind() == OpndKindFloatConst;
  157. }
  158. ///----------------------------------------------------------------------------
  159. ///
  160. /// Opnd::AsFloatConstOpnd
  161. ///
  162. /// Use this opnd as a FloatConstOpnd.
  163. ///
  164. ///----------------------------------------------------------------------------
  165. inline FloatConstOpnd *
  166. Opnd::AsFloatConstOpnd()
  167. {
  168. AssertMsg(this->IsFloatConstOpnd(), "Bad call to AsFloatConstOpnd()");
  169. return reinterpret_cast<FloatConstOpnd *>(this);
  170. }
  171. inline bool
  172. Opnd::IsSimd128ConstOpnd() const
  173. {
  174. return GetKind() == OpndKindSimd128Const;
  175. }
  176. inline Simd128ConstOpnd *
  177. Opnd::AsSimd128ConstOpnd()
  178. {
  179. AssertMsg(this->IsSimd128ConstOpnd(), "Bad call to AsSimd128ConstOpnd()");
  180. return reinterpret_cast<Simd128ConstOpnd *>(this);
  181. }
  182. ///----------------------------------------------------------------------------
  183. ///
  184. /// Opnd::IsHelperCallOpnd
  185. ///
  186. ///----------------------------------------------------------------------------
  187. inline bool
  188. Opnd::IsHelperCallOpnd() const
  189. {
  190. return GetKind() == OpndKindHelperCall;
  191. }
  192. ///----------------------------------------------------------------------------
  193. ///
  194. /// Opnd::AsHelperCallOpnd
  195. ///
  196. /// Use this opnd as a HelperCallOpnd.
  197. ///
  198. ///----------------------------------------------------------------------------
  199. inline HelperCallOpnd *
  200. Opnd::AsHelperCallOpnd()
  201. {
  202. AssertMsg(this->IsHelperCallOpnd(), "Bad call to AsHelperCallOpnd()");
  203. return reinterpret_cast<HelperCallOpnd *>(this);
  204. }
  205. ///----------------------------------------------------------------------------
  206. ///
  207. /// Opnd::IsAddrOpnd
  208. ///
  209. ///----------------------------------------------------------------------------
  210. inline bool
  211. Opnd::IsAddrOpnd() const
  212. {
  213. return GetKind() == OpndKindAddr;
  214. }
  215. ///----------------------------------------------------------------------------
  216. ///
  217. /// Opnd::AsAddrOpnd
  218. ///
  219. /// Use this opnd as a AddrOpnd.
  220. ///
  221. ///----------------------------------------------------------------------------
  222. inline AddrOpnd *
  223. Opnd::AsAddrOpnd()
  224. {
  225. AssertMsg(this->IsAddrOpnd(), "Bad call to AsAddrOpnd()");
  226. return reinterpret_cast<AddrOpnd *>(this);
  227. }
  228. ///----------------------------------------------------------------------------
  229. ///
  230. /// Opnd::IsIndirOpnd
  231. ///
  232. ///----------------------------------------------------------------------------
  233. inline bool
  234. Opnd::IsIndirOpnd() const
  235. {
  236. return GetKind() == OpndKindIndir;
  237. }
  238. ///----------------------------------------------------------------------------
  239. ///
  240. /// Opnd::AsIndirOpnd
  241. ///
  242. /// Use this opnd as a IndirOpnd.
  243. ///
  244. ///----------------------------------------------------------------------------
  245. inline IndirOpnd *
  246. Opnd::AsIndirOpnd()
  247. {
  248. AssertMsg(this->IsIndirOpnd(), "Bad call to AsIndirOpnd()");
  249. return reinterpret_cast<IndirOpnd *>(this);
  250. }
  251. ///----------------------------------------------------------------------------
  252. ///
  253. /// Opnd::IsMemRefOpnd
  254. ///
  255. ///----------------------------------------------------------------------------
  256. inline bool
  257. Opnd::IsMemRefOpnd() const
  258. {
  259. return GetKind() == OpndKindMemRef;
  260. }
  261. ///----------------------------------------------------------------------------
  262. ///
  263. /// Opnd::AsMemRefOpnd
  264. ///
  265. /// Use this opnd as a MemRefOpnd.
  266. ///
  267. ///----------------------------------------------------------------------------
  268. inline MemRefOpnd *
  269. Opnd::AsMemRefOpnd()
  270. {
  271. AssertMsg(this->IsMemRefOpnd(), "Bad call to AsMemRefOpnd()");
  272. return reinterpret_cast<MemRefOpnd *>(this);
  273. }
  274. inline bool
  275. Opnd::IsLabelOpnd() const
  276. {
  277. return GetKind() == OpndKindLabel;
  278. }
  279. inline LabelOpnd *
  280. Opnd::AsLabelOpnd()
  281. {
  282. AssertMsg(this->IsLabelOpnd(), "Bad call to AsLabelOpnd()");
  283. return reinterpret_cast<LabelOpnd *>(this);
  284. }
  285. ///----------------------------------------------------------------------------
  286. ///
  287. /// Opnd::IsImmediateOpnd
  288. ///
  289. ///----------------------------------------------------------------------------
  290. inline bool
  291. Opnd::IsImmediateOpnd() const
  292. {
  293. return this->IsIntConstOpnd() || this->IsAddrOpnd() || this->IsHelperCallOpnd();
  294. }
  295. inline bool Opnd::IsMemoryOpnd() const
  296. {
  297. switch(GetKind())
  298. {
  299. case OpndKindSym:
  300. case OpndKindIndir:
  301. case OpndKindMemRef:
  302. return true;
  303. }
  304. return false;
  305. }
  306. ///----------------------------------------------------------------------------
  307. ///
  308. /// Opnd::IsConstOpnd
  309. ///
  310. ///----------------------------------------------------------------------------
  311. inline bool
  312. Opnd::IsConstOpnd() const
  313. {
  314. bool result = this->IsImmediateOpnd() || this->IsFloatConstOpnd();
  315. result = result || this->IsSimd128ConstOpnd();
  316. return result;
  317. }
  318. ///----------------------------------------------------------------------------
  319. ///
  320. /// RegOpnd::AsArrayRegOpnd
  321. ///
  322. ///----------------------------------------------------------------------------
  323. inline ArrayRegOpnd *RegOpnd::AsArrayRegOpnd()
  324. {
  325. Assert(IsArrayRegOpnd());
  326. return static_cast<ArrayRegOpnd *>(this);
  327. }
  328. ///----------------------------------------------------------------------------
  329. ///
  330. /// RegOpnd::GetReg
  331. ///
  332. ///----------------------------------------------------------------------------
  333. inline RegNum
  334. RegOpnd::GetReg() const
  335. {
  336. return m_reg;
  337. }
  338. ///----------------------------------------------------------------------------
  339. ///
  340. /// RegOpnd::SetReg
  341. ///
  342. ///----------------------------------------------------------------------------
  343. inline void
  344. RegOpnd::SetReg(RegNum reg)
  345. {
  346. m_reg = reg;
  347. }
  348. ///----------------------------------------------------------------------------
  349. ///
  350. /// IndirOpnd::GetBaseOpnd
  351. ///
  352. ///----------------------------------------------------------------------------
  353. inline RegOpnd *
  354. IndirOpnd::GetBaseOpnd() const
  355. {
  356. return this->m_baseOpnd;
  357. }
  358. ///----------------------------------------------------------------------------
  359. ///
  360. /// IndirOpnd::GetIndexOpnd
  361. ///
  362. ///----------------------------------------------------------------------------
  363. inline RegOpnd *
  364. IndirOpnd::GetIndexOpnd()
  365. {
  366. return m_indexOpnd;
  367. }
  368. ///----------------------------------------------------------------------------
  369. ///
  370. /// IndirOpnd::GetOffset
  371. ///
  372. ///----------------------------------------------------------------------------
  373. inline int32
  374. IndirOpnd::GetOffset() const
  375. {
  376. return m_offset;
  377. }
  378. ///----------------------------------------------------------------------------
  379. ///
  380. /// IndirOpnd::SetOffset
  381. ///
  382. ///----------------------------------------------------------------------------
  383. inline void
  384. IndirOpnd::SetOffset(int32 offset, bool dontEncode /* = false */)
  385. {
  386. m_offset = offset;
  387. m_dontEncode = dontEncode;
  388. }
  389. ///----------------------------------------------------------------------------
  390. ///
  391. /// IndirOpnd::GetScale
  392. ///
  393. ///----------------------------------------------------------------------------
  394. inline byte
  395. IndirOpnd::GetScale() const
  396. {
  397. return m_scale;
  398. }
  399. ///----------------------------------------------------------------------------
  400. ///
  401. /// IndirOpnd::SetScale
  402. ///
  403. ///----------------------------------------------------------------------------
  404. inline void
  405. IndirOpnd::SetScale(byte scale)
  406. {
  407. m_scale = scale;
  408. }
  409. ///----------------------------------------------------------------------------
  410. ///
  411. /// MemRefOpnd::GetMemLoc
  412. ///
  413. ///----------------------------------------------------------------------------
  414. inline void *
  415. MemRefOpnd::GetMemLoc() const
  416. {
  417. return m_memLoc;
  418. }
  419. ///----------------------------------------------------------------------------
  420. ///
  421. /// MemRefOpnd::SetMemLoc
  422. ///
  423. ///----------------------------------------------------------------------------
  424. inline void
  425. MemRefOpnd::SetMemLoc(void * pMemLoc)
  426. {
  427. m_memLoc = pMemLoc;
  428. }
  429. inline LabelInstr *
  430. LabelOpnd::GetLabel() const
  431. {
  432. return m_label;
  433. }
  434. inline void
  435. LabelOpnd::SetLabel(LabelInstr * labelInstr)
  436. {
  437. m_label = labelInstr;
  438. }
  439. inline BVUnit32
  440. RegBVOpnd::GetValue() const
  441. {
  442. return m_value;
  443. }
  444. } // namespace IR