Constants.h revision 569cc890e8822c265cec66745791edbd510dac1c
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"
25009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
26d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
28009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass ArrayType;
29009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass StructType;
304cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattnerclass PointerType;
31715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeclass PackedType;
32009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
336cc89aad25155ecd93b5318414851aa46351196dChris Lattnertemplate<class ConstantClass, class TypeClass, class ValType>
346cc89aad25155ecd93b5318414851aa46351196dChris Lattnerstruct ConstantCreator;
355133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattnertemplate<class ConstantClass, class TypeClass>
365133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattnerstruct ConvertConstantType;
375133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner
3886e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
396b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// This is the shared class of boolean and integrer constants. This class
406b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// represents both boolean and integral constants.
416b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// @brief Class for constant integers.
426b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Shengclass ConstantInt : public Constant {
43994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattnerprotected:
44b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  uint64_t Val;
456b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Shengprotected:
466b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  ConstantInt(const ConstantInt &);      // DO NOT IMPLEMENT
476b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  ConstantInt(const Type *Ty, uint64_t V);
486b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  ConstantInt(const Type *Ty, int64_t V);
496b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  ConstantInt(bool V);
506b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
51994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattnerpublic:
520b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// Return the constant as a 64-bit unsigned integer value after it
530b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// has been zero extended as appropriate for the type of this constant.
540b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Return the zero extended value.
55a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  inline uint64_t getZExtValue() const {
56b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return Val;
57a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  }
58c2dfb8bb909b0ba08733be94821513aef9467fa0Chris Lattner
590b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// Return the constant as a 64-bit integer value after it has been sign
600b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// sign extended as appropriate for the type of this constant.
616c6b6a77c0f68d5a41e94d8ef0b1093089e683faChris Lattner  /// @brief Return the sign extended value.
62a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  inline int64_t getSExtValue() const {
63a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner    unsigned Size = getType()->getPrimitiveSizeInBits();
64b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return (int64_t(Val) << (64-Size)) >> (64-Size);
65a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  }
660b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// A helper method that can be used to determine if the constant contained
670b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// within is equal to a constant.  This only works for very small values,
680b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// because this is all that can be represented with all types.
690b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if this constant's value is same as an unsigned char.
70f98e88f7453df864a56bda6ca19cf70e09bf3e6eChris Lattner  bool equalsInt(unsigned char V) const {
713e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattner    assert(V <= 127 &&
72049c48f1adf5cd7862cc4a48a3d3935a0e98ebb0Misha Brukman           "equalsInt: Can only be used with very small positive constants!");
73b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return Val == V;
742ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner  }
752ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner
766b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// getTrue/getFalse - Return the singleton true/false values.
776b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  static inline ConstantInt *getTrue() {
786b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    static ConstantInt *T = 0;
796b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    if (T) return T;
806b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    return T = new ConstantInt(true);
816b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  }
826b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  static inline ConstantInt *getFalse() {
836b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    static ConstantInt *F = 0;
846b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    if (F) return F;
856b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    return F = new ConstantInt(false);
866b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  }
876b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng
88a0098386741949065f099b940819201f73cd86c2Reid Spencer  /// Return a ConstantInt with the specified value for the specified type. The
89a0098386741949065f099b940819201f73cd86c2Reid Spencer  /// value V will be canonicalized to a uint64_t but accessing it with either
906b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// getSExtValue() or getZExtValue() (ConstantInt) will yield the correct
91a0098386741949065f099b940819201f73cd86c2Reid Spencer  /// sized/signed value for the type Ty.
920b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Get a ConstantInt for a specific value.
93b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  static ConstantInt *get(const Type *Ty, int64_t V);
940b5a504d105514178c80b886321221fbe5ac1131Reid Spencer
950b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This static method returns true if the type Ty is big enough to
960b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// represent the value V. This can be used to avoid having the get method
976d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// assert when V is larger than Ty can represent. Note that there are two
986d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// versions of this method, one for unsigned and one for signed integers.
996d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// Although ConstantInt canonicalizes everything to an unsigned integer,
1006d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// the signed version avoids callers having to convert a signed quantity
1016d0483a7a365338e17537366c6c934edef2ef726Reid Spencer  /// to the appropriate unsigned type before calling the method.
1020b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if V is a valid value for type Ty
1030b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if the value is in range for the given type.
1049b11d518aef8e191e5e94f3503dfddbe1c0a387aReid Spencer  static bool isValueValidForType(const Type *Ty, uint64_t V);
105009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  static bool isValueValidForType(const Type *Ty, int64_t V);
10693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner
1076b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// This function will return true iff this constant represents the "null"
1086b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// value that would be returned by the getNullValue method.
109b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// @returns true if this is the null integer value.
1106b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Determine if the value is null.
1116b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  virtual bool isNullValue() const {
1126b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    return Val == 0;
1136b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  }
1145ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
1156b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// This function will return true iff every bit in this constant is set
1166b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// to true.
1170b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true iff this constant's bits are all set to true.
1186b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Determine if the value is all ones.
119579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer  bool isAllOnesValue() const {
1206b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng    return getSExtValue() == -1;
1216b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  }
1221680312867fffeb9369800949b809e0b9e29a914Chris Lattner
1236b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// This function will return true iff this constant represents the largest
1246b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// value that may be represented by the constant's type.
1250b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true iff this is the largest value that may be represented
1260b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// by this type.
1276b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Determine if the value is maximal.
128579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer  bool isMaxValue(bool isSigned) const {
1295c14a1bcb006c09ab6a06f96e09e62f6dc168a27Reid Spencer    if (isSigned) {
130b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      int64_t V = getSExtValue();
131b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      if (V < 0) return false;    // Be careful about wrap-around on 'long's
132b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      ++V;
1339b11d518aef8e191e5e94f3503dfddbe1c0a387aReid Spencer      return !isValueValidForType(getType(), V) || V < 0;
134b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    }
135b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return isAllOnesValue();
136994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  }
137994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
1386b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// This function will return true iff this constant represents the smallest
1396b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// value that may be represented by this constant's type.
1400b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if this is the smallest value that may be represented by
1410b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// this type.
1426b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Determine if the value is minimal.
143579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer  bool isMinValue(bool isSigned) const {
1445c14a1bcb006c09ab6a06f96e09e62f6dc168a27Reid Spencer    if (isSigned) {
145b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      int64_t V = getSExtValue();
146b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      if (V > 0) return false;    // Be careful about wrap-around on 'long's
147b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      --V;
1489b11d518aef8e191e5e94f3503dfddbe1c0a387aReid Spencer      return !isValueValidForType(getType(), V) || V > 0;
149b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    }
150b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return getZExtValue() == 0;
151994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  }
152994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
1536b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @returns the value for an integer constant of the given type that has all
1546b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// its bits set to true.
1556b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  /// @brief Get the all ones value
1566b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng  static ConstantInt *getAllOnesValue(const Type *Ty);
1576b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng
158b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
159b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  static inline bool classof(const ConstantInt *) { return true; }
16052eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
161b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return V->getValueType() == ConstantIntVal;
1625ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
163009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
164009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
165009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
16686e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
16793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantFP - Floating Point Values [float, double]
16893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
169e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantFP : public Constant {
170009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  double Val;
171cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
172cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
173e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantFP(const ConstantFP &);      // DO NOT IMPLEMENT
1743e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
175e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantFP(const Type *Ty, double V);
176009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
17793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
178e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static ConstantFP *get(const Type *Ty, double V);
179009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
18093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isValueValidForType - return true if Ty is big enough to represent V.
181009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  static bool isValueValidForType(const Type *Ty, double V);
182009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  inline double getValue() const { return Val; }
1835ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
18493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
185cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  /// getNullValue.  Don't depend on == for doubles to tell us it's zero, it
186cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  /// considers -0.0 to be null as well as 0.0.  :(
1873a1eff732b36a663cdb9f07f4a9ccae6452eadcbJim Laskey  virtual bool isNullValue() const;
1880eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
189f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// isExactlyValue - We don't rely on operator== working on double values, as
190f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
191f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// As such, this method can be used to do an exact bit-for-bit comparison of
192f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// two floating point values.
1933a1eff732b36a663cdb9f07f4a9ccae6452eadcbJim Laskey  bool isExactlyValue(double V) const;
194f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner
19593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
196e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantFP *) { return true; }
19752eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
198225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantFPVal;
1995ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
200009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
201009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
20286e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
20340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// ConstantAggregateZero - All zero aggregate value
20440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner///
20540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerclass ConstantAggregateZero : public Constant {
20640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
20740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  ConstantAggregateZero(const ConstantAggregateZero &);      // DO NOT IMPLEMENT
20840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerprotected:
20952eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  ConstantAggregateZero(const Type *Ty)
2105181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner    : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
21140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerpublic:
21240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// get() - static factory method for creating a null aggregate.  It is
21340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// illegal to call this method with a non-aggregate type.
21440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  static Constant *get(const Type *Ty);
21540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
21640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
21740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.
21840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual bool isNullValue() const { return true; }
21940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
22040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual void destroyConstant();
22140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
22240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
22340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  ///
22452eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const ConstantAggregateZero *) { return true; }
22552eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
22652eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner    return V->getValueType() == ConstantAggregateZeroVal;
22740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  }
22840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner};
22940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
230009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
23186e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
23293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantArray - Constant Array Declarations
23393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
234e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantArray : public Constant {
2356cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantArray, ArrayType,
2366cc89aad25155ecd93b5318414851aa46351196dChris Lattner                                    std::vector<Constant*> >;
237e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantArray(const ConstantArray &);      // DO NOT IMPLEMENT
2383e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
239697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner  ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
2405181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ~ConstantArray();
241009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
24293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
243ca705fa31d53469d2e6d0e52fa9e40d3e13a088aChris Lattner  static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
244efcaa42c282ae6c6ba9652c48738c334878afbc6Reid Spencer
245efcaa42c282ae6c6ba9652c48738c334878afbc6Reid Spencer  /// This method constructs a ConstantArray and initializes it with a text
246461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// string. The default behavior (AddNull==true) causes a null terminator to
247461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// be placed at the end of the array. This effectively increases the length
248461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// of the array by one (you've been warned).  However, in some situations
249461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// this is not desired so if AddNull==false then the string is copied without
250461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// null termination.
251461bed2b753c514ac15ff824befe585988408f45Reid Spencer  static Constant *get(const std::string &Initializer, bool AddNull = true);
2529769ab22265b313171d201b5928688524a01bd87Misha Brukman
25393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getType - Specialize the getType() method to always return an ArrayType,
25493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// which reduces the amount of casting needed in parts of the compiler.
25593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  ///
256682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  inline const ArrayType *getType() const {
2578b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner    return reinterpret_cast<const ArrayType*>(Value::getType());
258682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  }
259009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
2609b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// isString - This method returns true if the array is an array of sbyte or
2619b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// ubyte, and if the elements of the array are all ConstantInt's.
2629b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  bool isString() const;
2639b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner
26422c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// isCString - This method returns true if the array is a string (see
26522c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// isString) and it ends in a null byte \0 and does not contains any other
26622c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// null bytes except its terminator.
26722c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  bool isCString() const;
26822c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng
2699b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// getAsString - If this array is isString(), then this method converts the
2709b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// array to an std::string and returns it.  Otherwise, it asserts out.
27193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  ///
27293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  std::string getAsString() const;
27393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner
27493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
27540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.  This always returns false because zero arrays are always
27640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// created as ConstantAggregateZero objects.
27740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual bool isNullValue() const { return false; }
2780eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
279e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
28040cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
281e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner
28293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
283e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantArray *) { return true; }
28452eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
285225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantArrayVal;
2865ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
287009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
288009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
289009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
29086e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
291e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner// ConstantStruct - Constant Struct Declarations
292009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//
293e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantStruct : public Constant {
2946cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantStruct, StructType,
2956cc89aad25155ecd93b5318414851aa46351196dChris Lattner                                    std::vector<Constant*> >;
296e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
2973e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
298697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner  ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
2995181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ~ConstantStruct();
300009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
30193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
302c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner  ///
303ca705fa31d53469d2e6d0e52fa9e40d3e13a088aChris Lattner  static Constant *get(const StructType *T, const std::vector<Constant*> &V);
30438ecbf18eb9c8ca7ae08dfed4dc6fb4e3e5deb1eAndrew Lenharth  static Constant *get(const std::vector<Constant*> &V, bool packed = false);
305009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
30693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getType() specialization - Reduce amount of casting...
307c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner  ///
308682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  inline const StructType *getType() const {
3098b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner    return reinterpret_cast<const StructType*>(Value::getType());
310682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  }
311009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
31293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
31340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.  This always returns false because zero structs are always
31440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// created as ConstantAggregateZero objects.
315a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner  virtual bool isNullValue() const {
31640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner    return false;
317a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner  }
3180eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
319e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
32040cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
3219769ab22265b313171d201b5928688524a01bd87Misha Brukman
32293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
323e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantStruct *) { return true; }
32452eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
325225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantStructVal;
3265ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
327009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
328009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
32986e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
330715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke/// ConstantPacked - Constant Packed Declarations
331715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke///
332715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeclass ConstantPacked : public Constant {
333715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  friend struct ConstantCreator<ConstantPacked, PackedType,
334715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke                                    std::vector<Constant*> >;
335715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  ConstantPacked(const ConstantPacked &);      // DO NOT IMPLEMENT
336715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeprotected:
337715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val);
3385181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ~ConstantPacked();
339715c90ba524e736190a6380695ab337eeb5148beBrian Gaekepublic:
340715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// get() - Static factory methods - Return objects of the specified value
341715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static Constant *get(const PackedType *T, const std::vector<Constant*> &);
342715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static Constant *get(const std::vector<Constant*> &V);
3439769ab22265b313171d201b5928688524a01bd87Misha Brukman
344715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// getType - Specialize the getType() method to always return an PackedType,
345715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// which reduces the amount of casting needed in parts of the compiler.
346715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  ///
347715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  inline const PackedType *getType() const {
348715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke    return reinterpret_cast<const PackedType*>(Value::getType());
349715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  }
350715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
35158513aa1c22a08118734ac799d935ea2910db35aChris Lattner  /// @returns the value for an packed integer constant of the given type that
35258513aa1c22a08118734ac799d935ea2910db35aChris Lattner  /// has all its bits set to true.
35358513aa1c22a08118734ac799d935ea2910db35aChris Lattner  /// @brief Get the all ones value
35458513aa1c22a08118734ac799d935ea2910db35aChris Lattner  static ConstantPacked *getAllOnesValue(const PackedType *Ty);
35558513aa1c22a08118734ac799d935ea2910db35aChris Lattner
356715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// isNullValue - Return true if this is the value that would be returned by
357715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// getNullValue.  This always returns false because zero arrays are always
358715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// created as ConstantAggregateZero objects.
359715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  virtual bool isNullValue() const { return false; }
360715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
361fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey  /// This function will return true iff every element in this packed constant
362fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey  /// is set to all ones.
363fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey  /// @returns true iff this constant's emements are all set to all ones.
364fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey  /// @brief Determine if the value is all ones.
365569cc890e8822c265cec66745791edbd510dac1cJim Laskey  bool isAllOnesValue() const;
366fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey
367715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  virtual void destroyConstant();
36840cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
369715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
370715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// Methods for support type inquiry through isa, cast, and dyn_cast:
371715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static inline bool classof(const ConstantPacked *) { return true; }
372715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static bool classof(const Value *V) {
373225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantPackedVal;
374715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  }
375715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke};
376715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
37786e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
37893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantPointerNull - a constant pointer value that points to null
37993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
38048babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattnerclass ConstantPointerNull : public Constant {
3816cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
382e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
3835ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerprotected:
38448babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattner  ConstantPointerNull(const PointerType *T)
3855181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner    : Constant(reinterpret_cast<const Type*>(T),
386225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner               Value::ConstantPointerNullVal, 0, 0) {}
3876cc89aad25155ecd93b5318414851aa46351196dChris Lattner
3885ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerpublic:
3895ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
39093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
391e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static ConstantPointerNull *get(const PointerType *T);
3925ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
39393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
39493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getNullValue.
3950eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner  virtual bool isNullValue() const { return true; }
3960eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
397e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
398e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner
3990f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  /// getType - Specialize the getType() method to always return an PointerType,
4000f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  /// which reduces the amount of casting needed in parts of the compiler.
4010f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  ///
4020f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  inline const PointerType *getType() const {
4030f42ba67771627453187e44fea935d6bab7a8152Chris Lattner    return reinterpret_cast<const PointerType*>(Value::getType());
4040f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  }
4050f42ba67771627453187e44fea935d6bab7a8152Chris Lattner
40693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
407e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantPointerNull *) { return true; }
40852eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
409225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantPointerNullVal;
4105ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
4114cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner};
4124cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner
413f4ba6c710c298fe9b492b9cde82ce5efd46afd5dChris Lattner
41486e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// ConstantExpr - a constant value that is initialized with an expression using
415eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// other constant values.
41686e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner///
417eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// This class uses the standard Instruction opcodes to define the various
418eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// constant expressions.  The Opcode field for the ConstantExpr class is
419eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// maintained in the Value::SubclassData field.
42029ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adveclass ConstantExpr : public Constant {
4216cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantExpr,Type,
4226cc89aad25155ecd93b5318414851aa46351196dChris Lattner                            std::pair<unsigned, std::vector<Constant*> > >;
4235133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  friend struct ConvertConstantType<ConstantExpr, Type>;
4249769ab22265b313171d201b5928688524a01bd87Misha Brukman
4256cc89aad25155ecd93b5318414851aa46351196dChris Lattnerprotected:
4265181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
427eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner    : Constant(Ty, ConstantExprVal, Ops, NumOps) {
428eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner    // Operation type (an Instruction opcode) is stored as the SubclassData.
4299769ab22265b313171d201b5928688524a01bd87Misha Brukman    SubclassData = Opcode;
430eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner  }
4315133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner
4325133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  // These private methods are used by the type resolution code to create
4335133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  // ConstantExprs in intermediate forms.
4345133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  static Constant *getTy(const Type *Ty, unsigned Opcode,
43590fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer                         Constant *C1, Constant *C2);
436e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer  static Constant *getCompareTy(unsigned short pred, Constant *C1,
437e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer                                Constant *C2);
4385133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  static Constant *getShiftTy(const Type *Ty,
4395133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner                              unsigned Opcode, Constant *C1, Constant *C2);
44046a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  static Constant *getSelectTy(const Type *Ty,
44146a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner                               Constant *C1, Constant *C2, Constant *C3);
4425133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
4437fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner                                      const std::vector<Value*> &IdxList);
44449b78a569609881811d905960baa7dd1ab801383Robert Bocchino  static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
44549b78a569609881811d905960baa7dd1ab801383Robert Bocchino                                       Constant *Idx);
446f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino  static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
447f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino                                      Constant *Elt, Constant *Idx);
4489fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
4499fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner                                      Constant *V2, Constant *Mask);
4509769ab22265b313171d201b5928688524a01bd87Misha Brukman
45129ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Advepublic:
452fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner  // Static methods to construct a ConstantExpr of different kinds.  Note that
453baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // these methods may return a object that is not an instance of the
454baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // ConstantExpr class, because they will attempt to fold the constant
455baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // expression into something simpler if possible.
4569769ab22265b313171d201b5928688524a01bd87Misha Brukman
45793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Cast constant expr
4585133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  ///
459d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getTrunc   (Constant *C, const Type *Ty);
460d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getSExt    (Constant *C, const Type *Ty);
461d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getZExt    (Constant *C, const Type *Ty);
462d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getFPTrunc (Constant *C, const Type *Ty);
463d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getFPExtend(Constant *C, const Type *Ty);
464d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getUIToFP  (Constant *C, const Type *Ty);
465d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getSIToFP  (Constant *C, const Type *Ty);
466d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getFPToUI  (Constant *C, const Type *Ty);
467d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getFPToSI  (Constant *C, const Type *Ty);
468d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getPtrToInt(Constant *C, const Type *Ty);
469d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getIntToPtr(Constant *C, const Type *Ty);
470d977d8651a5cd26a3e1088267f31cade405f2adfReid Spencer  static Constant *getBitCast (Constant *C, const Type *Ty);
4713da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer
4723da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  // @brief Convenience function for getting one of the casting operations
4733da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  // using a CastOps opcode.
4743da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  static Constant *getCast(
4753da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer    unsigned ops,  ///< The opcode for the conversion
4763da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer    Constant *C,   ///< The constant to be converted
4773da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer    const Type *Ty ///< The type to which the constant is converted
4783da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  );
4793da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer
480848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  // @brief Create a ZExt or BitCast cast constant expression
481848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  static Constant *getZExtOrBitCast(
482848414e49c7600e3002a4366de52d03a9638b327Reid Spencer    Constant *C,   ///< The constant to zext or bitcast
483848414e49c7600e3002a4366de52d03a9638b327Reid Spencer    const Type *Ty ///< The type to zext or bitcast C to
484848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  );
485848414e49c7600e3002a4366de52d03a9638b327Reid Spencer
486848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  // @brief Create a SExt or BitCast cast constant expression
487848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  static Constant *getSExtOrBitCast(
48890fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer    Constant *C,   ///< The constant to sext or bitcast
48990fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer    const Type *Ty ///< The type to sext or bitcast C to
490848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  );
491848414e49c7600e3002a4366de52d03a9638b327Reid Spencer
492848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  // @brief Create a Trunc or BitCast cast constant expression
493848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  static Constant *getTruncOrBitCast(
49490fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer    Constant *C,   ///< The constant to trunc or bitcast
49590fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer    const Type *Ty ///< The type to trunc or bitcast C to
496848414e49c7600e3002a4366de52d03a9638b327Reid Spencer  );
497848414e49c7600e3002a4366de52d03a9638b327Reid Spencer
498887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer  /// @brief Create a BitCast or a PtrToInt cast constant expression
499887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer  static Constant *getPointerCast(
500887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer    Constant *C,   ///< The pointer value to be casted (operand 0)
501887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer    const Type *Ty ///< The type to which cast should be made
502887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer  );
503887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer
50484f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts
50584f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  static Constant *getIntegerCast(
50684f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    Constant *C,    ///< The integer constant to be casted
50784f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    const Type *Ty, ///< The integer type to cast to
50884f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    bool isSigned   ///< Whether C should be treated as signed or not
50984f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  );
51084f3eab017d56b6854155f2350759dc77ac48aadReid Spencer
51184f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
51284f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  static Constant *getFPCast(
51384f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    Constant *C,    ///< The integer constant to be casted
51484f3eab017d56b6854155f2350759dc77ac48aadReid Spencer    const Type *Ty ///< The integer type to cast to
51584f3eab017d56b6854155f2350759dc77ac48aadReid Spencer  );
51684f3eab017d56b6854155f2350759dc77ac48aadReid Spencer
5173da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  /// @brief Return true if this is a convert constant expression
5183da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer  bool isCast() const;
5193da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer
5204b94f49091be8e26ce6e49db1268458995299b82Reid Spencer  /// @brief Return true if this is a compare constant expression
5214b94f49091be8e26ce6e49db1268458995299b82Reid Spencer  bool isCompare() const;
5224b94f49091be8e26ce6e49db1268458995299b82Reid Spencer
52346a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  /// Select constant expr
52446a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  ///
52546a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) {
52646a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner    return getSelectTy(V1->getType(), C, V1, V2);
52746a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  }
52846a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner
5297be2a120659cc61e554b04815ed3f1d4f234ecafAlkis Evlogimenos  /// getSizeOf constant expr - computes the size of a type in a target
530b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// independent way (Note: the return type is a ULong).
53160ab1402981a757c5ee785de540a5d0f85839c5dAlkis Evlogimenos  ///
53260ab1402981a757c5ee785de540a5d0f85839c5dAlkis Evlogimenos  static Constant *getSizeOf(const Type *Ty);
53346a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner
5341cecd3a1d2846315c00cb1cf122372d7e096af8aAlkis Evlogimenos  /// getPtrPtrFromArrayPtr constant expr - given a pointer to a constant array,
5351cecd3a1d2846315c00cb1cf122372d7e096af8aAlkis Evlogimenos  /// return a pointer to a pointer of the array element type.
5361cecd3a1d2846315c00cb1cf122372d7e096af8aAlkis Evlogimenos  static Constant *getPtrPtrFromArrayPtr(Constant *C);
5371cecd3a1d2846315c00cb1cf122372d7e096af8aAlkis Evlogimenos
5387e208904ae8eeef888c3a6eecd38daa779ca36c9Chris Lattner  /// ConstantExpr::get - Return a binary or shift operator constant expression,
5397e208904ae8eeef888c3a6eecd38daa779ca36c9Chris Lattner  /// folding if possible.
5405133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  ///
54190fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer  static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
54290fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer
543887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer  /// @brief Return an ICmp or FCmp comparison operator constant expression.
544e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer  static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2);
545e8e4605021141d689493132a9c7c6fce6294937fChris Lattner
5464dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  /// ConstantExpr::get* - Return some common constants without having to
5474dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  /// specify the full Instruction::OPCODE identifier.
5484dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  ///
5494dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getNeg(Constant *C);
5504dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getNot(Constant *C);
5514dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getAdd(Constant *C1, Constant *C2);
5524dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSub(Constant *C1, Constant *C2);
5534dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getMul(Constant *C1, Constant *C2);
5541628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getUDiv(Constant *C1, Constant *C2);
5551628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getSDiv(Constant *C1, Constant *C2);
5561628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getFDiv(Constant *C1, Constant *C2);
5570a783f783ca05c961234385f5b269d4cf03dbbdbReid Spencer  static Constant *getURem(Constant *C1, Constant *C2); // unsigned rem
5580a783f783ca05c961234385f5b269d4cf03dbbdbReid Spencer  static Constant *getSRem(Constant *C1, Constant *C2); // signed rem
5590a783f783ca05c961234385f5b269d4cf03dbbdbReid Spencer  static Constant *getFRem(Constant *C1, Constant *C2);
5604dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getAnd(Constant *C1, Constant *C2);
5614dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getOr(Constant *C1, Constant *C2);
5624dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getXor(Constant *C1, Constant *C2);
563728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  static Constant* getICmp(unsigned short pred, Constant* LHS, Constant* RHS);
564728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  static Constant* getFCmp(unsigned short pred, Constant* LHS, Constant* RHS);
5654dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getShl(Constant *C1, Constant *C2);
5663822ff5c71478c7c90a50ca57045fb676fcb5005Reid Spencer  static Constant *getLShr(Constant *C1, Constant *C2);
5673822ff5c71478c7c90a50ca57045fb676fcb5005Reid Spencer  static Constant *getAShr(Constant *C1, Constant *C2);
56802140b025d821ca8cefe5086f90f4d8e0c52ae5bChris Lattner
5697fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  /// Getelementptr form.  std::vector<Value*> is only accepted for convenience:
5707fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  /// all elements must be Constant's.
5715133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  ///
572fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner  static Constant *getGetElementPtr(Constant *C,
573fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner                                    const std::vector<Constant*> &IdxList);
5747fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  static Constant *getGetElementPtr(Constant *C,
5757fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner                                    const std::vector<Value*> &IdxList);
5769769ab22265b313171d201b5928688524a01bd87Misha Brukman
5779fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getExtractElement(Constant *Vec, Constant *Idx);
5789fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
5799fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
580728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer
58193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
58293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getNullValue.
58329ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  virtual bool isNullValue() const { return false; }
5849769ab22265b313171d201b5928688524a01bd87Misha Brukman
58593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getOpcode - Return the opcode at the root of this constant expression
586eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner  unsigned getOpcode() const { return SubclassData; }
58729ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve
588728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is
589728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  /// not an ICMP or FCMP constant expression.
590728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer  unsigned getPredicate() const;
591728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer
59293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getOpcodeName - Return a string representation for an opcode.
593e8e4605021141d689493132a9c7c6fce6294937fChris Lattner  const char *getOpcodeName() const;
5949769ab22265b313171d201b5928688524a01bd87Misha Brukman
59579ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  /// getWithOperandReplaced - Return a constant expression identical to this
59679ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  /// one, but with the specified operand set to the specified value.
59779ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
59879ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner
5996b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// getWithOperands - This returns the current constant expression with the
6006b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// operands replaced with the specified values.  The specified operands must
6016b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// match count and type with the existing ones.
6026b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
60379ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner
604e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
60540cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
6069769ab22265b313171d201b5928688524a01bd87Misha Brukman
60717aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  /// Override methods to provide more type information...
6089769ab22265b313171d201b5928688524a01bd87Misha Brukman  inline Constant *getOperand(unsigned i) {
60917aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner    return cast<Constant>(User::getOperand(i));
61017aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  }
61117aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  inline Constant *getOperand(unsigned i) const {
61217aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner    return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
61317aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  }
6149769ab22265b313171d201b5928688524a01bd87Misha Brukman
61517aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner
61693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
61729ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  static inline bool classof(const ConstantExpr *) { return true; }
61829ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  static inline bool classof(const Value *V) {
61952eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner    return V->getValueType() == ConstantExprVal;
62029ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  }
62129ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve};
62229ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve
623e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
624e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner//===----------------------------------------------------------------------===//
625e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// UndefValue - 'undef' values are things that do not have specified contents.
626e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// These are used for a variety of purposes, including global variable
627e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// initializers and operands to instructions.  'undef' values can occur with
628e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// any type.
629e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner///
630e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerclass UndefValue : public Constant {
631e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  friend struct ConstantCreator<UndefValue, Type, char>;
632e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
633e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerprotected:
6345181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
635e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerpublic:
636e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// get() - Static factory methods - Return an 'undef' object of the specified
637e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// type.
638e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  ///
639e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static UndefValue *get(const Type *T);
640e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
641e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
642e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// getNullValue.
643e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  virtual bool isNullValue() const { return false; }
644e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
645e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  virtual void destroyConstant();
646e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
647e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
648e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static inline bool classof(const UndefValue *) { return true; }
649e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static bool classof(const Value *V) {
650e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner    return V->getValueType() == UndefValueVal;
651e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  }
652e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner};
653e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
654d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
655d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
656009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif
657