| 397 | |
| 398 | template <typename T> |
| 399 | static bool removeUnused(T &data, const Function::UsersTy &users, |
| 400 | const vector<string_view> &src_glbs) { |
| 401 | bool changed = false; |
| 402 | for (auto I = data.begin(); I != data.end(); ) { |
| 403 | if (users.count(I->get())) { |
| 404 | ++I; |
| 405 | continue; |
| 406 | } |
| 407 | |
| 408 | // don't delete glbs in target that are used in src |
| 409 | if (auto gv = dynamic_cast<GlobalVariable*>(I->get())) { |
| 410 | auto name = string_view(gv->getName()).substr(1); |
| 411 | if (find(src_glbs.begin(), src_glbs.end(), name) != src_glbs.end()) { |
| 412 | ++I; |
| 413 | continue; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | I = data.erase(I); |
| 418 | changed = true; |
| 419 | } |
| 420 | return changed; |
| 421 | } |
| 422 | |
| 423 | bool Function::removeUnusedStuff(const UsersTy &users, |
| 424 | const vector<string_view> &src_glbs) { |
no test coverage detected