@@ -71,7 +71,10 @@ struct ValueToDeclInferrer {
71
71
72
72
void ValueToDeclInferrer::printNote (llvm::raw_string_ostream &stream,
73
73
const ValueDecl *decl) {
74
+ assert (decl &&
75
+ " We assume for now that this is always called with a non-null decl" );
74
76
stream << " of '" << decl->getBaseName ();
77
+
75
78
for (auto &pair : accessPath) {
76
79
auto baseType = pair.first ;
77
80
auto &proj = pair.second ;
@@ -133,6 +136,12 @@ static SingleValueInstruction *isSupportedProjection(Projection p, SILValue v) {
133
136
llvm_unreachable (" Covered switch is not covered?!" );
134
137
}
135
138
139
+ static bool hasNonInlinedDebugScope (SILInstruction *i) {
140
+ if (auto *scope = i->getDebugScope ())
141
+ return !scope->InlinedCallSite ;
142
+ return false ;
143
+ }
144
+
136
145
bool ValueToDeclInferrer::infer (
137
146
ArgumentKeyKind keyKind, SILValue value,
138
147
SmallVectorImpl<Argument> &resultingInferredDecls) {
@@ -167,6 +176,46 @@ bool ValueToDeclInferrer::infer(
167
176
return true ;
168
177
}
169
178
179
+ if (auto *ari = dyn_cast<AllocRefInst>(value)) {
180
+ if (auto *decl = ari->getDecl ()) {
181
+ std::string msg;
182
+ {
183
+ llvm::raw_string_ostream stream (msg);
184
+ printNote (stream, decl);
185
+ }
186
+ resultingInferredDecls.push_back (
187
+ Argument ({keyKind, " InferredValue" }, std::move (msg), decl));
188
+ return true ;
189
+ }
190
+ }
191
+
192
+ if (auto *abi = dyn_cast<AllocBoxInst>(value)) {
193
+ if (auto *decl = abi->getDecl ()) {
194
+ std::string msg;
195
+ {
196
+ llvm::raw_string_ostream stream (msg);
197
+ printNote (stream, decl);
198
+ }
199
+
200
+ resultingInferredDecls.push_back (
201
+ Argument ({keyKind, " InferredValue" }, std::move (msg), decl));
202
+ return true ;
203
+ }
204
+ }
205
+
206
+ if (auto *asi = dyn_cast<AllocStackInst>(value)) {
207
+ if (auto *decl = asi->getDecl ()) {
208
+ std::string msg;
209
+ {
210
+ llvm::raw_string_ostream stream (msg);
211
+ printNote (stream, decl);
212
+ }
213
+ resultingInferredDecls.push_back (
214
+ Argument ({keyKind, " InferredValue" }, std::move (msg), decl));
215
+ return true ;
216
+ }
217
+ }
218
+
170
219
// Then visit our users and see if we can find a debug_value that provides
171
220
// us with a decl we can use to construct an argument.
172
221
bool foundDeclFromUse = false ;
@@ -178,18 +227,16 @@ bool ValueToDeclInferrer::infer(
178
227
if (auto *dvi = dyn_cast<DebugValueInst>(use->getUser ())) {
179
228
// Check if our debug_value has a decl and was not inlined into the
180
229
// current function.
181
- if (auto *scope = dvi->getDebugScope ()) {
182
- if (!scope->InlinedCallSite ) {
183
- if (auto *decl = dvi->getDecl ()) {
184
- std::string msg;
185
- {
186
- llvm::raw_string_ostream stream (msg);
187
- printNote (stream, decl);
188
- }
189
- resultingInferredDecls.push_back (
190
- Argument ({keyKind, " InferredValue" }, std::move (msg), decl));
191
- foundDeclFromUse = true ;
230
+ if (hasNonInlinedDebugScope (dvi)) {
231
+ if (auto *decl = dvi->getDecl ()) {
232
+ std::string msg;
233
+ {
234
+ llvm::raw_string_ostream stream (msg);
235
+ printNote (stream, decl);
192
236
}
237
+ resultingInferredDecls.push_back (
238
+ Argument ({keyKind, " InferredValue" }, std::move (msg), decl));
239
+ foundDeclFromUse = true ;
193
240
}
194
241
}
195
242
}
@@ -216,6 +263,8 @@ bool ValueToDeclInferrer::infer(
216
263
}
217
264
}
218
265
266
+ // TODO: We could emit at this point a msg for temporary allocations.
267
+
219
268
// If we reached this point, we finished falling through the loop and return
220
269
// true.
221
270
return true ;
@@ -245,6 +294,8 @@ struct OptRemarkGeneratorInstructionVisitor
245
294
void visitStrongReleaseInst (StrongReleaseInst *sri);
246
295
void visitRetainValueInst (RetainValueInst *rvi);
247
296
void visitReleaseValueInst (ReleaseValueInst *rvi);
297
+ void visitAllocRefInst (AllocRefInst *ari);
298
+ void visitAllocBoxInst (AllocBoxInst *abi);
248
299
void visitSILInstruction (SILInstruction *) {}
249
300
};
250
301
@@ -333,6 +384,64 @@ void OptRemarkGeneratorInstructionVisitor::visitReleaseValueInst(
333
384
});
334
385
}
335
386
387
+ void OptRemarkGeneratorInstructionVisitor::visitAllocRefInst (
388
+ AllocRefInst *ari) {
389
+ if (ari->canAllocOnStack ()) {
390
+ return ORE.emit ([&]() {
391
+ using namespace OptRemark ;
392
+ SmallVector<Argument, 8 > inferredArgs;
393
+ bool foundArgs =
394
+ valueToDeclInferrer.infer (ArgumentKeyKind::Note, ari, inferredArgs);
395
+ (void )foundArgs;
396
+ auto resultRemark =
397
+ RemarkPassed (" memory" , *ari,
398
+ SourceLocInferenceBehavior::ForwardScanOnly)
399
+ << " stack allocated ref of type '" << NV (" ValueType" , ari->getType ())
400
+ << " '" ;
401
+ for (auto &arg : inferredArgs)
402
+ resultRemark << arg;
403
+ return resultRemark;
404
+ });
405
+ }
406
+
407
+ return ORE.emit ([&]() {
408
+ using namespace OptRemark ;
409
+ SmallVector<Argument, 8 > inferredArgs;
410
+ bool foundArgs =
411
+ valueToDeclInferrer.infer (ArgumentKeyKind::Note, ari, inferredArgs);
412
+ (void )foundArgs;
413
+
414
+ auto resultRemark =
415
+ RemarkMissed (" memory" , *ari,
416
+ SourceLocInferenceBehavior::ForwardScanOnly)
417
+ << " heap allocated ref of type '" << NV (" ValueType" , ari->getType ())
418
+ << " '" ;
419
+ for (auto &arg : inferredArgs)
420
+ resultRemark << arg;
421
+ return resultRemark;
422
+ });
423
+ }
424
+
425
+ void OptRemarkGeneratorInstructionVisitor::visitAllocBoxInst (
426
+ AllocBoxInst *abi) {
427
+ return ORE.emit ([&]() {
428
+ using namespace OptRemark ;
429
+ SmallVector<Argument, 8 > inferredArgs;
430
+ bool foundArgs =
431
+ valueToDeclInferrer.infer (ArgumentKeyKind::Note, abi, inferredArgs);
432
+ (void )foundArgs;
433
+
434
+ auto resultRemark =
435
+ RemarkMissed (" memory" , *abi,
436
+ SourceLocInferenceBehavior::ForwardScanOnly)
437
+ << " heap allocated box of type '" << NV (" ValueType" , abi->getType ())
438
+ << " '" ;
439
+ for (auto &arg : inferredArgs)
440
+ resultRemark << arg;
441
+ return resultRemark;
442
+ });
443
+ }
444
+
336
445
// ===----------------------------------------------------------------------===//
337
446
// Top Level Entrypoint
338
447
// ===----------------------------------------------------------------------===//
0 commit comments