diff options
| author | vvvv <[email protected]> | 2025-10-09 12:25:18 +0300 |
|---|---|---|
| committer | vvvv <[email protected]> | 2025-10-09 12:57:17 +0300 |
| commit | cb77d014972b2cdb27d2e6d979fc3a2772b27ad4 (patch) | |
| tree | 7f3bcd8ce71c6bd0f3ccc11e31b9f665475b819e /yql/essentials/minikql/comp_nodes/mkql_map.cpp | |
| parent | d58a8990d353b051c27e1069141117fdfde64358 (diff) | |
YQL-20086 minikql
commit_hash:e96f7390db5fcbe7e9f64f898141a263ad522daa
Diffstat (limited to 'yql/essentials/minikql/comp_nodes/mkql_map.cpp')
| -rw-r--r-- | yql/essentials/minikql/comp_nodes/mkql_map.cpp | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/yql/essentials/minikql/comp_nodes/mkql_map.cpp b/yql/essentials/minikql/comp_nodes/mkql_map.cpp index fb9819fd4a5..1deedf055db 100644 --- a/yql/essentials/minikql/comp_nodes/mkql_map.cpp +++ b/yql/essentials/minikql/comp_nodes/mkql_map.cpp @@ -1,6 +1,6 @@ #include "mkql_map.h" #include <yql/essentials/minikql/computation/mkql_computation_node_holders.h> -#include <yql/essentials/minikql/computation/mkql_computation_node_codegen.h> // Y_IGNORE +#include <yql/essentials/minikql/computation/mkql_computation_node_codegen.h> // Y_IGNORE #include <yql/essentials/minikql/mkql_node_cast.h> namespace NKikimr { @@ -8,15 +8,17 @@ namespace NMiniKQL { namespace { -class TFlowMapWrapper : public TStatelessFlowCodegeneratorNode<TFlowMapWrapper> { +class TFlowMapWrapper: public TStatelessFlowCodegeneratorNode<TFlowMapWrapper> { typedef TStatelessFlowCodegeneratorNode<TFlowMapWrapper> TBaseComputation; + public: TFlowMapWrapper(EValueRepresentation kind, IComputationNode* flow, IComputationExternalNode* item, IComputationNode* newItem) : TBaseComputation(flow, kind) , Flow(flow) , Item(item) , NewItem(newItem) - {} + { + } NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const { if (auto item = Flow->GetValue(ctx); item.IsSpecial()) { @@ -69,9 +71,9 @@ private: template <bool IsStream> class TBaseMapWrapper { protected: - class TListValue : public TCustomListValue { + class TListValue: public TCustomListValue { public: - class TIterator : public TComputationValue<TIterator> { + class TIterator: public TComputationValue<TIterator> { public: TIterator(TMemoryUsageInfo* memInfo, TComputationContext& compCtx, NUdf::TUnboxedValue&& iter, IComputationExternalNode* item, IComputationNode* newItem) : TComputationValue<TIterator>(memInfo) @@ -79,7 +81,8 @@ protected: , Iter(std::move(iter)) , Item(item) , NewItem(newItem) - {} + { + } private: bool Next(NUdf::TUnboxedValue& value) override { @@ -103,7 +106,8 @@ protected: , List(std::move(list)) , Item(item) , NewItem(newItem) - {} + { + } private: NUdf::TUnboxedValue GetListIterator() const final { @@ -136,7 +140,7 @@ protected: IComputationNode* const NewItem; }; - class TStreamValue : public TComputationValue<TStreamValue> { + class TStreamValue: public TComputationValue<TStreamValue> { public: using TBase = TComputationValue<TStreamValue>; @@ -162,7 +166,8 @@ protected: return NUdf::TUnboxedValuePod::Zero(); } - void Load(const NUdf::TStringRef&) final {} + void Load(const NUdf::TStringRef&) final { + } NUdf::EFetchStatus Fetch(NUdf::TUnboxedValue& result) final { const auto status = Stream.Fetch(Item->RefValue(CompCtx)); @@ -181,8 +186,11 @@ protected: }; TBaseMapWrapper(IComputationNode* list, IComputationExternalNode* item, IComputationNode* newItem) - : List(list), Item(item), NewItem(newItem) - {} + : List(list) + , Item(item) + , NewItem(newItem) + { + } #ifndef MKQL_DISABLE_CODEGEN Function* GenerateMapper(NYql::NCodegen::ICodegen& codegen, const TString& name) const { @@ -193,8 +201,9 @@ protected: MKQL_ENSURE(codegenItem, "Item must be codegenerator node."); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } const auto valueType = Type::getInt128Ty(context); const auto containerType = static_cast<Type*>(valueType); @@ -223,13 +232,9 @@ protected: const auto itemPtr = codegenItem->CreateRefValue(ctx, block); - const auto status = IsStream ? - CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::Fetch>(statusType, container, codegen, block, itemPtr): - CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::Next>(statusType, container, codegen, block, itemPtr); + const auto status = IsStream ? CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::Fetch>(statusType, container, codegen, block, itemPtr) : CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::Next>(statusType, container, codegen, block, itemPtr); - const auto icmp = IsStream ? - CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, status, ConstantInt::get(statusType, static_cast<ui32>(NUdf::EFetchStatus::Ok)), "cond", block): - CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, status, ConstantInt::getFalse(context), "cond", block); + const auto icmp = IsStream ? CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, status, ConstantInt::get(statusType, static_cast<ui32>(NUdf::EFetchStatus::Ok)), "cond", block) : CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, status, ConstantInt::getFalse(context), "cond", block); BranchInst::Create(done, good, icmp, block); block = good; @@ -256,18 +261,22 @@ protected: IComputationNode* const NewItem; }; -class TStreamMapWrapper : public TCustomValueCodegeneratorNode<TStreamMapWrapper>, private TBaseMapWrapper<true> { +class TStreamMapWrapper: public TCustomValueCodegeneratorNode<TStreamMapWrapper>, private TBaseMapWrapper<true> { typedef TCustomValueCodegeneratorNode<TStreamMapWrapper> TBaseComputation; typedef TBaseMapWrapper<true> TBaseWrapper; + public: TStreamMapWrapper(TComputationMutables& mutables, IComputationNode* list, IComputationExternalNode* item, IComputationNode* newItem) - : TBaseComputation(mutables), TBaseWrapper(list, item, newItem) - {} + : TBaseComputation(mutables) + , TBaseWrapper(list, item, newItem) + { + } NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const { #ifndef MKQL_DISABLE_CODEGEN - if (ctx.ExecuteLLVM && Map) + if (ctx.ExecuteLLVM && Map) { return ctx.HolderFactory.Create<TStreamCodegenValueStateless>(Map, &ctx, List->GetValue(ctx)); + } #endif return ctx.HolderFactory.Create<TStreamValue>(ctx, List->GetValue(ctx), Item, NewItem); } @@ -285,19 +294,23 @@ private: } void FinalizeFunctions(NYql::NCodegen::ICodegen& codegen) final { - if (MapFunc) + if (MapFunc) { Map = reinterpret_cast<TMapPtr>(codegen.GetPointerToFunction(MapFunc)); + } } #endif }; -class TListMapWrapper : public TBothWaysCodegeneratorNode<TListMapWrapper>, private TBaseMapWrapper<false> { +class TListMapWrapper: public TBothWaysCodegeneratorNode<TListMapWrapper>, private TBaseMapWrapper<false> { typedef TBothWaysCodegeneratorNode<TListMapWrapper> TBaseComputation; typedef TBaseMapWrapper<false> TBaseWrapper; + public: TListMapWrapper(TComputationMutables& mutables, IComputationNode* list, IComputationExternalNode* item, IComputationNode* newItem) - : TBaseComputation(mutables), TBaseWrapper(list, item, newItem) - {} + : TBaseComputation(mutables) + , TBaseWrapper(list, item, newItem) + { + } NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const { auto list = List->GetValue(ctx); @@ -345,9 +358,7 @@ public: const auto size = CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetListLength>(Type::getInt64Ty(context), list, ctx.Codegen, block); - const auto itemsPtr = *Stateless_ || ctx.AlwaysInline ? - new AllocaInst(elementsType, 0U, "items_ptr", &ctx.Func->getEntryBlock().back()): - new AllocaInst(elementsType, 0U, "items_ptr", block); + const auto itemsPtr = *Stateless_ || ctx.AlwaysInline ? new AllocaInst(elementsType, 0U, "items_ptr", &ctx.Func->getEntryBlock().back()) : new AllocaInst(elementsType, 0U, "items_ptr", block); const auto array = GenNewArray(ctx, size, itemsPtr, block); const auto items = new LoadInst(elementsType, itemsPtr, "items", block); @@ -391,7 +402,7 @@ public: const auto doFunc = ConstantInt::get(Type::getInt64Ty(context), GetMethodPtr<&TListMapWrapper::MakeLazyList>()); const auto ptrType = PointerType::getUnqual(StructType::get(context)); const auto self = CastInst::Create(Instruction::IntToPtr, ConstantInt::get(Type::getInt64Ty(context), uintptr_t(this)), ptrType, "self", block); - const auto funType = FunctionType::get(list->getType() , {self->getType(), ctx.Ctx->getType(), list->getType()}, false); + const auto funType = FunctionType::get(list->getType(), {self->getType(), ctx.Ctx->getType(), list->getType()}, false); const auto doFuncPtr = CastInst::Create(Instruction::IntToPtr, doFunc, PointerType::getUnqual(funType), "function", block); const auto value = CallInst::Create(funType, doFuncPtr, {self, ctx.Ctx, list}, "value", block); map->addIncoming(value, block); @@ -418,13 +429,14 @@ private: void FinalizeFunctions(NYql::NCodegen::ICodegen& codegen) final { TMutableCodegeneratorRootNode<TListMapWrapper>::FinalizeFunctions(codegen); - if (MapFunc) + if (MapFunc) { Map = reinterpret_cast<TMapPtr>(codegen.GetPointerToFunction(MapFunc)); + } } #endif }; -} +} // namespace IComputationNode* WrapMap(TCallable& callable, const TComputationNodeFactoryContext& ctx) { MKQL_ENSURE(callable.GetInputsCount() == 3, "Expected 3 args, got " << callable.GetInputsCount()); @@ -443,5 +455,5 @@ IComputationNode* WrapMap(TCallable& callable, const TComputationNodeFactoryCont THROW yexception() << "Expected flow, list or stream."; } -} -} +} // namespace NMiniKQL +} // namespace NKikimr |
