[sil] Complement ValueBase::getParentBB() with ValueBase::get{Function,Module}().

These APIs work just like getParentBB does, namely they attempt to cast
self to either SILInstruction/SILArgument and if the instance is one of
those classes, using the APIs on said classes to get the relevant
Function or Module. If the dynamic casts fail, then nullptr is returned.
This commit is contained in:
Michael Gottesman
2016-10-22 15:33:36 -07:00
parent d010a09b05
commit 3eaa25bcd6
2 changed files with 26 additions and 0 deletions

View File

@@ -38,3 +38,19 @@ SILBasicBlock *ValueBase::getParentBB() {
return Arg->getParent();
return nullptr;
}
SILFunction *ValueBase::getFunction() {
if (auto Inst = dyn_cast<SILInstruction>(this))
return Inst->getFunction();
if (auto Arg = dyn_cast<SILArgument>(this))
return Arg->getFunction();
return nullptr;
}
SILModule *ValueBase::getModule() {
if (auto Inst = dyn_cast<SILInstruction>(this))
return &Inst->getModule();
if (auto Arg = dyn_cast<SILArgument>(this))
return &Arg->getModule();
return nullptr;
}