Constants.h revision 37eeaa729bc70258166a675ee00bbe95e608d519
148486893f46d2e12e926682a3ecb908716bc66c4Chris Lattner//===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===//
29769ab22265b313171d201b5928688524a01bd87Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
56fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// This file was developed by the LLVM research group and is distributed under
66fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// the University of Illinois Open Source License. See LICENSE.TXT for details.
79769ab22265b313171d201b5928688524a01bd87Misha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//
100b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// @file This file contains the declarations for the subclasses of Constant,
110b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// which represent the different flavors of constant values that live in LLVM.
120b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// Note that Constants are immutable (once created they never change) and are
130b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// fully shared by structural equivalence.  This means that two structurally
140b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// equivalent constants will always have the same address.  Constant's are
150b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// created on demand as needed and never deleted: thus clients don't have to
160b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// worry about the lifetime of the objects.
17009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//
18009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//===----------------------------------------------------------------------===//
19009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
2031bcdb822fe9133b1973de51519d34e5813a6184Chris Lattner#ifndef LLVM_CONSTANTS_H
2131bcdb822fe9133b1973de51519d34e5813a6184Chris Lattner#define LLVM_CONSTANTS_H
22009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
2331bcdb822fe9133b1973de51519d34e5813a6184Chris Lattner#include "llvm/Constant.h"
2452eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner#include "llvm/Type.h"
25532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer#include "llvm/ADT/APInt.h"
26009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
28d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
29009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass ArrayType;
30009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass StructType;
314cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattnerclass PointerType;
329d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencerclass VectorType;
33009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
346cc89aad25155ecd93b5318414851aa46351196dChris Lattnertemplate<class ConstantClass, class TypeClass, class ValType>
356cc89aad25155ecd93b5318414851aa46351196dChris Lattnerstruct ConstantCreator;
365133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattnertemplate<class ConstantClass, class TypeClass>
375133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattnerstruct ConvertConstantType;
385133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner
3986e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
4024d6da5fedcf39891f7d8c5b031c01324b3db545Reid Spencer/// This is the shared class of boolean and integer constants. This class
416b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// represents both boolean and integral constants.
426b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// @brief Class for constant integers.
436b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Shengclass ConstantInt : public Constant {
44d1afbd02ef9405fb5c1575bf1d3656f434c4a956Chris Lattner  static ConstantInt *TheTrueVal, *TheFalseVal;
456b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  ConstantInt(const ConstantInt &);      // DO NOT IMPLEMENT
46532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  ConstantInt(const IntegerType *Ty, const APInt& V);
47532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  APInt Val;
48994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattnerpublic:
49532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// Return the constant as an APInt value reference. This allows clients to
50532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// obtain a copy of the value, with all its precision in tact.
51532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// @brief Return the constant's value.
52532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  inline const APInt& getValue() const {
53532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer    return Val;
54532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  }
55532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer
560b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// Return the constant as a 64-bit unsigned integer value after it
57532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// has been zero extended as appropriate for the type of this constant. Note
58532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// that this method can assert if the value does not fit in 64 bits.
59532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// @deprecated
600b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Return the zero extended value.
61a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  inline uint64_t getZExtValue() const {
62532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer    return Val.getZExtValue();
63a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  }
64c2dfb8bb909b0ba08733be94821513aef9467fa0Chris Lattner
650b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// Return the constant as a 64-bit integer value after it has been sign
66532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// sign extended as appropriate for the type of this constant. Note that
67532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// this method can assert if the value does not fit in 64 bits.
68532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  /// @deprecated
696c6b6a77c0f68d5a41e94d8ef0b1093089e683faChris Lattner  /// @brief Return the sign extended value.
70a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  inline int64_t getSExtValue() const {
71532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer    return Val.getSExtValue();
72a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  }
73532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer
740b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// A helper method that can be used to determine if the constant contained
750b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// within is equal to a constant.  This only works for very small values,
760b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// because this is all that can be represented with all types.
770b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if this constant's value is same as an unsigned char.
78532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer  bool equalsInt(uint64_t V) const {
79b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return Val == V;
802ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner  }
812ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner
826b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// getTrue/getFalse - Return the singleton true/false values.
836b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  static inline ConstantInt *getTrue() {
84d1afbd02ef9405fb5c1575bf1d3656f434c4a956Chris Lattner    if (TheTrueVal) return TheTrueVal;
85d1afbd02ef9405fb5c1575bf1d3656f434c4a956Chris Lattner    return CreateTrueFalseVals(true);
866b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  }
876b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  static inline ConstantInt *getFalse() {
88d1afbd02ef9405fb5c1575bf1d3656f434c4a956Chris Lattner    if (TheFalseVal) return TheFalseVal;
89d1afbd02ef9405fb5c1575bf1d3656f434c4a956Chris Lattner    return CreateTrueFalseVals(false);
906b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  }
916b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng
92a0098386741949065f099b940819201f73cd86c2Reid Spencer  /// Return a ConstantInt with the specified value for the specified type. The
930050c737c549b89f5df6743dc81646a3b7f4a94fReid Spencer  /// value V will be canonicalized to a an unsigned APInt. Accessing it with
940050c737c549b89f5df6743dc81646a3b7f4a94fReid Spencer  /// either getSExtValue() or getZExtValue() will yield a correctly sized and
950050c737c549b89f5df6743dc81646a3b7f4a94fReid Spencer  /// signed value for the type Ty.
960b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Get a ConstantInt for a specific value.
970050c737c549b89f5df6743dc81646a3b7f4a94fReid Spencer  static ConstantInt *get(const Type *Ty, uint64_t V);
980b5a504d105514178c80b886321221fbe5ac1131Reid Spencer
99f57fc81faebf3eb81fb30fe17c4295d46060e03fReid Spencer  /// Return a ConstantInt with the specified value and an implied Type. The
100f57fc81faebf3eb81fb30fe17c4295d46060e03fReid Spencer  /// type is the integer type that corresponds to the bit width of the value.
101f57fc81faebf3eb81fb30fe17c4295d46060e03fReid Spencer  static ConstantInt *get(const APInt &V);
102f57fc81faebf3eb81fb30fe17c4295d46060e03fReid Spencer
103c10305743c313558405079452138f03124e87581Reid Spencer  /// getType - Specialize the getType() method to always return an IntegerType,
104c10305743c313558405079452138f03124e87581Reid Spencer  /// which reduces the amount of casting needed in parts of the compiler.
105c10305743c313558405079452138f03124e87581Reid Spencer  ///
106c10305743c313558405079452138f03124e87581Reid Spencer  inline const IntegerType *getType() const {
107c10305743c313558405079452138f03124e87581Reid Spencer    return reinterpret_cast<const IntegerType*>(Value::getType());
108c10305743c313558405079452138f03124e87581Reid Spencer  }
109c10305743c313558405079452138f03124e87581Reid Spencer
1100b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This static method returns true if the type Ty is big enough to
1110b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// represent the value V. This can be used to avoid having the get method
1126d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// assert when V is larger than Ty can represent. Note that there are two
1136d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// versions of this method, one for unsigned and one for signed integers.
1146d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// Although ConstantInt canonicalizes everything to an unsigned integer,
1156d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// the signed version avoids callers having to convert a signed quantity
1166d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// to the appropriate unsigned type before calling the method.
1170b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if V is a valid value for type Ty
1180b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if the value is in range for the given type.
1199b11d518aef8e191e5e94f3503dfddbe1c0a387aReid Spencer  static bool isValueValidForType(const Type *Ty, uint64_t V);
120009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  static bool isValueValidForType(const Type *Ty, int64_t V);
12193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner
1226b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// This function will return true iff this constant represents the "null"
1236b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// value that would be returned by the getNullValue method.
124b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// @returns true if this is the null integer value.
1256b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Determine if the value is null.
1266b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  virtual bool isNullValue() const {
1276b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    return Val == 0;
1286b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  }
1295ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
13037eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer  /// This is just a convenience method to make client code smaller for a
13137eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer  /// common case.
13237eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer  /// @brief Determine if the value is one.
13337eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer  virtual bool isUnitValue() const {
13437eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer    return Val == 1;
13537eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer  }
13637eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer
1376b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// This function will return true iff every bit in this constant is set
1386b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// to true.
1390b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true iff this constant's bits are all set to true.
1406b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Determine if the value is all ones.
141579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer  bool isAllOnesValue() const {
142532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer    return Val.isAllOnesValue();
1436b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  }
1441680312867fffeb9369800949b809e0b9e29a914Chris Lattner
1456b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// This function will return true iff this constant represents the largest
1466b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// value that may be represented by the constant's type.
1470b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true iff this is the largest value that may be represented
1480b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// by this type.
1496b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Determine if the value is maximal.
150579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer  bool isMaxValue(bool isSigned) const {
151532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer    if (isSigned)
152532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer      return Val.isMaxSignedValue();
153532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer    else
154532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer      return Val.isMaxValue();
155994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  }
156994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
1576b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// This function will return true iff this constant represents the smallest
1586b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// value that may be represented by this constant's type.
1590b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if this is the smallest value that may be represented by
1600b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// this type.
1616b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Determine if the value is minimal.
162579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer  bool isMinValue(bool isSigned) const {
163532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer    if (isSigned)
164532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer      return Val.isMinSignedValue();
165532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer    else
166532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer      return Val.isMinValue();
167994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  }
168994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
1696b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @returns the value for an integer constant of the given type that has all
1706b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// its bits set to true.
1716b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Get the all ones value
1726b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  static ConstantInt *getAllOnesValue(const Type *Ty);
1736b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng
174b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
175b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  static inline bool classof(const ConstantInt *) { return true; }
17652eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
177b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return V->getValueType() == ConstantIntVal;
1785ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
179d1afbd02ef9405fb5c1575bf1d3656f434c4a956Chris Lattner  static void ResetTrueFalse() { TheTrueVal = TheFalseVal = 0; }
180d1afbd02ef9405fb5c1575bf1d3656f434c4a956Chris Lattnerprivate:
181d1afbd02ef9405fb5c1575bf1d3656f434c4a956Chris Lattner  static ConstantInt *CreateTrueFalseVals(bool WhichOne);
182009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
183009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
184009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
18586e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
18693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantFP - Floating Point Values [float, double]
18793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
188e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantFP : public Constant {
189009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  double Val;
190e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantFP(const ConstantFP &);      // DO NOT IMPLEMENT
1913e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
192e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantFP(const Type *Ty, double V);
193009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
19493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
195e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static ConstantFP *get(const Type *Ty, double V);
196009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
19793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isValueValidForType - return true if Ty is big enough to represent V.
198009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  static bool isValueValidForType(const Type *Ty, double V);
199009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  inline double getValue() const { return Val; }
2005ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
20193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
202cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  /// getNullValue.  Don't depend on == for doubles to tell us it's zero, it
203cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  /// considers -0.0 to be null as well as 0.0.  :(
2043a1eff732b36a663cdb9f07f4a9ccae6452eadcbJim Laskey  virtual bool isNullValue() const;
2050eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
206f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// isExactlyValue - We don't rely on operator== working on double values, as
207f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
208f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// As such, this method can be used to do an exact bit-for-bit comparison of
209f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// two floating point values.
2103a1eff732b36a663cdb9f07f4a9ccae6452eadcbJim Laskey  bool isExactlyValue(double V) const;
211f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner
21293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
213e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantFP *) { return true; }
21452eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
215225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantFPVal;
2165ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
217009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
218009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
21986e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
22040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// ConstantAggregateZero - All zero aggregate value
22140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner///
22240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerclass ConstantAggregateZero : public Constant {
22340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
22440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  ConstantAggregateZero(const ConstantAggregateZero &);      // DO NOT IMPLEMENT
22540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerprotected:
22652eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  ConstantAggregateZero(const Type *Ty)
2275181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner    : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
22840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerpublic:
22940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// get() - static factory method for creating a null aggregate.  It is
23040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// illegal to call this method with a non-aggregate type.
23140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  static Constant *get(const Type *Ty);
23240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
23340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
23440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.
23540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual bool isNullValue() const { return true; }
23640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
23740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual void destroyConstant();
23840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
23940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
24040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  ///
24152eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const ConstantAggregateZero *) { return true; }
24252eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
24352eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner    return V->getValueType() == ConstantAggregateZeroVal;
24440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  }
24540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner};
24640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
247009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
24886e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
24993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantArray - Constant Array Declarations
25093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
251e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantArray : public Constant {
2526cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantArray, ArrayType,
2536cc89aad25155ecd93b5318414851aa46351196dChris Lattner                                    std::vector<Constant*> >;
254e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantArray(const ConstantArray &);      // DO NOT IMPLEMENT
2553e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
256697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner  ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
2575181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ~ConstantArray();
258009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
25993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
260ca705fa31d53469d2e6d0e52fa9e40d3e13a088aChris Lattner  static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
261df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner  static Constant *get(const ArrayType *T,
262df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner                       Constant*const*Vals, unsigned NumVals) {
263df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner    // FIXME: make this the primary ctor method.
264df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner    return get(T, std::vector<Constant*>(Vals, Vals+NumVals));
265df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner  }
266efcaa42c282ae6c6ba9652c48738c334878afbc6Reid Spencer
267efcaa42c282ae6c6ba9652c48738c334878afbc6Reid Spencer  /// This method constructs a ConstantArray and initializes it with a text
268461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// string. The default behavior (AddNull==true) causes a null terminator to
269461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// be placed at the end of the array. This effectively increases the length
270461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// of the array by one (you've been warned).  However, in some situations
271461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// this is not desired so if AddNull==false then the string is copied without
272461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// null termination.
273461bed2b753c514ac15ff824befe585988408f45Reid Spencer  static Constant *get(const std::string &Initializer, bool AddNull = true);
2749769ab22265b313171d201b5928688524a01bd87Misha Brukman
27593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getType - Specialize the getType() method to always return an ArrayType,
27693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// which reduces the amount of casting needed in parts of the compiler.
27793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  ///
278682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  inline const ArrayType *getType() const {
2798b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner    return reinterpret_cast<const ArrayType*>(Value::getType());
280682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  }
281009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
2829b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// isString - This method returns true if the array is an array of sbyte or
2839b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// ubyte, and if the elements of the array are all ConstantInt's.
2849b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  bool isString() const;
2859b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner
28622c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// isCString - This method returns true if the array is a string (see
28722c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// isString) and it ends in a null byte \0 and does not contains any other
28822c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// null bytes except its terminator.
28922c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  bool isCString() const;
29022c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng
2919b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// getAsString - If this array is isString(), then this method converts the
2929b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// array to an std::string and returns it.  Otherwise, it asserts out.
29393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  ///
29493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  std::string getAsString() const;
29593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner
29693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
29740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.  This always returns false because zero arrays are always
29840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// created as ConstantAggregateZero objects.
29940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual bool isNullValue() const { return false; }
3000eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
301e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
30240cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
303e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner
30493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
305e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantArray *) { return true; }
30652eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
307225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantArrayVal;
3085ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
309009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
310009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
311009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
31286e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
313e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner// ConstantStruct - Constant Struct Declarations
314009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//
315e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantStruct : public Constant {
3166cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantStruct, StructType,
3176cc89aad25155ecd93b5318414851aa46351196dChris Lattner                                    std::vector<Constant*> >;
318e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
3193e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
320697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner  ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
3215181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ~ConstantStruct();
322009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
32393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
324c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner  ///
325ca705fa31d53469d2e6d0e52fa9e40d3e13a088aChris Lattner  static Constant *get(const StructType *T, const std::vector<Constant*> &V);
326df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner  static Constant *get(const std::vector<Constant*> &V, bool Packed = false);
327df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner  static Constant *get(Constant*const* Vals, unsigned NumVals,
328df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner                       bool Packed = false) {
329df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner    // FIXME: make this the primary ctor method.
330df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner    return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
331df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner  }
332df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner
33393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getType() specialization - Reduce amount of casting...
334c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner  ///
335682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  inline const StructType *getType() const {
3368b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner    return reinterpret_cast<const StructType*>(Value::getType());
337682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  }
338009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
33993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
34040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.  This always returns false because zero structs are always
34140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// created as ConstantAggregateZero objects.
342a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner  virtual bool isNullValue() const {
34340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner    return false;
344a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner  }
3450eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
346e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
34740cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
3489769ab22265b313171d201b5928688524a01bd87Misha Brukman
34993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
350e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantStruct *) { return true; }
35152eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
352225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantStructVal;
3535ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
354009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
355009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
35686e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
3579d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer/// ConstantVector - Constant Vector Declarations
358715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke///
3599d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencerclass ConstantVector : public Constant {
3609d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  friend struct ConstantCreator<ConstantVector, VectorType,
361715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke                                    std::vector<Constant*> >;
3629d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  ConstantVector(const ConstantVector &);      // DO NOT IMPLEMENT
363715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeprotected:
3649d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
3659d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  ~ConstantVector();
366715c90ba524e736190a6380695ab337eeb5148beBrian Gaekepublic:
367715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// get() - Static factory methods - Return objects of the specified value
3689d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  static Constant *get(const VectorType *T, const std::vector<Constant*> &);
369715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static Constant *get(const std::vector<Constant*> &V);
370df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner  static Constant *get(Constant*const* Vals, unsigned NumVals) {
371df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner    // FIXME: make this the primary ctor method.
372df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner    return get(std::vector<Constant*>(Vals, Vals+NumVals));
373df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner  }
374df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner
3759d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  /// getType - Specialize the getType() method to always return an VectorType,
376715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// which reduces the amount of casting needed in parts of the compiler.
377715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  ///
3789d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  inline const VectorType *getType() const {
3799d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer    return reinterpret_cast<const VectorType*>(Value::getType());
380715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  }
381715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
38258513aa1c22a08118734ac799d935ea2910db35aChris Lattner  /// @returns the value for an packed integer constant of the given type that
38358513aa1c22a08118734ac799d935ea2910db35aChris Lattner  /// has all its bits set to true.
38458513aa1c22a08118734ac799d935ea2910db35aChris Lattner  /// @brief Get the all ones value
3859d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  static ConstantVector *getAllOnesValue(const VectorType *Ty);
38658513aa1c22a08118734ac799d935ea2910db35aChris Lattner
387715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// isNullValue - Return true if this is the value that would be returned by
388715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// getNullValue.  This always returns false because zero arrays are always
389715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// created as ConstantAggregateZero objects.
390715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  virtual bool isNullValue() const { return false; }
391715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
392fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey  /// This function will return true iff every element in this packed constant
393fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey  /// is set to all ones.
394fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey  /// @returns true iff this constant's emements are all set to all ones.
395fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey  /// @brief Determine if the value is all ones.
396569cc890e8822c265cec66745791edbd510dac1cJim Laskey  bool isAllOnesValue() const;
397fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey
398715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  virtual void destroyConstant();
39940cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
400715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
401715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// Methods for support type inquiry through isa, cast, and dyn_cast:
4029d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer  static inline bool classof(const ConstantVector *) { return true; }
403715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static bool classof(const Value *V) {
4049d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer    return V->getValueType() == ConstantVectorVal;
405715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  }
406715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke};
407715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
40886e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
40993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantPointerNull - a constant pointer value that points to null
41093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
41148babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattnerclass ConstantPointerNull : public Constant {
4126cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
413e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
4145ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerprotected:
41548babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattner  ConstantPointerNull(const PointerType *T)
4165181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner    : Constant(reinterpret_cast<const Type*>(T),
417225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner               Value::ConstantPointerNullVal, 0, 0) {}
4186cc89aad25155ecd93b5318414851aa46351196dChris Lattner
4195ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerpublic:
4205ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
42193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
422e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static ConstantPointerNull *get(const PointerType *T);
4235ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
42493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
42593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getNullValue.
4260eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner  virtual bool isNullValue() const { return true; }
4270eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
428e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
429e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner
4300f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  /// getType - Specialize the getType() method to always return an PointerType,
4310f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  /// which reduces the amount of casting needed in parts of the compiler.
4320f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  ///
4330f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  inline const PointerType *getType() const {
4340f42ba67771627453187e44fea935d6bab7a8152Chris Lattner    return reinterpret_cast<const PointerType*>(Value::getType());
4350f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  }
4360f42ba67771627453187e44fea935d6bab7a8152Chris Lattner
43793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
438e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantPointerNull *) { return true; }
43952eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
440225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantPointerNullVal;
4415ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
4424cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner};
4434cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner
444f4ba6c710c298fe9b492b9cde82ce5efd46afd5dChris Lattner
44586e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// ConstantExpr - a constant value that is initialized with an expression using
446eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// other constant values.
44786e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner///
448eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// This class uses the standard Instruction opcodes to define the various
449eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// constant expressions.  The Opcode field for the ConstantExpr class is
450eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// maintained in the Value::SubclassData field.
45129ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adveclass ConstantExpr : public Constant {
4526cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantExpr,Type,
4536cc89aad25155ecd93b5318414851aa46351196dChris Lattner                            std::pair<unsigned, std::vector<Constant*> > >;
4545133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  friend struct ConvertConstantType<ConstantExpr, Type>;
4559769ab22265b313171d201b5928688524a01bd87Misha Brukman
4566cc89aad25155ecd93b5318414851aa46351196dChris Lattnerprotected:
4575181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
458eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner    : Constant(Ty, ConstantExprVal, Ops, NumOps) {
459eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner    // Operation type (an Instruction opcode) is stored as the SubclassData.
4609769ab22265b313171d201b5928688524a01bd87Misha Brukman    SubclassData = Opcode;
461eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner  }
4625133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner
4635133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  // These private methods are used by the type resolution code to create
4645133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  // ConstantExprs in intermediate forms.
4655133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  static Constant *getTy(const Type *Ty, unsigned Opcode,
46690fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer                         Constant *C1, Constant *C2);
467e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer  static Constant *getCompareTy(unsigned short pred, Constant *C1,
468e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer                                Constant *C2);
46946a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  static Constant *getSelectTy(const Type *Ty,
47046a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner                               Constant *C1, Constant *C2, Constant *C3);
4715133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
472fb11053815ee4b3c6593c12aff06fefea96d7d0aChris Lattner                                      Value* const *Idxs, unsigned NumIdxs);
47349b78a569609881811d905960baa7dd1ab801383Robert Bocchino  static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
47449b78a569609881811d905960baa7dd1ab801383Robert Bocchino                                       Constant *Idx);
475f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino  static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
476f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino                                      Constant *Elt, Constant *Idx);
4779fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
4789fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner                                      Constant *V2, Constant *Mask);
4799769ab22265b313171d201b5928688524a01bd87Misha Brukman
48029ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Advepublic:
481fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner  // Static methods to construct a ConstantExpr of different kinds.  Note that
482baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // these methods may return a object that is not an instance of the
483baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // ConstantExpr class, because they will attempt to fold the constant
484baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // expression into something simpler if possible.
4859769ab22265b313171d201b5928688524a01bd87Misha Brukman
48693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Cast constant expr
4875133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  ///
488d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getTrunc   (Constant *C, const Type *Ty);
489d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getSExt    (Constant *C, const Type *Ty);
490d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getZExt    (Constant *C, const Type *Ty);
491d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getFPTrunc (Constant *C, const Type *Ty);
492d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getFPExtend(Constant *C, const Type *Ty);
493d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getUIToFP  (Constant *C, const Type *Ty);
494d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getSIToFP  (Constant *C, const Type *Ty);
495d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getFPToUI  (Constant *C, const Type *Ty);
496d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getFPToSI  (Constant *C, const Type *Ty);
497d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getPtrToInt(Constant *C, const Type *Ty);
498d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getIntToPtr(Constant *C, const Type *Ty);
499d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getBitCast (Constant *C, const Type *Ty);
5003da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer
5013da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  // @brief Convenience function for getting one of the casting operations
5023da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  // using a CastOps opcode.
5033da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  static Constant *getCast(
5043da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer    unsigned ops,  ///< The opcode for the conversion
5053da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer    Constant *C,   ///< The constant to be converted
5063da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer    const Type *Ty ///< The type to which the constant is converted
5073da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  );
5083da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer
509848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  // @brief Create a ZExt or BitCast cast constant expression
510848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  static Constant *getZExtOrBitCast(
511848414e49c7600e3002a4366de52d03a9638b327Reid Spencer    Constant *C,   ///< The constant to zext or bitcast
512848414e49c7600e3002a4366de52d03a9638b327Reid Spencer    const Type *Ty ///< The type to zext or bitcast C to
513848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  );
514848414e49c7600e3002a4366de52d03a9638b327Reid Spencer
515848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  // @brief Create a SExt or BitCast cast constant expression
516848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  static Constant *getSExtOrBitCast(
51790fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer    Constant *C,   ///< The constant to sext or bitcast
51890fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer    const Type *Ty ///< The type to sext or bitcast C to
519848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  );
520848414e49c7600e3002a4366de52d03a9638b327Reid Spencer
521848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  // @brief Create a Trunc or BitCast cast constant expression
522848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  static Constant *getTruncOrBitCast(
52390fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer    Constant *C,   ///< The constant to trunc or bitcast
52490fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer    const Type *Ty ///< The type to trunc or bitcast C to
525848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  );
526848414e49c7600e3002a4366de52d03a9638b327Reid Spencer
527887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer  /// @brief Create a BitCast or a PtrToInt cast constant expression
528887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer  static Constant *getPointerCast(
529887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer    Constant *C,   ///< The pointer value to be casted (operand 0)
530887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer    const Type *Ty ///< The type to which cast should be made
531887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer  );
532887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer
53384f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
53484f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  static Constant *getIntegerCast(
53584f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    Constant *C,    ///< The integer constant to be casted
53684f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    const Type *Ty, ///< The integer type to cast to
53784f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    bool isSigned   ///< Whether C should be treated as signed or not
53884f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  );
53984f3eab017d56b6854155f2350759dc77ac48aadReid Spencer
54084f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
54184f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  static Constant *getFPCast(
54284f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    Constant *C,    ///< The integer constant to be casted
54384f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    const Type *Ty ///< The integer type to cast to
54484f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  );
54584f3eab017d56b6854155f2350759dc77ac48aadReid Spencer
5463da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  /// @brief Return true if this is a convert constant expression
5473da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  bool isCast() const;
5483da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer
5494b94f49091be8e26ce6e49db1268458995299b82Reid Spencer  /// @brief Return true if this is a compare constant expression
5504b94f49091be8e26ce6e49db1268458995299b82Reid Spencer  bool isCompare() const;
5514b94f49091be8e26ce6e49db1268458995299b82Reid Spencer
55246a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  /// Select constant expr
55346a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  ///
55446a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
55546a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner    return getSelectTy(V1->getType(), C, V1, V2);
55646a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  }
55746a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner
5587be2a120659cc61e554b04815ed3f1d4f234ecafAlkis Evlogimenos  /// getSizeOf constant expr - computes the size of a type in a target
559b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// independent way (Note: the return type is a ULong).
56060ab1402981a757c5ee785de540a5d0f85839c5dAlkis Evlogimenos  ///
56160ab1402981a757c5ee785de540a5d0f85839c5dAlkis Evlogimenos  static Constant *getSizeOf(const Type *Ty);
56246a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner
5637e208904ae8eeef888c3a6eecd38daa779ca36c9Chris Lattner  /// ConstantExpr::get - Return a binary or shift operator constant expression,
5647e208904ae8eeef888c3a6eecd38daa779ca36c9Chris Lattner  /// folding if possible.
5655133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  ///
56690fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer  static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
56790fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer
568887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer  /// @brief Return an ICmp or FCmp comparison operator constant expression.
569e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer  static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
570e8e4605021141d689493132a9c7c6fce6294937fChris Lattner
5714dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  /// ConstantExpr::get* - Return some common constants without having to
5724dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  /// specify the full Instruction::OPCODE identifier.
5734dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  ///
5744dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getNeg(Constant *C);
5754dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getNot(Constant *C);
5764dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getAdd(Constant *C1, Constant *C2);
5774dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSub(Constant *C1, Constant *C2);
5784dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getMul(Constant *C1, Constant *C2);
5791628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getUDiv(Constant *C1, Constant *C2);
5801628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getSDiv(Constant *C1, Constant *C2);
5811628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getFDiv(Constant *C1, Constant *C2);
5820a783f783ca05c961234385f5b269d4cf03dbbdbReid Spencer  static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
5830a783f783ca05c961234385f5b269d4cf03dbbdbReid Spencer  static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
5840a783f783ca05c961234385f5b269d4cf03dbbdbReid Spencer  static Constant *getFRem(Constant *C1, Constant *C2);
5854dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getAnd(Constant *C1, Constant *C2);
5864dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getOr(Constant *C1, Constant *C2);
5874dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getXor(Constant *C1, Constant *C2);
588728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS);
589728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS);
5904dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getShl(Constant *C1, Constant *C2);
5913822ff5c71478c7c90a50ca57045fb676fcb5005Reid Spencer  static Constant *getLShr(Constant *C1, Constant *C2);
5923822ff5c71478c7c90a50ca57045fb676fcb5005Reid Spencer  static Constant *getAShr(Constant *C1, Constant *C2);
59302140b025d821ca8cefe5086f90f4d8e0c52ae5bChris Lattner
5947fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  /// Getelementptr form.  std::vector<Value*> is only accepted for convenience:
5957fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  /// all elements must be Constant's.
5965133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  ///
597fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner  static Constant *getGetElementPtr(Constant *C,
598fb11053815ee4b3c6593c12aff06fefea96d7d0aChris Lattner                                    Constant* const *IdxList, unsigned NumIdx);
5997fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  static Constant *getGetElementPtr(Constant *C,
600fb11053815ee4b3c6593c12aff06fefea96d7d0aChris Lattner                                    Value* const *IdxList, unsigned NumIdx);
601df7490a27323f194b63db75c0b16708fc7c6cfbeChris Lattner
6029fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getExtractElement(Constant *Vec, Constant *Idx);
6039fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
6049fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
605728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer
60624d6da5fedcf39891f7d8c5b031c01324b3db545Reid Spencer  /// Floating point negation must be implemented with f(x) = -0.0 - x. This
60724d6da5fedcf39891f7d8c5b031c01324b3db545Reid Spencer  /// method returns the negative zero constant for floating point or packed
60824d6da5fedcf39891f7d8c5b031c01324b3db545Reid Spencer  /// floating point types; for all other types, it returns the null value.
60924d6da5fedcf39891f7d8c5b031c01324b3db545Reid Spencer  static Constant *getZeroValueForNegationExpr(const Type *Ty);
61024d6da5fedcf39891f7d8c5b031c01324b3db545Reid Spencer
61193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
61293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getNullValue.
61329ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  virtual bool isNullValue() const { return false; }
6149769ab22265b313171d201b5928688524a01bd87Misha Brukman
61593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getOpcode - Return the opcode at the root of this constant expression
616eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner  unsigned getOpcode() const { return SubclassData; }
61729ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve
618728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
619728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  /// not an ICMP or FCMP constant expression.
620728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  unsigned getPredicate() const;
621728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer
62293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getOpcodeName - Return a string representation for an opcode.
623e8e4605021141d689493132a9c7c6fce6294937fChris Lattner  const char *getOpcodeName() const;
6249769ab22265b313171d201b5928688524a01bd87Misha Brukman
62579ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  /// getWithOperandReplaced - Return a constant expression identical to this
62679ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  /// one, but with the specified operand set to the specified value.
62779ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
62879ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner
6296b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// getWithOperands - This returns the current constant expression with the
6306b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// operands replaced with the specified values.  The specified operands must
6316b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// match count and type with the existing ones.
6326b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
63379ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner
634e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
63540cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
6369769ab22265b313171d201b5928688524a01bd87Misha Brukman
63717aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  /// Override methods to provide more type information...
6389769ab22265b313171d201b5928688524a01bd87Misha Brukman  inline Constant *getOperand(unsigned i) {
63917aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner    return cast<Constant>(User::getOperand(i));
64017aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  }
64117aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  inline Constant *getOperand(unsigned i) const {
64217aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner    return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
64317aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  }
6449769ab22265b313171d201b5928688524a01bd87Misha Brukman
64517aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner
64693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
64729ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  static inline bool classof(const ConstantExpr *) { return true; }
64829ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  static inline bool classof(const Value *V) {
64952eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner    return V->getValueType() == ConstantExprVal;
65029ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  }
65129ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve};
65229ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve
653e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
654e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner//===----------------------------------------------------------------------===//
655e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// UndefValue - 'undef' values are things that do not have specified contents.
656e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// These are used for a variety of purposes, including global variable
657e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// initializers and operands to instructions.  'undef' values can occur with
658e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// any type.
659e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner///
660e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerclass UndefValue : public Constant {
661e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  friend struct ConstantCreator<UndefValue, Type, char>;
662e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
663e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerprotected:
6645181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
665e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerpublic:
666e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// get() - Static factory methods - Return an 'undef' object of the specified
667e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// type.
668e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  ///
669e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static UndefValue *get(const Type *T);
670e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
671e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
672e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// getNullValue.
673e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  virtual bool isNullValue() const { return false; }
674e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
675e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  virtual void destroyConstant();
676e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
677e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
678e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static inline bool classof(const UndefValue *) { return true; }
679e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static bool classof(const Value *V) {
680e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner    return V->getValueType() == UndefValueVal;
681e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  }
682e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner};
683e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
684d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
685d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
686009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif
687