1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 03:23:01 +02:00

refactor the SROA code out into its own method, no functionality change.

llvm-svn: 36426
This commit is contained in:
Chris Lattner 2007-04-25 05:02:56 +00:00
parent ca7480e8cb
commit cf27f9705f

View File

@ -65,6 +65,8 @@ namespace {
bool isSafeMemIntrinsicOnAllocation(MemIntrinsic *MI, AllocationInst *AI);
bool isSafeUseOfBitCastedAllocation(BitCastInst *User, AllocationInst *AI);
int isSafeAllocaToScalarRepl(AllocationInst *AI);
void DoScalarReplacement(AllocationInst *AI,
std::vector<AllocationInst*> &WorkList);
void CanonicalizeAllocaUsers(AllocationInst *AI);
AllocaInst *AddNewAlloca(Function &F, const Type *Ty, AllocationInst *Base);
@ -166,26 +168,36 @@ bool SROA::performScalarRepl(Function &F) {
// We cannot transform the allocation instruction if it is an array
// allocation (allocations OF arrays are ok though), and an allocation of a
// scalar value cannot be decomposed at all.
//
if (AI->isArrayAllocation() ||
(!isa<StructType>(AI->getAllocatedType()) &&
!isa<ArrayType>(AI->getAllocatedType()))) continue;
if (!AI->isArrayAllocation() &&
(isa<StructType>(AI->getAllocatedType()) ||
isa<ArrayType>(AI->getAllocatedType()))) {
// Check that all of the users of the allocation are capable of being
// transformed.
switch (isSafeAllocaToScalarRepl(AI)) {
default: assert(0 && "Unexpected value!");
case 0: // Not safe to scalar replace.
continue;
break;
case 1: // Safe, but requires cleanup/canonicalizations first
CanonicalizeAllocaUsers(AI);
// FALL THROUGH.
case 3: // Safe to scalar replace.
break;
DoScalarReplacement(AI, WorkList);
Changed = true;
continue;
}
}
DOUT << "Found inst to xform: " << *AI;
Changed = true;
// Otherwise, couldn't process this.
}
return Changed;
}
/// DoScalarReplacement - This alloca satisfied the isSafeAllocaToScalarRepl
/// predicate, do SROA now.
void SROA::DoScalarReplacement(AllocationInst *AI,
std::vector<AllocationInst*> &WorkList) {
DOUT << "Found inst to xform: " << *AI;
SmallVector<AllocaInst*, 32> ElementAllocas;
if (const StructType *ST = dyn_cast<StructType>(AI->getAllocatedType())) {
ElementAllocas.reserve(ST->getNumContainedTypes());
@ -275,9 +287,6 @@ bool SROA::performScalarRepl(Function &F) {
NumReplaced++;
}
return Changed;
}
/// isSafeElementUse - Check to see if this use is an allowed use for a
/// getelementptr instruction of an array aggregate allocation. isFirstElt