Skip to content

Commit 460e55a

Browse files
authored
Merge pull request #3236 from adrian-prantl/26955467
2 parents e920ddc + 935b702 commit 460e55a

File tree

10 files changed

+60
-19
lines changed

10 files changed

+60
-19
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ Address IRGenFunction::getErrorResultSlot(SILType errorType) {
18901890
if (!ErrorResultSlot) {
18911891
auto &errorTI = cast<FixedTypeInfo>(getTypeInfo(errorType));
18921892

1893-
IRBuilder builder(IGM.getLLVMContext());
1893+
IRBuilder builder(IGM.getLLVMContext(), IGM.DebugInfo);
18941894
builder.SetInsertPoint(AllocaIP->getParent(), AllocaIP->getIterator());
18951895

18961896
// Create the alloca. We don't use allocateStack because we're

lib/IRGen/GenDecl.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,16 @@ void IRGenModule::emitRuntimeRegistration() {
573573
{
574574
llvm::BasicBlock *EntryBB = &EntryFunction->getEntryBlock();
575575
llvm::BasicBlock::iterator IP = EntryBB->getFirstInsertionPt();
576-
IRBuilder Builder(getLLVMContext());
576+
IRBuilder Builder(getLLVMContext(), DebugInfo);
577577
Builder.llvm::IRBuilderBase::SetInsertPoint(EntryBB, IP);
578+
if (DebugInfo)
579+
DebugInfo->setEntryPointLoc(Builder);
578580
Builder.CreateCall(RegistrationFunction, {});
579581
}
580582

581583
IRGenFunction RegIGF(*this, RegistrationFunction);
584+
if (DebugInfo)
585+
DebugInfo->emitArtificialFunction(RegIGF, RegistrationFunction);
582586

583587
// Register ObjC protocols, classes, and extensions we added.
584588
if (ObjCInterop) {
@@ -1004,12 +1008,17 @@ void IRGenModule::emitTypeVerifier() {
10041008
{
10051009
llvm::BasicBlock *EntryBB = &EntryFunction->getEntryBlock();
10061010
llvm::BasicBlock::iterator IP = EntryBB->getFirstInsertionPt();
1007-
IRBuilder Builder(getLLVMContext());
1011+
IRBuilder Builder(getLLVMContext(), DebugInfo);
10081012
Builder.llvm::IRBuilderBase::SetInsertPoint(EntryBB, IP);
1013+
if (DebugInfo)
1014+
DebugInfo->setEntryPointLoc(Builder);
10091015
Builder.CreateCall(VerifierFunction, {});
10101016
}
10111017

10121018
IRGenFunction VerifierIGF(*this, VerifierFunction);
1019+
if (DebugInfo)
1020+
DebugInfo->emitArtificialFunction(VerifierIGF, VerifierFunction);
1021+
10131022
emitTypeLayoutVerifier(VerifierIGF, TypesToVerify);
10141023
VerifierIGF.Builder.CreateRetVoid();
10151024
}

lib/IRGen/GenFunc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,8 @@ static llvm::Function *emitBlockCopyHelper(IRGenModule &IGM,
14241424
IGM.getModule());
14251425
func->setAttributes(IGM.constructInitialAttributes());
14261426
IRGenFunction IGF(IGM, func);
1427+
if (IGM.DebugInfo)
1428+
IGM.DebugInfo->emitArtificialFunction(IGF, func);
14271429

14281430
// Copy the captures from the source to the destination.
14291431
Explosion params = IGF.collectParameters();
@@ -1459,6 +1461,8 @@ static llvm::Function *emitBlockDisposeHelper(IRGenModule &IGM,
14591461
IGM.getModule());
14601462
func->setAttributes(IGM.constructInitialAttributes());
14611463
IRGenFunction IGF(IGM, func);
1464+
if (IGM.DebugInfo)
1465+
IGM.DebugInfo->emitArtificialFunction(IGF, func);
14621466

14631467
// Destroy the captures.
14641468
Explosion params = IGF.collectParameters();

lib/IRGen/GenMeta.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,6 @@ void irgen::emitLazyCacheAccessFunction(IRGenModule &IGM,
10811081
accessor->setDoesNotAccessMemory();
10821082

10831083
IRGenFunction IGF(IGM, accessor);
1084-
10851084
if (IGM.DebugInfo)
10861085
IGM.DebugInfo->emitArtificialFunction(IGF, accessor);
10871086

lib/IRGen/GenObjC.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "GenProto.h"
4141
#include "GenType.h"
4242
#include "HeapTypeInfo.h"
43+
#include "IRGenDebugInfo.h"
4344
#include "IRGenFunction.h"
4445
#include "IRGenModule.h"
4546
#include "Linking.h"
@@ -810,6 +811,8 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
810811
fwd->setAttributes(updatedAttrs);
811812

812813
IRGenFunction subIGF(IGM, fwd);
814+
if (IGM.DebugInfo)
815+
IGM.DebugInfo->emitArtificialFunction(subIGF, fwd);
813816

814817
// Do we need to lifetime-extend self?
815818
bool lifetimeExtendsSelf;

lib/IRGen/IRBuilder.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class IRBuilder : public IRBuilderBase {
3838
/// ordering.
3939
llvm::BasicBlock *ClearedIP;
4040

41+
/// Whether debug information is requested. Only used in assertions.
42+
bool DebugInfo;
43+
4144
// Set calling convention of the call instruction using
4245
// the same calling convention as the callee function.
4346
// This ensures that they are always compatible.
@@ -50,8 +53,8 @@ class IRBuilder : public IRBuilderBase {
5053
}
5154

5255
public:
53-
IRBuilder(llvm::LLVMContext &Context)
54-
: IRBuilderBase(Context), ClearedIP(nullptr) {}
56+
IRBuilder(llvm::LLVMContext &Context, bool DebugInfo)
57+
: IRBuilderBase(Context), ClearedIP(nullptr), DebugInfo(DebugInfo) {}
5558

5659
/// Determines if the current location is apparently reachable. The
5760
/// invariant we maintain is that the insertion point of the builder
@@ -259,6 +262,7 @@ class IRBuilder : public IRBuilderBase {
259262
llvm::CallInst *CreateCall(llvm::Value *Callee, ArrayRef<llvm::Value *> Args,
260263
const Twine &Name = "",
261264
llvm::MDNode *FPMathTag = nullptr) {
265+
assert((!DebugInfo || getCurrentDebugLocation()) && "no debugloc on call");
262266
auto Call = IRBuilderBase::CreateCall(Callee, Args, Name, FPMathTag);
263267
setCallingConvUsingCallee(Call);
264268
return Call;
@@ -268,6 +272,7 @@ class IRBuilder : public IRBuilderBase {
268272
ArrayRef<llvm::Value *> Args,
269273
const Twine &Name = "",
270274
llvm::MDNode *FPMathTag = nullptr) {
275+
assert((!DebugInfo || getCurrentDebugLocation()) && "no debugloc on call");
271276
auto Call = IRBuilderBase::CreateCall(FTy, Callee, Args, Name, FPMathTag);
272277
setCallingConvUsingCallee(Call);
273278
return Call;
@@ -277,6 +282,7 @@ class IRBuilder : public IRBuilderBase {
277282
ArrayRef<llvm::Value *> Args,
278283
const Twine &Name = "",
279284
llvm::MDNode *FPMathTag = nullptr) {
285+
assert((!DebugInfo || getCurrentDebugLocation()) && "no debugloc on call");
280286
auto Call = IRBuilderBase::CreateCall(Callee, Args, Name, FPMathTag);
281287
setCallingConvUsingCallee(Call);
282288
return Call;

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ void IRGenDebugInfo::setCurrentLoc(IRBuilder &Builder, const SILDebugScope *DS,
337337
Builder.SetCurrentDebugLocation(DL);
338338
}
339339

340+
void IRGenDebugInfo::setEntryPointLoc(IRBuilder &Builder) {
341+
auto DL = llvm::DebugLoc::get(0, 0, getEntryPointFn(), nullptr);
342+
Builder.SetCurrentDebugLocation(DL);
343+
}
344+
340345
llvm::DIScope *IRGenDebugInfo::getOrCreateScope(const SILDebugScope *DS) {
341346
if (DS == 0)
342347
return MainFile;
@@ -482,6 +487,20 @@ static CanSILFunctionType getFunctionType(SILType SILTy) {
482487
return FnTy;
483488
}
484489

490+
llvm::DIScope *IRGenDebugInfo::getEntryPointFn() {
491+
// Lazily create EntryPointFn.
492+
if (!EntryPointFn) {
493+
auto main = IGM.getSILModule().lookUpFunction(SWIFT_ENTRY_POINT_FUNCTION);
494+
assert(main && "emitting TopLevelCodeDecl in module without "
495+
SWIFT_ENTRY_POINT_FUNCTION "?");
496+
EntryPointFn = DBuilder.createReplaceableCompositeType(
497+
llvm::dwarf::DW_TAG_subroutine_type, SWIFT_ENTRY_POINT_FUNCTION,
498+
MainFile, MainFile, 0);
499+
}
500+
return EntryPointFn;
501+
}
502+
503+
485504
llvm::DIScope *IRGenDebugInfo::getOrCreateContext(DeclContext *DC) {
486505
if (!DC)
487506
return TheCU;
@@ -504,17 +523,7 @@ llvm::DIScope *IRGenDebugInfo::getOrCreateContext(DeclContext *DC) {
504523
return getOrCreateContext(DC->getParent());
505524

506525
case DeclContextKind::TopLevelCodeDecl:
507-
// Lazily create EntryPointFn.
508-
if (!EntryPointFn) {
509-
auto main = IGM.getSILModule().lookUpFunction(SWIFT_ENTRY_POINT_FUNCTION);
510-
assert(main && "emitting TopLevelCodeDecl in module without "
511-
SWIFT_ENTRY_POINT_FUNCTION "?");
512-
EntryPointFn = DBuilder.createReplaceableCompositeType(
513-
llvm::dwarf::DW_TAG_subroutine_type, SWIFT_ENTRY_POINT_FUNCTION,
514-
MainFile, MainFile, 0);
515-
}
516-
517-
return cast<llvm::DIScope>(EntryPointFn);
526+
return getEntryPointFn();
518527

519528
case DeclContextKind::Module:
520529
return getOrCreateModule({Module::AccessPathTy(), cast<ModuleDecl>(DC)});

lib/IRGen/IRGenDebugInfo.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class IRGenDebugInfo {
7373
llvm::DICompileUnit *TheCU = nullptr; /// The current compilation unit.
7474
llvm::DIFile *MainFile = nullptr; /// The main file.
7575
llvm::DIModule *MainModule = nullptr; /// The current module.
76-
llvm::MDNode *EntryPointFn = nullptr; /// Scope of SWIFT_ENTRY_POINT_FUNCTION.
76+
llvm::DIScope *EntryPointFn =
77+
nullptr; /// Scope of SWIFT_ENTRY_POINT_FUNCTION.
7778
TypeAliasDecl *MetadataTypeDecl; /// The type decl for swift.type.
7879
llvm::DIType *InternalType; /// Catch-all type for opaque internal types.
7980

@@ -128,6 +129,12 @@ class IRGenDebugInfo {
128129
Builder.SetCurrentDebugLocation(DL);
129130
}
130131

132+
/// Set the location for SWIFT_ENTRY_POINT_FUNCTION.
133+
void setEntryPointLoc(IRBuilder &Builder);
134+
135+
/// Return the scope for SWIFT_ENTRY_POINT_FUNCTION.
136+
llvm::DIScope *getEntryPointFn();
137+
131138
/// Emit debug info for an import declaration.
132139
///
133140
/// The DWARF output for import decls is similar to that of a using

lib/IRGen/IRGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ IRGenFunction::IRGenFunction(IRGenModule &IGM,
3535
llvm::Function *Fn,
3636
const SILDebugScope *DbgScope,
3737
Optional<SILLocation> DbgLoc)
38-
: IGM(IGM), Builder(IGM.getLLVMContext()),
38+
: IGM(IGM), Builder(IGM.getLLVMContext(), IGM.DebugInfo),
3939
CurFn(Fn), DbgScope(DbgScope)
4040
{
4141

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,10 @@ static void emitEntryPointArgumentsCOrObjC(IRGenSILFunction &IGF,
12581258

12591259
assert(params.empty() && "didn't claim all parameters!");
12601260

1261+
// emitPolymorphicParameters() may create function calls, so we need
1262+
// to initialize the debug location here.
1263+
ArtificialLocation Loc(IGF.getDebugScope(), IGF.IGM.DebugInfo, IGF.Builder);
1264+
12611265
// Bind polymorphic arguments. This can only be done after binding
12621266
// all the value parameters, and must be done even for non-polymorphic
12631267
// functions because of imported Objective-C generics.

0 commit comments

Comments
 (0)