@@ -1526,71 +1526,55 @@ constantFoldGlobalStringTablePointerBuiltin(BuiltinInst *bi,
15261526}
15271527
15281528// / Initialize the worklist to all of the constant instructions.
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-
1529+ void ConstantFolder::initializeWorklist (SILFunction &F) {
1530+ for (auto &BB : F) {
1531+ for (auto &I : BB) {
15371532 // If `I` is a floating-point literal instruction where the literal is
15381533 // inf, it means the input has a literal that overflows even
15391534 // MaxBuiltinFloatType. Diagnose this error, but allow this instruction
15401535 // to be folded, if needed.
1541- if (auto * floatLit = dyn_cast<FloatLiteralInst>(inst )) {
1536+ if (auto floatLit = dyn_cast<FloatLiteralInst>(&I )) {
15421537 APFloat fpVal = floatLit->getValue ();
15431538 if (EnableDiagnostics && fpVal.isInfinity ()) {
15441539 SmallString<10 > litStr;
15451540 tryExtractLiteralText (floatLit, litStr);
1546- diagnose (inst-> getModule ().getASTContext (), inst-> getLoc ().getSourceLoc (),
1541+ diagnose (I. getModule ().getASTContext (), I. getLoc ().getSourceLoc (),
15471542 diag::warning_float_overflows_maxbuiltin, litStr,
15481543 fpVal.isNegative ());
15491544 }
15501545 }
15511546
1552- if (isFoldable (inst ) && inst-> hasUsesOfAnyResult ()) {
1553- WorkList.insert (inst );
1547+ if (isFoldable (&I ) && I. hasUsesOfAnyResult ()) {
1548+ WorkList.insert (&I );
15541549 continue ;
15551550 }
15561551
15571552 // - Should we replace calls to assert_configuration by the assert
15581553 // configuration and fold calls to any cond_unreachable.
15591554 if (AssertConfiguration != SILOptions::DisableReplacement &&
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);
1555+ (isApplyOfBuiltin (I, BuiltinValueKind::AssertConf) ||
1556+ isApplyOfBuiltin (I, BuiltinValueKind::CondUnreachable))) {
1557+ WorkList.insert (&I);
15681558 continue ;
15691559 }
15701560
1571- if (isa<CheckedCastBranchInst>(inst) ||
1572- isa<CheckedCastAddrBranchInst>(inst) ||
1573- isa<UnconditionalCheckedCastInst>(inst) ||
1574- isa<UnconditionalCheckedCastAddrInst>(inst)) {
1575- WorkList.insert (inst);
1561+ if (isApplyOfBuiltin (I, BuiltinValueKind::GlobalStringTablePointer)) {
1562+ WorkList.insert (&I);
15761563 continue ;
15771564 }
15781565
1579- if (isApplyOfStringConcat (*inst)) {
1580- WorkList.insert (inst);
1566+ if (isa<CheckedCastBranchInst>(&I) ||
1567+ isa<CheckedCastAddrBranchInst>(&I) ||
1568+ isa<UnconditionalCheckedCastInst>(&I) ||
1569+ isa<UnconditionalCheckedCastAddrInst>(&I)) {
1570+ WorkList.insert (&I);
15811571 continue ;
15821572 }
15831573
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);
1574+ if (!isApplyOfStringConcat (I)) {
15901575 continue ;
15911576 }
1592-
1593- // ...
1577+ WorkList.insert (&I);
15941578 }
15951579 }
15961580}
0 commit comments