merge 2 loops in transforms.cpp
MODIFY
ir/instr.cpp
ir/instr.cpp
@@ -2158,8 +2158,7 @@ Calloc::ByteAccessInfo Calloc::getByteAccessInfo() const {
auto info = ByteAccessInfo::intOnly(1);
if (auto n = getInt(*num))
if (auto sz = getInt(*size)) {
- // assume calloc is 8 bytes aligned
- info.byteSize = gcd(8, *n * *sz);
+ info.byteSize = gcd(heap_block_alignment, *n * *sz);
}
return info;
}

MODIFY
tools/transform.cpp
tools/transform.cpp
@@ -523,6 +523,12 @@ static void calculateAndInitConstants(Transform &t) {
else
num_max_nonlocals_inst += returns_nonlocal(i);
+ for (auto op : i.operands()) {
+ nullptr_is_used |= has_nullptr(op);
+ }
+
+ has_fncall |= dynamic_cast<const FnCall*>(&i) != nullptr;
+
if (auto *mi = dynamic_cast<const MemInstr *>(&i)) {
max_alloc_size = max(max_alloc_size, mi->getMaxAllocSize());
max_access_size = max(max_access_size, mi->getMaxAccessSize());
@@ -537,9 +543,22 @@ static void calculateAndInitConstants(Transform &t) {
does_mem_access |= info.doesMemAccess();
min_access_size = gcd(min_access_size, info.byteSize);
+ if (auto alloc = dynamic_cast<const Alloc*>(&i)) {
+ has_dead_allocas |= alloc->initDead();
+ }
+ else if (auto alloc = dynamic_cast<const Malloc*>(&i)) {
+ has_malloc |= true;
+ has_free |= alloc->isRealloc();
+ } else {
+ has_malloc |= dynamic_cast<const Calloc*>(&i) != nullptr;
+ has_free |= dynamic_cast<const Free*>(&i) != nullptr;
+ }
+
} else if (isCast(ConversionOp::Int2Ptr, i) ||
isCast(ConversionOp::Ptr2Int, i)) {
max_alloc_size = max_access_size = cur_max_gep = UINT64_MAX;
+ has_int2ptr |= isCast(ConversionOp::Int2Ptr, i) != nullptr;
+ has_ptr2int |= isCast(ConversionOp::Ptr2Int, i) != nullptr;
} else if (auto *bc = isCast(ConversionOp::BitCast, i)) {
auto &t = bc->getType();
@@ -563,33 +582,6 @@ static void calculateAndInitConstants(Transform &t) {
}
}
- for (auto fn : { &t.src, &t.tgt }) {
- for (auto BB : fn->getBBs()) {
- for (auto &I : BB->instrs()) {
- for (auto op : I.operands()) {
- nullptr_is_used |= has_nullptr(op);
- }
-
- if (auto conv = dynamic_cast<const ConversionOp*>(&I)) {
- has_int2ptr |= conv->getOp() == ConversionOp::Int2Ptr;
- has_ptr2int |= conv->getOp() == ConversionOp::Ptr2Int;
- }
-
- if (auto alloc = dynamic_cast<const Alloc*>(&I))
- has_dead_allocas |= alloc->initDead();
-
- if (auto alloc = dynamic_cast<const Malloc*>(&I)) {
- has_malloc |= true;
- has_free |= alloc->isRealloc();
- }
-
- has_malloc |= dynamic_cast<const Calloc*>(&I) != nullptr;
- has_free |= dynamic_cast<const Free*>(&I) != nullptr;
- has_fncall |= dynamic_cast<const FnCall*>(&I) != nullptr;
- }
- }
- }
-
// check if null block is needed
// Global variables cannot be null pointers
has_null_block = num_ptrinputs > 0 || nullptr_is_used || has_malloc ||

merge 2 loops in transforms.cpp