Skip to content

Commit 075d3a4

Browse files
committed
Add SILValue::isFromVarDecl utility.
1 parent 7d65170 commit 075d3a4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,7 @@ enum HasPointerEscape_t : bool {
19781978
HasPointerEscape = true,
19791979
};
19801980

1981+
// See SILValue::isFromVarDecl()
19811982
enum IsFromVarDecl_t : bool {
19821983
IsNotFromVarDecl = false,
19831984
IsFromVarDecl = true,

include/swift/SIL/SILValue.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,12 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
609609
/// (it has a debug_value [trace] user).
610610
bool hasDebugTrace() const;
611611

612+
/// Does this SILValue begin a VarDecl scope? Only true in OSSA.
613+
///
614+
/// If this is true, the value must be a SingleValueInstruction whose first
615+
/// operand is the variable's initial value.
616+
bool isFromVarDecl();
617+
612618
static bool classof(SILNodePointer node) {
613619
return node->getKind() >= SILNodeKind::First_ValueBase &&
614620
node->getKind() <= SILNodeKind::Last_ValueBase;

lib/SIL/IR/SILValue.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ bool ValueBase::hasDebugTrace() const {
209209
return false;
210210
}
211211

212+
bool ValueBase::isFromVarDecl() {
213+
if (auto *mvi = dyn_cast<MoveValueInst>(this)) {
214+
return mvi->isFromVarDecl();
215+
}
216+
if (auto *bbi = dyn_cast<BeginBorrowInst>(this)) {
217+
return bbi->isFromVarDecl();
218+
}
219+
return false;
220+
}
221+
212222
SILBasicBlock *SILNode::getParentBlock() const {
213223
if (auto *Inst = dyn_cast<SILInstruction>(this))
214224
return Inst->getParent();

0 commit comments

Comments
 (0)