From f8a87e8343c5f829be9a75d8160e1bb969b84119 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 29 Aug 2009 23:35:16 +0000 Subject: [PATCH] Cleanup whitespace and indentation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80451 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 57 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index eda336a5801..701a195f7fd 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -49,7 +49,7 @@ static Constant *BitCastConstantVector(LLVMContext &Context, ConstantVector *CV, unsigned NumElts = DstTy->getNumElements(); if (NumElts != CV->getNumOperands()) return 0; - + // Check to verify that all elements of the input are simple. for (unsigned i = 0; i != NumElts; ++i) { if (!isa(CV->getOperand(i)) && @@ -79,7 +79,7 @@ foldConstantCastPair( assert(Op && Op->isCast() && "Can't fold cast of cast without a cast!"); assert(DstTy && DstTy->isFirstClassType() && "Invalid cast destination type"); assert(CastInst::isCast(opc) && "Invalid cast opcode"); - + // The the types and opcodes for the two Cast constant expressions const Type *SrcTy = Op->getOperand(0)->getType(); const Type *MidTy = Op->getType(); @@ -96,7 +96,7 @@ static Constant *FoldBitCast(LLVMContext &Context, const Type *SrcTy = V->getType(); if (SrcTy == DestTy) return V; // no-op cast - + // Check to see if we are casting a pointer to an aggregate to a pointer to // the first element. If so, return the appropriate GEP instruction. if (const PointerType *PTy = dyn_cast(V->getType())) @@ -120,13 +120,13 @@ static Constant *FoldBitCast(LLVMContext &Context, break; } } - + if (ElTy == DPTy->getElementType()) // This GEP is inbounds because all indices are zero. return ConstantExpr::getInBoundsGetElementPtr(V, &IdxList[0], IdxList.size()); } - + // Handle casts from one vector constant to another. We know that the src // and dest type have the same size (otherwise its an illegal cast). if (const VectorType *DestPTy = dyn_cast(DestTy)) { @@ -137,7 +137,7 @@ static Constant *FoldBitCast(LLVMContext &Context, // First, check for null. Undef is already handled. if (isa(V)) return Constant::getNullValue(DestTy); - + if (ConstantVector *CV = dyn_cast(V)) return BitCastConstantVector(Context, CV, DestPTy); } @@ -149,12 +149,12 @@ static Constant *FoldBitCast(LLVMContext &Context, return ConstantExpr::getBitCast( ConstantVector::get(&V, 1), DestPTy); } - + // Finally, implement bitcast folding now. The code below doesn't handle // bitcast right. if (isa(V)) // ptr->ptr cast. return ConstantPointerNull::get(cast(DestTy)); - + // Handle integral constant input. if (const ConstantInt *CI = dyn_cast(V)) { if (DestTy->isInteger()) @@ -341,7 +341,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(LLVMContext &Context, if (Val->isNullValue()) // ee(zero, x) -> zero return Constant::getNullValue( cast(Val->getType())->getElementType()); - + if (const ConstantVector *CVal = dyn_cast(Val)) { if (const ConstantInt *CIdx = dyn_cast(Idx)) { return CVal->getOperand(CIdx->getZExtValue()); @@ -417,7 +417,7 @@ static Constant *GetVectorElement(LLVMContext &Context, const Constant *C, unsigned EltNo) { if (const ConstantVector *CV = dyn_cast(C)) return CV->getOperand(EltNo); - + const Type *EltTy = cast(C->getType())->getElementType(); if (isa(C)) return Constant::getNullValue(EltTy); @@ -661,7 +661,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, if (CI2->isZero()) return const_cast(C2); // X & 0 == 0 if (CI2->isAllOnesValue()) return const_cast(C1); // X & -1 == X - + if (const ConstantExpr *CE1 = dyn_cast(C1)) { // (zext i32 to i64) & 4294967295 -> (zext i32 to i64) if (CE1->getOpcode() == Instruction::ZExt) { @@ -672,17 +672,17 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, if ((PossiblySetBits & CI2->getValue()) == PossiblySetBits) return const_cast(C1); } - + // If and'ing the address of a global with a constant, fold it. if (CE1->getOpcode() == Instruction::PtrToInt && isa(CE1->getOperand(0))) { GlobalValue *GV = cast(CE1->getOperand(0)); - + // Functions are at least 4-byte aligned. unsigned GVAlign = GV->getAlignment(); if (isa(GV)) GVAlign = std::max(GVAlign, 4U); - + if (GVAlign > 1) { unsigned DstWidth = CI2->getType()->getBitWidth(); unsigned SrcWidth = std::min(DstWidth, Log2_32(GVAlign)); @@ -712,7 +712,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, break; } } - + // At this point we know neither constant is an UndefValue. if (const ConstantInt *CI1 = dyn_cast(C1)) { if (const ConstantInt *CI2 = dyn_cast(C2)) { @@ -989,7 +989,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, case Instruction::Xor: // No change of opcode required. return ConstantFoldBinaryInstruction(Context, Opcode, C2, C1); - + case Instruction::Shl: case Instruction::LShr: case Instruction::AShr: @@ -1005,7 +1005,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context, break; } } - + // We don't know how to fold this. return 0; } @@ -1113,7 +1113,7 @@ static FCmpInst::Predicate evaluateFCmpRelation(LLVMContext &Context, // Nothing more we can do return FCmpInst::BAD_FCMP_PREDICATE; } - + // If the first operand is simple and second is ConstantExpr, swap operands. FCmpInst::Predicate SwappedRelation = evaluateFCmpRelation(Context, V2, V1); if (SwappedRelation != FCmpInst::BAD_FCMP_PREDICATE) @@ -1177,11 +1177,11 @@ static ICmpInst::Predicate evaluateICmpRelation(LLVMContext &Context, R = dyn_cast(ConstantExpr::getICmp(pred, C1, C2)); if (R && !R->isZero()) return pred; - + // If we couldn't figure it out, bail. return ICmpInst::BAD_ICMP_PREDICATE; } - + // If the first operand is simple, swap operands. ICmpInst::Predicate SwappedRelation = evaluateICmpRelation(Context, V2, V1, isSigned); @@ -1489,7 +1489,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, SmallVector C1Elts, C2Elts; C1->getVectorElements(Context, C1Elts); C2->getVectorElements(Context, C2Elts); - + // If we can constant fold the comparison of each element, constant fold // the whole vector comparison. SmallVector ResElts; @@ -1554,7 +1554,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, Result = 1; break; } - + // If we evaluated the result, return it now. if (Result != -1) return ConstantInt::get(Type::getInt1Ty(Context), Result); @@ -1631,11 +1631,11 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, if (pred == ICmpInst::ICMP_NE) Result = 1; break; } - + // If we evaluated the result, return it now. if (Result != -1) return ConstantInt::get(Type::getInt1Ty(Context), Result); - + if (!isa(C1) && isa(C2)) { // If C2 is a constant expr and C1 isn't, flip them around and fold the // other way if possible. @@ -1663,7 +1663,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context, } } return 0; - } +} Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context, const Constant *C, @@ -1759,7 +1759,7 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context, return ConstantExpr::getGetElementPtr( (Constant*)CE->getOperand(0), Idxs, NumIdx); } - + // Fold: getelementptr (i8* inttoptr (i64 1 to i8*), i32 -1) // Into: inttoptr (i64 0 to i8*) // This happens with pointers to member functions in C++. @@ -1768,7 +1768,7 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context, cast(CE->getType())->getElementType() == Type::getInt8Ty(Context)) { Constant *Base = CE->getOperand(0); Constant *Offset = Idxs[0]; - + // Convert the smaller integer to the larger type. if (Offset->getType()->getPrimitiveSizeInBits() < Base->getType()->getPrimitiveSizeInBits()) @@ -1776,11 +1776,10 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context, else if (Base->getType()->getPrimitiveSizeInBits() < Offset->getType()->getPrimitiveSizeInBits()) Base = ConstantExpr::getZExt(Base, Offset->getType()); - + Base = ConstantExpr::getAdd(Base, Offset); return ConstantExpr::getIntToPtr(Base, CE->getType()); } } return 0; } - -- 2.34.1