[llvm-commits] [SignlessTypes] CVS: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp

Zhou Sheng zhousheng00 at gmail.com
Sun Oct 29 00:36:12 PDT 2006



Changes in directory llvm/lib/ExecutionEngine/Interpreter:

Execution.cpp updated: 1.139.6.5 -> 1.139.6.6
---
Log message:



---
Diffs of the changes:  (+51 -14)

 Execution.cpp |   65 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 51 insertions(+), 14 deletions(-)


Index: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
diff -u llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.139.6.5 llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.139.6.6
--- llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.139.6.5	Wed Oct 25 20:58:05 2006
+++ llvm/lib/ExecutionEngine/Interpreter/Execution.cpp	Sun Oct 29 01:35:49 2006
@@ -40,7 +40,11 @@
                                    const Type *Ty);
 static GenericValue executeMulInst(GenericValue Src1, GenericValue Src2,
                                    const Type *Ty);
-static GenericValue executeRemInst(GenericValue Src1, GenericValue Src2,
+static GenericValue executeURemInst(GenericValue Src1, GenericValue Src2,
+                                   const Type *Ty);
+static GenericValue executeSRemInst(GenericValue Src1, GenericValue Src2,
+                                   const Type *Ty);
+static GenericValue executeFRemInst(GenericValue Src1, GenericValue Src2,
                                    const Type *Ty);
 static GenericValue executeUDivInst(GenericValue Src1, GenericValue Src2,
                                     const Type *Ty);
@@ -106,10 +110,17 @@
                            getOperandValue(CE->getOperand(1), SF),
                            CE->getOperand(0)->getType());
   case Instruction::URem:
+    return executeURemInst(getOperandValue(CE->getOperand(0), SF),
+                           getOperandValue(CE->getOperand(1), SF),
+                           CE->getOperand(0)->getType());
   case Instruction::SRem:
-    return executeRemInst(getOperandValue(CE->getOperand(0), SF),
-                          getOperandValue(CE->getOperand(1), SF),
-                          CE->getOperand(0)->getType());
+    return executeSRemInst(getOperandValue(CE->getOperand(0), SF),
+                           getOperandValue(CE->getOperand(1), SF),
+                           CE->getOperand(0)->getType());
+  case Instruction::FRem:
+    return executeFRemInst(getOperandValue(CE->getOperand(0), SF),
+                           getOperandValue(CE->getOperand(1), SF),
+                           CE->getOperand(0)->getType());
   case Instruction::And:
     return executeAndInst(getOperandValue(CE->getOperand(0), SF),
                           getOperandValue(CE->getOperand(1), SF),
@@ -296,24 +307,50 @@
     IMPLEMENT_BINARY_OPERATOR(/, Float);
     IMPLEMENT_BINARY_OPERATOR(/, Double);
   default:
-    std::cout << "Unhandled type for Div instruction: " << *Ty << "\n";
+    std::cout << "Unhandled type for FDiv instruction: " << *Ty << "\n";
     abort();
   }
   return Dest;
 }
 
-static GenericValue executeRemInst(GenericValue Src1, GenericValue Src2,
-                                   const Type *Ty) {
+static GenericValue executeURemInst(GenericValue Src1, GenericValue Src2,
+                                    const Type *Ty) {
   GenericValue Dest;
+  if (Ty->isSigned())
+    Ty = Ty->getUnsignedVersion();
   switch (Ty->getTypeID()) {
     IMPLEMENT_BINARY_OPERATOR(%, UByte);
-    IMPLEMENT_BINARY_OPERATOR(%, SByte);
     IMPLEMENT_BINARY_OPERATOR(%, UShort);
-    IMPLEMENT_BINARY_OPERATOR(%, Short);
     IMPLEMENT_BINARY_OPERATOR(%, UInt);
-    IMPLEMENT_BINARY_OPERATOR(%, Int);
     IMPLEMENT_BINARY_OPERATOR(%, ULong);
+  default:
+    std::cout << "Unhandled type for URem instruction: " << *Ty << "\n";
+    abort();
+  }
+  return Dest;
+}
+
+static GenericValue executeSRemInst(GenericValue Src1, GenericValue Src2,
+                                    const Type *Ty) {
+  GenericValue Dest;
+  if (Ty->isUnsigned())
+    Ty = Ty->getSignedVersion();
+  switch (Ty->getTypeID()) {
+    IMPLEMENT_BINARY_OPERATOR(%, SByte);
+    IMPLEMENT_BINARY_OPERATOR(%, Short);
+    IMPLEMENT_BINARY_OPERATOR(%, Int);
     IMPLEMENT_BINARY_OPERATOR(%, Long);
+  default:
+    std::cout << "Unhandled type for SRem instruction: " << *Ty << "\n";
+    abort();
+  }
+  return Dest;
+}
+
+static GenericValue executeFRemInst(GenericValue Src1, GenericValue Src2,
+                                    const Type *Ty) {
+  GenericValue Dest;
+  switch (Ty->getTypeID()) {
   case Type::FloatTyID:
     Dest.FloatVal = fmod(Src1.FloatVal, Src2.FloatVal);
     break;
@@ -321,7 +358,7 @@
     Dest.DoubleVal = fmod(Src1.DoubleVal, Src2.DoubleVal);
     break;
   default:
-    std::cout << "Unhandled type for Rem instruction: " << *Ty << "\n";
+    std::cout << "Unhandled type for FRem instruction: " << *Ty << "\n";
     abort();
   }
   return Dest;
@@ -543,9 +580,9 @@
   case Instruction::Add:   R = executeAddInst  (Src1, Src2, Ty); break;
   case Instruction::Sub:   R = executeSubInst  (Src1, Src2, Ty); break;
   case Instruction::Mul:   R = executeMulInst  (Src1, Src2, Ty); break;
-  case Instruction::URem:
-  case Instruction::SRem:  
-  case Instruction::FRem:  R = executeRemInst  (Src1, Src2, Ty); break;
+  case Instruction::URem:  R = executeURemInst (Src1, Src2, Ty); break;
+  case Instruction::SRem:  R = executeSRemInst (Src1, Src2, Ty); break;
+  case Instruction::FRem:  R = executeFRemInst (Src1, Src2, Ty); break;
   case Instruction::UDiv:  R = executeUDivInst (Src1, Src2, Ty); break;
   case Instruction::SDiv:  R = executeSDivInst (Src1, Src2, Ty); break;
   case Instruction::FDiv:  R = executeFDivInst (Src1, Src2, Ty); break;






More information about the llvm-commits mailing list