aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-romanov <Anton.Romanov@ydb.tech>2023-11-01 21:42:29 +0300
committera-romanov <Anton.Romanov@ydb.tech>2023-11-01 21:58:51 +0300
commitb5297acd9c76937bfee28428b340d571cee33a39 (patch)
tree5053ded61ac86da6ba0913d54260383cfc121bca
parente464f98c31ce1f93e5588e6bbc7c0e2c15cafb7e (diff)
downloadydb-b5297acd9c76937bfee28428b340d571cee33a39.tar.gz
YQL-17048 Get rid of SafeUnRefUnboxed for simplify generated llvm.
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_block_compress.cpp11
-rw-r--r--ydb/library/yql/minikql/comp_nodes/mkql_blocks.cpp40
-rw-r--r--ydb/library/yql/minikql/computation/mkql_block_impl.cpp4
-rw-r--r--ydb/library/yql/minikql/computation/mkql_block_impl.h2
4 files changed, 39 insertions, 18 deletions
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_block_compress.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_block_compress.cpp
index fcee52daed..f24b163376 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_block_compress.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_block_compress.cpp
@@ -260,7 +260,7 @@ public:
if (!s.Count) {
do if (!s.InputSize_) {
- s.Values.assign(s.Values.size(), NUdf::TUnboxedValuePod());
+ s.ClearValues();
switch (Flow_->FetchValues(ctx, fields)) {
case EFetchResult::Yield:
return EFetchResult::Yield;
@@ -382,9 +382,10 @@ public:
block = read;
- const auto valuesPtr = GetElementPtrInst::CreateInBounds(stateType, stateArg, { stateFields.This(), stateFields.GetPointer() }, "values_ptr", block);
- const auto values = new LoadInst(ptrValuesType, valuesPtr, "values", block);
- SafeUnRefUnboxed(values, ctx, block);
+ const auto clearFunc = ConstantInt::get(Type::getInt64Ty(context), GetMethodPtr(&TState::ClearValues));
+ const auto clearType = FunctionType::get(Type::getVoidTy(context), {statePtrType}, false);
+ const auto clearPtr = CastInst::Create(Instruction::IntToPtr, clearFunc, PointerType::getUnqual(clearType), "clear", block);
+ CallInst::Create(clearType, clearPtr, {stateArg}, "", block);
const auto getres = GetNodeValues(Flow_, ctx, block);
@@ -421,6 +422,8 @@ public:
block = save;
+ const auto valuesPtr = GetElementPtrInst::CreateInBounds(stateType, stateArg, { stateFields.This(), stateFields.GetPointer() }, "values_ptr", block);
+ const auto values = new LoadInst(ptrValuesType, valuesPtr, "values", block);
for (size_t idx = 0U; idx <= Types_.size(); ++idx) {
const auto pointer = GetElementPtrInst::CreateInBounds(arrayType, values, { ConstantInt::get(indexType, 0), ConstantInt::get(indexType, idx) }, "pointer", block);
const auto value = getres.second[idx < BitmapIndex_ ? idx : idx + 1U](ctx, block);
diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_blocks.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_blocks.cpp
index e038b23b45..b0130cca0f 100644
--- a/ydb/library/yql/minikql/comp_nodes/mkql_blocks.cpp
+++ b/ydb/library/yql/minikql/comp_nodes/mkql_blocks.cpp
@@ -585,9 +585,10 @@ public:
block = more;
- const auto valuesPtr = GetElementPtrInst::CreateInBounds(stateType, stateArg, { stateFields.This(), stateFields.GetPointer() }, "values_ptr", block);
- const auto values = new LoadInst(ptrValuesType, valuesPtr, "values", block);
- SafeUnRefUnboxed(values, ctx, block);
+ const auto clearFunc = ConstantInt::get(Type::getInt64Ty(context), GetMethodPtr(&TState::ClearValues));
+ const auto clearType = FunctionType::get(Type::getVoidTy(context), {statePtrType}, false);
+ const auto clearPtr = CastInst::Create(Instruction::IntToPtr, clearFunc, PointerType::getUnqual(clearType), "clear", block);
+ CallInst::Create(clearType, clearPtr, {stateArg}, "", block);
const auto getres = GetNodeValues(Flow_, ctx, block);
@@ -668,15 +669,11 @@ private:
std::vector<std::unique_ptr<IBlockReader>> Readers_;
std::vector<std::unique_ptr<IBlockItemConverter>> Converters_;
- TState(TMemoryUsageInfo* memInfo, TComputationContext& ctx, size_t wideFieldsIndex, const TVector<TType*>& types)
+ TState(TMemoryUsageInfo* memInfo, TComputationContext& ctx, const TVector<TType*>& types)
: TComputationValue(memInfo)
, Values_(types.size() + 1)
{
Pointer_ = Values_.data();
- auto**const fields = ctx.WideFields.data() + wideFieldsIndex;
- for (size_t i = 0; i < types.size() + 1; ++i) {
- fields[i] = &Values_[i];
- }
const auto& pgBuilder = ctx.Builder->GetPgBuilder();
for (size_t i = 0; i < types.size(); ++i) {
@@ -685,6 +682,10 @@ private:
}
}
+ void ClearValues() {
+ Values_.assign(Values_.size(), NUdf::TUnboxedValuePod());
+ }
+
NUdf::TUnboxedValuePod Get(const THolderFactory& holderFactory, size_t idx) const {
TBlockItem item;
if (const auto& datum = TArrowBlock::From(Values_[idx]).GetDatum(); datum.is_scalar()) {
@@ -746,12 +747,20 @@ private:
}
void MakeState(TComputationContext& ctx, NUdf::TUnboxedValue& state) const {
- state = ctx.HolderFactory.Create<TState>(ctx, WideFieldsIndex_, Types_);
+ state = ctx.HolderFactory.Create<TState>(ctx, Types_);
}
TState& GetState(NUdf::TUnboxedValue& state, TComputationContext& ctx) const {
- if (!state.HasValue())
+ if (!state.HasValue()) {
MakeState(ctx, state);
+
+ const auto s = static_cast<TState*>(state.AsBoxed().Get());
+ auto**const fields = ctx.WideFields.data() + WideFieldsIndex_;
+ for (size_t i = 0; i <= Types_.size(); ++i) {
+ fields[i] = &s->Values_[i];
+ }
+ return *s;
+ }
return *static_cast<TState*>(state.AsBoxed().Get());
}
@@ -949,8 +958,8 @@ public:
EFetchResult DoCalculate(NUdf::TUnboxedValue& state, TComputationContext& ctx, NUdf::TUnboxedValue*const* output) const {
auto& s = GetState(state, ctx);
if (!s.Count) {
- s.Values.assign(s.Values.size(), NUdf::TUnboxedValuePod());
const auto fields = ctx.WideFields.data() + WideFieldsIndex_;
+ s.ClearValues();
if (const auto result = Flow_->FetchValues(ctx, fields); result != EFetchResult::One)
return result;
s.FillArrays();
@@ -1024,9 +1033,10 @@ public:
block = read;
- const auto valuesPtr = GetElementPtrInst::CreateInBounds(stateType, stateArg, { stateFields.This(), stateFields.GetPointer() }, "values_ptr", block);
- const auto values = new LoadInst(ptrValuesType, valuesPtr, "values", block);
- SafeUnRefUnboxed(values, ctx, block);
+ const auto clearFunc = ConstantInt::get(Type::getInt64Ty(context), GetMethodPtr(&TBlockState::ClearValues));
+ const auto clearType = FunctionType::get(Type::getVoidTy(context), {statePtrType}, false);
+ const auto clearPtr = CastInst::Create(Instruction::IntToPtr, clearFunc, PointerType::getUnqual(clearType), "clear", block);
+ CallInst::Create(clearType, clearPtr, {stateArg}, "", block);
const auto getres = GetNodeValues(Flow_, ctx, block);
@@ -1039,6 +1049,8 @@ public:
block = work;
+ const auto valuesPtr = GetElementPtrInst::CreateInBounds(stateType, stateArg, { stateFields.This(), stateFields.GetPointer() }, "values_ptr", block);
+ const auto values = new LoadInst(ptrValuesType, valuesPtr, "values", block);
Value* array = UndefValue::get(arrayType);
for (auto idx = 0U; idx < getres.second.size(); ++idx) {
const auto value = getres.second[idx](ctx, block);
diff --git a/ydb/library/yql/minikql/computation/mkql_block_impl.cpp b/ydb/library/yql/minikql/computation/mkql_block_impl.cpp
index 263f244638..7566f1db0c 100644
--- a/ydb/library/yql/minikql/computation/mkql_block_impl.cpp
+++ b/ydb/library/yql/minikql/computation/mkql_block_impl.cpp
@@ -271,6 +271,10 @@ TBlockState::TBlockState(TMemoryUsageInfo* memInfo, size_t width)
Pointer_ = Values.data();
}
+void TBlockState::ClearValues() {
+ Values.assign(Values.size(), NUdf::TUnboxedValuePod());
+}
+
void TBlockState::FillArrays() {
auto& counterDatum = TArrowBlock::From(Values.back()).GetDatum();
MKQL_ENSURE(counterDatum.is_scalar(), "Unexpected block length type (expecting scalar)");
diff --git a/ydb/library/yql/minikql/computation/mkql_block_impl.h b/ydb/library/yql/minikql/computation/mkql_block_impl.h
index b081d9f573..c710dbfd8c 100644
--- a/ydb/library/yql/minikql/computation/mkql_block_impl.h
+++ b/ydb/library/yql/minikql/computation/mkql_block_impl.h
@@ -103,6 +103,8 @@ struct TBlockState : public TComputationValue<TBlockState> {
TBlockState(TMemoryUsageInfo* memInfo, size_t width);
+ void ClearValues();
+
void FillArrays();
ui64 Slice();