Skip to content

Commit e648016

Browse files
committed
SILOptimizer: Remove isSimpleType()
This was checking if the type is a trivial type that is not a class. However this was redundant because class types are not trivial anyway.
1 parent 6dce95f commit e648016

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

include/swift/SILOptimizer/Utils/Local.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,11 +522,6 @@ bool simplifyUsers(SingleValueInstruction *I);
522522
/// without a significant increase to code size.
523523
bool shouldExpand(SILModule &Module, SILType Ty);
524524

525-
/// Check if a given type is a simple type, i.e. a builtin
526-
/// integer or floating point type or a struct/tuple whose members
527-
/// are of simple types.
528-
bool isSimpleType(SILType SILTy, SILModule& Module);
529-
530525
/// Check if the value of V is computed by means of a simple initialization.
531526
/// Store the actual SILValue into \p Val and the reversed list of instructions
532527
/// initializing it in \p Insns.

lib/SILOptimizer/IPO/GlobalOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ void SILGlobalOpt::collectGlobalAccess(GlobalAddrInst *GAI) {
816816
if (GlobalVarSkipProcessing.count(SILG))
817817
return;
818818

819-
if (!isSimpleType(SILG->getLoweredType(), *Module)) {
819+
if (!SILG->getLoweredType().isTrivial(*Module)) {
820820
GlobalVarSkipProcessing.insert(SILG);
821821
return;
822822
}

lib/SILOptimizer/IPO/LetPropertiesOpts.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,11 @@ bool LetPropertiesOpt::isConstantLetProperty(VarDecl *Property) {
372372
<< "' has no unknown uses\n");
373373

374374
// Only properties of simple types can be optimized.
375-
if (!isSimpleType(Module->Types.getLoweredType(Property->getType()), *Module)) {
375+
376+
// FIXME: Expansion
377+
auto &TL = Module->Types.getTypeLowering(Property->getType(),
378+
ResilienceExpansion::Minimal);
379+
if (!TL.isTrivial()) {
376380
LLVM_DEBUG(llvm::dbgs() << "Property '" << *Property
377381
<< "' is not of trivial type\n");
378382
SkipProcessing.insert(Property);

lib/SILOptimizer/Utils/Local.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,22 +1518,6 @@ bool swift::shouldExpand(SILModule &Module, SILType Ty) {
15181518

15191519
/// Some support functions for the global-opt and let-properties-opts
15201520

1521-
/// Check if a given type is a simple type, i.e. a builtin
1522-
/// integer or floating point type or a struct/tuple whose members
1523-
/// are of simple types.
1524-
/// TODO: Cache the "simple" flag for types to avoid repeating checks.
1525-
bool swift::isSimpleType(SILType SILTy, SILModule& Module) {
1526-
// Classes can never be initialized statically at compile-time.
1527-
if (SILTy.getClassOrBoundGenericClass()) {
1528-
return false;
1529-
}
1530-
1531-
if (!SILTy.isTrivial(Module))
1532-
return false;
1533-
1534-
return true;
1535-
}
1536-
15371521
// Encapsulate the state used for recursive analysis of a static
15381522
// initializer. Discover all the instruction in a use-def graph and return them
15391523
// in topological order.
@@ -1583,7 +1567,7 @@ class StaticInitializerAnalysis {
15831567
bool recursivelyAnalyzeInstruction(SILInstruction *I) {
15841568
if (auto *SI = dyn_cast<StructInst>(I)) {
15851569
// If it is not a struct which is a simple type, bail.
1586-
if (!isSimpleType(SI->getType(), SI->getModule()))
1570+
if (!SI->getType().isTrivial(SI->getModule()))
15871571
return false;
15881572

15891573
return llvm::all_of(SI->getAllOperands(), [&](Operand &Op) -> bool {
@@ -1592,7 +1576,7 @@ class StaticInitializerAnalysis {
15921576
}
15931577
if (auto *TI = dyn_cast<TupleInst>(I)) {
15941578
// If it is not a tuple which is a simple type, bail.
1595-
if (!isSimpleType(TI->getType(), TI->getModule()))
1579+
if (!TI->getType().isTrivial(TI->getModule()))
15961580
return false;
15971581

15981582
return llvm::all_of(TI->getAllOperands(), [&](Operand &Op) -> bool {

0 commit comments

Comments
 (0)