X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FConstants.cpp;h=c519da36a861ecaee3b26f4c775ebca72fc03c79;hb=893af8c058aad683027c604d6cbe818c59e0eda8;hp=6a91757641a7c42a2e227c6e00bc7479a3e4d1ed;hpb=27accf7692562d247a162a6762391b4c07d2c23d;p=oota-llvm.git diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 6a91757641a..c519da36a86 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -5,6 +5,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Constants.h" +#include "llvm/ConstantHandling.h" #include "llvm/DerivedTypes.h" #include "llvm/iMemory.h" #include "llvm/SymbolTable.h" @@ -173,6 +174,13 @@ ConstantIntegral *ConstantIntegral::getAllOnesValue(const Type *Ty) { } } +bool ConstantUInt::isAllOnesValue() const { + unsigned TypeBits = getType()->getPrimitiveSize()*8; + uint64_t Val = ~0ULL; // All ones + Val >>= 64-TypeBits; // Shift out inappropriate bits + return getValue() == Val; +} + //===----------------------------------------------------------------------===// // ConstantXXX Classes @@ -411,7 +419,7 @@ void ConstantPointerRef::replaceUsesOfWithOnConstant(Value *From, Value *To) { void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *To) { assert(isa(To) && "Cannot make Constant refer to non-constant!"); - ConstantExpr *Replacement = 0; + Constant *Replacement = 0; if (getOpcode() == Instruction::GetElementPtr) { std::vector Indices; Constant *Pointer = cast(getOperand(0)); @@ -628,7 +636,9 @@ void ConstantPointerRef::destroyConstant() { typedef pair > ExprMapKeyType; static ValueMap ExprConstants; -ConstantExpr *ConstantExpr::getCast(Constant *C, const Type *Ty) { +Constant *ConstantExpr::getCast(Constant *C, const Type *Ty) { + if (Constant *FC = ConstantFoldCastInstruction(C, Ty)) + return FC; // Fold a few common cases... // Look up the constant in the table first to ensure uniqueness vector argVec(1, C); @@ -642,7 +652,11 @@ ConstantExpr *ConstantExpr::getCast(Constant *C, const Type *Ty) { return Result; } -ConstantExpr *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { +Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { + + if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2)) + return FC; // Fold a few common cases... + // Look up the constant in the table first to ensure uniqueness vector argVec(1, C1); argVec.push_back(C2); const ExprMapKeyType &Key = make_pair(Opcode, argVec); @@ -663,8 +677,10 @@ ConstantExpr *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) { return Result; } -ConstantExpr *ConstantExpr::getGetElementPtr(Constant *C, - const std::vector &IdxList) { +Constant *ConstantExpr::getGetElementPtr(Constant *C, + const std::vector &IdxList){ + if (Constant *FC = ConstantFoldGetElementPtr(C, IdxList)) + return FC; // Fold a few common cases... const Type *Ty = C->getType(); // Look up the constant in the table first to ensure uniqueness