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
16 changes: 15 additions & 1 deletion tslang/include/TypeScript/MLIRLogic/MLIRGenStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,20 @@ struct GenericClassInfo
}
};

// what we know about a registered function; deliberately not the FuncOp itself -
// discovery-pass ops are erased with the discovery module, so cached op handles dangle.
// Resolve a live op through theModule.lookupSymbol when one is actually needed.
struct FunctionEntry
{
std::string name;
mlir_ts::FunctionType funcType;

explicit operator bool() const
{
return static_cast<bool>(funcType);
}
};

struct NamespaceInfo
{
public:
Expand All @@ -998,7 +1012,7 @@ struct NamespaceInfo

llvm::StringMap<mlir_ts::FunctionType> functionTypeMap;

llvm::StringMap<mlir_ts::FuncOp> functionMap;
llvm::StringMap<FunctionEntry> functionMap;

llvm::StringMap<GenericFunctionInfo::TypePtr> genericFunctionMap;

Expand Down
28 changes: 17 additions & 11 deletions tslang/lib/TypeScript/MLIRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5312,7 +5312,7 @@ class MLIRGenImpl
auto funcIt = getFunctionMap().find(name);
if (funcIt != getFunctionMap().end())
{
auto cachedFuncType = funcIt->second.getFunctionType();
auto cachedFuncType = funcIt->second.funcType;
if (cachedFuncType.getNumResults() > 0)
{
auto returnType = cachedFuncType.getResult(0);
Expand Down Expand Up @@ -6032,7 +6032,8 @@ class MLIRGenImpl
auto name = funcProto->getNameWithoutNamespace();
if (!getFunctionMap().count(name))
{
getFunctionMap().insert({name, funcOp});
getFunctionMap().insert(
{name, FunctionEntry{funcOp.getName().str(), mlir::cast<mlir_ts::FunctionType>(funcOp.getFunctionType())}});

LLVM_DEBUG(llvm::dbgs() << "\n!! reg. func: " << name << " type:" << funcOp.getFunctionType() << " function name: " << funcProto->getName()
<< " num inputs:" << mlir::cast<mlir_ts::FunctionType>(funcOp.getFunctionType()).getNumInputs()
Expand Down Expand Up @@ -6081,10 +6082,18 @@ class MLIRGenImpl
{
auto [fullFunctionName, functionName] = getNameOfFunction(functionLikeDeclarationBaseAST, funcDeclGenContext);

auto funcOp = lookupFunctionMap(functionName);
if (funcOp && theModule.lookupSymbol(functionName)
auto funcEntry = lookupFunctionMap(functionName);
if (funcEntry && theModule.lookupSymbol(functionName)
|| theModule.lookupSymbol(fullFunctionName))
{
// resolve a live op from the module instead of returning a cached handle;
// the registered symbol is usually the full name
auto funcOp = theModule.lookupSymbol<mlir_ts::FuncOp>(functionName);
if (!funcOp)
{
funcOp = theModule.lookupSymbol<mlir_ts::FuncOp>(fullFunctionName);
}

return {mlir::success(), funcOp, functionName, false};
}
}
Expand Down Expand Up @@ -15966,11 +15975,8 @@ class MLIRGenImpl
auto fn = getFunctionMap().find(name);
if (fn != getFunctionMap().end())
{
auto funcOp = fn->getValue();
auto funcType = funcOp.getFunctionType();
auto funcName = funcOp.getName();

return resolveFunctionWithCapture(location, funcName, funcType, mlir::Value(), false, genContext);
auto &funcEntry = fn->getValue();
return resolveFunctionWithCapture(location, funcEntry.name, funcEntry.funcType, mlir::Value(), false, genContext);
}

return mlir::Value();
Expand Down Expand Up @@ -26273,12 +26279,12 @@ genContext);
lookupLogic(functionTypeMap);
}

auto getFunctionMap() -> llvm::StringMap<mlir_ts::FuncOp> &
auto getFunctionMap() -> llvm::StringMap<FunctionEntry> &
{
return currentNamespace->functionMap;
}

auto lookupFunctionMap(StringRef name) -> mlir_ts::FuncOp
auto lookupFunctionMap(StringRef name) -> FunctionEntry
{
lookupLogic(functionMap);
}
Expand Down
Loading