-/// \brief Locate the DISubprogram for F.
-///
-/// We look for the first instruction that has a debug annotation
-/// leading back to \p F.
-///
-/// \returns a valid DISubprogram, if found. Otherwise, it returns an empty
-/// DISubprogram.
-static const DISubprogram getDISubprogram(Function &F, const LLVMContext &Ctx) {
- for (auto &BI : F) {
- BasicBlock *BB = &BI;
- for (auto &Inst : BB->getInstList()) {
- DebugLoc DLoc = Inst.getDebugLoc();
- if (DLoc.isUnknown())
- continue;
- const MDNode *Scope = DLoc.getScopeNode(Ctx);
- DISubprogram Subprogram = getDISubprogram(Scope);
- return Subprogram.describes(&F) ? Subprogram : DISubprogram();
- }
- }
-
- return DISubprogram();
-}
-