Skip to content

Revert "[sil-performance-inliner] Re-introduce inlining of generics as a staging feature behind a flag" #5372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 6 additions & 48 deletions lib/SILOptimizer/Transforms/PerformanceInliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/SILOptimizer/PassManager/Transforms.h"
#include "swift/SILOptimizer/Utils/PerformanceInlinerUtils.h"
#include "swift/Strings.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/CommandLine.h"
Expand All @@ -27,10 +26,6 @@ llvm::cl::opt<bool> PrintShortestPathInfo(
"print-shortest-path-info", llvm::cl::init(false),
llvm::cl::desc("Print shortest-path information for inlining"));

llvm::cl::opt<bool> EnableSILInliningOfGenerics(
"sil-inline-generics", llvm::cl::init(false),
llvm::cl::desc("Enable inlining of generics"));

//===----------------------------------------------------------------------===//
// Performance Inliner
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -127,11 +122,6 @@ class SILPerformanceInliner {
ConstantTracker &constTracker,
int &NumCallerBlocks);

bool isProfitableToInlineGeneric(FullApplySite AI,
Weight CallerWeight,
ConstantTracker &constTracker,
int &NumCallerBlocks);

bool isProfitableInColdBlock(FullApplySite AI, SILFunction *Callee);

void visitColdBlocks(SmallVectorImpl<FullApplySite> &AppliesToInline,
Expand Down Expand Up @@ -201,6 +191,10 @@ SILFunction *SILPerformanceInliner::getEligibleFunction(FullApplySite AI) {
return nullptr;
}

// We don't support this yet.
if (AI.hasSubstitutions())
return nullptr;

SILFunction *Caller = AI.getFunction();

// We don't support inlining a function that binds dynamic self because we
Expand Down Expand Up @@ -375,37 +369,6 @@ bool SILPerformanceInliner::isProfitableToInlineNonGeneric(FullApplySite AI,
return true;
}

/// Return true if inlining this call site is profitable.
bool SILPerformanceInliner::isProfitableToInlineGeneric(FullApplySite AI,
Weight CallerWeight,
ConstantTracker &callerTracker,
int &NumCallerBlocks) {
assert(!AI.getSubstitutions().empty() &&
"Expected a generic apply");

SILFunction *Callee = AI.getReferencedFunction();

// Do not inline @_semantics functions when compiling the stdlib,
// because they need to be preserved, so that the optimizer
// can properly optimize a user code later.
auto ModuleName = Callee->getModule().getSwiftModule()->getName().str();
if (Callee->hasSemanticsAttrThatStartsWith("array.") &&
(ModuleName == STDLIB_NAME || ModuleName == SWIFT_ONONE_SUPPORT))
return false;

// Always inline generic functions which are marked as
// AlwaysInline or transparent.
bool ShouldInline = Callee->getInlineStrategy() == AlwaysInline ||
Callee->isTransparent();

// Only inline if we decided to inline or we are asked to inline all
// generic functions.
if (ShouldInline || EnableSILInliningOfGenerics)
return true;

return false;
}

/// Return true if inlining this call site into a cold block is profitable.
bool SILPerformanceInliner::isProfitableInColdBlock(FullApplySite AI,
SILFunction *Callee) {
Expand Down Expand Up @@ -519,13 +482,8 @@ void SILPerformanceInliner::collectAppliesToInline(
// The actual weight including a possible weight correction.
Weight W(BlockWeight, WeightCorrections.lookup(AI));

bool IsGenericApply = !AI.getSubstitutions().empty();
bool IsProfitableToInline =
IsGenericApply ? isProfitableToInlineGeneric(AI, W, constTracker,
NumCallerBlocks)
: isProfitableToInlineNonGeneric(AI, W, constTracker,
NumCallerBlocks);

bool IsProfitableToInline = isProfitableToInlineNonGeneric(
AI, W, constTracker, NumCallerBlocks);
if (IsProfitableToInline)
InitialCandidates.push_back(AI);
}
Expand Down