Unique the debug info function declarations for Swift runtime failure messages.

This reduces the size of the debug info of (random benchmark)
_StringProcessing.o by 1600 bytes. Modules with more arithmetic should
benefit more.

rdar://94060085
This commit is contained in:
Adrian Prantl
2022-06-14 16:49:51 -07:00
parent 30cb7a20c3
commit 92d7e63306
2 changed files with 25 additions and 7 deletions

View File

@@ -132,6 +132,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
llvm::DenseMap<TypeBase *, llvm::TrackingMDNodeRef> DITypeCache;
llvm::DenseMap<const void *, llvm::TrackingMDNodeRef> DIModuleCache;
llvm::StringMap<llvm::TrackingMDNodeRef> DIFileCache;
llvm::StringMap<llvm::TrackingMDNodeRef> RuntimeErrorFnCache;
TrackingDIRefMap DIRefMap;
TrackingDIRefMap InnerTypeCache;
/// \}
@@ -2109,13 +2110,20 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(nullptr);
std::string FuncName = "Swift runtime failure: ";
FuncName += failureMsg;
llvm::DISubprogram *TrapSP = DBuilder.createFunction(
MainModule, FuncName, StringRef(), TrapLoc->getFile(), 0, DIFnTy, 0,
llvm::DINode::FlagArtificial, llvm::DISubprogram::SPFlagDefinition,
nullptr, nullptr, nullptr);
llvm::DISubprogram *TrapSP;
auto It = RuntimeErrorFnCache.find(failureMsg);
if (It != RuntimeErrorFnCache.end())
TrapSP = llvm::cast<llvm::DISubprogram>(It->second);
else {
std::string FuncName = "Swift runtime failure: ";
FuncName += failureMsg;
llvm::DIFile *File = getOrCreateFile({});
TrapSP = DBuilder.createFunction(
File, FuncName, StringRef(), File, 0,
DIFnTy, 0, llvm::DINode::FlagArtificial,
llvm::DISubprogram::SPFlagDefinition, nullptr, nullptr, nullptr);
RuntimeErrorFnCache.insert({failureMsg, llvm::TrackingMDNodeRef(TrapSP)});
}
ScopeCache[TrapSc] = llvm::TrackingMDNodeRef(TrapSP);
LastScope = TrapSc;

View File

@@ -0,0 +1,10 @@
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
public func f(_ input: Int) -> Int {
return input * 2 + 1
}
// CHECK: distinct !DISubprogram(name: "Swift runtime failure: arithmetic overflow"
// CHECK-SAME: scope: ![[FILE:[0-9]+]]
// CHECK-SAME: file: ![[FILE]]
// CHECK-NOT: "Swift runtime failure: arithmetic overflow"