mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 21:29:41 +00:00
* Actually USE the statistic that we made
* Implement SRoA for arrays git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6349 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a161f0c7c9
commit
d10376bee5
@ -52,11 +52,14 @@ bool SROA::runOnFunction(Function &F) {
|
|||||||
WorkList.pop_back();
|
WorkList.pop_back();
|
||||||
|
|
||||||
// We cannot transform the allocation instruction if it is an array
|
// We cannot transform the allocation instruction if it is an array
|
||||||
// allocation, and an allocation of a scalar value cannot be decomposed
|
// allocation (allocations OF arrays are ok though), and an allocation of a
|
||||||
|
// scalar value cannot be decomposed at all.
|
||||||
|
//
|
||||||
if (AI->isArrayAllocation() ||
|
if (AI->isArrayAllocation() ||
|
||||||
(!isa<StructType>(AI->getAllocatedType()) /*&&
|
(!isa<StructType>(AI->getAllocatedType()) &&
|
||||||
!isa<ArrayType>(AI->getAllocatedType())*/
|
!isa<ArrayType>(AI->getAllocatedType()))) continue;
|
||||||
)) continue;
|
|
||||||
|
const ArrayType *AT = dyn_cast<ArrayType>(AI->getAllocatedType());
|
||||||
|
|
||||||
// Loop over the use list of the alloca. We can only transform it if there
|
// Loop over the use list of the alloca. We can only transform it if there
|
||||||
// are only getelementptr instructions (with a zero first index) and free
|
// are only getelementptr instructions (with a zero first index) and free
|
||||||
@ -77,6 +80,18 @@ bool SROA::runOnFunction(Function &F) {
|
|||||||
CannotTransform = true;
|
CannotTransform = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If this is an array access, check to make sure that index falls
|
||||||
|
// within the array. If not, something funny is going on, so we won't
|
||||||
|
// do the optimization.
|
||||||
|
if (AT && cast<ConstantSInt>(GEPI->getOperand(2))->getValue() >=
|
||||||
|
AT->getNumElements()) {
|
||||||
|
DEBUG(std::cerr << "Cannot transform: " << *AI << " due to user: "
|
||||||
|
<< User);
|
||||||
|
CannotTransform = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DEBUG(std::cerr << "Cannot transform: " << *AI << " due to user: "
|
DEBUG(std::cerr << "Cannot transform: " << *AI << " due to user: "
|
||||||
<< User);
|
<< User);
|
||||||
@ -100,7 +115,6 @@ bool SROA::runOnFunction(Function &F) {
|
|||||||
WorkList.push_back(NA); // Add to worklist for recursive processing
|
WorkList.push_back(NA); // Add to worklist for recursive processing
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const ArrayType *AT = cast<ArrayType>(AI->getAllocatedType());
|
|
||||||
ElementAllocas.reserve(AT->getNumElements());
|
ElementAllocas.reserve(AT->getNumElements());
|
||||||
const Type *ElTy = AT->getElementType();
|
const Type *ElTy = AT->getElementType();
|
||||||
for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
|
for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
|
||||||
@ -158,6 +172,7 @@ bool SROA::runOnFunction(Function &F) {
|
|||||||
|
|
||||||
// Finally, delete the Alloca instruction
|
// Finally, delete the Alloca instruction
|
||||||
AI->getParent()->getInstList().erase(AI);
|
AI->getParent()->getInstList().erase(AI);
|
||||||
|
NumReplaced++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Changed;
|
return Changed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user