Support Composite's, not just structs
authorChris Lattner <sabre@nondot.org>
Mon, 26 Nov 2001 17:00:13 +0000 (17:00 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 26 Nov 2001 17:00:13 +0000 (17:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1344 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/TransformInternals.h

index 7797ed15ead6c627d987c61a6585740e13cccd00..8edeffc82e199f0befa5a1dff4ec9ef3d7f765d6 100644 (file)
@@ -12,6 +12,7 @@
 #include "llvm/Instruction.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/ConstPoolVals.h"
 #include <map>
 #include <set>
 
 //
 extern const TargetData TD;
 
-// losslessCastableTypes - Return true if the types are bitwise equivalent.
-// This predicate returns true if it is possible to cast from one type to
-// another without gaining or losing precision, or altering the bits in any way.
-//
-bool losslessCastableTypes(const Type *T1, const Type *T2);
+static int getConstantValue(const ConstPoolInt *CPI) {
+  if (const ConstPoolSInt *CSI = dyn_cast<ConstPoolSInt>(CPI))
+    return CSI->getValue();
+  return cast<ConstPoolUInt>(CPI)->getValue();
+}
 
 
 // isFirstClassType - Return true if a value of the specified type can be held
@@ -37,12 +38,12 @@ static inline bool isFirstClassType(const Type *Ty) {
   return Ty->isPrimitiveType() || Ty->isPointerType();
 }
 
-// getPointedToStruct - If the argument is a pointer type, and the pointed to
-// value is a struct type, return the struct type, else return null.
+// getPointedToComposite - If the argument is a pointer type, and the pointed to
+// value is a composite type, return the composite type, else return null.
 //
-static inline const StructType *getPointedToStruct(const Type *Ty) {
+static inline const CompositeType *getPointedToComposite(const Type *Ty) {
   const PointerType *PT = dyn_cast<PointerType>(Ty);
-  return PT ? dyn_cast<StructType>(PT->getValueType()) : 0;
+  return PT ? dyn_cast<CompositeType>(PT->getValueType()) : 0;
 }
 
 
@@ -60,6 +61,19 @@ void ReplaceInstWithInst(BasicBlock::InstListType &BIL,
                          BasicBlock::iterator &BI, Instruction *I);
 
 
+// ConvertableToGEP - This function returns true if the specified value V is
+// a valid index into a pointer of type Ty.  If it is valid, Idx is filled in
+// with the values that would be appropriate to make this a getelementptr
+// instruction.  The type returned is the root type that the GEP would point
+// to if it were synthesized with this operands.
+//
+// If BI is nonnull, cast instructions are inserted as appropriate for the
+// arguments of the getelementptr.
+//
+const Type *ConvertableToGEP(const Type *Ty, Value *V, vector<Value*> &Indices,
+                             BasicBlock::iterator *BI = 0);
+
+
 // ------------- Expression Conversion ---------------------
 
 typedef map<const Value*, const Type*>         ValueTypeCache;
@@ -81,11 +95,11 @@ struct ValueMapCache {
 bool ExpressionConvertableToType(Value *V, const Type *Ty, ValueTypeCache &Map);
 Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC);
 
-// RetValConvertableToType - Return true if it is possible
-bool RetValConvertableToType(Value *V, const Type *Ty,
-                             ValueTypeCache &ConvertedTypes);
+// ValueConvertableToType - Return true if it is possible
+bool ValueConvertableToType(Value *V, const Type *Ty,
+                            ValueTypeCache &ConvertedTypes);
 
-void ConvertUsersType(Value *V, Value *NewVal, ValueMapCache &VMC);
+void ConvertValueToNewType(Value *V, Value *NewVal, ValueMapCache &VMC);
 
 
 //===----------------------------------------------------------------------===//
@@ -128,7 +142,7 @@ public:
 // false if you want a leaf
 //
 const Type *getStructOffsetType(const Type *Ty, unsigned &Offset,
-                                vector<ConstPoolVal*> &Offsets,
+                                vector<Value*> &Offsets,
                                 bool StopEarly = true);
 
 #endif