mkql_llvm_base.h.txt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #ifndef MKQL_DISABLE_CODEGEN
  3. #include <yql/essentials/minikql/computation/mkql_computation_node_impl.h>
  4. #include <llvm/IR/LLVMContext.h>
  5. #include <llvm/IR/Type.h>
  6. #include <llvm/IR/Constant.h>
  7. #include <llvm/IR/DerivedTypes.h>
  8. #include <llvm/IR/Constants.h>
  9. namespace NKikimr::NMiniKQL {
  10. template <class T>
  11. class TLLVMFieldsStructure;
  12. template <class T>
  13. class TLLVMFieldsStructure<TComputationValue<T>> {
  14. protected:
  15. llvm::LLVMContext& Context;
  16. ui32 GetFieldsCount() const {
  17. return FieldsCount;
  18. }
  19. const std::vector<llvm::Type*>& GetFields() const {
  20. return Fields;
  21. }
  22. private:
  23. llvm::PointerType* StructPtrType;
  24. std::vector<llvm::Type*> Fields;
  25. const ui32 FieldsCount;
  26. std::vector<llvm::Type*> BuildFields() {
  27. std::vector<llvm::Type*> result;
  28. result.emplace_back(StructPtrType); // vtbl
  29. result.emplace_back(llvm::Type::getInt32Ty(Context)); // ref
  30. result.emplace_back(llvm::Type::getInt16Ty(Context)); // abi
  31. result.emplace_back(llvm::Type::getInt16Ty(Context)); // reserved
  32. #ifndef NDEBUG
  33. result.emplace_back(StructPtrType); // meminfo
  34. #endif
  35. return result;
  36. }
  37. public:
  38. TLLVMFieldsStructure(llvm::LLVMContext& context)
  39. : Context(context)
  40. , StructPtrType(llvm::PointerType::getUnqual(llvm::StructType::get(Context)))
  41. , Fields(BuildFields())
  42. , FieldsCount(Fields.size()) {
  43. }
  44. llvm::Constant* This() const {
  45. return llvm::ConstantInt::get(llvm::Type::getInt32Ty(Context), 0);
  46. }
  47. const std::vector<llvm::Type*>& GetFieldsArray() const {
  48. return Fields;
  49. }
  50. };
  51. }
  52. #endif