@@ -494,82 +494,6 @@ Operand *UseWrapper::getOperand() {
494494 llvm_unreachable (" uninitialize use type" );
495495}
496496
497- // / At least one value feeding the specified SILArgument is a Struct. Attempt to
498- // / replace the Argument with a new Struct in the same block.
499- // /
500- // / When we handle more types of casts, this can become a template.
501- // /
502- // / ArgValues are the values feeding the specified Argument from each
503- // / predecessor. They must be listed in order of Arg->getParent()->getPreds().
504- static StructInst *
505- replaceBBArgWithStruct (SILPhiArgument *phiArg,
506- SmallVectorImpl<SILValue> &argValues) {
507-
508- SILBasicBlock *phiBlock = phiArg->getParent ();
509- auto *firstSI = dyn_cast<StructInst>(argValues[0 ]);
510- if (!firstSI)
511- return nullptr ;
512-
513- // Collect the BBArg index of each struct oper.
514- // e.g.
515- // struct(A, B)
516- // br (B, A)
517- // : ArgIdxForOper => {1, 0}
518- SmallVector<unsigned , 4 > argIdxForOper;
519- for (unsigned operIdx : indices (firstSI->getElements ())) {
520- bool foundMatchingArgIdx = false ;
521- for (unsigned argIdx : indices (phiBlock->getArguments ())) {
522- auto avIter = argValues.begin ();
523- bool tryNextArgIdx = false ;
524- for (SILBasicBlock *predBlock : phiBlock->getPredecessorBlocks ()) {
525- // All argument values must be StructInst.
526- auto *predSI = dyn_cast<StructInst>(*avIter++);
527- if (!predSI)
528- return nullptr ;
529- OperandValueArrayRef edgeValues =
530- getEdgeValuesForTerminator (predBlock->getTerminator (), phiBlock);
531- if (edgeValues[argIdx] != predSI->getElements ()[operIdx]) {
532- tryNextArgIdx = true ;
533- break ;
534- }
535- }
536- if (!tryNextArgIdx) {
537- assert (avIter == argValues.end () &&
538- " # ArgValues does not match # BB preds" );
539- foundMatchingArgIdx = true ;
540- argIdxForOper.push_back (argIdx);
541- break ;
542- }
543- }
544- if (!foundMatchingArgIdx)
545- return nullptr ;
546- }
547-
548- SmallVector<SILValue, 4 > structArgs;
549- for (auto argIdx : argIdxForOper)
550- structArgs.push_back (phiBlock->getArgument (argIdx));
551-
552- // TODO: We probably want to use a SILBuilderWithScope here. What should we
553- // use?
554- SILBuilder builder (phiBlock, phiBlock->begin ());
555- return builder.createStruct (cast<StructInst>(argValues[0 ])->getLoc (),
556- phiArg->getType (), structArgs);
557- }
558-
559- // / Canonicalize BB arguments, replacing argument-of-casts with
560- // / cast-of-arguments. This only eliminates existing arguments, replacing them
561- // / with casts. No new arguments are created. This allows downstream pattern
562- // / detection like induction variable analysis to succeed.
563- // /
564- // / If Arg is replaced, return the cast instruction. Otherwise return nullptr.
565- SILValue swift::replaceBBArgWithCast (SILPhiArgument *arg) {
566- SmallVector<SILValue, 4 > argValues;
567- arg->getIncomingPhiValues (argValues);
568- if (isa<StructInst>(argValues[0 ]))
569- return replaceBBArgWithStruct (arg, argValues);
570- return nullptr ;
571- }
572-
573497namespace swift ::test {
574498// Arguments:
575499// * the first arguments are values, which are added as "available values" to the SSA-updater
0 commit comments