Skip to content

Commit ae797d4

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.
1 parent ace94b0 commit ae797d4

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
@@ -7067,6 +7067,12 @@ class SelectEnumInstBase : public BaseTy {
70677067
getAllOperands()[i+1].get());
70687068
}
70697069

7070+
std::pair<EnumElementDecl *, Operand *> getCaseOperand(unsigned i) const {
7071+
auto *self = const_cast<SelectEnumInstBase *>(this);
7072+
return std::make_pair(getEnumElementDeclStorage()[i],
7073+
&self->getAllOperands()[i + 1]);
7074+
}
7075+
70707076
/// Return the value that will be used as the result for the specified enum
70717077
/// case.
70727078
SILValue getCaseResult(EnumElementDecl *D) {
@@ -7079,6 +7085,18 @@ class SelectEnumInstBase : public BaseTy {
70797085
return getDefaultResult();
70807086
}
70817087

7088+
Operand *getCaseResultOperand(EnumElementDecl *D) {
7089+
for (unsigned i = 0, e = getNumCases(); i != e; ++i) {
7090+
auto Entry = getCaseOperand(i);
7091+
if (Entry.first == D)
7092+
return Entry.second;
7093+
}
7094+
7095+
// select_enum is required to be fully covered, so return the default if we
7096+
// didn't find anything.
7097+
return getDefaultResultOperand();
7098+
}
7099+
70827100
bool hasDefault() const {
70837101
return sharedUInt8().SelectEnumInstBase.hasDefault;
70847102
}
@@ -7088,6 +7106,12 @@ class SelectEnumInstBase : public BaseTy {
70887106
return getAllOperands().back().get();
70897107
}
70907108

7109+
Operand *getDefaultResultOperand() const {
7110+
assert(hasDefault() && "doesn't have a default");
7111+
auto *self = const_cast<SelectEnumInstBase *>(this);
7112+
return &self->getAllOperands().back();
7113+
}
7114+
70917115
unsigned getNumCases() const {
70927116
return getAllOperands().size() - 1 - hasDefault();
70937117
}

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)