[llvm-commits] [SignlessTypes] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp SelectionDAGISel.cpp

Reid Spencer reid at x10sys.com
Wed Oct 18 20:59:01 PDT 2006



Changes in directory llvm/lib/CodeGen/SelectionDAG:

LegalizeDAG.cpp updated: 1.412 -> 1.412.2.1
SelectionDAGISel.cpp updated: 1.289 -> 1.289.2.1
---
Log message:

For PR950: http://llvm.org/PR950 :
This commit (on SignlessTypes branch) provides the first Iteration for 
moving LLVM away from Signed types. This patch removes the ConstantSInt
and ConstantUInt classes from Type.h and makes all necessary changes in
LLVM to compensate.


---
Diffs of the changes:  (+43 -39)

 LegalizeDAG.cpp      |    6 ++--
 SelectionDAGISel.cpp |   76 ++++++++++++++++++++++++++-------------------------
 2 files changed, 43 insertions(+), 39 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.412 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.412.2.1
--- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.412	Fri Oct 13 16:12:22 2006
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp	Wed Oct 18 22:57:55 2006
@@ -3562,7 +3562,7 @@
         CV.push_back(ConstantFP::get(OpNTy, V->getValue()));
       } else if (ConstantSDNode *V = 
                  dyn_cast<ConstantSDNode>(Node->getOperand(i))) {
-        CV.push_back(ConstantUInt::get(OpNTy, V->getValue()));
+        CV.push_back(ConstantInt::get(OpNTy, V->getValue()));
       } else {
         assert(Node->getOperand(i).getOpcode() == ISD::UNDEF);
         CV.push_back(UndefValue::get(OpNTy));
@@ -3915,7 +3915,7 @@
                                       SignSet, Four, Zero);
     uint64_t FF = 0x5f800000ULL;
     if (TLI.isLittleEndian()) FF <<= 32;
-    static Constant *FudgeFactor = ConstantUInt::get(Type::ULongTy, FF);
+    static Constant *FudgeFactor = ConstantInt::get(Type::ULongTy, FF);
 
     SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
     CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);
@@ -4046,7 +4046,7 @@
   case MVT::i64: FF = 0x5F800000ULL; break;  // 2^64 (as a float)
   }
   if (TLI.isLittleEndian()) FF <<= 32;
-  static Constant *FudgeFactor = ConstantUInt::get(Type::ULongTy, FF);
+  static Constant *FudgeFactor = ConstantInt::get(Type::ULongTy, FF);
 
   SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
   CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.289 llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.289.2.1
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp:1.289	Mon Oct 16 15:52:31 2006
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp	Wed Oct 18 22:57:55 2006
@@ -236,25 +236,27 @@
   Function::iterator BB = Fn.begin(), EB = Fn.end();
   for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
     if (AllocaInst *AI = dyn_cast<AllocaInst>(I))
-      if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(AI->getArraySize())) {
-        const Type *Ty = AI->getAllocatedType();
-        uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty);
-        unsigned Align = 
-          std::max((unsigned)TLI.getTargetData()->getTypeAlignment(Ty),
-                   AI->getAlignment());
-
-        // If the alignment of the value is smaller than the size of the value,
-        // and if the size of the value is particularly small (<= 8 bytes),
-        // round up to the size of the value for potentially better performance.
-        //
-        // FIXME: This could be made better with a preferred alignment hook in
-        // TargetData.  It serves primarily to 8-byte align doubles for X86.
-        if (Align < TySize && TySize <= 8) Align = TySize;
-        TySize *= CUI->getValue();   // Get total allocated size.
-        if (TySize == 0) TySize = 1; // Don't create zero-sized stack objects.
-        StaticAllocaMap[AI] =
-          MF.getFrameInfo()->CreateStackObject((unsigned)TySize, Align);
-      }
+      if (ConstantInt *CUI = dyn_cast<ConstantInt>(AI->getArraySize())) 
+        if (CUI->getType()->isUnsigned()) {
+          const Type *Ty = AI->getAllocatedType();
+          uint64_t TySize = TLI.getTargetData()->getTypeSize(Ty);
+          unsigned Align = 
+            std::max((unsigned)TLI.getTargetData()->getTypeAlignment(Ty),
+                     AI->getAlignment());
+
+          // If the alignment of the value is smaller than the size of the 
+          // value, and if the size of the value is particularly small 
+          // (<= 8 bytes), round up to the size of the value for potentially 
+          // better performance.
+          //
+          // FIXME: This could be made better with a preferred alignment hook in
+          // TargetData.  It serves primarily to 8-byte align doubles for X86.
+          if (Align < TySize && TySize <= 8) Align = TySize;
+          TySize *= CUI->getZExtValue();   // Get total allocated size.
+          if (TySize == 0) TySize = 1; // Don't create zero-sized stack objects.
+          StaticAllocaMap[AI] =
+            MF.getFrameInfo()->CreateStackObject((unsigned)TySize, Align);
+        }
 
   for (; BB != EB; ++BB)
     for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
@@ -393,11 +395,13 @@
   /// The comparison function for sorting Case values.
   struct CaseCmp {
     bool operator () (const Case& C1, const Case& C2) {
-      if (const ConstantUInt* U1 = dyn_cast<const ConstantUInt>(C1.first))
-        return U1->getValue() < cast<const ConstantUInt>(C2.first)->getValue();
+      if (const ConstantInt* I1 = dyn_cast<const ConstantInt>(C1.first))
+        if (I1->getType()->isUnsigned())
+          return I1->getZExtValue() <
+            cast<const ConstantInt>(C2.first)->getZExtValue();
       
-      const ConstantSInt* S1 = dyn_cast<const ConstantSInt>(C1.first);
-      return S1->getValue() < cast<const ConstantSInt>(C2.first)->getValue();
+      return cast<const ConstantInt>(C1.first)->getSExtValue() <
+         cast<const ConstantInt>(C2.first)->getSExtValue();
     }
   };
   
@@ -1250,7 +1254,7 @@
        OI != E; ++OI) {
     Value *Idx = *OI;
     if (const StructType *StTy = dyn_cast<StructType>(Ty)) {
-      unsigned Field = cast<ConstantUInt>(Idx)->getValue();
+      unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
       if (Field) {
         // N = N + Offset
         uint64_t Offset = TD->getStructLayout(StTy)->MemberOffsets[Field];
@@ -1264,12 +1268,13 @@
       // If this is a constant subscript, handle it quickly.
       if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
         if (CI->getRawValue() == 0) continue;
-
         uint64_t Offs;
-        if (ConstantSInt *CSI = dyn_cast<ConstantSInt>(CI))
-          Offs = (int64_t)TD->getTypeSize(Ty)*CSI->getValue();
+        if (CI->getType()->isSigned()) 
+          Offs = (int64_t)
+            TD->getTypeSize(Ty)*cast<ConstantInt>(CI)->getSExtValue();
         else
-          Offs = TD->getTypeSize(Ty)*cast<ConstantUInt>(CI)->getValue();
+          Offs = 
+            TD->getTypeSize(Ty)*cast<ConstantInt>(CI)->getZExtValue();
         N = DAG.getNode(ISD::ADD, N.getValueType(), N, getIntPtrConstant(Offs));
         continue;
       }
@@ -2723,7 +2728,7 @@
 }
 
 void SelectionDAGLowering::visitFrameReturnAddress(CallInst &I, bool isFrame) {
-  unsigned Depth = (unsigned)cast<ConstantUInt>(I.getOperand(1))->getValue();
+  unsigned Depth = (unsigned)cast<ConstantInt>(I.getOperand(1))->getZExtValue();
   std::pair<SDOperand,SDOperand> Result =
     TLI.LowerFrameReturnAddress(isFrame, getRoot(), Depth, DAG);
   setValue(&I, Result.first);
@@ -3150,7 +3155,7 @@
        E = GEPI->op_end(); OI != E; ++OI) {
     Value *Idx = *OI;
     if (const StructType *StTy = dyn_cast<StructType>(Ty)) {
-      unsigned Field = cast<ConstantUInt>(Idx)->getValue();
+      unsigned Field = cast<ConstantInt>(Idx)->getZExtValue();
       if (Field)
         ConstantOffset += TD->getStructLayout(StTy)->MemberOffsets[Field];
       Ty = StTy->getElementType(Field);
@@ -3160,11 +3165,10 @@
       // Handle constant subscripts.
       if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) {
         if (CI->getRawValue() == 0) continue;
-        
-        if (ConstantSInt *CSI = dyn_cast<ConstantSInt>(CI))
-          ConstantOffset += (int64_t)TD->getTypeSize(Ty)*CSI->getValue();
+        if (CI->getType()->isSigned())
+          ConstantOffset += (int64_t)TD->getTypeSize(Ty)*CI->getSExtValue();
         else
-          ConstantOffset+=TD->getTypeSize(Ty)*cast<ConstantUInt>(CI)->getValue();
+          ConstantOffset += TD->getTypeSize(Ty)*CI->getZExtValue();
         continue;
       }
       
@@ -3176,7 +3180,7 @@
       uint64_t ElementSize = TD->getTypeSize(Ty);
       // Mask off bits that should not be set.
       ElementSize &= ~0ULL >> (64-UIntPtrTy->getPrimitiveSizeInBits());
-      Constant *SizeCst = ConstantUInt::get(UIntPtrTy, ElementSize);
+      Constant *SizeCst = ConstantInt::get(UIntPtrTy, ElementSize);
 
       // Multiply by the element size and add to the base.
       Idx = BinaryOperator::createMul(Idx, SizeCst, "", GEPI);
@@ -3186,7 +3190,7 @@
   
   // Make sure that the offset fits in uintptr_t.
   ConstantOffset &= ~0ULL >> (64-UIntPtrTy->getPrimitiveSizeInBits());
-  Constant *PtrOffset = ConstantUInt::get(UIntPtrTy, ConstantOffset);
+  Constant *PtrOffset = ConstantInt::get(UIntPtrTy, ConstantOffset);
   
   // Okay, we have now emitted all of the variable index parts to the BB that
   // the GEP is defined in.  Loop over all of the using instructions, inserting






More information about the llvm-commits mailing list