[llvm-commits] CVS: llvm/include/llvm/InstrTypes.h Constants.h

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



Changes in directory llvm/include/llvm:

InstrTypes.h updated: 1.49 -> 1.50
Constants.h updated: 1.97 -> 1.98
---
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:  (+32 -4)

 Constants.h  |    9 ++++++++-
 InstrTypes.h |   27 ++++++++++++++++++++++++---
 2 files changed, 32 insertions(+), 4 deletions(-)


Index: llvm/include/llvm/InstrTypes.h
diff -u llvm/include/llvm/InstrTypes.h:1.49 llvm/include/llvm/InstrTypes.h:1.50
--- llvm/include/llvm/InstrTypes.h:1.49	Sun Nov 26 19:05:09 2006
+++ llvm/include/llvm/InstrTypes.h	Sun Dec  3 20:43:42 2006
@@ -303,7 +303,9 @@
   /// rules.
   static Instruction::CastOps getCastOpcode(
     const Value *Val, ///< The value to cast
-    const Type *Ty    ///< The Type to which the value should be casted
+    bool SrcIsSigned, ///< Whether to treat the source as signed
+    const Type *Ty,   ///< The Type to which the value should be casted
+    bool DstIsSigned  ///< Whether to treate the dest. as signed
   );
 
   /// Joins the create method (with insert-before-instruction semantics) above 
@@ -316,12 +318,21 @@
   /// @brief Inline helper method to join create with getCastOpcode.
   inline static CastInst *createInferredCast(
     Value *S,                     ///< The value to be casted (operand 0)
+    bool SrcIsSigned,             ///< Whether to treat the source as signed
     const Type *Ty,               ///< Type to which operand should be casted
+    bool DstIsSigned,             ///< Whether to treate the dest. as signed
     const std::string &Name = "", ///< Name for the instruction
     Instruction *InsertBefore = 0 ///< Place to insert the CastInst
   ) {
-    return create(getCastOpcode(S, Ty), S, Ty, Name, InsertBefore);
+    return create(getCastOpcode(S, SrcIsSigned, Ty, DstIsSigned), 
+                  S, Ty, Name, InsertBefore);
   }
+  static CastInst *createInferredCast(
+    Value *S,                     ///< The value to be casted (operand 0)
+    const Type *Ty,               ///< Type to which operand should be casted
+    const std::string &Name = "", ///< Name for the instruction
+    Instruction *InsertBefore = 0 ///< Place to insert the CastInst
+  );
 
   /// Joins the get method (with insert-at-end-of-block semantics) method 
   /// above with the getCastOpcode method. getOpcode(S,Ty) is called first to
@@ -334,13 +345,23 @@
   /// @brief Inline helper method to join create with getCastOpcode.
   inline static CastInst *createInferredCast(
     Value *S,                     ///< The value to be casted (operand 0)
+    bool SrcIsSigned,             ///< Whether to treat the source as signed
     const Type *Ty,               ///< Type to which operand should be casted
+    bool DstIsSigned,             ///< Whether to treate the dest. as signed
     const std::string &Name,      ///< Name for the instruction
     BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
   ) {
-    return create(getCastOpcode(S, Ty), S, Ty, Name, InsertAtEnd);
+    return create(getCastOpcode(S, SrcIsSigned, Ty, DstIsSigned), 
+                  S, Ty, Name, InsertAtEnd);
   }
 
+  static CastInst *createInferredCast(
+    Value *S,                     ///< The value to be casted (operand 0)
+    const Type *Ty,               ///< Type to which operand should be casted
+    const std::string &Name,      ///< Name for the instruction
+    BasicBlock *InsertAtEnd       ///< The block to insert the instruction into
+  );
+
   /// There are several places where we need to know if a cast instruction 
   /// only deals with integer source and destination types. To simplify that
   /// logic, this method is provided.


Index: llvm/include/llvm/Constants.h
diff -u llvm/include/llvm/Constants.h:1.97 llvm/include/llvm/Constants.h:1.98
--- llvm/include/llvm/Constants.h:1.97	Sat Dec  2 23:48:19 2006
+++ llvm/include/llvm/Constants.h	Sun Dec  3 20:43:42 2006
@@ -541,8 +541,15 @@
     const Type *Ty ///< The type to which the constant is converted
   );
 
+  // This method uses the CastInst::getCastOpcode method to infer the
+  // cast opcode to use. 
   // @brief Get a ConstantExpr Conversion operator that casts C to Ty
-  static Constant *getCast(Constant *C, const Type *Ty);
+  static Constant *getInferredCast(Constant *C, bool SrcIsSigned, 
+                                   const Type *Ty, bool DestIsSigned);
+
+  static Constant *getCast(Constant *C, const Type *Ty) {
+    return getInferredCast(C, C->getType()->isSigned(), Ty, Ty->isSigned());
+  }
 
   /// @brief Return true if this is a convert constant expression
   bool isCast() const;






More information about the llvm-commits mailing list