From cf3218640969175634b82e4e3fde1b9e680a5dc6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 7 Jan 2009 06:39:58 +0000 Subject: [PATCH] use continue to simplify code and reduce nesting, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61851 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Scalar/ScalarReplAggregates.cpp | 96 +++++++++++-------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 925672b7431..ae0eebcbd21 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -998,8 +998,10 @@ const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) { if (MergeInType(LI->getType(), UsedType, *TD)) return 0; - - } else if (StoreInst *SI = dyn_cast(User)) { + continue; + } + + if (StoreInst *SI = dyn_cast(User)) { // Storing the pointer, not into the value? if (SI->getOperand(0) == V) return 0; @@ -1012,11 +1014,16 @@ const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) { if (MergeInType(SI->getOperand(0)->getType(), UsedType, *TD)) return 0; - } else if (BitCastInst *CI = dyn_cast(User)) { + continue; + } + if (BitCastInst *CI = dyn_cast(User)) { IsNotTrivial = true; const Type *SubTy = CanConvertToScalar(CI, IsNotTrivial); if (!SubTy || MergeInType(SubTy, UsedType, *TD)) return 0; - } else if (GetElementPtrInst *GEP = dyn_cast(User)) { + continue; + } + + if (GetElementPtrInst *GEP = dyn_cast(User)) { // Check to see if this is stepping over an element: GEP Ptr, int C if (GEP->getNumOperands() == 2 && isa(GEP->getOperand(1))) { unsigned Idx = cast(GEP->getOperand(1))->getZExtValue(); @@ -1033,10 +1040,14 @@ const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) { if (NewTy == 0 || MergeInType(NewTy, UsedType, *TD)) return 0; continue; } - } else if (GEP->getNumOperands() == 3 && - isa(GEP->getOperand(1)) && - isa(GEP->getOperand(2)) && - cast(GEP->getOperand(1))->isZero()) { + // Cannot handle this! + return 0; + } + + if (GEP->getNumOperands() == 3 && + isa(GEP->getOperand(1)) && + isa(GEP->getOperand(2)) && + cast(GEP->getOperand(1))->isZero()) { // We are stepping into an element, e.g. a structure or an array: // GEP Ptr, i32 0, i32 Cst const Type *AggTy = PTy->getElementType(); @@ -1075,10 +1086,10 @@ const Type *SROA::CanConvertToScalar(Value *V, bool &IsNotTrivial) { continue; // Everything looks ok } return 0; - } else { - // Cannot handle this! - return 0; } + + // Cannot handle this! + return 0; } return UsedType; @@ -1120,17 +1131,25 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) { Value *NV = ConvertUsesOfLoadToScalar(LI, NewAI, Offset); LI->replaceAllUsesWith(NV); LI->eraseFromParent(); - } else if (StoreInst *SI = dyn_cast(User)) { + continue; + } + + if (StoreInst *SI = dyn_cast(User)) { assert(SI->getOperand(0) != Ptr && "Consistency error!"); Value *SV = ConvertUsesOfStoreToScalar(SI, NewAI, Offset); new StoreInst(SV, NewAI, SI); SI->eraseFromParent(); - - } else if (BitCastInst *CI = dyn_cast(User)) { + continue; + } + + if (BitCastInst *CI = dyn_cast(User)) { ConvertUsesToScalar(CI, NewAI, Offset); CI->eraseFromParent(); - } else if (GetElementPtrInst *GEP = dyn_cast(User)) { + continue; + } + + if (GetElementPtrInst *GEP = dyn_cast(User)) { const PointerType *AggPtrTy = cast(GEP->getOperand(0)->getType()); unsigned AggSizeInBits = @@ -1143,34 +1162,35 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) { unsigned BitOffset = Idx*AggSizeInBits; NewOffset += BitOffset; - } else if (GEP->getNumOperands() == 3) { - // We know that operand #2 is zero. - unsigned Idx = cast(GEP->getOperand(2))->getZExtValue(); - const Type *AggTy = AggPtrTy->getElementType(); - if (const SequentialType *SeqTy = dyn_cast(AggTy)) { - unsigned ElSizeBits = - TD->getABITypeSizeInBits(SeqTy->getElementType()); - - NewOffset += ElSizeBits*Idx; - } else if (const StructType *STy = dyn_cast(AggTy)) { - unsigned EltBitOffset = - TD->getStructLayout(STy)->getElementOffsetInBits(Idx); - - NewOffset += EltBitOffset; - } else { - assert(0 && "Unsupported operation!"); - abort(); - } + ConvertUsesToScalar(GEP, NewAI, NewOffset); + GEP->eraseFromParent(); + continue; + } + + assert(GEP->getNumOperands() == 3 && "Unsupported operation"); + + // We know that operand #2 is zero. + unsigned Idx = cast(GEP->getOperand(2))->getZExtValue(); + const Type *AggTy = AggPtrTy->getElementType(); + if (const SequentialType *SeqTy = dyn_cast(AggTy)) { + unsigned ElSizeBits = + TD->getABITypeSizeInBits(SeqTy->getElementType()); + + NewOffset += ElSizeBits*Idx; } else { - assert(0 && "Unsupported operation!"); - abort(); + const StructType *STy = cast(AggTy); + unsigned EltBitOffset = + TD->getStructLayout(STy)->getElementOffsetInBits(Idx); + + NewOffset += EltBitOffset; } ConvertUsesToScalar(GEP, NewAI, NewOffset); GEP->eraseFromParent(); - } else { - assert(0 && "Unsupported operation!"); - abort(); + continue; } + + assert(0 && "Unsupported operation!"); + abort(); } } -- 2.34.1