diff --git a/include/swift/SIL/SILValue.h b/include/swift/SIL/SILValue.h index 3761c8734da..cfd9407ad23 100644 --- a/include/swift/SIL/SILValue.h +++ b/include/swift/SIL/SILValue.h @@ -29,6 +29,8 @@ namespace swift { class ValueBaseUseIterator; class ValueUseIterator; class SILBasicBlock; + class SILFunction; + class SILModule; class SILInstruction; class SILLocation; class DominanceInfo; @@ -119,6 +121,14 @@ public: /// If this is a SILArgument or a SILInstruction get its parent basic block, /// otherwise return null. SILBasicBlock *getParentBB(); + + /// If this is a SILArgument or a SILInstruction get its parent function, + /// otherwise return null. + SILFunction *getFunction(); + + /// If this is a SILArgument or a SILInstruction get its parent module, + /// otherwise return null. + SILModule *getModule(); }; inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, diff --git a/lib/SIL/SILValue.cpp b/lib/SIL/SILValue.cpp index 9d7a3cda73a..3a047d8c4db 100644 --- a/lib/SIL/SILValue.cpp +++ b/lib/SIL/SILValue.cpp @@ -38,3 +38,19 @@ SILBasicBlock *ValueBase::getParentBB() { return Arg->getParent(); return nullptr; } + +SILFunction *ValueBase::getFunction() { + if (auto Inst = dyn_cast(this)) + return Inst->getFunction(); + if (auto Arg = dyn_cast(this)) + return Arg->getFunction(); + return nullptr; +} + +SILModule *ValueBase::getModule() { + if (auto Inst = dyn_cast(this)) + return &Inst->getModule(); + if (auto Arg = dyn_cast(this)) + return &Arg->getModule(); + return nullptr; +}