Skip to content

Commit 753f06e

Browse files
committed
[region-isolation] Propagate through the whole source operand instead of just the representative of the source value when constructing assign and merge.
This will let me know the exact source operand used instead of the source value representative. This will ensure that the name associated with the diagnostic is not of the representative value, but the actual value that was the source of the assign. This is an NFCI commit that is an algebraic refactor. (cherry picked from commit ae797d4)
1 parent a54ddae commit 753f06e

File tree

4 files changed

+154
-72
lines changed

4 files changed

+154
-72
lines changed

include/swift/SIL/InstWrappers.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ class SelectEnumOperation {
221221
return sei->getCase(i);
222222
return value.get<SelectEnumAddrInst *>()->getCase(i);
223223
}
224+
225+
std::pair<EnumElementDecl *, Operand *> getCaseOperand(unsigned i) const {
226+
if (auto *sei = value.dyn_cast<SelectEnumInst *>())
227+
return sei->getCaseOperand(i);
228+
return value.get<SelectEnumAddrInst *>()->getCaseOperand(i);
229+
}
230+
224231
/// Return the value that will be used as the result for the specified enum
225232
/// case.
226233
SILValue getCaseResult(EnumElementDecl *D) {
@@ -229,6 +236,12 @@ class SelectEnumOperation {
229236
return value.get<SelectEnumAddrInst *>()->getCaseResult(D);
230237
}
231238

239+
Operand *getCaseResultOperand(EnumElementDecl *D) {
240+
if (auto *sei = value.dyn_cast<SelectEnumInst *>())
241+
return sei->getCaseResultOperand(D);
242+
return value.get<SelectEnumAddrInst *>()->getCaseResultOperand(D);
243+
}
244+
232245
/// If the default refers to exactly one case decl, return it.
233246
NullablePtr<EnumElementDecl> getUniqueCaseForDefault();
234247

@@ -243,6 +256,12 @@ class SelectEnumOperation {
243256
return sei->getDefaultResult();
244257
return value.get<SelectEnumAddrInst *>()->getDefaultResult();
245258
}
259+
260+
Operand *getDefaultResultOperand() const {
261+
if (auto *sei = value.dyn_cast<SelectEnumInst *>())
262+
return sei->getDefaultResultOperand();
263+
return value.get<SelectEnumAddrInst *>()->getDefaultResultOperand();
264+
}
246265
};
247266

248267
class ForwardingOperation {

include/swift/SIL/SILInstruction.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7018,6 +7018,12 @@ class SelectEnumInstBase : public BaseTy {
70187018
getAllOperands()[i+1].get());
70197019
}
70207020

7021+
std::pair<EnumElementDecl *, Operand *> getCaseOperand(unsigned i) const {
7022+
auto *self = const_cast<SelectEnumInstBase *>(this);
7023+
return std::make_pair(getEnumElementDeclStorage()[i],
7024+
&self->getAllOperands()[i + 1]);
7025+
}
7026+
70217027
/// Return the value that will be used as the result for the specified enum
70227028
/// case.
70237029
SILValue getCaseResult(EnumElementDecl *D) {
@@ -7030,6 +7036,18 @@ class SelectEnumInstBase : public BaseTy {
70307036
return getDefaultResult();
70317037
}
70327038

7039+
Operand *getCaseResultOperand(EnumElementDecl *D) {
7040+
for (unsigned i = 0, e = getNumCases(); i != e; ++i) {
7041+
auto Entry = getCaseOperand(i);
7042+
if (Entry.first == D)
7043+
return Entry.second;
7044+
}
7045+
7046+
// select_enum is required to be fully covered, so return the default if we
7047+
// didn't find anything.
7048+
return getDefaultResultOperand();
7049+
}
7050+
70337051
bool hasDefault() const {
70347052
return sharedUInt8().SelectEnumInstBase.hasDefault;
70357053
}
@@ -7039,6 +7057,12 @@ class SelectEnumInstBase : public BaseTy {
70397057
return getAllOperands().back().get();
70407058
}
70417059

7060+
Operand *getDefaultResultOperand() const {
7061+
assert(hasDefault() && "doesn't have a default");
7062+
auto *self = const_cast<SelectEnumInstBase *>(this);
7063+
return &self->getAllOperands().back();
7064+
}
7065+
70427066
unsigned getNumCases() const {
70437067
return getAllOperands().size() - 1 - hasDefault();
70447068
}

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,15 +510,23 @@ class PartitionOp {
510510
"Transfer needs a sourceInst");
511511
}
512512

513+
PartitionOp(PartitionOpKind opKind, Element arg1, Element arg2,
514+
Operand *sourceOp = nullptr)
515+
: opKind(opKind), opArgs({arg1, arg2}), source(sourceOp) {
516+
assert((opKind == PartitionOpKind::Assign ||
517+
opKind == PartitionOpKind::Merge) &&
518+
"Only supported for assign and merge");
519+
}
520+
513521
PartitionOp(PartitionOpKind opKind, SILInstruction *sourceInst)
514522
: opKind(opKind), opArgs(), source(sourceInst) {}
515523

516524
friend class Partition;
517525

518526
public:
519-
static PartitionOp Assign(Element tgt, Element src,
520-
SILInstruction *sourceInst = nullptr) {
521-
return PartitionOp(PartitionOpKind::Assign, tgt, src, sourceInst);
527+
static PartitionOp Assign(Element destElt, Element srcElt,
528+
Operand *srcOperand = nullptr) {
529+
return PartitionOp(PartitionOpKind::Assign, destElt, srcElt, srcOperand);
522530
}
523531

524532
static PartitionOp AssignFresh(Element tgt,
@@ -535,9 +543,10 @@ class PartitionOp {
535543
return PartitionOp(PartitionOpKind::UndoTransfer, tgt, untransferringInst);
536544
}
537545

538-
static PartitionOp Merge(Element tgt1, Element tgt2,
539-
SILInstruction *sourceInst = nullptr) {
540-
return PartitionOp(PartitionOpKind::Merge, tgt1, tgt2, sourceInst);
546+
static PartitionOp Merge(Element destElement, Element srcElement,
547+
Operand *sourceOperand = nullptr) {
548+
return PartitionOp(PartitionOpKind::Merge, destElement, srcElement,
549+
sourceOperand);
541550
}
542551

543552
static PartitionOp Require(Element tgt,

0 commit comments

Comments
 (0)