Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ir: thread vscale range from State to Type #1139

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ir/attrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ ostream& operator<<(ostream &os, const FnAttrs &attr) {
os << ", " << attr.allocsize_1;
os << ')';
}
if (attr.vscaleRange) {
auto [low, high] = *attr.vscaleRange;
os << " vscale_range(" << low << ", " << high << ')';
}

attr.fp_denormal.print(os);
if (attr.fp_denormal32)
Expand Down
2 changes: 2 additions & 0 deletions ir/attrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class FnAttrs final {
AllocSize = 1 << 12, ZeroExt = 1<<13,
SignExt = 1<<14, NoFPClass = 1<<15, Asm = 1<<16 };

std::optional<std::pair<uint16_t, uint16_t>> vscaleRange;

FnAttrs(unsigned bits = None) : bits(bits) {}

bool has(Attribute a) const { return (bits & a) != 0; }
Expand Down
24 changes: 12 additions & 12 deletions ir/constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ StateValue IntConst::toSMT(State &s) const {
return { expr::mkInt(get<string>(val).c_str(), bits()), true };
}

expr IntConst::getTypeConstraints() const {
expr IntConst::getTypeConstraints(const Function &f) const {
unsigned min_bits = 0;
if (auto v = get_if<int64_t>(&val))
min_bits = (*v >= 0 ? 63 : 64) - num_sign_bits(*v);

return Value::getTypeConstraints() &&
return Value::getTypeConstraints(f) &&
getType().enforceIntType() &&
getType().sizeVar().uge(min_bits);
}
Expand Down Expand Up @@ -86,8 +86,8 @@ FloatConst::FloatConst(Type &type, string val, bool bit_value)
: Constant(type, bit_value ? int_to_readable_float(type, val) : val),
val(std::move(val)), bit_value(bit_value) {}

expr FloatConst::getTypeConstraints() const {
return Value::getTypeConstraints() &&
expr FloatConst::getTypeConstraints(const Function &f) const {
return Value::getTypeConstraints(f) &&
getType().enforceFloatType();
}

Expand All @@ -104,12 +104,12 @@ StateValue FloatConst::toSMT(State &s) const {


StateValue ConstantInput::toSMT(State &s) const {
auto type = getType().getDummyValue(false).value;
auto type = getType().getDummyValue(false, s.getVscale()).value;
return { expr::mkVar(getName().c_str(), type), true };
}

expr ConstantInput::getTypeConstraints() const {
return Value::getTypeConstraints() &&
expr ConstantInput::getTypeConstraints(const Function &f) const {
return Value::getTypeConstraints(f) &&
(getType().enforceIntType() || getType().enforceFloatType());
}

Expand Down Expand Up @@ -157,8 +157,8 @@ StateValue ConstantBinOp::toSMT(State &s) const {
return { std::move(val), ap && bp };
}

expr ConstantBinOp::getTypeConstraints() const {
return Value::getTypeConstraints() &&
expr ConstantBinOp::getTypeConstraints(const Function &f) const {
return Value::getTypeConstraints(f) &&
getType().enforceIntType() &&
getType() == lhs.getType() &&
getType() == rhs.getType();
Expand Down Expand Up @@ -210,10 +210,10 @@ StateValue ConstantFn::toSMT(State &s) const {
return { std::move(r), true };
}

expr ConstantFn::getTypeConstraints() const {
expr r = Value::getTypeConstraints();
expr ConstantFn::getTypeConstraints(const Function &f) const {
expr r = Value::getTypeConstraints(f);
for (auto a : args) {
r &= a->getTypeConstraints();
r &= a->getTypeConstraints(f);
}

Type &ty = getType();
Expand Down
10 changes: 5 additions & 5 deletions ir/constant.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IntConst final : public Constant {
IntConst(Type &type, int64_t val);
IntConst(Type &type, std::string &&val);
StateValue toSMT(State &s) const override;
smt::expr getTypeConstraints() const override;
smt::expr getTypeConstraints(const Function &f) const override;
auto getInt() const { return std::get_if<int64_t>(&val); }
};

Expand All @@ -38,7 +38,7 @@ class FloatConst final : public Constant {
FloatConst(Type &type, std::string val, bool bit_value);

StateValue toSMT(State &s) const override;
smt::expr getTypeConstraints() const override;
smt::expr getTypeConstraints(const Function &f) const override;
};


Expand All @@ -47,7 +47,7 @@ class ConstantInput final : public Constant {
ConstantInput(Type &type, std::string &&name)
: Constant(type, std::move(name)) {}
StateValue toSMT(State &s) const override;
smt::expr getTypeConstraints() const override;
smt::expr getTypeConstraints(const Function &f) const override;
};


Expand All @@ -62,7 +62,7 @@ class ConstantBinOp final : public Constant {
public:
ConstantBinOp(Type &type, Constant &lhs, Constant &rhs, Op op);
StateValue toSMT(State &s) const override;
smt::expr getTypeConstraints() const override;
smt::expr getTypeConstraints(const Function &f) const override;
};


Expand All @@ -73,7 +73,7 @@ class ConstantFn final : public Constant {
public:
ConstantFn(Type &type, std::string_view name, std::vector<Value*> &&args);
StateValue toSMT(State &s) const override;
smt::expr getTypeConstraints() const override;
smt::expr getTypeConstraints(const Function &f) const override;
};

struct ConstantFnException {
Expand Down
12 changes: 6 additions & 6 deletions ir/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ expr Function::getTypeConstraints() const {
}
for (auto &l : { getConstants(), getInputs(), getUndefs() }) {
for (auto &v : l) {
t &= v.getTypeConstraints();
t &= v.getTypeConstraints(*this);
}
}
return t;
Expand Down Expand Up @@ -448,7 +448,7 @@ static vector<BasicBlock*> top_sort(const vector<BasicBlock*> &bbs) {
// in order to account for some transitive dependencies we may have
// missed due to compression of its inner loops.
// If there are no inner loops, this is redundant and if `bb` is not
// a loop header, the set of its exit blocks is empty.
// a loop header, the set of its exit blocks is empty.
for (auto &dst : bb->getExitBlocks()) {
auto dst_I = bb_map.find(dst);
if (dst_I != bb_map.end())
Expand Down Expand Up @@ -807,8 +807,8 @@ void Function::unroll(unsigned k) {
static PtrType ptr_type(0);
static IntType i32(string("i32"), 32);
auto &type = val->getType();
auto size_alloc
= make_unique<IntConst>(i32, Memory::getStoreByteSize(type));
auto size_alloc = make_unique<IntConst>(
i32, Memory::getStoreByteSize(type, expr::mkVscaleMin()));
auto *size = size_alloc.get();
addConstant(std::move(size_alloc));

Expand Down Expand Up @@ -1017,7 +1017,7 @@ void DomTree::buildDominators(const CFG &cfg) {
auto &entry = doms.at(&f.getFirstBB());
entry.dominator = &entry;

// Cooper, Keith D.; Harvey, Timothy J.; and Kennedy, Ken (2001).
// Cooper, Keith D.; Harvey, Timothy J.; and Kennedy, Ken (2001).
// A Simple, Fast Dominance Algorithm
// http://www.cs.rice.edu/~keith/EMBED/dom.pdf
// Makes multiple passes when CFG is cyclic to update incorrect initial
Expand Down Expand Up @@ -1220,5 +1220,5 @@ void LoopAnalysis::printDot(ostream &os) const {
os << "}\n";
}

}
}

Loading
Loading