@@ -132,6 +132,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
132132 llvm::DenseMap<TypeBase *, llvm::TrackingMDNodeRef> DITypeCache;
133133 llvm::DenseMap<const void *, llvm::TrackingMDNodeRef> DIModuleCache;
134134 llvm::StringMap<llvm::TrackingMDNodeRef> DIFileCache;
135+ llvm::StringMap<llvm::TrackingMDNodeRef> RuntimeErrorFnCache;
135136 TrackingDIRefMap DIRefMap;
136137 TrackingDIRefMap InnerTypeCache;
137138 // / \}
@@ -2109,13 +2110,20 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
21092110
21102111 llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType (nullptr );
21112112
2112- std::string FuncName = " Swift runtime failure: " ;
2113- FuncName += failureMsg;
2114-
2115- llvm::DISubprogram *TrapSP = DBuilder.createFunction (
2116- MainModule, FuncName, StringRef (), TrapLoc->getFile (), 0 , DIFnTy, 0 ,
2117- llvm::DINode::FlagArtificial, llvm::DISubprogram::SPFlagDefinition,
2118- nullptr , nullptr , nullptr );
2113+ llvm::DISubprogram *TrapSP;
2114+ auto It = RuntimeErrorFnCache.find (failureMsg);
2115+ if (It != RuntimeErrorFnCache.end ())
2116+ TrapSP = llvm::cast<llvm::DISubprogram>(It->second );
2117+ else {
2118+ std::string FuncName = " Swift runtime failure: " ;
2119+ FuncName += failureMsg;
2120+ llvm::DIFile *File = getOrCreateFile ({});
2121+ TrapSP = DBuilder.createFunction (
2122+ File, FuncName, StringRef (), File, 0 ,
2123+ DIFnTy, 0 , llvm::DINode::FlagArtificial,
2124+ llvm::DISubprogram::SPFlagDefinition, nullptr , nullptr , nullptr );
2125+ RuntimeErrorFnCache.insert ({failureMsg, llvm::TrackingMDNodeRef (TrapSP)});
2126+ }
21192127
21202128 ScopeCache[TrapSc] = llvm::TrackingMDNodeRef (TrapSP);
21212129 LastScope = TrapSc;
0 commit comments