BfIRBuilder.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. #pragma once
  2. //#define BFIR_RENTRY_CHECK
  3. #include "BeefySysLib/Common.h"
  4. #include "BeefySysLib/util/BumpAllocator.h"
  5. #include "BeefySysLib/util/ChunkedDataBuffer.h"
  6. #include "BeefySysLib/util/Dictionary.h"
  7. #include "BfAstAllocator.h"
  8. #include <unordered_map>
  9. //#include "BfSystem.h"
  10. #pragma warning(push)
  11. #pragma warning(disable:4141)
  12. #pragma warning(disable:4146)
  13. #pragma warning(disable:4291)
  14. #pragma warning(disable:4244)
  15. #pragma warning(disable:4267)
  16. #pragma warning(disable:4624)
  17. #pragma warning(disable:4800)
  18. #pragma warning(disable:4996)
  19. #include "llvm/IR/DebugLoc.h"
  20. #include "llvm/IR/IRBuilder.h"
  21. #pragma warning(pop)
  22. namespace llvm
  23. {
  24. class Constant;
  25. class Value;
  26. class Type;
  27. class BasicBlock;
  28. class Function;
  29. class FunctionType;
  30. class MDNode;
  31. class InlineAsm;
  32. class DIType;
  33. class DIBuilder;
  34. class DICompileUnit;
  35. class AttributeList;
  36. class Module;
  37. class LLVMContext;
  38. };
  39. NS_BF_BEGIN
  40. class BfModule;
  41. class BfType;
  42. class BfTypeInstance;
  43. class BfIRConstHolder;
  44. class BfIRCodeGen;
  45. class BeIRCodeGen;
  46. class BfMethodInstance;
  47. class BfFieldInstance;
  48. class BfFileInstance;
  49. class BfParser;
  50. class BfParserData;
  51. class BfFilePosition
  52. {
  53. public:
  54. BfFileInstance* mFileInstance;
  55. int mCurSrcPos;
  56. int mCurLine;
  57. int mCurColumn;
  58. public:
  59. BfFilePosition()
  60. {
  61. mFileInstance = NULL;
  62. mCurSrcPos = 0;
  63. mCurLine = 0;
  64. mCurColumn = 0;
  65. }
  66. };
  67. enum BfTypeCode : uint8
  68. {
  69. BfTypeCode_None,
  70. BfTypeCode_CharPtr,
  71. BfTypeCode_Pointer,
  72. BfTypeCode_NullPtr,
  73. BfTypeCode_Self,
  74. BfTypeCode_Dot,
  75. BfTypeCode_Var,
  76. BfTypeCode_Let,
  77. BfTypeCode_Boolean,
  78. BfTypeCode_Int8,
  79. BfTypeCode_UInt8,
  80. BfTypeCode_Int16,
  81. BfTypeCode_UInt16,
  82. BfTypeCode_Int32,
  83. BfTypeCode_UInt32,
  84. BfTypeCode_Int64,
  85. BfTypeCode_UInt64,
  86. BfTypeCode_IntPtr,
  87. BfTypeCode_UIntPtr,
  88. BfTypeCode_IntUnknown,
  89. BfTypeCode_UIntUnknown,
  90. BfTypeCode_Char8,
  91. BfTypeCode_Char16,
  92. BfTypeCode_Char32,
  93. BfTypeCode_Single,
  94. BfTypeCode_Double,
  95. BfTypeCode_Object,
  96. BfTypeCode_Interface,
  97. BfTypeCode_Struct,
  98. BfTypeCode_Enum,
  99. BfTypeCode_TypeAlias,
  100. BfTypeCode_Extension,
  101. BfTypeCode_Length
  102. };
  103. enum BfConstType
  104. {
  105. BfConstType_GlobalVar = BfTypeCode_Length,
  106. BfConstType_BitCast,
  107. BfConstType_BitCastNull,
  108. BfConstType_GEP32_2,
  109. BfConstType_PtrToInt,
  110. BfConstType_TypeOf,
  111. BfConstType_AggZero,
  112. BfConstType_Array,
  113. BfConstType_Undef
  114. };
  115. enum BfIRValueFlags : uint8
  116. {
  117. BfIRValueFlags_None,
  118. BfIRValueFlags_Value = 1,
  119. BfIRValueFlags_Arg = 2,
  120. BfIRValueFlags_Const = 4,
  121. BfIRValueFlags_FromLLVM = 8,
  122. BfIRValueFlags_Block = 16,
  123. BfIRValueFlags_Func = 32
  124. };
  125. enum BfIRCmd : uint8
  126. {
  127. BfIRCmd_Module_Start,
  128. BfIRCmd_Module_SetTargetTriple,
  129. BfIRCmd_Module_AddModuleFlag,
  130. BfIRCmd_WriteIR,
  131. BfIRCmd_SetType,
  132. BfIRCmd_SetInstType,
  133. BfIRCmd_PrimitiveType,
  134. BfIRCmd_CreateStruct,
  135. BfIRCmd_StructSetBody,
  136. BfIRCmd_Type,
  137. BfIRCmd_TypeInst,
  138. BfIRCmd_TypeInstPtr,
  139. BfIRCmd_GetType,
  140. BfIRCmd_GetPointerToFuncType,
  141. BfIRCmd_GetPointerToType,
  142. BfIRCmd_GetSizedArrayType,
  143. BfIRCmd_CreateConstStruct,
  144. BfIRCmd_CreateConstStructZero,
  145. BfIRCmd_CreateConstArray,
  146. BfIRCmd_CreateConstString,
  147. BfIRCmd_ConfigConst,
  148. BfIRCmd_SetName,
  149. BfIRCmd_CreateUndefValue,
  150. BfIRCmd_NumericCast,
  151. BfIRCmd_CmpEQ,
  152. BfIRCmd_CmpNE,
  153. BfIRCmd_CmpSLT,
  154. BfIRCmd_CmpULT,
  155. BfIRCmd_CmpSLE,
  156. BfIRCmd_CmpULE,
  157. BfIRCmd_CmpSGT,
  158. BfIRCmd_CmpUGT,
  159. BfIRCmd_CmpSGE,
  160. BfIRCmd_CmpUGE,
  161. BfIRCmd_Add,
  162. BfIRCmd_Sub,
  163. BfIRCmd_Mul,
  164. BfIRCmd_SDiv,
  165. BfIRCmd_UDiv,
  166. BfIRCmd_SRem,
  167. BfIRCmd_URem,
  168. BfIRCmd_And,
  169. BfIRCmd_Or,
  170. BfIRCmd_Xor,
  171. BfIRCmd_Shl,
  172. BfIRCmd_AShr,
  173. BfIRCmd_LShr,
  174. BfIRCmd_Neg,
  175. BfIRCmd_Not,
  176. BfIRCmd_BitCast,
  177. BfIRCmd_PtrToInt,
  178. BfIRCmd_IntToPtr,
  179. BfIRCmd_InboundsGEP1_32,
  180. BfIRCmd_InboundsGEP2_32,
  181. BfIRCmd_InBoundsGEP1,
  182. BfIRCmd_InBoundsGEP2,
  183. BfIRCmd_IsNull,
  184. BfIRCmd_IsNotNull,
  185. BfIRCmd_ExtractValue,
  186. BfIRCmd_InsertValue,
  187. BfIRCmd_Alloca,
  188. BfIRCmd_AllocaArray,
  189. BfIRCmd_SetAllocaAlignment,
  190. BfIRCmd_SetAllocaNoChkStkHint,
  191. BfIRCmd_SetAllocaForceMem,
  192. BfIRCmd_AliasValue,
  193. BfIRCmd_LifetimeStart,
  194. BfIRCmd_LifetimeEnd,
  195. BfIRCmd_LifetimeExtend,
  196. BfIRCmd_ValueScopeStart,
  197. BfIRCmd_ValueScopeRetain,
  198. BfIRCmd_ValueScopeSoftEnd,
  199. BfIRCmd_ValueScopeHardEnd,
  200. BfIRCmd_Load,
  201. BfIRCmd_AlignedLoad,
  202. BfIRCmd_Store,
  203. BfIRCmd_AlignedStore,
  204. BfIRCmd_MemSet,
  205. BfIRCmd_Fence,
  206. BfIRCmd_StackSave,
  207. BfIRCmd_StackRestore,
  208. BfIRCmd_GlobalVariable,
  209. BfIRCmd_GlobalVar_SetUnnamedAddr,
  210. BfIRCmd_GlobalVar_SetInitializer,
  211. BfIRCmd_GlobalVar_SetAlignment,
  212. BfIRCmd_GlobalStringPtr,
  213. BfIRCmd_CreateBlock,
  214. BfIRCmd_MaybeChainNewBlock,
  215. BfIRCmd_AddBlock,
  216. BfIRCmd_DropBlocks,
  217. BfIRCmd_MergeBlockDown,
  218. BfIRCmd_SetInsertPoint,
  219. BfIRCmd_SetInsertPointAtStart,
  220. BfIRCmd_EraseFromParent,
  221. BfIRCmd_DeleteBlock,
  222. BfIRCmd_EraseInstFromParent,
  223. BfIRCmd_CreateBr,
  224. BfIRCmd_CreateBr_Fake,
  225. BfIRCmd_CreateBr_NoCollapse,
  226. BfIRCmd_CreateCondBr,
  227. BfIRCmd_MoveBlockToEnd,
  228. BfIRCmd_CreateSwitch,
  229. BfIRCmd_AddSwitchCase,
  230. BfIRCmd_SetSwitchDefaultDest,
  231. BfIRCmd_CreatePhi,
  232. BfIRCmd_AddPhiIncoming,
  233. BfIRCmd_GetIntrinsic,
  234. BfIRCmd_CreateFunctionType,
  235. BfIRCmd_CreateFunction,
  236. BfIRCmd_EnsureFunctionPatchable,
  237. BfIRCmd_RemapBindFunction,
  238. BfIRCmd_SetActiveFunction,
  239. BfIRCmd_CreateCall,
  240. BfIRCmd_SetCallCallingConv,
  241. BfIRCmd_SetFuncCallingConv,
  242. BfIRCmd_SetTailCall,
  243. BfIRCmd_SetCallAttribute,
  244. BfIRCmd_CreateRet,
  245. BfIRCmd_CreateRetVoid,
  246. BfIRCmd_CreateUnreachable,
  247. BfIRCmd_Call_AddAttribute,
  248. BfIRCmd_Call_AddAttribute1,
  249. BfIRCmd_Func_AddAttribute,
  250. BfIRCmd_Func_AddAttribute1,
  251. BfIRCmd_Func_SetParamName,
  252. BfIRCmd_Func_DeleteBody,
  253. BfIRCmd_Func_EraseFromParent,
  254. BfIRCmd_Func_SetLinkage,
  255. BfIRCmd_SaveDebugLocation,
  256. BfIRCmd_RestoreDebugLocation,
  257. BfIRCmd_ClearDebugLocation,
  258. BfIRCmd_ClearDebugLocationInst,
  259. BfIRCmd_ClearDebugLocationInstLast,
  260. BfIRCmd_UpdateDebugLocation,
  261. BfIRCmd_SetCurrentDebugLocation,
  262. BfIRCmd_Nop,
  263. BfIRCmd_EnsureInstructionAt,
  264. BfIRCmd_StatementStart,
  265. BfIRCmd_ObjectAccessCheck,
  266. BfIRCmd_DbgInit,
  267. BfIRCmd_DbgFinalize,
  268. BfIRCmd_DbgCreateCompileUnit,
  269. BfIRCmd_DbgCreateFile,
  270. BfIRCmd_ConstValueI64,
  271. BfIRCmd_DbgGetCurrentLocation,
  272. BfIRCmd_DbgSetType,
  273. BfIRCmd_DbgSetInstType,
  274. BfIRCmd_DbgGetType,
  275. BfIRCmd_DbgGetTypeInst,
  276. BfIRCmd_DbgTrackDITypes,
  277. BfIRCmd_DbgCreateNamespace,
  278. BfIRCmd_DbgCreateImportedModule,
  279. BfIRCmd_DbgCreateBasicType,
  280. BfIRCmd_DbgCreateStructType,
  281. BfIRCmd_DbgCreateEnumerationType,
  282. BfIRCmd_DbgCreatePointerType,
  283. BfIRCmd_DbgCreateReferenceType,
  284. BfIRCmd_DbgCreateConstType,
  285. BfIRCmd_DbgCreateArtificialType,
  286. BfIRCmd_DbgCreateArrayType,
  287. BfIRCmd_DbgCreateReplaceableCompositeType,
  288. BfIRCmd_DbgCreateForwardDecl,
  289. BfIRCmd_DbgCreateSizedForwardDecl,
  290. BeIRCmd_DbgSetTypeSize,
  291. BfIRCmd_DbgReplaceAllUses,
  292. BfIRCmd_DbgDeleteTemporary,
  293. BfIRCmd_DbgMakePermanent,
  294. BfIRCmd_CreateEnumerator,
  295. BfIRCmd_DbgCreateMemberType,
  296. BfIRCmd_DbgStaticCreateMemberType,
  297. BfIRCmd_DbgCreateInheritance,
  298. BfIRCmd_DbgCreateMethod,
  299. BfIRCmd_DbgCreateFunction,
  300. BfIRCmd_DbgCreateParameterVariable,
  301. BfIRCmd_DbgCreateSubroutineType,
  302. BfIRCmd_DbgCreateAutoVariable,
  303. BfIRCmd_DbgInsertValueIntrinsic,
  304. BfIRCmd_DbgInsertDeclare,
  305. BfIRCmd_DbgLifetimeEnd,
  306. BfIRCmd_DbgCreateGlobalVariable,
  307. BfIRCmd_DbgCreateLexicalBlock,
  308. BfIRCmd_DbgCreateLexicalBlockFile,
  309. BfIRCmd_DbgCreateAnnotation,
  310. BfIRCmd_COUNT
  311. };
  312. enum BfIRCallingConv
  313. {
  314. BfIRCallingConv_ThisCall,
  315. BfIRCallingConv_StdCall,
  316. BfIRCallingConv_CDecl,
  317. };
  318. enum BfIRParamType : uint8
  319. {
  320. BfIRParamType_None,
  321. BfIRParamType_Const,
  322. BfIRParamType_Arg,
  323. BfIRParamType_StreamId_Abs8,
  324. BfIRParamType_StreamId_Rel,
  325. BfIRParamType_StreamId_Back1,
  326. BfIRParamType_StreamId_Back_LAST = 0xFF, // Use remaining encoding
  327. };
  328. enum BfIRLinkageType : uint8
  329. {
  330. BfIRLinkageType_External,
  331. BfIRLinkageType_Internal
  332. };
  333. enum BfIRInitType : uint8
  334. {
  335. BfIRInitType_NotSet, // Not specified
  336. BfIRInitType_NotNeeded, // Explicitly disable
  337. BfIRInitType_NotNeeded_AliveOnDecl, // Explicitly disable, treat variable as alive at declaration
  338. BfIRInitType_Uninitialized, // May set to 0xCC for debug
  339. BfIRInitType_Zero, // Must be zero
  340. };
  341. enum BfIRFenceType : uint8
  342. {
  343. BfIRFenceType_AcquireRelease
  344. };
  345. enum BfIRConfigConst : uint8
  346. {
  347. BfIRConfigConst_VirtualMethodOfs,
  348. BfIRConfigConst_DynSlotOfs
  349. };
  350. enum BfIRIntrinsic : uint8
  351. {
  352. BfIRIntrinsic_AtomicAdd,
  353. BfIRIntrinsic_AtomicAnd,
  354. BfIRIntrinsic_AtomicCmpStore,
  355. BfIRIntrinsic_AtomicCmpStore_Weak,
  356. BfIRIntrinsic_AtomicCmpXChg,
  357. BfIRIntrinsic_AtomicFence,
  358. BfIRIntrinsic_AtomicLoad,
  359. BfIRIntrinsic_AtomicMax,
  360. BfIRIntrinsic_AtomicMin,
  361. BfIRIntrinsic_AtomicNAnd,
  362. BfIRIntrinsic_AtomicOr,
  363. BfIRIntrinsic_AtomicStore,
  364. BfIRIntrinsic_AtomicSub,
  365. BfIRIntrinsic_AtomicUMax,
  366. BfIRIntrinsic_AtomicUMin,
  367. BfIRIntrinsic_AtomicXChg,
  368. BfIRIntrinsic_AtomicXor,
  369. BfIRIntrinsic_BSwap,
  370. BfIRIntrinsic_Cos,
  371. BfIRIntrinsic_Floor,
  372. BfIRIntrinsic_Free,
  373. BfIRIntrinsic_Log,
  374. BfIRIntrinsic_Log10,
  375. BfIRIntrinsic_Log2,
  376. BfIRIntrinsic_Malloc,
  377. BfIRIntrinsic_MemCpy,
  378. BfIRIntrinsic_MemMove,
  379. BfIRIntrinsic_MemSet,
  380. BfIRIntrinsic_Pow,
  381. BfIRIntrinsic_PowI,
  382. BfIRIntrinsic_Round,
  383. BfIRIntrinsic_Sin,
  384. BfIRIntrinsic_Sqrt,
  385. BfIRIntrinsic_COUNT,
  386. BfIRIntrinsic_Atomic_FIRST = BfIRIntrinsic_AtomicAdd,
  387. BfIRIntrinsic_Atomic_LAST = BfIRIntrinsic_AtomicXor
  388. };
  389. enum BfIRAtomicOrdering : uint8
  390. {
  391. BfIRAtomicOrdering_Unordered,
  392. BfIRAtomicOrdering_Relaxed,
  393. BfIRAtomicOrdering_Acquire,
  394. BfIRAtomicOrdering_Release,
  395. BfIRAtomicOrdering_AcqRel,
  396. BfIRAtomicOrdering_SeqCst,
  397. BfIRAtomicOrdering_ORDERMASK = 7,
  398. BfIRAtomicOrdering_Volatile = 8,
  399. BfIRAtomicOrdering_ReturnModified = 0x10 // Generally atomic instructions return original value, this overrides that
  400. };
  401. //#define CHECK_CONSTHOLDER
  402. struct BfIRRawValue
  403. {
  404. public:
  405. int mId;
  406. BfIRRawValue()
  407. {
  408. mId = -1;
  409. }
  410. operator bool() const
  411. {
  412. return mId != -1;
  413. }
  414. bool IsFake() const
  415. {
  416. return mId < -1;
  417. }
  418. };
  419. struct BfIRValue
  420. {
  421. public:
  422. // Reserved 'fake' Ids
  423. enum
  424. {
  425. ID_IMPLICIT = -3
  426. };
  427. public:
  428. int mId;
  429. BfIRValueFlags mFlags;
  430. #ifdef CHECK_CONSTHOLDER
  431. BfIRConstHolder* mHolder;
  432. #endif
  433. public:
  434. BfIRValue()
  435. {
  436. mId = -1;
  437. mFlags = BfIRValueFlags_None;
  438. #ifdef CHECK_CONSTHOLDER
  439. mHolder = NULL;
  440. #endif
  441. }
  442. BfIRValue(const BfIRValue& from)
  443. {
  444. mFlags = from.mFlags;
  445. mId = from.mId;
  446. #ifdef CHECK_CONSTHOLDER
  447. mHolder = from.mHolder;
  448. #endif
  449. }
  450. BfIRValue(BfIRValueFlags flags, int id)
  451. {
  452. mFlags = flags;
  453. mId = id;
  454. }
  455. operator bool() const
  456. {
  457. return mFlags != BfIRValueFlags_None;
  458. }
  459. bool IsFake() const;
  460. bool IsConst() const;
  461. bool IsArg() const;
  462. bool IsFromLLVM() const;
  463. bool operator==(const BfIRValue& rhs) const
  464. {
  465. if (mFlags != rhs.mFlags)
  466. return false;
  467. if (mId != rhs.mId)
  468. return false;
  469. return true;
  470. }
  471. bool operator!=(const BfIRValue& rhs) const
  472. {
  473. if (mFlags != rhs.mFlags)
  474. return true;
  475. if (mId != rhs.mId)
  476. return true;
  477. return false;
  478. }
  479. };
  480. struct BfIRTypeData
  481. {
  482. enum TypeKind
  483. {
  484. TypeKind_None,
  485. TypeKind_TypeId,
  486. TypeKind_TypeInstId,
  487. TypeKind_TypeInstPtrId,
  488. TypeKind_Stream,
  489. };
  490. TypeKind mKind;
  491. int mId;
  492. };
  493. struct BfIRType : public BfIRTypeData
  494. {
  495. public:
  496. BfIRType()
  497. {
  498. mKind = TypeKind_None;
  499. mId = -1;
  500. }
  501. BfIRType(BfIRTypeData typeData)
  502. {
  503. mKind = typeData.mKind;
  504. mId = typeData.mId;
  505. }
  506. BfIRType(const BfIRValue& val) { mKind = TypeKind_Stream; mId = val.mId; }
  507. operator bool()
  508. {
  509. return (mId != -1);
  510. }
  511. };
  512. struct BfIRBlock : public BfIRValue
  513. {
  514. public:
  515. BfIRBlock();
  516. BfIRBlock(const BfIRValue& fromVal) : BfIRValue(fromVal) {}
  517. };
  518. enum BfIRAttribute
  519. {
  520. BfIRAttribute_NoReturn,
  521. BfIRAttribute_NoAlias,
  522. BfIRAttribute_NoCapture,
  523. BfIRAttribute_StructRet,
  524. BfIRAttribute_ZExt,
  525. BfIRAttribute_ByVal,
  526. BfIRAttribute_Dereferencable,
  527. BFIRAttribute_NoUnwind,
  528. BFIRAttribute_UWTable,
  529. BFIRAttribute_AlwaysInline,
  530. BFIRAttribute_NoFramePointerElim,
  531. BFIRAttribute_DllImport,
  532. BFIRAttribute_DllExport,
  533. };
  534. struct BfIRFunctionType
  535. {
  536. public:
  537. int mId;
  538. public:
  539. BfIRFunctionType();
  540. BfIRFunctionType(const BfIRValue& val) { mId = val.mId; }
  541. operator bool() const
  542. {
  543. return mId != -1;
  544. }
  545. };
  546. struct BfIRFunction : public BfIRRawValue
  547. {
  548. public:
  549. BfIRFunction();
  550. BfIRFunction(const BfIRValue& val)
  551. {
  552. BF_ASSERT((val.mFlags == BfIRValueFlags_None) || (val.mFlags == BfIRValueFlags_Value));
  553. mId = val.mId;
  554. }
  555. //: BfIRValue(val) {}
  556. bool operator==(const BfIRFunction& rhs) const
  557. {
  558. if (mId != rhs.mId)
  559. return false;
  560. return true;
  561. }
  562. bool operator!=(const BfIRFunction& rhs) const
  563. {
  564. if (mId == rhs.mId)
  565. return false;
  566. return true;
  567. }
  568. operator bool() const
  569. {
  570. return mId != -1;
  571. }
  572. operator BfIRValue() const
  573. {
  574. return BfIRValue((mId == -1) ? BfIRValueFlags_None : BfIRValueFlags_Value, mId);
  575. }
  576. };
  577. struct BfIRMDNode
  578. {
  579. public:
  580. int mId;
  581. BfIRMDNode()
  582. {
  583. mId = -1;
  584. }
  585. BfIRMDNode(const BfIRValue& val)
  586. {
  587. mId = val.mId;
  588. }
  589. BfIRMDNode(llvm::MDNode* mdNode)
  590. {
  591. mId = -1;
  592. }
  593. operator bool() const
  594. {
  595. return mId != -1;
  596. }
  597. bool operator==(const BfIRMDNode& rhs) const
  598. {
  599. if (mId != rhs.mId)
  600. return false;
  601. return true;
  602. }
  603. bool operator!=(const BfIRMDNode& rhs) const
  604. {
  605. if (mId == rhs.mId)
  606. return false;
  607. return true;
  608. }
  609. };
  610. class BfFileInstance
  611. {
  612. public:
  613. BfParserData* mParser;
  614. BfIRMDNode mDIFile;
  615. BfFilePosition mPrevPosition;
  616. public:
  617. BfFileInstance()
  618. {
  619. mParser = NULL;
  620. }
  621. };
  622. struct BfGlobalVar
  623. {
  624. BfConstType mConstType;
  625. const char* mName;
  626. BfIRType mType;
  627. bool mIsConst;
  628. BfIRLinkageType mLinkageType;
  629. int mStreamId;
  630. BfIRValue mInitializer;
  631. bool mIsTLS;
  632. };
  633. struct BfGlobalVar_TypeInst
  634. {
  635. BfConstType mConstType;
  636. const char* mName;
  637. BfTypeInstance* mTypeInst;
  638. bool mIsConst;
  639. BfIRLinkageType mLinkageType;
  640. int mStreamId;
  641. BfIRValue mInitializer;
  642. bool mIsTLS;
  643. };
  644. struct BfTypeOf_Const
  645. {
  646. BfConstType mConstType;
  647. BfType* mType;
  648. };
  649. struct BfConstant
  650. {
  651. public:
  652. union
  653. {
  654. BfTypeCode mTypeCode;
  655. BfConstType mConstType;
  656. };
  657. union
  658. {
  659. bool mBool;
  660. int64 mInt64;
  661. int32 mInt32;
  662. int16 mInt16;
  663. int8 mInt8;
  664. uint64 mUInt64;
  665. uint32 mUInt32;
  666. uint16 mUInt16;
  667. uint8 mUInt8;
  668. uint8 mChar;
  669. uint32 mChar32;
  670. double mDouble;
  671. BfIRTypeData mIRType;
  672. };
  673. bool IsNull()
  674. {
  675. if (mTypeCode == BfTypeCode_NullPtr)
  676. return true;
  677. if (mConstType == BfConstType_BitCastNull)
  678. return true;
  679. return false;
  680. }
  681. };
  682. struct BfConstantUndef
  683. {
  684. BfConstType mConstType;
  685. BfTypeCode mTypeCode;
  686. };
  687. struct BfConstantBitCast
  688. {
  689. BfConstType mConstType;
  690. int mTarget;
  691. BfIRType mToType;
  692. };
  693. struct BfConstantPtrToInt
  694. {
  695. BfConstType mConstType;
  696. int mTarget;
  697. BfTypeCode mToTypeCode;
  698. };
  699. struct BfConstantGEP32_2
  700. {
  701. BfConstType mConstType;
  702. int mTarget;
  703. int mIdx0;
  704. int mIdx1;
  705. };
  706. struct BfConstantArray
  707. {
  708. BfConstType mConstType;
  709. BfIRType mType;
  710. BfSizedArray<BfIRValue> mValues;
  711. };
  712. class BfIRConstHolder
  713. {
  714. public:
  715. BumpAllocatorT<256> mTempAlloc;
  716. BfModule* mModule;
  717. public:
  718. void FixTypeCode(BfTypeCode& typeCode);
  719. static bool IsInt(BfTypeCode typeCode);
  720. static bool IsSigned(BfTypeCode typeCode);
  721. static bool IsFloat(BfTypeCode typeCode);
  722. const char* AllocStr(const StringImpl& str);
  723. public:
  724. BfIRConstHolder(BfModule* module);
  725. virtual ~BfIRConstHolder();
  726. BfConstant* GetConstantById(int id);
  727. BfConstant* GetConstant(BfIRValue id);
  728. bool TryGetBool(BfIRValue id, bool& boolVal);
  729. BfIRValue CreateConst(BfTypeCode typeCode, uint64 val);
  730. BfIRValue CreateConst(BfTypeCode typeCode, int val);
  731. BfIRValue CreateConst(BfTypeCode typeCode, double val);
  732. BfIRValue CreateConst(BfConstant* fromConst, BfIRConstHolder* fromHolder);
  733. BfIRValue CreateConstNull();
  734. BfIRValue CreateConstNull(BfIRType nullType);
  735. BfIRValue CreateConstStructZero(BfIRType aggType);
  736. BfIRValue CreateConstArray(BfIRType type, const BfSizedArray<BfIRValue>& values);
  737. BfIRValue CreateTypeOf(BfType* type);
  738. BfIRValue GetUndefConstValue(BfTypeCode typeCode);
  739. };
  740. enum BfIRPopulateType
  741. {
  742. BfIRPopulateType_Identity,
  743. BfIRPopulateType_Declaration,
  744. BfIRPopulateType_Eventually_Full,
  745. BfIRPopulateType_Full,
  746. BfIRPopulateType_Full_ForceDefinition
  747. };
  748. class BfIRBuilder : public BfIRConstHolder
  749. {
  750. public:
  751. bool mIgnoreWrites;
  752. bool mDbgVerifyCodeGen;
  753. int mCurFakeId;
  754. bool mHasGlobalDefs;
  755. int mNumFunctionsWithBodies;
  756. int mBlockCount;
  757. bool mHasStarted;
  758. int mCmdCount;
  759. ChunkedDataBuffer mStream;
  760. BfIRBlock mActualInsertBlock; // Only when not ignoring writes
  761. BfIRBlock mInsertBlock;
  762. bool mHasDebugLoc;
  763. bool mHasDebugInfo;
  764. Dictionary<BfMethodInstance*, BfIRFunctionType> mMethodTypeMap;
  765. Dictionary<String, BfIRFunction> mFunctionMap;
  766. Dictionary<BfType*, BfIRPopulateType> mTypeMap;
  767. Dictionary<int, BfIRValue> mConstMemMap;
  768. Array<BfTypeInstance*> mDITemporaryTypes;
  769. BfIRFunction mActiveFunction;
  770. bool mActiveFunctionHasBody;
  771. Array<BfFilePosition> mSavedDebugLocs;
  772. Array<BfType*> mDeferredDbgTypeDefs;
  773. BfIRCodeGenBase* mIRCodeGen;
  774. BfIRCodeGen* mBfIRCodeGen;
  775. #ifdef BF_PLATFORM_WINDOWS
  776. BeIRCodeGen* mBeIRCodeGen;
  777. #endif
  778. #ifdef BFIR_RENTRY_CHECK
  779. std::set<BfType*> mDeclReentrySet;
  780. std::set<BfType*> mDefReentrySet;
  781. #endif
  782. bool mOpFailed;
  783. public:
  784. ~BfIRBuilder();
  785. void WriteSLEB128(int64 val);
  786. void Write(uint8 val);
  787. void Write(bool val);
  788. void Write(int val);
  789. void Write(int64 val);
  790. void Write(const StringImpl& str);
  791. void Write(const BfIRValue& irValue);
  792. void Write(BfTypeCode typeCode);
  793. void Write(BfIRTypeData type);
  794. void Write(BfIRFunctionType func);
  795. void Write(BfIRFunction funcType);
  796. void Write(BfIRBlock block);
  797. void Write(BfIRMDNode node);
  798. template <typename T>
  799. void Write(const BfSizedArray<T>& sizedArray)
  800. {
  801. WriteSLEB128(sizedArray.mSize);
  802. for (int i = 0; i < sizedArray.mSize; i++)
  803. Write(sizedArray.mVals[i]);
  804. }
  805. BfIRValue WriteCmd(BfIRCmd cmd);
  806. template <typename T>
  807. void WriteArg(const T& first)
  808. {
  809. Write(first);
  810. }
  811. template <typename T, typename... Args>
  812. void WriteArg(const T& first, const Args&... args)
  813. {
  814. Write(first);
  815. WriteArg(args...);
  816. }
  817. template <typename... Args>
  818. BfIRValue WriteCmd(BfIRCmd cmd, const Args&... args)
  819. {
  820. if (mIgnoreWrites)
  821. return GetFakeVal();
  822. //int dataPos = mStream.GetSize();
  823. auto result = WriteCmd(cmd);
  824. WriteArg(args...);
  825. return result;
  826. //return BfIRValue(BfIRValueFlags_Value, dataPos);
  827. }
  828. public:
  829. void NewCmdInserted();
  830. BfIRMDNode CreateNamespaceScope(BfType* type, BfIRMDNode fileDIScope);
  831. String GetDebugTypeName(BfTypeInstance* typeInstance, bool includeOuterTypeName);
  832. void CreateDbgTypeDefinition(BfType* type);
  833. void CreateTypeDeclaration(BfType* type, bool forceDefine);
  834. void CreateTypeDefinition(BfType* type, bool forceDefine);
  835. void ReplaceDITemporaryTypes();
  836. void PushDbgLoc(BfTypeInstance* typeInst);
  837. BfIRPopulateType GetPopulateTypeState(BfType* type);
  838. void PopulateType(BfType* type, BfIRPopulateType populateType = BfIRPopulateType_Full);
  839. void SetType(BfType* type, BfIRType irType);
  840. void SetInstType(BfType* type, BfIRType irType);
  841. int GetFakeId();
  842. BfIRValue GetFakeVal();
  843. BfIRValue GetFakeConst();
  844. BfIRType GetFakeType();
  845. BfIRType GetFakeBlock();
  846. BfIRFunctionType GetFakeFunctionType();
  847. BfIRFunction GetFakeFunction();
  848. public:
  849. void OpFailed();
  850. uint8 CheckedAdd(uint8 a, uint8 b);
  851. uint16 CheckedAdd(uint16 a, uint16 b);
  852. uint32 CheckedAdd(uint32 a, uint32 b);
  853. uint64 CheckedAdd(uint64 a, uint64 b);
  854. int8 CheckedAdd(int8 a, int8 b);
  855. int16 CheckedAdd(int16 a, int16 b);
  856. int32 CheckedAdd(int32 a, int32 b);
  857. int64 CheckedAdd(int64 a, int64 b);
  858. float CheckedAdd(float a, float b) { return a + b; }
  859. double CheckedAdd(double a, double b) { return a + b; }
  860. uint8 CheckedSub(uint8 a, uint8 b);
  861. uint16 CheckedSub(uint16 a, uint16 b);
  862. uint32 CheckedSub(uint32 a, uint32 b);
  863. uint64 CheckedSub(uint64 a, uint64 b);
  864. int8 CheckedSub(int8 a, int8 b);
  865. int16 CheckedSub(int16 a, int16 b);
  866. int32 CheckedSub(int32 a, int32 b);
  867. int64 CheckedSub(int64 a, int64 b);
  868. float CheckedSub(float a, float b) { return a - b; }
  869. double CheckedSub(double a, double b) { return a - b; }
  870. uint8 CheckedMul(uint8 a, uint8 b);
  871. uint16 CheckedMul(uint16 a, uint16 b);
  872. uint32 CheckedMul(uint32 a, uint32 b);
  873. uint64 CheckedMul(uint64 a, uint64 b);
  874. int8 CheckedMul(int8 a, int8 b);
  875. int16 CheckedMul(int16 a, int16 b);
  876. int32 CheckedMul(int32 a, int32 b);
  877. int64 CheckedMul(int64 a, int64 b);
  878. float CheckedMul(float a, float b) { return a * b; }
  879. double CheckedMul(double a, double b) { return a * b; }
  880. uint8 CheckedShl(uint8 a, uint8 b);
  881. uint16 CheckedShl(uint16 a, uint16 b);
  882. uint32 CheckedShl(uint32 a, uint32 b);
  883. uint64 CheckedShl(uint64 a, uint64 b);
  884. int8 CheckedShl(int8 a, int8 b);
  885. int16 CheckedShl(int16 a, int16 b);
  886. int32 CheckedShl(int32 a, int32 b);
  887. int64 CheckedShl(int64 a, int64 b);
  888. public:
  889. BfIRBuilder(BfModule* module);
  890. bool HasExports(); // Contains non-empty functions and/or non-empty globals
  891. String ToString(BfIRValue irValue);
  892. String ToString(BfIRType irType);
  893. String ToString(BfIRFunction irFunc);
  894. String ToString(BfIRFunctionType irType);
  895. String ToString(BfIRMDNode irMDNode);
  896. String ActiveFuncToString();
  897. void PrintActiveFunc();
  898. void pv(const BfIRValue& irValue);
  899. void pt(const BfIRType& irType);
  900. void pbft(BfType* type);
  901. void pt(const BfIRFunction& irFun);
  902. void pft(const BfIRFunctionType& irType);
  903. void pmd(const BfIRMDNode& irMDNode);
  904. void GetBufferData(Array<uint8>& outBuffer);
  905. void ClearConstData();
  906. void Start(const StringImpl& moduleName, int ptrSize, bool isOptimized);
  907. void SetBackend(bool isBeefBackend);
  908. void RemoveIRCodeGen();
  909. void WriteIR(const StringImpl& fileName);
  910. void Module_SetTargetTriple(const StringImpl& targetTriple);
  911. void Module_AddModuleFlag(const StringImpl& flag, int val);
  912. BfIRType GetPrimitiveType(BfTypeCode typeCode);
  913. BfIRType CreateStructType(const StringImpl& name);
  914. void StructSetBody(BfIRType type, const BfSizedArray<BfIRType>& memberTypes, bool isPacked);
  915. BfIRType MapType(BfType* type, BfIRPopulateType populateType = BfIRPopulateType_Declaration);
  916. BfIRType MapTypeInst(BfTypeInstance* typeInst, BfIRPopulateType populateType = BfIRPopulateType_Declaration);
  917. BfIRType MapTypeInstPtr(BfTypeInstance* typeInst);
  918. BfIRType GetType(BfIRValue val);
  919. BfIRType GetPointerTo(BfIRFunctionType funcType);
  920. BfIRType GetPointerTo(BfIRType type);
  921. BfIRType GetSizedArrayType(BfIRType elementType, int length);
  922. BfIRValue CreateConstStruct(BfIRType type, const BfSizedArray<BfIRValue>& values);
  923. BfIRValue CreateConstString(const StringImpl& string);
  924. BfIRValue ConstToMemory(BfIRValue constVal);
  925. BfIRValue GetConfigConst(BfIRConfigConst constType, BfTypeCode typeCode);
  926. BfIRValue GetArgument(int argIdx);
  927. void SetName(BfIRValue val, const StringImpl& name);
  928. BfIRValue CreateUndefValue(BfIRType type);
  929. BfIRValue CreateNumericCast(BfIRValue val, bool valIsSigned, BfTypeCode typeCode);
  930. BfIRValue CreateCmpEQ(BfIRValue lhs, BfIRValue rhs);
  931. BfIRValue CreateCmpNE(BfIRValue lhs, BfIRValue rhs);
  932. BfIRValue CreateCmpLT(BfIRValue lhs, BfIRValue rhs, bool isSigned);
  933. BfIRValue CreateCmpLTE(BfIRValue lhs, BfIRValue rhs, bool isSigned);
  934. BfIRValue CreateCmpGT(BfIRValue lhs, BfIRValue rhs, bool isSigned);
  935. BfIRValue CreateCmpGTE(BfIRValue lhs, BfIRValue rhs, bool isSigned);
  936. BfIRValue CreateAdd(BfIRValue lhs, BfIRValue rhs);
  937. BfIRValue CreateSub(BfIRValue lhs, BfIRValue rhs);
  938. BfIRValue CreateMul(BfIRValue lhs, BfIRValue rhs);
  939. BfIRValue CreateDiv(BfIRValue lhs, BfIRValue rhs, bool isSigned);
  940. BfIRValue CreateRem(BfIRValue lhs, BfIRValue rhs, bool isSigned);
  941. BfIRValue CreateAnd(BfIRValue lhs, BfIRValue rhs);
  942. BfIRValue CreateOr(BfIRValue lhs, BfIRValue rhs);
  943. BfIRValue CreateXor(BfIRValue lhs, BfIRValue rhs);
  944. BfIRValue CreateShl(BfIRValue lhs, BfIRValue rhs);
  945. BfIRValue CreateShr(BfIRValue lhs, BfIRValue rhs, bool isSigned);
  946. BfIRValue CreateNeg(BfIRValue val);
  947. BfIRValue CreateNot(BfIRValue val);
  948. BfIRValue CreateBitCast(BfIRValue val, BfIRType type);
  949. BfIRValue CreatePtrToInt(BfIRValue val, BfTypeCode typeCode);
  950. BfIRValue CreateIntToPtr(BfIRValue val, BfIRType type);
  951. BfIRValue CreateInBoundsGEP(BfIRValue val, int idx0);
  952. BfIRValue CreateInBoundsGEP(BfIRValue val, int idx0, int idx1);
  953. BfIRValue CreateInBoundsGEP(BfIRValue val, BfIRValue idx0);
  954. BfIRValue CreateInBoundsGEP(BfIRValue val, BfIRValue idx0, BfIRValue idx1);
  955. BfIRValue CreateIsNull(BfIRValue val);
  956. BfIRValue CreateIsNotNull(BfIRValue val);
  957. BfIRValue CreateExtractValue(BfIRValue val, int idx);
  958. BfIRValue CreateExtractValue(BfIRValue val, BfIRValue idx);
  959. BfIRValue CreateInsertValue(BfIRValue agg, BfIRValue val, int idx);
  960. BfIRValue CreateAlloca(BfIRType type);
  961. BfIRValue CreateAlloca(BfIRType type, BfIRValue arraySize);
  962. void SetAllocaAlignment(BfIRValue val, int alignment);
  963. // When we do a dynamic alloca where we know the memory access patterns will not cause a page fault, we can omit the __chkstk call
  964. // Generally, this is when we allocate less than 4k and we know there will be a write on this memory before the next alloca
  965. void SetAllocaNoChkStkHint(BfIRValue val);
  966. void SetAllocaForceMem(BfIRValue val);
  967. BfIRValue CreateAliasValue(BfIRValue val);
  968. BfIRValue CreateLifetimeStart(BfIRValue val);
  969. BfIRValue CreateLifetimeEnd(BfIRValue val);
  970. BfIRValue CreateLifetimeExtend(BfIRValue val);
  971. BfIRValue CreateValueScopeStart();
  972. void CreateValueScopeRetain(BfIRValue val); // When a value is held by a variable -- don't release until we have a HardValueScopeEnd
  973. void CreateValueScopeSoftEnd(BfIRValue scopeStart);
  974. void CreateValueScopeHardEnd(BfIRValue scopeStart);
  975. BfIRValue CreateLoad(BfIRValue val, bool isVolatile = false);
  976. BfIRValue CreateAlignedLoad(BfIRValue val, int align, bool isVolatile = false);
  977. BfIRValue CreateStore(BfIRValue val, BfIRValue ptr, bool isVolatile = false);
  978. BfIRValue CreateAlignedStore(BfIRValue val, BfIRValue ptr, int align, bool isVolatile = false);
  979. BfIRValue CreateMemSet(BfIRValue addr, BfIRValue val, BfIRValue size, int align);
  980. void CreateFence(BfIRFenceType fenceType);
  981. BfIRValue CreateStackSave();
  982. void CreateStackRestore(BfIRValue stackVal);
  983. BfIRValue CreateGlobalVariable(BfIRType varType, bool isConstant, BfIRLinkageType linkageType, BfIRValue initializer, const StringImpl& name, bool isTLS = false);
  984. void GlobalVar_SetUnnamedAddr(BfIRValue val, bool unnamedAddr);
  985. void GlobalVar_SetInitializer(BfIRValue globalVar, BfIRValue initVal);
  986. void GlobalVar_SetAlignment(BfIRValue globalVar, int alignment);
  987. BfIRValue CreateGlobalStringPtr(const StringImpl& str);
  988. BfIRBlock CreateBlock(const StringImpl& name, bool addNow = false);
  989. BfIRBlock MaybeChainNewBlock(const StringImpl& name); // Creates new block if current block isn't empty
  990. void AddBlock(BfIRBlock block);
  991. void DropBlocks(BfIRBlock block);
  992. void MergeBlockDown(BfIRBlock fromBlock, BfIRBlock intoBlock);
  993. void SetInsertPoint(BfIRValue value);
  994. void SetInsertPoint(BfIRBlock block);
  995. void SetInsertPointAtStart(BfIRBlock block);
  996. void EraseFromParent(BfIRBlock block);
  997. void DeleteBlock(BfIRBlock block);
  998. void EraseInstFromParent(BfIRValue val);
  999. BfIRValue CreateBr(BfIRBlock block);
  1000. BfIRValue CreateBr_Fake(BfIRBlock block);
  1001. BfIRValue CreateBr_NoCollapse(BfIRBlock block);
  1002. void CreateCondBr(BfIRValue val, BfIRBlock trueBlock, BfIRBlock falseBlock);
  1003. BfIRBlock GetInsertBlock();
  1004. void MoveBlockToEnd(BfIRBlock block);
  1005. BfIRValue CreateSwitch(BfIRValue value, BfIRBlock dest, int numCases);
  1006. BfIRValue AddSwitchCase(BfIRValue switchVal, BfIRValue caseVal, BfIRBlock caseBlock);
  1007. void SetSwitchDefaultDest(BfIRValue switchVal, BfIRBlock caseBlock);
  1008. BfIRValue CreatePhi(BfIRType type, int incomingCount);
  1009. void AddPhiIncoming(BfIRValue phi, BfIRValue value, BfIRBlock comingFrom);
  1010. BfIRFunction GetIntrinsic(int intrinId, const BfSizedArray<BfIRType>& paramTypes);
  1011. BfIRFunctionType MapMethod(BfMethodInstance* methodInstance);
  1012. BfIRFunctionType CreateFunctionType(BfIRType resultType, const BfSizedArray<BfIRType>& paramTypes, bool isVarArg = false);
  1013. BfIRFunction CreateFunction(BfIRFunctionType funcType, BfIRLinkageType linkageType, const StringImpl& name);
  1014. void EnsureFunctionPatchable();
  1015. BfIRValue RemapBindFunction(BfIRValue func);
  1016. void SetActiveFunction(BfIRFunction func);
  1017. BfIRFunction GetActiveFunction();
  1018. BfIRFunction GetFunction(const StringImpl& name);
  1019. BfIRValue CreateCall(BfIRValue func, const BfSizedArray<BfIRValue>& params);
  1020. void SetCallCallingConv(BfIRValue callInst, BfIRCallingConv callingConv);
  1021. void SetFuncCallingConv(BfIRFunction func, BfIRCallingConv callingConv);
  1022. void SetTailCall(BfIRValue callInst);
  1023. void SetCallAttribute(BfIRValue callInst, int paramIdx, BfIRAttribute attribute);
  1024. BfIRValue CreateRet(BfIRValue val);
  1025. void CreateRetVoid();
  1026. void CreateUnreachable();
  1027. void Call_AddAttribute(BfIRValue callInst, int argIdx, BfIRAttribute attr);
  1028. void Call_AddAttribute(BfIRValue callInst, int argIdx, BfIRAttribute attr, int arg);
  1029. void Func_AddAttribute(BfIRFunction func, int argIdx, BfIRAttribute attr);
  1030. void Func_AddAttribute(BfIRFunction func, int argIdx, BfIRAttribute attr, int arg);
  1031. void Func_SetParamName(BfIRFunction func, int argIdx, const StringImpl& name);
  1032. void Func_DeleteBody(BfIRFunction func);
  1033. void Func_EraseFromParent(BfIRFunction func);
  1034. void Func_SetLinkage(BfIRFunction func, BfIRLinkageType linkage);
  1035. void SaveDebugLocation();
  1036. void RestoreDebugLocation();
  1037. bool HasDebugLocation();
  1038. void ClearDebugLocation();
  1039. void ClearDebugLocation(BfIRValue inst);
  1040. void ClearDebugLocation_Last();
  1041. void UpdateDebugLocation(BfIRValue inst);
  1042. void SetCurrentDebugLocation(int line, int column, BfIRMDNode diScope, BfIRMDNode diInlinedAt);
  1043. void CreateNop();
  1044. void CreateEnsureInstructionAt();
  1045. void CreateStatementStart();
  1046. void CreateObjectAccessCheck(BfIRValue value, bool useAsm);
  1047. void DbgInit();
  1048. void DbgFinalize();
  1049. bool DbgHasInfo();
  1050. String DbgGetStaticFieldName(BfFieldInstance* fieldInstance);
  1051. void DbgAddPrefix(String& name);
  1052. BfIRMDNode DbgCreateCompileUnit(int lang, const StringImpl& filename, const StringImpl& directory, const StringImpl& producer, bool isOptimized,
  1053. const StringImpl& flags, int runtimeVer, bool linesOnly);
  1054. BfIRMDNode DbgCreateFile(const StringImpl& fileName, const StringImpl& directory);
  1055. BfIRMDNode DbgGetCurrentLocation();
  1056. void DbgSetType(BfType * type, BfIRMDNode diType);
  1057. void DbgSetInstType(BfType * type, BfIRMDNode diType);
  1058. BfIRMDNode DbgCreateConstValue(int64 val);
  1059. BfIRMDNode DbgGetType(BfType* type, BfIRPopulateType populateType = BfIRPopulateType_Declaration);
  1060. BfIRMDNode DbgGetTypeInst(BfTypeInstance* typeInst, BfIRPopulateType populateType = BfIRPopulateType_Declaration);
  1061. void DbgTrackDITypes(BfType* type);
  1062. BfIRMDNode DbgCreateNameSpace(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNum);
  1063. BfIRMDNode DbgCreateImportedModule(BfIRMDNode context, BfIRMDNode namespaceNode, int line);
  1064. BfIRMDNode DbgCreateBasicType(const StringImpl& name, int64 sizeInBits, int64 alignInBits, int encoding);
  1065. BfIRMDNode DbgCreateStructType(BfIRMDNode context, const StringImpl& name, BfIRMDNode file, int lineNum, int64 sizeInBits, int64 alignInBits,
  1066. int flags, BfIRMDNode derivedFrom, const BfSizedArray<BfIRMDNode>& elements);
  1067. BfIRMDNode DbgCreateEnumerationType(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNumber, int64 SizeInBits, int64 alignInBits,
  1068. const BfSizedArray<BfIRMDNode>& elements, BfIRMDNode underlyingType);
  1069. BfIRMDNode DbgCreatePointerType(BfIRMDNode diType);
  1070. BfIRMDNode DbgCreateReferenceType(BfIRMDNode diType);
  1071. BfIRMDNode DbgCreateConstType(BfIRMDNode diType);
  1072. BfIRMDNode DbgCreateArtificialType(BfIRMDNode diType);
  1073. BfIRMDNode DbgCreateArrayType(int64 sizeInBits, int64 alignInBits, BfIRMDNode elementType, int64 numElements);
  1074. BfIRMDNode DbgCreateReplaceableCompositeType(int tag, const StringImpl& name, BfIRMDNode scope, BfIRMDNode F, int line, int64 sizeInBits = 0, int64 alignInBits = 0, int flags = 0);
  1075. void DbgSetTypeSize(BfIRMDNode diType, int64 sizeInBits, int alignInBits);
  1076. BfIRMDNode DbgCreateForwardDecl(int tag, const StringImpl& name, BfIRMDNode scope, BfIRMDNode F, int line);
  1077. BfIRMDNode DbgCreateSizedForwardDecl(int tag, const StringImpl& name, BfIRMDNode scope, BfIRMDNode F, int line, int64 sizeInBits, int64 alignInBits);
  1078. BfIRMDNode DbgReplaceAllUses(BfIRMDNode diPrevNode, BfIRMDNode diNewNode);
  1079. void DbgDeleteTemporary(BfIRMDNode diNode);
  1080. BfIRMDNode DbgMakePermanent(BfIRMDNode diNode, BfIRMDNode diBaseType, const BfSizedArray<BfIRMDNode>& elements);
  1081. BfIRMDNode DbgCreateEnumerator(const StringImpl& name, int64 val);
  1082. BfIRMDNode DbgCreateMemberType(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNumber, int64 sizeInBits, int64 alignInBits,
  1083. int64 offsetInBits, int flags, BfIRMDNode type);
  1084. BfIRMDNode DbgCreateStaticMemberType(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNumber, BfIRMDNode type, int flags, BfIRValue val);
  1085. BfIRMDNode DbgCreateInheritance(BfIRMDNode type, BfIRMDNode baseType, int64 baseOffset, int flags);
  1086. BfIRMDNode DbgCreateMethod(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNum, BfIRMDNode type,
  1087. bool isLocalToUnit, bool isDefinition, int vk, int vIndex, BfIRMDNode vTableHolder, int flags, bool isOptimized, BfIRValue fn,
  1088. const BfSizedArray<BfIRMDNode>& genericArgs, const BfSizedArray<BfIRValue>& genericConstValueArgs);
  1089. BfIRMDNode DbgCreateFunction(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNum, BfIRMDNode type,
  1090. bool isLocalToUnit, bool isDefinition, int scopeLine, int flags, bool isOptimized, BfIRValue fn);
  1091. BfIRMDNode DbgCreateParameterVariable(BfIRMDNode scope, const StringImpl& name, int argNo, BfIRMDNode file, int lineNum, BfIRMDNode type,
  1092. bool AlwaysPreserve = false, int flags = 0);
  1093. BfIRMDNode DbgCreateSubroutineType(const BfSizedArray<BfIRMDNode>& elements);
  1094. BfIRMDNode DbgCreateAutoVariable(BfIRMDNode scope, const StringImpl& name, BfIRMDNode file, int lineNo, BfIRMDNode type, BfIRInitType initType = BfIRInitType_NotSet);
  1095. BfIRValue DbgInsertValueIntrinsic(BfIRValue val, BfIRMDNode varInfo);
  1096. BfIRValue DbgInsertDeclare(BfIRValue val, BfIRMDNode varInfo, BfIRValue declareBefore = BfIRValue());
  1097. BfIRValue DbgLifetimeEnd(BfIRMDNode varInfo);
  1098. void DbgCreateGlobalVariable(BfIRMDNode context, const StringImpl& name, const StringImpl& linkageName, BfIRMDNode file, int lineNumber,
  1099. BfIRMDNode type, bool isLocalToUnit, BfIRValue val, BfIRMDNode Decl = BfIRMDNode());
  1100. BfIRMDNode DbgCreateLexicalBlock(BfIRMDNode scope, BfIRMDNode file, int line, int col);
  1101. void DbgCreateAnnotation(BfIRMDNode scope, const StringImpl& name, BfIRValue value);
  1102. };
  1103. NS_BF_END