Skip to content

Commit 91fe4ee

Browse files
authored
Remove GPE pass implementation. (#24418)
1 parent ef21eaf commit 91fe4ee

26 files changed

+40
-14087
lines changed

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,20 +283,6 @@ PASS(SwiftArrayOpts, "array-specialize",
283283
// SWIFT_ENABLE_TENSORFLOW
284284
PASS(Differentiation, "differentiation",
285285
"Automatic Differentiation")
286-
PASS(TFDeabstractionMandatory, "tf-deabstraction-mandatory",
287-
"Deabstract tensor operations")
288-
PASS(TFDeabstractionOpt, "tf-deabstraction-opt",
289-
"Deabstract tensor operations")
290-
PASS(TFPartitionMandatory, "tf-partition-mandatory",
291-
"Partition accelerator operations out of mainline control flow")
292-
PASS(TFPartitionOpt, "tf-partition-opt",
293-
"Partition accelerator operations out of mainline control flow")
294-
PASS(TFPartitionTest, "tf-partition",
295-
"Partition accelerator operations out of mainline control flow")
296-
PASS(TFXLACFGCanonicalize, "tf-xla-cfg-canonicalize",
297-
"Canonicalize the control flow graph into SESE region for XLA")
298-
PASS(TFLowerGraph, "tf-lower-graph",
299-
"Lower the given control flow graph into a TF graph")
300286
// SWIFT_ENABLE_TENSORFLOW End
301287
PASS(UnsafeGuaranteedPeephole, "unsafe-guaranteed-peephole",
302288
"SIL retain/release Peephole Removal for Builtin.unsafeGuaranteed")

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,5 @@ silopt_register_sources(
2121
RawSILInstLowering.cpp
2222
MandatoryOptUtils.cpp
2323
# SWIFT_ENABLE_TENSORFLOW
24-
TFCanonicalizeCFG.cpp
2524
TFConstExpr.cpp
26-
TFDeabstraction.cpp
27-
TFDevicePartition.cpp
28-
TFLowerGraph.cpp
29-
TFPartition.cpp
30-
TFUtilities.cpp
3125
)

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 23 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@
2525
#include "llvm/ADT/DenseSet.h"
2626
#include "llvm/ADT/ImmutableSet.h"
2727
#include "llvm/ADT/Statistic.h"
28-
// SWIFT_ENABLE_TENSORFLOW
29-
#include "llvm/Support/CommandLine.h"
3028
#include "llvm/Support/Debug.h"
3129

3230
using namespace swift;
3331

3432
using DenseFunctionSet = llvm::DenseSet<SILFunction *>;
3533
using ImmutableFunctionSet = llvm::ImmutableSet<SILFunction *>;
3634

37-
// SWIFT_ENABLE_TENSORFLOW
38-
extern llvm::cl::opt<bool> TFLogDeabstractionStats;
39-
4035
STATISTIC(NumMandatoryInlines,
4136
"Number of function application sites inlined by the mandatory "
4237
"inlining pass");
@@ -306,9 +301,7 @@ static void collectPartiallyAppliedArguments(
306301
static SILFunction *getCalleeFunction(
307302
SILFunction *F, FullApplySite AI, bool &IsThick,
308303
SmallVectorImpl<std::pair<SILValue, ParameterConvention>> &CaptureArgs,
309-
SmallVectorImpl<SILValue> &FullArgs, PartialApplyInst *&PartialApply,
310-
// SWIFT_ENABLE_TENSORFLOW
311-
const ShouldMandatoryInlineFnPred &shouldInlinePredicate) {
304+
SmallVectorImpl<SILValue> &FullArgs, PartialApplyInst *&PartialApply) {
312305
IsThick = false;
313306
PartialApply = nullptr;
314307
CaptureArgs.clear();
@@ -454,11 +447,17 @@ static SILFunction *getCalleeFunction(
454447
return nullptr;
455448
}
456449

457-
// TODO(SR-8015): `shouldInlinePredicate` does too much. Fix this.
458450
// If the CalleeFunction is a not-transparent definition, we can not process
459451
// it.
460-
// SWIFT_ENABLE_TENSORFLOW
461-
if (!shouldInlinePredicate(AI, *CalleeFunction))
452+
if (CalleeFunction->isTransparent() == IsNotTransparent)
453+
return nullptr;
454+
455+
// If CalleeFunction is a declaration, see if we can load it.
456+
if (CalleeFunction->empty())
457+
AI.getModule().loadFunction(CalleeFunction);
458+
459+
// If we fail to load it, bail.
460+
if (CalleeFunction->empty())
462461
return nullptr;
463462

464463
if (F->isSerialized() &&
@@ -492,20 +491,6 @@ tryDevirtualizeApplyHelper(FullApplySite InnerAI, SILBasicBlock::iterator I,
492491
newApplyAI->getIterator());
493492
}
494493

495-
// SWIFT_ENABLE_TENSORFLOW
496-
// Event schema:
497-
//
498-
// "S4TF CallEdge", ParentName, ParentSizeBefore, ParentSizeAfter, ChildName,
499-
// ChildSize
500-
static void maybeLogCallEdge(SILFunction *parent, unsigned parentSizeBefore,
501-
SILFunction *child) {
502-
if (!TFLogDeabstractionStats)
503-
return;
504-
llvm::dbgs() << "S4TF CallEdge," << parent->getName() << ","
505-
<< parentSizeBefore << "," << parent->codeSize() << ","
506-
<< child->getName() << "," << child->codeSize() << "\n";
507-
}
508-
509494
/// \brief Inlines all mandatory inlined functions into the body of a function,
510495
/// first recursively inlining all mandatory apply instructions in those
511496
/// functions into their bodies if necessary.
@@ -520,14 +505,13 @@ static void maybeLogCallEdge(SILFunction *parent, unsigned parentSizeBefore,
520505
/// the current call stack of recursive calls
521506
///
522507
/// \returns true if successful, false if failed due to circular inlining.
523-
static bool runOnFunctionRecursively(
524-
SILOptFunctionBuilder &FuncBuilder, SILFunction *F, FullApplySite AI,
525-
DenseFunctionSet &FullyInlinedSet,
526-
ImmutableFunctionSet::Factory &SetFactory,
527-
ImmutableFunctionSet CurrentInliningSet, ClassHierarchyAnalysis *CHA,
528-
// SWIFT_ENABLE_TENSORFLOW
529-
SILInliner::InlineKind inlineKind,
530-
const ShouldMandatoryInlineFnPred &shouldInlinePredicate) {
508+
static bool
509+
runOnFunctionRecursively(SILOptFunctionBuilder &FuncBuilder,
510+
SILFunction *F, FullApplySite AI,
511+
DenseFunctionSet &FullyInlinedSet,
512+
ImmutableFunctionSet::Factory &SetFactory,
513+
ImmutableFunctionSet CurrentInliningSet,
514+
ClassHierarchyAnalysis *CHA) {
531515
// Avoid reprocessing functions needlessly.
532516
if (FullyInlinedSet.count(F))
533517
return true;
@@ -574,18 +558,15 @@ static bool runOnFunctionRecursively(
574558
bool IsThick;
575559
PartialApplyInst *PAI;
576560
SILFunction *CalleeFunction = getCalleeFunction(
577-
F, InnerAI, IsThick, CaptureArgs, FullArgs, PAI,
578-
shouldInlinePredicate); // SWIFT_ENABLE_TENSORFLOW
561+
F, InnerAI, IsThick, CaptureArgs, FullArgs, PAI);
579562

580563
if (!CalleeFunction)
581564
continue;
582565

583566
// Then recursively process it first before trying to inline it.
584567
if (!runOnFunctionRecursively(FuncBuilder, CalleeFunction, InnerAI,
585568
FullyInlinedSet, SetFactory,
586-
CurrentInliningSet, CHA,
587-
// SWIFT_ENABLE_TENSORFLOW
588-
inlineKind, shouldInlinePredicate)) {
569+
CurrentInliningSet, CHA)) {
589570
// If we failed due to circular inlining, then emit some notes to
590571
// trace back the failure if we have more information.
591572
// FIXME: possibly it could be worth recovering and attempting other
@@ -616,10 +597,8 @@ static bool runOnFunctionRecursively(
616597
OpenedArchetypesTracker.registerUsedOpenedArchetypes(PAI);
617598
}
618599

619-
// SWIFT_ENABLE_TENSORFLOW
620-
unsigned parentSizeBefore = F->codeSize();
621-
SILInliner Inliner(FuncBuilder, inlineKind, Subs,
622-
OpenedArchetypesTracker);
600+
SILInliner Inliner(FuncBuilder, SILInliner::InlineKind::MandatoryInline,
601+
Subs, OpenedArchetypesTracker);
623602
if (!Inliner.canInlineApplySite(InnerAI)) {
624603
// See comment above about casting when devirtualizing and how this
625604
// sometimes causes II and InnerAI to be different and even in different
@@ -666,9 +645,6 @@ static bool runOnFunctionRecursively(
666645
assert(nextI == ApplyBlock->end()
667646
|| nextI->getParent() == ApplyBlock
668647
&& "Mismatch between the instruction and basic block");
669-
670-
// SWIFT_ENABLE_TENSORFLOW
671-
maybeLogCallEdge(F, parentSizeBefore, CalleeFunction);
672648
}
673649
}
674650

@@ -678,29 +654,6 @@ static bool runOnFunctionRecursively(
678654
return true;
679655
}
680656

681-
// SWIFT_ENABLE_TENSORFLOW
682-
/// Scan the given function body, mandatory inlining calls to callees that
683-
/// satisfy the specified predicate, including calls sites exposed by inlining
684-
/// other functions.
685-
///
686-
/// The deabstraction phase of TensorFlow support needs to mandatory inline
687-
/// certain functions using the standard mandatory inlining algorithm. This
688-
/// function implements support for it, inlining direct calls to callees that
689-
/// satisfy the given predicate.
690-
void swift::inlineForTFDeabstraction(SILOptFunctionBuilder &FB, SILFunction &fn,
691-
const ShouldMandatoryInlineFnPred &predicate) {
692-
DenseFunctionSet FullyInlinedSet;
693-
ImmutableFunctionSet::Factory SetFactory;
694-
695-
runOnFunctionRecursively(FB, &fn,
696-
FullApplySite(static_cast<ApplyInst*>(nullptr)),
697-
FullyInlinedSet,
698-
SetFactory, SetFactory.getEmptySet(),
699-
/*CHA*/nullptr,
700-
SILInliner::InlineKind::PerformanceInline,
701-
predicate);
702-
}
703-
704657
//===----------------------------------------------------------------------===//
705658
// Top Level Driver
706659
//===----------------------------------------------------------------------===//
@@ -726,24 +679,9 @@ class MandatoryInlining : public SILModuleTransform {
726679
if (F.wasDeserializedCanonical())
727680
continue;
728681

729-
// SWIFT_ENABLE_TENSORFLOW
730682
runOnFunctionRecursively(FuncBuilder, &F,
731-
FullApplySite(),
732-
FullyInlinedSet,
733-
SetFactory, SetFactory.getEmptySet(), CHA,
734-
SILInliner::InlineKind::MandatoryInline,
735-
[&](FullApplySite site, SILFunction &callee) -> bool {
736-
if (callee.isTransparent() != IsTransparent)
737-
return false;
738-
739-
// If CalleeFunction is a declaration, see if we can load it.
740-
if (callee.empty())
741-
site.getModule().loadFunction(&callee);
742-
743-
// If we failed to load it, bail.
744-
return !callee.empty();
745-
}
746-
);
683+
FullApplySite(), FullyInlinedSet, SetFactory,
684+
SetFactory.getEmptySet(), CHA);
747685
}
748686

749687
if (!ShouldCleanup)

0 commit comments

Comments
 (0)