;
// Get indexth childNode.
- const ASTNode operator[](size_t index) const
+ const ASTNode& operator[](size_t index) const
{
return GetChildren()[index];
}
ASTNode STPMgr::CreateZeroConst(unsigned width)
{
- CBV z = CONSTANTBV::BitVector_Create(width, true);
- return CreateBVConst(z, width);
+ assert(width > 0);
+ if (zeroes.size() == 0)
+ {
+ zeroes.push_back(ASTNode()); // null
+ for (int i =1; i < 65;i++)
+ zeroes.push_back(CreateZeroConst(i));
+ }
+
+ if (width < zeroes.size())
+ return zeroes[width];
+ else
+ {
+ CBV z = CONSTANTBV::BitVector_Create(width, true);
+ return CreateBVConst(z, width);
+ }
}
+
ASTNode STPMgr::CreateOneConst(unsigned width)
{
- CBV o = CONSTANTBV::BitVector_Create(width, true);
- CONSTANTBV::BitVector_increment(o);
+ assert(width > 0);
+ if (ones.size() == 0)
+ {
+ ones.push_back(ASTNode()); // null
+ for (int i =1; i < 65;i++)
+ ones.push_back(CreateOneConst(i));
+ }
+
+ if (width < ones.size())
+ return ones[width];
+ else
+ {
+ CBV o = CONSTANTBV::BitVector_Create(width, true);
+ CONSTANTBV::BitVector_increment(o);
- return CreateBVConst(o, width);
+ return CreateBVConst(o, width);
+ }
}
ASTNode STPMgr::CreateTwoConst(unsigned width)
ASTNode STPMgr::CreateMaxConst(unsigned width)
{
- CBV max = CONSTANTBV::BitVector_Create(width, false);
- CONSTANTBV::BitVector_Fill(max);
+ assert(width > 0);
+ if (max.size() == 0)
+ {
+ max.push_back(ASTNode()); // null
+ for (int i =1; i < 65;i++)
+ max.push_back(CreateMaxConst(i));
+ }
+
+ if (width < max.size())
+ return max[width];
+ else
+ {
+ CBV max = CONSTANTBV::BitVector_Create(width, false);
+ CONSTANTBV::BitVector_Fill(max);
- return CreateBVConst(max, width);
+ return CreateBVConst(max, width);
+ }
}
//To ensure unique BVConst nodes, lookup the node in unique-table
// Called by ASTNode constructors to uniqueify ASTBVConst
ASTBVConst *LookupOrCreateBVConst(ASTBVConst& s);
+ // Cache of zero/one/max BVConsts of different widths.
+ ASTVec zeroes;
+ ASTVec ones;
+ ASTVec max;
+
public:
/****************************************************************
if (simplify_upfront)
{
- if (k != BVCONST && k != SYMBOL) // const and symbols need to be created specially.
+ assert(k != BVCONST);
+ if (k != SYMBOL) // const and symbols need to be created specially.
{
ASTVec v;
+ v.reserve(actualInputterm.Degree());
for (unsigned i = 0; i < actualInputterm.Degree(); i++)
if (inputterm[i].GetType() == BITVECTOR_TYPE)
v.push_back(SimplifyTerm(inputterm[i], VarConstMap));
else
v.push_back(inputterm[i]);
- // TODO: Should check if the children arrays are different and only
- // create then.
- output = nf->CreateTerm(k, inputValueWidth, v);
- output.SetIndexWidth(actualInputterm.GetIndexWidth());
+ assert(v.size() > 0);
+ if (v != actualInputterm.GetChildren()) // short-cut.
+ {
+ output = nf->CreateTerm(k, inputValueWidth, v);
+ output.SetIndexWidth(actualInputterm.GetIndexWidth());
+ }
+ else
+ output = actualInputterm;
if (inputterm != output) {
UpdateSimplifyMap(inputterm, output, false, VarConstMap);
//indices for BVEXTRACT
ASTNode i = inputterm[1];
ASTNode j = inputterm[2];
- ASTNode zero = _bm->CreateBVConst(32, 0);
+ ASTNode zero = _bm->CreateZeroConst(32);
+
//recall that the indices of BVEXTRACT are always 32 bits
//long. therefore doing a GetBVUnsigned is ok.
unsigned int i_val = i.GetUnsignedConst();
// } break; }
case ITE:
{
- ASTNode t0 = a0[0];
+ const ASTNode& t0 = a0[0];
ASTNode t1 =
SimplifyTerm(nf->CreateTerm(BVEXTRACT,
a_len, a0[1], i, j),
{
ASTNode zero = _bm->CreateZeroConst(shift);
ASTNode hi = _bm->CreateBVConst(32, width - shift -1);
- ASTNode low = _bm->CreateBVConst(32, 0);
+ ASTNode low = _bm->CreateZeroConst(32);
ASTNode extract =
nf->CreateTerm(BVEXTRACT, width - shift,
a, hi, low);