diff options
| author | Reid Spencer <rspencer@reidspencer.com> | 2007-01-12 07:05:14 +0000 |
|---|---|---|
| committer | Reid Spencer <rspencer@reidspencer.com> | 2007-01-12 07:05:14 +0000 |
| commit | 7a9c62baa66ae262755db0d3221ce095d48681d5 (patch) | |
| tree | 4fee2892414be30e801ea1691ee9035b3c8f4341 /llvm/lib/Transforms/Scalar | |
| parent | 899a89b11b80ac3bda127de372a380162190a0c9 (diff) | |
| download | bcm5719-llvm-7a9c62baa66ae262755db0d3221ce095d48681d5.tar.gz bcm5719-llvm-7a9c62baa66ae262755db0d3221ce095d48681d5.zip | |
For PR1064:
Implement the arbitrary bit-width integer feature. The feature allows
integers of any bitwidth (up to 64) to be defined instead of just 1, 8,
16, 32, and 64 bit integers.
This change does several things:
1. Introduces a new Derived Type, IntegerType, to represent the number of
bits in an integer. The Type classes SubclassData field is used to
store the number of bits. This allows 2^23 bits in an integer type.
2. Removes the five integer Type::TypeID values for the 1, 8, 16, 32 and
64-bit integers. These are replaced with just IntegerType which is not
a primitive any more.
3. Adjust the rest of LLVM to account for this change.
Note that while this incremental change lays the foundation for arbitrary
bit-width integers, LLVM has not yet been converted to actually deal with
them in any significant way. Most optimization passes, for example, will
still only deal with the byte-width integer types. Future increments
will rectify this situation.
llvm-svn: 33113
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 20 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 33 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/SCCP.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp | 7 |
4 files changed, 34 insertions, 28 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index a5a9f69c2a6..0643e75ab34 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -50,6 +50,7 @@ #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Transforms/Utils/Local.h" #include "llvm/Support/CommandLine.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" using namespace llvm; @@ -528,18 +529,27 @@ void IndVarSimplify::runOnLoop(Loop *L) { // induction variable to the right size for them, avoiding the need for the // code evaluation methods to insert induction variables of different sizes. if (DifferingSizes) { - bool InsertedSizes[17] = { false }; - InsertedSizes[LargestType->getPrimitiveSize()] = true; - for (unsigned i = 0, e = IndVars.size(); i != e; ++i) - if (!InsertedSizes[IndVars[i].first->getType()->getPrimitiveSize()]) { + SmallVector<unsigned,4> InsertedSizes; + InsertedSizes.push_back(LargestType->getPrimitiveSizeInBits()); + for (unsigned i = 0, e = IndVars.size(); i != e; ++i) { + unsigned ithSize = IndVars[i].first->getType()->getPrimitiveSizeInBits(); + bool alreadyInsertedSize = false; + for (SmallVector<unsigned,4>::iterator I = InsertedSizes.begin(), + E = InsertedSizes.end(); I != E; ++I) + if (*I == ithSize) { + alreadyInsertedSize = true; + break; + } + if (!alreadyInsertedSize) { PHINode *PN = IndVars[i].first; - InsertedSizes[PN->getType()->getPrimitiveSize()] = true; + InsertedSizes.push_back(ithSize); Instruction *New = new TruncInst(IndVar, PN->getType(), "indvar", InsertPt); Rewriter.addInsertedValue(New, SE->getSCEV(New)); DOUT << "INDVARS: Made trunc IV for " << *PN << " NewVal = " << *New << "\n"; } + } } // Rewrite all induction variables in terms of the canonical induction diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index c039b3999a3..aecc9a93ef1 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -339,12 +339,12 @@ static bool isOnlyUse(Value *V) { // getPromotedType - Return the specified type promoted as it would be to pass // though a va_arg area... static const Type *getPromotedType(const Type *Ty) { - switch (Ty->getTypeID()) { - case Type::Int8TyID: - case Type::Int16TyID: return Type::Int32Ty; - case Type::FloatTyID: return Type::DoubleTy; - default: return Ty; - } + if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty)) { + if (ITy->getBitWidth() < 32) + return Type::Int32Ty; + } else if (Ty == Type::FloatTy) + return Type::DoubleTy; + return Ty; } /// getBitCastOperand - If the specified operand is a CastInst or a constant @@ -531,7 +531,6 @@ static ConstantInt *SubOne(ConstantInt *C) { ConstantInt::get(C->getType(), 1))); } - /// ComputeMaskedBits - Determine which of the bits specified in Mask are /// known to be either zero or one and return them in the KnownZero/KnownOne /// bitsets. This code only analyzes bits in Mask, in order to short-circuit @@ -3516,7 +3515,7 @@ Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) { /// ByteValues - For each byte of the result, we keep track of which value /// defines each byte. std::vector<Value*> ByteValues; - ByteValues.resize(I.getType()->getPrimitiveSize()); + ByteValues.resize(TD->getTypeSize(I.getType())); // Try to find all the pieces corresponding to the bswap. if (CollectBSwapParts(I.getOperand(0), ByteValues) || @@ -6580,9 +6579,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { } if (SI.getType() == Type::Int1Ty) { - ConstantInt *C; - if ((C = dyn_cast<ConstantInt>(TrueVal)) && - C->getType() == Type::Int1Ty) { + if (ConstantInt *C = dyn_cast<ConstantInt>(TrueVal)) { if (C->getZExtValue()) { // Change: A = select B, true, C --> A = or B, C return BinaryOperator::createOr(CondVal, FalseVal); @@ -6593,8 +6590,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { "not."+CondVal->getName()), SI); return BinaryOperator::createAnd(NotCond, FalseVal); } - } else if ((C = dyn_cast<ConstantInt>(FalseVal)) && - C->getType() == Type::Int1Ty) { + } else if (ConstantInt *C = dyn_cast<ConstantInt>(FalseVal)) { if (C->getZExtValue() == false) { // Change: A = select B, C, false --> A = and B, C return BinaryOperator::createAnd(CondVal, TrueVal); @@ -7649,7 +7645,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { } } else if (SrcTy->getPrimitiveSizeInBits() < DestTy->getPrimitiveSizeInBits() && - SrcTy->getPrimitiveSize() == 4) { + SrcTy->getPrimitiveSizeInBits() == 32) { // We can eliminate a cast from [u]int to [u]long iff the target // is a 32-bit pointer target. if (SrcTy->getPrimitiveSizeInBits() >= TD->getPointerSizeInBits()) { @@ -7664,7 +7660,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // insert it. This explicit cast can make subsequent optimizations more // obvious. Value *Op = GEP.getOperand(i); - if (Op->getType()->getPrimitiveSize() > TD->getPointerSize()) + if (TD->getTypeSize(Op->getType()) > TD->getPointerSize()) if (Constant *C = dyn_cast<Constant>(Op)) { GEP.setOperand(i, ConstantExpr::getTrunc(C, TD->getIntPtrType())); MadeChange = true; @@ -7722,11 +7718,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { GO1 = ConstantExpr::getIntegerCast(GO1C, SO1->getType(), true); } else { unsigned PS = TD->getPointerSize(); - if (SO1->getType()->getPrimitiveSize() == PS) { + if (TD->getTypeSize(SO1->getType()) == PS) { // Convert GO1 to SO1's type. GO1 = InsertCastToIntPtrTy(GO1, SO1->getType(), &GEP, this); - } else if (GO1->getType()->getPrimitiveSize() == PS) { + } else if (TD->getTypeSize(GO1->getType()) == PS) { // Convert SO1 to GO1's type. SO1 = InsertCastToIntPtrTy(SO1, GO1->getType(), &GEP, this); } else { @@ -9056,8 +9052,7 @@ static void AddReachableCodeToWorklist(BasicBlock *BB, // only visit the reachable successor. TerminatorInst *TI = BB->getTerminator(); if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { - if (BI->isConditional() && isa<ConstantInt>(BI->getCondition()) && - BI->getCondition()->getType() == Type::Int1Ty) { + if (BI->isConditional() && isa<ConstantInt>(BI->getCondition())) { bool CondVal = cast<ConstantInt>(BI->getCondition())->getZExtValue(); AddReachableCodeToWorklist(BI->getSuccessor(!CondVal), Visited, WorkList, TD); diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 2bc000440ae..1ebc1cf4a9e 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -1611,7 +1611,7 @@ bool IPSCCP::runOnModule(Module &M) { Instruction *I = cast<Instruction>(DeadBB->use_back()); bool Folded = ConstantFoldTerminator(I->getParent()); if (!Folded) { - // The constant folder may not have been able to fold the termiantor + // The constant folder may not have been able to fold the terminator // if this is a branch or switch on undef. Fold it manually as a // branch to the first successor. if (BranchInst *BI = dyn_cast<BranchInst>(I)) { diff --git a/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 00e58180bd0..a92459b8094 100644 --- a/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -444,7 +444,8 @@ static bool MergeInType(const Type *In, const Type *&Accum, // Noop. } else if (In->isIntegral() && Accum->isIntegral()) { // integer union. // Otherwise pick whichever type is larger. - if (In->getTypeID() > Accum->getTypeID()) + if (cast<IntegerType>(In)->getBitWidth() > + cast<IntegerType>(Accum)->getBitWidth()) Accum = In; } else if (isa<PointerType>(In) && isa<PointerType>(Accum)) { // Pointer unions just stay as one of the pointers. @@ -643,8 +644,8 @@ void SROA::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, unsigned Offset) { } else { // Must be an element access. unsigned Elt = Offset/(TD.getTypeSize(PTy->getElementType())*8); - NV = new ExtractElementInst(NV, ConstantInt::get(Type::Int32Ty, Elt), - "tmp", LI); + NV = new ExtractElementInst( + NV, ConstantInt::get(Type::Int32Ty, Elt), "tmp", LI); } } else if (isa<PointerType>(NV->getType())) { assert(isa<PointerType>(LI->getType())); |

