forked from github/verilator
Make DfgConst hold V3Number directly
Remove intermediary AstConst. No functional change intended.
This commit is contained in:
parent
439d30a953
commit
90447d54d1
@ -592,7 +592,7 @@ static void dumpDotVertex(std::ostream& os, const DfgVertex& vtx) {
|
||||
}
|
||||
|
||||
if (const DfgConst* const constVtxp = vtx.cast<DfgConst>()) {
|
||||
const V3Number& num = constVtxp->constp()->num();
|
||||
const V3Number& num = constVtxp->num();
|
||||
|
||||
os << toDotId(vtx);
|
||||
os << " [label=\"";
|
||||
@ -915,10 +915,10 @@ void DfgVertex::replaceWith(DfgVertex* newSorucep) {
|
||||
// DfgConst ----------
|
||||
|
||||
bool DfgConst::selfEquals(const DfgVertex& that) const {
|
||||
return constp()->sameTree(that.as<DfgConst>()->constp());
|
||||
return num().isCaseEq(that.as<DfgConst>()->num());
|
||||
}
|
||||
|
||||
V3Hash DfgConst::selfHash() const { return m_constp->num().toHash(); }
|
||||
V3Hash DfgConst::selfHash() const { return num().toHash(); }
|
||||
|
||||
// DfgSel ----------
|
||||
|
||||
@ -930,7 +930,7 @@ V3Hash DfgSel::selfHash() const { return V3Hash{lsb()}; }
|
||||
|
||||
bool DfgVertexVar::selfEquals(const DfgVertex& that) const {
|
||||
UASSERT_OBJ(varp() != that.as<DfgVertexVar>()->varp(), this,
|
||||
"There should only be one DfgVarPacked for a given AstVar");
|
||||
"There should only be one DfgVertexVar for a given AstVar");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -458,7 +458,7 @@ class AstToDfgVisitor final : public VNVisitor {
|
||||
void visit(AstConst* nodep) override {
|
||||
UASSERT_OBJ(!nodep->user1p(), nodep, "Already has Dfg vertex");
|
||||
if (unhandled(nodep)) return;
|
||||
DfgVertex* const vtxp = new DfgConst{*m_dfgp, nodep->cloneTree(false)};
|
||||
DfgVertex* const vtxp = new DfgConst{*m_dfgp, nodep->fileline(), nodep->num()};
|
||||
m_uncommittedVertices.push_back(vtxp);
|
||||
nodep->user1p(vtxp);
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ class DfgToAstVisitor final : DfgVisitor {
|
||||
}
|
||||
|
||||
void visit(DfgConst* vtxp) override { //
|
||||
m_resultp = vtxp->constp()->cloneTree(false);
|
||||
m_resultp = new AstConst{vtxp->fileline(), vtxp->num()};
|
||||
}
|
||||
|
||||
void visit(DfgSel* vtxp) override {
|
||||
|
@ -154,17 +154,11 @@ class V3DfgPeephole final : public DfgVisitor {
|
||||
// Shorthand
|
||||
static AstNodeDType* dtypeForWidth(uint32_t width) { return DfgVertex::dtypeForWidth(width); }
|
||||
|
||||
// Create a new DfgConst vertex with the given width and value
|
||||
DfgConst* makeConst(FileLine* flp, uint32_t width, uint32_t value) {
|
||||
const int widthInt = static_cast<int>(width);
|
||||
return new DfgConst{m_dfg, new AstConst{flp, AstConst::WidthedValue{}, widthInt, value}};
|
||||
}
|
||||
// Create a 32-bit DfgConst vertex
|
||||
DfgConst* makeI32(FileLine* flp, uint32_t val) { return new DfgConst{m_dfg, flp, 32, val}; }
|
||||
|
||||
// Create a new 32-bit DfgConst vertex
|
||||
DfgConst* makeI32(FileLine* flp, uint32_t value) { return makeConst(flp, 32, value); }
|
||||
|
||||
// Create a new DfgConst vertex with the given width and value zero
|
||||
DfgConst* makeZero(FileLine* flp, uint32_t width) { return makeConst(flp, width, 0); }
|
||||
// Create a DfgConst vertex with the given width and value zero
|
||||
DfgConst* makeZero(FileLine* flp, uint32_t width) { return new DfgConst{m_dfg, flp, width}; }
|
||||
|
||||
// Constant fold unary vertex, return true if folded
|
||||
template <typename Vertex>
|
||||
|
@ -79,21 +79,22 @@ class DfgConst final : public DfgVertex {
|
||||
friend class DfgVertex;
|
||||
friend class DfgVisitor;
|
||||
|
||||
AstConst* const m_constp; // The AstConst associated with this vertex (owned by this vertex)
|
||||
V3Number m_num; // Constant value
|
||||
|
||||
bool selfEquals(const DfgVertex& that) const override;
|
||||
V3Hash selfHash() const override;
|
||||
|
||||
public:
|
||||
DfgConst(DfgGraph& dfg, AstConst* constp)
|
||||
: DfgVertex{dfg, dfgType(), constp->fileline(), dtypeFor(constp)}
|
||||
, m_constp{constp} {}
|
||||
DfgConst(DfgGraph& dfg, FileLine* flp, const V3Number& num)
|
||||
: DfgVertex{dfg, dfgType(), flp, dtypeForWidth(num.width())}
|
||||
, m_num{num} {}
|
||||
DfgConst(DfgGraph& dfg, FileLine* flp, uint32_t width, uint32_t value = 0)
|
||||
: DfgVertex{dfg, dfgType(), flp, dtypeForWidth(width)}
|
||||
, m_num{flp, static_cast<int>(width), value} {}
|
||||
ASTGEN_MEMBERS_DfgConst;
|
||||
|
||||
~DfgConst() override { VL_DO_DANGLING(m_constp->deleteTree(), m_constp); }
|
||||
|
||||
AstConst* constp() const { return m_constp; }
|
||||
V3Number& num() const { return m_constp->num(); }
|
||||
V3Number& num() { return m_num; }
|
||||
const V3Number& num() const { return m_num; }
|
||||
|
||||
uint32_t toU32() const { return num().toUInt(); }
|
||||
int32_t toI32() const { return num().toSInt(); }
|
||||
|
@ -472,6 +472,12 @@ public:
|
||||
m_data.num()[0].m_value = value;
|
||||
opCleanThis();
|
||||
}
|
||||
V3Number(FileLine* flp, int width, uint32_t value) {
|
||||
init(nullptr, width, true);
|
||||
m_fileline = flp;
|
||||
m_data.num()[0].m_value = value;
|
||||
opCleanThis();
|
||||
}
|
||||
// Create from a verilog 32'hxxxx number.
|
||||
V3Number(AstNode* nodep, const char* sourcep) { create(nodep, sourcep); }
|
||||
V3Number(FileLine* flp, const char* sourcep) { create(flp, sourcep); }
|
||||
|
Loading…
Reference in New Issue
Block a user