Constants.h revision 22c7030a0c535ed48d8465994f8f8aaf8fa76813
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//===----------------------------------------------------------------------===//
390b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// This is the shared superclass of boolean and integer constants. This class
400b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// just defines some common interfaces to be implemented by the subclasses.
410b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// @brief An abstract class for integer constants.
42c75071c3bff982c6d83e1274060ec5fcf5fa5922Chris Lattnerclass ConstantIntegral : public Constant {
43994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattnerprotected:
44b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  uint64_t Val;
45225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner  ConstantIntegral(const Type *Ty, ValueTy VT, uint64_t V);
46994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattnerpublic:
470b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// Return the constant as a 64-bit unsigned integer value after it
480b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// has been zero extended as appropriate for the type of this constant.
490b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Return the zero extended value.
50a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  inline uint64_t getZExtValue() const {
51b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return Val;
52a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  }
53c2dfb8bb909b0ba08733be94821513aef9467fa0Chris Lattner
540b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// Return the constant as a 64-bit integer value after it has been sign
550b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// sign extended as appropriate for the type of this constant.
566c6b6a77c0f68d5a41e94d8ef0b1093089e683faChris Lattner  /// @brief Return the sign extended value.
57a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  inline int64_t getSExtValue() const {
58a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner    unsigned Size = getType()->getPrimitiveSizeInBits();
59b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return (int64_t(Val) << (64-Size)) >> (64-Size);
60a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner  }
61a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner
620b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This function is implemented by subclasses and will return true iff this
630b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// constant represents the the "null" value that would be returned by the
640b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// getNullValue method.
650b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if the constant's value is 0.
660b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if the value is null.
67994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  virtual bool isNullValue() const = 0;
68994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
690b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This function is implemented by sublcasses and will return true iff this
700b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// constant represents the the largest value that may be represented by this
710b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// constant's type.
720b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if the constant's value is maximal.
730b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if the value is maximal.
74994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  virtual bool isMaxValue() const = 0;
75994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
760b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This function is implemented by subclasses and will return true iff this
770b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// constant represents the smallest value that may be represented by this
780b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// constant's type.
790b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if the constant's value is minimal
800b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if the value is minimal.
81994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  virtual bool isMinValue() const = 0;
82994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
830b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This function is implemented by subclasses and will return true iff every
840b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// bit in this constant is set to true.
850b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if all bits of the constant are ones.
860b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if the value is all ones.
87994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  virtual bool isAllOnesValue() const = 0;
88994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
890b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns the largest value for an integer constant of the given type
900b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Get the maximal value
91c75071c3bff982c6d83e1274060ec5fcf5fa5922Chris Lattner  static ConstantIntegral *getMaxValue(const Type *Ty);
920b5a504d105514178c80b886321221fbe5ac1131Reid Spencer
930b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns the smallest value for an integer constant of the given type
940b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Get the minimal value
95c75071c3bff982c6d83e1274060ec5fcf5fa5922Chris Lattner  static ConstantIntegral *getMinValue(const Type *Ty);
960b5a504d105514178c80b886321221fbe5ac1131Reid Spencer
970b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns the value for an integer constant of the given type that has all
980b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// its bits set to true.
990b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Get the all ones value
100c75071c3bff982c6d83e1274060ec5fcf5fa5922Chris Lattner  static ConstantIntegral *getAllOnesValue(const Type *Ty);
101c75071c3bff982c6d83e1274060ec5fcf5fa5922Chris Lattner
1020b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// Methods to support type inquiry through isa, cast, and dyn_cast:
103c75071c3bff982c6d83e1274060ec5fcf5fa5922Chris Lattner  static inline bool classof(const ConstantIntegral *) { return true; }
10452eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
105225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantBoolVal ||
106b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer           V->getValueType() == ConstantIntVal;
107994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  }
108994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner};
109994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
110994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
11186e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
1120b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// This concrete class represents constant values of type BoolTy. There are
1130b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// only two instances of this class constructed: the True and False static
1140b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// members. The constructor is hidden to ensure this invariant.
1150b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// @brief Constant Boolean class
116c75071c3bff982c6d83e1274060ec5fcf5fa5922Chris Lattnerclass ConstantBool : public ConstantIntegral {
117e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantBool(bool V);
118009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
119003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  /// getTrue/getFalse - Return the singleton true/false values.
120003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  static ConstantBool *getTrue();
121003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  static ConstantBool *getFalse();
122009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
1230b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This method is provided mostly for compatibility with the other
1240b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// ConstantIntegral subclasses.
1250b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Static factory method for getting a ConstantBool instance.
126003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  static ConstantBool *get(bool Value) { return Value ? getTrue() : getFalse();}
1270b5a504d105514178c80b886321221fbe5ac1131Reid Spencer
1280b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This method is provided mostly for compatibility with the other
1290b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// ConstantIntegral subclasses.
1300b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Static factory method for getting a ConstantBool instance.
131e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static ConstantBool *get(const Type *Ty, bool Value) { return get(Value); }
132009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
1330b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// Returns the opposite value of this ConstantBool value.
1340b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Get inverse value.
135003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  inline ConstantBool *inverted() const {
136003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner    return getValue() ? getFalse() : getTrue();
137003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  }
138009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
1390b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns the value of this ConstantBool
1400b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief return the boolean value of this constant.
141b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  inline bool getValue() const { return static_cast<bool>(getZExtValue()); }
1421d87bcf4909b06dcd86320722653341f08b8b396Chris Lattner
1430b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @see ConstantIntegral for details
1440b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Implement overrides
145003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  virtual bool isNullValue() const { return getValue() == false; }
146003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  virtual bool isMaxValue() const { return getValue() == true; }
147003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  virtual bool isMinValue() const { return getValue() == false; }
148003cbf35f4d9feebf0f1508c85b69b87645727cdChris Lattner  virtual bool isAllOnesValue() const { return getValue() == true; }
1490eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
1500b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Methods to support type inquiry through isa, cast, and dyn_cast:
151e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantBool *) { return true; }
15252eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
153225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantBoolVal;
1541d87bcf4909b06dcd86320722653341f08b8b396Chris Lattner  }
155009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
156009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
157009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
15886e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
159b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer/// This is concrete integer subclass of ConstantIntegral that represents
160b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer/// both signed and unsigned integral constants, other than boolean.
161b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer/// @brief Class for constant integers.
162c75071c3bff982c6d83e1274060ec5fcf5fa5922Chris Lattnerclass ConstantInt : public ConstantIntegral {
1632ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattnerprotected:
164e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantInt(const ConstantInt &);      // DO NOT IMPLEMENT
165b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  ConstantInt(const Type *Ty, uint64_t V);
166b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  ConstantInt(const Type *Ty, int64_t V);
167b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  friend struct ConstantCreator<ConstantInt, Type, uint64_t>;
1682ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattnerpublic:
1690b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// A helper method that can be used to determine if the constant contained
1700b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// within is equal to a constant.  This only works for very small values,
1710b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// because this is all that can be represented with all types.
1720b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if this constant's value is same as an unsigned char.
173f98e88f7453df864a56bda6ca19cf70e09bf3e6eChris Lattner  bool equalsInt(unsigned char V) const {
1743e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattner    assert(V <= 127 &&
175049c48f1adf5cd7862cc4a48a3d3935a0e98ebb0Misha Brukman           "equalsInt: Can only be used with very small positive constants!");
176b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return Val == V;
1772ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner  }
1782ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner
179a0098386741949065f099b940819201f73cd86c2Reid Spencer  /// Return a ConstantInt with the specified value for the specified type. The
180a0098386741949065f099b940819201f73cd86c2Reid Spencer  /// value V will be canonicalized to a uint64_t but accessing it with either
181a0098386741949065f099b940819201f73cd86c2Reid Spencer  /// getSExtValue() or getZExtValue() (ConstantIntegral) will yield the correct
182a0098386741949065f099b940819201f73cd86c2Reid Spencer  /// sized/signed value for the type Ty.
1830b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Get a ConstantInt for a specific value.
184b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  static ConstantInt *get(const Type *Ty, int64_t V);
1850b5a504d105514178c80b886321221fbe5ac1131Reid Spencer
1860b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// This static method returns true if the type Ty is big enough to
1870b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// represent the value V. This can be used to avoid having the get method
1880b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// assert when V is larger than Ty can represent.
1890b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if V is a valid value for type Ty
1900b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Determine if the value is in range for the given type.
191009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  static bool isValueValidForType(const Type *Ty, int64_t V);
19293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner
193b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// @returns true if this is the null integer value.
194b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// @see ConstantIntegral for details
195b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// @brief Implement override.
196b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  virtual bool isNullValue() const { return Val == 0; }
1975ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
1980b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true iff this constant's bits are all set to true.
1990b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @see ConstantIntegral
2000b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Override implementation
201b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  virtual bool isAllOnesValue() const { return getSExtValue() == -1; }
2021680312867fffeb9369800949b809e0b9e29a914Chris Lattner
2030b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true iff this is the largest value that may be represented
2040b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// by this type.
2050b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @see ConstantIntegeral
2060b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Override implementation
207994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  virtual bool isMaxValue() const {
208b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    if (getType()->isSigned()) {
209b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      int64_t V = getSExtValue();
210b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      if (V < 0) return false;    // Be careful about wrap-around on 'long's
211b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      ++V;
212b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      return !isValueValidForType(getType(), V) || V < 0;
213b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    }
214b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return isAllOnesValue();
215994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  }
216994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
2170b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @returns true if this is the smallest value that may be represented by
2180b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// this type.
2190b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @see ConstantIntegral
2200b5a504d105514178c80b886321221fbe5ac1131Reid Spencer  /// @brief Override implementation
221994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  virtual bool isMinValue() const {
222b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    if (getType()->isSigned()) {
223b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      int64_t V = getSExtValue();
224b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      if (V > 0) return false;    // Be careful about wrap-around on 'long's
225b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      --V;
226b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer      return !isValueValidForType(getType(), V) || V > 0;
227b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    }
228b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return getZExtValue() == 0;
229994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner  }
230994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner
231b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
232b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer  static inline bool classof(const ConstantInt *) { return true; }
23352eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
234b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer    return V->getValueType() == ConstantIntVal;
2355ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
236009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
237009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
238009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
23986e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
24093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantFP - Floating Point Values [float, double]
24193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
242e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantFP : public Constant {
243009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  double Val;
244cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  friend struct ConstantCreator<ConstantFP, Type, uint64_t>;
245cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  friend struct ConstantCreator<ConstantFP, Type, uint32_t>;
246e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantFP(const ConstantFP &);      // DO NOT IMPLEMENT
2473e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
248e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantFP(const Type *Ty, double V);
249009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
25093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
251e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static ConstantFP *get(const Type *Ty, double V);
252009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
25393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isValueValidForType - return true if Ty is big enough to represent V.
254009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  static bool isValueValidForType(const Type *Ty, double V);
255009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner  inline double getValue() const { return Val; }
2565ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
25793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
258cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  /// getNullValue.  Don't depend on == for doubles to tell us it's zero, it
259cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner  /// considers -0.0 to be null as well as 0.0.  :(
2603a1eff732b36a663cdb9f07f4a9ccae6452eadcbJim Laskey  virtual bool isNullValue() const;
2610eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
262f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// isExactlyValue - We don't rely on operator== working on double values, as
263f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
264f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// As such, this method can be used to do an exact bit-for-bit comparison of
265f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner  /// two floating point values.
2663a1eff732b36a663cdb9f07f4a9ccae6452eadcbJim Laskey  bool isExactlyValue(double V) const;
267f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner
26893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
269e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantFP *) { return true; }
27052eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
271225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantFPVal;
2725ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
273009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
274009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
27586e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
27640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// ConstantAggregateZero - All zero aggregate value
27740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner///
27840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerclass ConstantAggregateZero : public Constant {
27940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
28040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  ConstantAggregateZero(const ConstantAggregateZero &);      // DO NOT IMPLEMENT
28140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerprotected:
28252eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  ConstantAggregateZero(const Type *Ty)
2835181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner    : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
28440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerpublic:
28540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// get() - static factory method for creating a null aggregate.  It is
28640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// illegal to call this method with a non-aggregate type.
28740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  static Constant *get(const Type *Ty);
28840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
28940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
29040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.
29140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual bool isNullValue() const { return true; }
29240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
29340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual void destroyConstant();
29440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
29540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
29640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  ///
29752eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const ConstantAggregateZero *) { return true; }
29852eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
29952eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner    return V->getValueType() == ConstantAggregateZeroVal;
30040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  }
30140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner};
30240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner
303009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
30486e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
30593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantArray - Constant Array Declarations
30693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
307e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantArray : public Constant {
3086cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantArray, ArrayType,
3096cc89aad25155ecd93b5318414851aa46351196dChris Lattner                                    std::vector<Constant*> >;
310e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantArray(const ConstantArray &);      // DO NOT IMPLEMENT
3113e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
312697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner  ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val);
3135181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ~ConstantArray();
314009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
31593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
316ca705fa31d53469d2e6d0e52fa9e40d3e13a088aChris Lattner  static Constant *get(const ArrayType *T, const std::vector<Constant*> &);
317efcaa42c282ae6c6ba9652c48738c334878afbc6Reid Spencer
318efcaa42c282ae6c6ba9652c48738c334878afbc6Reid Spencer  /// This method constructs a ConstantArray and initializes it with a text
319461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// string. The default behavior (AddNull==true) causes a null terminator to
320461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// be placed at the end of the array. This effectively increases the length
321461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// of the array by one (you've been warned).  However, in some situations
322461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// this is not desired so if AddNull==false then the string is copied without
323461bed2b753c514ac15ff824befe585988408f45Reid Spencer  /// null termination.
324461bed2b753c514ac15ff824befe585988408f45Reid Spencer  static Constant *get(const std::string &Initializer, bool AddNull = true);
3259769ab22265b313171d201b5928688524a01bd87Misha Brukman
32693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getType - Specialize the getType() method to always return an ArrayType,
32793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// which reduces the amount of casting needed in parts of the compiler.
32893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  ///
329682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  inline const ArrayType *getType() const {
3308b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner    return reinterpret_cast<const ArrayType*>(Value::getType());
331682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  }
332009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
3339b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// isString - This method returns true if the array is an array of sbyte or
3349b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// ubyte, and if the elements of the array are all ConstantInt's.
3359b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  bool isString() const;
3369b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner
33722c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// isCString - This method returns true if the array is a string (see
33822c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// isString) and it ends in a null byte \0 and does not contains any other
33922c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  /// null bytes except its terminator.
34022c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng  bool isCString() const;
34122c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng
3429b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// getAsString - If this array is isString(), then this method converts the
3439b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner  /// array to an std::string and returns it.  Otherwise, it asserts out.
34493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  ///
34593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  std::string getAsString() const;
34693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner
34793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
34840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.  This always returns false because zero arrays are always
34940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// created as ConstantAggregateZero objects.
35040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  virtual bool isNullValue() const { return false; }
3510eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
352e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
35340cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
354e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner
35593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
356e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantArray *) { return true; }
35752eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
358225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantArrayVal;
3595ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
360009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
361009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
362009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
36386e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
364e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner// ConstantStruct - Constant Struct Declarations
365009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//
366e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantStruct : public Constant {
3676cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantStruct, StructType,
3686cc89aad25155ecd93b5318414851aa46351196dChris Lattner                                    std::vector<Constant*> >;
369e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantStruct(const ConstantStruct &);      // DO NOT IMPLEMENT
3703e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected:
371697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner  ConstantStruct(const StructType *T, const std::vector<Constant*> &Val);
3725181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ~ConstantStruct();
373009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic:
37493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
375c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner  ///
376ca705fa31d53469d2e6d0e52fa9e40d3e13a088aChris Lattner  static Constant *get(const StructType *T, const std::vector<Constant*> &V);
377c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner  static Constant *get(const std::vector<Constant*> &V);
378009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
37993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getType() specialization - Reduce amount of casting...
380c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner  ///
381682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  inline const StructType *getType() const {
3828b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner    return reinterpret_cast<const StructType*>(Value::getType());
383682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner  }
384009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
38593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
38640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// getNullValue.  This always returns false because zero structs are always
38740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner  /// created as ConstantAggregateZero objects.
388a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner  virtual bool isNullValue() const {
38940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner    return false;
390a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner  }
3910eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
392e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
39340cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
3949769ab22265b313171d201b5928688524a01bd87Misha Brukman
39593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
396e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantStruct *) { return true; }
39752eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
398225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantStructVal;
3995ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
400009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner};
401009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner
40286e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
403715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke/// ConstantPacked - Constant Packed Declarations
404715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke///
405715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeclass ConstantPacked : public Constant {
406715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  friend struct ConstantCreator<ConstantPacked, PackedType,
407715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke                                    std::vector<Constant*> >;
408715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  ConstantPacked(const ConstantPacked &);      // DO NOT IMPLEMENT
409715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeprotected:
410715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  ConstantPacked(const PackedType *T, const std::vector<Constant*> &Val);
4115181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ~ConstantPacked();
412715c90ba524e736190a6380695ab337eeb5148beBrian Gaekepublic:
413715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// get() - Static factory methods - Return objects of the specified value
414715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static Constant *get(const PackedType *T, const std::vector<Constant*> &);
415715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static Constant *get(const std::vector<Constant*> &V);
4169769ab22265b313171d201b5928688524a01bd87Misha Brukman
417715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// getType - Specialize the getType() method to always return an PackedType,
418715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// which reduces the amount of casting needed in parts of the compiler.
419715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  ///
420715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  inline const PackedType *getType() const {
421715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke    return reinterpret_cast<const PackedType*>(Value::getType());
422715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  }
423715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
424715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// isNullValue - Return true if this is the value that would be returned by
425715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// getNullValue.  This always returns false because zero arrays are always
426715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// created as ConstantAggregateZero objects.
427715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  virtual bool isNullValue() const { return false; }
428715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
429715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  virtual void destroyConstant();
43040cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
431715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
432715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  /// Methods for support type inquiry through isa, cast, and dyn_cast:
433715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static inline bool classof(const ConstantPacked *) { return true; }
434715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  static bool classof(const Value *V) {
435225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantPackedVal;
436715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke  }
437715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke};
438715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke
43986e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===//
44093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantPointerNull - a constant pointer value that points to null
44193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner///
44248babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattnerclass ConstantPointerNull : public Constant {
4436cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
444e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  ConstantPointerNull(const ConstantPointerNull &);      // DO NOT IMPLEMENT
4455ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerprotected:
44648babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattner  ConstantPointerNull(const PointerType *T)
4475181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner    : Constant(reinterpret_cast<const Type*>(T),
448225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner               Value::ConstantPointerNullVal, 0, 0) {}
4496cc89aad25155ecd93b5318414851aa46351196dChris Lattner
4505ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerpublic:
4515ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
45293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// get() - Static factory methods - Return objects of the specified value
453e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static ConstantPointerNull *get(const PointerType *T);
4545ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner
45593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
45693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getNullValue.
4570eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner  virtual bool isNullValue() const { return true; }
4580eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner
459e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
460e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner
4610f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  /// getType - Specialize the getType() method to always return an PointerType,
4620f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  /// which reduces the amount of casting needed in parts of the compiler.
4630f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  ///
4640f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  inline const PointerType *getType() const {
4650f42ba67771627453187e44fea935d6bab7a8152Chris Lattner    return reinterpret_cast<const PointerType*>(Value::getType());
4660f42ba67771627453187e44fea935d6bab7a8152Chris Lattner  }
4670f42ba67771627453187e44fea935d6bab7a8152Chris Lattner
46893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
469e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner  static inline bool classof(const ConstantPointerNull *) { return true; }
47052eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner  static bool classof(const Value *V) {
471225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner    return V->getValueType() == ConstantPointerNullVal;
4725ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner  }
4734cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner};
4744cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner
475f4ba6c710c298fe9b492b9cde82ce5efd46afd5dChris Lattner
47686e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// ConstantExpr - a constant value that is initialized with an expression using
477eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// other constant values.
47886e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner///
479eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// This class uses the standard Instruction opcodes to define the various
480eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// constant expressions.  The Opcode field for the ConstantExpr class is
481eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// maintained in the Value::SubclassData field.
48229ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adveclass ConstantExpr : public Constant {
4836cc89aad25155ecd93b5318414851aa46351196dChris Lattner  friend struct ConstantCreator<ConstantExpr,Type,
4846cc89aad25155ecd93b5318414851aa46351196dChris Lattner                            std::pair<unsigned, std::vector<Constant*> > >;
4855133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  friend struct ConvertConstantType<ConstantExpr, Type>;
4869769ab22265b313171d201b5928688524a01bd87Misha Brukman
4876cc89aad25155ecd93b5318414851aa46351196dChris Lattnerprotected:
4885181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  ConstantExpr(const Type *Ty, unsigned Opcode, Use *Ops, unsigned NumOps)
489eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner    : Constant(Ty, ConstantExprVal, Ops, NumOps) {
490eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner    // Operation type (an Instruction opcode) is stored as the SubclassData.
4919769ab22265b313171d201b5928688524a01bd87Misha Brukman    SubclassData = Opcode;
492eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner  }
4935133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner
4945133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  // These private methods are used by the type resolution code to create
4955133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  // ConstantExprs in intermediate forms.
4965133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  static Constant *getTy(const Type *Ty, unsigned Opcode,
4975133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner                         Constant *C1, Constant *C2);
4985133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  static Constant *getShiftTy(const Type *Ty,
4995133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner                              unsigned Opcode, Constant *C1, Constant *C2);
50046a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner  static Constant *getSelectTy(const Type *Ty,
50146a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner                               Constant *C1, Constant *C2, Constant *C3);
5025133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  static Constant *getGetElementPtrTy(const Type *Ty, Constant *C,
5037fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner                                      const std::vector<Value*> &IdxList);
50449b78a569609881811d905960baa7dd1ab801383Robert Bocchino  static Constant *getExtractElementTy(const Type *Ty, Constant *Val,
50549b78a569609881811d905960baa7dd1ab801383Robert Bocchino                                       Constant *Idx);
506f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino  static Constant *getInsertElementTy(const Type *Ty, Constant *Val,
507f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino                                      Constant *Elt, Constant *Idx);
5089fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1,
5099fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner                                      Constant *V2, Constant *Mask);
5109769ab22265b313171d201b5928688524a01bd87Misha Brukman
51129ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Advepublic:
512fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner  // Static methods to construct a ConstantExpr of different kinds.  Note that
513baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // these methods may return a object that is not an instance of the
514baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // ConstantExpr class, because they will attempt to fold the constant
515baf850a51a253a39c60196343d756197bfbb27dbChris Lattner  // expression into something simpler if possible.
5169769ab22265b313171d201b5928688524a01bd87Misha Brukman
51793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Cast constant expr
5185133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  ///
519fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner  static Constant *getCast(Constant *C, const Type *Ty);
520d144f42a5aa0e9c41b0bf478ea20742c09e9a015Chris Lattner  static Constant *getSignExtend(Constant *C, const Type *Ty);
521d144f42a5aa0e9c41b0bf478ea20742c09e9a015Chris Lattner  static Constant *getZeroExtend(Constant *C, const Type *Ty);
522e8e4605021141d689493132a9c7c6fce6294937fChris Lattner
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  ///
541ff4c183790ab241b85170fdfc326a5d6959139aeChris Lattner  static Constant *get(unsigned Opcode, Constant *C1, Constant *C2);
542e8e4605021141d689493132a9c7c6fce6294937fChris Lattner
5434dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  /// ConstantExpr::get* - Return some common constants without having to
5444dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  /// specify the full Instruction::OPCODE identifier.
5454dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  ///
5464dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getNeg(Constant *C);
5474dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getNot(Constant *C);
5484dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getAdd(Constant *C1, Constant *C2);
5494dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSub(Constant *C1, Constant *C2);
5504dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getMul(Constant *C1, Constant *C2);
5511628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getUDiv(Constant *C1, Constant *C2);
5521628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getSDiv(Constant *C1, Constant *C2);
5531628cec4d7fce310d9cde0bcc73997e5a71692c4Reid Spencer  static Constant *getFDiv(Constant *C1, Constant *C2);
5544dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getRem(Constant *C1, Constant *C2);
5554dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getAnd(Constant *C1, Constant *C2);
5564dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getOr(Constant *C1, Constant *C2);
5574dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getXor(Constant *C1, Constant *C2);
5584dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSetEQ(Constant *C1, Constant *C2);
5594dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSetNE(Constant *C1, Constant *C2);
5604dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSetLT(Constant *C1, Constant *C2);
5614dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSetGT(Constant *C1, Constant *C2);
5624dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSetLE(Constant *C1, Constant *C2);
5634dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getSetGE(Constant *C1, Constant *C2);
5644dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getShl(Constant *C1, Constant *C2);
5654dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner  static Constant *getShr(Constant *C1, Constant *C2);
5664dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner
56702140b025d821ca8cefe5086f90f4d8e0c52ae5bChris Lattner  static Constant *getUShr(Constant *C1, Constant *C2); // unsigned shr
56802140b025d821ca8cefe5086f90f4d8e0c52ae5bChris Lattner  static Constant *getSShr(Constant *C1, Constant *C2); // signed shr
56902140b025d821ca8cefe5086f90f4d8e0c52ae5bChris Lattner
5707fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  /// Getelementptr form.  std::vector<Value*> is only accepted for convenience:
5717fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  /// all elements must be Constant's.
5725133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner  ///
573fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner  static Constant *getGetElementPtr(Constant *C,
574fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner                                    const std::vector<Constant*> &IdxList);
5757fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner  static Constant *getGetElementPtr(Constant *C,
5767fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner                                    const std::vector<Value*> &IdxList);
5779769ab22265b313171d201b5928688524a01bd87Misha Brukman
5789fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getExtractElement(Constant *Vec, Constant *Idx);
5799fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx);
5809fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner  static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask);
5819fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner
58293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
58393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getNullValue.
58429ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  virtual bool isNullValue() const { return false; }
5859769ab22265b313171d201b5928688524a01bd87Misha Brukman
58693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getOpcode - Return the opcode at the root of this constant expression
587eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner  unsigned getOpcode() const { return SubclassData; }
58829ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve
58993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// getOpcodeName - Return a string representation for an opcode.
590e8e4605021141d689493132a9c7c6fce6294937fChris Lattner  const char *getOpcodeName() const;
5919769ab22265b313171d201b5928688524a01bd87Misha Brukman
59279ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  /// getWithOperandReplaced - Return a constant expression identical to this
59379ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  /// one, but with the specified operand set to the specified value.
59479ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner  Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const;
59579ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner
5966b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// getWithOperands - This returns the current constant expression with the
5976b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// operands replaced with the specified values.  The specified operands must
5986b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  /// match count and type with the existing ones.
5996b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner  Constant *getWithOperands(const std::vector<Constant*> &Ops) const;
60079ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner
601e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner  virtual void destroyConstant();
60240cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner  virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
6039769ab22265b313171d201b5928688524a01bd87Misha Brukman
60417aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  /// Override methods to provide more type information...
6059769ab22265b313171d201b5928688524a01bd87Misha Brukman  inline Constant *getOperand(unsigned i) {
60617aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner    return cast<Constant>(User::getOperand(i));
60717aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  }
60817aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  inline Constant *getOperand(unsigned i) const {
60917aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner    return const_cast<Constant*>(cast<Constant>(User::getOperand(i)));
61017aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner  }
6119769ab22265b313171d201b5928688524a01bd87Misha Brukman
61217aefb168fb2cfffcbd7131d1529a90ae1831b1cChris Lattner
61393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
61429ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  static inline bool classof(const ConstantExpr *) { return true; }
61529ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  static inline bool classof(const Value *V) {
61652eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner    return V->getValueType() == ConstantExprVal;
61729ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve  }
61829ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve};
61929ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve
620e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
621e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner//===----------------------------------------------------------------------===//
622e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// UndefValue - 'undef' values are things that do not have specified contents.
623e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// These are used for a variety of purposes, including global variable
624e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// initializers and operands to instructions.  'undef' values can occur with
625e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// any type.
626e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner///
627e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerclass UndefValue : public Constant {
628e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  friend struct ConstantCreator<UndefValue, Type, char>;
629e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  UndefValue(const UndefValue &);      // DO NOT IMPLEMENT
630e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerprotected:
6315181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner  UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
632e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerpublic:
633e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// get() - Static factory methods - Return an 'undef' object of the specified
634e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// type.
635e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  ///
636e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static UndefValue *get(const Type *T);
637e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
638e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// isNullValue - Return true if this is the value that would be returned by
639e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// getNullValue.
640e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  virtual bool isNullValue() const { return false; }
641e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
642e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  virtual void destroyConstant();
643e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
644e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  /// Methods for support type inquiry through isa, cast, and dyn_cast:
645e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static inline bool classof(const UndefValue *) { return true; }
646e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  static bool classof(const Value *V) {
647e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner    return V->getValueType() == UndefValueVal;
648e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner  }
649e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner};
650e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner
651d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace
652d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
653009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif
654