1- // ===--- OptRemarkGenerator .cpp ----------- --------------------------------===//
1+ // ===--- AssemblyVisionRemarkGenerator .cpp --------------------------------===//
22//
33// This source file is part of the Swift.org open source project
44//
5- // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+ // Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
66// Licensed under Apache License v2.0 with Runtime Library Exception
77//
88// See https://swift.org/LICENSE.txt for license information
1212// /
1313// / \file
1414// /
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.
1717// /
1818// ===----------------------------------------------------------------------===//
1919
20- #define DEBUG_TYPE " sil-opt -remark-gen"
20+ #define DEBUG_TYPE " sil-assembly-vision -remark-gen"
2121
2222#include " swift/AST/SemanticAttrs.h"
2323#include " swift/Basic/Defer.h"
2424#include " swift/SIL/DebugUtils.h"
2525#include " swift/SIL/DynamicCasts.h"
2626#include " swift/SIL/MemAccessUtils.h"
2727#include " swift/SIL/OptimizationRemark.h"
28+ #include " swift/SIL/PatternMatch.h"
2829#include " swift/SIL/Projection.h"
2930#include " swift/SIL/SILFunction.h"
3031#include " swift/SIL/SILInstruction.h"
31- #include " swift/SIL/PatternMatch.h"
3232#include " swift/SIL/SILModule.h"
3333#include " swift/SIL/SILVisitor.h"
3434#include " swift/SILOptimizer/Analysis/RCIdentityAnalysis.h"
@@ -41,13 +41,14 @@ using namespace swift;
4141using namespace swift ::PatternMatch;
4242
4343static llvm::cl::opt<bool > ForceVisitImplicitAutogeneratedFunctions (
44- " optremarkgen -visit-implicit-autogen-funcs" , llvm::cl::Hidden,
44+ " assemblyvisionremarkgen -visit-implicit-autogen-funcs" , llvm::cl::Hidden,
4545 llvm::cl::desc (
4646 " Emit opt remarks even on implicit and autogenerated functions" ),
4747 llvm::cl::init(false ));
4848
4949static 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,
5152 llvm::cl::desc (
5253 " If a debug_value does not have a decl, infer a value with a name from "
5354 " that info that has a loc set to the loc of the debug_value "
@@ -98,7 +99,8 @@ struct ValueToDeclInferrer {
9899 // /
99100 // / sil @theFunction : $@convention(thin) () -> () {
100101 // / bb0:
101- // / %0 = apply %getKlassPair() : $@convention(thin) () -> @owned KlassPair
102+ // / %0 = apply %getKlassPair() : $@convention(thin) () -> @owned
103+ // / KlassPair
102104 // / // This debug_value's name can be combined...
103105 // / debug_value %0 : $KlassPair, name "myPair"
104106 // / // ... with the access path from the struct_extract here...
@@ -119,8 +121,9 @@ struct ValueToDeclInferrer {
119121 // / //
120122 // / // The reason why we must do this is due to the behavior of the late
121123 // / // 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
124127 // / strong_retain %1 : $Klass
125128 // / %2 = struct $Array(%0 : $Builtin.NativeObject, ...)
126129 // / debug_value %2 : $Array, ...
@@ -130,7 +133,8 @@ struct ValueToDeclInferrer {
130133
131134 // / Convenience overload that calls:
132135 // /
133- // / printNote(stream, decl->getBaseName().userFacingName(), shouldPrintAccessPath).
136+ // / printNote(stream, decl->getBaseName().userFacingName(),
137+ // / shouldPrintAccessPath).
134138 void printNote (llvm::raw_string_ostream &stream, const ValueDecl *decl,
135139 bool shouldPrintAccessPath = true ) {
136140 printNote (stream, decl->getBaseName ().userFacingName (),
@@ -308,9 +312,7 @@ bool ValueToDeclInferrer::infer(
308312 SmallVectorImpl<Argument> &resultingInferredDecls,
309313 bool allowSingleRefEltAddrPeek) {
310314 // Clear the stored access path at end of scope.
311- SWIFT_DEFER {
312- accessPath.clear ();
313- };
315+ SWIFT_DEFER { accessPath.clear (); };
314316 ValueUseToDeclInferrer valueUseInferrer{
315317 {}, *this , keyKind, resultingInferredDecls};
316318 bool foundSingleRefElementAddr = false ;
@@ -379,8 +381,9 @@ bool ValueToDeclInferrer::infer(
379381 // A pattern that we see around empty array storage is:
380382 //
381383 // %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
384387 //
385388 // Recognize this case.
386389 {
@@ -490,17 +493,18 @@ bool ValueToDeclInferrer::infer(
490493
491494namespace {
492495
493- struct OptRemarkGeneratorInstructionVisitor
494- : public SILInstructionVisitor<OptRemarkGeneratorInstructionVisitor> {
496+ struct AssemblyVisionRemarkGeneratorInstructionVisitor
497+ : public SILInstructionVisitor<
498+ AssemblyVisionRemarkGeneratorInstructionVisitor> {
495499 SILModule &mod;
496500 OptRemark::Emitter ORE;
497501
498502 // / A class that we use to infer the decl that is associated with a
499503 // / miscellaneous SIL value. This is just a heuristic that is to taste.
500504 ValueToDeclInferrer valueToDeclInferrer;
501505
502- OptRemarkGeneratorInstructionVisitor (SILFunction &fn,
503- RCIdentityFunctionInfo &rcfi)
506+ AssemblyVisionRemarkGeneratorInstructionVisitor (SILFunction &fn,
507+ RCIdentityFunctionInfo &rcfi)
504508 : mod(fn.getModule()), ORE(DEBUG_TYPE, fn), valueToDeclInferrer(rcfi) {}
505509
506510 void visitStrongRetainInst (StrongRetainInst *sri);
@@ -519,7 +523,7 @@ struct OptRemarkGeneratorInstructionVisitor
519523
520524} // anonymous namespace
521525
522- void OptRemarkGeneratorInstructionVisitor ::
526+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::
523527 visitUnconditionalCheckedCastAddrInst (
524528 UnconditionalCheckedCastAddrInst *uccai) {
525529 ORE.emit ([&]() {
@@ -542,8 +546,8 @@ void OptRemarkGeneratorInstructionVisitor::
542546 });
543547}
544548
545- void OptRemarkGeneratorInstructionVisitor::visitCheckedCastAddrBranchInst (
546- CheckedCastAddrBranchInst *ccabi) {
549+ void AssemblyVisionRemarkGeneratorInstructionVisitor::
550+ visitCheckedCastAddrBranchInst ( CheckedCastAddrBranchInst *ccabi) {
547551 ORE.emit ([&]() {
548552 using namespace OptRemark ;
549553 SmallVector<Argument, 8 > inferredArgs;
@@ -564,7 +568,7 @@ void OptRemarkGeneratorInstructionVisitor::visitCheckedCastAddrBranchInst(
564568 });
565569}
566570
567- void OptRemarkGeneratorInstructionVisitor ::visitBeginAccessInst (
571+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitBeginAccessInst (
568572 BeginAccessInst *bai) {
569573 ORE.emit ([&]() {
570574 using namespace OptRemark ;
@@ -586,7 +590,7 @@ void OptRemarkGeneratorInstructionVisitor::visitBeginAccessInst(
586590 });
587591}
588592
589- void OptRemarkGeneratorInstructionVisitor ::visitEndAccessInst (
593+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitEndAccessInst (
590594 EndAccessInst *eai) {
591595 ORE.emit ([&]() {
592596 using namespace OptRemark ;
@@ -611,7 +615,7 @@ void OptRemarkGeneratorInstructionVisitor::visitEndAccessInst(
611615 });
612616}
613617
614- void OptRemarkGeneratorInstructionVisitor ::visitStrongRetainInst (
618+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitStrongRetainInst (
615619 StrongRetainInst *sri) {
616620 ORE.emit ([&]() {
617621 using namespace OptRemark ;
@@ -633,7 +637,7 @@ void OptRemarkGeneratorInstructionVisitor::visitStrongRetainInst(
633637 });
634638}
635639
636- void OptRemarkGeneratorInstructionVisitor ::visitStrongReleaseInst (
640+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitStrongReleaseInst (
637641 StrongReleaseInst *sri) {
638642 ORE.emit ([&]() {
639643 using namespace OptRemark ;
@@ -656,7 +660,7 @@ void OptRemarkGeneratorInstructionVisitor::visitStrongReleaseInst(
656660 });
657661}
658662
659- void OptRemarkGeneratorInstructionVisitor ::visitRetainValueInst (
663+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitRetainValueInst (
660664 RetainValueInst *rvi) {
661665 ORE.emit ([&]() {
662666 using namespace OptRemark ;
@@ -677,7 +681,7 @@ void OptRemarkGeneratorInstructionVisitor::visitRetainValueInst(
677681 });
678682}
679683
680- void OptRemarkGeneratorInstructionVisitor ::visitReleaseValueInst (
684+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitReleaseValueInst (
681685 ReleaseValueInst *rvi) {
682686 ORE.emit ([&]() {
683687 using namespace OptRemark ;
@@ -699,7 +703,7 @@ void OptRemarkGeneratorInstructionVisitor::visitReleaseValueInst(
699703 });
700704}
701705
702- void OptRemarkGeneratorInstructionVisitor ::visitAllocRefInst (
706+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitAllocRefInst (
703707 AllocRefInst *ari) {
704708 if (ari->canAllocOnStack ()) {
705709 return ORE.emit ([&]() {
@@ -735,7 +739,7 @@ void OptRemarkGeneratorInstructionVisitor::visitAllocRefInst(
735739 });
736740}
737741
738- void OptRemarkGeneratorInstructionVisitor ::visitAllocBoxInst (
742+ void AssemblyVisionRemarkGeneratorInstructionVisitor ::visitAllocBoxInst (
739743 AllocBoxInst *abi) {
740744 return ORE.emit ([&]() {
741745 using namespace OptRemark ;
@@ -760,8 +764,8 @@ void OptRemarkGeneratorInstructionVisitor::visitAllocBoxInst(
760764
761765namespace {
762766
763- class OptRemarkGenerator : public SILFunctionTransform {
764- ~OptRemarkGenerator () override {}
767+ class AssemblyVisionRemarkGenerator : public SILFunctionTransform {
768+ ~AssemblyVisionRemarkGenerator () override {}
765769
766770 bool isOptRemarksEnabled () {
767771 auto *fn = getFunction ();
@@ -798,7 +802,7 @@ class OptRemarkGenerator : public SILFunctionTransform {
798802
799803 LLVM_DEBUG (llvm::dbgs () << " Visiting: " << fn->getName () << " \n " );
800804 auto &rcfi = *getAnalysis<RCIdentityAnalysis>()->get (fn);
801- OptRemarkGeneratorInstructionVisitor visitor (*fn, rcfi);
805+ AssemblyVisionRemarkGeneratorInstructionVisitor visitor (*fn, rcfi);
802806 for (auto &block : *fn) {
803807 for (auto &inst : block) {
804808 visitor.visit (&inst);
@@ -809,6 +813,6 @@ class OptRemarkGenerator : public SILFunctionTransform {
809813
810814} // end anonymous namespace
811815
812- SILTransform *swift::createOptRemarkGenerator () {
813- return new OptRemarkGenerator ();
816+ SILTransform *swift::createAssemblyVisionRemarkGenerator () {
817+ return new AssemblyVisionRemarkGenerator ();
814818}
0 commit comments