Improve counting of local and non-local blocks for alloc fn calls
MODIFY
ir/attrs.h
ir/attrs.h
@@ -105,6 +105,7 @@ public:
void add(AllocKind k) { allockind |= (uint8_t)k; }
bool has(AllocKind k) const { return allockind & (uint8_t)k; }
+ bool isAlloc() const { return allockind != 0; }
std::pair<smt::expr,smt::expr>
computeAllocSize(State &s,

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -577,7 +577,8 @@ static unsigned num_ptrs(const Type &ty) {
static bool returns_local(const Value &v) {
// no alias fns return local block
if (auto call = dynamic_cast<const FnCall*>(&v))
- return call->getAttributes().has(FnAttrs::NoAlias);
+ return call->hasAttribute(FnAttrs::NoAlias) ||
+ call->getAttributes().isAlloc();
return dynamic_cast<const Alloc*>(&v);
}
@@ -897,6 +898,7 @@ static void calculateAndInitConstants(Transform &t) {
if (auto fn = dynamic_cast<const FnCall*>(&i)) {
has_fncall |= true;
+ if (!fn->getAttributes().isAlloc()) {
if (fn->hasAttribute(FnAttrs::InaccessibleMemOnly)) {
if (inaccessiblememonly_fns.emplace(fn->getName()).second)
++num_inaccessiblememonly_fns;
@@ -904,6 +906,7 @@ static void calculateAndInitConstants(Transform &t) {
has_write_fncall |= !fn->hasAttribute(FnAttrs::NoWrite);
}
}
+ }
if (auto *mi = dynamic_cast<const MemInstr *>(&i)) {
auto [alloc, align] = mi->getMaxAllocSize();

Improve counting of local and non-local blocks for alloc fn calls