BeModule.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161
  1. #pragma once
  2. #include "BeefySysLib/Common.h"
  3. #include "BeefySysLib/util/HashSet.h"
  4. #include "../BumpList.h"
  5. #include "../Compiler/BfIRBuilder.h"
  6. #include "BeContext.h"
  7. #include "../X64.h"
  8. NS_BF_BEGIN
  9. class BeContext;
  10. class BeValue;
  11. class BeCallInst;
  12. class BeValue;
  13. class BeBlock;
  14. class BeArgument;
  15. class BeInst;
  16. class BeNopInst;
  17. class BeUnreachableInst;
  18. class BeEnsureInstructionAtInst;
  19. class BeUndefValueInst;
  20. class BeExtractValueInst;
  21. class BeInsertValueInst;
  22. class BeNumericCastInst;
  23. class BeBitCastInst;
  24. class BeNegInst;
  25. class BeNotInst;
  26. class BeBinaryOpInst;
  27. class BeCmpInst;
  28. class BeObjectAccessCheckInst;
  29. class BeAllocaInst;
  30. class BeLifetimeExtendInst;
  31. class BeAliasValueInst;
  32. class BeLifetimeStartInst;
  33. class BeLifetimeEndInst;
  34. class BeLifetimeFenceInst;
  35. class BeValueScopeStartInst;
  36. class BeValueScopeRetainInst;
  37. class BeValueScopeEndInst;
  38. class BeLoadInst;
  39. class BeStoreInst;
  40. class BeSetCanMergeInst;
  41. class BeMemSetInst;
  42. class BeFenceInst;
  43. class BeStackSaveInst;
  44. class BeStackRestoreInst;
  45. class BeGEPInst;
  46. class BeBrInst;
  47. class BeCondBrInst;
  48. class BePhiIncoming;
  49. class BePhiInst;
  50. class BeSwitchInst;
  51. class BeRetInst;
  52. class BeCallInst;
  53. class BeDbgVariable;
  54. class BeDbgDeclareInst;
  55. class BeValueVisitor
  56. {
  57. public:
  58. void VisitChild(BeValue* value);
  59. virtual void Visit(BeValue* beValue) {}
  60. virtual void Visit(BeBlock* beBlock) {}
  61. virtual void Visit(BeArgument* beArgument) {}
  62. virtual void Visit(BeInst* beInst) {}
  63. virtual void Visit(BeNopInst* nopInst) {}
  64. virtual void Visit(BeUnreachableInst* unreachableInst) {}
  65. virtual void Visit(BeEnsureInstructionAtInst* ensureCodeAtInst) {}
  66. virtual void Visit(BeUndefValueInst* undefValue) {}
  67. virtual void Visit(BeExtractValueInst* extractValue) {}
  68. virtual void Visit(BeInsertValueInst* insertValue) {}
  69. virtual void Visit(BeNumericCastInst* castInst) {}
  70. virtual void Visit(BeBitCastInst* castInst) {}
  71. virtual void Visit(BeNegInst* negInst) {}
  72. virtual void Visit(BeNotInst* notInst) {}
  73. virtual void Visit(BeBinaryOpInst* binaryOpInst) {}
  74. virtual void Visit(BeFenceInst* fenceInst) {}
  75. virtual void Visit(BeStackSaveInst* stackSaveInst) {}
  76. virtual void Visit(BeStackRestoreInst* stackRestoreInst) {}
  77. virtual void Visit(BeCmpInst* cmpInst) {}
  78. virtual void Visit(BeObjectAccessCheckInst* objectAccessCheckInst) {}
  79. virtual void Visit(BeAllocaInst* allocaInst) {}
  80. virtual void Visit(BeAliasValueInst* aliasValueInst) {}
  81. virtual void Visit(BeLifetimeExtendInst* lifetimeExtendInst) {}
  82. virtual void Visit(BeLifetimeStartInst* lifetimeStartInst) {}
  83. virtual void Visit(BeLifetimeEndInst* lifetimeEndInst) {}
  84. virtual void Visit(BeLifetimeFenceInst* lifetimeFenceInst) {}
  85. virtual void Visit(BeValueScopeStartInst* valueScopeStartInst) {}
  86. virtual void Visit(BeValueScopeRetainInst* valueScopeRetainInst) {}
  87. virtual void Visit(BeValueScopeEndInst* valueScopeEndInst) {}
  88. virtual void Visit(BeLoadInst* allocaInst) {}
  89. virtual void Visit(BeStoreInst* storeInst) {}
  90. virtual void Visit(BeSetCanMergeInst* setCanMergeInst) {}
  91. virtual void Visit(BeMemSetInst* memSetInst) {}
  92. virtual void Visit(BeGEPInst* gepInst) {}
  93. virtual void Visit(BeBrInst* brInst) {}
  94. virtual void Visit(BeCondBrInst* condBrInst) {}
  95. virtual void Visit(BePhiIncoming* phiIncomingInst) {}
  96. virtual void Visit(BePhiInst* phiInst) {}
  97. virtual void Visit(BeSwitchInst* switchInst) {}
  98. virtual void Visit(BeRetInst* retInst) {}
  99. virtual void Visit(BeCallInst* callInst) {}
  100. //virtual void Visit(BeDbgVariable* dbgVariable) {}
  101. virtual void Visit(BeDbgDeclareInst* dbgDeclareInst) {}
  102. };
  103. class BeModule;
  104. class BeFunction;
  105. class BeDbgLoc;
  106. class BeInliner : public BeValueVisitor
  107. {
  108. public:
  109. BumpAllocator* mAlloc;
  110. OwnedVector<BeValue>* mOwnedValueVec;
  111. Dictionary<BeValue*, BeValue*> mValueMap;
  112. Dictionary<BeDbgLoc*, BeDbgLoc*> mInlinedAtMap;
  113. BeModule* mModule;
  114. BeFunction* mSrcFunc;
  115. BeFunction* mDestFunc;
  116. BeCallInst* mCallInst;
  117. BeBlock* mDestBlock;
  118. BeDbgLoc* mSrcDbgLoc;
  119. BeDbgLoc* mDestDbgLoc;
  120. public:
  121. BeInliner()
  122. {
  123. mSrcDbgLoc = NULL;
  124. mDestDbgLoc = NULL;
  125. }
  126. BeValue* Remap(BeValue* srcValue);
  127. BeDbgLoc* ExtendInlineDbgLoc(BeDbgLoc* srcInlineAt);
  128. void AddInst(BeInst* destInst, BeInst* srcInst);
  129. template <typename T>
  130. T* AllocInst(T* srcInst)
  131. {
  132. auto inst = mAlloc->Alloc<T>();
  133. AddInst(inst, srcInst);
  134. return inst;
  135. }
  136. template <typename T>
  137. T* AllocInstOwned(T* srcInst)
  138. {
  139. auto inst = mOwnedValueVec->Alloc<T>();
  140. AddInst(inst, srcInst);
  141. return inst;
  142. }
  143. virtual void Visit(BeValue* beValue) override;
  144. virtual void Visit(BeBlock* beBlock) override;
  145. virtual void Visit(BeArgument* beArgument) override;
  146. virtual void Visit(BeInst* beInst) override;
  147. virtual void Visit(BeNopInst* nopInst) override;
  148. virtual void Visit(BeUnreachableInst* unreachableInst) override;
  149. virtual void Visit(BeEnsureInstructionAtInst* ensureCodeAtInst) override;
  150. virtual void Visit(BeUndefValueInst* undefValue) override;
  151. virtual void Visit(BeExtractValueInst* extractValue) override;
  152. virtual void Visit(BeInsertValueInst* insertValue) override;
  153. virtual void Visit(BeNumericCastInst* castInst) override;
  154. virtual void Visit(BeBitCastInst* castInst) override;
  155. virtual void Visit(BeNegInst* negInst) override;
  156. virtual void Visit(BeNotInst* notInst) override;
  157. virtual void Visit(BeBinaryOpInst* binaryOpInst) override;
  158. virtual void Visit(BeCmpInst* cmpInst) override;
  159. virtual void Visit(BeFenceInst* fenceInst) override;
  160. virtual void Visit(BeStackSaveInst* stackSaveInst) override;
  161. virtual void Visit(BeStackRestoreInst* stackRestoreInst) override;
  162. virtual void Visit(BeObjectAccessCheckInst* objectAccessCheckInst) override;
  163. virtual void Visit(BeAllocaInst* allocaInst) override;
  164. virtual void Visit(BeAliasValueInst* aliasValueInst) override;
  165. virtual void Visit(BeLifetimeStartInst* lifetimeStartInst) override;
  166. virtual void Visit(BeLifetimeExtendInst* lifetimeExtendInst) override;
  167. virtual void Visit(BeLifetimeEndInst* lifetimeEndInst) override;
  168. virtual void Visit(BeLifetimeFenceInst* lifetimeFenceInst) override;
  169. virtual void Visit(BeValueScopeStartInst* valueScopeStartInst) override;
  170. virtual void Visit(BeValueScopeRetainInst* valueScopeRetainInst) override;
  171. virtual void Visit(BeValueScopeEndInst* valueScopeEndInst) override;
  172. virtual void Visit(BeLoadInst* allocaInst) override;
  173. virtual void Visit(BeStoreInst* storeInst) override;
  174. virtual void Visit(BeSetCanMergeInst* setCanMergeInst) override;
  175. virtual void Visit(BeMemSetInst* memSetInst) override;
  176. virtual void Visit(BeGEPInst* gepInst) override;
  177. virtual void Visit(BeBrInst* brInst) override;
  178. virtual void Visit(BeCondBrInst* condBrInst) override;
  179. virtual void Visit(BePhiIncoming* phiIncomingInst) override;
  180. virtual void Visit(BePhiInst* phiInst) override;
  181. virtual void Visit(BeSwitchInst* switchInst) override;
  182. virtual void Visit(BeRetInst* retInst) override;
  183. virtual void Visit(BeCallInst* callInst) override;
  184. virtual void Visit(BeDbgDeclareInst* dbgDeclareInst) override;
  185. };
  186. class BeValue : public BeHashble
  187. {
  188. public:
  189. #ifdef _DEBUG
  190. bool mLifetimeEnded;
  191. bool mWasRemoved;
  192. BeValue()
  193. {
  194. mLifetimeEnded = false;
  195. mWasRemoved = false;
  196. }
  197. #endif
  198. virtual ~BeValue()
  199. {
  200. }
  201. static const int TypeId = 0;
  202. virtual void Accept(BeValueVisitor* beVisitor) = 0;
  203. virtual bool TypeIdIsA(int typeId) = 0;
  204. virtual BeValue* DynCast(int typeId)
  205. {
  206. if (TypeIdIsA(typeId))
  207. return this;
  208. return NULL;
  209. }
  210. static bool ClassIsA(int typeId)
  211. {
  212. return typeId == 0;
  213. }
  214. virtual int GetTypeId() { return TypeId; }
  215. public:
  216. virtual BeType* GetType()
  217. {
  218. return NULL;
  219. }
  220. virtual void SetName(const StringImpl& name)
  221. {
  222. }
  223. };
  224. #define BE_VALUE_TYPE(name, TBase) static const int TypeId = __LINE__; \
  225. virtual void Accept(BeValueVisitor* beVisitor) override { beVisitor->Visit(this); } \
  226. static bool ClassIsA(int typeId) { return (typeId == TypeId) || TBase::ClassIsA(typeId); } \
  227. virtual bool TypeIdIsA(int typeId) override { return ClassIsA(typeId); } \
  228. virtual int GetTypeId() override { return TypeId; } \
  229. TBase* ToBase() { return (TBase*)this; }
  230. template <typename T>
  231. T* BeValueDynCast(BeValue* value)
  232. {
  233. if (value == NULL)
  234. return NULL;
  235. BeValue* result = value->DynCast(T::TypeId);
  236. return (T*)result;
  237. }
  238. class BeBlock;
  239. class BeInst;
  240. class BeModule;
  241. class BeDbgLoc;
  242. class BeMDNode;
  243. class BeGlobalVariable;
  244. class BeConstant : public BeValue
  245. {
  246. public:
  247. BE_VALUE_TYPE(BeConstant, BeValue);
  248. BeType* mType;
  249. union
  250. {
  251. bool mBool;
  252. int64 mInt64;
  253. int32 mInt32;
  254. int16 mInt16;
  255. int8 mInt8;
  256. uint64 mUInt64;
  257. uint32 mUInt32;
  258. uint16 mUInt16;
  259. uint8 mUInt8;
  260. uint8 mChar;
  261. uint32 mChar32;
  262. double mDouble;
  263. //BeType* mTypeParam;
  264. //BeGlobalVariable* mGlobalVar;
  265. BeConstant* mTarget;
  266. };
  267. bool IsNull()
  268. {
  269. if (mType->mTypeCode == BeTypeCode_NullPtr)
  270. return true;
  271. return false;
  272. }
  273. virtual BeType* GetType();
  274. virtual void GetData(Array<uint8>& data);
  275. virtual void HashContent(BeHashContext& hashCtx) override;
  276. };
  277. class BeCastConstant : public BeConstant
  278. {
  279. public:
  280. BE_VALUE_TYPE(BeCastConstant, BeConstant);
  281. virtual void HashContent(BeHashContext& hashCtx) override
  282. {
  283. hashCtx.Mixin(TypeId);
  284. mType->HashReference(hashCtx);
  285. mTarget->HashReference(hashCtx);
  286. }
  287. };
  288. class BeGEPConstant : public BeConstant
  289. {
  290. public:
  291. BE_VALUE_TYPE(BeGEPConstant, BeConstant);
  292. int mIdx0;
  293. int mIdx1;
  294. virtual BeType* GetType();
  295. virtual void HashContent(BeHashContext& hashCtx) override
  296. {
  297. hashCtx.Mixin(TypeId);
  298. mTarget->HashReference(hashCtx);
  299. hashCtx.Mixin(mIdx0);
  300. hashCtx.Mixin(mIdx1);
  301. }
  302. };
  303. class BeStructConstant : public BeConstant
  304. {
  305. public:
  306. BE_VALUE_TYPE(BeStructConstant, BeConstant);
  307. SizedArray<BeConstant*, 4> mMemberValues;
  308. virtual void GetData(Array<uint8>& data) override;
  309. virtual void HashContent(BeHashContext& hashCtx) override
  310. {
  311. hashCtx.Mixin(TypeId);
  312. hashCtx.Mixin(mMemberValues.size());
  313. for (auto member : mMemberValues)
  314. member->HashReference(hashCtx);
  315. }
  316. };
  317. class BeStringConstant : public BeConstant
  318. {
  319. public:
  320. BE_VALUE_TYPE(BeStringConstant, BeConstant);
  321. String mString;
  322. virtual void HashContent(BeHashContext& hashCtx) override
  323. {
  324. hashCtx.Mixin(TypeId);
  325. hashCtx.MixinStr(mString);
  326. }
  327. };
  328. class BeGlobalVariable : public BeConstant
  329. {
  330. public:
  331. BE_VALUE_TYPE(BeGlobalVariable, BeConstant);
  332. BeModule* mModule;
  333. String mName;
  334. BeConstant* mInitializer;
  335. BfIRLinkageType mLinkageType;
  336. bool mIsConstant;
  337. bool mIsTLS;
  338. int mAlign;
  339. bool mUnnamedAddr;
  340. virtual BeType* GetType();
  341. virtual void HashContent(BeHashContext& hashCtx) override
  342. {
  343. hashCtx.Mixin(TypeId);
  344. hashCtx.MixinStr(mName);
  345. if (mInitializer != NULL)
  346. mInitializer->HashReference(hashCtx);
  347. hashCtx.Mixin(mLinkageType);
  348. hashCtx.Mixin(mIsConstant);
  349. hashCtx.Mixin(mIsTLS);
  350. hashCtx.Mixin(mAlign);
  351. hashCtx.Mixin(mUnnamedAddr);
  352. }
  353. };
  354. class BeFunctionParam
  355. {
  356. public:
  357. String mName;
  358. bool mStructRet;
  359. bool mNoAlias;
  360. bool mNoCapture;
  361. bool mZExt;
  362. int mDereferenceableSize;
  363. BeFunctionParam()
  364. {
  365. mStructRet = false;
  366. mNoAlias = false;
  367. mNoCapture = false;
  368. mZExt = false;
  369. mDereferenceableSize = -1;
  370. }
  371. };
  372. class BeDbgFunction;
  373. class BeIntrinsic : public BeValue
  374. {
  375. public:
  376. BE_VALUE_TYPE(BeIntrinsic, BeValue);
  377. BfIRIntrinsic mKind;
  378. BeType* mReturnType;
  379. BeIntrinsic()
  380. {
  381. mReturnType = NULL;
  382. }
  383. virtual void HashContent(BeHashContext& hashCtx) override
  384. {
  385. hashCtx.Mixin(TypeId);
  386. hashCtx.Mixin(mKind);
  387. }
  388. };
  389. class BeFunction : public BeConstant
  390. {
  391. public:
  392. BE_VALUE_TYPE(BeFunction, BeConstant);
  393. BeModule* mModule;
  394. String mName;
  395. BfIRLinkageType mLinkageType;
  396. bool mAlwaysInline;
  397. bool mNoUnwind;
  398. bool mUWTable;
  399. bool mNoReturn;
  400. bool mDidInlinePass;
  401. bool mNoFramePointerElim;
  402. bool mIsDLLExport;
  403. bool mIsDLLImport;
  404. BfIRCallingConv mCallingConv;
  405. Array<BeBlock*> mBlocks;
  406. Array<BeFunctionParam> mParams;
  407. BeDbgFunction* mDbgFunction;
  408. BeGlobalVariable* mRemapBindVar;
  409. int mCurElementId;
  410. public:
  411. BeFunction()
  412. {
  413. mCallingConv = BfIRCallingConv_CDecl;
  414. mLinkageType = BfIRLinkageType_External;
  415. mModule = NULL;
  416. mDbgFunction = NULL;
  417. mAlwaysInline = false;
  418. mDidInlinePass = false;
  419. mNoUnwind = false;
  420. mUWTable = false;
  421. mNoReturn = false;
  422. mNoFramePointerElim = false;
  423. mIsDLLExport = false;
  424. mIsDLLImport = false;
  425. mRemapBindVar = NULL;
  426. mCurElementId = 0;
  427. }
  428. BeFunctionType* GetFuncType()
  429. {
  430. BF_ASSERT(mType->IsPointer());
  431. return (BeFunctionType*)(((BePointerType*)mType)->mElementType);
  432. }
  433. bool IsDecl()
  434. {
  435. return mBlocks.size() == 0;
  436. }
  437. bool HasStructRet()
  438. {
  439. return (!mParams.IsEmpty()) && (mParams[0].mStructRet);
  440. }
  441. virtual void HashContent(BeHashContext& hashCtx) override;
  442. };
  443. class BeBlock : public BeValue
  444. {
  445. public:
  446. BE_VALUE_TYPE(BeBlock, BeValue);
  447. String mName;
  448. Array<BeInst*> mInstructions;
  449. BeFunction* mFunction;
  450. public:
  451. bool IsEmpty();
  452. virtual void HashContent(BeHashContext& hashCtx) override;
  453. };
  454. //////////////////////////////////////////////////////////////////////////
  455. class BeInst : public BeValue
  456. {
  457. public:
  458. BE_VALUE_TYPE(BeInst, BeValue);
  459. BeBlock* mParentBlock;
  460. const char* mName;
  461. BeDbgLoc* mDbgLoc;
  462. public:
  463. BeContext* GetContext();
  464. BeModule* GetModule();
  465. virtual bool CanBeReferenced()
  466. {
  467. return GetType() != NULL;
  468. }
  469. virtual void SetName(const StringImpl& name) override;
  470. BeInst()
  471. {
  472. mParentBlock = NULL;
  473. mName = NULL;
  474. mDbgLoc = NULL;
  475. }
  476. virtual void HashInst(BeHashContext& hashCtx) = 0;
  477. virtual void HashContent(BeHashContext& hashCtx) override;
  478. };
  479. class BeNopInst : public BeInst
  480. {
  481. public:
  482. BE_VALUE_TYPE(BeNopInst, BeInst);
  483. virtual void HashInst(BeHashContext& hashCtx) override
  484. {
  485. hashCtx.Mixin(TypeId);
  486. }
  487. };
  488. class BeUnreachableInst : public BeInst
  489. {
  490. public:
  491. BE_VALUE_TYPE(BeUnreachableInst, BeInst);
  492. virtual void HashInst(BeHashContext& hashCtx) override
  493. {
  494. hashCtx.Mixin(TypeId);
  495. }
  496. };
  497. class BeEnsureInstructionAtInst : public BeInst
  498. {
  499. public:
  500. BE_VALUE_TYPE(BeEnsureInstructionAtInst, BeInst);
  501. virtual void HashInst(BeHashContext& hashCtx) override
  502. {
  503. hashCtx.Mixin(TypeId);
  504. }
  505. };
  506. class BeUndefValueInst : public BeInst
  507. {
  508. public:
  509. BE_VALUE_TYPE(BeUndefValueInst, BeInst);
  510. BeType* mType;
  511. virtual BeType* GetType() override;
  512. virtual void HashInst(BeHashContext& hashCtx) override
  513. {
  514. hashCtx.Mixin(TypeId);
  515. mType->HashReference(hashCtx);
  516. }
  517. };
  518. class BeExtractValueInst : public BeInst
  519. {
  520. public:
  521. BE_VALUE_TYPE(BeExtractValueInst, BeInst);
  522. BeValue* mAggVal;
  523. int mIdx;
  524. virtual BeType* GetType() override;
  525. virtual void HashInst(BeHashContext& hashCtx) override
  526. {
  527. hashCtx.Mixin(TypeId);
  528. mAggVal->HashReference(hashCtx);
  529. hashCtx.Mixin(mIdx);
  530. }
  531. };
  532. class BeInsertValueInst : public BeInst
  533. {
  534. public:
  535. BE_VALUE_TYPE(BeInsertValueInst, BeInst);
  536. BeValue* mAggVal;
  537. BeValue* mMemberVal;
  538. int mIdx;
  539. virtual BeType* GetType() override;
  540. virtual void HashInst(BeHashContext& hashCtx) override
  541. {
  542. hashCtx.Mixin(TypeId);
  543. mAggVal->HashReference(hashCtx);
  544. mMemberVal->HashReference(hashCtx);
  545. hashCtx.Mixin(mIdx);
  546. }
  547. };
  548. class BeNumericCastInst : public BeInst
  549. {
  550. public:
  551. BE_VALUE_TYPE(BeNumericCastInst, BeInst);
  552. BeValue* mValue;
  553. BeType* mToType;
  554. bool mValSigned;
  555. bool mToSigned;
  556. virtual BeType* GetType() override;
  557. virtual void HashInst(BeHashContext& hashCtx) override
  558. {
  559. hashCtx.Mixin(TypeId);
  560. mValue->HashReference(hashCtx);
  561. mToType->HashReference(hashCtx);
  562. hashCtx.Mixin(mValSigned);
  563. hashCtx.Mixin(mToSigned);
  564. }
  565. };
  566. class BeBitCastInst : public BeInst
  567. {
  568. public:
  569. BE_VALUE_TYPE(BeBitCastInst, BeInst);
  570. BeValue* mValue;
  571. BeType* mToType;
  572. virtual BeType* GetType() override;
  573. virtual void HashInst(BeHashContext& hashCtx) override
  574. {
  575. hashCtx.Mixin(TypeId);
  576. mValue->HashReference(hashCtx);
  577. mToType->HashReference(hashCtx);
  578. }
  579. };
  580. class BeNegInst : public BeInst
  581. {
  582. public:
  583. BE_VALUE_TYPE(BeNegInst, BeInst);
  584. BeValue* mValue;
  585. virtual BeType* GetType() override;
  586. virtual void HashInst(BeHashContext& hashCtx) override
  587. {
  588. hashCtx.Mixin(TypeId);
  589. mValue->HashReference(hashCtx);
  590. }
  591. };
  592. class BeNotInst : public BeInst
  593. {
  594. public:
  595. BE_VALUE_TYPE(BeNotInst, BeInst);
  596. BeValue* mValue;
  597. virtual BeType* GetType() override;
  598. virtual void HashInst(BeHashContext& hashCtx) override
  599. {
  600. hashCtx.Mixin(TypeId);
  601. mValue->HashReference(hashCtx);
  602. }
  603. };
  604. enum BeBinaryOpKind
  605. {
  606. BeBinaryOpKind_None,
  607. BeBinaryOpKind_Add,
  608. BeBinaryOpKind_Subtract,
  609. BeBinaryOpKind_Multiply,
  610. BeBinaryOpKind_SDivide,
  611. BeBinaryOpKind_UDivide,
  612. BeBinaryOpKind_SModulus,
  613. BeBinaryOpKind_UModulus,
  614. BeBinaryOpKind_BitwiseAnd,
  615. BeBinaryOpKind_BitwiseOr,
  616. BeBinaryOpKind_ExclusiveOr,
  617. BeBinaryOpKind_LeftShift,
  618. BeBinaryOpKind_RightShift,
  619. BeBinaryOpKind_ARightShift,
  620. BeBinaryOpKind_Equality,
  621. BeBinaryOpKind_InEquality,
  622. BeBinaryOpKind_GreaterThan,
  623. BeBinaryOpKind_LessThan,
  624. BeBinaryOpKind_GreaterThanOrEqual,
  625. BeBinaryOpKind_LessThanOrEqual,
  626. };
  627. class BeBinaryOpInst : public BeInst
  628. {
  629. public:
  630. BE_VALUE_TYPE(BeBinaryOpInst, BeInst);
  631. BeBinaryOpKind mOpKind;
  632. BeValue* mLHS;
  633. BeValue* mRHS;
  634. virtual BeType* GetType() override;
  635. virtual void HashInst(BeHashContext& hashCtx) override
  636. {
  637. hashCtx.Mixin(TypeId);
  638. hashCtx.Mixin(mOpKind);
  639. mLHS->HashReference(hashCtx);
  640. mRHS->HashReference(hashCtx);
  641. }
  642. };
  643. enum BeCmpKind
  644. {
  645. BeCmpKind_None,
  646. BeCmpKind_SLT,
  647. BeCmpKind_ULT,
  648. BeCmpKind_SLE,
  649. BeCmpKind_ULE,
  650. BeCmpKind_EQ,
  651. BeCmpKind_NE,
  652. BeCmpKind_SGT,
  653. BeCmpKind_UGT,
  654. BeCmpKind_SGE,
  655. BeCmpKind_UGE
  656. };
  657. class BeCmpInst : public BeInst
  658. {
  659. public:
  660. BE_VALUE_TYPE(BeCmpInst, BeInst);
  661. BeValue* mLHS;
  662. BeValue* mRHS;
  663. BeCmpKind mCmpKind;
  664. virtual BeType* GetType() override;
  665. virtual void HashInst(BeHashContext& hashCtx) override
  666. {
  667. hashCtx.Mixin(TypeId);
  668. mLHS->HashReference(hashCtx);
  669. mRHS->HashReference(hashCtx);
  670. hashCtx.Mixin(mCmpKind);
  671. }
  672. };
  673. class BeObjectAccessCheckInst : public BeInst
  674. {
  675. public:
  676. BE_VALUE_TYPE(BeObjectAccessCheckInst, BeInst);
  677. BeValue* mValue;
  678. virtual void HashInst(BeHashContext& hashCtx) override
  679. {
  680. hashCtx.Mixin(TypeId);
  681. mValue->HashReference(hashCtx);
  682. }
  683. };
  684. class BeAllocaInst : public BeInst
  685. {
  686. public:
  687. BE_VALUE_TYPE(BeAllocaInst, BeInst);
  688. BeType* mType;
  689. BeValue* mArraySize;
  690. int mAlign;
  691. bool mNoChkStk;
  692. bool mForceMem;
  693. public:
  694. virtual BeType* GetType() override;
  695. virtual void HashInst(BeHashContext& hashCtx) override
  696. {
  697. hashCtx.Mixin(TypeId);
  698. mType->HashReference(hashCtx);
  699. if (mArraySize != NULL)
  700. mArraySize->HashReference(hashCtx);
  701. hashCtx.Mixin(mAlign);
  702. hashCtx.Mixin(mNoChkStk);
  703. hashCtx.Mixin(mForceMem);
  704. }
  705. };
  706. class BeAliasValueInst : public BeInst
  707. {
  708. public:
  709. BE_VALUE_TYPE(BeAliasValueInst, BeInst);
  710. BeValue* mPtr;
  711. virtual void HashInst(BeHashContext& hashCtx) override
  712. {
  713. hashCtx.Mixin(TypeId);
  714. mPtr->HashReference(hashCtx);
  715. }
  716. virtual BeType* GetType() override
  717. {
  718. return mPtr->GetType();
  719. }
  720. };
  721. class BeLifetimeStartInst : public BeInst
  722. {
  723. public:
  724. BE_VALUE_TYPE(BeLifetimeStartInst, BeInst);
  725. BeValue* mPtr;
  726. virtual void HashInst(BeHashContext& hashCtx) override
  727. {
  728. hashCtx.Mixin(TypeId);
  729. mPtr->HashReference(hashCtx);
  730. }
  731. };
  732. class BeLifetimeEndInst : public BeInst
  733. {
  734. public:
  735. BE_VALUE_TYPE(BeLifetimeEndInst, BeInst);
  736. BeValue* mPtr;
  737. virtual void HashInst(BeHashContext& hashCtx) override
  738. {
  739. hashCtx.Mixin(TypeId);
  740. mPtr->HashReference(hashCtx);
  741. }
  742. };
  743. class BeLifetimeFenceInst : public BeInst
  744. {
  745. public:
  746. BE_VALUE_TYPE(BeLifetimeFenceInst, BeInst);
  747. BeBlock* mFenceBlock; // Lifetime is blocked from extending into the end of this block
  748. BeValue* mPtr;
  749. virtual void HashInst(BeHashContext& hashCtx) override
  750. {
  751. hashCtx.Mixin(TypeId);
  752. mFenceBlock->HashReference(hashCtx);
  753. mPtr->HashReference(hashCtx);
  754. }
  755. };
  756. class BeLifetimeExtendInst : public BeInst
  757. {
  758. public:
  759. BE_VALUE_TYPE(BeLifetimeExtendInst, BeInst);
  760. BeValue* mPtr;
  761. virtual void HashInst(BeHashContext& hashCtx) override
  762. {
  763. hashCtx.Mixin(TypeId);
  764. mPtr->HashReference(hashCtx);
  765. }
  766. };
  767. class BeValueScopeStartInst : public BeInst
  768. {
  769. public:
  770. BE_VALUE_TYPE(BeValueScopeStartInst, BeInst);
  771. virtual BeType* GetType() override;
  772. virtual void HashInst(BeHashContext& hashCtx) override
  773. {
  774. hashCtx.Mixin(TypeId);
  775. }
  776. };
  777. class BeValueScopeRetainInst : public BeInst
  778. {
  779. public:
  780. BE_VALUE_TYPE(BeValueScopeRetainInst, BeInst);
  781. BeValue* mValue;
  782. virtual void HashInst(BeHashContext& hashCtx) override
  783. {
  784. hashCtx.Mixin(TypeId);
  785. mValue->HashReference(hashCtx);
  786. }
  787. };
  788. class BeValueScopeEndInst : public BeInst
  789. {
  790. public:
  791. BE_VALUE_TYPE(BeValueScopeEndInst, BeInst);
  792. BeValueScopeStartInst* mScopeStart;
  793. bool mIsSoft;
  794. virtual void HashInst(BeHashContext& hashCtx) override
  795. {
  796. hashCtx.Mixin(TypeId);
  797. mScopeStart->HashReference(hashCtx);
  798. hashCtx.Mixin(mIsSoft);
  799. }
  800. };
  801. class BeLoadInst : public BeInst
  802. {
  803. public:
  804. BE_VALUE_TYPE(BeLoadInst, BeInst);
  805. BeValue* mTarget;
  806. bool mIsVolatile;
  807. public:
  808. virtual BeType* GetType() override;
  809. virtual void HashInst(BeHashContext& hashCtx) override
  810. {
  811. hashCtx.Mixin(TypeId);
  812. mTarget->HashReference(hashCtx);
  813. }
  814. };
  815. class BeStoreInst : public BeInst
  816. {
  817. public:
  818. BE_VALUE_TYPE(BeStoreInst, BeInst);
  819. BeValue* mVal;
  820. BeValue* mPtr;
  821. bool mIsVolatile;
  822. virtual void HashInst(BeHashContext& hashCtx) override
  823. {
  824. hashCtx.Mixin(TypeId);
  825. mVal->HashReference(hashCtx);
  826. mPtr->HashReference(hashCtx);
  827. }
  828. };
  829. class BeSetCanMergeInst : public BeInst
  830. {
  831. public:
  832. BE_VALUE_TYPE(BeSetCanMergeInst, BeInst);
  833. BeValue* mVal;
  834. virtual void HashInst(BeHashContext& hashCtx) override
  835. {
  836. hashCtx.Mixin(TypeId);
  837. mVal->HashReference(hashCtx);
  838. }
  839. };
  840. class BeMemSetInst : public BeInst
  841. {
  842. public:
  843. BE_VALUE_TYPE(BeGEPInst, BeInst);
  844. BeValue* mAddr;
  845. BeValue* mVal;
  846. BeValue* mSize;
  847. int mAlignment;
  848. virtual void HashInst(BeHashContext& hashCtx) override
  849. {
  850. hashCtx.Mixin(TypeId);
  851. mAddr->HashReference(hashCtx);
  852. mVal->HashReference(hashCtx);
  853. mSize->HashReference(hashCtx);
  854. hashCtx.Mixin(mAlignment);
  855. }
  856. };
  857. class BeFenceInst : public BeInst
  858. {
  859. public:
  860. BE_VALUE_TYPE(BeFenceInst, BeInst);
  861. virtual void HashInst(BeHashContext& hashCtx) override
  862. {
  863. hashCtx.Mixin(TypeId);
  864. }
  865. };
  866. class BeStackSaveInst : public BeInst
  867. {
  868. public:
  869. BE_VALUE_TYPE(BeStackSaveInst, BeInst);
  870. virtual void HashInst(BeHashContext& hashCtx) override
  871. {
  872. hashCtx.Mixin(TypeId);
  873. }
  874. virtual BeType* GetType() override
  875. {
  876. return GetContext()->GetPrimitiveType(BeTypeCode_NullPtr);
  877. }
  878. };
  879. class BeStackRestoreInst : public BeInst
  880. {
  881. public:
  882. BE_VALUE_TYPE(BeStackRestoreInst, BeInst);
  883. BeValue* mStackVal;
  884. virtual void HashInst(BeHashContext& hashCtx) override
  885. {
  886. hashCtx.Mixin(TypeId);
  887. mStackVal->HashReference(hashCtx);
  888. }
  889. };
  890. class BeGEPInst : public BeInst
  891. {
  892. public:
  893. BE_VALUE_TYPE(BeGEPInst, BeInst);
  894. BeValue* mPtr;
  895. BeValue* mIdx0;
  896. BeValue* mIdx1;
  897. virtual BeType* GetType() override;
  898. virtual void HashInst(BeHashContext& hashCtx) override
  899. {
  900. hashCtx.Mixin(TypeId);
  901. mPtr->HashReference(hashCtx);
  902. mIdx0->HashReference(hashCtx);
  903. if (mIdx1 != NULL)
  904. mIdx1->HashReference(hashCtx);
  905. }
  906. };
  907. class BeBrInst : public BeInst
  908. {
  909. public:
  910. BE_VALUE_TYPE(BeBrInst, BeInst);
  911. BeBlock* mTargetBlock;
  912. bool mNoCollapse;
  913. bool mIsFake;
  914. virtual void HashInst(BeHashContext& hashCtx) override
  915. {
  916. hashCtx.Mixin(TypeId);
  917. mTargetBlock->HashReference(hashCtx);
  918. hashCtx.Mixin(mNoCollapse);
  919. hashCtx.Mixin(mIsFake);
  920. }
  921. };
  922. class BeCondBrInst : public BeInst
  923. {
  924. public:
  925. BE_VALUE_TYPE(BeCondBrInst, BeInst);
  926. BeValue* mCond;
  927. BeBlock* mTrueBlock;
  928. BeBlock* mFalseBlock;
  929. virtual void HashInst(BeHashContext& hashCtx) override
  930. {
  931. hashCtx.Mixin(TypeId);
  932. mCond->HashReference(hashCtx);
  933. mTrueBlock->HashReference(hashCtx);
  934. mFalseBlock->HashReference(hashCtx);
  935. }
  936. };
  937. class BePhiIncoming : public BeValue
  938. {
  939. public:
  940. BE_VALUE_TYPE(BePhiIncoming, BeValue);
  941. BeBlock* mBlock;
  942. BeValue* mValue;
  943. virtual void HashContent(BeHashContext& hashCtx) override
  944. {
  945. hashCtx.Mixin(TypeId);
  946. mBlock->HashReference(hashCtx);
  947. mValue->HashReference(hashCtx);
  948. }
  949. };
  950. class BePhiInst : public BeInst
  951. {
  952. public:
  953. BE_VALUE_TYPE(BePhiInst, BeInst);
  954. BeType* mType;
  955. SizedArray<BePhiIncoming*, 4> mIncoming;
  956. virtual BeType* GetType() override;
  957. virtual void HashInst(BeHashContext& hashCtx) override
  958. {
  959. hashCtx.Mixin(TypeId);
  960. mType->HashReference(hashCtx);
  961. hashCtx.Mixin(mIncoming.size());
  962. for (auto incoming : mIncoming)
  963. {
  964. incoming->mBlock->HashReference(hashCtx);
  965. incoming->mValue->HashReference(hashCtx);
  966. }
  967. }
  968. };
  969. class BeSwitchCase
  970. {
  971. public:
  972. BeConstant* mValue;
  973. BeBlock* mBlock;
  974. };
  975. class BeSwitchInst : public BeInst
  976. {
  977. public:
  978. BE_VALUE_TYPE(BeSwitchInst, BeInst);
  979. BeValue* mValue;
  980. BeBlock* mDefaultBlock;
  981. Array<BeSwitchCase> mCases;
  982. virtual void HashInst(BeHashContext& hashCtx) override
  983. {
  984. hashCtx.Mixin(TypeId);
  985. mValue->HashReference(hashCtx);
  986. mDefaultBlock->HashReference(hashCtx);
  987. for (auto& caseVal : mCases)
  988. {
  989. caseVal.mValue->HashReference(hashCtx);
  990. caseVal.mBlock->HashReference(hashCtx);
  991. }
  992. }
  993. };
  994. class BeRetInst : public BeInst
  995. {
  996. public:
  997. BE_VALUE_TYPE(BeRetInst, BeInst);
  998. BeValue* mRetValue;
  999. virtual void HashInst(BeHashContext& hashCtx) override
  1000. {
  1001. hashCtx.Mixin(TypeId);
  1002. if (mRetValue != NULL)
  1003. mRetValue->HashReference(hashCtx);
  1004. }
  1005. };
  1006. class BeCallInst : public BeInst
  1007. {
  1008. public:
  1009. struct Arg
  1010. {
  1011. BeValue* mValue;
  1012. int mDereferenceableSize;
  1013. bool mStructRet;
  1014. bool mZExt;
  1015. bool mNoAlias;
  1016. bool mNoCapture;
  1017. Arg()
  1018. {
  1019. mValue = NULL;
  1020. mStructRet = false;
  1021. mZExt = false;
  1022. mNoAlias = false;
  1023. mNoCapture = false;
  1024. mDereferenceableSize = -1;
  1025. }
  1026. };
  1027. public:
  1028. BE_VALUE_TYPE(BeCallInst, BeInst);
  1029. BeValue* mInlineResult;
  1030. BeValue* mFunc;
  1031. SizedArray<Arg, 4> mArgs;
  1032. BfIRCallingConv mCallingConv;
  1033. bool mNoReturn;
  1034. bool mTailCall;
  1035. virtual BeType* GetType() override;
  1036. BeCallInst()
  1037. {
  1038. mInlineResult = NULL;
  1039. mFunc = NULL;
  1040. mCallingConv = BfIRCallingConv_CDecl;
  1041. mNoReturn = false;
  1042. mTailCall = false;
  1043. }
  1044. virtual void HashInst(BeHashContext& hashCtx) override
  1045. {
  1046. hashCtx.Mixin(TypeId);
  1047. if (mInlineResult != NULL)
  1048. mInlineResult->HashReference(hashCtx);
  1049. mFunc->HashReference(hashCtx);
  1050. for (auto& arg : mArgs)
  1051. {
  1052. arg.mValue->HashReference(hashCtx);
  1053. hashCtx.Mixin(arg.mStructRet);
  1054. hashCtx.Mixin(arg.mZExt);
  1055. }
  1056. hashCtx.Mixin(mCallingConv);
  1057. hashCtx.Mixin(mNoReturn);
  1058. hashCtx.Mixin(mTailCall);
  1059. }
  1060. bool HasStructRet()
  1061. {
  1062. return (!mArgs.IsEmpty()) && (mArgs[0].mStructRet);
  1063. }
  1064. };
  1065. class BeArgument : public BeValue
  1066. {
  1067. public:
  1068. BE_VALUE_TYPE(BeArgument, BeValue);
  1069. BeModule* mModule;
  1070. int mArgIdx;
  1071. virtual BeType* GetType() override;
  1072. virtual void HashContent(BeHashContext& hashCtx) override
  1073. {
  1074. hashCtx.Mixin(TypeId);
  1075. hashCtx.Mixin(mArgIdx);
  1076. }
  1077. };
  1078. struct BeDumpContext
  1079. {
  1080. public:
  1081. BeModule* mModule;
  1082. Dictionary<BeValue*, String> mValueNameMap;
  1083. Dictionary<String, int> mSeenNames;
  1084. void ToString(StringImpl& str, BeValue* value, bool showType = true, bool mdDrillDown = false);
  1085. void ToString(StringImpl& str, BeType* type);
  1086. void ToString(StringImpl& str, BeDbgFunction* dbgFunction, bool showScope);
  1087. static void ToString(StringImpl& str, int val);
  1088. static void ToString(StringImpl& str, BeCmpKind cmpKind);
  1089. static void ToString(StringImpl& str, BeBinaryOpKind opKind);
  1090. String ToString(BeValue* value, bool showType = true, bool mdDrillDown = false);
  1091. String ToString(BeType* type);
  1092. String ToString(BeDbgFunction* dbgFunction);
  1093. static String ToString(int val);
  1094. static String ToString(BeCmpKind cmpKind);
  1095. static String ToString(BeBinaryOpKind opKind);
  1096. public:
  1097. BeDumpContext()
  1098. {
  1099. mModule = NULL;
  1100. }
  1101. };
  1102. //////////////////////////////////////////////////////////////////////////
  1103. class BeDbgVariable;
  1104. class BeDbgDeclareInst : public BeInst
  1105. {
  1106. public:
  1107. BE_VALUE_TYPE(BeDbgDeclareInst, BeInst);
  1108. public:
  1109. BeDbgVariable* mDbgVar;
  1110. BeValue* mValue;
  1111. bool mIsValue;
  1112. virtual void HashInst(BeHashContext& hashCtx) override;
  1113. };
  1114. class BeMDNode : public BeValue
  1115. {
  1116. public:
  1117. BE_VALUE_TYPE(BeMDNode, BeValue);
  1118. public:
  1119. virtual ~BeMDNode()
  1120. {
  1121. }
  1122. virtual void HashContent(BeHashContext& hashCtx) override
  1123. {
  1124. hashCtx.Mixin(TypeId);
  1125. }
  1126. };
  1127. class BeDbgFile;
  1128. class BeDbgLoc : public BeMDNode
  1129. {
  1130. public:
  1131. BE_VALUE_TYPE(BeDbgLoc, BeMDNode);
  1132. public:
  1133. int mLine;
  1134. int mColumn;
  1135. BeMDNode* mDbgScope;
  1136. BeDbgLoc* mDbgInlinedAt;
  1137. int mIdx;
  1138. bool mHadInline;
  1139. public:
  1140. BeDbgLoc()
  1141. {
  1142. }
  1143. int GetInlineDepth();
  1144. int GetInlineMatchDepth(BeDbgLoc* other);
  1145. BeDbgLoc* GetInlinedAt(int idx = 0);
  1146. BeDbgLoc* GetRoot();
  1147. BeDbgFunction* GetDbgFunc();
  1148. BeDbgFile* GetDbgFile();
  1149. virtual void HashContent(BeHashContext& hashCtx) override
  1150. {
  1151. hashCtx.Mixin(TypeId);
  1152. hashCtx.Mixin(mLine);
  1153. hashCtx.Mixin(mColumn);
  1154. if (mDbgScope != NULL)
  1155. mDbgScope->HashReference(hashCtx);
  1156. else
  1157. hashCtx.Mixin(-1);
  1158. if (mDbgInlinedAt != NULL)
  1159. mDbgInlinedAt->HashReference(hashCtx);
  1160. }
  1161. };
  1162. class BeDbgLexicalBlock : public BeMDNode
  1163. {
  1164. public:
  1165. BE_VALUE_TYPE(BeDbgLexicalBlock, BeMDNode);
  1166. public:
  1167. BeDbgFile* mFile;
  1168. BeMDNode* mScope;
  1169. BeBlock* mLastBeBlock;
  1170. int mId;
  1171. virtual void HashContent(BeHashContext& hashCtx) override;
  1172. };
  1173. class BeDbgNamespace : public BeMDNode
  1174. {
  1175. public:
  1176. BE_VALUE_TYPE(BeDbgNamespace, BeMDNode);
  1177. public:
  1178. BeMDNode* mScope;
  1179. String mName;
  1180. virtual void HashContent(BeHashContext& hashCtx) override
  1181. {
  1182. hashCtx.Mixin(TypeId);
  1183. mScope->HashReference(hashCtx);
  1184. hashCtx.MixinStr(mName);
  1185. }
  1186. };
  1187. class BeDbgType : public BeMDNode
  1188. {
  1189. public:
  1190. BE_VALUE_TYPE(BeDbgType, BeMDNode);
  1191. public:
  1192. int mSize;
  1193. int mAlign;
  1194. int mCvDeclTypeId;
  1195. int mCvDefTypeId;
  1196. BumpList<BeDbgType*> mDerivedTypes;
  1197. BeDbgType()
  1198. {
  1199. mSize = -1;
  1200. mAlign = -1;
  1201. mCvDeclTypeId = -1;
  1202. mCvDefTypeId = -1;
  1203. }
  1204. BeDbgType* FindDerivedType(int typeId)
  1205. {
  1206. for (auto derivedType : mDerivedTypes)
  1207. {
  1208. if (derivedType->GetTypeId() == typeId)
  1209. return derivedType;
  1210. }
  1211. return NULL;
  1212. }
  1213. virtual void HashContent(BeHashContext& hashCtx) override
  1214. {
  1215. hashCtx.Mixin(TypeId);
  1216. hashCtx.Mixin(mSize);
  1217. hashCtx.Mixin(mAlign);
  1218. }
  1219. };
  1220. class BeDbgBasicType : public BeDbgType
  1221. {
  1222. public:
  1223. BE_VALUE_TYPE(BeDbgBasicType, BeDbgType);
  1224. public:
  1225. String mName;
  1226. int mEncoding;
  1227. virtual void HashContent(BeHashContext& hashCtx) override
  1228. {
  1229. hashCtx.Mixin(TypeId);
  1230. hashCtx.Mixin(mSize);
  1231. hashCtx.Mixin(mAlign);
  1232. hashCtx.MixinStr(mName);
  1233. hashCtx.Mixin(mEncoding);
  1234. }
  1235. };
  1236. class BeDbgArrayType : public BeDbgType
  1237. {
  1238. public:
  1239. BE_VALUE_TYPE(BeDbgArrayType, BeDbgType);
  1240. public:
  1241. BeDbgType* mElement;
  1242. int mNumElements;
  1243. virtual void HashContent(BeHashContext& hashCtx) override
  1244. {
  1245. hashCtx.Mixin(TypeId);
  1246. hashCtx.Mixin(mSize);
  1247. hashCtx.Mixin(mAlign);
  1248. hashCtx.Mixin(mNumElements);
  1249. mElement->HashReference(hashCtx);
  1250. }
  1251. };
  1252. class BeDbgArtificialType : public BeDbgType
  1253. {
  1254. public:
  1255. BE_VALUE_TYPE(BeDbgArtificialType, BeDbgType);
  1256. public:
  1257. BeDbgType* mElement;
  1258. virtual void HashContent(BeHashContext& hashCtx) override
  1259. {
  1260. hashCtx.Mixin(TypeId);
  1261. mElement->HashReference(hashCtx);
  1262. }
  1263. };
  1264. class BeDbgConstType : public BeDbgType
  1265. {
  1266. public:
  1267. BE_VALUE_TYPE(BeDbgConstType, BeDbgType);
  1268. public:
  1269. BeDbgType* mElement;
  1270. virtual void HashContent(BeHashContext& hashCtx) override
  1271. {
  1272. hashCtx.Mixin(TypeId);
  1273. mElement->HashReference(hashCtx);
  1274. }
  1275. };
  1276. class BeDbgReferenceType : public BeDbgType
  1277. {
  1278. public:
  1279. BE_VALUE_TYPE(BeDbgReferenceType, BeDbgType);
  1280. public:
  1281. BeDbgType* mElement;
  1282. virtual void HashContent(BeHashContext& hashCtx) override
  1283. {
  1284. hashCtx.Mixin(TypeId);
  1285. mElement->HashReference(hashCtx);
  1286. }
  1287. };
  1288. class BeDbgPointerType : public BeDbgType
  1289. {
  1290. public:
  1291. BE_VALUE_TYPE(BeDbgPointerType, BeDbgType);
  1292. public:
  1293. BeDbgType* mElement;
  1294. virtual void HashContent(BeHashContext& hashCtx) override
  1295. {
  1296. hashCtx.Mixin(TypeId);
  1297. mElement->HashReference(hashCtx);
  1298. }
  1299. };
  1300. class BeDbgInheritance : public BeMDNode
  1301. {
  1302. public:
  1303. BE_VALUE_TYPE(BeDbgInheritance, BeMDNode);
  1304. public:
  1305. BeDbgType* mBaseType;
  1306. virtual void HashContent(BeHashContext& hashCtx) override
  1307. {
  1308. hashCtx.Mixin(TypeId);
  1309. mBaseType->HashReference(hashCtx);
  1310. }
  1311. };
  1312. class BeDbgStructMember : public BeMDNode
  1313. {
  1314. public:
  1315. BE_VALUE_TYPE(BeDbgStructMember, BeMDNode);
  1316. public:
  1317. String mName;
  1318. BeDbgType* mType;
  1319. int mFlags;
  1320. int mOffset;
  1321. bool mIsStatic;
  1322. BeValue* mStaticValue;
  1323. public:
  1324. BeDbgStructMember()
  1325. {
  1326. mType = NULL;
  1327. mFlags = 0;
  1328. mOffset = -1;
  1329. mIsStatic = false;
  1330. mStaticValue = NULL;
  1331. }
  1332. virtual void HashContent(BeHashContext& hashCtx) override
  1333. {
  1334. hashCtx.Mixin(TypeId);
  1335. hashCtx.MixinStr(mName);
  1336. mType->HashReference(hashCtx);
  1337. hashCtx.Mixin(mFlags);
  1338. hashCtx.Mixin(mOffset);
  1339. hashCtx.Mixin(mIsStatic);
  1340. if (mStaticValue != NULL)
  1341. mStaticValue->HashReference(hashCtx);
  1342. }
  1343. };
  1344. class BeDbgFunctionType : public BeMDNode
  1345. {
  1346. public:
  1347. BE_VALUE_TYPE(BeDbgFunctionType, BeMDNode);
  1348. public:
  1349. BeDbgType* mReturnType;
  1350. Array<BeDbgType*> mParams;
  1351. public:
  1352. virtual void HashContent(BeHashContext& hashCtx) override
  1353. {
  1354. hashCtx.Mixin(TypeId);
  1355. if (mReturnType != NULL)
  1356. mReturnType->HashReference(hashCtx);
  1357. hashCtx.Mixin(mParams.size());
  1358. for (auto param : mParams)
  1359. param->HashReference(hashCtx);
  1360. }
  1361. };
  1362. /*class BeDbgVariableRange
  1363. {
  1364. public:
  1365. enum Kind
  1366. {
  1367. Kind_None,
  1368. Kind_Reg, // Direct reg usage
  1369. Kind_Indexed // [RBP+8] type usage (spilled)
  1370. };
  1371. public:
  1372. int mCodeStartOfs;
  1373. int mCodeRange;
  1374. Kind mKind;
  1375. X64CPURegister mReg;
  1376. int mOfs;
  1377. public:
  1378. BeDbgVariableRange()
  1379. {
  1380. mCodeStartOfs = -1;
  1381. mCodeRange = -1;
  1382. mKind = Kind_None;
  1383. mReg = X64Reg_None;
  1384. mOfs = 0;
  1385. }
  1386. };*/
  1387. class BeDbgVariableRange
  1388. {
  1389. public:
  1390. int mOffset;
  1391. int mLength;
  1392. };
  1393. class BeDbgVariableLoc
  1394. {
  1395. public:
  1396. enum Kind
  1397. {
  1398. Kind_None,
  1399. Kind_Reg, // Direct reg usage
  1400. Kind_Indexed, // [RBP+8] type usage (spilled)
  1401. Kind_SymbolAddr
  1402. };
  1403. Kind mKind;
  1404. X64CPURegister mReg;
  1405. int mOfs;
  1406. public:
  1407. BeDbgVariableLoc()
  1408. {
  1409. mKind = Kind_None;
  1410. mReg = X64Reg_None;
  1411. mOfs = 0;
  1412. }
  1413. };
  1414. class BeDbgVariable : public BeMDNode
  1415. {
  1416. public:
  1417. BE_VALUE_TYPE(BeDbgVariable, BeMDNode);
  1418. public:
  1419. String mName;
  1420. BeDbgType* mType;
  1421. BeValue* mValue;
  1422. int mParamNum;
  1423. BfIRInitType mInitType;
  1424. BfIRInitType mPendingInitType;
  1425. bool mPendingInitDef;
  1426. BeMDNode* mScope;
  1427. BeDbgLoc* mDeclDbgLoc;
  1428. BeDbgVariableLoc mPrimaryLoc;
  1429. BeDbgVariableLoc mSavedLoc;
  1430. int mDeclStart;
  1431. int mDeclEnd;
  1432. int mDeclMCBlockId;
  1433. bool mDeclLifetimeExtend;
  1434. bool mDbgLifeEnded;
  1435. bool mIsValue; // Value vs Addr
  1436. Array<BeDbgVariableRange> mSavedRanges;
  1437. Array<BeDbgVariableRange> mGaps;
  1438. public:
  1439. BeDbgVariable()
  1440. {
  1441. mType = NULL;
  1442. mValue = NULL;
  1443. mParamNum = -1;
  1444. mInitType = BfIRInitType_NotSet;
  1445. mPendingInitType = BfIRInitType_NotNeeded;
  1446. mPendingInitDef = false;
  1447. mScope = NULL;
  1448. mDeclDbgLoc = NULL;
  1449. mDeclStart = -1;
  1450. mDeclEnd = -1;
  1451. mDeclMCBlockId = -1;
  1452. mIsValue = false;
  1453. mDbgLifeEnded = false;
  1454. mDeclLifetimeExtend = false;
  1455. }
  1456. virtual void HashContent(BeHashContext& hashCtx) override
  1457. {
  1458. hashCtx.Mixin(TypeId);
  1459. hashCtx.MixinStr(mName);
  1460. mType->HashReference(hashCtx);
  1461. if (mValue != NULL)
  1462. mValue->HashReference(hashCtx);
  1463. hashCtx.Mixin(mParamNum);
  1464. hashCtx.Mixin(mInitType);
  1465. hashCtx.Mixin(mPendingInitType);
  1466. if (mScope != NULL)
  1467. mScope->HashReference(hashCtx);
  1468. if (mDeclDbgLoc != NULL)
  1469. mDeclDbgLoc->HashReference(hashCtx);
  1470. // The others only get filled in after generation -- not part of hash
  1471. }
  1472. };
  1473. class BeDbgFile;
  1474. class BeDbgCodeEmission
  1475. {
  1476. public:
  1477. BeDbgLoc* mDbgLoc;
  1478. int mPos;
  1479. };
  1480. class BeDbgFunction : public BeMDNode
  1481. {
  1482. public:
  1483. BE_VALUE_TYPE(BeDbgFunction, BeMDNode);
  1484. public:
  1485. int mIdx;
  1486. BeMDNode* mScope;
  1487. BeDbgFile* mFile;
  1488. int mLine;
  1489. String mName;
  1490. String mLinkageName;
  1491. BeDbgFunctionType* mType;
  1492. //Array<BeDbgVariable*> mParams;
  1493. Array<BeDbgType*> mGenericArgs;
  1494. Array<BeConstant*> mGenericConstValueArgs;
  1495. BeFunction* mValue;
  1496. bool mIsLocalToUnit;
  1497. bool mIsStaticMethod;
  1498. bool mIncludedAsMember;
  1499. int mFlags;
  1500. int mVK;
  1501. int mVIndex;
  1502. Array<BeDbgVariable*> mVariables;
  1503. int mPrologSize;
  1504. int mCodeLen;
  1505. Array<BeDbgCodeEmission> mEmissions;
  1506. int mCvTypeId;
  1507. int mCvFuncId;
  1508. int mCvArgListId;
  1509. public:
  1510. BeDbgFunction()
  1511. {
  1512. mIdx = -1;
  1513. mScope = NULL;
  1514. mFile = NULL;
  1515. mLine = -1;
  1516. mType = NULL;
  1517. mValue = NULL;
  1518. mFlags = 0;
  1519. mIsLocalToUnit = false;
  1520. mVK = -1;
  1521. mVIndex = -1;
  1522. mIsStaticMethod = true;
  1523. mIncludedAsMember = false;
  1524. mPrologSize = 0;
  1525. mCodeLen = -1;
  1526. mCvTypeId = -1;
  1527. mCvFuncId = -1;
  1528. mCvArgListId = -1;
  1529. }
  1530. BeDbgType* GetParamType(int paramIdx)
  1531. {
  1532. /*if (!mParams.empty())
  1533. return mParams[paramIdx]->mType;*/
  1534. if (paramIdx < (int)mVariables.size())
  1535. {
  1536. auto param = mVariables[paramIdx];
  1537. if (param->mParamNum == paramIdx)
  1538. return param->mType;
  1539. }
  1540. return mType->mParams[paramIdx];
  1541. }
  1542. bool HasThis()
  1543. {
  1544. return !mIsStaticMethod;
  1545. /*bool matchLLVM = false;
  1546. // This matches the LLVM CV emitter
  1547. if (matchLLVM)
  1548. {
  1549. return (BeValueDynCast<BeDbgType>(mScope) != NULL) &&
  1550. (mType->mParams.size() > 0);
  1551. }
  1552. else
  1553. {
  1554. return ((mVariables.size() > 0) && (mVariables[0]->mName == "this"));
  1555. }*/
  1556. }
  1557. virtual void HashContent(BeHashContext& hashCtx) override
  1558. {
  1559. hashCtx.Mixin(TypeId);
  1560. hashCtx.Mixin(mLine);
  1561. hashCtx.MixinStr(mName);
  1562. hashCtx.MixinStr(mLinkageName);
  1563. mType->HashReference(hashCtx);
  1564. for (auto genericArg : mGenericArgs)
  1565. genericArg->HashReference(hashCtx);
  1566. for (auto genericConstValueArgs : mGenericArgs)
  1567. genericConstValueArgs->HashReference(hashCtx);
  1568. if (mValue != NULL)
  1569. mValue->HashReference(hashCtx);
  1570. hashCtx.Mixin(mIsLocalToUnit);
  1571. hashCtx.Mixin(mIsStaticMethod);
  1572. hashCtx.Mixin(mFlags);
  1573. hashCtx.Mixin(mVK);
  1574. hashCtx.Mixin(mVIndex);
  1575. hashCtx.Mixin(mVariables.size());
  1576. for (auto& variable : mVariables)
  1577. {
  1578. if (variable == NULL)
  1579. hashCtx.Mixin(-1);
  1580. else
  1581. variable->HashReference(hashCtx);
  1582. }
  1583. hashCtx.Mixin(mPrologSize);
  1584. hashCtx.Mixin(mCodeLen);
  1585. }
  1586. };
  1587. class BeDbgInlinedScope : public BeMDNode
  1588. {
  1589. public:
  1590. BE_VALUE_TYPE(BeDbgInlinedScope, BeMDNode);
  1591. BeMDNode* mScope;
  1592. virtual void HashContent(BeHashContext& hashCtx) override
  1593. {
  1594. hashCtx.Mixin(TypeId);
  1595. mScope->HashReference(hashCtx);
  1596. }
  1597. };
  1598. class BeDbgFile;
  1599. class BeDbgStructType : public BeDbgType
  1600. {
  1601. public:
  1602. BE_VALUE_TYPE(BeDbgStructType, BeDbgType);
  1603. public:
  1604. BeMDNode* mScope;
  1605. String mName;
  1606. BeDbgType* mDerivedFrom;
  1607. Array<BeDbgStructMember*> mMembers;
  1608. Array<BeDbgFunction*> mMethods;
  1609. bool mIsFullyDefined;
  1610. bool mIsStatic;
  1611. BeDbgFile* mDefFile;
  1612. int mDefLine;
  1613. public:
  1614. BeDbgStructType()
  1615. {
  1616. mScope = NULL;
  1617. mDerivedFrom = NULL;
  1618. mIsStatic = false;
  1619. mIsFullyDefined = false;
  1620. mDefFile = NULL;
  1621. mDefLine = 0;
  1622. }
  1623. void SetMembers(SizedArrayImpl<BeMDNode*>& members);
  1624. virtual void HashContent(BeHashContext& hashCtx) override;
  1625. };
  1626. class BeDbgEnumMember : public BeMDNode
  1627. {
  1628. public:
  1629. BE_VALUE_TYPE(BeDbgEnumMember, BeMDNode);
  1630. public:
  1631. String mName;
  1632. int64 mValue;
  1633. virtual void HashContent(BeHashContext& hashCtx) override
  1634. {
  1635. hashCtx.Mixin(TypeId);
  1636. hashCtx.MixinStr(mName);
  1637. hashCtx.Mixin(mValue);
  1638. }
  1639. };
  1640. class BeDbgEnumType : public BeDbgType
  1641. {
  1642. public:
  1643. BE_VALUE_TYPE(BeDbgEnumType, BeDbgType);
  1644. public:
  1645. BeMDNode* mScope;
  1646. String mName;
  1647. BeDbgType* mElementType;
  1648. bool mIsFullyDefined;
  1649. Array<BeDbgEnumMember*> mMembers;
  1650. public:
  1651. BeDbgEnumType()
  1652. {
  1653. mScope = NULL;
  1654. mElementType = NULL;
  1655. mIsFullyDefined = false;
  1656. }
  1657. void SetMembers(SizedArrayImpl<BeMDNode*>& members);
  1658. virtual void HashContent(BeHashContext& hashCtx) override
  1659. {
  1660. mScope->HashReference(hashCtx);
  1661. hashCtx.MixinStr(mName);
  1662. if (mElementType != NULL)
  1663. mElementType->HashReference(hashCtx);
  1664. hashCtx.Mixin(mIsFullyDefined);
  1665. for (auto member : mMembers)
  1666. member->HashReference(hashCtx);
  1667. }
  1668. };
  1669. class BeDbgFile : public BeMDNode
  1670. {
  1671. public:
  1672. BE_VALUE_TYPE(BeDbgFile, BeMDNode);
  1673. public:
  1674. String mFileName;
  1675. String mDirectory;
  1676. int mIdx;
  1677. void ToString(String& str);
  1678. virtual void HashContent(BeHashContext& hashCtx) override
  1679. {
  1680. hashCtx.Mixin(TypeId);
  1681. hashCtx.MixinStr(mFileName);
  1682. hashCtx.MixinStr(mDirectory);
  1683. }
  1684. };
  1685. class BeDbgGlobalVariable : public BeMDNode
  1686. {
  1687. public:
  1688. BE_VALUE_TYPE(BeDbgGlobalVariable, BeMDNode);
  1689. BeMDNode* mContext;
  1690. String mName;
  1691. String mLinkageName;
  1692. BeDbgFile* mFile;
  1693. int mLineNum;
  1694. BeDbgType* mType;
  1695. bool mIsLocalToUnit;
  1696. BeConstant* mValue;
  1697. BeMDNode* mDecl;
  1698. virtual void HashContent(BeHashContext& hashCtx) override
  1699. {
  1700. hashCtx.Mixin(TypeId);
  1701. hashCtx.MixinStr(mName);
  1702. hashCtx.MixinStr(mLinkageName);
  1703. if (mFile != NULL)
  1704. mFile->HashReference(hashCtx);
  1705. hashCtx.Mixin(mLineNum);
  1706. mType->HashReference(hashCtx);
  1707. hashCtx.Mixin(mIsLocalToUnit);
  1708. if (mValue != NULL)
  1709. mValue->HashReference(hashCtx);
  1710. if (mDecl != NULL)
  1711. mDecl->HashReference(hashCtx);
  1712. }
  1713. };
  1714. class BeDbgModule : public BeMDNode
  1715. {
  1716. public:
  1717. BE_VALUE_TYPE(BeDbgModule, BeMDNode);
  1718. public:
  1719. BeModule* mBeModule;
  1720. String mFileName;
  1721. String mDirectory;
  1722. String mProducer;
  1723. OwnedVector<BeDbgFile> mFiles;
  1724. OwnedVector<BeDbgNamespace> mNamespaces;
  1725. OwnedVector<BeDbgGlobalVariable> mGlobalVariables;
  1726. OwnedVector<BeDbgType> mTypes;
  1727. Array<BeDbgFunction*> mFuncs; // Does not include methods in structs
  1728. virtual void HashContent(BeHashContext& hashCtx) override;
  1729. BeDbgReferenceType* CreateReferenceType(BeDbgType* dbgType);
  1730. };
  1731. //////////////////////////////////////////////////////////////////////////
  1732. class BeDbgModule;
  1733. class BeModule
  1734. {
  1735. public:
  1736. BeIRCodeGen* mBeIRCodeGen;
  1737. Array<BeConstant*> mConfigConsts32;
  1738. Array<BeConstant*> mConfigConsts64;
  1739. BeFunction* mActiveFunction;
  1740. BumpAllocator mAlloc;
  1741. OwnedVector<BeValue> mOwnedValues; // Those that need dtors
  1742. OwnedVector<BeGlobalVariable> mGlobalVariables;
  1743. BeContext* mContext;
  1744. String mModuleName;
  1745. String mTargetTriple;
  1746. BeBlock* mActiveBlock;
  1747. int mInsertPos;
  1748. BeDbgLoc* mCurDbgLoc;
  1749. BeDbgLoc* mPrevDbgLocInline;
  1750. BeDbgLoc* mLastDbgLoc;
  1751. Array<BeArgument*> mArgs;
  1752. Array<BeFunction*> mFunctions;
  1753. Dictionary<String, BeFunction*> mFunctionMap;
  1754. int mCurDbgLocIdx;
  1755. int mCurLexBlockId;
  1756. BeDbgModule* mDbgModule;
  1757. public:
  1758. void AddInst(BeInst* inst);
  1759. static void ToString(StringImpl& str, BeType* type);
  1760. static void StructToString(StringImpl& str, BeStructType* type);
  1761. template <typename T>
  1762. T* AllocInst()
  1763. {
  1764. T* newInst = mAlloc.Alloc<T>();
  1765. AddInst(newInst);
  1766. return newInst;
  1767. }
  1768. template <typename T>
  1769. T* AllocInstOwned()
  1770. {
  1771. T* newInst = mOwnedValues.Alloc<T>();
  1772. AddInst(newInst);
  1773. return newInst;
  1774. }
  1775. public:
  1776. BeModule(const StringImpl& moduleName, BeContext* context);
  1777. ~BeModule();
  1778. void Hash(BeHashContext& hashCtx);
  1779. String ToString(BeFunction* func = NULL);
  1780. void Print();
  1781. void Print(BeFunction* func);
  1782. void PrintValue(BeValue* val);
  1783. void DoInlining(BeFunction* func);
  1784. void DoInlining();
  1785. static BeCmpKind InvertCmp(BeCmpKind cmpKind);
  1786. static BeCmpKind SwapCmpSides(BeCmpKind cmpKind);
  1787. void SetActiveFunction(BeFunction* function);
  1788. BeArgument* GetArgument(int arg);
  1789. BeBlock* CreateBlock(const StringImpl& name);
  1790. void AddBlock(BeFunction* function, BeBlock* block);
  1791. void RemoveBlock(BeFunction* function, BeBlock* block);
  1792. BeBlock* GetInsertBlock();
  1793. void SetInsertPoint(BeBlock* block);
  1794. void SetInsertPointAtStart(BeBlock* block);
  1795. BeFunction* CreateFunction(BeFunctionType* funcType, BfIRLinkageType linkageType, const StringImpl& name);
  1796. BeDbgLoc* GetCurrentDebugLocation();
  1797. void SetCurrentDebugLocation(BeDbgLoc* dbgLoc);
  1798. void SetCurrentDebugLocation(int line, int column, BeMDNode* diScope, BeDbgLoc* diInlinedAt);
  1799. ///
  1800. BeNopInst* CreateNop();
  1801. BeUndefValueInst* CreateUndefValue(BeType* type);
  1802. BeNumericCastInst* CreateNumericCast(BeValue* value, BeType* toType, bool valSigned, bool toSigned);
  1803. BeBitCastInst* CreateBitCast(BeValue* value, BeType* toType);;
  1804. BeCmpInst* CreateCmp(BeCmpKind cmpKind, BeValue* lhs, BeValue* rhs);
  1805. BeBinaryOpInst* CreateBinaryOp(BeBinaryOpKind opKind, BeValue* lhs, BeValue* rhs);
  1806. BeAllocaInst* CreateAlloca(BeType* type);
  1807. BeLoadInst* CreateLoad(BeValue* value, bool isVolatile);
  1808. BeLoadInst* CreateAlignedLoad(BeValue* value, int alignment, bool isVolatile);
  1809. BeStoreInst* CreateStore(BeValue* val, BeValue* ptr, bool isVolatile);
  1810. BeStoreInst* CreateAlignedStore(BeValue* val, BeValue* ptr, int alignment, bool isVolatile);
  1811. BeGEPInst* CreateGEP(BeValue* ptr, BeValue* idx0, BeValue* idx1);
  1812. BeBrInst* CreateBr(BeBlock* block);
  1813. BeCondBrInst* CreateCondBr(BeValue* cond, BeBlock* trueBlock, BeBlock* falseBlock);
  1814. BeRetInst* CreateRetVoid();
  1815. BeRetInst* CreateRet(BeValue* value);
  1816. BeCallInst* CreateCall(BeValue* func, const SizedArrayImpl<BeValue*>& args);
  1817. BeConstant* GetConstant(BeType* type, double floatVal);
  1818. BeConstant* GetConstant(BeType* type, int64 intVal);
  1819. BeConstant* GetConstant(BeType* type, bool boolVal);
  1820. BeConstant* GetConstantNull(BePointerType* type);
  1821. };
  1822. NS_BF_END