Skip to content

Commit cf645ff

Browse files
[DebugInfo]Generate call-site information in swift
This patch adds support for emitting the flag llvm::DINode::FlagAllCallsDescribed when generating LLVM IR from the Swift compiler to get call-site information for swift source code.
1 parent 6aea6ce commit cf645ff

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
284284
void emitPackCountParameter(IRGenFunction &IGF, llvm::Value *Metadata,
285285
SILDebugVariable VarInfo);
286286

287+
/// Return flags which enable debug info emission for call sites, provided
288+
/// that it is supported and enabled.
289+
llvm::DINode::DIFlags getCallSiteRelatedAttrs() const;
290+
287291
/// Return the DIBuilder.
288292
llvm::DIBuilder &getBuilder() { return DBuilder; }
289293

@@ -3042,6 +3046,27 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
30423046
ImportedModules.insert(Imported.importedModule);
30433047
}
30443048

3049+
/// This is effectively \p clang::CGDebugInfo::getCallSiteRelatedAttrs().
3050+
llvm::DINode::DIFlags IRGenDebugInfoImpl::getCallSiteRelatedAttrs() const {
3051+
auto SwiftLangOpts = IGM.Context.LangOpts;
3052+
auto Loader = IGM.getSILModule().getASTContext().getClangModuleLoader();
3053+
auto *Importer = static_cast<ClangImporter *>(&*Loader);
3054+
auto &CGO = Importer->getCodeGenOpts();
3055+
3056+
// Do not generate call site attributes if there is no debug info to be
3057+
// emitted.
3058+
if (CGO.getDebugInfo() == llvm::codegenoptions::NoDebugInfo ||
3059+
CGO.getDebugInfo() == llvm::codegenoptions::LocTrackingOnly)
3060+
return llvm::DINode::FlagZero;
3061+
3062+
// Call site attributes are available in DWARFv5. However, for swift, lldb can
3063+
// accept these attributes as if they were part of DWARFv4.
3064+
if (Opts.DWARFVersion < 4)
3065+
return llvm::DINode::FlagZero;
3066+
3067+
return llvm::DINode::FlagAllCallsDescribed;
3068+
}
3069+
30453070
llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction(SILFunction &SILFn,
30463071
llvm::Function *Fn) {
30473072
auto *DS = SILFn.getDebugScope();
@@ -3193,9 +3218,10 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
31933218
}
31943219

31953220
// Construct the DISubprogram.
3196-
llvm::DISubprogram *SP = DBuilder.createFunction(
3197-
Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags,
3198-
TemplateParameters, Decl, Error);
3221+
llvm::DISubprogram *SP =
3222+
DBuilder.createFunction(Scope, Name, LinkageName, File, Line, DIFnTy,
3223+
ScopeLine, Flags | getCallSiteRelatedAttrs(),
3224+
SPFlags, TemplateParameters, Decl, Error);
31993225

32003226
if (Fn && !Fn->isDeclaration())
32013227
Fn->setSubprogram(SP);

test/DebugInfo/call-site-info.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend -emit-ir -parse-as-library -g -O -module-name S %s -o - | %FileCheck %s
2+
// CHECK: {{[0-9]+}} = distinct !DISubprogram(name: "f", linkageName: {{.*}}, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}}, scopeLine: {{[0-9]+}}, flags: DIFlagAllCallsDescribed
3+
// CHECK: {{[0-9]+}} = distinct !DISubprogram(linkageName: {{.*}}, scope: !{{[0-9]+}}, file: !{{[0-9]+}}, type: !{{[0-9]+}}, flags: {{.*}} DIFlagAllCallsDescribed
4+
5+
public struct S {
6+
public func f() {}
7+
}

0 commit comments

Comments
 (0)