[llvm-commits] [SignlessTypes] CVS: llvm/lib/Transforms/Utils/CodeExtractor.cpp Local.cpp LowerAllocations.cpp LowerInvoke.cpp LowerSwitch.cpp

Reid Spencer reid at x10sys.com
Wed Oct 18 20:58:57 PDT 2006



Changes in directory llvm/lib/Transforms/Utils:

CodeExtractor.cpp updated: 1.40 -> 1.40.2.1
Local.cpp updated: 1.58 -> 1.58.4.1
LowerAllocations.cpp updated: 1.61 -> 1.61.2.1
LowerInvoke.cpp updated: 1.41 -> 1.41.2.1
LowerSwitch.cpp updated: 1.24 -> 1.24.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:  (+20 -19)

 CodeExtractor.cpp    |   14 +++++++-------
 Local.cpp            |    6 +++---
 LowerAllocations.cpp |    2 +-
 LowerInvoke.cpp      |    8 ++++----
 LowerSwitch.cpp      |    9 +++++----
 5 files changed, 20 insertions(+), 19 deletions(-)


Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp
diff -u llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.40 llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.40.2.1
--- llvm/lib/Transforms/Utils/CodeExtractor.cpp:1.40	Thu Sep 28 17:58:25 2006
+++ llvm/lib/Transforms/Utils/CodeExtractor.cpp	Wed Oct 18 22:57:56 2006
@@ -305,7 +305,7 @@
     if (AggregateArgs) {
       std::vector<Value*> Indices;
       Indices.push_back(Constant::getNullValue(Type::UIntTy));
-      Indices.push_back(ConstantUInt::get(Type::UIntTy, i));
+      Indices.push_back(ConstantInt::get(Type::UIntTy, i));
       std::string GEPname = "gep_" + inputs[i]->getName();
       TerminatorInst *TI = newFunction->begin()->getTerminator();
       GetElementPtrInst *GEP = new GetElementPtrInst(AI, Indices, GEPname, TI);
@@ -392,7 +392,7 @@
     for (unsigned i = 0, e = inputs.size(); i != e; ++i) {
       std::vector<Value*> Indices;
       Indices.push_back(Constant::getNullValue(Type::UIntTy));
-      Indices.push_back(ConstantUInt::get(Type::UIntTy, i));
+      Indices.push_back(ConstantInt::get(Type::UIntTy, i));
       GetElementPtrInst *GEP =
         new GetElementPtrInst(Struct, Indices,
                               "gep_" + StructValues[i]->getName());
@@ -418,7 +418,7 @@
     if (AggregateArgs) {
       std::vector<Value*> Indices;
       Indices.push_back(Constant::getNullValue(Type::UIntTy));
-      Indices.push_back(ConstantUInt::get(Type::UIntTy, FirstOut + i));
+      Indices.push_back(ConstantInt::get(Type::UIntTy, FirstOut + i));
       GetElementPtrInst *GEP
         = new GetElementPtrInst(Struct, Indices,
                                 "gep_reload_" + outputs[i]->getName());
@@ -439,7 +439,7 @@
 
   // Now we can emit a switch statement using the call as a value.
   SwitchInst *TheSwitch =
-    new SwitchInst(ConstantUInt::getNullValue(Type::UShortTy),
+    new SwitchInst(ConstantInt::getNullValue(Type::UShortTy),
                    codeReplacer, 0, codeReplacer);
 
   // Since there may be multiple exits from the original region, make the new
@@ -473,14 +473,14 @@
             brVal = ConstantBool::get(!SuccNum);
             break;
           default:
-            brVal = ConstantUInt::get(Type::UShortTy, SuccNum);
+            brVal = ConstantInt::get(Type::UShortTy, SuccNum);
             break;
           }
 
           ReturnInst *NTRet = new ReturnInst(brVal, NewTarget);
 
           // Update the switch instruction.
-          TheSwitch->addCase(ConstantUInt::get(Type::UShortTy, SuccNum),
+          TheSwitch->addCase(ConstantInt::get(Type::UShortTy, SuccNum),
                              OldTarget);
 
           // Restore values just before we exit
@@ -519,7 +519,7 @@
               if (AggregateArgs) {
                 std::vector<Value*> Indices;
                 Indices.push_back(Constant::getNullValue(Type::UIntTy));
-                Indices.push_back(ConstantUInt::get(Type::UIntTy,FirstOut+out));
+                Indices.push_back(ConstantInt::get(Type::UIntTy,FirstOut+out));
                 GetElementPtrInst *GEP =
                   new GetElementPtrInst(OAI, Indices,
                                         "gep_" + outputs[out]->getName(),


Index: llvm/lib/Transforms/Utils/Local.cpp
diff -u llvm/lib/Transforms/Utils/Local.cpp:1.58 llvm/lib/Transforms/Utils/Local.cpp:1.58.4.1
--- llvm/lib/Transforms/Utils/Local.cpp:1.58	Fri May 26 20:18:04 2006
+++ llvm/lib/Transforms/Utils/Local.cpp	Wed Oct 18 22:57:56 2006
@@ -272,10 +272,10 @@
   gep_type_iterator I = gep_type_begin(CE), E = gep_type_end(CE);
   for (++I; I != E; ++I)
     if (const StructType *STy = dyn_cast<StructType>(*I)) {
-      ConstantUInt *CU = cast<ConstantUInt>(I.getOperand());
-      assert(CU->getValue() < STy->getNumElements() &&
+      ConstantInt *CU = cast<ConstantInt>(I.getOperand());
+      assert(CU->getZExtValue() < STy->getNumElements() &&
              "Struct index out of range!");
-      unsigned El = (unsigned)CU->getValue();
+      unsigned El = (unsigned)CU->getZExtValue();
       if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
         C = CS->getOperand(El);
       } else if (isa<ConstantAggregateZero>(C)) {


Index: llvm/lib/Transforms/Utils/LowerAllocations.cpp
diff -u llvm/lib/Transforms/Utils/LowerAllocations.cpp:1.61 llvm/lib/Transforms/Utils/LowerAllocations.cpp:1.61.2.1
--- llvm/lib/Transforms/Utils/LowerAllocations.cpp:1.61	Sun Aug 27 17:42:52 2006
+++ llvm/lib/Transforms/Utils/LowerAllocations.cpp	Wed Oct 18 22:57:56 2006
@@ -119,7 +119,7 @@
       // malloc(type) becomes sbyte *malloc(size)
       Value *MallocArg;
       if (LowerMallocArgToInteger)
-        MallocArg = ConstantUInt::get(Type::ULongTy, TD.getTypeSize(AllocTy));
+        MallocArg = ConstantInt::get(Type::ULongTy, TD.getTypeSize(AllocTy));
       else
         MallocArg = ConstantExpr::getSizeOf(AllocTy);
       MallocArg = ConstantExpr::getCast(cast<Constant>(MallocArg), IntPtrTy);


Index: llvm/lib/Transforms/Utils/LowerInvoke.cpp
diff -u llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.41 llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.41.2.1
--- llvm/lib/Transforms/Utils/LowerInvoke.cpp:1.41	Tue Sep  5 12:48:07 2006
+++ llvm/lib/Transforms/Utils/LowerInvoke.cpp	Wed Oct 18 22:57:56 2006
@@ -269,7 +269,7 @@
 void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
                                          AllocaInst *InvokeNum,
                                          SwitchInst *CatchSwitch) {
-  ConstantUInt *InvokeNoC = ConstantUInt::get(Type::UIntTy, InvokeNo);
+  ConstantInt *InvokeNoC = ConstantInt::get(Type::UIntTy, InvokeNo);
 
   // Insert a store of the invoke num before the invoke and store zero into the
   // location afterward.
@@ -461,7 +461,7 @@
     
     std::vector<Value*> Idx;
     Idx.push_back(Constant::getNullValue(Type::IntTy));
-    Idx.push_back(ConstantUInt::get(Type::UIntTy, 1));
+    Idx.push_back(ConstantInt::get(Type::UIntTy, 1));
     OldJmpBufPtr = new GetElementPtrInst(JmpBuf, Idx, "OldBuf",
                                          EntryBB->getTerminator());
 
@@ -500,7 +500,7 @@
     BasicBlock *ContBlock = EntryBB->splitBasicBlock(EntryBB->getTerminator(),
                                                      "setjmp.cont");
 
-    Idx[1] = ConstantUInt::get(Type::UIntTy, 0);
+    Idx[1] = ConstantInt::get(Type::UIntTy, 0);
     Value *JmpBufPtr = new GetElementPtrInst(JmpBuf, Idx, "TheJmpBuf",
                                              EntryBB->getTerminator());
     Value *SJRet = new CallInst(SetJmpFn, JmpBufPtr, "sjret",
@@ -550,7 +550,7 @@
   // Get a pointer to the jmpbuf and longjmp.
   std::vector<Value*> Idx;
   Idx.push_back(Constant::getNullValue(Type::IntTy));
-  Idx.push_back(ConstantUInt::get(Type::UIntTy, 0));
+  Idx.push_back(ConstantInt::get(Type::UIntTy, 0));
   Idx[0] = new GetElementPtrInst(BufPtr, Idx, "JmpBuf", UnwindBlock);
   Idx[1] = ConstantInt::get(Type::IntTy, 1);
   new CallInst(LongJmpFn, Idx, "", UnwindBlock);


Index: llvm/lib/Transforms/Utils/LowerSwitch.cpp
diff -u llvm/lib/Transforms/Utils/LowerSwitch.cpp:1.24 llvm/lib/Transforms/Utils/LowerSwitch.cpp:1.24.2.1
--- llvm/lib/Transforms/Utils/LowerSwitch.cpp:1.24	Sun Aug 27 17:42:52 2006
+++ llvm/lib/Transforms/Utils/LowerSwitch.cpp	Wed Oct 18 22:57:56 2006
@@ -60,11 +60,12 @@
   struct CaseCmp {
     bool operator () (const LowerSwitch::Case& C1,
                       const LowerSwitch::Case& C2) {
-      if (const ConstantUInt* U1 = dyn_cast<const ConstantUInt>(C1.first))
-        return U1->getValue() < cast<const ConstantUInt>(C2.first)->getValue();
 
-      const ConstantSInt* S1 = dyn_cast<const ConstantSInt>(C1.first);
-      return S1->getValue() < cast<const ConstantSInt>(C2.first)->getValue();
+      const ConstantInt* CI1 = cast<const ConstantInt>(C1.first);
+      const ConstantInt* CI2 = cast<const ConstantInt>(C2.first);
+      if (CI1->getType()->isUnsigned()) 
+        return CI1->getZExtValue() < CI2->getZExtValue();
+      return CI1->getSExtValue() < CI2->getSExtValue();
     }
   };
 






More information about the llvm-commits mailing list