@@ -132,6 +132,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
132
132
llvm::DenseMap<TypeBase *, llvm::TrackingMDNodeRef> DITypeCache;
133
133
llvm::DenseMap<const void *, llvm::TrackingMDNodeRef> DIModuleCache;
134
134
llvm::StringMap<llvm::TrackingMDNodeRef> DIFileCache;
135
+ llvm::StringMap<llvm::TrackingMDNodeRef> RuntimeErrorFnCache;
135
136
TrackingDIRefMap DIRefMap;
136
137
TrackingDIRefMap InnerTypeCache;
137
138
// / \}
@@ -2109,13 +2110,20 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
2109
2110
2110
2111
llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType (nullptr );
2111
2112
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
+ }
2119
2127
2120
2128
ScopeCache[TrapSc] = llvm::TrackingMDNodeRef (TrapSP);
2121
2129
LastScope = TrapSc;
0 commit comments