Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions tslang/lib/TypeScript/MLIRGenCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5193,6 +5193,29 @@ namespace mlirgen
return mlir::failed(result) ? mlir::failure() : mlir::success();
}

// The calls through a value in the specializations of a helper made from source (`___any_key<...>`,
// `___any_invoke<...>`) are the adapter's (ANY_CALL_ADAPTER_CALL_ATTR_NAME). The helpers are functions of the
// module's own, so only its top-level functions are looked at, and one marked already is passed over: walking
// every op of the module after each `x[k]` or call of an `any` made a function of many of them quadratic
// (binaryArithmeticControlFlowGraphNotTooLarge, 1300 lines: 45 s, near the sweep's time limit)
void MLIRGenImpl::markAnyAdapterCalls(StringRef namePrefix)
{
for (auto funcOp : theModule.getOps<mlir_ts::FuncOp>())
{
if (!funcOp.getName().starts_with(namePrefix))
{
continue;
}

funcOp.walk([&](mlir_ts::CallIndirectOp callOp) {
if (!callOp->hasAttr(ANY_CALL_ADAPTER_CALL_ATTR_NAME))
{
callOp->setAttr(ANY_CALL_ADAPTER_CALL_ATTR_NAME, builder.getUnitAttr());
}
});
}
}

// `a(x, y)` of `a: any`: `__any_invoke(a, [<any>x, <any>y])`, which calls the adapter of the function `a`
// holds (TYPE_DESCR_CALL): the result is `any`, a value that is no function a TypeError
ValueOrLogicalResult MLIRGenImpl::mlirGenAnyCall(mlir::Location location, mlir::Value callee, CallExpression callExpression,
Expand Down Expand Up @@ -5259,14 +5282,7 @@ namespace mlirgen

// the one call through a value in `__any_invoke` is the adapter's: it returns what the adapter returns,
// a box its caller owns (OwnedReturnConsumptionPass) - counted as a call of nothing known, it leaked
theModule.walk([&](mlir_ts::FuncOp funcOp) {
if (funcOp.getName().starts_with("___any_invoke<"))
{
funcOp.walk([&](mlir_ts::CallIndirectOp callOp) {
callOp->setAttr(ANY_CALL_ADAPTER_CALL_ATTR_NAME, builder.getUnitAttr());
});
}
});
markAnyAdapterCalls("___any_invoke<");

return result;
}
Expand Down Expand Up @@ -5944,14 +5960,7 @@ namespace mlirgen

// the one call through a value in `__any_key` is the adapter's: it returns what the adapter returns, a box
// its caller owns (OwnedReturnConsumptionPass)
theModule.walk([&](mlir_ts::FuncOp funcOp) {
if (funcOp.getName().starts_with("___any_key<"))
{
funcOp.walk([&](mlir_ts::CallIndirectOp callOp) {
callOp->setAttr(ANY_CALL_ADAPTER_CALL_ATTR_NAME, builder.getUnitAttr());
});
}
});
markAnyAdapterCalls("___any_key<");

if (op == ANY_KEYS_OP_HAS)
{
Expand Down
14 changes: 14 additions & 0 deletions tslang/lib/TypeScript/MLIRGenGenerics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,20 @@ namespace mlirgen
return {mlir::failure(), mlir_ts::FunctionType(), ""};
}

// A discovery pass (dummyRun) whose module is thrown away needs the instance's type only, and an
// instance made already has it in the function map: its module does not keep the function, so
// mlirGenFunctionLikeDeclaration found none and made it again - for each call. Every `x[k]` of an
// `any` made `___any_key<any>` (and its `___unbox`es) again in each such pass: a function of 1300
// lines of them took 45 s (binaryArithmeticControlFlowGraphNotTooLarge). Its type arguments given,
// the type is the one the real pass makes the instance with.
if (genericTypeGenContext.dummyRun && typeArguments && typeArguments.size() == typeParams.size())
{
if (auto funcEntry = lookupFunctionMap(name))
{
return {mlir::success(), funcEntry.funcType, fullName};
}
}

// `f<T>` calling `f<T[]>` would make instances without end
if (functionGenericTypeInfo->processing.size() >= MAX_NESTED_GENERIC_INSTANCES)
{
Expand Down
2 changes: 2 additions & 0 deletions tslang/lib/TypeScript/MLIRGenImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13388,6 +13388,8 @@ class MLIRGenImpl

// A call of a value of type `any` (user ruling 11-18): through the adapter made for the function's
// type when it was boxed (TYPE_DESCR_CALL); a TypeError when it holds no function, or one with none
void markAnyAdapterCalls(StringRef namePrefix);

ValueOrLogicalResult mlirGenAnyCall(mlir::Location location, mlir::Value callee, CallExpression callExpression,
const GenContext &genContext);

Expand Down
Loading
Loading