Delete some dead code.
[oota-llvm.git] / include / llvm / Constants.h
index a7480d2a8908039e3d483ee9de923790b6c9e3ec..43f625a68f609898b09a7673d8b38b3470c5b725 100644 (file)
@@ -316,16 +316,20 @@ public:
 
   /// getSequentialElement - If this CAZ has array or vector type, return a zero
   /// with the right element type.
-  Constant *getSequentialElement();
+  Constant *getSequentialElement() const;
 
   /// getStructElement - If this CAZ has struct type, return a zero with the
   /// right element type for the specified element.
-  Constant *getStructElement(unsigned Elt);
+  Constant *getStructElement(unsigned Elt) const;
 
   /// getElementValue - Return a zero of the right value for the specified GEP
   /// index.
-  Constant *getElementValue(Constant *C);
-  
+  Constant *getElementValue(Constant *C) const;
+
+  /// getElementValue - Return a zero of the right value for the specified GEP
+  /// index.
+  Constant *getElementValue(unsigned Idx) const;
+
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
   ///
   static bool classof(const ConstantAggregateZero *) { return true; }
@@ -354,6 +358,8 @@ public:
   /// of the array by one (you've been warned).  However, in some situations 
   /// this is not desired so if AddNull==false then the string is copied without
   /// null termination.
+  
+  // FIXME Remove this.
   static Constant *get(LLVMContext &Context, StringRef Initializer,
                        bool AddNull = true);
   
@@ -367,6 +373,9 @@ public:
     return reinterpret_cast<ArrayType*>(Value::getType());
   }
 
+  // FIXME: String methods will eventually be removed.
+  
+  
   /// isString - This method returns true if the array is an array of i8 and
   /// the elements of the array are all ConstantInt's.
   bool isString() const;
@@ -480,6 +489,10 @@ public:
   // ConstantVector accessors
   static Constant *get(ArrayRef<Constant*> V);
   
+  /// getSplat - Return a ConstantVector with the specified constant in each
+  /// element.
+  static Constant *getSplat(unsigned NumElts, Constant *Elt);
+  
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 
@@ -548,10 +561,13 @@ public:
 };
   
 //===----------------------------------------------------------------------===//
-/// ConstantDataSequential - A vector or array of data that contains no
-/// relocations, and whose element type is a simple 1/2/4/8-byte integer or
-/// float/double.  This is the common base class of ConstantDataArray and
-/// ConstantDataVector.
+/// ConstantDataSequential - A vector or array constant whose element type is a
+/// simple 1/2/4/8-byte integer or float/double, and whose elements are just
+/// simple data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
+/// operands because it stores all of the elements of the constant as densely
+/// packed data, instead of as Value*'s.
+///
+/// This is the common base class of ConstantDataArray and ConstantDataVector.
 ///
 class ConstantDataSequential : public Constant {
   friend class LLVMContextImpl;
@@ -568,7 +584,7 @@ class ConstantDataSequential : public Constant {
   ConstantDataSequential(const ConstantDataSequential &);    // DO NOT IMPLEMENT
 protected:
   explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data)
-    : Constant(ty, VT, 0, 0), DataElements(Data) {}
+    : Constant(ty, VT, 0, 0), DataElements(Data), Next(0) {}
   ~ConstantDataSequential() { delete Next; }
   
   static Constant *getImpl(StringRef Bytes, Type *Ty);
@@ -599,7 +615,7 @@ public:
   float getElementAsFloat(unsigned i) const;
   
   /// getElementAsDouble - If this is an sequential container of doubles, return
-  /// the specified element as a float.
+  /// the specified element as a double.
   double getElementAsDouble(unsigned i) const;
   
   /// getElementAsConstant - Return a Constant for a specified index's element.
@@ -616,12 +632,46 @@ public:
   
   /// getElementType - Return the element type of the array/vector.
   Type *getElementType() const;
+  
+  /// getNumElements - Return the number of elements in the array or vector.
+  unsigned getNumElements() const;
 
   /// getElementByteSize - Return the size (in bytes) of each element in the
   /// array/vector.  The size of the elements is known to be a multiple of one
   /// byte.
   uint64_t getElementByteSize() const;
 
+  
+  /// isString - This method returns true if this is an array of i8.
+  bool isString() const;
+  
+  /// isCString - This method returns true if the array "isString", ends with a
+  /// nul byte, and does not contains any other nul bytes.
+  bool isCString() const;
+  
+  /// getAsString - If this array is isString(), then this method returns the
+  /// array as a StringRef.  Otherwise, it asserts out.
+  ///
+  StringRef getAsString() const {
+    assert(isString() && "Not a string");
+    return getRawDataValues();
+  }
+  
+  /// getAsCString - If this array is isCString(), then this method returns the
+  /// array (without the trailing null byte) as a StringRef. Otherwise, it
+  /// asserts out.
+  ///
+  StringRef getAsCString() const {
+    assert(isCString() && "Isn't a C string");
+    StringRef Str = getAsString();
+    return Str.substr(0, Str.size()-1);
+  }
+  
+  /// getRawDataValues - Return the raw, underlying, bytes of this data.  Note
+  /// that this is an extremely tricky thing to work with, as it exposes the
+  /// host endianness of the data elements.
+  StringRef getRawDataValues() const;
+  
   virtual void destroyConstant();
   
   /// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -636,9 +686,11 @@ private:
 };
 
 //===----------------------------------------------------------------------===//
-/// ConstantDataArray - An array of data that contains no relocations, and whose
-/// element type is a simple 1/2/4/8-byte integer or float/double.
-///
+/// ConstantDataArray - An array constant whose element type is a simple
+/// 1/2/4/8-byte integer or float/double, and whose elements are just simple
+/// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
+/// operands because it stores all of the elements of the constant as densely
+/// packed data, instead of as Value*'s.
 class ConstantDataArray : public ConstantDataSequential {
   void *operator new(size_t, unsigned);            // DO NOT IMPLEMENT
   ConstantDataArray(const ConstantDataArray &);    // DO NOT IMPLEMENT
@@ -656,13 +708,21 @@ public:
   /// get() constructors - Return a constant with array type with an element
   /// count and element type matching the ArrayRef passed in.  Note that this
   /// can return a ConstantAggregateZero object.
-  static Constant *get(ArrayRef<uint8_t> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<uint16_t> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<uint32_t> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<uint64_t> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<float> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<double> Elts, LLVMContext &Context);
+  static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
   
+  /// getString - This method constructs a CDS and initializes it with a text
+  /// string. The default behavior (AddNull==true) causes a null terminator to
+  /// be placed at the end of the array (increasing the length of the string by
+  /// one more than the StringRef would normally indicate.  Pass AddNull=false
+  /// to disable this behavior.
+  static Constant *getString(LLVMContext &Context, StringRef Initializer,
+                             bool AddNull = true);
+
   /// getType - Specialize the getType() method to always return an ArrayType,
   /// which reduces the amount of casting needed in parts of the compiler.
   ///
@@ -679,9 +739,11 @@ public:
 };
   
 //===----------------------------------------------------------------------===//
-/// ConstantDataVector - A vector of data that contains no relocations, and
-/// whose element type is a simple 1/2/4/8-byte integer or float/double.
-///
+/// ConstantDataVector - A vector constant whose element type is a simple
+/// 1/2/4/8-byte integer or float/double, and whose elements are just simple
+/// data values (i.e. ConstantInt/ConstantFP).  This Constant node has no
+/// operands because it stores all of the elements of the constant as densely
+/// packed data, instead of as Value*'s.
 class ConstantDataVector : public ConstantDataSequential {
   void *operator new(size_t, unsigned);              // DO NOT IMPLEMENT
   ConstantDataVector(const ConstantDataVector &);    // DO NOT IMPLEMENT
@@ -699,12 +761,21 @@ public:
   /// get() constructors - Return a constant with vector type with an element
   /// count and element type matching the ArrayRef passed in.  Note that this
   /// can return a ConstantAggregateZero object.
-  static Constant *get(ArrayRef<uint8_t> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<uint16_t> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<uint32_t> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<uint64_t> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<float> Elts, LLVMContext &Context);
-  static Constant *get(ArrayRef<double> Elts, LLVMContext &Context);
+  static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<float> Elts);
+  static Constant *get(LLVMContext &Context, ArrayRef<double> Elts);
+  
+  /// getSplat - Return a ConstantVector with the specified constant in each
+  /// element.  The specified constant has to be a of a compatible type (i8/i16/
+  /// i32/i64/float/double) and must be a ConstantFP or ConstantInt.
+  static Constant *getSplat(unsigned NumElts, Constant *Elt);
+
+  /// getSplatValue - If this is a splat constant, meaning that all of the
+  /// elements have the same value, return that value. Otherwise return NULL.
+  Constant *getSplatValue() const;
   
   /// getType - Specialize the getType() method to always return a VectorType,
   /// which reduces the amount of casting needed in parts of the compiler.
@@ -1097,16 +1168,20 @@ public:
 
   /// getSequentialElement - If this Undef has array or vector type, return a
   /// undef with the right element type.
-  UndefValue *getSequentialElement();
+  UndefValue *getSequentialElement() const;
   
   /// getStructElement - If this undef has struct type, return a undef with the
   /// right element type for the specified element.
-  UndefValue *getStructElement(unsigned Elt);
+  UndefValue *getStructElement(unsigned Elt) const;
   
   /// getElementValue - Return an undef of the right value for the specified GEP
   /// index.
-  UndefValue *getElementValue(Constant *C);
-  
+  UndefValue *getElementValue(Constant *C) const;
+
+  /// getElementValue - Return an undef of the right value for the specified GEP
+  /// index.
+  UndefValue *getElementValue(unsigned Idx) const;
+
   virtual void destroyConstant();
 
   /// Methods for support type inquiry through isa, cast, and dyn_cast: