mkql_toindexdict.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "mkql_toindexdict.h"
  2. #include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>
  3. #include <yql/essentials/minikql/computation/mkql_computation_node_codegen.h> // Y_IGNORE
  4. #include <yql/essentials/minikql/mkql_node_cast.h>
  5. namespace NKikimr {
  6. namespace NMiniKQL {
  7. namespace {
  8. class TToIndexDictWrapper : public TMutableCodegeneratorNode<TToIndexDictWrapper> {
  9. typedef TMutableCodegeneratorNode<TToIndexDictWrapper> TBaseComputation;
  10. public:
  11. TToIndexDictWrapper(TComputationMutables& mutables, IComputationNode* list)
  12. : TBaseComputation(mutables, list->GetRepresentation())
  13. , List(list)
  14. {
  15. }
  16. NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
  17. return ctx.HolderFactory.ToIndexDict(ctx.Builder, List->GetValue(ctx).Release());
  18. }
  19. #ifndef MKQL_DISABLE_CODEGEN
  20. Value* DoGenerateGetValue(const TCodegenContext& ctx, BasicBlock*& block) const {
  21. auto& context = ctx.Codegen.GetContext();
  22. const auto indexType = Type::getInt32Ty(context);
  23. const auto first = GetElementPtrInst::CreateInBounds(GetCompContextType(context), ctx.Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 0)}, "first", block);
  24. const auto fourth = GetElementPtrInst::CreateInBounds(GetCompContextType(context), ctx.Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 3)}, "fourth", block);
  25. const auto structPtrType = PointerType::getUnqual(StructType::get(context));
  26. const auto factory = new LoadInst(structPtrType, first, "factory", block);
  27. const auto builder = new LoadInst(structPtrType, fourth, "builder", block);
  28. const auto func = ConstantInt::get(Type::getInt64Ty(context), GetMethodPtr(&THolderFactory::ToIndexDict));
  29. const auto list = GetNodeValue(List, ctx, block);
  30. const auto funType = FunctionType::get(list->getType(), {factory->getType(), builder->getType(), list->getType()}, false);
  31. const auto funcPtr = CastInst::Create(Instruction::IntToPtr, func, PointerType::getUnqual(funType), "function", block);
  32. const auto result = CallInst::Create(funType, funcPtr, {factory, builder, list}, "result", block);
  33. return result;
  34. }
  35. #endif
  36. private:
  37. void RegisterDependencies() const final {
  38. DependsOn(List);
  39. }
  40. IComputationNode* const List;
  41. };
  42. }
  43. IComputationNode* WrapToIndexDict(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
  44. MKQL_ENSURE(callable.GetInputsCount() == 1, "Expected 1 args");
  45. return new TToIndexDictWrapper(ctx.Mutables, LocateNode(ctx.NodeLocator, callable, 0));
  46. }
  47. }
  48. }