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/computation/mkql_computation_node_codegen.cpp | |
| parent | d58a8990d353b051c27e1069141117fdfde64358 (diff) | |
YQL-20086 minikql
commit_hash:e96f7390db5fcbe7e9f64f898141a263ad522daa
Diffstat (limited to 'yql/essentials/minikql/computation/mkql_computation_node_codegen.cpp')
| -rw-r--r-- | yql/essentials/minikql/computation/mkql_computation_node_codegen.cpp | 782 |
1 files changed, 510 insertions, 272 deletions
diff --git a/yql/essentials/minikql/computation/mkql_computation_node_codegen.cpp b/yql/essentials/minikql/computation/mkql_computation_node_codegen.cpp index e0bbb759c2e..e98493803f8 100644 --- a/yql/essentials/minikql/computation/mkql_computation_node_codegen.cpp +++ b/yql/essentials/minikql/computation/mkql_computation_node_codegen.cpp @@ -9,7 +9,7 @@ #ifndef MKQL_DISABLE_CODEGEN -extern "C" void DeleteBoxed(NKikimr::NUdf::IBoxedValue *const boxed) { +extern "C" void DeleteBoxed(NKikimr::NUdf::IBoxedValue* const boxed) { delete boxed; } @@ -25,39 +25,33 @@ constexpr bool EnableStaticRefcount = true; using namespace llvm; -Type* GetStringRefType(LLVMContext &context) { - const auto stringRefType = StructType::get(context, { - Type::getInt8PtrTy(context), - Type::getInt32Ty(context), - Type::getInt32Ty(context) - }); +Type* GetStringRefType(LLVMContext& context) { + const auto stringRefType = StructType::get(context, {Type::getInt8PtrTy(context), + Type::getInt32Ty(context), + Type::getInt32Ty(context)}); return stringRefType; } -Type* GetSourcePosType(LLVMContext &context) { - const auto sourcePosType = StructType::get(context, { - Type::getInt32Ty(context), - Type::getInt32Ty(context), - GetStringRefType(context) - }); +Type* GetSourcePosType(LLVMContext& context) { + const auto sourcePosType = StructType::get(context, {Type::getInt32Ty(context), + Type::getInt32Ty(context), + GetStringRefType(context)}); return sourcePosType; } -Type* GetCompContextType(LLVMContext &context) { +Type* GetCompContextType(LLVMContext& context) { const auto ptrValueType = PointerType::getUnqual(Type::getInt128Ty(context)); const auto structPtrType = PointerType::getUnqual(StructType::get(context)); const auto sourcePosType = GetSourcePosType(context); - return StructType::get(context, { - structPtrType, // factory - structPtrType, // stats - ptrValueType, // mutables - structPtrType, // builder - Type::getFloatTy(context), // adjustor - Type::getInt32Ty(context), // rsscounter - PointerType::getUnqual(sourcePosType) - }); + return StructType::get(context, {structPtrType, // factory + structPtrType, // stats + ptrValueType, // mutables + structPtrType, // builder + Type::getFloatTy(context), // adjustor + Type::getInt32Ty(context), // rsscounter + PointerType::getUnqual(sourcePosType)}); } Value* TCodegenContext::GetFactory() const { @@ -66,10 +60,14 @@ Value* TCodegenContext::GetFactory() const { const auto indexType = Type::getInt32Ty(context); const auto ptrType = PointerType::getUnqual(StructType::get(context)); if (Func->getEntryBlock().empty()) { - const auto ptr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 0)}, "factory_ptr", &Func->getEntryBlock()); + const auto ptr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 0)}, "factory_ptr", &Func->getEntryBlock()); const_cast<Value*&>(Factory) = new LoadInst(ptrType, ptr, "factory", &Func->getEntryBlock()); } else { - const auto ptr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 0)}, "factory_ptr", &Func->getEntryBlock().front()); + const auto ptr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 0)}, "factory_ptr", &Func->getEntryBlock().front()); const_cast<Value*&>(Factory) = new LoadInst(ptrType, ptr, "factory", &Func->getEntryBlock().back()); } } @@ -82,10 +80,14 @@ Value* TCodegenContext::GetStat() const { const auto indexType = Type::getInt32Ty(context); const auto ptrType = PointerType::getUnqual(StructType::get(context)); if (Func->getEntryBlock().empty()) { - const auto ptr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 1)}, "stat_ptr", &Func->getEntryBlock()); + const auto ptr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 1)}, "stat_ptr", &Func->getEntryBlock()); const_cast<Value*&>(Stat) = new LoadInst(ptrType, ptr, "stat", &Func->getEntryBlock()); } else { - const auto ptr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 1)}, "stat_ptr", &Func->getEntryBlock().front()); + const auto ptr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 1)}, "stat_ptr", &Func->getEntryBlock().front()); const_cast<Value*&>(Stat) = new LoadInst(ptrType, ptr, "stat", &Func->getEntryBlock().back()); } } @@ -98,10 +100,14 @@ Value* TCodegenContext::GetMutables() const { const auto indexType = Type::getInt32Ty(context); const auto ptrType = PointerType::getUnqual(Type::getInt128Ty(context)); if (Func->getEntryBlock().empty()) { - const auto ptr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 2)}, "mutables_ptr", &Func->getEntryBlock()); + const auto ptr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 2)}, "mutables_ptr", &Func->getEntryBlock()); const_cast<Value*&>(Mutables) = new LoadInst(ptrType, ptr, "mutables", &Func->getEntryBlock()); } else { - const auto ptr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 2)}, "mutables_ptr", &Func->getEntryBlock().front()); + const auto ptr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 2)}, "mutables_ptr", &Func->getEntryBlock().front()); const_cast<Value*&>(Mutables) = new LoadInst(ptrType, ptr, "mutables", &Func->getEntryBlock().back()); } } @@ -114,10 +120,14 @@ Value* TCodegenContext::GetBuilder() const { const auto indexType = Type::getInt32Ty(context); const auto ptrType = PointerType::getUnqual(StructType::get(context)); if (Func->getEntryBlock().empty()) { - const auto ptr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 3)}, "builder_ptr", &Func->getEntryBlock()); + const auto ptr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 3)}, "builder_ptr", &Func->getEntryBlock()); const_cast<Value*&>(Builder) = new LoadInst(ptrType, ptr, "builder", &Func->getEntryBlock()); } else { - const auto ptr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 3)}, "builder_ptr", &Func->getEntryBlock().front()); + const auto ptr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 3)}, "builder_ptr", &Func->getEntryBlock().front()); const_cast<Value*&>(Builder) = new LoadInst(ptrType, ptr, "builder", &Func->getEntryBlock().back()); } } @@ -125,10 +135,11 @@ Value* TCodegenContext::GetBuilder() const { } Function* GenerateCompareFunction(NYql::NCodegen::ICodegen& codegen, const TString& name, IComputationExternalNode* left, - IComputationExternalNode* right, IComputationNode* compare) { + IComputationExternalNode* right, IComputationNode* compare) { auto& module = codegen.GetModule(); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } const auto codegenLeft = dynamic_cast<ICodegeneratorExternalNode*>(left); const auto codegenRight = dynamic_cast<ICodegeneratorExternalNode*>(right); @@ -178,16 +189,23 @@ Function* GenerateCompareFunction(NYql::NCodegen::ICodegen& codegen, const TStri return ctx.Func; } -Value* GetterFor(NUdf::EDataSlot slot, Value* value, LLVMContext &context, BasicBlock* block) { +Value* GetterFor(NUdf::EDataSlot slot, Value* value, LLVMContext& context, BasicBlock* block) { switch (slot) { - case NUdf::EDataSlot::Bool: return GetterFor<bool>(value, context, block); - case NUdf::EDataSlot::Decimal: return GetterForInt128(value, block); - case NUdf::EDataSlot::Float: return GetterFor<float>(value, context, block); - case NUdf::EDataSlot::Double: return GetterFor<double>(value, context, block); - default: break; + case NUdf::EDataSlot::Bool: + return GetterFor<bool>(value, context, block); + case NUdf::EDataSlot::Decimal: + return GetterForInt128(value, block); + case NUdf::EDataSlot::Float: + return GetterFor<float>(value, context, block); + case NUdf::EDataSlot::Double: + return GetterFor<double>(value, context, block); + default: + break; } - const auto trunc = CastInst::Create(Instruction::Trunc, value, IntegerType::get(context, NUdf::GetDataTypeInfo(slot).FixedSize << 3U), "trunc", block); + const auto trunc = CastInst::Create( + Instruction::Trunc, value, + IntegerType::get(context, NUdf::GetDataTypeInfo(slot).FixedSize << 3U), "trunc", block); return trunc; } @@ -201,33 +219,38 @@ Value* GetMarkFromUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock* const auto type = StructType::get(context, {PointerType::getUnqual(StructType::get(context)), ArrayType::get(type8, 8U)}); const auto cast = CastInst::Create(Instruction::BitCast, value, PointerType::getUnqual(type), "cast", block); const auto type32 = Type::getInt32Ty(context); - const auto metaptr = GetElementPtrInst::CreateInBounds(type, cast, {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1), ConstantInt::get(type32, 7)}, "metaptr", block); + const auto metaptr = GetElementPtrInst::CreateInBounds( + type, cast, + {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1), ConstantInt::get(type32, 7)}, "metaptr", block); const auto meta = new LoadInst(type8, metaptr, "meta", block); const auto mark = BinaryOperator::CreateAnd(meta, ConstantInt::get(meta->getType(), 3), "mark", block); return mark; } else { - const auto lshr = BinaryOperator::CreateLShr(value, ConstantInt::get(value->getType(), 120), "lshr", block); + const auto lshr = BinaryOperator::CreateLShr(value, ConstantInt::get(value->getType(), 120), "lshr", block); const auto meta = CastInst::Create(Instruction::Trunc, lshr, type8, "meta", block); const auto mark = BinaryOperator::CreateAnd(ConstantInt::get(meta->getType(), 3), meta, "mark", block); return mark; } - } -template<bool BoxedOrString> -std::pair<Value*,Type*> GetPointerFromUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock* block) { +template <bool BoxedOrString> +std::pair<Value*, Type*> GetPointerFromUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock* block) { auto& context = ctx.Codegen.GetContext(); const auto type32 = Type::getInt32Ty(context); const auto type64 = Type::getInt64Ty(context); - const auto elemType = BoxedOrString ? - StructType::get(context, {PointerType::getUnqual(StructType::get(context)), type32, Type::getInt16Ty(context)}): - StructType::get(context, {type32, type32, type32, type32}); + const auto elemType = BoxedOrString + ? StructType::get(context, + {PointerType::getUnqual(StructType::get(context)), type32, Type::getInt16Ty(context)}) + : StructType::get(context, + {type32, type32, type32, type32}); const auto type = PointerType::getUnqual(elemType); if (value->getType()->isPointerTy()) { const auto strType = StructType::get(context, {type, type64}); const auto cast = CastInst::Create(Instruction::BitCast, value, PointerType::getUnqual(strType), "cast", block); - const auto ptr = GetElementPtrInst::CreateInBounds(strType, cast, {ConstantInt::get(type32, 0), ConstantInt::get(type32, 0)}, "ptr", block); + const auto ptr = GetElementPtrInst::CreateInBounds( + strType, cast, + {ConstantInt::get(type32, 0), ConstantInt::get(type32, 0)}, "ptr", block); const auto pointer = new LoadInst(type, ptr, "pointer", block); return {pointer, elemType}; } else { @@ -258,22 +281,31 @@ Value* GenEqualsFunction<false>(NUdf::EDataSlot slot, Value* lv, Value* rv, TCod const auto& info = NUdf::GetDataTypeInfo(slot); - if ((info.Features & NUdf::EDataTypeFeatures::CommonType) && (info.Features & NUdf::EDataTypeFeatures::StringType || NUdf::EDataSlot::Uuid == slot || NUdf::EDataSlot::DyNumber == slot)) { + if ((info.Features & NUdf::EDataTypeFeatures::CommonType) && + (info.Features & NUdf::EDataTypeFeatures::StringType || + NUdf::EDataSlot::Uuid == slot || + NUdf::EDataSlot::DyNumber == slot)) { return CallBinaryUnboxedValueFunction<&MyEquteStrings>(Type::getInt1Ty(context), lv, rv, ctx.Codegen, block); } const auto lhs = GetterFor(slot, lv, context, block); const auto rhs = GetterFor(slot, rv, context, block); - if (info.Features & (NUdf::EDataTypeFeatures::IntegralType | NUdf::EDataTypeFeatures::DateType | NUdf::EDataTypeFeatures::TimeIntervalType | NUdf::EDataTypeFeatures::DecimalType) || NUdf::EDataSlot::Bool == slot) { + if (info.Features & (NUdf::EDataTypeFeatures::IntegralType | + NUdf::EDataTypeFeatures::DateType | + NUdf::EDataTypeFeatures::TimeIntervalType | + NUdf::EDataTypeFeatures::DecimalType) || + NUdf::EDataSlot::Bool == slot) { const auto equal = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, lhs, rhs, "equal", block); return equal; } if (info.Features & NUdf::EDataTypeFeatures::FloatType) { const auto ueq = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_UEQ, lhs, rhs, "equals", block); - const auto lord = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_ORD, ConstantFP::get(lhs->getType(), 0.0), lhs, "lord", block); - const auto runo = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_UNO, ConstantFP::get(rhs->getType(), 0.0), rhs, "runo", block); + const auto lord = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_ORD, + ConstantFP::get(lhs->getType(), 0.0), lhs, "lord", block); + const auto runo = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_UNO, + ConstantFP::get(rhs->getType(), 0.0), rhs, "runo", block); const auto once = BinaryOperator::CreateXor(lord, runo, "xor", block); return BinaryOperator::CreateAnd(ueq, once, "and", block); } @@ -337,7 +369,10 @@ Value* GenCompareFunction<false>(NUdf::EDataSlot slot, Value* lv, Value* rv, TCo const auto& info = NUdf::GetDataTypeInfo(slot); - if ((info.Features & NUdf::EDataTypeFeatures::CommonType) && (info.Features & NUdf::EDataTypeFeatures::StringType || NUdf::EDataSlot::Uuid == slot || NUdf::EDataSlot::DyNumber == slot)) { + if ((info.Features & NUdf::EDataTypeFeatures::CommonType) && + (info.Features & NUdf::EDataTypeFeatures::StringType || + NUdf::EDataSlot::Uuid == slot || + NUdf::EDataSlot::DyNumber == slot)) { return CallBinaryUnboxedValueFunction<&MyCompareStrings>(Type::getInt32Ty(context), lv, rv, ctx.Codegen, block); } @@ -361,8 +396,10 @@ Value* GenCompareFunction<false>(NUdf::EDataSlot slot, Value* lv, Value* rv, TCo BranchInst::Create(more, next, uno, block); block = more; - const auto luno = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_UNO, ConstantFP::get(lhs->getType(), 0.0), lhs, "luno", block); - const auto runo = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_UNO, ConstantFP::get(rhs->getType(), 0.0), rhs, "runo", block); + const auto luno = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_UNO, + ConstantFP::get(lhs->getType(), 0.0), lhs, "luno", block); + const auto runo = CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_UNO, + ConstantFP::get(rhs->getType(), 0.0), rhs, "runo", block); const auto once = BinaryOperator::CreateXor(luno, runo, "xor", block); const auto left = SelectInst::Create(luno, ConstantInt::get(resultType, 1), ConstantInt::get(resultType, -1), "left", block); @@ -374,9 +411,9 @@ Value* GenCompareFunction<false>(NUdf::EDataSlot slot, Value* lv, Value* rv, TCo block = next; } - const auto equals = info.Features & NUdf::EDataTypeFeatures::FloatType ? - CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_OEQ, lhs, rhs, "equals", block): - CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, lhs, rhs, "equals", block); + const auto equals = info.Features & NUdf::EDataTypeFeatures::FloatType + ? CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_OEQ, lhs, rhs, "equals", block) + : CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, lhs, rhs, "equals", block); if (info.Features & NUdf::EDataTypeFeatures::TzDateType) { const auto more = BasicBlock::Create(context, "more", ctx.Func); @@ -404,13 +441,17 @@ Value* GenCompareFunction<false>(NUdf::EDataSlot slot, Value* lv, Value* rv, TCo block = test; - const auto less = info.Features & NUdf::EDataTypeFeatures::FloatType ? - CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_OLT, lhs, rhs, "less", block): // float - info.Features & (NUdf::EDataTypeFeatures::SignedIntegralType | NUdf::EDataTypeFeatures::TimeIntervalType | NUdf::EDataTypeFeatures::DecimalType) ? - CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, lhs, rhs, "less", block): // signed - info.Features & (NUdf::EDataTypeFeatures::UnsignedIntegralType | NUdf::EDataTypeFeatures::DateType | NUdf::EDataTypeFeatures::TzDateType) ? - CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_ULT, lhs, rhs, "less", block): // unsigned - rhs; // bool + const auto less = info.Features & NUdf::EDataTypeFeatures::FloatType // float + ? CmpInst::Create(Instruction::FCmp, FCmpInst::FCMP_OLT, lhs, rhs, "less", block) + : info.Features & (NUdf::EDataTypeFeatures::SignedIntegralType | // signed + NUdf::EDataTypeFeatures::TimeIntervalType | + NUdf::EDataTypeFeatures::DecimalType) + ? CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, lhs, rhs, "less", block) + : info.Features & (NUdf::EDataTypeFeatures::UnsignedIntegralType | // unsigned + NUdf::EDataTypeFeatures::DateType | + NUdf::EDataTypeFeatures::TzDateType) + ? CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_ULT, lhs, rhs, "less", block) + : rhs; // bool const auto out = SelectInst::Create(less, ConstantInt::get(resultType, -1), ConstantInt::get(resultType, 1), "out", block); res->addIncoming(out, block); @@ -462,35 +503,37 @@ Value* GenCompareFunction<true>(NUdf::EDataSlot slot, Value* lv, Value* rv, TCod } Value* GenCompareFunction(NUdf::EDataSlot slot, bool isOptional, Value* lv, Value* rv, TCodegenContext& ctx, BasicBlock*& block) { - return isOptional ? GenCompareFunction<true>(slot, lv, rv, ctx, block) : GenCompareFunction<false>(slot, lv, rv, ctx, block); + return isOptional + ? GenCompareFunction<true>(slot, lv, rv, ctx, block) + : GenCompareFunction<false>(slot, lv, rv, ctx, block); } Value* GenCombineHashes(Value* first, Value* second, BasicBlock* block) { -// key += ~(key << 32); + // key += ~(key << 32); const auto x01 = BinaryOperator::CreateShl(first, ConstantInt::get(first->getType(), 32), "x01", block); const auto x02 = BinaryOperator::CreateXor(x01, ConstantInt::get(x01->getType(), ~0), "x02", block); const auto x03 = BinaryOperator::CreateAdd(x02, first, "x03", block); -// key ^= (key >> 22); + // key ^= (key >> 22); const auto x04 = BinaryOperator::CreateLShr(x03, ConstantInt::get(x03->getType(), 22), "x04", block); const auto x05 = BinaryOperator::CreateXor(x04, x03, "x05", block); -// key += ~(key << 13); + // key += ~(key << 13); const auto x06 = BinaryOperator::CreateShl(x05, ConstantInt::get(x05->getType(), 13), "x06", block); const auto x07 = BinaryOperator::CreateXor(x06, ConstantInt::get(x06->getType(), ~0), "x07", block); const auto x08 = BinaryOperator::CreateAdd(x05, x07, "x08", block); -// key ^= (key >> 8); + // key ^= (key >> 8); const auto x09 = BinaryOperator::CreateLShr(x08, ConstantInt::get(x08->getType(), 8), "x09", block); const auto x10 = BinaryOperator::CreateXor(x08, x09, "x10", block); -// key += (key << 3); + // key += (key << 3); const auto x11 = BinaryOperator::CreateShl(x10, ConstantInt::get(x10->getType(), 3), "x11", block); const auto x12 = BinaryOperator::CreateAdd(x10, x11, "x12", block); -// key ^= (key >> 15); + // key ^= (key >> 15); const auto x13 = BinaryOperator::CreateLShr(x12, ConstantInt::get(x12->getType(), 15), "x13", block); const auto x14 = BinaryOperator::CreateXor(x13, x12, "x14", block); -// key += ~(key << 27); + // key += ~(key << 27); const auto x15 = BinaryOperator::CreateShl(x14, ConstantInt::get(x14->getType(), 27), "x15", block); const auto x16 = BinaryOperator::CreateXor(x15, ConstantInt::get(x15->getType(), ~0), "x16", block); const auto x17 = BinaryOperator::CreateAdd(x14, x16, "x17", block); -// key ^= (key >> 31); + // key ^= (key >> 31); const auto x18 = BinaryOperator::CreateLShr(x17, ConstantInt::get(x17->getType(), 31), "x18", block); const auto x19 = BinaryOperator::CreateXor(x17, x18, "x19", block); @@ -506,14 +549,20 @@ Value* GenHashFunction<false>(NUdf::EDataSlot slot, Value* value, TCodegenContex const auto& info = NUdf::GetDataTypeInfo(slot); - if ((info.Features & NUdf::EDataTypeFeatures::CommonType) && (info.Features & NUdf::EDataTypeFeatures::StringType || NUdf::EDataSlot::Uuid == slot || NUdf::EDataSlot::DyNumber == slot)) { + if ((info.Features & NUdf::EDataTypeFeatures::CommonType) && + (info.Features & NUdf::EDataTypeFeatures::StringType || + NUdf::EDataSlot::Uuid == slot || + NUdf::EDataSlot::DyNumber == slot)) { return CallUnaryUnboxedValueFunction<&MyHashString>(Type::getInt64Ty(context), value, ctx.Codegen, block); } const auto val = GetterFor(slot, value, context, block); const auto hashType = Type::getInt64Ty(context); - if (info.Features & (NUdf::EDataTypeFeatures::IntegralType | NUdf::EDataTypeFeatures::DateType | NUdf::EDataTypeFeatures::TimeIntervalType) || NUdf::EDataSlot::Bool == slot) { + if (info.Features & (NUdf::EDataTypeFeatures::IntegralType | + NUdf::EDataTypeFeatures::DateType | + NUdf::EDataTypeFeatures::TimeIntervalType) || + NUdf::EDataSlot::Bool == slot) { if (val->getType() == hashType) { return val; } @@ -591,12 +640,13 @@ Value* LoadIfPointer(Value* value, Type* itemType, BasicBlock* block) { return value->getType()->isPointerTy() ? new LoadInst(itemType, value, "load_value", block) : value; } -} +} // namespace Function* GenerateEqualsFunction(NYql::NCodegen::ICodegen& codegen, const TString& name, bool isTuple, const TKeyTypes& types) { auto& module = codegen.GetModule(); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } auto& context = codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); @@ -631,11 +681,17 @@ Function* GenerateEqualsFunction(NYql::NCodegen::ICodegen& codegen, const TStrin const auto elementsType = ArrayType::get(valueType, types.size()); const auto elementsPtrType = PointerType::getUnqual(elementsType); - const auto elementsPtrOne = CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetElements>(elementsPtrType, lv, ctx.Codegen, block); - const auto elementsPtrTwo = CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetElements>(elementsPtrType, rv, ctx.Codegen, block); - - const auto goodOne = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, elementsPtrOne, ConstantPointerNull::get(elementsPtrType), "good_one", block); - const auto goodTwo = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, elementsPtrTwo, ConstantPointerNull::get(elementsPtrType), "good_two", block); + const auto elementsPtrOne = CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetElements>( + elementsPtrType, lv, ctx.Codegen, block); + const auto elementsPtrTwo = CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetElements>( + elementsPtrType, rv, ctx.Codegen, block); + + const auto goodOne = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, elementsPtrOne, + ConstantPointerNull::get(elementsPtrType), "good_one", block); + const auto goodTwo = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, elementsPtrTwo, + ConstantPointerNull::get(elementsPtrType), "good_two", block); const auto good = BinaryOperator::CreateAnd(goodOne, goodTwo, "good", block); BranchInst::Create(fast, slow, good, block); @@ -677,8 +733,12 @@ Function* GenerateEqualsFunction(NYql::NCodegen::ICodegen& codegen, const TStrin const auto indexType = Type::getInt32Ty(context); for (ui32 i = 0U; i < last; ++i) { - CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetElement>(elementOne, lv, ctx.Codegen, block, ConstantInt::get(indexType, i)); - CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetElement>(elementTwo, rv, ctx.Codegen, block, ConstantInt::get(indexType, i)); + CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetElement>( + elementOne, lv, ctx.Codegen, block, ConstantInt::get(indexType, i)); + CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetElement>( + elementTwo, rv, ctx.Codegen, block, ConstantInt::get(indexType, i)); const auto nextOne = new LoadInst(valueType, elementOne, (TString("next_one_") += ToString(i)).c_str(), block); const auto nextTwo = new LoadInst(valueType, elementTwo, (TString("next_two_") += ToString(i)).c_str(), block); @@ -696,8 +756,12 @@ Function* GenerateEqualsFunction(NYql::NCodegen::ICodegen& codegen, const TStrin block = step; } - CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetElement>(elementOne, lv, ctx.Codegen, block, ConstantInt::get(indexType, last)); - CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetElement>(elementTwo, rv, ctx.Codegen, block, ConstantInt::get(indexType, last)); + CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetElement>( + elementOne, lv, ctx.Codegen, block, ConstantInt::get(indexType, last)); + CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetElement>( + elementTwo, rv, ctx.Codegen, block, ConstantInt::get(indexType, last)); const auto backOne = new LoadInst(valueType, elementOne, "back_one", block); const auto backTwo = new LoadInst(valueType, elementTwo, "back_two", block); @@ -724,8 +788,9 @@ Function* GenerateEqualsFunction(NYql::NCodegen::ICodegen& codegen, const TStrin Function* GenerateHashFunction(NYql::NCodegen::ICodegen& codegen, const TString& name, bool isTuple, const TKeyTypes& types) { auto& module = codegen.GetModule(); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } auto& context = codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); @@ -756,9 +821,12 @@ Function* GenerateHashFunction(NYql::NCodegen::ICodegen& codegen, const TString& const auto elementsType = ArrayType::get(valueType, types.size()); const auto elementsPtrType = PointerType::getUnqual(elementsType); - const auto elementsPtr = CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetElements>(elementsPtrType, arg, ctx.Codegen, block); + const auto elementsPtr = CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetElements>( + elementsPtrType, arg, ctx.Codegen, block); - const auto null = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, elementsPtr, ConstantPointerNull::get(elementsPtrType), "null", block); + const auto null = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, elementsPtr, + ConstantPointerNull::get(elementsPtrType), "null", block); BranchInst::Create(slow, fast, null, block); @@ -788,7 +856,9 @@ Function* GenerateHashFunction(NYql::NCodegen::ICodegen& codegen, const TString& auto result = static_cast<Value*>(ConstantInt::get(returnType, 0)); for (auto i = 0U; i < types.size(); ++i) { - CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetElement>(element, arg, ctx.Codegen, block, ConstantInt::get(Type::getInt32Ty(context), i)); + CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetElement>( + element, arg, ctx.Codegen, block, ConstantInt::get(Type::getInt32Ty(context), i)); const auto next = new LoadInst(valueType, element, (TString("next_") += ToString(i)).c_str(), block); if (NUdf::GetDataTypeInfo(types[i].first).Features & NUdf::EDataTypeFeatures::StringType) { @@ -813,8 +883,9 @@ Function* GenerateHashFunction(NYql::NCodegen::ICodegen& codegen, const TString& Function* GenerateEqualsFunction(NYql::NCodegen::ICodegen& codegen, const TString& name, const TKeyTypes& types) { auto& module = codegen.GetModule(); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } auto& context = codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); @@ -874,8 +945,9 @@ Function* GenerateEqualsFunction(NYql::NCodegen::ICodegen& codegen, const TStrin Function* GenerateHashFunction(NYql::NCodegen::ICodegen& codegen, const TString& name, const TKeyTypes& types) { auto& module = codegen.GetModule(); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } auto& context = codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); @@ -925,8 +997,9 @@ Function* GenerateHashFunction(NYql::NCodegen::ICodegen& codegen, const TString& Function* GenerateCompareFunction(NYql::NCodegen::ICodegen& codegen, const TString& name, const TKeyTypes& types) { auto& module = codegen.GetModule(); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } auto& context = codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); @@ -971,7 +1044,8 @@ Function* GenerateCompareFunction(NYql::NCodegen::ICodegen& codegen, const TStri const auto step = BasicBlock::Create(context, (TString("step_") += ToString(i)).c_str(), ctx.Func); const auto test = GenCompareFunction(types[i].first, types[i].second, nextOne, nextTwo, ctx, block); - const auto skip = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, zero, test, (TString("skip_") += ToString(i)).c_str(), block); + const auto skip = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, zero, test, + (TString("skip_") += ToString(i)).c_str(), block); BranchInst::Create(step, exit, skip, block); @@ -990,14 +1064,18 @@ Function* GenerateCompareFunction(NYql::NCodegen::ICodegen& codegen, const TStri return ctx.Func; } -void GenInvalidate(const TCodegenContext& ctx, const std::vector<std::pair<ui32, EValueRepresentation>>& invalidationSet, BasicBlock*& block) { +void GenInvalidate(const TCodegenContext& ctx, + const std::vector<std::pair<ui32, EValueRepresentation>>& invalidationSet, + BasicBlock*& block) { auto& context = ctx.Codegen.GetContext(); const auto indexType = Type::getInt32Ty(context); const auto valueType = Type::getInt128Ty(context); const auto values = ctx.GetMutables(); for (const auto& index : invalidationSet) { - const auto invPtr = GetElementPtrInst::CreateInBounds(valueType, values, {ConstantInt::get(indexType, index.first)}, "inv_ptr", block); + const auto invPtr = GetElementPtrInst::CreateInBounds( + valueType, values, + {ConstantInt::get(indexType, index.first)}, "inv_ptr", block); ValueUnRef(index.second, invPtr, ctx, block); new StoreInst(GetInvalid(context), invPtr, block); } @@ -1005,29 +1083,35 @@ void GenInvalidate(const TCodegenContext& ctx, const std::vector<std::pair<ui32, TUnboxedImmutableCodegeneratorNode::TUnboxedImmutableCodegeneratorNode(TMemoryUsageInfo* memInfo, NUdf::TUnboxedValue&& value) : TUnboxedImmutableComputationNode(memInfo, std::move(value)) -{} +{ +} Value* TUnboxedImmutableCodegeneratorNode::CreateGetValue(const TCodegenContext& ctx, BasicBlock*&) const { - return ConstantInt::get(Type::getInt128Ty(ctx.Codegen.GetContext()), APInt(128, 2, reinterpret_cast<const uint64_t*>(&UnboxedValue_))); + return ConstantInt::get( + Type::getInt128Ty(ctx.Codegen.GetContext()), APInt(128, 2, reinterpret_cast<const uint64_t*>(&UnboxedValue_))); } TExternalCodegeneratorNode::TExternalCodegeneratorNode(TComputationMutables& mutables, EValueRepresentation kind) : TExternalComputationNode(mutables, kind) -{} +{ +} TExternalCodegeneratorRootNode::TExternalCodegeneratorRootNode(TComputationMutables& mutables, EValueRepresentation kind) : TExternalCodegeneratorNode(mutables, kind) -{} +{ +} NUdf::TUnboxedValue TExternalCodegeneratorRootNode::GetValue(TComputationContext& compCtx) const { - if (compCtx.ExecuteLLVM && GetFunction) + if (compCtx.ExecuteLLVM && GetFunction) { return GetFunction(&compCtx); + } return TExternalComputationNode::GetValue(compCtx); } void TExternalCodegeneratorRootNode::SetValue(TComputationContext& compCtx, NUdf::TUnboxedValue&& newValue) const { - if (compCtx.ExecuteLLVM && SetFunction) + if (compCtx.ExecuteLLVM && SetFunction) { return SetFunction(&compCtx, newValue.Release()); + } TExternalComputationNode::SetValue(compCtx, std::move(newValue)); } @@ -1039,11 +1123,13 @@ TString TExternalCodegeneratorRootNode::MakeName(const TString& method) const { } void TExternalCodegeneratorRootNode::FinalizeFunctions(NYql::NCodegen::ICodegen& codegen) { - if (GetValueFunc) + if (GetValueFunc) { GetFunction = reinterpret_cast<TGetPtr>(codegen.GetPointerToFunction(GetValueFunc)); + } - if (SetValueFunc) + if (SetValueFunc) { SetFunction = reinterpret_cast<TSetPtr>(codegen.GetPointerToFunction(SetValueFunc)); + } } void TExternalCodegeneratorRootNode::GenerateFunctions(NYql::NCodegen::ICodegen& codegen) { @@ -1057,8 +1143,9 @@ Function* TExternalCodegeneratorRootNode::GenerateGetValue(NYql::NCodegen::ICode auto& module = codegen.GetModule(); auto& context = codegen.GetContext(); const auto& name = MakeName("Get"); - 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 contextType = GetCompContextType(context); @@ -1086,8 +1173,9 @@ Function* TExternalCodegeneratorRootNode::GenerateSetValue(NYql::NCodegen::ICode auto& module = codegen.GetModule(); auto& context = codegen.GetContext(); const auto& name = MakeName("Set"); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } const auto intType = Type::getInt128Ty(context); const auto contextType = GetCompContextType(context); @@ -1127,7 +1215,9 @@ Value* TExternalCodegeneratorNode::CreateGetValue(const TCodegenContext& ctx, Ba auto& context = ctx.Codegen.GetContext(); const auto indexType = Type::getInt32Ty(context); const auto valueType = Type::getInt128Ty(context); - const auto valuePtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(indexType, ValueIndex_)}, "value_ptr", block); + const auto valuePtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(indexType, ValueIndex_)}, "value_ptr", block); const auto value = new LoadInst(valueType, valuePtr, "value", block); return value; } @@ -1139,7 +1229,9 @@ Value* TExternalCodegeneratorNode::CreateRefValue(const TCodegenContext& ctx, Ba const auto indexType = Type::getInt32Ty(context); const auto valueType = Type::getInt128Ty(context); const auto values = ctx.GetMutables(); - const auto valuePtr = GetElementPtrInst::CreateInBounds(valueType, values, {ConstantInt::get(indexType, ValueIndex_)}, "value_ptr", block); + const auto valuePtr = GetElementPtrInst::CreateInBounds( + valueType, values, + {ConstantInt::get(indexType, ValueIndex_)}, "value_ptr", block); return valuePtr; } @@ -1148,8 +1240,9 @@ void TExternalCodegeneratorNode::CreateSetValue(const TCodegenContext& ctx, Basi const auto indexType = Type::getInt32Ty(context); const auto valueType = Type::getInt128Ty(context); const auto values = ctx.GetMutables(); - const auto valuePtr = GetElementPtrInst::CreateInBounds(valueType, values, {ConstantInt::get(indexType, ValueIndex_)}, "value_ptr", block); - + const auto valuePtr = GetElementPtrInst::CreateInBounds( + valueType, values, + {ConstantInt::get(indexType, ValueIndex_)}, "value_ptr", block); if (value->getType()->isPointerTy()) { ValueUnRef(RepresentationKind_, valuePtr, ctx, block); @@ -1175,7 +1268,6 @@ void TExternalCodegeneratorNode::CreateSetValue(const TCodegenContext& ctx, Basi BranchInst::Create(skip, block); block = skip; } - } CreateInvalidate(ctx, block); } @@ -1185,7 +1277,9 @@ Value* TExternalCodegeneratorNode::CreateSwapValue(const TCodegenContext& ctx, B const auto indexType = Type::getInt32Ty(context); const auto valueType = Type::getInt128Ty(context); const auto values = ctx.GetMutables(); - const auto valuePtr = GetElementPtrInst::CreateInBounds(valueType, values, {ConstantInt::get(indexType, ValueIndex_)}, "value_ptr", block); + const auto valuePtr = GetElementPtrInst::CreateInBounds( + valueType, values, + {ConstantInt::get(indexType, ValueIndex_)}, "value_ptr", block); const auto output = new LoadInst(valueType, valuePtr, "output", block); ValueRelease(RepresentationKind_, output, ctx, block); @@ -1247,36 +1341,35 @@ Value* MakeOptional(LLVMContext& context, Value* value, BasicBlock* block) { return result; } -ConstantInt* GetTrue(LLVMContext &context) { +ConstantInt* GetTrue(LLVMContext& context) { const uint64_t init[] = {1ULL, 0x100000000000000ULL}; return ConstantInt::get(context, APInt(128, 2, init)); } -ConstantInt* GetFalse(LLVMContext &context) { +ConstantInt* GetFalse(LLVMContext& context) { const uint64_t init[] = {0ULL, 0x100000000000000ULL}; return ConstantInt::get(context, APInt(128, 2, init)); } -ConstantInt* GetDecimalPlusInf(LLVMContext &context) { +ConstantInt* GetDecimalPlusInf(LLVMContext& context) { const auto& pair = NYql::NDecimal::MakePair(+NYql::NDecimal::Inf()); const uint64_t init[] = {pair.first, pair.second}; return ConstantInt::get(context, APInt(128, 2, init)); } -ConstantInt* GetDecimalMinusInf(LLVMContext &context) { +ConstantInt* GetDecimalMinusInf(LLVMContext& context) { const auto& pair = NYql::NDecimal::MakePair(-NYql::NDecimal::Inf()); const uint64_t init[] = {pair.first, pair.second}; return ConstantInt::get(context, APInt(128, 2, init)); } -ConstantInt* GetDecimalNan(LLVMContext &context) { +ConstantInt* GetDecimalNan(LLVMContext& context) { const auto& pair = NYql::NDecimal::MakePair(NYql::NDecimal::Nan()); const uint64_t init[] = {pair.first, pair.second}; return ConstantInt::get(context, APInt(128, 2, init)); } - -ConstantInt* GetDecimalMinusNan(LLVMContext &context) { +ConstantInt* GetDecimalMinusNan(LLVMContext& context) { const auto& pair = NYql::NDecimal::MakePair(-NYql::NDecimal::Nan()); const uint64_t init[] = {pair.first, pair.second}; return ConstantInt::get(context, APInt(128, 2, init)); @@ -1286,76 +1379,76 @@ static constexpr ui64 InvalidData = std::numeric_limits<ui64>::max(); static constexpr ui64 FinishData = InvalidData - 1ULL; static constexpr ui64 YieldData = InvalidData; -ConstantInt* GetEmpty(LLVMContext &context) { +ConstantInt* GetEmpty(LLVMContext& context) { return ConstantInt::get(Type::getInt128Ty(context), 0ULL); } -ConstantInt* GetInvalid(LLVMContext &context) { +ConstantInt* GetInvalid(LLVMContext& context) { return ConstantInt::get(Type::getInt128Ty(context), InvalidData); } -ConstantInt* GetFinish(LLVMContext &context) { +ConstantInt* GetFinish(LLVMContext& context) { return ConstantInt::get(Type::getInt128Ty(context), FinishData); } -ConstantInt* GetYield(LLVMContext &context) { +ConstantInt* GetYield(LLVMContext& context) { return ConstantInt::get(Type::getInt128Ty(context), YieldData); } -ConstantInt* GetConstant(ui64 value, LLVMContext &context) { +ConstantInt* GetConstant(ui64 value, LLVMContext& context) { const uint64_t init[] = {value, 0x100000000000000ULL}; return ConstantInt::get(context, APInt(128, 2, init)); } -Value* IsExists(Value* value, BasicBlock* block, LLVMContext &context) { +Value* IsExists(Value* value, BasicBlock* block, LLVMContext& context) { auto itemType = Type::getInt128Ty(context); const auto v = LoadIfPointer(value, itemType, block); return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, v, ConstantInt::get(v->getType(), 0ULL), "exists", block); } -Value* IsEmpty(Value* value, BasicBlock* block, LLVMContext &context) { +Value* IsEmpty(Value* value, BasicBlock* block, LLVMContext& context) { auto itemType = Type::getInt128Ty(context); const auto v = LoadIfPointer(value, itemType, block); return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, v, ConstantInt::get(v->getType(), 0ULL), "empty", block); } -Value* IsInvalid(Value* value, BasicBlock* block, LLVMContext &context) { +Value* IsInvalid(Value* value, BasicBlock* block, LLVMContext& context) { auto itemType = Type::getInt128Ty(context); const auto v = LoadIfPointer(value, itemType, block); return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, v, ConstantInt::get(v->getType(), InvalidData), "invalid", block); } -Value* IsValid(Value* value, BasicBlock* block, LLVMContext &context) { +Value* IsValid(Value* value, BasicBlock* block, LLVMContext& context) { auto itemType = Type::getInt128Ty(context); const auto v = LoadIfPointer(value, itemType, block); return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, v, ConstantInt::get(v->getType(), InvalidData), "valid", block); } -Value* IsFinish(Value* value, BasicBlock* block, LLVMContext &context) { +Value* IsFinish(Value* value, BasicBlock* block, LLVMContext& context) { auto itemType = Type::getInt128Ty(context); const auto v = LoadIfPointer(value, itemType, block); return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, v, ConstantInt::get(v->getType(), FinishData), "finish", block); } -Value* IsYield(Value* value, BasicBlock* block, LLVMContext &context) { +Value* IsYield(Value* value, BasicBlock* block, LLVMContext& context) { auto itemType = Type::getInt128Ty(context); const auto v = LoadIfPointer(value, itemType, block); return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, v, ConstantInt::get(v->getType(), YieldData), "yield", block); } -Value* IsSpecial(Value* value, BasicBlock* block, LLVMContext &context) { +Value* IsSpecial(Value* value, BasicBlock* block, LLVMContext& context) { auto itemType = Type::getInt128Ty(context); const auto v = LoadIfPointer(value, itemType, block); return BinaryOperator::CreateOr(IsFinish(v, block, context), IsYield(v, block, context), "special", block); } -Value* HasValue(Value* value, BasicBlock* block, LLVMContext &context) { +Value* HasValue(Value* value, BasicBlock* block, LLVMContext& context) { auto itemType = Type::getInt128Ty(context); const auto v = LoadIfPointer(value, itemType, block); return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_UGT, v, ConstantInt::get(v->getType(), InvalidData), "has", block); } -Value* MakeBoolean(Value* boolean , LLVMContext &context, BasicBlock* block) { +Value* MakeBoolean(Value* boolean, LLVMContext& context, BasicBlock* block) { return SelectInst::Create(boolean, GetTrue(context), GetFalse(context), "result", block); } @@ -1382,7 +1475,8 @@ Value* GetterForInt128(Value* value, BasicBlock* block) { const auto trun = ConstantInt::get(value->getType(), APInt(128, 2, mask)); const auto plus = BinaryOperator::CreateAnd(value, trun, "and", block); - const auto check = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, sign, ConstantInt::get(sign->getType(), 0), "check", block); + const auto check = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, sign, + ConstantInt::get(sign->getType(), 0), "check", block); const auto result = SelectInst::Create(check, plus, minus, "result", block); return result; } @@ -1393,36 +1487,72 @@ Value* GetterForTimezone(LLVMContext& context, Value* value, BasicBlock* block) return trunc; } -template<> Type* GetTypeFor<bool>(LLVMContext &context) { return Type::getInt1Ty(context); } -template<> Type* GetTypeFor<ui8>(LLVMContext &context) { return Type::getInt8Ty(context); } -template<> Type* GetTypeFor<i8>(LLVMContext &context) { return Type::getInt8Ty(context); } +template <> +Type* GetTypeFor<bool>(LLVMContext& context) { + return Type::getInt1Ty(context); +} +template <> +Type* GetTypeFor<ui8>(LLVMContext& context) { + return Type::getInt8Ty(context); +} +template <> +Type* GetTypeFor<i8>(LLVMContext& context) { + return Type::getInt8Ty(context); +} -template<> Type* GetTypeFor<i16>(LLVMContext &context) { return Type::getInt16Ty(context); } -template<> Type* GetTypeFor<ui16>(LLVMContext &context) { return Type::getInt16Ty(context); } +template <> +Type* GetTypeFor<i16>(LLVMContext& context) { + return Type::getInt16Ty(context); +} +template <> +Type* GetTypeFor<ui16>(LLVMContext& context) { + return Type::getInt16Ty(context); +} -template<> Type* GetTypeFor<i32>(LLVMContext &context) { return Type::getInt32Ty(context); } -template<> Type* GetTypeFor<ui32>(LLVMContext &context) { return Type::getInt32Ty(context); } +template <> +Type* GetTypeFor<i32>(LLVMContext& context) { + return Type::getInt32Ty(context); +} +template <> +Type* GetTypeFor<ui32>(LLVMContext& context) { + return Type::getInt32Ty(context); +} -template<> Type* GetTypeFor<i64>(LLVMContext &context) { return Type::getInt64Ty(context); } -template<> Type* GetTypeFor<ui64>(LLVMContext &context) { return Type::getInt64Ty(context); } +template <> +Type* GetTypeFor<i64>(LLVMContext& context) { + return Type::getInt64Ty(context); +} +template <> +Type* GetTypeFor<ui64>(LLVMContext& context) { + return Type::getInt64Ty(context); +} -template<> Type* GetTypeFor<float>(LLVMContext &context) { return Type::getFloatTy(context); } -template<> Type* GetTypeFor<double>(LLVMContext &context) { return Type::getDoubleTy(context); } +template <> +Type* GetTypeFor<float>(LLVMContext& context) { + return Type::getFloatTy(context); +} +template <> +Type* GetTypeFor<double>(LLVMContext& context) { + return Type::getDoubleTy(context); +} void AddRefBoxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { auto& context = ctx.Codegen.GetContext(); const auto load = value->getType()->isPointerTy() ? new LoadInst(Type::getInt128Ty(context), value, "load", block) : value; const auto half = CastInst::Create(Instruction::Trunc, load, Type::getInt64Ty(context), "half", block); const auto counterType = Type::getInt32Ty(context); - const auto type = StructType::get(context, {PointerType::getUnqual(StructType::get(context)), counterType, Type::getInt16Ty(context)}); + const auto type = StructType::get(context, + {PointerType::getUnqual(StructType::get(context)), counterType, Type::getInt16Ty(context)}); const auto boxptr = CastInst::Create(Instruction::IntToPtr, half, PointerType::getUnqual(type), "boxptr", block); - const auto cntptr = GetElementPtrInst::CreateInBounds(type, boxptr, {ConstantInt::get(Type::getInt32Ty(context), 0), ConstantInt::get(Type::getInt32Ty(context), 1)}, "cntptr", block); + const auto cntptr = GetElementPtrInst::CreateInBounds( + type, boxptr, {ConstantInt::get(Type::getInt32Ty(context), 0), ConstantInt::get(Type::getInt32Ty(context), 1)}, "cntptr", block); const auto refs = new LoadInst(counterType, cntptr, "refs", block); -#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) + #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) if constexpr (EnableStaticRefcount) { const auto work = BasicBlock::Create(context, "work", ctx.Func); const auto skip = BasicBlock::Create(context, "skip", ctx.Func); - const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, ConstantInt::get(refs->getType(), 0), "magic", block); + const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, + ConstantInt::get(refs->getType(), 0), "magic", block); BranchInst::Create(skip, work, magic, block); block = work; @@ -1435,10 +1565,10 @@ void AddRefBoxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { const auto incr = BinaryOperator::CreateAdd(refs, ConstantInt::get(refs->getType(), 1), "incr", block); new StoreInst(incr, cntptr, block); } -#else + #else const auto incr = BinaryOperator::CreateAdd(refs, ConstantInt::get(refs->getType(), 1), "incr", block); new StoreInst(incr, cntptr, block); -#endif + #endif } void UnRefBoxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { @@ -1446,23 +1576,27 @@ void UnRefBoxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { const auto load = value->getType()->isPointerTy() ? new LoadInst(Type::getInt128Ty(context), value, "load", block) : value; const auto half = CastInst::Create(Instruction::Trunc, load, Type::getInt64Ty(context), "half", block); const auto counterType = Type::getInt32Ty(context); - const auto type = StructType::get(context, {PointerType::getUnqual(StructType::get(context)), counterType, Type::getInt16Ty(context)}); + const auto type = StructType::get(context, + {PointerType::getUnqual(StructType::get(context)), counterType, Type::getInt16Ty(context)}); const auto boxptr = CastInst::Create(Instruction::IntToPtr, half, PointerType::getUnqual(type), "boxptr", block); - const auto cntptr = GetElementPtrInst::CreateInBounds(type, boxptr, {ConstantInt::get(Type::getInt32Ty(context), 0), ConstantInt::get(Type::getInt32Ty(context), 1)}, "cntptr", block); + const auto cntptr = GetElementPtrInst::CreateInBounds( + type, boxptr, + {ConstantInt::get(Type::getInt32Ty(context), 0), ConstantInt::get(Type::getInt32Ty(context), 1)}, "cntptr", block); const auto refs = new LoadInst(counterType, cntptr, "refs", block); const auto live = BasicBlock::Create(context, "live", ctx.Func); -#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) + #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) if constexpr (EnableStaticRefcount) { - const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, ConstantInt::get(refs->getType(), 0), "magic", block); + const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, + ConstantInt::get(refs->getType(), 0), "magic", block); const auto work = BasicBlock::Create(context, "work", ctx.Func); BranchInst::Create(live, work, magic, block); block = work; } -#endif + #endif const auto decr = BinaryOperator::CreateSub(refs, ConstantInt::get(refs->getType(), 1), "decr", block); new StoreInst(decr, cntptr, block); @@ -1489,9 +1623,12 @@ void CleanupBoxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) const auto load = value->getType()->isPointerTy() ? new LoadInst(Type::getInt128Ty(context), value, "load", block) : value; const auto half = CastInst::Create(Instruction::Trunc, load, Type::getInt64Ty(context), "half", block); const auto counterType = Type::getInt32Ty(context); - const auto type = StructType::get(context, {PointerType::getUnqual(StructType::get(context)), counterType, Type::getInt16Ty(context)}); + const auto type = StructType::get(context, + {PointerType::getUnqual(StructType::get(context)), counterType, Type::getInt16Ty(context)}); const auto boxptr = CastInst::Create(Instruction::IntToPtr, half, PointerType::getUnqual(type), "boxptr", block); - const auto cntptr = GetElementPtrInst::CreateInBounds(type, boxptr, {ConstantInt::get(Type::getInt32Ty(context), 0), ConstantInt::get(Type::getInt32Ty(context), 1)}, "cntptr", block); + const auto cntptr = GetElementPtrInst::CreateInBounds( + type, boxptr, + {ConstantInt::get(Type::getInt32Ty(context), 0), ConstantInt::get(Type::getInt32Ty(context), 1)}, "cntptr", block); const auto refs = new LoadInst(counterType, cntptr, "refs", block); const auto test = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, refs, ConstantInt::get(refs->getType(), 0), "many", block); @@ -1512,8 +1649,7 @@ void CleanupBoxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) block = live; } - -template<bool IncOrDec> +template <bool IncOrDec> void ChangeRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { auto& context = ctx.Codegen.GetContext(); @@ -1538,7 +1674,9 @@ void ChangeRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& blo block = strb; const auto [strptr, strtype] = GetPointerFromUnboxed<false>(value, ctx, block); - const auto elemptr = GetElementPtrInst::CreateInBounds(strtype, strptr, {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1)}, "elemptr", block); + const auto elemptr = GetElementPtrInst::CreateInBounds( + strtype, strptr, + {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1)}, "elemptr", block); refsptr->addIncoming(elemptr, block); BranchInst::Create(doit, block); } @@ -1547,7 +1685,9 @@ void ChangeRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& blo block = boxb; const auto [boxptr, boxtype] = GetPointerFromUnboxed<true>(value, ctx, block); - const auto elemptr = GetElementPtrInst::CreateInBounds(boxtype, boxptr, {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1)}, "elemptr", block); + const auto elemptr = GetElementPtrInst::CreateInBounds( + boxtype, boxptr, + {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1)}, "elemptr", block); refsptr->addIncoming(elemptr, block); BranchInst::Create(doit, block); } @@ -1555,26 +1695,29 @@ void ChangeRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& blo block = doit; const auto refs = new LoadInst(type32, refsptr, "refs", block); -#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) + #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) if constexpr (EnableStaticRefcount) { - const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, ConstantInt::get(refs->getType(), 0), "magic", block); + const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, + ConstantInt::get(refs->getType(), 0), "magic", block); const auto work = BasicBlock::Create(context, "work", ctx.Func); BranchInst::Create(done, work, magic, block); block = work; } -#endif - const auto next = IncOrDec ? - BinaryOperator::CreateAdd(refs, ConstantInt::get(refs->getType(), 1), "incr", block): - BinaryOperator::CreateSub(refs, ConstantInt::get(refs->getType(), 1), "decr", block); + #endif + const auto next = IncOrDec + ? BinaryOperator::CreateAdd(refs, + ConstantInt::get(refs->getType(), 1), "incr", block) + : BinaryOperator::CreateSub(refs, + ConstantInt::get(refs->getType(), 1), "decr", block); new StoreInst(next, refsptr, block); BranchInst::Create(done, block); block = done; } -template<bool Decrement> +template <bool Decrement> void CheckRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { auto& context = ctx.Codegen.GetContext(); @@ -1595,28 +1738,33 @@ void CheckRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& bloc block = strb; const auto [strptr, strtype] = GetPointerFromUnboxed<false>(value, ctx, block); - const auto refptr = GetElementPtrInst::CreateInBounds(strtype, strptr, {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1)}, "refptr", block); + const auto refptr = GetElementPtrInst::CreateInBounds( + strtype, strptr, + {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1)}, "refptr", block); const auto refs = new LoadInst(type32, refptr, "refs", block); -#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) + #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) if constexpr (EnableStaticRefcount) { - const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, ConstantInt::get(refs->getType(), 0), "magic", block); + const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, + ConstantInt::get(refs->getType(), 0), "magic", block); const auto work = BasicBlock::Create(context, "work", ctx.Func); BranchInst::Create(nope, work, magic, block); block = work; } -#endif + #endif Value* test = refs; if constexpr (Decrement) { - const auto decr = BinaryOperator::CreateSub(refs, ConstantInt::get(refs->getType(), 1), "decr", block); + const auto decr = BinaryOperator::CreateSub(refs, + ConstantInt::get(refs->getType(), 1), "decr", block); new StoreInst(decr, refptr, block); test = decr; } - const auto good = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_UGT, test, ConstantInt::get(test->getType(), 0), "test", block); + const auto good = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_UGT, test, + ConstantInt::get(test->getType(), 0), "test", block); const auto free = BasicBlock::Create(context, "free", ctx.Func); @@ -1635,30 +1783,36 @@ void CheckRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& bloc { block = boxb; - const auto [boxptr, boxtype] = GetPointerFromUnboxed<true>(value, ctx, block);; - const auto refptr = GetElementPtrInst::CreateInBounds(boxtype, boxptr, {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1)}, "cntptr", block); + const auto [boxptr, boxtype] = GetPointerFromUnboxed<true>(value, ctx, block); + ; + const auto refptr = GetElementPtrInst::CreateInBounds( + boxtype, boxptr, + {ConstantInt::get(type32, 0), ConstantInt::get(type32, 1)}, "cntptr", block); const auto refs = new LoadInst(type32, refptr, "refs", block); -#if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) + #if UDF_ABI_COMPATIBILITY_VERSION_CURRENT >= UDF_ABI_COMPATIBILITY_VERSION(2, 4) if constexpr (EnableStaticRefcount) { - const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, ConstantInt::get(refs->getType(), 0), "magic", block); + const auto magic = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_SLT, refs, + ConstantInt::get(refs->getType(), 0), "magic", block); const auto work = BasicBlock::Create(context, "work", ctx.Func); BranchInst::Create(nope, work, magic, block); block = work; } -#endif + #endif Value* test = refs; if constexpr (Decrement) { - const auto decr = BinaryOperator::CreateSub(refs, ConstantInt::get(refs->getType(), 1), "decr", block); + const auto decr = BinaryOperator::CreateSub(refs, + ConstantInt::get(refs->getType(), 1), "decr", block); new StoreInst(decr, refptr, block); test = decr; } - const auto good = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_UGT, test, ConstantInt::get(test->getType(), 0), "test", block); + const auto good = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_UGT, test, + ConstantInt::get(test->getType(), 0), "test", block); const auto kill = BasicBlock::Create(context, "kill", ctx.Func); @@ -1677,13 +1831,14 @@ void CheckRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& bloc block = nope; } -#ifdef MAKE_UNBOXED_VALUE_LLVM_REFCOUNTION_FUNCTIONS + #ifdef MAKE_UNBOXED_VALUE_LLVM_REFCOUNTION_FUNCTIONS Function* GenRefCountFunction(const char* label, void (*func)(Value*, const TCodegenContext&, BasicBlock*&), Type* type, NYql::NCodegen::ICodegen& codegen) { auto& module = codegen.GetModule(); auto& context = codegen.GetContext(); const auto name = TString(label) += (type->isPointerTy() ? "Ptr" : "Val"); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } const auto funcType = FunctionType::get(Type::getVoidTy(context), {type}, false); @@ -1713,7 +1868,7 @@ void UnRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) void CleanupUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { CallInst::Create(GenRefCountFunction(__func__, &CheckRefUnboxed<false>, value->getType(), ctx.Codegen), {value}, "", block); } -#else + #else void AddRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { return ChangeRefUnboxed<true>(value, ctx, block); } @@ -1729,7 +1884,7 @@ void UnRefUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) void CleanupUnboxed(Value* value, const TCodegenContext& ctx, BasicBlock*& block) { return CheckRefUnboxed<false>(value, ctx, block); } -#endif + #endif void SafeUnRefUnboxedOne(Value* pointer, const TCodegenContext& ctx, BasicBlock*& block) { auto itemType = Type::getInt128Ty(ctx.Codegen.GetContext()); @@ -1741,46 +1896,59 @@ void SafeUnRefUnboxedArray(Value* pointer, ArrayType* arrayType, const TCodegenC const auto indexType = Type::getInt64Ty(ctx.Codegen.GetContext()); Value* zeros = UndefValue::get(arrayType); for (ui32 idx = 0U; idx < arrayType->getNumElements(); ++idx) { - const auto item = GetElementPtrInst::CreateInBounds(arrayType, pointer, { ConstantInt::get(indexType, 0), ConstantInt::get(indexType, idx) }, (TString("item_") += ToString(idx)).c_str(), block); + const auto item = GetElementPtrInst::CreateInBounds( + arrayType, pointer, + {ConstantInt::get(indexType, 0), + ConstantInt::get(indexType, idx)}, (TString("item_") += ToString(idx)).c_str(), block); UnRefUnboxed(item, ctx, block); - zeros = InsertValueInst::Create(zeros, ConstantInt::get(arrayType->getArrayElementType(), 0), {idx}, (TString("zero_") += ToString(idx)).c_str(), block); + zeros = InsertValueInst::Create( + zeros, + ConstantInt::get(arrayType->getArrayElementType(), 0), {idx}, (TString("zero_") += ToString(idx)).c_str(), block); } new StoreInst(zeros, pointer, block); } void ValueAddRef(EValueRepresentation kind, Value* pointer, const TCodegenContext& ctx, BasicBlock*& block) { switch (kind) { - case EValueRepresentation::Embedded: return; - case EValueRepresentation::Boxed: // TODO + case EValueRepresentation::Embedded: + return; + case EValueRepresentation::Boxed: // TODO case EValueRepresentation::String: // TODO - case EValueRepresentation::Any: return AddRefUnboxed(pointer, ctx, block); + case EValueRepresentation::Any: + return AddRefUnboxed(pointer, ctx, block); } } void ValueUnRef(EValueRepresentation kind, Value* pointer, const TCodegenContext& ctx, BasicBlock*& block) { switch (kind) { - case EValueRepresentation::Embedded: return; - case EValueRepresentation::Boxed: // TODO + case EValueRepresentation::Embedded: + return; + case EValueRepresentation::Boxed: // TODO case EValueRepresentation::String: // TODO - case EValueRepresentation::Any: return UnRefUnboxed(pointer, ctx, block); + case EValueRepresentation::Any: + return UnRefUnboxed(pointer, ctx, block); } } void ValueCleanup(EValueRepresentation kind, Value* pointer, const TCodegenContext& ctx, BasicBlock*& block) { switch (kind) { - case EValueRepresentation::Embedded: return; - case EValueRepresentation::Boxed: // TODO + case EValueRepresentation::Embedded: + return; + case EValueRepresentation::Boxed: // TODO case EValueRepresentation::String: // TODO - case EValueRepresentation::Any: return CleanupUnboxed(pointer, ctx, block); + case EValueRepresentation::Any: + return CleanupUnboxed(pointer, ctx, block); } } void ValueRelease(EValueRepresentation kind, Value* pointer, const TCodegenContext& ctx, BasicBlock*& block) { switch (kind) { - case EValueRepresentation::Embedded: return; - case EValueRepresentation::Boxed: // TODO + case EValueRepresentation::Embedded: + return; + case EValueRepresentation::Boxed: // TODO case EValueRepresentation::String: // TODO - case EValueRepresentation::Any: return ReleaseUnboxed(pointer, ctx, block); + case EValueRepresentation::Any: + return ReleaseUnboxed(pointer, ctx, block); } } @@ -1788,10 +1956,10 @@ std::pair<Value*, Value*> GetVariantParts(Value* variant, const TCodegenContext& auto& context = ctx.Codegen.GetContext(); const auto type = Type::getInt32Ty(context); - const auto lshr = BinaryOperator::CreateLShr(variant, ConstantInt::get(variant->getType(), 122), "lshr", block); + const auto lshr = BinaryOperator::CreateLShr(variant, ConstantInt::get(variant->getType(), 122), "lshr", block); const auto trunc = CastInst::Create(Instruction::Trunc, lshr, type, "trunc", block); - const auto check = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, trunc, ConstantInt::get(type , 0), "check", block); + const auto check = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE, trunc, ConstantInt::get(type, 0), "check", block); const auto boxed = BasicBlock::Create(context, "boxed", ctx.Func); const auto embed = BasicBlock::Create(context, "embed", ctx.Func); @@ -1807,9 +1975,9 @@ std::pair<Value*, Value*> GetVariantParts(Value* variant, const TCodegenContext& const uint64_t init[] = {0xFFFFFFFFFFFFFFFFULL, 0x3FFFFFFFFFFFFFFULL}; const auto mask = ConstantInt::get(variant->getType(), APInt(128, 2, init)); - const auto clean = BinaryOperator::CreateAnd(variant, mask, "clean", block); + const auto clean = BinaryOperator::CreateAnd(variant, mask, "clean", block); - const auto dec = BinaryOperator::CreateSub(trunc, ConstantInt::get(type, 1), "dec", block); + const auto dec = BinaryOperator::CreateSub(trunc, ConstantInt::get(type, 1), "dec", block); index->addIncoming(dec, block); item->addIncoming(clean, block); BranchInst::Create(done, block); @@ -1819,9 +1987,12 @@ std::pair<Value*, Value*> GetVariantParts(Value* variant, const TCodegenContext& block = boxed; const auto place = new AllocaInst(item->getType(), 0U, "place", &ctx.Func->getEntryBlock().back()); - const auto idx = CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetVariantIndex>(type, variant, ctx.Codegen, block); - CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetVariantItem>(place, variant, ctx.Codegen, block); - const auto clean = new LoadInst(item->getType(), place, "clean", block); + const auto idx = CallBoxedValueVirtualMethod< + NUdf::TBoxedValueAccessor::EMethod::GetVariantIndex>( + type, variant, ctx.Codegen, block); + CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::GetVariantItem>( + place, variant, ctx.Codegen, block); + const auto clean = new LoadInst(item->getType(), place, "clean", block); ValueRelease(EValueRepresentation::Any, clean, ctx, block); index->addIncoming(idx, block); item->addIncoming(clean, block); @@ -1844,8 +2015,10 @@ Value* MakeVariant(Value* item, Value* variant, const TCodegenContext& ctx, Basi const auto offset = ConstantInt::get(item->getType(), 122); const auto lshr = BinaryOperator::CreateLShr(item, offset, "lshr", block); - const auto checkItem = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, lshr, ConstantInt::get(lshr->getType(), 0), "check_item", block); - const auto checkIndex = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_ULT, variant, ConstantInt::get(variant->getType(), (1U << 6U) - 1U), "check_index", block); + const auto checkItem = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, lshr, + ConstantInt::get(lshr->getType(), 0), "check_item", block); + const auto checkIndex = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_ULT, variant, + ConstantInt::get(variant->getType(), (1U << 6U) - 1U), "check_index", block); const auto check = BinaryOperator::CreateAnd(checkItem, checkIndex, "and", block); BranchInst::Create(embed, boxed, check, block); @@ -1853,10 +2026,10 @@ Value* MakeVariant(Value* item, Value* variant, const TCodegenContext& ctx, Basi { block = embed; - const auto index = BinaryOperator::CreateAdd(variant, ConstantInt::get(variant->getType(), 1), "index", block); + const auto index = BinaryOperator::CreateAdd(variant, ConstantInt::get(variant->getType(), 1), "index", block); const auto extend = CastInst::Create(Instruction::ZExt, index, item->getType(), "extend", block); - const auto shift = BinaryOperator::CreateShl(extend, offset, "shift", block); - const auto output = BinaryOperator::CreateOr(item, shift, "output", block); + const auto shift = BinaryOperator::CreateShl(extend, offset, "shift", block); + const auto output = BinaryOperator::CreateOr(item, shift, "output", block); result->addIncoming(output, block); BranchInst::Create(done, block); } @@ -1880,8 +2053,9 @@ Value* MakeVariant(Value* item, Value* variant, const TCodegenContext& ctx, Basi } Value* GetNodeValue(IComputationNode* node, const TCodegenContext& ctx, BasicBlock*& block) { - if (const auto codegen = dynamic_cast<ICodegeneratorInlineNode*>(node)) + if (const auto codegen = dynamic_cast<ICodegeneratorInlineNode*>(node)) { return codegen->CreateGetValue(ctx, block); + } auto& context = ctx.Codegen.GetContext(); const auto ptr = ConstantInt::get(Type::getInt64Ty(context), intptr_t(node)); @@ -1897,7 +2071,9 @@ Value* GetNodeValue(IComputationNode* node, const TCodegenContext& ctx, BasicBlo const auto nodeVTable = CastInst::Create(Instruction::IntToPtr, ptr, PointerType::getUnqual(tableType), "node_vtable", block); const auto table = new LoadInst(tableType, nodeVTable, "table", false, block); - const auto elem = GetElementPtrInst::CreateInBounds(ptrFunType, table, {ConstantInt::get(Type::getInt64Ty(context), GetMethodIndex(&IComputationNode::GetValue))}, "element", block); + const auto elem = GetElementPtrInst::CreateInBounds( + ptrFunType, table, + {ConstantInt::get(Type::getInt64Ty(context), GetMethodIndex(&IComputationNode::GetValue))}, "element", block); const auto func = new LoadInst(ptrFunType, elem, "func", false, block); CallInst::Create(funType, func, {retPtr, nodeThis, ctx.Ctx}, "", block); @@ -1928,15 +2104,19 @@ void GetNodeValue(Value* value, IComputationNode* node, const TCodegenContext& c const auto nodeVTable = CastInst::Create(Instruction::IntToPtr, ptr, PointerType::getUnqual(tableType), "node_vtable", block); const auto table = new LoadInst(tableType, nodeVTable, "table", false, block); - const auto elem = GetElementPtrInst::CreateInBounds(ptrFunType, table, {ConstantInt::get(Type::getInt64Ty(context), GetMethodIndex(&IComputationNode::GetValue))}, "element", block); + const auto elem = GetElementPtrInst::CreateInBounds( + ptrFunType, table, + {ConstantInt::get(Type::getInt64Ty(context), GetMethodIndex(&IComputationNode::GetValue))}, "element", block); const auto func = new LoadInst(ptrFunType, elem, "func", false, block); CallInst::Create(funType, func, {value, nodeThis, ctx.Ctx}, "", block); } -ICodegeneratorInlineWideNode::TGenerateResult GetNodeValues(IComputationWideFlowNode* node, const TCodegenContext& ctx, BasicBlock*& block) { - if (const auto codegen = dynamic_cast<ICodegeneratorInlineWideNode*>(node)) +ICodegeneratorInlineWideNode::TGenerateResult GetNodeValues(IComputationWideFlowNode* node, + const TCodegenContext& ctx, BasicBlock*& block) { + if (const auto codegen = dynamic_cast<ICodegeneratorInlineWideNode*>(node)) { return codegen->GenGetValues(ctx, block); + } throw TNoCodegen(); } @@ -1974,12 +2154,14 @@ Value* CheckAdjustedMemLimit(ui64 limit, Value* init, const TCodegenContext& ctx const auto indexType = Type::getInt32Ty(context); if constexpr (TrackRss) { - const auto rssPtr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), ctx.Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 5)}, "rss_ptr", block); + const auto rssPtr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), ctx.Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 5)}, "rss_ptr", block); const auto rss = new LoadInst(Type::getInt32Ty(context), rssPtr, "rsscounter", block); const auto inc = BinaryOperator::CreateAdd(rss, ConstantInt::get(rss->getType(), 1), "inc", block); new StoreInst(inc, rssPtr, block); const auto mod = BinaryOperator::CreateURem(rss, ConstantInt::get(rss->getType(), STEP_FOR_RSS_CHECK), "mod", block); - const auto now = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, mod, ConstantInt::get(mod->getType() , 0), "now", block); + const auto now = CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ, mod, ConstantInt::get(mod->getType(), 0), "now", block); const auto call = BasicBlock::Create(context, "call", ctx.Func); const auto skip = BasicBlock::Create(context, "skip", ctx.Func); @@ -1997,7 +2179,9 @@ Value* CheckAdjustedMemLimit(ui64 limit, Value* init, const TCodegenContext& ctx block = skip; } - const auto adjPtr = GetElementPtrInst::CreateInBounds(GetCompContextType(context), ctx.Ctx, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 4)}, "adj_ptr", block); + const auto adjPtr = GetElementPtrInst::CreateInBounds( + GetCompContextType(context), ctx.Ctx, + {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, 4)}, "adj_ptr", block); const auto adjustor = new LoadInst(Type::getFloatTy(context), adjPtr, "adjustor", block); const auto curr = GetMemoryUsed(limit, ctx, block); @@ -2011,7 +2195,8 @@ Value* CheckAdjustedMemLimit(ui64 limit, Value* init, const TCodegenContext& ctx template Value* CheckAdjustedMemLimit<false>(ui64 limit, Value* init, const TCodegenContext& ctx, BasicBlock*& block); template Value* CheckAdjustedMemLimit<true>(ui64 limit, Value* init, const TCodegenContext& ctx, BasicBlock*& block); -Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, Value* value, NYql::NCodegen::ICodegen& codegen, BasicBlock* block) { +Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, + Value* value, NYql::NCodegen::ICodegen& codegen, BasicBlock* block) { auto& context = codegen.GetContext(); const auto data = CastInst::Create(Instruction::Trunc, value, Type::getInt64Ty(context), "data", block); @@ -2024,14 +2209,17 @@ Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, Va const auto vTable = CastInst::Create(Instruction::IntToPtr, data, PointerType::getUnqual(tableType), "vtable", block); const auto table = new LoadInst(tableType, vTable, "table", false, block); - const auto elem = GetElementPtrInst::CreateInBounds(ptrFunType, table, {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); + const auto elem = GetElementPtrInst::CreateInBounds( + ptrFunType, table, + {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); const auto func = new LoadInst(ptrFunType, elem, "func", false, block); const auto call = CallInst::Create(funType, func, {boxed}, returnType->isVoidTy() ? "" : "return", block); return call; } -void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* value, NYql::NCodegen::ICodegen& codegen, BasicBlock* block) { +void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* value, + NYql::NCodegen::ICodegen& codegen, BasicBlock* block) { auto& context = codegen.GetContext(); const auto data = CastInst::Create(Instruction::Trunc, value, Type::getInt64Ty(context), "data", block); @@ -2045,13 +2233,16 @@ void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* const auto vTable = CastInst::Create(Instruction::IntToPtr, data, PointerType::getUnqual(tableType), "vtable", block); const auto table = new LoadInst(tableType, vTable, "table", false, block); - const auto elem = GetElementPtrInst::CreateInBounds(ptrFunType, table, {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); + const auto elem = GetElementPtrInst::CreateInBounds( + ptrFunType, table, + {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); const auto func = new LoadInst(ptrFunType, elem, "func", false, block); CallInst::Create(funType, func, {output, boxed}, "", block); } -void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* value, NYql::NCodegen::ICodegen& codegen, BasicBlock* block, Value* argument) { +void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* value, + NYql::NCodegen::ICodegen& codegen, BasicBlock* block, Value* argument) { auto& context = codegen.GetContext(); const auto data = CastInst::Create(Instruction::Trunc, value, Type::getInt64Ty(context), "data", block); @@ -2065,13 +2256,16 @@ void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* const auto vTable = CastInst::Create(Instruction::IntToPtr, data, PointerType::getUnqual(tableType), "vtable", block); const auto table = new LoadInst(tableType, vTable, "table", false, block); - const auto elem = GetElementPtrInst::CreateInBounds(ptrFunType, table, {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); + const auto elem = GetElementPtrInst::CreateInBounds( + ptrFunType, table, + {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); const auto func = new LoadInst(ptrFunType, elem, "func", false, block); CallInst::Create(funType, func, {output, boxed, argument}, "", block); } -Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, Value* value, NYql::NCodegen::ICodegen& codegen, BasicBlock* block, Value* argument) { +Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, Value* value, + NYql::NCodegen::ICodegen& codegen, BasicBlock* block, Value* argument) { auto& context = codegen.GetContext(); const auto data = CastInst::Create(Instruction::Trunc, value, Type::getInt64Ty(context), "data", block); @@ -2084,14 +2278,17 @@ Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, Va const auto vTable = CastInst::Create(Instruction::IntToPtr, data, PointerType::getUnqual(tableType), "vtable", block); const auto table = new LoadInst(tableType, vTable, "table", false, block); - const auto elem = GetElementPtrInst::CreateInBounds(ptrFunType, table, {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); + const auto elem = GetElementPtrInst::CreateInBounds( + ptrFunType, table, + {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); const auto func = new LoadInst(ptrFunType, elem, "func", false, block); const auto call = CallInst::Create(funType, func, {boxed, argument}, returnType->isVoidTy() ? "" : "return", block); return call; } -void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* value, NYql::NCodegen::ICodegen& codegen, BasicBlock* block, Value* arg1, Value* arg2) { +void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* value, + NYql::NCodegen::ICodegen& codegen, BasicBlock* block, Value* arg1, Value* arg2) { auto& context = codegen.GetContext(); const auto data = CastInst::Create(Instruction::Trunc, value, Type::getInt64Ty(context), "data", block); @@ -2105,13 +2302,16 @@ void CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Value* output, Value* const auto vTable = CastInst::Create(Instruction::IntToPtr, data, PointerType::getUnqual(tableType), "vtable", block); const auto table = new LoadInst(tableType, vTable, "table", false, block); - const auto elem = GetElementPtrInst::CreateInBounds(ptrFunType, table, {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); + const auto elem = GetElementPtrInst::CreateInBounds( + ptrFunType, table, + {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); const auto func = new LoadInst(ptrFunType, elem, "func", false, block); CallInst::Create(funType, func, {output, boxed, arg1, arg2}, "", block); } -Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, Value* value, NYql::NCodegen::ICodegen& codegen, BasicBlock* block, Value* arg1, Value* arg2) { +Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, Value* value, + NYql::NCodegen::ICodegen& codegen, BasicBlock* block, Value* arg1, Value* arg2) { auto& context = codegen.GetContext(); const auto data = CastInst::Create(Instruction::Trunc, value, Type::getInt64Ty(context), "data", block); @@ -2124,14 +2324,17 @@ Value* CallBoxedValueVirtualMethodImpl(uintptr_t methodPtr, Type* returnType, Va const auto vTable = CastInst::Create(Instruction::IntToPtr, data, PointerType::getUnqual(tableType), "vtable", block); const auto table = new LoadInst(tableType, vTable, "table", false, block); - const auto elem = GetElementPtrInst::CreateInBounds(ptrFunType, table, {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); + const auto elem = GetElementPtrInst::CreateInBounds( + ptrFunType, table, + {ConstantInt::get(Type::getInt64Ty(context), GetMethodPtrIndex(methodPtr))}, "element", block); const auto func = new LoadInst(ptrFunType, elem, "func", false, block); const auto call = CallInst::Create(funType, func, {boxed, arg1, arg2}, returnType->isVoidTy() ? "" : "return", block); return call; } -Value* CallUnaryUnboxedValueFunctionImpl(uintptr_t methodPtr, Type* result, Value* arg, NYql::NCodegen::ICodegen& codegen, BasicBlock* block) { +Value* CallUnaryUnboxedValueFunctionImpl(uintptr_t methodPtr, Type* result, Value* arg, + NYql::NCodegen::ICodegen& codegen, BasicBlock* block) { auto& context = codegen.GetContext(); const auto doFunc = ConstantInt::get(Type::getInt64Ty(context), methodPtr); const auto funType = FunctionType::get(result, {arg->getType()}, false); @@ -2140,7 +2343,8 @@ Value* CallUnaryUnboxedValueFunctionImpl(uintptr_t methodPtr, Type* result, Valu return call; } -Value* CallBinaryUnboxedValueFunctionImpl(uintptr_t methodPtr, Type* result, Value* left, Value* right, NYql::NCodegen::ICodegen& codegen, BasicBlock* block) { +Value* CallBinaryUnboxedValueFunctionImpl(uintptr_t methodPtr, Type* result, Value* left, Value* right, + NYql::NCodegen::ICodegen& codegen, BasicBlock* block) { auto& context = codegen.GetContext(); const auto doFunc = ConstantInt::get(Type::getInt64Ty(context), methodPtr); const auto funType = FunctionType::get(result, {left->getType(), right->getType()}, false); @@ -2149,7 +2353,8 @@ Value* CallBinaryUnboxedValueFunctionImpl(uintptr_t methodPtr, Type* result, Val return call; } -Y_NO_INLINE Value* TDecoratorCodegeneratorNodeBase::CreateGetValueImpl(IComputationNode* node, +Y_NO_INLINE Value* TDecoratorCodegeneratorNodeBase::CreateGetValueImpl( + IComputationNode* node, const TCodegenContext& ctx, BasicBlock*& block) const { const auto arg = GetNodeValue(node, ctx, block); const auto value = DoGenerateGetValue(ctx, arg, block); @@ -2162,7 +2367,8 @@ Y_NO_INLINE Value* TDecoratorCodegeneratorNodeBase::CreateGetValueImpl(IComputat } } -Y_NO_INLINE Value* TStatelessFlowCodegeneratorNodeBase::CreateGetValueImpl(const IComputationNode* node, +Y_NO_INLINE Value* TStatelessFlowCodegeneratorNodeBase::CreateGetValueImpl( + const IComputationNode* node, const TCodegenContext& ctx, BasicBlock*& block) const { const auto value = DoGenerateGetValue(ctx, block); if (value->getType()->isPointerTy()) { @@ -2183,7 +2389,9 @@ Y_NO_INLINE Value* TFlowSourceCodegeneratorNodeBase::CreateGetValueImpl( const IComputationNode* node, const TCodegenContext& ctx, BasicBlock*& block) const { auto& context = ctx.Codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); - const auto statePtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(Type::getInt32Ty(context), node->GetIndex())}, "state_ptr", block); + const auto statePtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(Type::getInt32Ty(context), node->GetIndex())}, "state_ptr", block); const auto value = DoGenerateGetValue(ctx, statePtr, block); if (value->getType()->isPointerTy()) { @@ -2199,7 +2407,9 @@ Y_NO_INLINE ICodegeneratorInlineWideNode::TGenerateResult TWideFlowSourceCodegen const IComputationNode* node, const TCodegenContext& ctx, BasicBlock*& block) const { auto& context = ctx.Codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); - const auto statePtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(Type::getInt32Ty(context), node->GetIndex())}, "state_ptr", block); + const auto statePtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(Type::getInt32Ty(context), node->GetIndex())}, "state_ptr", block); return DoGenGetValues(ctx, statePtr, block); } @@ -2207,7 +2417,9 @@ Y_NO_INLINE Value* TStatefulFlowCodegeneratorNodeBase::CreateGetValueImpl( const IComputationNode* node, const TCodegenContext& ctx, BasicBlock*& block) const { auto& context = ctx.Codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); - const auto statePtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(Type::getInt32Ty(context), node->GetIndex())}, "state_ptr", block); + const auto statePtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(Type::getInt32Ty(context), node->GetIndex())}, "state_ptr", block); const auto value = DoGenerateGetValue(ctx, statePtr, block); if (value->getType()->isPointerTy()) { @@ -2223,7 +2435,9 @@ Y_NO_INLINE ICodegeneratorInlineWideNode::TGenerateResult TStatefulWideFlowCodeg const IComputationNode* node, const TCodegenContext& ctx, BasicBlock*& block) const { auto& context = ctx.Codegen.GetContext(); const auto valueType = Type::getInt128Ty(context); - const auto statePtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(Type::getInt32Ty(context), node->GetIndex())}, "state_ptr", block); + const auto statePtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(Type::getInt32Ty(context), node->GetIndex())}, "state_ptr", block); return DoGenGetValues(ctx, statePtr, block); } @@ -2232,8 +2446,12 @@ Y_NO_INLINE ICodegeneratorInlineWideNode::TGenerateResult TPairStateWideFlowCode auto& context = ctx.Codegen.GetContext(); auto idx = node->GetIndex(); const auto valueType = Type::getInt128Ty(context); - const auto firstPtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(Type::getInt32Ty(context), idx)}, "first_ptr", block); - const auto secondPtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(Type::getInt32Ty(context), ++idx)}, "second_ptr", block); + const auto firstPtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(Type::getInt32Ty(context), idx)}, "first_ptr", block); + const auto secondPtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(Type::getInt32Ty(context), ++idx)}, "second_ptr", block); return DoGenGetValues(ctx, firstPtr, secondPtr, block); } @@ -2242,8 +2460,12 @@ Y_NO_INLINE Value* TPairStateFlowCodegeneratorNodeBase::CreateGetValueImpl( auto& context = ctx.Codegen.GetContext(); auto idx = node->GetIndex(); const auto valueType = Type::getInt128Ty(context); - const auto firstPtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(Type::getInt32Ty(context), idx)}, "first_ptr", block); - const auto secondPtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(Type::getInt32Ty(context), ++idx)}, "second_ptr", block); + const auto firstPtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(Type::getInt32Ty(context), idx)}, "first_ptr", block); + const auto secondPtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(Type::getInt32Ty(context), ++idx)}, "second_ptr", block); const auto value = DoGenerateGetValue(ctx, firstPtr, secondPtr, block); if (value->getType()->isPointerTy()) { @@ -2255,8 +2477,8 @@ Y_NO_INLINE Value* TPairStateFlowCodegeneratorNodeBase::CreateGetValueImpl( } } -Y_NO_INLINE Value* TBinaryCodegeneratorNodeBase::CreateGetValueImpl(const IComputationNode* node, - const TCodegenContext& ctx, BasicBlock*& block) const { +Y_NO_INLINE Value* TBinaryCodegeneratorNodeBase::CreateGetValueImpl( + const IComputationNode* node, const TCodegenContext& ctx, BasicBlock*& block) const { const auto value = DoGenerateGetValue(ctx, block); if (value->getType()->isPointerTy()) { ValueRelease(node->GetRepresentation(), value, ctx, block); @@ -2281,16 +2503,19 @@ Y_NO_INLINE Value* TMutableCodegeneratorNodeBase::CreateGetValueImpl( } } - return ctx.AlwaysInline ? MakeGetValueBody(representation, valueIndex, ctx, block) : - CallInst::Create(GenerateInternalGetValue(name, representation, valueIndex, ctx.Codegen), {ctx.Ctx}, "getter", block); + return ctx.AlwaysInline + ? MakeGetValueBody(representation, valueIndex, ctx, block) + : CallInst::Create( + GenerateInternalGetValue(name, representation, valueIndex, ctx.Codegen), {ctx.Ctx}, "getter", block); } -Function* TMutableCodegeneratorNodeBase::GenerateInternalGetValue(const TString& name, - EValueRepresentation representation, ui32 valueIndex, NYql::NCodegen::ICodegen& codegen) const { +Function* TMutableCodegeneratorNodeBase::GenerateInternalGetValue( + const TString& name, EValueRepresentation representation, ui32 valueIndex, NYql::NCodegen::ICodegen& codegen) const { auto& module = codegen.GetModule(); auto& context = codegen.GetContext(); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } const auto funcType = FunctionType::get(Type::getInt128Ty(context), {PointerType::getUnqual(GetCompContextType(context))}, false); @@ -2309,11 +2534,14 @@ Function* TMutableCodegeneratorNodeBase::GenerateInternalGetValue(const TString& return ctx.Func; } -Value* TMutableCodegeneratorNodeBase::MakeGetValueBody(EValueRepresentation representation, ui32 valueIndex, const TCodegenContext& ctx, BasicBlock*& block) const { +Value* TMutableCodegeneratorNodeBase::MakeGetValueBody(EValueRepresentation representation, ui32 valueIndex, + const TCodegenContext& ctx, BasicBlock*& block) const { auto& context = ctx.Codegen.GetContext(); const auto indexType = Type::getInt32Ty(context); const auto valueType = Type::getInt128Ty(context); - const auto valuePtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(indexType, valueIndex)}, "value_ptr", block); + const auto valuePtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(indexType, valueIndex)}, "value_ptr", block); const auto value = new LoadInst(valueType, valuePtr, "value", block); const auto invv = ConstantInt::get(value->getType(), 0xFFFFFFFFFFFFFFFFULL); @@ -2350,9 +2578,9 @@ Y_NO_INLINE Value* TMutableCodegeneratorPtrNodeBase::CreateGetValueImpl( const TString& name, const TCodegenContext& ctx, BasicBlock*& block) const { if (stateless) { const auto type = Type::getInt128Ty(ctx.Codegen.GetContext()); - const auto pointer = ctx.Func->getEntryBlock().empty() ? - new AllocaInst(type, 0U, "output", &ctx.Func->getEntryBlock()): - new AllocaInst(type, 0U, "output", &ctx.Func->getEntryBlock().back()); + const auto pointer = ctx.Func->getEntryBlock().empty() + ? new AllocaInst(type, 0U, "output", &ctx.Func->getEntryBlock()) + : new AllocaInst(type, 0U, "output", &ctx.Func->getEntryBlock().back()); DoGenerateGetValue(ctx, pointer, block); ValueRelease(representation, pointer, ctx, block); @@ -2360,15 +2588,18 @@ Y_NO_INLINE Value* TMutableCodegeneratorPtrNodeBase::CreateGetValueImpl( return load; } - return ctx.AlwaysInline ? MakeGetValueBody(valueIndex, ctx, block) : - CallInst::Create(GenerateInternalGetValue(name, valueIndex, ctx.Codegen), {ctx.Ctx}, "getter", block); + return ctx.AlwaysInline + ? MakeGetValueBody(valueIndex, ctx, block) + : CallInst::Create(GenerateInternalGetValue(name, valueIndex, ctx.Codegen), {ctx.Ctx}, "getter", block); } Value* TMutableCodegeneratorPtrNodeBase::MakeGetValueBody(ui32 valueIndex, const TCodegenContext& ctx, BasicBlock*& block) const { auto& context = ctx.Codegen.GetContext(); const auto indexType = Type::getInt32Ty(context); const auto valueType = Type::getInt128Ty(context); - const auto valuePtr = GetElementPtrInst::CreateInBounds(valueType, ctx.GetMutables(), {ConstantInt::get(indexType, valueIndex)}, "value_ptr", block); + const auto valuePtr = GetElementPtrInst::CreateInBounds( + valueType, ctx.GetMutables(), + {ConstantInt::get(indexType, valueIndex)}, "value_ptr", block); const auto value = new LoadInst(valueType, valuePtr, "value", block); const auto invv = ConstantInt::get(value->getType(), 0xFFFFFFFFFFFFFFFFULL); @@ -2391,11 +2622,13 @@ Value* TMutableCodegeneratorPtrNodeBase::MakeGetValueBody(ui32 valueIndex, const return result; } -Function* TMutableCodegeneratorPtrNodeBase::GenerateInternalGetValue(const TString& name, ui32 valueIndex, NYql::NCodegen::ICodegen& codegen) const { +Function* TMutableCodegeneratorPtrNodeBase::GenerateInternalGetValue( + const TString& name, ui32 valueIndex, NYql::NCodegen::ICodegen& codegen) const { auto& module = codegen.GetModule(); auto& context = codegen.GetContext(); - if (const auto f = module.getFunction(name.c_str())) + if (const auto f = module.getFunction(name.c_str())) { return f; + } const auto contextType = GetCompContextType(context); @@ -2422,7 +2655,8 @@ Y_NO_INLINE Value* TMutableCodegeneratorFallbackNodeBase::DoGenerateGetValueImpl const auto type = Type::getInt128Ty(context); const auto ptrType = PointerType::getUnqual(StructType::get(context)); const auto doFunc = ConstantInt::get(Type::getInt64Ty(context), methodPtr); - const auto self = CastInst::Create(Instruction::IntToPtr, ConstantInt::get(Type::getInt64Ty(context), thisPtr), ptrType, "self", block); + const auto self = CastInst::Create(Instruction::IntToPtr, + ConstantInt::get(Type::getInt64Ty(context), thisPtr), ptrType, "self", block); const auto funType = FunctionType::get(type, {self->getType(), ctx.Ctx->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}, "value", block); @@ -2434,8 +2668,9 @@ Y_NO_INLINE Function* TCodegeneratorRootNodeBase::GenerateGetValueImpl( auto& module = codegen.GetModule(); auto& context = codegen.GetContext(); - 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 contextType = GetCompContextType(context); @@ -2459,7 +2694,7 @@ Y_NO_INLINE Function* TCodegeneratorRootNodeBase::GenerateGetValueImpl( return ctx.Func; } -#if __clang__ && (__clang_major__ < 16) + #if __clang__ && (__clang_major__ < 16) TSrcLocation TSrcLocation::current() { return {}; } @@ -2475,7 +2710,7 @@ size_t TSrcLocation::line() const { size_t TSrcLocation::column() const { return 0; } -#endif + #endif DISubprogramAnnotator::DISubprogramAnnotator(TCodegenContext& ctx, Function* subprogramFunc, const TSrcLocation& location) : Ctx(ctx) @@ -2519,8 +2754,7 @@ DISubprogram* DISubprogramAnnotator::MakeDISubprogram(const StringRef& name, con name, llvm::StringRef(), file, 0, - subroutineType, 0, llvm::DINode::FlagPrototyped, llvm::DISubprogram::SPFlagDefinition - ); + subroutineType, 0, llvm::DINode::FlagPrototyped, llvm::DISubprogram::SPFlagDefinition); } DIScopeAnnotator::DIScopeAnnotator(DISubprogramAnnotator* subprogramAnnotator, const TSrcLocation& location) @@ -2529,7 +2763,11 @@ DIScopeAnnotator::DIScopeAnnotator(DISubprogramAnnotator* subprogramAnnotator, c { Y_ENSURE(subprogramAnnotator != nullptr); SubprogramAnnotator = subprogramAnnotator; - Scope = SubprogramAnnotator->DebugBuilder->createLexicalBlock(SubprogramAnnotator->Subprogram, SubprogramAnnotator->MakeDIFile(location), location.line(), location.column()); + Scope = SubprogramAnnotator->DebugBuilder->createLexicalBlock( + SubprogramAnnotator->Subprogram, + SubprogramAnnotator->MakeDIFile(location), + location.line(), + location.column()); } Instruction* DIScopeAnnotator::operator()(Instruction* inst, const TSrcLocation& location) const { @@ -2537,6 +2775,6 @@ Instruction* DIScopeAnnotator::operator()(Instruction* inst, const TSrcLocation& return inst; } -} -} +} // namespace NMiniKQL +} // namespace NKikimr #endif |
