| 1011 | } |
| 1012 | |
| 1013 | bool IRContext::ProcessReachableCallTree(ProcessFunction& pfn) { |
| 1014 | std::queue<uint32_t> roots; |
| 1015 | |
| 1016 | // Add all entry points since they can be reached from outside the module. |
| 1017 | for (auto& e : module()->entry_points()) |
| 1018 | roots.push(e.GetSingleWordInOperand(kEntryPointFunctionIdInIdx)); |
| 1019 | |
| 1020 | // Add all exported functions since they can be reached from outside the |
| 1021 | // module. |
| 1022 | for (auto& a : annotations()) { |
| 1023 | // TODO: Handle group decorations as well. Currently not generate by any |
| 1024 | // front-end, but could be coming. |
| 1025 | if (a.opcode() == spv::Op::OpDecorate) { |
| 1026 | if (spv::Decoration(a.GetSingleWordOperand(1)) == |
| 1027 | spv::Decoration::LinkageAttributes) { |
| 1028 | uint32_t lastOperand = a.NumOperands() - 1; |
| 1029 | if (spv::LinkageType(a.GetSingleWordOperand(lastOperand)) == |
| 1030 | spv::LinkageType::Export) { |
| 1031 | uint32_t id = a.GetSingleWordOperand(0); |
| 1032 | if (GetFunction(id)) { |
| 1033 | roots.push(id); |
| 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | return ProcessCallTreeFromRoots(pfn, &roots); |
| 1041 | } |
| 1042 | |
| 1043 | bool IRContext::ProcessCallTreeFromRoots(ProcessFunction& pfn, |
| 1044 | std::queue<uint32_t>* roots) { |