Skip to content

Commit 40f0980

Browse files
committed
SIL: simplify the SILNode getParent functions.
A small cleanup, NFC.
1 parent e4f2bbf commit 40f0980

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,7 @@ class SILInstruction
405405
return SILInstructionKind(SILNode::getKind());
406406
}
407407

408-
const SILBasicBlock *getParent() const { return ParentBB; }
409-
SILBasicBlock *getParent() { return ParentBB; }
408+
SILBasicBlock *getParent() const { return ParentBB; }
410409

411410
SILFunction *getFunction();
412411
const SILFunction *getFunction() const;

lib/SIL/IR/SILValue.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,32 +99,25 @@ ValueBase::getDefiningInstructionResult() {
9999
}
100100

101101
SILBasicBlock *SILNode::getParentBlock() const {
102-
auto *CanonicalNode =
103-
const_cast<SILNode *>(this)->getRepresentativeSILNodeInObject();
104-
if (auto *Inst = dyn_cast<SILInstruction>(CanonicalNode))
102+
if (auto *Inst = dyn_cast<SILInstruction>(this))
105103
return Inst->getParent();
106-
if (auto *Arg = dyn_cast<SILArgument>(CanonicalNode))
104+
if (auto *Arg = dyn_cast<SILArgument>(this))
107105
return Arg->getParent();
106+
if (auto *MVR = dyn_cast<MultipleValueInstructionResult>(this)) {
107+
return MVR->getParent()->getParent();
108+
}
108109
return nullptr;
109110
}
110111

111112
SILFunction *SILNode::getFunction() const {
112-
auto *CanonicalNode =
113-
const_cast<SILNode *>(this)->getRepresentativeSILNodeInObject();
114-
if (auto *Inst = dyn_cast<SILInstruction>(CanonicalNode))
115-
return Inst->getFunction();
116-
if (auto *Arg = dyn_cast<SILArgument>(CanonicalNode))
117-
return Arg->getFunction();
113+
if (auto *parentBlock = getParentBlock())
114+
return parentBlock->getParent();
118115
return nullptr;
119116
}
120117

121118
SILModule *SILNode::getModule() const {
122-
auto *CanonicalNode =
123-
const_cast<SILNode *>(this)->getRepresentativeSILNodeInObject();
124-
if (auto *Inst = dyn_cast<SILInstruction>(CanonicalNode))
125-
return &Inst->getModule();
126-
if (auto *Arg = dyn_cast<SILArgument>(CanonicalNode))
127-
return &Arg->getModule();
119+
if (SILFunction *func = getFunction())
120+
return &func->getModule();
128121
return nullptr;
129122
}
130123

0 commit comments

Comments
 (0)