MCPcopy Create free account
hub / github.com/AliveToolkit/alive2 / get_base_ptr

Function get_base_ptr

tools/transform.cpp:800–840  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

798}
799
800static 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
842static bool may_be_nonlocal(Value *ptr) {
843 vector<Value*> todo = { ptr };

Callers 1

optimize_ptrcmpFunction · 0.85

Calls 7

isNoOpFunction · 0.85
getTrueValueMethod · 0.80
getFalseValueMethod · 0.80
operandsMethod · 0.45
endMethod · 0.45
beginMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected