Changes in directory llvm/lib/Transforms/Scalar:

IndVarSimplify.cpp updated: 1.102 -> 1.103
InstructionCombining.cpp updated: 1.592 -> 1.593
SCCP.cpp updated: 1.150 -> 1.151
ScalarReplAggregates.cpp updated: 1.63 -> 1.64
---
Log message:

For PR1064: http://llvm.org/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.



---
Diffs of the changes:  (+34 -28)

 IndVarSimplify.cpp       |   20 +++++++++++++++-----
 InstructionCombining.cpp |   33 ++++++++++++++-------------------
 SCCP.cpp                 |    2 +-
 ScalarReplAggregates.cpp |    7 ++++---
 4 files changed, 34 insertions(+), 28 deletions(-)


Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.102 
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.103
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.102 Mon Jan  8 10:32:00 2007
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp       Fri Jan 12 01:05:14 2007
@@ -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 @@
   // 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


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.592 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.593
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.592   Thu Jan 11 
22:24:45 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jan 12 01:05:14 2007
@@ -339,12 +339,12 @@
 // 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 @@
                                          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 @@
   /// 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 @@
   }
 
   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 @@
                                              "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 @@
             }
           } 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 @@
       // 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 @@
             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 @@
   // 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);


Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.150 
llvm/lib/Transforms/Scalar/SCCP.cpp:1.151
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.150   Thu Jan 11 22:24:46 2007
+++ llvm/lib/Transforms/Scalar/SCCP.cpp Fri Jan 12 01:05:14 2007
@@ -1611,7 +1611,7 @@
         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)) {


Index: llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp
diff -u llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.63 
llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.64
--- llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.63    Mon Jan  8 
10:32:00 2007
+++ llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp Fri Jan 12 01:05:14 2007
@@ -444,7 +444,8 @@
     // 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 @@
           } 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()));



_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to