Skip to content

Commit 1d28b5c

Browse files
Merge pull request #79308 from rastogishubham/CallSiteSwift
[DebugInfo]Generate call-site information in swift
2 parents bad5adb + c2c5eb1 commit 1d28b5c

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ class IRGenOptions {
296296
/// indexing info.
297297
PathRemapper FilePrefixMap;
298298

299+
/// Indicates whether or not the frontend should generate callsite information
300+
/// in the debug info.
301+
bool DebugCallsiteInfo = false;
302+
299303
/// What level of debug info to generate.
300304
IRGenDebugInfoLevel DebugInfoLevel : 2;
301305

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,6 +2196,10 @@ def cas_backend: Flag<["-"], "cas-backend">,
21962196
Flags<[FrontendOption, NoDriverOption]>,
21972197
HelpText<"Enable using CASBackend for object file output">;
21982198

2199+
def debug_callsite_info: Flag<["-"], "debug-callsite-info">,
2200+
Flags<[FrontendOption, NoDriverOption]>,
2201+
HelpText<"Generate callsite information in debug info">;
2202+
21992203
def cas_backend_mode: Joined<["-"], "cas-backend-mode=">,
22002204
Flags<[FrontendOption, NoDriverOption]>,
22012205
HelpText<"CASBackendMode for output kind">,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,6 +3693,8 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
36933693
Opts.UseCASBackend |= Args.hasArg(OPT_cas_backend);
36943694
Opts.EmitCASIDFile |= Args.hasArg(OPT_cas_emit_casid_file);
36953695

3696+
Opts.DebugCallsiteInfo |= Args.hasArg(OPT_debug_callsite_info);
3697+
36963698
return false;
36973699
}
36983700

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 35 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,33 @@ 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+
3052+
// Do not generate callsite attributes if unless the -gen-callsite-info flag
3053+
// is passed.
3054+
if (!Opts.DebugCallsiteInfo)
3055+
return llvm::DINode::FlagZero;
3056+
3057+
auto SwiftLangOpts = IGM.Context.LangOpts;
3058+
auto Loader = IGM.getSILModule().getASTContext().getClangModuleLoader();
3059+
auto *Importer = static_cast<ClangImporter *>(&*Loader);
3060+
auto &CGO = Importer->getCodeGenOpts();
3061+
3062+
// Do not generate callsite attributes if there is no debug info to be
3063+
// emitted.
3064+
if (CGO.getDebugInfo() == llvm::codegenoptions::NoDebugInfo ||
3065+
CGO.getDebugInfo() == llvm::codegenoptions::LocTrackingOnly)
3066+
return llvm::DINode::FlagZero;
3067+
3068+
// Callsite attributes are available in DWARFv5. However, for swift, lldb can
3069+
// accept these attributes as if they were part of DWARFv4.
3070+
if (Opts.DWARFVersion < 4)
3071+
return llvm::DINode::FlagZero;
3072+
3073+
return llvm::DINode::FlagAllCallsDescribed;
3074+
}
3075+
30453076
llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction(SILFunction &SILFn,
30463077
llvm::Function *Fn) {
30473078
auto *DS = SILFn.getDebugScope();
@@ -3193,9 +3224,10 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
31933224
}
31943225

31953226
// Construct the DISubprogram.
3196-
llvm::DISubprogram *SP = DBuilder.createFunction(
3197-
Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags,
3198-
TemplateParameters, Decl, Error);
3227+
llvm::DISubprogram *SP =
3228+
DBuilder.createFunction(Scope, Name, LinkageName, File, Line, DIFnTy,
3229+
ScopeLine, Flags | getCallSiteRelatedAttrs(),
3230+
SPFlags, TemplateParameters, Decl, Error);
31993231

32003232
if (Fn && !Fn->isDeclaration())
32013233
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 -debug-callsite-info -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)