Skip to content

Commit bc2bb5b

Browse files
authored
Merge pull request swiftlang#62771 from eeckstein/debug-info
Some small debug-info fixes
2 parents d3c3d87 + 0c6f0bb commit bc2bb5b

21 files changed

+79
-60
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ class IntegerLiteralExpr : public NumberLiteralExpr {
741741
/// \p value The integer value.
742742
/// \return An implicit integer literal expression which evaluates to the value.
743743
static IntegerLiteralExpr *
744-
createFromUnsigned(ASTContext &C, unsigned value);
744+
createFromUnsigned(ASTContext &C, unsigned value, SourceLoc loc);
745745

746746
/// Returns the value of the literal, appropriately constructed in the
747747
/// target type.

include/swift/SIL/SILBuilder.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ class SILBuilder {
263263
bool hasValidInsertionPoint() const { return BB != nullptr; }
264264
SILBasicBlock *getInsertionBB() const { return BB; }
265265
SILBasicBlock::iterator getInsertionPoint() const { return InsertPt; }
266-
SILLocation getInsertionPointLoc() const { return InsertPt->getLoc(); }
266+
SILLocation getInsertionPointLoc() const {
267+
assert(!insertingAtEndOfBlock());
268+
return InsertPt->getLoc();
269+
}
267270

268271
/// insertingAtEndOfBlock - Return true if the insertion point is at the end
269272
/// of the current basic block. False if we're inserting before an existing

lib/AST/Expr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,11 +1039,11 @@ StringRef LiteralExpr::getLiteralKindDescription() const {
10391039
llvm_unreachable("Unhandled literal");
10401040
}
10411041

1042-
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value) {
1042+
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value, SourceLoc loc) {
10431043
llvm::SmallString<8> Scratch;
10441044
llvm::APInt(sizeof(unsigned)*8, value).toString(Scratch, 10, /*signed*/ false);
10451045
auto Text = C.AllocateCopy(StringRef(Scratch));
1046-
return new (C) IntegerLiteralExpr(Text, SourceLoc(), /*implicit*/ true);
1046+
return new (C) IntegerLiteralExpr(Text, loc, /*implicit*/ true);
10471047
}
10481048

10491049
APInt IntegerLiteralExpr::getRawValue() const {

lib/SIL/IR/SILPrinter.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,10 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
10121012
if (!DL.filename.empty()) {
10131013
if (PrintComma)
10141014
*this << ", ";
1015-
*this << "loc " << QuotedString(DL.filename) << ':' << DL.line << ':'
1015+
*this << "loc ";
1016+
if (Loc.isAutoGenerated())
1017+
*this << "* ";
1018+
*this << QuotedString(DL.filename) << ':' << DL.line << ':'
10161019
<< (unsigned)DL.column;
10171020
}
10181021
}
@@ -3012,7 +3015,14 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
30123015
}
30133016
}
30143017

3015-
OS << "// " << demangleSymbol(getName()) << '\n';
3018+
OS << "// " << demangleSymbol(getName());
3019+
if (PrintCtx.printDebugInfo()) {
3020+
auto &SM = getModule().getASTContext().SourceMgr;
3021+
SILPrinter P(PrintCtx);
3022+
P.printDebugLocRef(getLocation(), SM);
3023+
P.printDebugScopeRef(getDebugScope(), SM);
3024+
}
3025+
OS << '\n';
30163026
printClangQualifiedNameCommentIfPresent(OS, getClangDecl());
30173027

30183028
OS << "sil ";

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,12 @@ bool SILParser::parseSILLocation(SILLocation &Loc) {
21172117
if (parseVerbatim("loc"))
21182118
return true;
21192119

2120+
bool isAutoGenerated = false;
2121+
if (P.Tok.isAnyOperator() && P.Tok.getText().startswith("*")) {
2122+
isAutoGenerated = true;
2123+
P.consumeStartingCharacterOfCurrentToken();
2124+
}
2125+
21202126
if (P.Tok.getKind() != tok::string_literal) {
21212127
P.diagnose(P.Tok, diag::expected_tok_in_sil_instr, "string");
21222128
return true;
@@ -2140,7 +2146,7 @@ bool SILParser::parseSILLocation(SILLocation &Loc) {
21402146

21412147
Loc = RegularLocation(fnl);
21422148

2143-
if (*fnl == *SILLocation::getCompilerGeneratedLoc())
2149+
if (isAutoGenerated)
21442150
Loc.markAutoGenerated();
21452151

21462152
return false;

lib/SILOptimizer/Transforms/ARCCodeMotion.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class CodeMotionContext {
161161
RCIdentityFunctionInfo *RCFI;
162162

163163
/// All the unique refcount roots retained or released in the function.
164-
llvm::SetVector<SILValue> RCRootVault;
164+
llvm::SmallVector<SILValue, 16> RCRootVault;
165165

166166
/// Contains a map between RC roots to their index in the RCRootVault.
167167
/// used to facilitate fast RC roots to index lookup.
@@ -413,7 +413,7 @@ void RetainCodeMotionContext::initializeCodeMotionDataFlow() {
413413
if (RCRootIndex.find(Root) != RCRootIndex.end())
414414
continue;
415415
RCRootIndex[Root] = RCRootVault.size();
416-
RCRootVault.insert(Root);
416+
RCRootVault.push_back(Root);
417417
LLVM_DEBUG(llvm::dbgs()
418418
<< "Retain Root #" << RCRootVault.size() << " " << Root);
419419
}
@@ -801,7 +801,7 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
801801
if (RCRootIndex.find(Root) != RCRootIndex.end())
802802
continue;
803803
RCRootIndex[Root] = RCRootVault.size();
804-
RCRootVault.insert(Root);
804+
RCRootVault.push_back(Root);
805805
LLVM_DEBUG(llvm::dbgs()
806806
<< "Release Root #" << RCRootVault.size() << " " << Root);
807807
}

lib/SILOptimizer/Transforms/StringOptimization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ SILValue StringOptimization::copyValue(SILValue value, SILInstruction *before) {
681681
/// Creates a call to a string initializer.
682682
ApplyInst *StringOptimization::createStringInit(StringRef str,
683683
SILInstruction *beforeInst) {
684-
SILBuilder builder(beforeInst);
684+
SILBuilderWithScope builder(beforeInst);
685685
SILLocation loc = beforeInst->getLoc();
686686
SILModule &module = beforeInst->getFunction()->getModule();
687687
ASTContext &ctxt = module.getASTContext();

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class SILInlineCloner
285285
/// This location wraps the call site AST node that is being inlined.
286286
/// Alternatively, it can be the SIL file location of the call site (in case
287287
/// of SIL-to-SIL transformations).
288-
Optional<SILLocation> Loc;
288+
SILLocation Loc;
289289
const SILDebugScope *CallSiteScope = nullptr;
290290
llvm::SmallDenseMap<const SILDebugScope *, const SILDebugScope *, 8>
291291
InlinedScopeCache;
@@ -338,9 +338,7 @@ class SILInlineCloner
338338
return InLoc;
339339
// Inlined location wraps the call site that is being inlined, regardless
340340
// of the input location.
341-
return Loc.has_value()
342-
? Loc.value()
343-
: MandatoryInlinedLocation();
341+
return Loc;
344342
}
345343

346344
const SILDebugScope *remapScope(const SILDebugScope *DS) {
@@ -387,6 +385,16 @@ SILInliner::inlineFullApply(FullApplySite apply,
387385
appliedArgs);
388386
}
389387

388+
static SILLocation selectLoc(bool mandatory, SILLocation orig) {
389+
// Compute the SILLocation which should be used by all the inlined
390+
// instructions.
391+
if (mandatory)
392+
return MandatoryInlinedLocation(orig);
393+
else {
394+
return InlinedLocation(orig);
395+
}
396+
}
397+
390398
SILInlineCloner::SILInlineCloner(
391399
SILFunction *calleeFunction, FullApplySite apply,
392400
SILOptFunctionBuilder &funcBuilder, InlineKind inlineKind,
@@ -395,7 +403,8 @@ SILInlineCloner::SILInlineCloner(
395403
: SuperTy(*apply.getFunction(), *calleeFunction, applySubs,
396404
/*DT=*/nullptr, /*Inlining=*/true),
397405
FuncBuilder(funcBuilder), IKind(inlineKind), Apply(apply),
398-
deleter(deleter) {
406+
deleter(deleter),
407+
Loc(selectLoc(inlineKind == InlineKind::MandatoryInline, apply.getLoc())) {
399408

400409
SILFunction &F = getBuilder().getFunction();
401410
assert(apply.getFunction() && apply.getFunction() == &F
@@ -408,15 +417,6 @@ SILInlineCloner::SILInlineCloner(
408417
&& "Cannot inline Objective-C methods or C functions in mandatory "
409418
"inlining");
410419

411-
// Compute the SILLocation which should be used by all the inlined
412-
// instructions.
413-
if (IKind == InlineKind::PerformanceInline)
414-
Loc = InlinedLocation(apply.getLoc());
415-
else {
416-
assert(IKind == InlineKind::MandatoryInline && "Unknown InlineKind.");
417-
Loc = MandatoryInlinedLocation(apply.getLoc());
418-
}
419-
420420
auto applyScope = apply.getDebugScope();
421421
// FIXME: Turn this into an assertion instead.
422422
if (!applyScope)
@@ -436,7 +436,7 @@ SILInlineCloner::SILInlineCloner(
436436
assert(CallSiteScope->getParentFunction() == &F);
437437

438438
// Set up the coroutine-specific inliner if applicable.
439-
BeginApply = BeginApplySite::get(apply, Loc.value(), &getBuilder());
439+
BeginApply = BeginApplySite::get(apply, Loc, &getBuilder());
440440
}
441441

442442
// Clone the entire callee function into the caller function at the apply site.

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ namespace {
29392939

29402940
// Make the integer literals for the parameters.
29412941
auto buildExprFromUnsigned = [&](unsigned value) {
2942-
LiteralExpr *expr = IntegerLiteralExpr::createFromUnsigned(ctx, value);
2942+
LiteralExpr *expr = IntegerLiteralExpr::createFromUnsigned(ctx, value, loc);
29432943
cs.setType(expr, ctx.getIntType());
29442944
return handleIntegerLiteralExpr(expr);
29452945
};

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ deriveBodyHashable_enum_hasAssociatedValues_hashInto(
716716

717717
{
718718
// Generate: hasher.combine(<ordinal>)
719-
auto ordinalExpr = IntegerLiteralExpr::createFromUnsigned(C, index++);
719+
auto ordinalExpr = IntegerLiteralExpr::createFromUnsigned(C, index++, SourceLoc());
720720
auto combineExpr = createHasherCombineCall(C, hasherParam, ordinalExpr);
721721
statements.emplace_back(ASTNode(combineExpr));
722722
}

0 commit comments

Comments
 (0)