| 798 | } |
| 799 | |
| 800 | static Value *get_base_ptr(Value *ptr) { |
| 801 | vector<Value*> todo = { ptr }; |
| 802 | Value *base_ptr = nullptr; |
| 803 | set<Value*> seen; |
| 804 | do { |
| 805 | ptr = todo.back(); |
| 806 | todo.pop_back(); |
| 807 | if (!seen.insert(ptr).second) |
| 808 | continue; |
| 809 | |
| 810 | if (auto gep = dynamic_cast<GEP*>(ptr)) { |
| 811 | todo.emplace_back(&gep->getPtr()); |
| 812 | continue; |
| 813 | } |
| 814 | |
| 815 | if (auto c = isNoOp(*ptr)) { |
| 816 | todo.emplace_back(c); |
| 817 | continue; |
| 818 | } |
| 819 | |
| 820 | if (auto phi = dynamic_cast<Phi*>(ptr)) { |
| 821 | auto ops = phi->operands(); |
| 822 | todo.insert(todo.end(), ops.begin(), ops.end()); |
| 823 | continue; |
| 824 | } |
| 825 | |
| 826 | if (auto s = dynamic_cast<Select*>(ptr)) { |
| 827 | todo.emplace_back(s->getTrueValue()); |
| 828 | todo.emplace_back(s->getFalseValue()); |
| 829 | continue; |
| 830 | } |
| 831 | |
| 832 | if (base_ptr && base_ptr != ptr) |
| 833 | return nullptr; |
| 834 | |
| 835 | base_ptr = ptr; |
| 836 | |
| 837 | } while (!todo.empty()); |
| 838 | |
| 839 | return base_ptr; |
| 840 | } |
| 841 | |
| 842 | static bool may_be_nonlocal(Value *ptr) { |
| 843 | vector<Value*> todo = { ptr }; |
no test coverage detected