refactor Instr poison/side effect info
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -99,11 +99,6 @@ uint64_t getGlobalVarSize(const IR::Value *V) {
namespace IR {
-bool Instr::propagatesPoison() const {
- // be on the safe side
- return false;
-}
-
expr Instr::getTypeConstraints() const {
UNREACHABLE();
return {};
@@ -140,6 +135,10 @@ bool BinOp::propagatesPoison() const {
return true;
}
+bool BinOp::hasSideEffects() const {
+ return isDivOrRem() || (flags & NoUndef);
+}
+
void BinOp::rauw(const Value &what, Value &with) {
RAUW(lhs);
RAUW(rhs);
@@ -594,6 +593,10 @@ bool FpBinOp::propagatesPoison() const {
return true;
}
+bool FpBinOp::hasSideEffects() const {
+ return false;
+}
+
void FpBinOp::rauw(const Value &what, Value &with) {
RAUW(lhs);
RAUW(rhs);
@@ -907,6 +910,10 @@ bool UnaryOp::propagatesPoison() const {
return true;
}
+bool UnaryOp::hasSideEffects() const {
+ return false;
+}
+
void UnaryOp::rauw(const Value &what, Value &with) {
RAUW(val);
@@ -1037,6 +1044,10 @@ bool FpUnaryOp::propagatesPoison() const {
return true;
}
+bool FpUnaryOp::hasSideEffects() const {
+ return false;
+}
+
void FpUnaryOp::rauw(const Value &what, Value &with) {
RAUW(val);
}
@@ -1144,6 +1155,10 @@ bool UnaryReductionOp::propagatesPoison() const {
return true;
}
+bool UnaryReductionOp::hasSideEffects() const {
+ return false;
+}
+
void UnaryReductionOp::rauw(const Value &what, Value &with) {
RAUW(val);
}
@@ -1214,6 +1229,10 @@ bool TernaryOp::propagatesPoison() const {
return true;
}
+bool TernaryOp::hasSideEffects() const {
+ return false;
+}
+
void TernaryOp::rauw(const Value &what, Value &with) {
RAUW(a);
RAUW(b);
@@ -1329,6 +1348,10 @@ bool FpTernaryOp::propagatesPoison() const {
return true;
}
+bool FpTernaryOp::hasSideEffects() const {
+ return false;
+}
+
void FpTernaryOp::rauw(const Value &what, Value &with) {
RAUW(a);
RAUW(b);
@@ -1412,6 +1435,10 @@ bool TestOp::propagatesPoison() const {
return true;
}
+bool TestOp::hasSideEffects() const {
+ return false;
+}
+
void TestOp::rauw(const Value &what, Value &with) {
RAUW(lhs);
RAUW(rhs);
@@ -1435,10 +1462,7 @@ StateValue TestOp::toSMT(State &s) const {
case Is_FPClass:
fn = [&](const expr &v, const Type &ty) -> expr {
uint64_t n;
- if (!b.value.isUInt(n) || !b.non_poison.isTrue()) {
- s.addUB(expr(false));
- return {};
- }
+ ENSURE(b.value.isUInt(n) && b.non_poison.isTrue());
auto *fpty = ty.getAsFloatType();
auto a = fpty->getFloat(v);
OrExpr result;
@@ -1504,6 +1528,10 @@ bool ConversionOp::propagatesPoison() const {
return true;
}
+bool ConversionOp::hasSideEffects() const {
+ return false;
+}
+
void ConversionOp::rauw(const Value &what, Value &with) {
RAUW(val);
}
@@ -1645,6 +1673,10 @@ bool FpConversionOp::propagatesPoison() const {
return true;
}
+bool FpConversionOp::hasSideEffects() const {
+ return flags & NoUndef;
+}
+
void FpConversionOp::rauw(const Value &what, Value &with) {
RAUW(val);
}
@@ -1822,6 +1854,14 @@ vector<Value*> Select::operands() const {
return { cond, a, b };
}
+bool Select::propagatesPoison() const {
+ return false;
+}
+
+bool Select::hasSideEffects() const {
+ return false;
+}
+
void Select::rauw(const Value &what, Value &with) {
RAUW(cond);
RAUW(a);
@@ -1884,6 +1924,14 @@ vector<Value*> ExtractValue::operands() const {
return { val };
}
+bool ExtractValue::propagatesPoison() const {
+ return false;
+}
+
+bool ExtractValue::hasSideEffects() const {
+ return false;
+}
+
void ExtractValue::rauw(const Value &what, Value &with) {
RAUW(val);
}
@@ -1945,6 +1993,14 @@ vector<Value*> InsertValue::operands() const {
return { val, elt };
}
+bool InsertValue::propagatesPoison() const {
+ return false;
+}
+
+bool InsertValue::hasSideEffects() const {
+ return false;
+}
+
void InsertValue::rauw(const Value &what, Value &with) {
RAUW(val);
RAUW(elt);
@@ -2139,6 +2195,10 @@ vector<Value*> FnCall::operands() const {
return output;
}
+bool FnCall::propagatesPoison() const {
+ return false;
+}
+
void FnCall::rauw(const Value &what, Value &with) {
for (auto &arg : args) {
RAUW(arg.first);
@@ -2445,6 +2505,10 @@ bool ICmp::propagatesPoison() const {
return true;
}
+bool ICmp::hasSideEffects() const {
+ return false;
+}
+
bool ICmp::isPtrCmp() const {
auto &elem_ty = a->getType();
return elem_ty.isPtrType() ||
@@ -2569,6 +2633,14 @@ vector<Value*> FCmp::operands() const {
return { a, b };
}
+bool FCmp::propagatesPoison() const {
+ return true;
+}
+
+bool FCmp::hasSideEffects() const {
+ return false;
+}
+
void FCmp::rauw(const Value &what, Value &with) {
RAUW(a);
RAUW(b);
@@ -2656,6 +2728,14 @@ vector<Value*> Freeze::operands() const {
return { val };
}
+bool Freeze::propagatesPoison() const {
+ return false;
+}
+
+bool Freeze::hasSideEffects() const {
+ return false;
+}
+
void Freeze::rauw(const Value &what, Value &with) {
RAUW(val);
}
@@ -2740,6 +2820,14 @@ vector<Value*> Phi::operands() const {
return v;
}
+bool Phi::propagatesPoison() const {
+ return false;
+}
+
+bool Phi::hasSideEffects() const {
+ return false;
+}
+
void Phi::rauw(const Value &what, Value &with) {
for (auto &[val, bb] : values) {
RAUW(val);
@@ -2805,6 +2893,14 @@ unique_ptr<Instr> Phi::dup(Function &f, const string &suffix) const {
}
+bool JumpInstr::propagatesPoison() const {
+ return false;
+}
+
+bool JumpInstr::hasSideEffects() const {
+ return true;
+}
+
const BasicBlock& JumpInstr::target_iterator::operator*() const {
if (auto br = dynamic_cast<const Branch*>(instr))
return idx == 0 ? br->getTrue() : *br->getFalse();
@@ -2953,6 +3049,14 @@ vector<Value*> Return::operands() const {
return { val };
}
+bool Return::propagatesPoison() const {
+ return false;
+}
+
+bool Return::hasSideEffects() const {
+ return true;
+}
+
void Return::rauw(const Value &what, Value &with) {
RAUW(val);
}
@@ -3058,6 +3162,14 @@ vector<Value*> Assume::operands() const {
return args;
}
+bool Assume::propagatesPoison() const {
+ return false;
+}
+
+bool Assume::hasSideEffects() const {
+ return true;
+}
+
void Assume::rauw(const Value &what, Value &with) {
for (auto &arg: args)
RAUW(arg);
@@ -3158,6 +3270,14 @@ vector<Value*> AssumeVal::operands() const {
return ret;
}
+bool AssumeVal::propagatesPoison() const {
+ return true;
+}
+
+bool AssumeVal::hasSideEffects() const {
+ return false;
+}
+
void AssumeVal::rauw(const Value &what, Value &with) {
RAUW(val);
for (auto &arg: args)
@@ -3239,6 +3359,10 @@ unique_ptr<Instr> AssumeVal::dup(Function &f, const string &suffix) const {
}
+bool MemInstr::hasSideEffects() const {
+ return true;
+}
+
MemInstr::ByteAccessInfo MemInstr::ByteAccessInfo::intOnly(unsigned bytesz) {
ByteAccessInfo info;
info.byteSize = bytesz;
@@ -3290,6 +3414,10 @@ vector<Value*> Alloc::operands() const {
return { size };
}
+bool Alloc::propagatesPoison() const {
+ return true;
+}
+
void Alloc::rauw(const Value &what, Value &with) {
RAUW(size);
RAUW(mul);
@@ -3351,6 +3479,10 @@ vector<Value*> StartLifetime::operands() const {
return { ptr };
}
+bool StartLifetime::propagatesPoison() const {
+ return false;
+}
+
void StartLifetime::rauw(const Value &what, Value &with) {
RAUW(ptr);
}
@@ -3383,6 +3515,10 @@ vector<Value*> EndLifetime::operands() const {
return { ptr };
}
+bool EndLifetime::propagatesPoison() const {
+ return false;
+}
+
void EndLifetime::rauw(const Value &what, Value &with) {
RAUW(ptr);
}
@@ -3452,6 +3588,14 @@ vector<Value*> GEP::operands() const {
return v;
}
+bool GEP::propagatesPoison() const {
+ return true;
+}
+
+bool GEP::hasSideEffects() const {
+ return false;
+}
+
void GEP::rauw(const Value &what, Value &with) {
RAUW(ptr);
for (auto &[sz, idx] : idxs) {
@@ -3567,6 +3711,10 @@ vector<Value*> Load::operands() const {
return { ptr };
}
+bool Load::propagatesPoison() const {
+ return true;
+}
+
void Load::rauw(const Value &what, Value &with) {
RAUW(ptr);
}
@@ -3609,6 +3757,10 @@ vector<Value*> Store::operands() const {
return { val, ptr };
}
+bool Store::propagatesPoison() const {
+ return false;
+}
+
void Store::rauw(const Value &what, Value &with) {
RAUW(val);
RAUW(ptr);
@@ -3661,6 +3813,10 @@ vector<Value*> Memset::operands() const {
return { ptr, val, bytes };
}
+bool Memset::propagatesPoison() const {
+ return false;
+}
+
void Memset::rauw(const Value &what, Value &with) {
RAUW(ptr);
RAUW(val);
@@ -3728,6 +3884,10 @@ vector<Value*> MemsetPattern::operands() const {
return { ptr, pattern, bytes };
}
+bool MemsetPattern::propagatesPoison() const {
+ return false;
+}
+
void MemsetPattern::rauw(const Value &what, Value &with) {
RAUW(ptr);
RAUW(pattern);
@@ -3774,6 +3934,10 @@ vector<Value*> FillPoison::operands() const {
return { ptr };
}
+bool FillPoison::propagatesPoison() const {
+ return true;
+}
+
void FillPoison::rauw(const Value &what, Value &with) {
RAUW(ptr);
}
@@ -3822,6 +3986,10 @@ vector<Value*> Memcpy::operands() const {
return { dst, src, bytes };
}
+bool Memcpy::propagatesPoison() const {
+ return false;
+}
+
void Memcpy::rauw(const Value &what, Value &with) {
RAUW(dst);
RAUW(src);
@@ -3897,6 +4065,10 @@ vector<Value*> Memcmp::operands() const {
return { ptr1, ptr2, num };
}
+bool Memcmp::propagatesPoison() const {
+ return false;
+}
+
void Memcmp::rauw(const Value &what, Value &with) {
RAUW(ptr1);
RAUW(ptr2);
@@ -4006,6 +4178,10 @@ vector<Value*> Strlen::operands() const {
return { ptr };
}
+bool Strlen::propagatesPoison() const {
+ return true;
+}
+
void Strlen::rauw(const Value &what, Value &with) {
RAUW(ptr);
}
@@ -4050,6 +4226,14 @@ vector<Value*> VaStart::operands() const {
return { ptr };
}
+bool VaStart::propagatesPoison() const {
+ return true;
+}
+
+bool VaStart::hasSideEffects() const {
+ return true;
+}
+
void VaStart::rauw(const Value &what, Value &with) {
RAUW(ptr);
}
@@ -4103,6 +4287,14 @@ vector<Value*> VaEnd::operands() const {
return { ptr };
}
+bool VaEnd::propagatesPoison() const {
+ return true;
+}
+
+bool VaEnd::hasSideEffects() const {
+ return true;
+}
+
void VaEnd::rauw(const Value &what, Value &with) {
RAUW(ptr);
}
@@ -4164,6 +4356,14 @@ vector<Value*> VaCopy::operands() const {
return { dst, src };
}
+bool VaCopy::propagatesPoison() const {
+ return true;
+}
+
+bool VaCopy::hasSideEffects() const {
+ return true;
+}
+
void VaCopy::rauw(const Value &what, Value &with) {
RAUW(dst);
RAUW(src);
@@ -4221,6 +4421,14 @@ vector<Value*> VaArg::operands() const {
return { ptr };
}
+bool VaArg::propagatesPoison() const {
+ return true;
+}
+
+bool VaArg::hasSideEffects() const {
+ return true;
+}
+
void VaArg::rauw(const Value &what, Value &with) {
RAUW(ptr);
}
@@ -4280,6 +4488,15 @@ vector<Value*> ExtractElement::operands() const {
return { v, idx };
}
+bool ExtractElement::propagatesPoison() const {
+ // the output depends on the idx, so it may not propagate to all lanes
+ return false;
+}
+
+bool ExtractElement::hasSideEffects() const {
+ return false;
+}
+
void ExtractElement::rauw(const Value &what, Value &with) {
RAUW(v);
RAUW(idx);
@@ -4313,6 +4530,14 @@ vector<Value*> InsertElement::operands() const {
return { v, e, idx };
}
+bool InsertElement::propagatesPoison() const {
+ return false;
+}
+
+bool InsertElement::hasSideEffects() const {
+ return false;
+}
+
void InsertElement::rauw(const Value &what, Value &with) {
RAUW(v);
RAUW(e);
@@ -4350,6 +4575,15 @@ vector<Value*> ShuffleVector::operands() const {
return { v1, v2 };
}
+bool ShuffleVector::propagatesPoison() const {
+ // the output depends on the mask, so it may not propagate to all lanes
+ return false;
+}
+
+bool ShuffleVector::hasSideEffects() const {
+ return false;
+}
+
void ShuffleVector::rauw(const Value &what, Value &with) {
RAUW(v1);
RAUW(v2);
@@ -4397,17 +4631,6 @@ const ConversionOp* isCast(ConversionOp::Op op, const Value &v) {
return (c && c->getOp() == op) ? c : nullptr;
}
-bool hasNoSideEffects(const Instr &i) {
- return isNoOp(i) ||
- dynamic_cast<const ConversionOp*>(&i) ||
- dynamic_cast<const ExtractValue*>(&i) ||
- dynamic_cast<const Freeze*>(&i) ||
- dynamic_cast<const GEP*>(&i) ||
- dynamic_cast<const ICmp*>(&i) ||
- dynamic_cast<const InsertValue*>(&i) ||
- dynamic_cast<const ShuffleVector*>(&i);
-}
-
Value* isNoOp(const Value &v) {
if (auto *c = isCast(ConversionOp::BitCast, v))
return &c->getValue();

MODIFY
ir/instr.h
ir/instr.h
@@ -19,7 +19,8 @@ protected:
public:
virtual std::vector<Value*> operands() const = 0;
- virtual bool propagatesPoison() const;
+ virtual bool propagatesPoison() const = 0;
+ virtual bool hasSideEffects() const = 0;
smt::expr getTypeConstraints() const override;
virtual smt::expr getTypeConstraints(const Function &f) const = 0;
virtual std::unique_ptr<Instr> dup(Function &f,
@@ -49,6 +50,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -78,6 +80,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -105,6 +108,7 @@ public:
Value& getValue() const { return *val; }
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -137,6 +141,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -163,6 +168,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -187,6 +193,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -216,6 +223,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -239,6 +247,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -264,6 +273,7 @@ public:
Value& getValue() const { return *val; }
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -296,6 +306,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -317,6 +328,8 @@ public:
Value *getFalseValue() const { return b; }
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -335,6 +348,8 @@ public:
void addIdx(unsigned idx);
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -353,6 +368,8 @@ public:
void addIdx(unsigned idx);
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -389,6 +406,7 @@ public:
std::vector<Value*> operands() const override;
bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -414,6 +432,8 @@ public:
: Instr(type, std::move(name)), a(&a), b(&b), cond(cond), fmath(fmath) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -430,6 +450,8 @@ public:
: Instr(type, std::move(name)), val(&val) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -455,6 +477,8 @@ public:
std::vector<std::string> sources() const;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void replace(const std::string &predecessor, Value &newval);
void print(std::ostream &os) const override;
@@ -468,6 +492,8 @@ public:
class JumpInstr : public Instr {
public:
JumpInstr(const char *name) : Instr(Type::voidTy, name) {}
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
class target_iterator {
const JumpInstr *instr;
@@ -549,6 +575,8 @@ public:
Return(Type &type, Value &val) : Instr(type, "return"), val(&val) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -576,6 +604,8 @@ public:
Assume(std::vector<Value *> &&args, Kind kind);
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -604,6 +634,8 @@ public:
std::vector<Value *> &&args, Kind kind);
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -617,6 +649,8 @@ class MemInstr : public Instr {
public:
MemInstr(Type &type, std::string &&name) : Instr(type, std::move(name)) {}
+ bool hasSideEffects() const override;
+
// If this instruction allocates a memory block, return its size and
// alignment. Returns 0 if it doesn't allocate anything.
virtual std::pair<uint64_t, uint64_t> getMaxAllocSize() const = 0;
@@ -673,6 +707,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -694,6 +729,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -714,6 +750,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -742,6 +779,8 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -767,6 +806,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -794,6 +834,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -820,6 +861,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -842,6 +884,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -862,6 +905,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -891,6 +935,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -916,6 +961,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -939,6 +985,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -976,6 +1023,7 @@ public:
ByteAccessInfo getByteAccessInfo() const override;
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -997,6 +1045,8 @@ class VaStart final : public Instr {
public:
VaStart(Value &ptr) : Instr(Type::voidTy, "va_start"), ptr(&ptr) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -1011,6 +1061,8 @@ class VaEnd final : public Instr {
public:
VaEnd(Value &ptr) : Instr(Type::voidTy, "va_end"), ptr(&ptr) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -1026,6 +1078,8 @@ public:
VaCopy(Value &dst, Value &src)
: Instr(Type::voidTy, "va_copy"), dst(&dst), src(&src) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -1041,6 +1095,8 @@ public:
VaArg(Type &type, std::string &&name, Value &ptr)
: Instr(type, std::move(name)), ptr(&ptr) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -1056,6 +1112,8 @@ public:
ExtractElement(Type &type, std::string &&name, Value &v, Value &idx)
: Instr(type, std::move(name)), v(&v), idx(&idx) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -1071,6 +1129,8 @@ public:
InsertElement(Type &type, std::string &&name, Value &v, Value &e, Value &idx)
: Instr(type, std::move(name)), v(&v), e(&e), idx(&idx) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -1088,6 +1148,8 @@ public:
std::vector<unsigned> mask)
: Instr(type, std::move(name)), v1(&v1), v2(&v2), mask(std::move(mask)) {}
std::vector<Value*> operands() const override;
+ bool propagatesPoison() const override;
+ bool hasSideEffects() const override;
void rauw(const Value &what, Value &with) override;
void print(std::ostream &os) const override;
StateValue toSMT(State &s) const override;
@@ -1098,6 +1160,5 @@ public:
const ConversionOp *isCast(ConversionOp::Op op, const Value &v);
-bool hasNoSideEffects(const Instr &i);
Value *isNoOp(const Value &v);
}

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -1502,7 +1502,7 @@ void Transform::preprocess() {
for (auto bb : fn->getBBs()) {
for (auto &i : bb->instrs()) {
auto i_ptr = const_cast<Instr*>(&i);
- if (hasNoSideEffects(i) && !users.count(i_ptr))
+ if (!i.hasSideEffects() && !users.count(i_ptr))
to_remove.emplace_back(i_ptr);
}

refactor Instr poison/side effect info