Constants.h revision 411984810e4a66591123e1b16873e5f19ae18817
148486893f46d2e12e926682a3ecb908716bc66c4Chris Lattner//===-- llvm/Constants.h - Constant class subclass definitions --*- C++ -*-===// 29769ab22265b313171d201b5928688524a01bd87Misha Brukman// 36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// The LLVM Compiler Infrastructure 46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 79769ab22265b313171d201b5928688524a01bd87Misha Brukman// 86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===// 9009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner// 100f8b53f19d29013ab18f3d444cea1e6305405611Dan Gohman/// @file 110f8b53f19d29013ab18f3d444cea1e6305405611Dan Gohman/// This file contains the declarations for the subclasses of Constant, 120b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// which represent the different flavors of constant values that live in LLVM. 130b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// Note that Constants are immutable (once created they never change) and are 140b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// fully shared by structural equivalence. This means that two structurally 150b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// equivalent constants will always have the same address. Constant's are 160b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// created on demand as needed and never deleted: thus clients don't have to 170b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// worry about the lifetime of the objects. 18009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner// 19009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner//===----------------------------------------------------------------------===// 20009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 2131bcdb822fe9133b1973de51519d34e5813a6184Chris Lattner#ifndef LLVM_CONSTANTS_H 2231bcdb822fe9133b1973de51519d34e5813a6184Chris Lattner#define LLVM_CONSTANTS_H 23009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 2431bcdb822fe9133b1973de51519d34e5813a6184Chris Lattner#include "llvm/Constant.h" 25efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif#include "llvm/OperandTraits.h" 26532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer#include "llvm/ADT/APInt.h" 27343e770983dcf53a1ea2dfca4e04d28ebc41138aDale Johannesen#include "llvm/ADT/APFloat.h" 2881a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman#include "llvm/ADT/SmallVector.h" 29174101e13a6f24f6f2737e043194f0ffae925bb3Benjamin Kramer#include <vector> 30009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 31d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 32d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 33009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass ArrayType; 34174101e13a6f24f6f2737e043194f0ffae925bb3Benjamin Kramerclass IntegerType; 35009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass StructType; 364cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattnerclass PointerType; 379d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencerclass VectorType; 38009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 396cc89aad25155ecd93b5318414851aa46351196dChris Lattnertemplate<class ConstantClass, class TypeClass, class ValType> 406cc89aad25155ecd93b5318414851aa46351196dChris Lattnerstruct ConstantCreator; 415133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattnertemplate<class ConstantClass, class TypeClass> 425f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patelstruct ConvertConstantType; 435133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner 4486e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 4524d6da5fedcf39891f7d8c5b031c01324b3db545Reid Spencer/// This is the shared class of boolean and integer constants. This class 466b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// represents both boolean and integral constants. 476b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// @brief Class for constant integers. 486b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Shengclass ConstantInt : public Constant { 49051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 506b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT 51532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer ConstantInt(const IntegerType *Ty, const APInt& V); 52532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer APInt Val; 53051a950000e21935165db56695e35bade668193bGabor Greifprotected: 54051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 55051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 56051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 57051a950000e21935165db56695e35bade668193bGabor Greif } 58994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattnerpublic: 592c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *getTrue(LLVMContext &Context); 602c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *getFalse(LLVMContext &Context); 615defacc6e605f4651c6300237cef8e9bb2eb6d0eOwen Anderson 62eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// If Ty is a vector type, return a Constant with a splat of the given 63eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value. Otherwise return a ConstantInt for the given value. 642c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const Type *Ty, uint64_t V, bool isSigned = false); 65eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 66eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified integer value for the specified 67eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// type. If the type is wider than 64 bits, the value will be zero-extended 68eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// to fit the type, unless isSigned is true, in which case the value will 69eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// be interpreted as a 64-bit signed integer and sign-extended to fit 70eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// the type. 71eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// @brief Get a ConstantInt for a specific value. 722c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *get(const IntegerType *Ty, uint64_t V, 73eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson bool isSigned = false); 74eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 75eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified value for the specified type. The 76eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value V will be canonicalized to a an unsigned APInt. Accessing it with 77eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// either getSExtValue() or getZExtValue() will yield a correctly sized and 78eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// signed value for the type Ty. 79eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// @brief Get a ConstantInt for a specific signed value. 802c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *getSigned(const IntegerType *Ty, int64_t V); 81eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson static Constant *getSigned(const Type *Ty, int64_t V); 82eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 83eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified value and an implied Type. The 84eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// type is the integer type that corresponds to the bit width of the value. 852c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *get(LLVMContext &Context, const APInt &V); 860e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar 870e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar /// Return a ConstantInt constructed from the string strStart with the given 880e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar /// radix. 892928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar static ConstantInt *get(const IntegerType *Ty, StringRef Str, 900e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar uint8_t radix); 91eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 92eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// If Ty is a vector type, return a Constant with a splat of the given 93eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value. Otherwise return a ConstantInt for the given value. 942c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const Type* Ty, const APInt& V); 95eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 96532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// Return the constant as an APInt value reference. This allows clients to 97532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// obtain a copy of the value, with all its precision in tact. 98532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// @brief Return the constant's value. 992c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner inline const APInt &getValue() const { 100532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val; 101532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer } 102e51f2a59d93336b2be46b9663af317b96a7e045bChris Lattner 103e51f2a59d93336b2be46b9663af317b96a7e045bChris Lattner /// getBitWidth - Return the bitwidth of this constant. 104e51f2a59d93336b2be46b9663af317b96a7e045bChris Lattner unsigned getBitWidth() const { return Val.getBitWidth(); } 105532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer 1060b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// Return the constant as a 64-bit unsigned integer value after it 107532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// has been zero extended as appropriate for the type of this constant. Note 108532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// that this method can assert if the value does not fit in 64 bits. 109532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// @deprecated 1100b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Return the zero extended value. 111a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner inline uint64_t getZExtValue() const { 112532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.getZExtValue(); 113a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner } 114c2dfb8bb909b0ba08733be94821513aef9467fa0Chris Lattner 1150b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// Return the constant as a 64-bit integer value after it has been sign 1167b048b391f9ded004170a67780d1c6a5eedeb604Bob Wilson /// extended as appropriate for the type of this constant. Note that 117532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// this method can assert if the value does not fit in 64 bits. 118532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// @deprecated 1196c6b6a77c0f68d5a41e94d8ef0b1093089e683faChris Lattner /// @brief Return the sign extended value. 120a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner inline int64_t getSExtValue() const { 121532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.getSExtValue(); 122a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner } 123532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer 1240b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// A helper method that can be used to determine if the constant contained 1250b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// within is equal to a constant. This only works for very small values, 1260b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// because this is all that can be represented with all types. 1270b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Determine if this constant's value is same as an unsigned char. 128532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer bool equalsInt(uint64_t V) const { 129b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer return Val == V; 1302ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner } 1312ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner 132c10305743c313558405079452138f03124e87581Reid Spencer /// getType - Specialize the getType() method to always return an IntegerType, 133c10305743c313558405079452138f03124e87581Reid Spencer /// which reduces the amount of casting needed in parts of the compiler. 134c10305743c313558405079452138f03124e87581Reid Spencer /// 135c10305743c313558405079452138f03124e87581Reid Spencer inline const IntegerType *getType() const { 136c10305743c313558405079452138f03124e87581Reid Spencer return reinterpret_cast<const IntegerType*>(Value::getType()); 137c10305743c313558405079452138f03124e87581Reid Spencer } 138c10305743c313558405079452138f03124e87581Reid Spencer 1390b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// This static method returns true if the type Ty is big enough to 1400b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// represent the value V. This can be used to avoid having the get method 1416d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// assert when V is larger than Ty can represent. Note that there are two 1426d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// versions of this method, one for unsigned and one for signed integers. 1436d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// Although ConstantInt canonicalizes everything to an unsigned integer, 1446d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// the signed version avoids callers having to convert a signed quantity 1456d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// to the appropriate unsigned type before calling the method. 1460b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true if V is a valid value for type Ty 1470b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Determine if the value is in range for the given type. 1489b11d518aef8e191e5e94f3503dfddbe1c0a387aReid Spencer static bool isValueValidForType(const Type *Ty, uint64_t V); 149009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner static bool isValueValidForType(const Type *Ty, int64_t V); 15093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner 1516b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// This function will return true iff this constant represents the "null" 1526b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// value that would be returned by the getNullValue method. 153b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer /// @returns true if this is the null integer value. 1546b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is null. 1556b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng virtual bool isNullValue() const { 1566b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng return Val == 0; 1576b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng } 1585ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 15934da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// This is just a convenience method to make client code smaller for a 16034da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// common code. It also correctly performs the comparison without the 16134da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// potential for an assertion from getZExtValue(). 16234da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer bool isZero() const { 16334da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer return Val == 0; 16434da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer } 16534da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer 16637eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer /// This is just a convenience method to make client code smaller for a 16734da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// common case. It also correctly performs the comparison without the 16834da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// potential for an assertion from getZExtValue(). 16937eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer /// @brief Determine if the value is one. 17034da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer bool isOne() const { 17137eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer return Val == 1; 17237eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer } 17337eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer 1746b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// This function will return true iff every bit in this constant is set 1756b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// to true. 1760b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true iff this constant's bits are all set to true. 1776b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is all ones. 178579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer bool isAllOnesValue() const { 179532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isAllOnesValue(); 1806b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng } 1811680312867fffeb9369800949b809e0b9e29a914Chris Lattner 1826b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// This function will return true iff this constant represents the largest 1836b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// value that may be represented by the constant's type. 1840b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true iff this is the largest value that may be represented 1850b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// by this type. 1866b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is maximal. 187579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer bool isMaxValue(bool isSigned) const { 188532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer if (isSigned) 189532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMaxSignedValue(); 190532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer else 191532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMaxValue(); 192994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner } 193994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner 1946b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// This function will return true iff this constant represents the smallest 1956b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// value that may be represented by this constant's type. 1960b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true if this is the smallest value that may be represented by 1970b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// this type. 1986b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is minimal. 199579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer bool isMinValue(bool isSigned) const { 200532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer if (isSigned) 201532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMinSignedValue(); 202532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer else 203532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMinValue(); 204994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner } 205994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner 206b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// This function will return true iff this constant represents a value with 207b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// active bits bigger than 64 bits or a value greater than the given uint64_t 208b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// value. 209b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// @returns true iff this constant is greater or equal to the given number. 210b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// @brief Determine if the value is greater or equal to the given number. 2110642f75836960afd547a6b98fad33026d0c355beZhou Sheng bool uge(uint64_t Num) { 2120642f75836960afd547a6b98fad33026d0c355beZhou Sheng return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num; 213b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng } 214b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng 215edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// getLimitedValue - If the value is smaller than the specified limit, 216edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// return it, otherwise return the limit value. This causes the value 217edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// to saturate to the limit. 218edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// @returns the min of the value of the constant and the specified value 219edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// @brief Get the constant's value with a saturation limit 22099b1b38818e3a1628e39af40500bad47d5207d0dChris Lattner uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const { 22199b1b38818e3a1628e39af40500bad47d5207d0dChris Lattner return Val.getLimitedValue(Limit); 222b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng } 223b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng 224b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer /// @brief Methods to support type inquiry through isa, cast, and dyn_cast. 225b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer static inline bool classof(const ConstantInt *) { return true; } 22652eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 227a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantIntVal; 2285ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 229009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 230009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 231009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 23286e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 23393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantFP - Floating Point Values [float, double] 23493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 235e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantFP : public Constant { 236343e770983dcf53a1ea2dfca4e04d28ebc41138aDale Johannesen APFloat Val; 237051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned);// DO NOT IMPLEMENT 238e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT 23912ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramer friend class LLVMContextImpl; 2403e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 241f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen ConstantFP(const Type *Ty, const APFloat& V); 242051a950000e21935165db56695e35bade668193bGabor Greifprotected: 243051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 244051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 245051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 246051a950000e21935165db56695e35bade668193bGabor Greif } 247009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 2486f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// Floating point negation must be implemented with f(x) = -0.0 - x. This 2496f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// method returns the negative zero constant for floating point or vector 2506f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// floating point types; for all other types, it returns the null value. 2512c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getZeroValueForNegation(const Type *Ty); 2526f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson 2536f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// get() - This returns a ConstantFP, or a vector containing a splat of a 2546f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// ConstantFP, for the specified value in the specified type. This should 2556f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// only be used for simple constant values like 2.0/1.0 etc, that are 2566f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// known-valid both as host double and as the target format. 2572c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const Type* Ty, double V); 2582928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar static Constant *get(const Type* Ty, StringRef Str); 2592c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantFP *get(LLVMContext &Context, const APFloat &V); 2602c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantFP *getNegativeZero(const Type* Ty); 2612c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantFP *getInfinity(const Type *Ty, bool Negative = false); 2626f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson 26393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isValueValidForType - return true if Ty is big enough to represent V. 2642c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static bool isValueValidForType(const Type *Ty, const APFloat &V); 265f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen inline const APFloat& getValueAPF() const { return Val; } 2665ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 26793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 268cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner /// getNullValue. Don't depend on == for doubles to tell us it's zero, it 269cf2c4f8ae52d5f0a01ab40eda6d165f91b8de441Chris Lattner /// considers -0.0 to be null as well as 0.0. :( 2703a1eff732b36a663cdb9f07f4a9ccae6452eadcbJim Laskey virtual bool isNullValue() const; 271fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson 272fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson /// isNegativeZeroValue - Return true if the value is what would be returned 273fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson /// by getZeroValueForNegation. 274fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson virtual bool isNegativeZeroValue() const { 275fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson return Val.isZero() && Val.isNegative(); 276fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson } 2770eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner 278f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// isExactlyValue - We don't rely on operator== working on double values, as 279f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// it returns true for things that are clearly not equal, like -0.0 and 0.0. 280f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// As such, this method can be used to do an exact bit-for-bit comparison of 28143421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen /// two floating point values. The version with a double operand is retained 28243421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen /// because it's so convenient to write isExactlyValue(2.0), but please use 283def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner /// it only for simple constants. 2842c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner bool isExactlyValue(const APFloat &V) const; 28543421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen 286f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen bool isExactlyValue(double V) const { 2878aaec36fa760c9dd50627e397ca85798d9eb6e79Dale Johannesen bool ignored; 288beb5be03320f9bbe6a4a92b0c7e1e0ebf3ef865dDale Johannesen // convert is not supported on this type 289beb5be03320f9bbe6a4a92b0c7e1e0ebf3ef865dDale Johannesen if (&Val.getSemantics() == &APFloat::PPCDoubleDouble) 290beb5be03320f9bbe6a4a92b0c7e1e0ebf3ef865dDale Johannesen return false; 291def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner APFloat FV(V); 2928aaec36fa760c9dd50627e397ca85798d9eb6e79Dale Johannesen FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored); 293def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner return isExactlyValue(FV); 294f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen } 29593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 296e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner static inline bool classof(const ConstantFP *) { return true; } 29752eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 298a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantFPVal; 2995ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 300009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 301009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 30286e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 30340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// ConstantAggregateZero - All zero aggregate value 30440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// 30540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerclass ConstantAggregateZero : public Constant { 30640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner friend struct ConstantCreator<ConstantAggregateZero, Type, char>; 307051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 30840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT 30940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerprotected: 31013d57320bd212483463d4f8992d5787b29eda5dfBill Wendling explicit ConstantAggregateZero(const Type *ty) 31113d57320bd212483463d4f8992d5787b29eda5dfBill Wendling : Constant(ty, ConstantAggregateZeroVal, 0, 0) {} 312051a950000e21935165db56695e35bade668193bGabor Greifprotected: 313051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 314051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 315051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 316051a950000e21935165db56695e35bade668193bGabor Greif } 31740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerpublic: 3182c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantAggregateZero* get(const Type *Ty); 3199e9a0d5fc26878e51a58a8b57900fcbf952c2691Owen Anderson 32040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 32140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// getNullValue. 32240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner virtual bool isNullValue() const { return true; } 32340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner 32404fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 32540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner 32640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 32740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// 32852eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const ConstantAggregateZero *) { return true; } 32952eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 330a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantAggregateZeroVal; 33140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner } 33240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner}; 33340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner 334009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 33586e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 33693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantArray - Constant Array Declarations 33793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 338e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantArray : public Constant { 3396cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantArray, ArrayType, 3406cc89aad25155ecd93b5318414851aa46351196dChris Lattner std::vector<Constant*> >; 341e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT 3423e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 343697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val); 344009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 3451fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson // ConstantArray accessors 3462c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const ArrayType *T, const std::vector<Constant*> &V); 3472c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const ArrayType *T, Constant *const *Vals, 3481fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson unsigned NumVals); 3491fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson 3501fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// This method constructs a ConstantArray and initializes it with a text 3511fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// string. The default behavior (AddNull==true) causes a null terminator to 3521fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// be placed at the end of the array. This effectively increases the length 3531fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// of the array by one (you've been warned). However, in some situations 3541fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// this is not desired so if AddNull==false then the string is copied without 3551fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// null termination. 3562928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar static Constant *get(LLVMContext &Context, StringRef Initializer, 3571d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson bool AddNull = true); 3581fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson 359efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 360efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 361efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 36293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getType - Specialize the getType() method to always return an ArrayType, 36393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// which reduces the amount of casting needed in parts of the compiler. 36493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// 365682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner inline const ArrayType *getType() const { 3668b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner return reinterpret_cast<const ArrayType*>(Value::getType()); 367682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner } 368009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 3696eabd74d1a236effc6757e7c81182fa1ecd52ac6Nick Lewycky /// isString - This method returns true if the array is an array of i8 and 3706eabd74d1a236effc6757e7c81182fa1ecd52ac6Nick Lewycky /// the elements of the array are all ConstantInt's. 3719b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner bool isString() const; 3729b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner 37322c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng /// isCString - This method returns true if the array is a string (see 374181b6c9cb5def44658d15848e34c5c45d973f065Reid Spencer /// @verbatim 37522c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng /// isString) and it ends in a null byte \0 and does not contains any other 376181b6c9cb5def44658d15848e34c5c45d973f065Reid Spencer /// @endverbatim 37722c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng /// null bytes except its terminator. 3781ca29d318a6632c115b9f62c791077b575494e42Owen Anderson bool isCString() const; 37922c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng 3809b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner /// getAsString - If this array is isString(), then this method converts the 3819b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner /// array to an std::string and returns it. Otherwise, it asserts out. 38293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// 38393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner std::string getAsString() const; 38493aeea3748b11fa213b345edf3c86275a4936a31Chris 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 arrays are always 38740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// created as ConstantAggregateZero objects. 38840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner virtual bool isNullValue() const { return false; } 3890eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner 39004fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 39140cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 392e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner 39393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 394e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner static inline bool classof(const ConstantArray *) { return true; } 39552eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 396a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantArrayVal; 3975ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 398009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 399009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 400efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 40159bf4fcc0680e75b408579064d1205a132361196Duncan Sandsstruct OperandTraits<ConstantArray> : public VariadicOperandTraits<> { 402efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 403efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 404efe65369a74871c3140a540a6c95ce5d1f080954Gabor GreifDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant) 405009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 40686e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 407e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner// ConstantStruct - Constant Struct Declarations 408009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner// 409e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantStruct : public Constant { 4106cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantStruct, StructType, 4116cc89aad25155ecd93b5318414851aa46351196dChris Lattner std::vector<Constant*> >; 412e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT 4133e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 414697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner ConstantStruct(const StructType *T, const std::vector<Constant*> &Val); 415009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 4168fa3338ed2400c1352b137613d2c2c70d1ead695Owen Anderson // ConstantStruct accessors 4172c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const StructType *T, const std::vector<Constant*> &V); 4182c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(LLVMContext &Context, 4192c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner const std::vector<Constant*> &V, bool Packed); 4202c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(LLVMContext &Context, 4212c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner Constant *const *Vals, unsigned NumVals, bool Packed); 422c332fba8285e35a5a11463c34795af84f3960759Nick Lewycky 423efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 424efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 425efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 42693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getType() specialization - Reduce amount of casting... 427c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner /// 428682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner inline const StructType *getType() const { 4298b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner return reinterpret_cast<const StructType*>(Value::getType()); 430682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner } 431009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 43293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 43340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// getNullValue. This always returns false because zero structs are always 43440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// created as ConstantAggregateZero objects. 435a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner virtual bool isNullValue() const { 43640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner return false; 437a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner } 4380eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner 43904fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 44040cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 4419769ab22265b313171d201b5928688524a01bd87Misha Brukman 44293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 443e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner static inline bool classof(const ConstantStruct *) { return true; } 44452eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 445a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantStructVal; 4465ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 447009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 448009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 449efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 45059bf4fcc0680e75b408579064d1205a132361196Duncan Sandsstruct OperandTraits<ConstantStruct> : public VariadicOperandTraits<> { 451efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 452efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 453efe65369a74871c3140a540a6c95ce5d1f080954Gabor GreifDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant) 454efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 45586e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 4569d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer/// ConstantVector - Constant Vector Declarations 457715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke/// 4589d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencerclass ConstantVector : public Constant { 4599d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer friend struct ConstantCreator<ConstantVector, VectorType, 460715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke std::vector<Constant*> >; 4619d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT 462715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeprotected: 4639d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer ConstantVector(const VectorType *T, const std::vector<Constant*> &Val); 464715c90ba524e736190a6380695ab337eeb5148beBrian Gaekepublic: 465af7ec975870f92245f1f1484ac80a1e2db6a0afaOwen Anderson // ConstantVector accessors 4662c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const VectorType *T, const std::vector<Constant*> &V); 4672c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const std::vector<Constant*> &V); 4682c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(Constant *const *Vals, unsigned NumVals); 469af7ec975870f92245f1f1484ac80a1e2db6a0afaOwen Anderson 470efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 471efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 472efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 473fa73ea2d9fd785a214256ca44488407b26c5a3dbDan Gohman /// getType - Specialize the getType() method to always return a VectorType, 474715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// which reduces the amount of casting needed in parts of the compiler. 475715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// 4769d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer inline const VectorType *getType() const { 4779d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer return reinterpret_cast<const VectorType*>(Value::getType()); 478715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke } 47958513aa1c22a08118734ac799d935ea2910db35aChris Lattner 480715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// isNullValue - Return true if this is the value that would be returned by 48107a96765daedf180a7102d39fe56c499878312b7Dan Gohman /// getNullValue. This always returns false because zero vectors are always 482715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// created as ConstantAggregateZero objects. 483715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke virtual bool isNullValue() const { return false; } 484715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke 485fa73ea2d9fd785a214256ca44488407b26c5a3dbDan Gohman /// This function will return true iff every element in this vector constant 486fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey /// is set to all ones. 487fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey /// @returns true iff this constant's emements are all set to all ones. 488fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey /// @brief Determine if the value is all ones. 489569cc890e8822c265cec66745791edbd510dac1cJim Laskey bool isAllOnesValue() const; 490fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey 4913b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman /// getSplatValue - If this is a splat constant, meaning that all of the 4923b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman /// elements have the same value, return that value. Otherwise return NULL. 4933b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman Constant *getSplatValue(); 4943b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman 49504fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 49640cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 497715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke 498715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// Methods for support type inquiry through isa, cast, and dyn_cast: 4999d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer static inline bool classof(const ConstantVector *) { return true; } 500715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke static bool classof(const Value *V) { 501a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantVectorVal; 502715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke } 503715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke}; 504715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke 505efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 50659bf4fcc0680e75b408579064d1205a132361196Duncan Sandsstruct OperandTraits<ConstantVector> : public VariadicOperandTraits<> { 507efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 508efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 509efe65369a74871c3140a540a6c95ce5d1f080954Gabor GreifDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant) 510efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 51186e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 51293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantPointerNull - a constant pointer value that points to null 51393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 51448babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattnerclass ConstantPointerNull : public Constant { 5156cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantPointerNull, PointerType, char>; 516051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 517e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT 5185ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerprotected: 519423c2260f95883f7c84ac962e58ac66c3a11efacDan Gohman explicit ConstantPointerNull(const PointerType *T) 5205181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner : Constant(reinterpret_cast<const Type*>(T), 521225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner Value::ConstantPointerNullVal, 0, 0) {} 522afba8fe662d65b25b4baf46bb26cc18e1f9cc0a5Gordon Henriksen 523051a950000e21935165db56695e35bade668193bGabor Greifprotected: 524051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 525051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 526051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 527051a950000e21935165db56695e35bade668193bGabor Greif } 5285ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerpublic: 52993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// get() - Static factory methods - Return objects of the specified value 53004fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static ConstantPointerNull *get(const PointerType *T); 5315ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 53293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 53393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getNullValue. 5340eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner virtual bool isNullValue() const { return true; } 5350eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner 53604fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 537e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner 5380f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// getType - Specialize the getType() method to always return an PointerType, 5390f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// which reduces the amount of casting needed in parts of the compiler. 5400f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// 5410f42ba67771627453187e44fea935d6bab7a8152Chris Lattner inline const PointerType *getType() const { 5420f42ba67771627453187e44fea935d6bab7a8152Chris Lattner return reinterpret_cast<const PointerType*>(Value::getType()); 5430f42ba67771627453187e44fea935d6bab7a8152Chris Lattner } 5440f42ba67771627453187e44fea935d6bab7a8152Chris Lattner 54593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 546e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner static inline bool classof(const ConstantPointerNull *) { return true; } 54752eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 548a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantPointerNullVal; 5495ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 5504cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner}; 5514cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner 5522ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner/// BlockAddress - The address of a basic block. 5532ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner/// 5542ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnerclass BlockAddress : public Constant { 5552ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 5562ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner void *operator new(size_t s) { return User::operator new(s, 2); } 5572ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner BlockAddress(Function *F, BasicBlock *BB); 5582ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnerpublic: 5592ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// get - Return a BlockAddress for the specified function and basic block. 5602ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static BlockAddress *get(Function *F, BasicBlock *BB); 5612ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5622ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// get - Return a BlockAddress for the specified basic block. The basic 5632ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// block must be embedded into a function. 5642ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static BlockAddress *get(BasicBlock *BB); 5652ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5662ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// Transparently provide more efficient getOperand methods. 5670eeb913aa17a68b1f2963b02ca1d68f09dba0b78Chris Lattner DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 5682ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5692ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner Function *getFunction() const { return (Function*)Op<0>().get(); } 5702ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); } 5712ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5722ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// isNullValue - Return true if this is the value that would be returned by 5732ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// getNullValue. 5742ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner virtual bool isNullValue() const { return false; } 5752ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5762ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner virtual void destroyConstant(); 5772ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 5782ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5792ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 5802ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static inline bool classof(const BlockAddress *) { return true; } 5812ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static inline bool classof(const Value *V) { 5822ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner return V->getValueID() == BlockAddressVal; 5832ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner } 5842ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner}; 5852ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5862ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnertemplate <> 5872ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnerstruct OperandTraits<BlockAddress> : public FixedNumOperandTraits<2> { 5882ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner}; 589f4ba6c710c298fe9b492b9cde82ce5efd46afd5dChris Lattner 5900eeb913aa17a68b1f2963b02ca1d68f09dba0b78Chris LattnerDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(BlockAddress, Value) 5912ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5922ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner//===----------------------------------------------------------------------===// 59386e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// ConstantExpr - a constant value that is initialized with an expression using 594eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// other constant values. 59586e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// 596eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// This class uses the standard Instruction opcodes to define the various 597eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// constant expressions. The Opcode field for the ConstantExpr class is 598eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// maintained in the Value::SubclassData field. 59929ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adveclass ConstantExpr : public Constant { 6006cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantExpr,Type, 6016cc89aad25155ecd93b5318414851aa46351196dChris Lattner std::pair<unsigned, std::vector<Constant*> > >; 6025f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patel friend struct ConvertConstantType<ConstantExpr, Type>; 6039769ab22265b313171d201b5928688524a01bd87Misha Brukman 6046cc89aad25155ecd93b5318414851aa46351196dChris Lattnerprotected: 60513d57320bd212483463d4f8992d5787b29eda5dfBill Wendling ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps) 60613d57320bd212483463d4f8992d5787b29eda5dfBill Wendling : Constant(ty, ConstantExprVal, Ops, NumOps) { 607eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner // Operation type (an Instruction opcode) is stored as the SubclassData. 6089769ab22265b313171d201b5928688524a01bd87Misha Brukman SubclassData = Opcode; 609eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner } 6105133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner 6115133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner // These private methods are used by the type resolution code to create 6125133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner // ConstantExprs in intermediate forms. 6135133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner static Constant *getTy(const Type *Ty, unsigned Opcode, 614f8dbee7cea072eb63ae343759975109553697bcbDan Gohman Constant *C1, Constant *C2, 615f8dbee7cea072eb63ae343759975109553697bcbDan Gohman unsigned Flags = 0); 616ff795a80a35dc99a1971646de11f088e71d0a2c6Nate Begeman static Constant *getCompareTy(unsigned short pred, Constant *C1, 617ff795a80a35dc99a1971646de11f088e71d0a2c6Nate Begeman Constant *C2); 61804fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getSelectTy(const Type *Ty, 61904fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson Constant *C1, Constant *C2, Constant *C3); 6205133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner static Constant *getGetElementPtrTy(const Type *Ty, Constant *C, 62104fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson Value* const *Idxs, unsigned NumIdxs); 622f8dbee7cea072eb63ae343759975109553697bcbDan Gohman static Constant *getInBoundsGetElementPtrTy(const Type *Ty, Constant *C, 623f8dbee7cea072eb63ae343759975109553697bcbDan Gohman Value* const *Idxs, 624f8dbee7cea072eb63ae343759975109553697bcbDan Gohman unsigned NumIdxs); 62549b78a569609881811d905960baa7dd1ab801383Robert Bocchino static Constant *getExtractElementTy(const Type *Ty, Constant *Val, 62649b78a569609881811d905960baa7dd1ab801383Robert Bocchino Constant *Idx); 627f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino static Constant *getInsertElementTy(const Type *Ty, Constant *Val, 628f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino Constant *Elt, Constant *Idx); 6299fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1, 6309fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner Constant *V2, Constant *Mask); 631041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getExtractValueTy(const Type *Ty, Constant *Agg, 63281a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const unsigned *Idxs, unsigned NumIdxs); 633041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getInsertValueTy(const Type *Ty, Constant *Agg, 634041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman Constant *Val, 63581a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const unsigned *Idxs, unsigned NumIdxs); 6369769ab22265b313171d201b5928688524a01bd87Misha Brukman 63729ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Advepublic: 638fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner // Static methods to construct a ConstantExpr of different kinds. Note that 639baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // these methods may return a object that is not an instance of the 640baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // ConstantExpr class, because they will attempt to fold the constant 641baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // expression into something simpler if possible. 6429769ab22265b313171d201b5928688524a01bd87Misha Brukman 64393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Cast constant expr 6445133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner /// 645baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson 646baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// getAlignOf constant expr - computes the alignment of a type in a target 647baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// independent way (Note: the return type is an i32; Note: assumes that i8 648baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// is byte aligned). 6492c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getAlignOf(const Type* Ty); 650baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson 651baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// getSizeOf constant expr - computes the size of a type in a target 652baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// independent way (Note: the return type is an i64). 653baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// 6542c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getSizeOf(const Type* Ty); 6553778f21b17e675c2fd1600901361fa4a73888ebaDan Gohman 6563778f21b17e675c2fd1600901361fa4a73888ebaDan Gohman /// getOffsetOf constant expr - computes the offset of a field in a target 6573778f21b17e675c2fd1600901361fa4a73888ebaDan Gohman /// independent way (Note: the return type is an i64). 6583778f21b17e675c2fd1600901361fa4a73888ebaDan Gohman /// 6592c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getOffsetOf(const StructType* Ty, unsigned FieldNo); 660baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson 6612c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getNeg(Constant *C); 6622c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFNeg(Constant *C); 6632c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getNot(Constant *C); 6642c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getAdd(Constant *C1, Constant *C2); 6652c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFAdd(Constant *C1, Constant *C2); 6662c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getSub(Constant *C1, Constant *C2); 6672c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFSub(Constant *C1, Constant *C2); 6682c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getMul(Constant *C1, Constant *C2); 6692c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFMul(Constant *C1, Constant *C2); 6702c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getUDiv(Constant *C1, Constant *C2); 6712c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getSDiv(Constant *C1, Constant *C2); 6722c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFDiv(Constant *C1, Constant *C2); 6732c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getURem(Constant *C1, Constant *C2); 6742c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getSRem(Constant *C1, Constant *C2); 6752c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFRem(Constant *C1, Constant *C2); 6762c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getAnd(Constant *C1, Constant *C2); 6772c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getOr(Constant *C1, Constant *C2); 6782c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getXor(Constant *C1, Constant *C2); 6792c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getShl(Constant *C1, Constant *C2); 6802c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getLShr(Constant *C1, Constant *C2); 6812c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getAShr(Constant *C1, Constant *C2); 68204fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getTrunc (Constant *C, const Type *Ty); 68304fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getSExt (Constant *C, const Type *Ty); 68404fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getZExt (Constant *C, const Type *Ty); 68504fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getFPTrunc (Constant *C, const Type *Ty); 68604fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getFPExtend(Constant *C, const Type *Ty); 68704fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getUIToFP (Constant *C, const Type *Ty); 68804fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getSIToFP (Constant *C, const Type *Ty); 68904fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getFPToUI (Constant *C, const Type *Ty); 69004fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getFPToSI (Constant *C, const Type *Ty); 69104fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getPtrToInt(Constant *C, const Type *Ty); 69204fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getIntToPtr(Constant *C, const Type *Ty); 69304fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getBitCast (Constant *C, const Type *Ty); 6943da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 695bdc46c6af5ffcf3596a72df75880fe8703436060Dan Gohman static Constant *getNSWNeg(Constant *C); 6962c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getNSWAdd(Constant *C1, Constant *C2); 6972c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getNSWSub(Constant *C1, Constant *C2); 698411984810e4a66591123e1b16873e5f19ae18817Dan Gohman static Constant *getNSWMul(Constant *C1, Constant *C2); 6992c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getExactSDiv(Constant *C1, Constant *C2); 7006e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman 701efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 702efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 703efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 7043da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer // @brief Convenience function for getting one of the casting operations 7053da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer // using a CastOps opcode. 7063da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer static Constant *getCast( 7073da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer unsigned ops, ///< The opcode for the conversion 7083da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer Constant *C, ///< The constant to be converted 70904fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson const Type *Ty ///< The type to which the constant is converted 7103da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer ); 7113da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 712848414e49c7600e3002a4366de52d03a9638b327Reid Spencer // @brief Create a ZExt or BitCast cast constant expression 713848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getZExtOrBitCast( 714848414e49c7600e3002a4366de52d03a9638b327Reid Spencer Constant *C, ///< The constant to zext or bitcast 715848414e49c7600e3002a4366de52d03a9638b327Reid Spencer const Type *Ty ///< The type to zext or bitcast C to 716848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 717848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 718848414e49c7600e3002a4366de52d03a9638b327Reid Spencer // @brief Create a SExt or BitCast cast constant expression 719848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getSExtOrBitCast( 72090fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer Constant *C, ///< The constant to sext or bitcast 72104fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson const Type *Ty ///< The type to sext or bitcast C to 722848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 723848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 724848414e49c7600e3002a4366de52d03a9638b327Reid Spencer // @brief Create a Trunc or BitCast cast constant expression 725848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getTruncOrBitCast( 72690fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer Constant *C, ///< The constant to trunc or bitcast 72790fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer const Type *Ty ///< The type to trunc or bitcast C to 728848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 729848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 730887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer /// @brief Create a BitCast or a PtrToInt cast constant expression 731887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer static Constant *getPointerCast( 732887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer Constant *C, ///< The pointer value to be casted (operand 0) 73304fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson const Type *Ty ///< The type to which cast should be made 734887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer ); 735887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer 73684f3eab017d56b6854155f2350759dc77ac48aadReid Spencer /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts 73784f3eab017d56b6854155f2350759dc77ac48aadReid Spencer static Constant *getIntegerCast( 73884f3eab017d56b6854155f2350759dc77ac48aadReid Spencer Constant *C, ///< The integer constant to be casted 73984f3eab017d56b6854155f2350759dc77ac48aadReid Spencer const Type *Ty, ///< The integer type to cast to 74084f3eab017d56b6854155f2350759dc77ac48aadReid Spencer bool isSigned ///< Whether C should be treated as signed or not 74184f3eab017d56b6854155f2350759dc77ac48aadReid Spencer ); 74284f3eab017d56b6854155f2350759dc77ac48aadReid Spencer 74384f3eab017d56b6854155f2350759dc77ac48aadReid Spencer /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts 74484f3eab017d56b6854155f2350759dc77ac48aadReid Spencer static Constant *getFPCast( 74584f3eab017d56b6854155f2350759dc77ac48aadReid Spencer Constant *C, ///< The integer constant to be casted 74684f3eab017d56b6854155f2350759dc77ac48aadReid Spencer const Type *Ty ///< The integer type to cast to 74784f3eab017d56b6854155f2350759dc77ac48aadReid Spencer ); 74884f3eab017d56b6854155f2350759dc77ac48aadReid Spencer 7493da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer /// @brief Return true if this is a convert constant expression 7503da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer bool isCast() const; 7513da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 7524b94f49091be8e26ce6e49db1268458995299b82Reid Spencer /// @brief Return true if this is a compare constant expression 7534b94f49091be8e26ce6e49db1268458995299b82Reid Spencer bool isCompare() const; 7544b94f49091be8e26ce6e49db1268458995299b82Reid Spencer 75581a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// @brief Return true if this is an insertvalue or extractvalue expression, 75681a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// and the getIndices() method may be used. 75781a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman bool hasIndices() const; 75881a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman 759e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// @brief Return true if this is a getelementptr expression and all 760e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// the index operands are compile-time known integers within the 761e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// corresponding notional static array extents. Note that this is 762e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// not equivalant to, a subset of, or a superset of the "inbounds" 763e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// property. 764e6992f728a94654e43269580a10a667f18dadba9Dan Gohman bool isGEPWithNoNotionalOverIndexing() const; 765e6992f728a94654e43269580a10a667f18dadba9Dan Gohman 76646a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner /// Select constant expr 76746a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner /// 76846a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) { 76946a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner return getSelectTy(V1->getType(), C, V1, V2); 77046a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner } 77146a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner 772baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// get - Return a binary or shift operator constant expression, 7737e208904ae8eeef888c3a6eecd38daa779ca36c9Chris Lattner /// folding if possible. 7745133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner /// 775f8dbee7cea072eb63ae343759975109553697bcbDan Gohman static Constant *get(unsigned Opcode, Constant *C1, Constant *C2, 776f8dbee7cea072eb63ae343759975109553697bcbDan Gohman unsigned Flags = 0); 77790fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer 7787f6aa2b162e5daaf7b9ccf05d749597d3d7cf460Nick Lewycky /// @brief Return an ICmp or FCmp comparison operator constant expression. 779e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2); 780e8e4605021141d689493132a9c7c6fce6294937fChris Lattner 781baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// get* - Return some common constants without having to 7824dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner /// specify the full Instruction::OPCODE identifier. 7834dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner /// 7844647569fe7706e76135a08ca0e5f90a447ccc5b4Gordon Henriksen static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS); 7854647569fe7706e76135a08ca0e5f90a447ccc5b4Gordon Henriksen static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS); 78602140b025d821ca8cefe5086f90f4d8e0c52ae5bChris Lattner 7877fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner /// Getelementptr form. std::vector<Value*> is only accepted for convenience: 7887fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner /// all elements must be Constant's. 7895133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner /// 79004fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getGetElementPtr(Constant *C, 7912c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner Constant *const *IdxList, unsigned NumIdx); 79204fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getGetElementPtr(Constant *C, 79304fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson Value* const *IdxList, unsigned NumIdx); 794e2574d3215c412a15763d26aee9aa5d856764c2cDan Gohman 7956e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman /// Create an "inbounds" getelementptr. See the documentation for the 7966e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman /// "inbounds" flag in LangRef.html for details. 7976e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman static Constant *getInBoundsGetElementPtr(Constant *C, 7982c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner Constant *const *IdxList, 7996e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman unsigned NumIdx); 8006e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman static Constant *getInBoundsGetElementPtr(Constant *C, 8016e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman Value* const *IdxList, 8026e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman unsigned NumIdx); 8036e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman 8049fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getExtractElement(Constant *Vec, Constant *Idx); 8059fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx); 8069fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask); 807041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getExtractValue(Constant *Agg, 80881a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const unsigned *IdxList, unsigned NumIdx); 809041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getInsertValue(Constant *Agg, Constant *Val, 81081a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const unsigned *IdxList, unsigned NumIdx); 811728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer 81293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 81393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getNullValue. 81429ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve virtual bool isNullValue() const { return false; } 8159769ab22265b313171d201b5928688524a01bd87Misha Brukman 81693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getOpcode - Return the opcode at the root of this constant expression 817eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner unsigned getOpcode() const { return SubclassData; } 81829ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve 819728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is 820728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer /// not an ICMP or FCMP constant expression. 821728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer unsigned getPredicate() const; 822728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer 82381a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// getIndices - Assert that this is an insertvalue or exactvalue 82481a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// expression and return the list of indices. 82581a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const SmallVector<unsigned, 4> &getIndices() const; 82681a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman 82793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getOpcodeName - Return a string representation for an opcode. 828e8e4605021141d689493132a9c7c6fce6294937fChris Lattner const char *getOpcodeName() const; 8299769ab22265b313171d201b5928688524a01bd87Misha Brukman 83079ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner /// getWithOperandReplaced - Return a constant expression identical to this 83179ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner /// one, but with the specified operand set to the specified value. 83279ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const; 83379ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner 8346b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner /// getWithOperands - This returns the current constant expression with the 8356b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner /// operands replaced with the specified values. The specified operands must 8366b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner /// match count and type with the existing ones. 837b054bfd3ea50d599fe14bce1b74e39b686724dd9Chris Lattner Constant *getWithOperands(const std::vector<Constant*> &Ops) const { 838135ccbd74f041caccfbc26a0c935006dfa828e84Bill Wendling return getWithOperands(&Ops[0], (unsigned)Ops.size()); 839b054bfd3ea50d599fe14bce1b74e39b686724dd9Chris Lattner } 8402c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner Constant *getWithOperands(Constant *const *Ops, unsigned NumOps) const; 84179ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner 84204fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 84340cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 8449769ab22265b313171d201b5928688524a01bd87Misha Brukman 84593aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 84629ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve static inline bool classof(const ConstantExpr *) { return true; } 84729ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve static inline bool classof(const Value *V) { 848a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantExprVal; 84929ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve } 85029ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve}; 85129ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve 852efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 85359bf4fcc0680e75b408579064d1205a132361196Duncan Sandsstruct OperandTraits<ConstantExpr> : public VariadicOperandTraits<1> { 854efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 855efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 856efe65369a74871c3140a540a6c95ce5d1f080954Gabor GreifDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant) 857e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 858e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner//===----------------------------------------------------------------------===// 859e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// UndefValue - 'undef' values are things that do not have specified contents. 860e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// These are used for a variety of purposes, including global variable 861e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// initializers and operands to instructions. 'undef' values can occur with 862e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// any type. 863e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// 864e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerclass UndefValue : public Constant { 865e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner friend struct ConstantCreator<UndefValue, Type, char>; 866051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 867e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner UndefValue(const UndefValue &); // DO NOT IMPLEMENT 868e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerprotected: 869423c2260f95883f7c84ac962e58ac66c3a11efacDan Gohman explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {} 870051a950000e21935165db56695e35bade668193bGabor Greifprotected: 871051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 872051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 873051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 874051a950000e21935165db56695e35bade668193bGabor Greif } 875e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerpublic: 876e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// get() - Static factory methods - Return an 'undef' object of the specified 877e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// type. 878e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// 87904fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static UndefValue *get(const Type *T); 880e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 881e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 882e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// getNullValue. 883e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner virtual bool isNullValue() const { return false; } 884e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 88504fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 886e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 887e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 888e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner static inline bool classof(const UndefValue *) { return true; } 889e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner static bool classof(const Value *V) { 890a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == UndefValueVal; 891e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner } 892e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner}; 893d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 894d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 895009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif 896