1
- // ===--- OptRemarkGenerator .cpp ----------- --------------------------------===//
1
+ // ===--- AssemblyVisionRemarkGenerator .cpp --------------------------------===//
2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
12
12
// /
13
13
// / \file
14
14
// /
15
- // / In this pass, we define the opt- remark-generator, a simple SILVisitor that
16
- // / attempts to infer opt- remarks for the user using heuristics.
15
+ // / In this pass, we define the assembly-vision- remark-generator, a simple
16
+ // / SILVisitor that attempts to infer remarks for the user using heuristics.
17
17
// /
18
18
// ===----------------------------------------------------------------------===//
19
19
20
- #define DEBUG_TYPE " sil-opt -remark-gen"
20
+ #define DEBUG_TYPE " sil-assembly-vision -remark-gen"
21
21
22
22
#include " swift/AST/SemanticAttrs.h"
23
23
#include " swift/Basic/Defer.h"
24
24
#include " swift/SIL/DebugUtils.h"
25
25
#include " swift/SIL/DynamicCasts.h"
26
26
#include " swift/SIL/MemAccessUtils.h"
27
27
#include " swift/SIL/OptimizationRemark.h"
28
+ #include " swift/SIL/PatternMatch.h"
28
29
#include " swift/SIL/Projection.h"
29
30
#include " swift/SIL/SILFunction.h"
30
31
#include " swift/SIL/SILInstruction.h"
31
- #include " swift/SIL/PatternMatch.h"
32
32
#include " swift/SIL/SILModule.h"
33
33
#include " swift/SIL/SILVisitor.h"
34
34
#include " swift/SILOptimizer/Analysis/RCIdentityAnalysis.h"
@@ -41,13 +41,14 @@ using namespace swift;
41
41
using namespace swift ::PatternMatch;
42
42
43
43
static llvm::cl::opt<bool > ForceVisitImplicitAutogeneratedFunctions (
44
- " optremarkgen -visit-implicit-autogen-funcs" , llvm::cl::Hidden,
44
+ " assemblyvisionremarkgen -visit-implicit-autogen-funcs" , llvm::cl::Hidden,
45
45
llvm::cl::desc (
46
46
" Emit opt remarks even on implicit and autogenerated functions" ),
47
47
llvm::cl::init(false ));
48
48
49
49
static llvm::cl::opt<bool > DecllessDebugValueUseSILDebugInfo (
50
- " optremarkgen-declless-debugvalue-use-sildebugvar-info" , llvm::cl::Hidden,
50
+ " assemblyvisionremarkgen-declless-debugvalue-use-sildebugvar-info" ,
51
+ llvm::cl::Hidden,
51
52
llvm::cl::desc (
52
53
" If a debug_value does not have a decl, infer a value with a name from "
53
54
" that info that has a loc set to the loc of the debug_value "
@@ -98,7 +99,8 @@ struct ValueToDeclInferrer {
98
99
// /
99
100
// / sil @theFunction : $@convention(thin) () -> () {
100
101
// / bb0:
101
- // / %0 = apply %getKlassPair() : $@convention(thin) () -> @owned KlassPair
102
+ // / %0 = apply %getKlassPair() : $@convention(thin) () -> @owned
103
+ // / KlassPair
102
104
// / // This debug_value's name can be combined...
103
105
// / debug_value %0 : $KlassPair, name "myPair"
104
106
// / // ... with the access path from the struct_extract here...
@@ -119,8 +121,9 @@ struct ValueToDeclInferrer {
119
121
// / //
120
122
// / // The reason why we must do this is due to the behavior of the late
121
123
// / // optimizer and how it forms these patterns in the code.
122
- // / %0a = apply %getStateWithOwningPointer() : $@convention(thin) () -> @owned StateWithOwningPointer
123
- // / %1 = struct_extract %0a : $StateWithOwningPointer, #StateWithOwningPointer.owningPtr
124
+ // / %0a = apply %getStateWithOwningPointer() : $@convention(thin) () ->
125
+ // / @owned StateWithOwningPointer %1 = struct_extract %0a :
126
+ // / $StateWithOwningPointer, #StateWithOwningPointer.owningPtr
124
127
// / strong_retain %1 : $Klass
125
128
// / %2 = struct $Array(%0 : $Builtin.NativeObject, ...)
126
129
// / debug_value %2 : $Array, ...
@@ -130,7 +133,8 @@ struct ValueToDeclInferrer {
130
133
131
134
// / Convenience overload that calls:
132
135
// /
133
- // / printNote(stream, decl->getBaseName().userFacingName(), shouldPrintAccessPath).
136
+ // / printNote(stream, decl->getBaseName().userFacingName(),
137
+ // / shouldPrintAccessPath).
134
138
void printNote (llvm::raw_string_ostream &stream, const ValueDecl *decl,
135
139
bool shouldPrintAccessPath = true ) {
136
140
printNote (stream, decl->getBaseName ().userFacingName (),
@@ -308,9 +312,7 @@ bool ValueToDeclInferrer::infer(
308
312
SmallVectorImpl<Argument> &resultingInferredDecls,
309
313
bool allowSingleRefEltAddrPeek) {
310
314
// Clear the stored access path at end of scope.
311
- SWIFT_DEFER {
312
- accessPath.clear ();
313
- };
315
+ SWIFT_DEFER { accessPath.clear (); };
314
316
ValueUseToDeclInferrer valueUseInferrer{
315
317
{}, *this , keyKind, resultingInferredDecls};
316
318
bool foundSingleRefElementAddr = false ;
@@ -379,8 +381,9 @@ bool ValueToDeclInferrer::infer(
379
381
// A pattern that we see around empty array storage is:
380
382
//
381
383
// %0 = global_addr @_swiftEmptyArrayStorage : $*_SwiftEmptyArrayStorage
382
- // %1 = address_to_pointer %0 : $*_SwiftEmptyArrayStorage to $Builtin.RawPointer
383
- // %2 = raw_pointer_to_ref %1 : $Builtin.RawPointer to $__EmptyArrayStorage
384
+ // %1 = address_to_pointer %0 : $*_SwiftEmptyArrayStorage to
385
+ // $Builtin.RawPointer %2 = raw_pointer_to_ref %1 : $Builtin.RawPointer to
386
+ // $__EmptyArrayStorage
384
387
//
385
388
// Recognize this case.
386
389
{
@@ -490,17 +493,18 @@ bool ValueToDeclInferrer::infer(
490
493
491
494
namespace {
492
495
493
- struct OptRemarkGeneratorInstructionVisitor
494
- : public SILInstructionVisitor<OptRemarkGeneratorInstructionVisitor> {
496
+ struct AssemblyVisionRemarkGeneratorInstructionVisitor
497
+ : public SILInstructionVisitor<
498
+ AssemblyVisionRemarkGeneratorInstructionVisitor> {
495
499
SILModule &mod;
496
500
OptRemark::Emitter ORE;
497
501
498
502
// / A class that we use to infer the decl that is associated with a
499
503
// / miscellaneous SIL value. This is just a heuristic that is to taste.
500
504
ValueToDeclInferrer valueToDeclInferrer;
501
505
502
- OptRemarkGeneratorInstructionVisitor (SILFunction &fn,
503
- RCIdentityFunctionInfo &rcfi)
506
+ AssemblyVisionRemarkGeneratorInstructionVisitor (SILFunction &fn,
507
+ RCIdentityFunctionInfo &rcfi)
504
508
: mod(fn.getModule()), ORE(DEBUG_TYPE, fn), valueToDeclInferrer(rcfi) {}
505
509
506
510
void visitStrongRetainInst (StrongRetainInst *sri);
@@ -519,7 +523,7 @@ struct OptRemarkGeneratorInstructionVisitor
519
523
520
524
} // anonymous namespace
521
525
522
- void OptRemarkGeneratorInstructionVisitor ::
526
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::
523
527
visitUnconditionalCheckedCastAddrInst (
524
528
UnconditionalCheckedCastAddrInst *uccai) {
525
529
ORE.emit ([&]() {
@@ -542,8 +546,8 @@ void OptRemarkGeneratorInstructionVisitor::
542
546
});
543
547
}
544
548
545
- void OptRemarkGeneratorInstructionVisitor::visitCheckedCastAddrBranchInst (
546
- CheckedCastAddrBranchInst *ccabi) {
549
+ void AssemblyVisionRemarkGeneratorInstructionVisitor::
550
+ visitCheckedCastAddrBranchInst ( CheckedCastAddrBranchInst *ccabi) {
547
551
ORE.emit ([&]() {
548
552
using namespace OptRemark ;
549
553
SmallVector<Argument, 8 > inferredArgs;
@@ -564,7 +568,7 @@ void OptRemarkGeneratorInstructionVisitor::visitCheckedCastAddrBranchInst(
564
568
});
565
569
}
566
570
567
- void OptRemarkGeneratorInstructionVisitor ::visitBeginAccessInst (
571
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitBeginAccessInst (
568
572
BeginAccessInst *bai) {
569
573
ORE.emit ([&]() {
570
574
using namespace OptRemark ;
@@ -586,7 +590,7 @@ void OptRemarkGeneratorInstructionVisitor::visitBeginAccessInst(
586
590
});
587
591
}
588
592
589
- void OptRemarkGeneratorInstructionVisitor ::visitEndAccessInst (
593
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitEndAccessInst (
590
594
EndAccessInst *eai) {
591
595
ORE.emit ([&]() {
592
596
using namespace OptRemark ;
@@ -611,7 +615,7 @@ void OptRemarkGeneratorInstructionVisitor::visitEndAccessInst(
611
615
});
612
616
}
613
617
614
- void OptRemarkGeneratorInstructionVisitor ::visitStrongRetainInst (
618
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitStrongRetainInst (
615
619
StrongRetainInst *sri) {
616
620
ORE.emit ([&]() {
617
621
using namespace OptRemark ;
@@ -633,7 +637,7 @@ void OptRemarkGeneratorInstructionVisitor::visitStrongRetainInst(
633
637
});
634
638
}
635
639
636
- void OptRemarkGeneratorInstructionVisitor ::visitStrongReleaseInst (
640
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitStrongReleaseInst (
637
641
StrongReleaseInst *sri) {
638
642
ORE.emit ([&]() {
639
643
using namespace OptRemark ;
@@ -656,7 +660,7 @@ void OptRemarkGeneratorInstructionVisitor::visitStrongReleaseInst(
656
660
});
657
661
}
658
662
659
- void OptRemarkGeneratorInstructionVisitor ::visitRetainValueInst (
663
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitRetainValueInst (
660
664
RetainValueInst *rvi) {
661
665
ORE.emit ([&]() {
662
666
using namespace OptRemark ;
@@ -677,7 +681,7 @@ void OptRemarkGeneratorInstructionVisitor::visitRetainValueInst(
677
681
});
678
682
}
679
683
680
- void OptRemarkGeneratorInstructionVisitor ::visitReleaseValueInst (
684
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitReleaseValueInst (
681
685
ReleaseValueInst *rvi) {
682
686
ORE.emit ([&]() {
683
687
using namespace OptRemark ;
@@ -699,7 +703,7 @@ void OptRemarkGeneratorInstructionVisitor::visitReleaseValueInst(
699
703
});
700
704
}
701
705
702
- void OptRemarkGeneratorInstructionVisitor ::visitAllocRefInst (
706
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitAllocRefInst (
703
707
AllocRefInst *ari) {
704
708
if (ari->canAllocOnStack ()) {
705
709
return ORE.emit ([&]() {
@@ -735,7 +739,7 @@ void OptRemarkGeneratorInstructionVisitor::visitAllocRefInst(
735
739
});
736
740
}
737
741
738
- void OptRemarkGeneratorInstructionVisitor ::visitAllocBoxInst (
742
+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitAllocBoxInst (
739
743
AllocBoxInst *abi) {
740
744
return ORE.emit ([&]() {
741
745
using namespace OptRemark ;
@@ -760,8 +764,8 @@ void OptRemarkGeneratorInstructionVisitor::visitAllocBoxInst(
760
764
761
765
namespace {
762
766
763
- class OptRemarkGenerator : public SILFunctionTransform {
764
- ~OptRemarkGenerator () override {}
767
+ class AssemblyVisionRemarkGenerator : public SILFunctionTransform {
768
+ ~AssemblyVisionRemarkGenerator () override {}
765
769
766
770
bool isOptRemarksEnabled () {
767
771
auto *fn = getFunction ();
@@ -798,7 +802,7 @@ class OptRemarkGenerator : public SILFunctionTransform {
798
802
799
803
LLVM_DEBUG (llvm::dbgs () << " Visiting: " << fn->getName () << " \n " );
800
804
auto &rcfi = *getAnalysis<RCIdentityAnalysis>()->get (fn);
801
- OptRemarkGeneratorInstructionVisitor visitor (*fn, rcfi);
805
+ AssemblyVisionRemarkGeneratorInstructionVisitor visitor (*fn, rcfi);
802
806
for (auto &block : *fn) {
803
807
for (auto &inst : block) {
804
808
visitor.visit (&inst);
@@ -809,6 +813,6 @@ class OptRemarkGenerator : public SILFunctionTransform {
809
813
810
814
} // end anonymous namespace
811
815
812
- SILTransform *swift::createOptRemarkGenerator () {
813
- return new OptRemarkGenerator ();
816
+ SILTransform *swift::createAssemblyVisionRemarkGenerator () {
817
+ return new AssemblyVisionRemarkGenerator ();
814
818
}
0 commit comments