[llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp Constants.cpp

Reid Spencer reid at x10sys.com
Sun Dec 3 18:44:00 PST 2006



Changes in directory llvm/lib/VMCore:

Instructions.cpp updated: 1.49 -> 1.50
Constants.cpp updated: 1.174 -> 1.175
---
Log message:

Take a baby step towards getting rid of inferred casts. Provide methods on
CastInst and ConstantExpr that allow the signedness to be explicitly passed
in and reliance on signedness removed from getCastOpcode. These are 
temporary measures useful during the conversion of inferred casts.


---
Diffs of the changes:  (+26 -10)

 Constants.cpp    |   13 +++++++------
 Instructions.cpp |   23 +++++++++++++++++++----
 2 files changed, 26 insertions(+), 10 deletions(-)


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.49 llvm/lib/VMCore/Instructions.cpp:1.50
--- llvm/lib/VMCore/Instructions.cpp:1.49	Fri Dec  1 20:22:01 2006
+++ llvm/lib/VMCore/Instructions.cpp	Sun Dec  3 20:43:42 2006
@@ -1507,7 +1507,8 @@
 // should not assert in checkCast. In other words, this produces a "correct"
 // casting opcode for the arguments passed to it.
 Instruction::CastOps
-CastInst::getCastOpcode(const Value *Src, const Type *DestTy) {
+CastInst::getCastOpcode(
+  const Value *Src, bool SrcIsSigned, const Type *DestTy, bool DestIsSigned) {
   // Get the bit sizes, we'll need these
   const Type *SrcTy = Src->getType();
   unsigned SrcBits = SrcTy->getPrimitiveSizeInBits();   // 0 for ptr/packed
@@ -1519,7 +1520,7 @@
       if (DestBits < SrcBits)
         return Trunc;                               // int -> smaller int
       else if (DestBits > SrcBits) {                // its an extension
-        if (SrcTy->isSigned())
+        if (SrcIsSigned)
           return SExt;                              // signed -> SEXT
         else
           return ZExt;                              // unsigned -> ZEXT
@@ -1527,7 +1528,7 @@
         return BitCast;                             // Same size, No-op cast
       }
     } else if (SrcTy->isFloatingPoint()) {          // Casting from floating pt
-      if (DestTy->isSigned()) 
+      if (DestIsSigned) 
         return FPToSI;                              // FP -> sint
       else
         return FPToUI;                              // FP -> uint 
@@ -1542,7 +1543,7 @@
     }
   } else if (DestTy->isFloatingPoint()) {           // Casting to floating pt
     if (SrcTy->isIntegral()) {                      // Casting from integral
-      if (SrcTy->isSigned())
+      if (SrcIsSigned)
         return SIToFP;                              // sint -> FP
       else
         return UIToFP;                              // uint -> FP
@@ -1649,6 +1650,20 @@
   }
 }
 
+CastInst *CastInst::createInferredCast(
+  Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore)
+{
+  return createInferredCast(S, S->getType()->isSigned(), Ty, Ty->isSigned(),
+      Name, InsertBefore);
+}
+
+CastInst *CastInst::createInferredCast(
+  Value *S, const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) 
+{
+  return createInferredCast(S, S->getType()->isSigned(), Ty, Ty->isSigned(),
+      Name, InsertAtEnd);
+}
+
 TruncInst::TruncInst(
   Value *S, const Type *Ty, const std::string &Name, Instruction *InsertBefore
 ) : CastInst(Ty, Trunc, S, Name, InsertBefore) {


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.174 llvm/lib/VMCore/Constants.cpp:1.175
--- llvm/lib/VMCore/Constants.cpp:1.174	Sat Dec  2 23:48:19 2006
+++ llvm/lib/VMCore/Constants.cpp	Sun Dec  3 20:43:42 2006
@@ -1486,9 +1486,11 @@
   return ExprConstants->getOrCreate(Ty, Key);
 }
 
-Constant *ConstantExpr::getCast( Constant *C, const Type *Ty ) {
+Constant *ConstantExpr::getInferredCast(Constant *C, bool SrcIsSigned, 
+                                const Type *Ty, bool DestIsSigned) {
   // Note: we can't inline this because it requires the Instructions.h header
-  return getCast(CastInst::getCastOpcode(C, Ty), C, Ty);
+  return getCast(
+    CastInst::getCastOpcode(C, SrcIsSigned, Ty, DestIsSigned), C, Ty);
 }
 
 Constant *ConstantExpr::getCast(unsigned oc, Constant *C, const Type *Ty) {
@@ -1612,10 +1614,9 @@
 
 Constant *ConstantExpr::getSizeOf(const Type *Ty) {
   // sizeof is implemented as: (ulong) gep (Ty*)null, 1
-  return getCast(
-    getGetElementPtr(getNullValue(PointerType::get(Ty)),
-                 std::vector<Constant*>(1, ConstantInt::get(Type::UIntTy, 1))),
-    Type::ULongTy);
+  return getCast(Instruction::PtrToInt, getGetElementPtr(getNullValue(
+    PointerType::get(Ty)), std::vector<Constant*>(1, 
+    ConstantInt::get(Type::UIntTy, 1))), Type::ULongTy);
 }
 
 Constant *ConstantExpr::getPtrPtrFromArrayPtr(Constant *C) {






More information about the llvm-commits mailing list