@@ -409,14 +409,14 @@ unsigned ArgumentDescriptor::updateOptimizedBBArgs(SILBuilder &Builder,
409
409
}
410
410
411
411
// ===----------------------------------------------------------------------===//
412
- // Function Analyzer
412
+ // Signature Optimizer
413
413
// ===----------------------------------------------------------------------===//
414
414
415
415
namespace {
416
416
417
417
// / A class that contains all analysis information we gather about our
418
418
// / function. Also provides utility methods for creating the new empty function.
419
- class FunctionAnalyzer {
419
+ class SignatureOptimizer {
420
420
llvm::BumpPtrAllocator &Allocator;
421
421
422
422
RCIdentityFunctionInfo *RCIA;
@@ -441,12 +441,12 @@ class FunctionAnalyzer {
441
441
442
442
public:
443
443
ArrayRef<ArgumentDescriptor> getArgList () const { return ArgDescList; }
444
- FunctionAnalyzer () = delete ;
445
- FunctionAnalyzer (const FunctionAnalyzer &) = delete ;
446
- FunctionAnalyzer (FunctionAnalyzer &&) = delete ;
444
+ SignatureOptimizer () = delete ;
445
+ SignatureOptimizer (const SignatureOptimizer &) = delete ;
446
+ SignatureOptimizer (SignatureOptimizer &&) = delete ;
447
447
448
- FunctionAnalyzer (llvm::BumpPtrAllocator &Allocator,
449
- RCIdentityFunctionInfo *RCIA, SILFunction *F)
448
+ SignatureOptimizer (llvm::BumpPtrAllocator &Allocator,
449
+ RCIdentityFunctionInfo *RCIA, SILFunction *F)
450
450
: Allocator(Allocator), RCIA(RCIA), F(F),
451
451
MayBindDynamicSelf (computeMayBindDynamicSelf(F)), ShouldOptimize(false ),
452
452
HaveModifiedSelfArgument(false ), ArgDescList() {}
@@ -487,7 +487,7 @@ class FunctionAnalyzer {
487
487
// / This function goes through the arguments of F and sees if we have anything
488
488
// / to optimize in which case it returns true. If we have nothing to optimize,
489
489
// / it returns false.
490
- bool FunctionAnalyzer ::analyze () {
490
+ bool SignatureOptimizer ::analyze () {
491
491
// For now ignore functions with indirect results.
492
492
if (F->getLoweredFunctionType ()->hasIndirectResult ())
493
493
return false ;
@@ -563,7 +563,7 @@ bool FunctionAnalyzer::analyze() {
563
563
// Creating the New Function
564
564
// ===----------------------------------------------------------------------===//
565
565
566
- CanSILFunctionType FunctionAnalyzer ::createOptimizedSILFunctionType () {
566
+ CanSILFunctionType SignatureOptimizer ::createOptimizedSILFunctionType () {
567
567
const ASTContext &Ctx = F->getModule ().getASTContext ();
568
568
CanSILFunctionType FTy = F->getLoweredFunctionType ();
569
569
@@ -589,8 +589,8 @@ CanSILFunctionType FunctionAnalyzer::createOptimizedSILFunctionType() {
589
589
InterfaceResult, InterfaceErrorResult, Ctx);
590
590
}
591
591
592
- SILFunction *FunctionAnalyzer ::createEmptyFunctionWithOptimizedSig (
593
- const std::string &NewFName) {
592
+ SILFunction *SignatureOptimizer ::createEmptyFunctionWithOptimizedSig (
593
+ const std::string &NewFName) {
594
594
SILModule &M = F->getModule ();
595
595
596
596
// Create the new optimized function type.
@@ -618,7 +618,7 @@ SILFunction *FunctionAnalyzer::createEmptyFunctionWithOptimizedSig(
618
618
// Mangling
619
619
// ===----------------------------------------------------------------------===//
620
620
621
- std::string FunctionAnalyzer ::getOptimizedName () {
621
+ std::string SignatureOptimizer ::getOptimizedName () {
622
622
Mangle::Mangler M;
623
623
auto P = SpecializationPass::FunctionSignatureOpts;
624
624
FunctionSignatureSpecializationMangler FSSM (P, M, F);
@@ -653,7 +653,7 @@ std::string FunctionAnalyzer::getOptimizedName() {
653
653
654
654
// / This function takes in OldF and all callsites of OldF and rewrites the
655
655
// / callsites to call the new function.
656
- static void rewriteApplyInstToCallNewFunction (FunctionAnalyzer &Analyzer ,
656
+ static void rewriteApplyInstToCallNewFunction (SignatureOptimizer &Optimizer ,
657
657
SILFunction *NewF,
658
658
const ApplyList &CallSites) {
659
659
for (auto FAS : CallSites) {
@@ -665,7 +665,7 @@ static void rewriteApplyInstToCallNewFunction(FunctionAnalyzer &Analyzer,
665
665
666
666
// Create the args for the new apply, ignoring any dead arguments.
667
667
llvm::SmallVector<SILValue, 8 > NewArgs;
668
- ArrayRef<ArgumentDescriptor> ArgDescs = Analyzer .getArgDescList ();
668
+ ArrayRef<ArgumentDescriptor> ArgDescs = Optimizer .getArgDescList ();
669
669
for (auto &ArgDesc : ArgDescs) {
670
670
ArgDesc.addCallerArgs (Builder, FAS, NewArgs);
671
671
}
@@ -719,7 +719,7 @@ static void rewriteApplyInstToCallNewFunction(FunctionAnalyzer &Analyzer,
719
719
}
720
720
721
721
static void createThunkBody (SILBasicBlock *BB, SILFunction *NewF,
722
- FunctionAnalyzer &Analyzer ) {
722
+ SignatureOptimizer &Optimizer ) {
723
723
// TODO: What is the proper location to use here?
724
724
SILLocation Loc = BB->getParent ()->getLocation ();
725
725
SILBuilder Builder (BB);
@@ -729,7 +729,7 @@ static void createThunkBody(SILBasicBlock *BB, SILFunction *NewF,
729
729
730
730
// Create the args for the thunk's apply, ignoring any dead arguments.
731
731
llvm::SmallVector<SILValue, 8 > ThunkArgs;
732
- ArrayRef<ArgumentDescriptor> ArgDescs = Analyzer .getArgDescList ();
732
+ ArrayRef<ArgumentDescriptor> ArgDescs = Optimizer .getArgDescList ();
733
733
for (auto &ArgDesc : ArgDescs) {
734
734
ArgDesc.addThunkArgs (Builder, BB, ThunkArgs);
735
735
}
@@ -791,22 +791,22 @@ static void createThunkBody(SILBasicBlock *BB, SILFunction *NewF,
791
791
static SILFunction *
792
792
moveFunctionBodyToNewFunctionWithName (SILFunction *F,
793
793
const std::string &NewFName,
794
- FunctionAnalyzer &Analyzer ) {
794
+ SignatureOptimizer &Optimizer ) {
795
795
// First we create an empty function (i.e. no BB) whose function signature has
796
796
// had its arity modified.
797
797
//
798
798
// We only do this to remove dead arguments. All other function signature
799
799
// optimization is done later by modifying the function signature elements
800
800
// themselves.
801
- SILFunction *NewF = Analyzer .createEmptyFunctionWithOptimizedSig (NewFName);
801
+ SILFunction *NewF = Optimizer .createEmptyFunctionWithOptimizedSig (NewFName);
802
802
// Then we transfer the body of F to NewF. At this point, the arguments of the
803
803
// first BB will not match.
804
804
NewF->spliceBody (F);
805
805
// Do the same with the call graph.
806
806
807
807
// Then perform any updates to the arguments of NewF.
808
808
SILBasicBlock *NewFEntryBB = &*NewF->begin ();
809
- MutableArrayRef<ArgumentDescriptor> ArgDescs = Analyzer .getArgDescList ();
809
+ MutableArrayRef<ArgumentDescriptor> ArgDescs = Optimizer .getArgDescList ();
810
810
unsigned ArgOffset = 0 ;
811
811
SILBuilder Builder (NewFEntryBB->begin ());
812
812
Builder.setCurrentDebugScope (NewFEntryBB->getParent ()->getDebugScope ());
@@ -824,7 +824,7 @@ moveFunctionBodyToNewFunctionWithName(SILFunction *F,
824
824
for (auto &ArgDesc : ArgDescs) {
825
825
ThunkBody->createBBArg (ArgDesc.ParameterInfo .getSILType (), ArgDesc.Decl );
826
826
}
827
- createThunkBody (ThunkBody, NewF, Analyzer );
827
+ createThunkBody (ThunkBody, NewF, Optimizer );
828
828
829
829
F->setThunk (IsThunk);
830
830
assert (F->getDebugScope ()->SILFn != NewF->getDebugScope ()->SILFn );
@@ -852,8 +852,8 @@ static bool optimizeFunctionSignature(llvm::BumpPtrAllocator &BPA,
852
852
llvm::SmallVector<ArgumentDescriptor, 8 > Arguments;
853
853
854
854
// Analyze function arguments. If there is no work to be done, exit early.
855
- FunctionAnalyzer Analyzer (BPA, RCIA, F);
856
- if (!Analyzer .analyze ()) {
855
+ SignatureOptimizer Optimizer (BPA, RCIA, F);
856
+ if (!Optimizer .analyze ()) {
857
857
DEBUG (llvm::dbgs () << " Has no optimizable arguments... "
858
858
" bailing...\n " );
859
859
return false ;
@@ -864,7 +864,7 @@ static bool optimizeFunctionSignature(llvm::BumpPtrAllocator &BPA,
864
864
865
865
++NumFunctionSignaturesOptimized;
866
866
867
- auto NewFName = Analyzer .getOptimizedName ();
867
+ auto NewFName = Optimizer .getOptimizedName ();
868
868
869
869
// If we already have a specialized version of this function, do not
870
870
// respecialize. For now just bail.
@@ -878,13 +878,13 @@ static bool optimizeFunctionSignature(llvm::BumpPtrAllocator &BPA,
878
878
879
879
// Otherwise, move F over to NewF.
880
880
SILFunction *NewF =
881
- moveFunctionBodyToNewFunctionWithName (F, NewFName, Analyzer );
881
+ moveFunctionBodyToNewFunctionWithName (F, NewFName, Optimizer );
882
882
883
883
// And remove all Callee releases that we found and made redundant via owned
884
884
// to guaranteed conversion.
885
885
//
886
886
// TODO: If more stuff needs to be placed here, refactor into its own method.
887
- for (auto &A : Analyzer .getArgDescList ()) {
887
+ for (auto &A : Optimizer .getArgDescList ()) {
888
888
if (A.CalleeRelease ) {
889
889
A.CalleeRelease ->eraseFromParent ();
890
890
if (A.CalleeReleaseInThrowBlock ) {
@@ -895,7 +895,7 @@ static bool optimizeFunctionSignature(llvm::BumpPtrAllocator &BPA,
895
895
896
896
// Rewrite all apply insts calling F to call NewF. Update each call site as
897
897
// appropriate given the form of function signature optimization performed.
898
- rewriteApplyInstToCallNewFunction (Analyzer , NewF, CallSites);
898
+ rewriteApplyInstToCallNewFunction (Optimizer , NewF, CallSites);
899
899
900
900
return true ;
901
901
}
0 commit comments