Skip to content

Commit 033934d

Browse files
committed
Rename FunctionAnalyzer to SignatureOptimizer.
This is a first step towards moving the analysis portion of function signature optimization into an actual SILAnalysis. I'll split this class into two pieces (one for the analysis it does, and one for the rewrites it does) next.
1 parent 0dcd84f commit 033934d

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

lib/SILOptimizer/IPO/FunctionSignatureOpts.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,14 @@ unsigned ArgumentDescriptor::updateOptimizedBBArgs(SILBuilder &Builder,
409409
}
410410

411411
//===----------------------------------------------------------------------===//
412-
// Function Analyzer
412+
// Signature Optimizer
413413
//===----------------------------------------------------------------------===//
414414

415415
namespace {
416416

417417
/// A class that contains all analysis information we gather about our
418418
/// function. Also provides utility methods for creating the new empty function.
419-
class FunctionAnalyzer {
419+
class SignatureOptimizer {
420420
llvm::BumpPtrAllocator &Allocator;
421421

422422
RCIdentityFunctionInfo *RCIA;
@@ -441,12 +441,12 @@ class FunctionAnalyzer {
441441

442442
public:
443443
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;
447447

448-
FunctionAnalyzer(llvm::BumpPtrAllocator &Allocator,
449-
RCIdentityFunctionInfo *RCIA, SILFunction *F)
448+
SignatureOptimizer(llvm::BumpPtrAllocator &Allocator,
449+
RCIdentityFunctionInfo *RCIA, SILFunction *F)
450450
: Allocator(Allocator), RCIA(RCIA), F(F),
451451
MayBindDynamicSelf(computeMayBindDynamicSelf(F)), ShouldOptimize(false),
452452
HaveModifiedSelfArgument(false), ArgDescList() {}
@@ -487,7 +487,7 @@ class FunctionAnalyzer {
487487
/// This function goes through the arguments of F and sees if we have anything
488488
/// to optimize in which case it returns true. If we have nothing to optimize,
489489
/// it returns false.
490-
bool FunctionAnalyzer::analyze() {
490+
bool SignatureOptimizer::analyze() {
491491
// For now ignore functions with indirect results.
492492
if (F->getLoweredFunctionType()->hasIndirectResult())
493493
return false;
@@ -563,7 +563,7 @@ bool FunctionAnalyzer::analyze() {
563563
// Creating the New Function
564564
//===----------------------------------------------------------------------===//
565565

566-
CanSILFunctionType FunctionAnalyzer::createOptimizedSILFunctionType() {
566+
CanSILFunctionType SignatureOptimizer::createOptimizedSILFunctionType() {
567567
const ASTContext &Ctx = F->getModule().getASTContext();
568568
CanSILFunctionType FTy = F->getLoweredFunctionType();
569569

@@ -589,8 +589,8 @@ CanSILFunctionType FunctionAnalyzer::createOptimizedSILFunctionType() {
589589
InterfaceResult, InterfaceErrorResult, Ctx);
590590
}
591591

592-
SILFunction *FunctionAnalyzer::createEmptyFunctionWithOptimizedSig(
593-
const std::string &NewFName) {
592+
SILFunction *SignatureOptimizer::createEmptyFunctionWithOptimizedSig(
593+
const std::string &NewFName) {
594594
SILModule &M = F->getModule();
595595

596596
// Create the new optimized function type.
@@ -618,7 +618,7 @@ SILFunction *FunctionAnalyzer::createEmptyFunctionWithOptimizedSig(
618618
// Mangling
619619
//===----------------------------------------------------------------------===//
620620

621-
std::string FunctionAnalyzer::getOptimizedName() {
621+
std::string SignatureOptimizer::getOptimizedName() {
622622
Mangle::Mangler M;
623623
auto P = SpecializationPass::FunctionSignatureOpts;
624624
FunctionSignatureSpecializationMangler FSSM(P, M, F);
@@ -653,7 +653,7 @@ std::string FunctionAnalyzer::getOptimizedName() {
653653

654654
/// This function takes in OldF and all callsites of OldF and rewrites the
655655
/// callsites to call the new function.
656-
static void rewriteApplyInstToCallNewFunction(FunctionAnalyzer &Analyzer,
656+
static void rewriteApplyInstToCallNewFunction(SignatureOptimizer &Optimizer,
657657
SILFunction *NewF,
658658
const ApplyList &CallSites) {
659659
for (auto FAS : CallSites) {
@@ -665,7 +665,7 @@ static void rewriteApplyInstToCallNewFunction(FunctionAnalyzer &Analyzer,
665665

666666
// Create the args for the new apply, ignoring any dead arguments.
667667
llvm::SmallVector<SILValue, 8> NewArgs;
668-
ArrayRef<ArgumentDescriptor> ArgDescs = Analyzer.getArgDescList();
668+
ArrayRef<ArgumentDescriptor> ArgDescs = Optimizer.getArgDescList();
669669
for (auto &ArgDesc : ArgDescs) {
670670
ArgDesc.addCallerArgs(Builder, FAS, NewArgs);
671671
}
@@ -719,7 +719,7 @@ static void rewriteApplyInstToCallNewFunction(FunctionAnalyzer &Analyzer,
719719
}
720720

721721
static void createThunkBody(SILBasicBlock *BB, SILFunction *NewF,
722-
FunctionAnalyzer &Analyzer) {
722+
SignatureOptimizer &Optimizer) {
723723
// TODO: What is the proper location to use here?
724724
SILLocation Loc = BB->getParent()->getLocation();
725725
SILBuilder Builder(BB);
@@ -729,7 +729,7 @@ static void createThunkBody(SILBasicBlock *BB, SILFunction *NewF,
729729

730730
// Create the args for the thunk's apply, ignoring any dead arguments.
731731
llvm::SmallVector<SILValue, 8> ThunkArgs;
732-
ArrayRef<ArgumentDescriptor> ArgDescs = Analyzer.getArgDescList();
732+
ArrayRef<ArgumentDescriptor> ArgDescs = Optimizer.getArgDescList();
733733
for (auto &ArgDesc : ArgDescs) {
734734
ArgDesc.addThunkArgs(Builder, BB, ThunkArgs);
735735
}
@@ -791,22 +791,22 @@ static void createThunkBody(SILBasicBlock *BB, SILFunction *NewF,
791791
static SILFunction *
792792
moveFunctionBodyToNewFunctionWithName(SILFunction *F,
793793
const std::string &NewFName,
794-
FunctionAnalyzer &Analyzer) {
794+
SignatureOptimizer &Optimizer) {
795795
// First we create an empty function (i.e. no BB) whose function signature has
796796
// had its arity modified.
797797
//
798798
// We only do this to remove dead arguments. All other function signature
799799
// optimization is done later by modifying the function signature elements
800800
// themselves.
801-
SILFunction *NewF = Analyzer.createEmptyFunctionWithOptimizedSig(NewFName);
801+
SILFunction *NewF = Optimizer.createEmptyFunctionWithOptimizedSig(NewFName);
802802
// Then we transfer the body of F to NewF. At this point, the arguments of the
803803
// first BB will not match.
804804
NewF->spliceBody(F);
805805
// Do the same with the call graph.
806806

807807
// Then perform any updates to the arguments of NewF.
808808
SILBasicBlock *NewFEntryBB = &*NewF->begin();
809-
MutableArrayRef<ArgumentDescriptor> ArgDescs = Analyzer.getArgDescList();
809+
MutableArrayRef<ArgumentDescriptor> ArgDescs = Optimizer.getArgDescList();
810810
unsigned ArgOffset = 0;
811811
SILBuilder Builder(NewFEntryBB->begin());
812812
Builder.setCurrentDebugScope(NewFEntryBB->getParent()->getDebugScope());
@@ -824,7 +824,7 @@ moveFunctionBodyToNewFunctionWithName(SILFunction *F,
824824
for (auto &ArgDesc : ArgDescs) {
825825
ThunkBody->createBBArg(ArgDesc.ParameterInfo.getSILType(), ArgDesc.Decl);
826826
}
827-
createThunkBody(ThunkBody, NewF, Analyzer);
827+
createThunkBody(ThunkBody, NewF, Optimizer);
828828

829829
F->setThunk(IsThunk);
830830
assert(F->getDebugScope()->SILFn != NewF->getDebugScope()->SILFn);
@@ -852,8 +852,8 @@ static bool optimizeFunctionSignature(llvm::BumpPtrAllocator &BPA,
852852
llvm::SmallVector<ArgumentDescriptor, 8> Arguments;
853853

854854
// 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()) {
857857
DEBUG(llvm::dbgs() << " Has no optimizable arguments... "
858858
"bailing...\n");
859859
return false;
@@ -864,7 +864,7 @@ static bool optimizeFunctionSignature(llvm::BumpPtrAllocator &BPA,
864864

865865
++NumFunctionSignaturesOptimized;
866866

867-
auto NewFName = Analyzer.getOptimizedName();
867+
auto NewFName = Optimizer.getOptimizedName();
868868

869869
// If we already have a specialized version of this function, do not
870870
// respecialize. For now just bail.
@@ -878,13 +878,13 @@ static bool optimizeFunctionSignature(llvm::BumpPtrAllocator &BPA,
878878

879879
// Otherwise, move F over to NewF.
880880
SILFunction *NewF =
881-
moveFunctionBodyToNewFunctionWithName(F, NewFName, Analyzer);
881+
moveFunctionBodyToNewFunctionWithName(F, NewFName, Optimizer);
882882

883883
// And remove all Callee releases that we found and made redundant via owned
884884
// to guaranteed conversion.
885885
//
886886
// 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()) {
888888
if (A.CalleeRelease) {
889889
A.CalleeRelease->eraseFromParent();
890890
if (A.CalleeReleaseInThrowBlock) {
@@ -895,7 +895,7 @@ static bool optimizeFunctionSignature(llvm::BumpPtrAllocator &BPA,
895895

896896
// Rewrite all apply insts calling F to call NewF. Update each call site as
897897
// appropriate given the form of function signature optimization performed.
898-
rewriteApplyInstToCallNewFunction(Analyzer, NewF, CallSites);
898+
rewriteApplyInstToCallNewFunction(Optimizer, NewF, CallSites);
899899

900900
return true;
901901
}

0 commit comments

Comments
 (0)