@@ -1526,55 +1526,71 @@ constantFoldGlobalStringTablePointerBuiltin(BuiltinInst *bi,
1526
1526
}
1527
1527
1528
1528
// / Initialize the worklist to all of the constant instructions.
1529
- void ConstantFolder::initializeWorklist (SILFunction &F) {
1530
- for (auto &BB : F) {
1531
- for (auto &I : BB) {
1529
+ void ConstantFolder::initializeWorklist (SILFunction &f) {
1530
+ for (auto &block : f) {
1531
+ for (auto ii = block.begin (), ie = block.end (); ii != ie; ) {
1532
+ auto *inst = &*ii;
1533
+ ++ii;
1534
+
1535
+ // TODO: Eliminate trivially dead instructions here.
1536
+
1532
1537
// If `I` is a floating-point literal instruction where the literal is
1533
1538
// inf, it means the input has a literal that overflows even
1534
1539
// MaxBuiltinFloatType. Diagnose this error, but allow this instruction
1535
1540
// to be folded, if needed.
1536
- if (auto floatLit = dyn_cast<FloatLiteralInst>(&I )) {
1541
+ if (auto * floatLit = dyn_cast<FloatLiteralInst>(inst )) {
1537
1542
APFloat fpVal = floatLit->getValue ();
1538
1543
if (EnableDiagnostics && fpVal.isInfinity ()) {
1539
1544
SmallString<10 > litStr;
1540
1545
tryExtractLiteralText (floatLit, litStr);
1541
- diagnose (I. getModule ().getASTContext (), I. getLoc ().getSourceLoc (),
1546
+ diagnose (inst-> getModule ().getASTContext (), inst-> getLoc ().getSourceLoc (),
1542
1547
diag::warning_float_overflows_maxbuiltin, litStr,
1543
1548
fpVal.isNegative ());
1544
1549
}
1545
1550
}
1546
1551
1547
- if (isFoldable (&I ) && I. hasUsesOfAnyResult ()) {
1548
- WorkList.insert (&I );
1552
+ if (isFoldable (inst ) && inst-> hasUsesOfAnyResult ()) {
1553
+ WorkList.insert (inst );
1549
1554
continue ;
1550
1555
}
1551
1556
1552
1557
// - Should we replace calls to assert_configuration by the assert
1553
1558
// configuration and fold calls to any cond_unreachable.
1554
1559
if (AssertConfiguration != SILOptions::DisableReplacement &&
1555
- (isApplyOfBuiltin (I, BuiltinValueKind::AssertConf) ||
1556
- isApplyOfBuiltin (I, BuiltinValueKind::CondUnreachable))) {
1557
- WorkList.insert (&I);
1560
+ (isApplyOfBuiltin (*inst, BuiltinValueKind::AssertConf) ||
1561
+ isApplyOfBuiltin (*inst, BuiltinValueKind::CondUnreachable))) {
1562
+ WorkList.insert (inst);
1563
+ continue ;
1564
+ }
1565
+
1566
+ if (isApplyOfBuiltin (*inst, BuiltinValueKind::GlobalStringTablePointer)) {
1567
+ WorkList.insert (inst);
1558
1568
continue ;
1559
1569
}
1560
1570
1561
- if (isApplyOfBuiltin (I, BuiltinValueKind::GlobalStringTablePointer)) {
1562
- WorkList.insert (&I);
1571
+ if (isa<CheckedCastBranchInst>(inst) ||
1572
+ isa<CheckedCastAddrBranchInst>(inst) ||
1573
+ isa<UnconditionalCheckedCastInst>(inst) ||
1574
+ isa<UnconditionalCheckedCastAddrInst>(inst)) {
1575
+ WorkList.insert (inst);
1563
1576
continue ;
1564
1577
}
1565
1578
1566
- if (isa<CheckedCastBranchInst>(&I) ||
1567
- isa<CheckedCastAddrBranchInst>(&I) ||
1568
- isa<UnconditionalCheckedCastInst>(&I) ||
1569
- isa<UnconditionalCheckedCastAddrInst>(&I)) {
1570
- WorkList.insert (&I);
1579
+ if (isApplyOfStringConcat (*inst)) {
1580
+ WorkList.insert (inst);
1571
1581
continue ;
1572
1582
}
1573
1583
1574
- if (!isApplyOfStringConcat (I)) {
1584
+ // If we have nominal type literals like struct, tuple, enum visit them
1585
+ // like we do in the worklist to see if we can fold any projection
1586
+ // manipulation operations.
1587
+ if (isa<StructInst>(inst) || isa<TupleInst>(inst)) {
1588
+ // TODO: Enum.
1589
+ WorkList.insert (inst);
1575
1590
continue ;
1576
1591
}
1577
- WorkList.insert (&I);
1592
+
1593
+ // ...
1578
1594
}
1579
1595
}
1580
1596
}
0 commit comments