@@ -162,6 +162,9 @@ namespace {
162
162
using DebugScopeID = DeclID;
163
163
using DebugScopeIDField = DeclIDField;
164
164
165
+ using LocationID = DeclID;
166
+ using LocationIDField = DeclIDField;
167
+
165
168
Serializer &S;
166
169
167
170
llvm::BitstreamWriter &Out;
@@ -226,6 +229,7 @@ namespace {
226
229
227
230
llvm::DenseMap<PointerUnion<const SILDebugScope *, SILFunction *>, DeclID>
228
231
DebugScopeMap;
232
+ llvm::DenseMap<const void *, unsigned > SourceLocMap;
229
233
230
234
// / Give each SILBasicBlock a unique ID.
231
235
llvm::DenseMap<const SILBasicBlock *, unsigned > BasicBlockMap;
@@ -299,6 +303,7 @@ namespace {
299
303
300
304
// / Serialize and write SILDebugScope graph in post order.
301
305
void writeDebugScopes (const SILDebugScope *Scope, const SourceManager &SM);
306
+ void writeSourceLoc (SILLocation SLoc, const SourceManager &SM);
302
307
303
308
void writeNoOperandLayout (const SILInstruction *I) {
304
309
unsigned abbrCode = SILAbbrCodes[SILInstNoOperandLayout::Code];
@@ -600,6 +605,7 @@ void SILSerializer::writeSILFunction(const SILFunction &F, bool DeclOnly) {
600
605
}
601
606
602
607
DebugScopeMap.clear ();
608
+ SourceLocMap.clear ();
603
609
604
610
if (SerializeDebugInfoSIL)
605
611
writeDebugScopes (F.getDebugScope (), F.getModule ().getSourceManager ());
@@ -697,6 +703,9 @@ void SILSerializer::writeSILBasicBlock(const SILBasicBlock &BB) {
697
703
writeDebugScopes (Prev, SM);
698
704
}
699
705
}
706
+ if (SerializeDebugInfoSIL) {
707
+ writeSourceLoc (SI.getLoc (), SM);
708
+ }
700
709
701
710
writeSILInstruction (SI);
702
711
}
@@ -3074,6 +3083,51 @@ void SILSerializer::writeSILProperty(const SILProperty &prop) {
3074
3083
componentValues);
3075
3084
}
3076
3085
3086
+ void SILSerializer::writeSourceLoc (SILLocation Loc, const SourceManager &SM) {
3087
+ auto SLoc = Loc.getSourceLoc ();
3088
+ auto OpaquePtr = SLoc.getOpaquePointerValue ();
3089
+ uint8_t LocationKind;
3090
+ switch (Loc.getKind ()) {
3091
+ case SILLocation::ReturnKind:
3092
+ LocationKind = SILLocation::ReturnKind;
3093
+ break ;
3094
+ case SILLocation::ImplicitReturnKind:
3095
+ LocationKind = SILLocation::ImplicitReturnKind;
3096
+ break ;
3097
+ case SILLocation::InlinedKind:
3098
+ case SILLocation::MandatoryInlinedKind:
3099
+ case SILLocation::CleanupKind:
3100
+ case SILLocation::ArtificialUnreachableKind:
3101
+ case SILLocation::RegularKind:
3102
+ LocationKind = SILLocation::RegularKind;
3103
+ break ;
3104
+ }
3105
+
3106
+ if (SourceLocMap.find (OpaquePtr) != SourceLocMap.end ()) {
3107
+ SourceLocRefLayout::emitRecord (Out, ScratchRecord,
3108
+ SILAbbrCodes[SourceLocRefLayout::Code],
3109
+ SourceLocMap[OpaquePtr], LocationKind, (unsigned )Loc.isImplicit ());
3110
+ return ;
3111
+ }
3112
+
3113
+ ValueID Row = 0 ;
3114
+ ValueID Column = 0 ;
3115
+ ValueID FNameID = 0 ;
3116
+
3117
+ if (!SLoc.isValid ()) {
3118
+ // emit empty source loc
3119
+ SourceLocRefLayout::emitRecord (Out, ScratchRecord, SILAbbrCodes[SourceLocRefLayout::Code], 0 , 0 , (unsigned )0 );
3120
+ return ;
3121
+ }
3122
+
3123
+ std::tie (Row, Column) = SM.getPresumedLineAndColumnForLoc (SLoc);
3124
+ FNameID = S.addUniquedStringRef (SM.getDisplayNameForLoc (SLoc));
3125
+ SourceLocMap.insert ({OpaquePtr, SourceLocMap.size () + 1 });
3126
+ SourceLocLayout::emitRecord (Out, ScratchRecord,
3127
+ SILAbbrCodes[SourceLocLayout::Code], Row, Column,
3128
+ FNameID, LocationKind, (unsigned )Loc.isImplicit ());
3129
+ }
3130
+
3077
3131
void SILSerializer::writeDebugScopes (const SILDebugScope *Scope,
3078
3132
const SourceManager &SM) {
3079
3133
@@ -3387,6 +3441,8 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
3387
3441
registerSILAbbr<DifferentiabilityWitnessLayout>();
3388
3442
registerSILAbbr<SILDebugScopeLayout>();
3389
3443
registerSILAbbr<SILDebugScopeRefLayout>();
3444
+ registerSILAbbr<SourceLocLayout>();
3445
+ registerSILAbbr<SourceLocRefLayout>();
3390
3446
3391
3447
// Write out VTables first because it may require serializations of
3392
3448
// non-transparent SILFunctions (body is not needed).
0 commit comments