Skip to content

Commit cac03a6

Browse files
committed
[SIL] Let addArgumentToBranch accept plural args.
Previously, the addArgumentToBranch only allowed one to add a single additional argument to a branch. It then verified the argument count. That is a problem if multiple arguments have to be added to arrive at the correct argument count. Specifically, that was a problem when running Mem2Reg on a lexical alloc_stack, where three new phi arguments are added. Here, the function name is changed to addArgumentsToBranch (plural arguments) and the function accepts a SmallVector<SILValue> rather than a single SILValue, allowing one to add all the arguments that are necessary in order to verify that the resulting number of arguments is correct.
1 parent d97a24a commit cac03a6

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

include/swift/SILOptimizer/Utils/InstOptUtils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ bool isAddressOfArrayElement(SILValue addr);
190190
/// Move an ApplyInst's FuncRef so that it dominates the call site.
191191
void placeFuncRef(ApplyInst *ai, DominanceInfo *dt);
192192

193-
/// Add an argument, \p val, to the branch-edge that is pointing into
193+
/// Add arguments, \p vals, to the branch-edge that is pointing into
194194
/// block \p Dest. Return a new instruction and do not erase the old
195195
/// instruction.
196-
TermInst *addArgumentToBranch(SILValue val, SILBasicBlock *dest,
197-
TermInst *branch);
196+
TermInst *addArgumentsToBranch(ArrayRef<SILValue> vals, SILBasicBlock *dest,
197+
TermInst *branch);
198198

199199
/// Get the linkage to be used for specializations of a function with
200200
/// the given linkage.

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,8 @@ void swift::placeFuncRef(ApplyInst *ai, DominanceInfo *domInfo) {
864864
/// Add an argument, \p val, to the branch-edge that is pointing into
865865
/// block \p Dest. Return a new instruction and do not erase the old
866866
/// instruction.
867-
TermInst *swift::addArgumentToBranch(SILValue val, SILBasicBlock *dest,
868-
TermInst *branch) {
867+
TermInst *swift::addArgumentsToBranch(ArrayRef<SILValue> vals,
868+
SILBasicBlock *dest, TermInst *branch) {
869869
SILBuilderWithScope builder(branch);
870870

871871
if (auto *cbi = dyn_cast<CondBranchInst>(branch)) {
@@ -879,10 +879,12 @@ TermInst *swift::addArgumentToBranch(SILValue val, SILBasicBlock *dest,
879879
falseArgs.push_back(arg);
880880

881881
if (dest == cbi->getTrueBB()) {
882-
trueArgs.push_back(val);
882+
for (auto val : vals)
883+
trueArgs.push_back(val);
883884
assert(trueArgs.size() == dest->getNumArguments());
884885
} else {
885-
falseArgs.push_back(val);
886+
for (auto val : vals)
887+
falseArgs.push_back(val);
886888
assert(falseArgs.size() == dest->getNumArguments());
887889
}
888890

@@ -898,7 +900,8 @@ TermInst *swift::addArgumentToBranch(SILValue val, SILBasicBlock *dest,
898900
for (auto arg : bi->getArgs())
899901
args.push_back(arg);
900902

901-
args.push_back(val);
903+
for (auto val : vals)
904+
args.push_back(val);
902905
assert(args.size() == dest->getNumArguments());
903906
return builder.createBranch(bi->getLoc(), bi->getDestBB(), args);
904907
}

0 commit comments

Comments
 (0)