| 54 | } |
| 55 | |
| 56 | std::set<const Function *> |
| 57 | IndCallSolverMgr::getCalledFunctions(const CallBase &CB) const { |
| 58 | // Step 1. check strip Pointer |
| 59 | auto *CO = CB.getCalledOperand(); |
| 60 | if (!CO) |
| 61 | return {}; |
| 62 | |
| 63 | auto *V = CO->stripPointerCasts(); |
| 64 | if (!V) |
| 65 | return {}; |
| 66 | |
| 67 | if (V->getName() != "") { |
| 68 | if (auto *F = dyn_cast<Function>(V)) |
| 69 | return {F}; |
| 70 | |
| 71 | if (auto *GA = dyn_cast<GlobalAlias>(V)) { |
| 72 | const auto *F = dyn_cast_or_null<Function>(GA->getAliasee()); |
| 73 | if (F) |
| 74 | return {F}; |
| 75 | } |
| 76 | |
| 77 | return {}; |
| 78 | } |
| 79 | |
| 80 | // Step 2. check callee MD |
| 81 | auto *Node = CB.getMetadata(LLVMContext::MD_callees); |
| 82 | if (Node) |
| 83 | return {mdconst::extract<Function>(Node->getOperand(0))}; |
| 84 | |
| 85 | for (const auto &Solver : Solvers) { |
| 86 | assert(Solver && "Unexpected Program State"); |
| 87 | |
| 88 | auto Result = Solver->solve(CB); |
| 89 | if (Result.size() > 0) |
| 90 | return Result; |
| 91 | } |
| 92 | return {}; |
| 93 | } |