@@ -162,8 +162,8 @@ using TBaseComputation = TStatefulFlowCodegeneratorNode<TWithContextFlowWrapper>
162
162
const std::string_view ContextType;
163
163
};
164
164
165
- class TWithContextWideFlowWrapper : public TStatefulWideFlowComputationNode <TWithContextWideFlowWrapper> {
166
- using TBaseComputation = TStatefulWideFlowComputationNode <TWithContextWideFlowWrapper>;
165
+ class TWithContextWideFlowWrapper : public TStatefulWideFlowCodegeneratorNode <TWithContextWideFlowWrapper> {
166
+ using TBaseComputation = TStatefulWideFlowCodegeneratorNode <TWithContextWideFlowWrapper>;
167
167
public:
168
168
TWithContextWideFlowWrapper (TComputationMutables& mutables, IComputationWideFlowNode* flow,
169
169
const std::string_view& contextType)
@@ -184,11 +184,8 @@ using TBaseComputation = TStatefulWideFlowComputationNode<TWithContextWideFlowWr
184
184
state.Detach (status == EFetchResult::Finish);
185
185
return status;
186
186
}
187
- /*
188
187
#ifndef MKQL_DISABLE_CODEGEN
189
188
ICodegeneratorInlineWideNode::TGenerateResult DoGenGetValues (const TCodegenContext& ctx, Value* statePtr, BasicBlock*& block) const {
190
- Cerr << Flow->DebugString() << Endl;
191
- Y_ABORT("bad");
192
189
auto & context = ctx.Codegen .GetContext ();
193
190
194
191
const auto valueType = Type::getInt128Ty (context);
@@ -198,6 +195,8 @@ using TBaseComputation = TStatefulWideFlowComputationNode<TWithContextWideFlowWr
198
195
199
196
const auto make = BasicBlock::Create (context, " make" , ctx.Func );
200
197
const auto main = BasicBlock::Create (context, " main" , ctx.Func );
198
+ const auto good = BasicBlock::Create (context, " good" , ctx.Func );
199
+ const auto exit = BasicBlock::Create (context, " exit" , ctx.Func );
201
200
202
201
BranchInst::Create (main, make, HasValue (statePtr, block), block);
203
202
block = make;
@@ -207,7 +206,7 @@ using TBaseComputation = TStatefulWideFlowComputationNode<TWithContextWideFlowWr
207
206
const auto makeFunc = ConstantInt::get (Type::getInt64Ty (context), GetMethodPtr (&TWithContextWideFlowWrapper::MakeState));
208
207
const auto makeType = FunctionType::get (Type::getVoidTy (context), {self->getType (), ctx.Ctx ->getType (), statePtr->getType ()}, false );
209
208
const auto makeFuncPtr = CastInst::Create (Instruction::IntToPtr, makeFunc, PointerType::getUnqual (makeType), " function" , block);
210
- CallInst::Create(makeFuncPtr, {self, ctx.Ctx, statePtr}, "", block);
209
+ CallInst::Create (makeType, makeFuncPtr, {self, ctx.Ctx , statePtr}, " " , block);
211
210
BranchInst::Create (main, block);
212
211
213
212
block = main;
@@ -219,35 +218,46 @@ using TBaseComputation = TStatefulWideFlowComputationNode<TWithContextWideFlowWr
219
218
const auto attachFunc = ConstantInt::get (Type::getInt64Ty (context), GetMethodPtr (&TState::Attach));
220
219
const auto attachFuncType = FunctionType::get (Type::getVoidTy (context), { statePtrType }, false );
221
220
const auto attachFuncPtr = CastInst::Create (Instruction::IntToPtr, attachFunc, PointerType::getUnqual (attachFuncType), " attach" , block);
222
- CallInst::Create(attachFuncPtr, { stateArg }, "", block);
221
+ CallInst::Create (attachFuncType, attachFuncPtr, { stateArg }, " " , block);
223
222
224
223
auto getres = GetNodeValues (Flow, ctx, block);
225
- const auto array = new AllocaInst(ArrayType::get(valueType, getres.second.size()), 0U, "array", &ctx.Func->getEntryBlock().back());
226
- auto i = 0 ;
227
- for (auto& getter : getres.second) {
228
- const auto itemPtr = GetElementPtrInst::CreateInBounds(array, {ConstantInt::get(indexType, 0), ConstantInt::get(indexType, i)}, "item_ptr", &ctx.Func->getEntryBlock().back() );
229
- const auto item = getter(ctx, block);
230
- ValueAddRef(EValueRepresentation::Any, item, ctx, block) ;
231
- new StoreInst(item, itemPtr, block);
232
- getter = [itemPtr] (const TCodegenContext& ctx, BasicBlock*& block) {
233
- const auto item = new LoadInst(itemPtr, "item ", block );
234
- ValueRelease(EValueRepresentation::Any, item, ctx, block );
235
- return item;
236
- } ;
237
- ++i ;
224
+
225
+ const auto special = CmpInst::Create (Instruction::ICmp, ICmpInst::ICMP_SLE, getres. first , ConstantInt::get (getres. first -> getType (), static_cast <i32>(EFetchResult::Yield)), " special " , block) ;
226
+
227
+ BranchInst::Create ( exit , good, special, block );
228
+
229
+ block = good ;
230
+
231
+ const auto arrayType = ArrayType::get (valueType, getres. second . size ());
232
+ const auto arrayPtr = new AllocaInst (arrayType, 0U , " array_ptr " , &ctx. Func -> getEntryBlock (). back () );
233
+ Value* array = UndefValue::get (arrayType );
234
+ for ( auto idx = 0U ; idx < getres. second . size (); ++idx) {
235
+ const auto item = getres. second [idx](ctx, block) ;
236
+ array = InsertValueInst::Create (array, item, {idx}, ( TString ( " value_ " ) += ToString (idx)). c_str (), block) ;
238
237
}
238
+ new StoreInst (array, arrayPtr, block);
239
+
240
+ BranchInst::Create (exit , block);
241
+
242
+ block = exit ;
239
243
240
244
const auto finish = CmpInst::Create (Instruction::ICmp, ICmpInst::ICMP_EQ, getres.first , ConstantInt::get (getres.first ->getType (), static_cast <i32>(EFetchResult::Finish)), " finish" , block);
241
245
242
246
const auto detachFunc = ConstantInt::get (Type::getInt64Ty (context), GetMethodPtr (&TState::Detach));
243
247
const auto detachFuncType = FunctionType::get (Type::getVoidTy (context), { statePtrType, finish->getType () }, false );
244
248
const auto detachFuncPtr = CastInst::Create (Instruction::IntToPtr, detachFunc, PointerType::getUnqual (detachFuncType), " detach" , block);
245
- CallInst::Create(detachFuncPtr, { stateArg, finish }, "", block);
249
+ CallInst::Create (detachFuncType, detachFuncPtr, { stateArg, finish }, " " , block);
250
+
251
+ for (auto idx = 0U ; idx < getres.second .size (); ++idx) {
252
+ getres.second [idx] = [idx, arrayPtr, arrayType, indexType, valueType] (const TCodegenContext& ctx, BasicBlock*& block) {
253
+ const auto itemPtr = GetElementPtrInst::CreateInBounds (arrayType, arrayPtr, {ConstantInt::get (indexType, 0 ), ConstantInt::get (indexType, idx)}, (TString (" ptr_" ) += ToString (idx)).c_str (), block);
254
+ return new LoadInst (valueType, itemPtr, (TString (" item_" ) += ToString (idx)).c_str (), block);
255
+ };
256
+ }
246
257
247
258
return getres;
248
259
}
249
260
#endif
250
- */
251
261
private:
252
262
void MakeState (TComputationContext& ctx, NUdf::TUnboxedValue& state) const {
253
263
state = ctx.HolderFactory .Create <TState>(ContextType);
@@ -267,11 +277,10 @@ IComputationNode* WrapWithContext(TCallable& callable, const TComputationNodeFac
267
277
const auto contextTypeData = AS_VALUE (TDataLiteral, callable.GetInput (0 ));
268
278
const auto contextType = contextTypeData->AsValue ().AsStringRef ();
269
279
const auto arg = LocateNode (ctx.NodeLocator , callable, 1 );
270
- if (callable.GetInput ( 1 ). GetStaticType () ->IsFlow ()) {
280
+ if (const auto type = callable.GetType ()-> GetReturnType (); type ->IsFlow ()) {
271
281
if (const auto wide = dynamic_cast <IComputationWideFlowNode*>(arg)) {
272
282
return new TWithContextWideFlowWrapper (ctx.Mutables , wide , contextType);
273
283
} else {
274
- const auto type = callable.GetType ()->GetReturnType ();
275
284
return new TWithContextFlowWrapper (ctx.Mutables , contextType, GetValueRepresentation (type), arg);
276
285
}
277
286
} else {
0 commit comments