mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user