| 45 | } |
| 46 | |
| 47 | std::set<RDNode> RDAnalyzer::findRootDefinitions(Use &U) { |
| 48 | unsigned OpIdx = U.getOperandNo(); |
| 49 | auto *I = dyn_cast_or_null<Instruction>(U.getUser()); |
| 50 | if (!I) |
| 51 | return {}; |
| 52 | |
| 53 | auto *F = I->getFunction(); |
| 54 | if (!F) |
| 55 | return {}; |
| 56 | |
| 57 | RDNode Node(OpIdx, *I); |
| 58 | |
| 59 | auto *CB = dyn_cast_or_null<CallBase>(I); |
| 60 | if (!CB) |
| 61 | return traverseFunction(Node, *F, true, false); |
| 62 | |
| 63 | auto *CF = CB->getCalledFunction(); |
| 64 | if (!CF) |
| 65 | return traverseFunction(Node, *F, true, false); |
| 66 | |
| 67 | if (CF->isDeclaration()) |
| 68 | Node.setFirstUse(*CB, OpIdx); |
| 69 | |
| 70 | if (isForcedDef(Node)) { |
| 71 | Node.setForcedDef(); |
| 72 | return {Node}; |
| 73 | } |
| 74 | |
| 75 | if (CF->isDeclaration()) { |
| 76 | auto OutParamIndices = getOutParamIndices(*CB); |
| 77 | |
| 78 | if (OutParamIndices.find(OpIdx) == OutParamIndices.end()) { |
| 79 | return traverseFunction(Node, *F, true, false); |
| 80 | } |
| 81 | |
| 82 | std::set<RDNode> Result; |
| 83 | for (size_t S = 0, E = CB->getNumArgOperands(); S < E; ++S) { |
| 84 | if (OutParamIndices.find(S) != OutParamIndices.end()) |
| 85 | continue; |
| 86 | |
| 87 | for (auto &Trace : findRootDefinitions(CB->getOperandUse(S))) |
| 88 | mergeRDNode(Result, Trace); |
| 89 | } |
| 90 | |
| 91 | if (Result.size() == 0) { |
| 92 | RDNode NewNode(OpIdx, *CB, &Node); |
| 93 | NewNode.setForcedDef(); |
| 94 | mergeRDNode(Result, NewNode); |
| 95 | } |
| 96 | |
| 97 | return Result; |
| 98 | } |
| 99 | |
| 100 | return traverseFunction(Node, *F, true, false); |
| 101 | } |
| 102 | |
| 103 | std::set<RDNode> RDAnalyzer::traverseFunction(RDNode &Node, Function &F, |
| 104 | bool TraceCaller, |
nothing calls this directly
no test coverage detected