uniformize API of phi with switch
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -550,6 +550,10 @@ unique_ptr<Instr> Freeze::dup(const string &suffix) const {
}
+void Phi::addValue(Value &val, string &&BB_name) {
+ values.emplace_back(val, move(BB_name));
+}
+
void Phi::print(ostream &os) const {
os << getName() << " = phi ";
auto t = getType().toString();
@@ -595,7 +599,11 @@ expr Phi::getTypeConstraints(const Function &f) const {
}
unique_ptr<Instr> Phi::dup(const string &suffix) const {
- return make_unique<Phi>(getType(), getName() + suffix, ValTy(values));
+ auto phi = make_unique<Phi>(getType(), getName() + suffix);
+ for (auto &[val, bb] : values) {
+ phi->addValue(val, string(bb));
+ }
+ return phi;
}

MODIFY
ir/instr.h
ir/instr.h
@@ -149,13 +149,11 @@ public:
class Phi final : public Instr {
+ std::vector<std::pair<Value&, std::string>> values;
public:
- typedef std::vector<std::pair<Value&, std::string>> ValTy;
-private:
- ValTy values;
-public:
- Phi(Type &type, std::string &&name, ValTy &&values)
- : Instr(type, std::move(name)), values(std::move(values)) {}
+ Phi(Type &type, std::string &&name) : Instr(type, std::move(name)) {}
+
+ void addValue(Value &val, std::string &&BB_name);
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;

MODIFY
tv/tv.cpp
tv/tv.cpp
@@ -260,19 +260,19 @@ public:
}
RetTy visitPHINode(llvm::PHINode &i) {
- Phi::ValTy values;
auto ty = llvm_type2alive(i.getType());
if (!ty)
return error(i);
+ auto phi = make_unique<Phi>(*ty, value_name(i));
for (unsigned idx = 0, e = i.getNumIncomingValues(); idx != e; ++idx) {
auto op = get_operand(i.getIncomingValue(idx));
if (!op)
return error(i);
- values.emplace_back(*op, value_name(*i.getIncomingBlock(idx)));
+ phi->addValue(*op, value_name(*i.getIncomingBlock(idx)));
}
- RETURN_IDENTIFIER(make_unique<Phi>(*ty, value_name(i), move(values)));
+ RETURN_IDENTIFIER(move(phi));
}
RetTy visitBranchInst(llvm::BranchInst &i) {

uniformize API of phi with switch