Skip to content

Commit be1881a

Browse files
committed
Remove redundant Transform.getName() definitions.
At some point, pass definitions were heavily macro-ized. Pass descriptive names were added in two places. This is not only redundant but a source of confusion. You could waste a lot of time grepping for the wrong string. I removed all the getName() overrides which, at around 90 passes, was a fairly significant amount of code bloat. Any pass that we want to be able to invoke by name from a tool (sil-opt) or pipeline plan *should* have unique type name, enum value, commend-line string, and name string. I removed a comment about the various inliner passes that contradicted that. Side note: We should be consistent with the policy that a pass is identified by its type. We have a couple passes, LICM and CSE, which currently violate that convention.
1 parent 3bcbf04 commit be1881a

File tree

103 files changed

+82
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+82
-184
lines changed

include/swift/SILOptimizer/PassManager/PassPipeline.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class SILPassPipelinePlan final {
5050
SILPassPipelinePlan(const SILPassPipelinePlan &) = default;
5151

5252
// Each pass gets its own add-function.
53-
#define PASS(ID, NAME, DESCRIPTION) \
53+
#define PASS(ID, TAG, NAME) \
5454
void add##ID() { \
5555
assert(!PipelineStages.empty() && "startPipeline before adding passes."); \
5656
Kinds.push_back(PassKind::ID); \

include/swift/SILOptimizer/PassManager/Passes.def

+19-7
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,33 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
/// PASS(Id, Name, Description)
18-
/// The pass is identified by PassKind::Id, and there exists a
19-
/// global function swift::create##Id().
17+
/// PASS(Id, Tag, Name)
18+
/// Id is a pass "identifier", used for its enum case, PassKind::Id,
19+
/// and type name, as returned by the global function swift::create##Id().
20+
///
21+
/// Tag identifies the pass as a command-line compatible option string.
22+
///
23+
/// Name is the descriptive, human readable pass name.
24+
///
25+
/// All three if these fields are unique identifiers which may be used in test
26+
/// cases and tools to specify a pass by string. Different tools simply prefer
27+
/// different identifier formats. Changing any of one these strings may change
28+
/// the functionality of some tests.
2029
///
2130
/// This macro must be defined by the includer.
2231
#ifndef PASS
2332
#error "Macro must be defined by includer"
2433
#endif
2534

26-
/// IRGEN_PASS(Id, Name, Description)
27-
/// The pass is identified by PassKind::Id.
28-
/// An IRGen pass is created by IRGen and needs to be register with the pass
35+
/// IRGEN_PASS(Id, Tag, Name)
36+
/// This macro follows the same conventions as PASS(Id, Tag, Name),
37+
/// but is used for IRGen passes which are built outside of the
38+
/// SILOptimizer library.
39+
///
40+
/// An IRGen pass is created by IRGen and needs to be registered with the pass
2941
/// manager dynamically.
3042
#ifndef IRGEN_PASS
31-
#define IRGEN_PASS(Id, Name, Description) PASS(Id, Name, Description)
43+
#define IRGEN_PASS(Id, Tag, Name) PASS(Id, Tag, Name)
3244
#endif
3345

3446
/// PASS_RANGE(RANGE_ID, START, END)

include/swift/SILOptimizer/PassManager/Passes.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,19 @@ namespace swift {
6868
/// \brief Identifiers for all passes. Used to procedurally create passes from
6969
/// lists of passes.
7070
enum class PassKind {
71-
#define PASS(ID, NAME, DESCRIPTION) ID,
71+
#define PASS(ID, TAG, NAME) ID,
7272
#define PASS_RANGE(ID, START, END) ID##_First = START, ID##_Last = END,
7373
#include "Passes.def"
7474
invalidPassKind
7575
};
7676

7777
PassKind PassKindFromString(StringRef ID);
78-
StringRef PassKindName(PassKind Kind);
7978
StringRef PassKindID(PassKind Kind);
79+
StringRef PassKindTag(PassKind Kind);
80+
StringRef PassKindName(PassKind Kind);
8081

81-
#define PASS(ID, NAME, DESCRIPTION) SILTransform *create##ID();
82-
#define IRGEN_PASS(ID, NAME, DESCRIPTION)
82+
#define PASS(ID, TAG, NAME) SILTransform *create##ID();
83+
#define IRGEN_PASS(ID, TAG, NAME)
8384
#include "Passes.def"
8485

8586
} // end namespace swift

include/swift/SILOptimizer/PassManager/Transforms.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace swift {
6767
void injectPassManager(SILPassManager *PMM) { PM = PMM; }
6868

6969
/// Get the name of the transform.
70-
virtual llvm::StringRef getName() = 0;
70+
llvm::StringRef getName() { return PassKindName(getPassKind()); }
7171

7272
protected:
7373
/// \brief Searches for an analysis of type T in the list of registered

lib/IRGen/AllocStackHoisting.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ class AllocStackHoisting : public SILFunctionTransform {
426426
PM->invalidateAnalysis(F, SILAnalysis::InvalidationKind::Instructions);
427427
}
428428
}
429-
StringRef getName() override { return "alloc_stack Hoisting"; }
430429
};
431430
} // end anonymous namespace
432431

lib/IRGen/IRGen.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,9 @@ void swift::irgen::deleteIRGenModule(
645645
static void runIRGenPreparePasses(SILModule &Module,
646646
irgen::IRGenModule &IRModule) {
647647
SILPassManager PM(&Module, &IRModule);
648-
#define PASS(ID, Name, Description)
649-
#define IRGEN_PASS(ID, Name, Description) \
650-
PM.registerIRGenPass(swift::PassKind::ID, irgen::create##ID());
648+
#define PASS(ID, Tag, Name)
649+
#define IRGEN_PASS(ID, Tag, Name) \
650+
PM.registerIRGenPass(swift::PassKind::ID, irgen::create##ID());
651651
#include "swift/SILOptimizer/PassManager/Passes.def"
652652
PM.executePassPipelinePlan(
653653
SILPassPipelinePlan::getIRGenPreparePassPipeline());

lib/SILOptimizer/ARC/ARCLoopOpts.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ class ARCLoopOpts : public SILFunctionTransform {
8383
invalidateAnalysis(SILAnalysis::InvalidationKind::CallsAndInstructions);
8484
}
8585
}
86-
87-
StringRef getName() override { return "ARC Loop Opts"; }
8886
};
8987

9088
} // end anonymous namespace

lib/SILOptimizer/ARC/ARCSequenceOpts.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@ class ARCSequenceOpts : public SILFunctionTransform {
309309
}
310310

311311
}
312-
313-
StringRef getName() override { return "ARC Sequence Opts"; }
314312
};
315313

316314
} // end anonymous namespace

lib/SILOptimizer/IPO/CapturePromotion.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,6 @@ class CapturePromotionPass : public SILModuleTransform {
13061306

13071307
void processFunction(SILFunction *F, SmallVectorImpl<SILFunction*> &Worklist);
13081308

1309-
StringRef getName() override { return "Capture Promotion"; }
13101309
};
13111310

13121311
} // end anonymous namespace

lib/SILOptimizer/IPO/CapturePropagation.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ class CapturePropagation : public SILFunctionTransform
4141
public:
4242
void run() override;
4343

44-
StringRef getName() override { return "Captured Constant Propagation"; }
45-
4644
protected:
4745
bool optimizePartialApply(PartialApplyInst *PAI);
4846
SILFunction *specializeConstClosure(PartialApplyInst *PAI,

lib/SILOptimizer/IPO/ClosureSpecializer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ class SILClosureSpecializerTransform : public SILFunctionTransform {
677677

678678
void run() override;
679679

680-
StringRef getName() override { return "Closure Specialization"; }
681680
};
682681

683682
void SILClosureSpecializerTransform::run() {

lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,6 @@ class SILDeadFuncElimination : public SILModuleTransform {
844844
deadFunctionElimination.eliminateFunctions(this);
845845
}
846846

847-
StringRef getName() override { return "Dead Function Elimination"; }
848847
};
849848

850849
class SILExternalFuncDefinitionsElimination : public SILModuleTransform {
@@ -862,9 +861,6 @@ class SILExternalFuncDefinitionsElimination : public SILModuleTransform {
862861
EFDFE.eliminateFunctions(this);
863862
}
864863

865-
StringRef getName() override {
866-
return "External Function Definitions Elimination";
867-
}
868864
};
869865

870866
} // end anonymous namespace

lib/SILOptimizer/IPO/EagerSpecializer.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,6 @@ class EagerSpecializerTransform : public SILModuleTransform {
685685

686686
void run() override;
687687

688-
StringRef getName() override { return "Eager Specializer"; }
689688
};
690689
} // end anonymous namespace
691690

lib/SILOptimizer/IPO/ExternalDefsToDecls.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class ExternalDefsToDecls : public SILModuleTransform {
3333
}
3434
}
3535

36-
StringRef getName() override { return "External Defs To Decls"; }
3736
};
3837

3938
} // end anonymous namespace

lib/SILOptimizer/IPO/GlobalOpt.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ class SILGlobalOptPass : public SILModuleTransform
930930
}
931931
}
932932

933-
StringRef getName() override { return "SIL Global Optimization"; }
934933
};
935934
} // end anonymous namespace
936935

lib/SILOptimizer/IPO/GlobalPropertyOpt.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,6 @@ class GlobalPropertyOptPass : public SILModuleTransform {
523523
GlobalPropertyOpt(*M).run(this);
524524
}
525525

526-
StringRef getName() override { return "GlobalPropertyOpt"; }
527526
};
528527

529528
} // end anonymous namespace

lib/SILOptimizer/IPO/LetPropertiesOpts.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,6 @@ class LetPropertiesOptPass : public SILModuleTransform
610610
LetPropertiesOpt(getModule()).run(this);
611611
}
612612

613-
StringRef getName() override {
614-
return "SIL Let Properties Optimization";
615-
}
616613
};
617614
} // end anonymous namespace
618615

lib/SILOptimizer/IPO/UsePrespecialized.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ class UsePrespecialized: public SILModuleTransform {
5252
}
5353
}
5454

55-
StringRef getName() override {
56-
return "Use pre-specialized versions of functions";
57-
}
58-
5955
bool replaceByPrespecialized(SILFunction &F);
6056
};
6157

lib/SILOptimizer/LoopTransforms/ArrayBoundsCheckOpts.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1311,8 +1311,6 @@ class ABCOpt : public SILFunctionTransform {
13111311
public:
13121312
ABCOpt() {}
13131313

1314-
StringRef getName() override { return "SIL Array bounds check optimization"; }
1315-
13161314
void run() override {
13171315
if (!EnableABCOpts)
13181316
return;

lib/SILOptimizer/LoopTransforms/COWArrayOpt.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,6 @@ class COWArrayOptPass : public SILFunctionTransform {
16021602
}
16031603
}
16041604

1605-
StringRef getName() override { return "SIL COW Array Optimization"; }
16061605
};
16071606
} // end anonymous namespace
16081607

@@ -2346,7 +2345,6 @@ class SwiftArrayOptPass : public SILFunctionTransform {
23462345
}
23472346
}
23482347

2349-
StringRef getName() override { return "SIL Swift Array Optimization"; }
23502348
};
23512349
} // end anonymous namespace
23522350

lib/SILOptimizer/LoopTransforms/LICM.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ void LoopTreeOptimization::optimizeLoop(SILLoop *CurrentLoop,
526526

527527
namespace {
528528
/// Hoist loop invariant code out of innermost loops.
529+
///
530+
/// Transforms are identified by type, not instance. Split this
531+
/// Into two types: "High-level Loop Invariant Code Motion"
532+
/// and "Loop Invariant Code Motion".
529533
class LICM : public SILFunctionTransform {
530534

531535
public:
@@ -536,11 +540,6 @@ class LICM : public SILFunctionTransform {
536540
/// We only hoist semantic calls on high-level SIL because we can be sure that
537541
/// e.g. an Array as SILValue is really immutable (including its content).
538542
bool RunsOnHighLevelSil;
539-
540-
StringRef getName() override {
541-
return RunsOnHighLevelSil ? "High-level Loop Invariant Code Motion" :
542-
"Loop Invariant Code Motion";
543-
}
544543

545544
void run() override {
546545
SILFunction *F = getFunction();

lib/SILOptimizer/LoopTransforms/LoopRotate.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,6 @@ namespace {
398398

399399
class LoopRotation : public SILFunctionTransform {
400400

401-
StringRef getName() override { return "SIL Loop Rotation"; }
402-
403401
void run() override {
404402
SILLoopAnalysis *LA = PM->getAnalysis<SILLoopAnalysis>();
405403
assert(LA);

lib/SILOptimizer/LoopTransforms/LoopUnroll.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,6 @@ namespace {
424424

425425
class LoopUnrolling : public SILFunctionTransform {
426426

427-
StringRef getName() override { return "SIL Loop Unrolling"; }
428-
429427
void run() override {
430428
bool Changed = false;
431429

lib/SILOptimizer/Mandatory/AddressLowering.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1452,8 +1452,6 @@ class AddressLowering : public SILModuleTransform {
14521452
/// The entry point to this function transformation.
14531453
void run() override;
14541454

1455-
StringRef getName() override { return "Address Lowering"; }
1456-
14571455
void runOnFunction(SILFunction *F);
14581456
};
14591457
} // end anonymous namespace

lib/SILOptimizer/Mandatory/ConstantPropagation.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1154,8 +1154,6 @@ class ConstantPropagation : public SILFunctionTransform {
11541154
invalidateAnalysis(Invalidation);
11551155
}
11561156
}
1157-
1158-
StringRef getName() override { return "Constant Propagation"; }
11591157
};
11601158

11611159
} // end anonymous namespace

lib/SILOptimizer/Mandatory/DataflowDiagnostics.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ namespace {
122122
class EmitDFDiagnostics : public SILFunctionTransform {
123123
~EmitDFDiagnostics() override {}
124124

125-
StringRef getName() override { return "Emit Dataflow Diagnostics"; }
126-
127125
/// The entry point to the transformation.
128126
void run() override {
129127
SILModule &M = getFunction()->getModule();

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,6 @@ class DefiniteInitialization : public SILFunctionTransform {
27012701
invalidateAnalysis(SILAnalysis::InvalidationKind::FunctionBody);
27022702
}
27032703

2704-
StringRef getName() override { return "Definite Initialization"; }
27052704
};
27062705
} // end anonymous namespace
27072706

lib/SILOptimizer/Mandatory/DiagnoseUnreachable.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,6 @@ namespace {
791791
void run() override {
792792
performNoReturnFunctionProcessing(getModule(), this);
793793
}
794-
795-
StringRef getName() override { return "NoReturnFolding"; }
796794
};
797795
} // end anonymous namespace
798796

@@ -806,8 +804,6 @@ namespace {
806804
void run() override {
807805
performSILDiagnoseUnreachable(getModule(), this);
808806
}
809-
810-
StringRef getName() override { return "Diagnose Unreachable"; }
811807
};
812808
} // end anonymous namespace
813809

lib/SILOptimizer/Mandatory/GuaranteedARCOpts.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,6 @@ struct GuaranteedARCOpts : SILFunctionTransform {
221221
invalidateAnalysis(SILAnalysis::InvalidationKind::Instructions);
222222
}
223223
}
224-
225-
StringRef getName() override { return "Guaranteed ARC Opts"; }
226224
};
227225

228226
} // end anonymous namespace

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ class MandatoryInlining : public SILModuleTransform {
582582
}
583583
}
584584

585-
StringRef getName() override { return "Mandatory Inlining"; }
586585
};
587586
} // end anonymous namespace
588587

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,6 @@ class PredictableMemoryOptimizations : public SILFunctionTransform {
10181018
invalidateAnalysis(SILAnalysis::InvalidationKind::FunctionBody);
10191019
}
10201020

1021-
StringRef getName() override { return "Predictable Memory Opts"; }
10221021
};
10231022
} // end anonymous namespace
10241023

lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ struct SemanticARCOpts : SILFunctionTransform {
166166
}
167167
}
168168

169-
StringRef getName() override { return "Semantic ARC Opts"; }
170169
};
171170

172171
} // end anonymous namespace

lib/SILOptimizer/PassManager/PassManager.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,14 @@ void SILPassManager::addPass(PassKind Kind) {
607607
assert(unsigned(PassKind::AllPasses_Last) >= unsigned(Kind) &&
608608
"Invalid pass kind");
609609
switch (Kind) {
610-
#define PASS(ID, NAME, DESCRIPTION) \
610+
#define PASS(ID, TAG, NAME) \
611611
case PassKind::ID: { \
612612
SILTransform *T = swift::create##ID(); \
613613
T->setPassKind(PassKind::ID); \
614614
Transformations.push_back(T); \
615615
break; \
616616
}
617-
#define IRGEN_PASS(ID, NAME, DESCRIPTION) \
617+
#define IRGEN_PASS(ID, TAG, NAME) \
618618
case PassKind::ID: { \
619619
SILTransform *T = IRGenPasses[unsigned(Kind)]; \
620620
assert(T && "Missing IRGen pass?"); \
@@ -631,7 +631,7 @@ void SILPassManager::addPass(PassKind Kind) {
631631

632632
void SILPassManager::addPassForName(StringRef Name) {
633633
PassKind P = llvm::StringSwitch<PassKind>(Name)
634-
#define PASS(ID, NAME, DESCRIPTION) .Case(#ID, PassKind::ID)
634+
#define PASS(ID, TAG, NAME) .Case(#ID, PassKind::ID)
635635
#include "swift/SILOptimizer/PassManager/Passes.def"
636636
;
637637
addPass(P);

0 commit comments

Comments
 (0)