Constants.h revision 1c5730facaefbacd66badea74c83571a16611bd4
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" 282ca5c8644e6c35b3a7910a576ed89cddb7b82c3bChris Lattner#include "llvm/ADT/ArrayRef.h" 29009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 30d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 31d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 32009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass ArrayType; 33174101e13a6f24f6f2737e043194f0ffae925bb3Benjamin Kramerclass IntegerType; 34009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass StructType; 354cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattnerclass PointerType; 369d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencerclass VectorType; 37009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 386cc89aad25155ecd93b5318414851aa46351196dChris Lattnertemplate<class ConstantClass, class TypeClass, class ValType> 396cc89aad25155ecd93b5318414851aa46351196dChris Lattnerstruct ConstantCreator; 405133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattnertemplate<class ConstantClass, class TypeClass> 415f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patelstruct ConvertConstantType; 425133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner 4386e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 4424d6da5fedcf39891f7d8c5b031c01324b3db545Reid Spencer/// This is the shared class of boolean and integer constants. This class 456b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// represents both boolean and integral constants. 466b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// @brief Class for constant integers. 476b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Shengclass ConstantInt : public Constant { 48051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 496b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT 50532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer ConstantInt(const IntegerType *Ty, const APInt& V); 51532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer APInt Val; 52051a950000e21935165db56695e35bade668193bGabor Greifprotected: 53051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 54051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 55051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 56051a950000e21935165db56695e35bade668193bGabor Greif } 57994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattnerpublic: 582c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *getTrue(LLVMContext &Context); 592c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *getFalse(LLVMContext &Context); 605defacc6e605f4651c6300237cef8e9bb2eb6d0eOwen Anderson 61eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// If Ty is a vector type, return a Constant with a splat of the given 62eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value. Otherwise return a ConstantInt for the given value. 632c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const Type *Ty, uint64_t V, bool isSigned = false); 64eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 65eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified integer value for the specified 66eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// type. If the type is wider than 64 bits, the value will be zero-extended 67eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// to fit the type, unless isSigned is true, in which case the value will 68eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// be interpreted as a 64-bit signed integer and sign-extended to fit 69eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// the type. 70eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// @brief Get a ConstantInt for a specific value. 712c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *get(const IntegerType *Ty, uint64_t V, 72eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson bool isSigned = false); 73eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 74eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified value for the specified type. The 75eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value V will be canonicalized to a an unsigned APInt. Accessing it with 76eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// either getSExtValue() or getZExtValue() will yield a correctly sized and 77eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// signed value for the type Ty. 78eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// @brief Get a ConstantInt for a specific signed value. 792c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *getSigned(const IntegerType *Ty, int64_t V); 80eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson static Constant *getSigned(const Type *Ty, int64_t V); 81eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 82eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified value and an implied Type. The 83eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// type is the integer type that corresponds to the bit width of the value. 842c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *get(LLVMContext &Context, const APInt &V); 850e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar 860e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar /// Return a ConstantInt constructed from the string strStart with the given 870e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar /// radix. 882928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar static ConstantInt *get(const IntegerType *Ty, StringRef Str, 890e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar uint8_t radix); 90eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 91eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// If Ty is a vector type, return a Constant with a splat of the given 92eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value. Otherwise return a ConstantInt for the given value. 932c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const Type* Ty, const APInt& V); 94eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 95532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// Return the constant as an APInt value reference. This allows clients to 96532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// obtain a copy of the value, with all its precision in tact. 97532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// @brief Return the constant's value. 982c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner inline const APInt &getValue() const { 99532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val; 100532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer } 101e51f2a59d93336b2be46b9663af317b96a7e045bChris Lattner 102e51f2a59d93336b2be46b9663af317b96a7e045bChris Lattner /// getBitWidth - Return the bitwidth of this constant. 103e51f2a59d93336b2be46b9663af317b96a7e045bChris Lattner unsigned getBitWidth() const { return Val.getBitWidth(); } 104532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer 1050b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// Return the constant as a 64-bit unsigned integer value after it 106532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// has been zero extended as appropriate for the type of this constant. Note 107532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// that this method can assert if the value does not fit in 64 bits. 108532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// @deprecated 1090b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Return the zero extended value. 110a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner inline uint64_t getZExtValue() const { 111532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.getZExtValue(); 112a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner } 113c2dfb8bb909b0ba08733be94821513aef9467fa0Chris Lattner 1140b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// Return the constant as a 64-bit integer value after it has been sign 1157b048b391f9ded004170a67780d1c6a5eedeb604Bob Wilson /// extended as appropriate for the type of this constant. Note that 116532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// this method can assert if the value does not fit in 64 bits. 117532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// @deprecated 1186c6b6a77c0f68d5a41e94d8ef0b1093089e683faChris Lattner /// @brief Return the sign extended value. 119a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner inline int64_t getSExtValue() const { 120532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.getSExtValue(); 121a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner } 122532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer 1230b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// A helper method that can be used to determine if the constant contained 1240b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// within is equal to a constant. This only works for very small values, 1250b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// because this is all that can be represented with all types. 1260b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Determine if this constant's value is same as an unsigned char. 127532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer bool equalsInt(uint64_t V) const { 128b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer return Val == V; 1292ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner } 1302ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner 131c10305743c313558405079452138f03124e87581Reid Spencer /// getType - Specialize the getType() method to always return an IntegerType, 132c10305743c313558405079452138f03124e87581Reid Spencer /// which reduces the amount of casting needed in parts of the compiler. 133c10305743c313558405079452138f03124e87581Reid Spencer /// 134c10305743c313558405079452138f03124e87581Reid Spencer inline const IntegerType *getType() const { 135c10305743c313558405079452138f03124e87581Reid Spencer return reinterpret_cast<const IntegerType*>(Value::getType()); 136c10305743c313558405079452138f03124e87581Reid Spencer } 137c10305743c313558405079452138f03124e87581Reid Spencer 1380b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// This static method returns true if the type Ty is big enough to 1390b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// represent the value V. This can be used to avoid having the get method 1406d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// assert when V is larger than Ty can represent. Note that there are two 1416d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// versions of this method, one for unsigned and one for signed integers. 1426d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// Although ConstantInt canonicalizes everything to an unsigned integer, 1436d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// the signed version avoids callers having to convert a signed quantity 1446d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// to the appropriate unsigned type before calling the method. 1450b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true if V is a valid value for type Ty 1460b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Determine if the value is in range for the given type. 1479b11d518aef8e191e5e94f3503dfddbe1c0a387aReid Spencer static bool isValueValidForType(const Type *Ty, uint64_t V); 148009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner static bool isValueValidForType(const Type *Ty, int64_t V); 14993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner 1506b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// This function will return true iff this constant represents the "null" 1516b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// value that would be returned by the getNullValue method. 152b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer /// @returns true if this is the null integer value. 1536b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is null. 1546b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng virtual bool isNullValue() const { 1556b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng return Val == 0; 1566b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng } 1575ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 15834da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// This is just a convenience method to make client code smaller for a 15934da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// common code. It also correctly performs the comparison without the 16034da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// potential for an assertion from getZExtValue(). 16134da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer bool isZero() const { 16234da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer return Val == 0; 16334da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer } 16434da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer 16537eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer /// This is just a convenience method to make client code smaller for a 16634da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// common case. It also correctly performs the comparison without the 16734da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// potential for an assertion from getZExtValue(). 16837eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer /// @brief Determine if the value is one. 16934da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer bool isOne() const { 17037eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer return Val == 1; 17137eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer } 17237eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer 1736b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// This function will return true iff every bit in this constant is set 1746b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// to true. 1750b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true iff this constant's bits are all set to true. 1766b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is all ones. 177579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer bool isAllOnesValue() const { 178532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isAllOnesValue(); 1796b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng } 1801680312867fffeb9369800949b809e0b9e29a914Chris Lattner 1816b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// This function will return true iff this constant represents the largest 1826b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// value that may be represented by the constant's type. 1830b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true iff this is the largest value that may be represented 1840b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// by this type. 1856b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is maximal. 186579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer bool isMaxValue(bool isSigned) const { 187532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer if (isSigned) 188532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMaxSignedValue(); 189532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer else 190532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMaxValue(); 191994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner } 192994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner 1936b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// This function will return true iff this constant represents the smallest 1946b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// value that may be represented by this constant's type. 1950b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true if this is the smallest value that may be represented by 1960b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// this type. 1976b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is minimal. 198579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer bool isMinValue(bool isSigned) const { 199532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer if (isSigned) 200532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMinSignedValue(); 201532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer else 202532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMinValue(); 203994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner } 204994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner 205b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// This function will return true iff this constant represents a value with 206b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// active bits bigger than 64 bits or a value greater than the given uint64_t 207b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// value. 208b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// @returns true iff this constant is greater or equal to the given number. 209b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// @brief Determine if the value is greater or equal to the given number. 2100642f75836960afd547a6b98fad33026d0c355beZhou Sheng bool uge(uint64_t Num) { 2110642f75836960afd547a6b98fad33026d0c355beZhou Sheng return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num; 212b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng } 213b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng 214edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// getLimitedValue - If the value is smaller than the specified limit, 215edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// return it, otherwise return the limit value. This causes the value 216edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// to saturate to the limit. 217edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// @returns the min of the value of the constant and the specified value 218edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// @brief Get the constant's value with a saturation limit 21999b1b38818e3a1628e39af40500bad47d5207d0dChris Lattner uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const { 22099b1b38818e3a1628e39af40500bad47d5207d0dChris Lattner return Val.getLimitedValue(Limit); 221b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng } 222b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng 223b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer /// @brief Methods to support type inquiry through isa, cast, and dyn_cast. 224b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer static inline bool classof(const ConstantInt *) { return true; } 22552eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 226a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantIntVal; 2275ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 228009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 229009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 230009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 23186e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 23293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantFP - Floating Point Values [float, double] 23393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 234e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantFP : public Constant { 235343e770983dcf53a1ea2dfca4e04d28ebc41138aDale Johannesen APFloat Val; 236051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned);// DO NOT IMPLEMENT 237e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT 23812ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramer friend class LLVMContextImpl; 2393e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 240f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen ConstantFP(const Type *Ty, const APFloat& V); 241051a950000e21935165db56695e35bade668193bGabor Greifprotected: 242051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 243051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 244051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 245051a950000e21935165db56695e35bade668193bGabor Greif } 246009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 2476f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// Floating point negation must be implemented with f(x) = -0.0 - x. This 2486f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// method returns the negative zero constant for floating point or vector 2496f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// floating point types; for all other types, it returns the null value. 2502c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getZeroValueForNegation(const Type *Ty); 2516f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson 2526f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// get() - This returns a ConstantFP, or a vector containing a splat of a 2536f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// ConstantFP, for the specified value in the specified type. This should 2546f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// only be used for simple constant values like 2.0/1.0 etc, that are 2556f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// known-valid both as host double and as the target format. 2562c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const Type* Ty, double V); 2572928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar static Constant *get(const Type* Ty, StringRef Str); 2582c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantFP *get(LLVMContext &Context, const APFloat &V); 2592c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantFP *getNegativeZero(const Type* Ty); 2602c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantFP *getInfinity(const Type *Ty, bool Negative = false); 2616f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson 26293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isValueValidForType - return true if Ty is big enough to represent V. 2632c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static bool isValueValidForType(const Type *Ty, const APFloat &V); 264f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen inline const APFloat& getValueAPF() const { return Val; } 2655ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 26693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 2678d64989275b8708a4545934a52ddef5284d473b8Chris Lattner /// getNullValue. For ConstantFP, this is +0.0, but not -0.0. To handle the 2688d64989275b8708a4545934a52ddef5284d473b8Chris Lattner /// two the same, use isZero(). 2693a1eff732b36a663cdb9f07f4a9ccae6452eadcbJim Laskey virtual bool isNullValue() const; 270fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson 271fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson /// isNegativeZeroValue - Return true if the value is what would be returned 272fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson /// by getZeroValueForNegation. 273fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson virtual bool isNegativeZeroValue() const { 274fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson return Val.isZero() && Val.isNegative(); 275fa82b6eba4e1584d7dba291c28fe908272e1e002Owen Anderson } 2760eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner 277e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman /// isZero - Return true if the value is positive or negative zero. 278e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman bool isZero() const { return Val.isZero(); } 279e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman 280e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman /// isNaN - Return true if the value is a NaN. 281e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman bool isNaN() const { return Val.isNaN(); } 282e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman 283f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// isExactlyValue - We don't rely on operator== working on double values, as 284f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// it returns true for things that are clearly not equal, like -0.0 and 0.0. 285f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// As such, this method can be used to do an exact bit-for-bit comparison of 28643421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen /// two floating point values. The version with a double operand is retained 28743421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen /// because it's so convenient to write isExactlyValue(2.0), but please use 288def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner /// it only for simple constants. 2892c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner bool isExactlyValue(const APFloat &V) const; 29043421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen 291f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen bool isExactlyValue(double V) const { 2928aaec36fa760c9dd50627e397ca85798d9eb6e79Dale Johannesen bool ignored; 293beb5be03320f9bbe6a4a92b0c7e1e0ebf3ef865dDale Johannesen // convert is not supported on this type 294beb5be03320f9bbe6a4a92b0c7e1e0ebf3ef865dDale Johannesen if (&Val.getSemantics() == &APFloat::PPCDoubleDouble) 295beb5be03320f9bbe6a4a92b0c7e1e0ebf3ef865dDale Johannesen return false; 296def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner APFloat FV(V); 2978aaec36fa760c9dd50627e397ca85798d9eb6e79Dale Johannesen FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored); 298def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner return isExactlyValue(FV); 299f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen } 30093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 301e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner static inline bool classof(const ConstantFP *) { return true; } 30252eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 303a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantFPVal; 3045ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 305009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 306009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 30786e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 30840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// ConstantAggregateZero - All zero aggregate value 30940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// 31040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerclass ConstantAggregateZero : public Constant { 31140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner friend struct ConstantCreator<ConstantAggregateZero, Type, char>; 312051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 31340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT 31440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerprotected: 31513d57320bd212483463d4f8992d5787b29eda5dfBill Wendling explicit ConstantAggregateZero(const Type *ty) 31613d57320bd212483463d4f8992d5787b29eda5dfBill Wendling : Constant(ty, ConstantAggregateZeroVal, 0, 0) {} 317051a950000e21935165db56695e35bade668193bGabor Greifprotected: 318051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 319051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 320051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 321051a950000e21935165db56695e35bade668193bGabor Greif } 32240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerpublic: 3232c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantAggregateZero* get(const Type *Ty); 3249e9a0d5fc26878e51a58a8b57900fcbf952c2691Owen Anderson 32540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 32640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// getNullValue. 32740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner virtual bool isNullValue() const { return true; } 32840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner 32904fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 33040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner 33140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 33240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// 33352eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const ConstantAggregateZero *) { return true; } 33452eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 335a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantAggregateZeroVal; 33640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner } 33740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner}; 33840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner 339009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 34086e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 34193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantArray - Constant Array Declarations 34293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 343e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantArray : public Constant { 3446cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantArray, ArrayType, 3456cc89aad25155ecd93b5318414851aa46351196dChris Lattner std::vector<Constant*> >; 346e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner ConstantArray(const ConstantArray &); // DO NOT IMPLEMENT 3473e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 348697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner ConstantArray(const ArrayType *T, const std::vector<Constant*> &Val); 349009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 3501fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson // ConstantArray accessors 3512c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const ArrayType *T, const std::vector<Constant*> &V); 3522c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const ArrayType *T, Constant *const *Vals, 3531fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson unsigned NumVals); 3541fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson 3551fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// This method constructs a ConstantArray and initializes it with a text 3561fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// string. The default behavior (AddNull==true) causes a null terminator to 3571fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// be placed at the end of the array. This effectively increases the length 3581fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// of the array by one (you've been warned). However, in some situations 3591fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// this is not desired so if AddNull==false then the string is copied without 3601fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson /// null termination. 3612928c83b010f7cfdb0f819199d806f6942a7d995Daniel Dunbar static Constant *get(LLVMContext &Context, StringRef Initializer, 3621d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson bool AddNull = true); 3631fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson 364efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 365efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 366efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 36793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getType - Specialize the getType() method to always return an ArrayType, 36893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// which reduces the amount of casting needed in parts of the compiler. 36993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// 370682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner inline const ArrayType *getType() const { 3718b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner return reinterpret_cast<const ArrayType*>(Value::getType()); 372682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner } 373009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 3746eabd74d1a236effc6757e7c81182fa1ecd52ac6Nick Lewycky /// isString - This method returns true if the array is an array of i8 and 3756eabd74d1a236effc6757e7c81182fa1ecd52ac6Nick Lewycky /// the elements of the array are all ConstantInt's. 3769b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner bool isString() const; 3779b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner 37822c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng /// isCString - This method returns true if the array is a string (see 379181b6c9cb5def44658d15848e34c5c45d973f065Reid Spencer /// @verbatim 38022c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng /// isString) and it ends in a null byte \0 and does not contains any other 381181b6c9cb5def44658d15848e34c5c45d973f065Reid Spencer /// @endverbatim 38222c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng /// null bytes except its terminator. 3831ca29d318a6632c115b9f62c791077b575494e42Owen Anderson bool isCString() const; 38422c7030a0c535ed48d8465994f8f8aaf8fa76813Evan Cheng 3859b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner /// getAsString - If this array is isString(), then this method converts the 3869b0a5ee5bb77b5f74320f3603750f4521d16d196Chris Lattner /// array to an std::string and returns it. Otherwise, it asserts out. 38793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// 38893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner std::string getAsString() const; 38993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner 39093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 39140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// getNullValue. This always returns false because zero arrays are always 39240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// created as ConstantAggregateZero objects. 39340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner virtual bool isNullValue() const { return false; } 3940eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner 39504fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 39640cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 397e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner 39893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 399e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner static inline bool classof(const ConstantArray *) { return true; } 40052eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 401a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantArrayVal; 4025ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 403009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 404009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 405efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 40667c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<ConstantArray> : 40767c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public VariadicOperandTraits<ConstantArray> { 408efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 409efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 410efe65369a74871c3140a540a6c95ce5d1f080954Gabor GreifDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantArray, Constant) 411009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 41286e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 413e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner// ConstantStruct - Constant Struct Declarations 414009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner// 415e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantStruct : public Constant { 4166cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantStruct, StructType, 4176cc89aad25155ecd93b5318414851aa46351196dChris Lattner std::vector<Constant*> >; 418e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner ConstantStruct(const ConstantStruct &); // DO NOT IMPLEMENT 4193e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 420697954c15da58bd8b186dbafdedd8b06db770201Chris Lattner ConstantStruct(const StructType *T, const std::vector<Constant*> &Val); 421009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 4228fa3338ed2400c1352b137613d2c2c70d1ead695Owen Anderson // ConstantStruct accessors 4232c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const StructType *T, const std::vector<Constant*> &V); 4242c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(LLVMContext &Context, 4252c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner const std::vector<Constant*> &V, bool Packed); 4262c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(LLVMContext &Context, 4272c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner Constant *const *Vals, unsigned NumVals, bool Packed); 42841ee4e57ea0f2afb89fd136065edb03f32f972d3Talin static Constant *get(LLVMContext &Context, bool Packed, 42941ee4e57ea0f2afb89fd136065edb03f32f972d3Talin Constant * Val, ...) END_WITH_NULL; 430c332fba8285e35a5a11463c34795af84f3960759Nick Lewycky 431efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 432efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 433efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 43493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getType() specialization - Reduce amount of casting... 435c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner /// 436682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner inline const StructType *getType() const { 4378b70b78ba489b090d9866e6a4084ab1e8613b527Chris Lattner return reinterpret_cast<const StructType*>(Value::getType()); 438682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner } 439009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 44093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 44140bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// getNullValue. This always returns false because zero structs are always 44240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// created as ConstantAggregateZero objects. 443a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner virtual bool isNullValue() const { 44440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner return false; 445a5ae71a137b9c6f458cc6c9064be787dbc5f4311Chris Lattner } 4460eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner 44704fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 44840cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 4499769ab22265b313171d201b5928688524a01bd87Misha Brukman 45093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 451e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner static inline bool classof(const ConstantStruct *) { return true; } 45252eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 453a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantStructVal; 4545ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 455009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 456009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 457efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 45867c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<ConstantStruct> : 45967c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public VariadicOperandTraits<ConstantStruct> { 460efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 461efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 462efe65369a74871c3140a540a6c95ce5d1f080954Gabor GreifDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantStruct, Constant) 463efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 464fdfeb6976f07ad10d809b922ed7376ba2a3539beChris Lattner 465fdfeb6976f07ad10d809b922ed7376ba2a3539beChris Lattner//===----------------------------------------------------------------------===// 4669d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer/// ConstantVector - Constant Vector Declarations 467715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke/// 4689d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencerclass ConstantVector : public Constant { 4699d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer friend struct ConstantCreator<ConstantVector, VectorType, 470715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke std::vector<Constant*> >; 4719d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer ConstantVector(const ConstantVector &); // DO NOT IMPLEMENT 472715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeprotected: 4739d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer ConstantVector(const VectorType *T, const std::vector<Constant*> &Val); 474715c90ba524e736190a6380695ab337eeb5148beBrian Gaekepublic: 475af7ec975870f92245f1f1484ac80a1e2db6a0afaOwen Anderson // ConstantVector accessors 4762ca5c8644e6c35b3a7910a576ed89cddb7b82c3bChris Lattner static Constant *get(ArrayRef<Constant*> V); 4772ca5c8644e6c35b3a7910a576ed89cddb7b82c3bChris Lattner // FIXME: Eliminate this constructor form. 4782c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *get(const VectorType *T, const std::vector<Constant*> &V); 479af7ec975870f92245f1f1484ac80a1e2db6a0afaOwen Anderson 480efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 481efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 482efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 483fa73ea2d9fd785a214256ca44488407b26c5a3dbDan Gohman /// getType - Specialize the getType() method to always return a VectorType, 484715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// which reduces the amount of casting needed in parts of the compiler. 485715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// 4869d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer inline const VectorType *getType() const { 4879d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer return reinterpret_cast<const VectorType*>(Value::getType()); 488715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke } 48958513aa1c22a08118734ac799d935ea2910db35aChris Lattner 490715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// isNullValue - Return true if this is the value that would be returned by 49107a96765daedf180a7102d39fe56c499878312b7Dan Gohman /// getNullValue. This always returns false because zero vectors are always 492715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// created as ConstantAggregateZero objects. 493715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke virtual bool isNullValue() const { return false; } 494715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke 495fa73ea2d9fd785a214256ca44488407b26c5a3dbDan Gohman /// This function will return true iff every element in this vector constant 496fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey /// is set to all ones. 497fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey /// @returns true iff this constant's emements are all set to all ones. 498fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey /// @brief Determine if the value is all ones. 499569cc890e8822c265cec66745791edbd510dac1cJim Laskey bool isAllOnesValue() const; 500fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey 5013b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman /// getSplatValue - If this is a splat constant, meaning that all of the 5023b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman /// elements have the same value, return that value. Otherwise return NULL. 5037681c6da606efcc392f76b8acea8301cb5fc7a0aDuncan Sands Constant *getSplatValue() const; 5043b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman 50504fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 50640cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 507715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke 508715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// Methods for support type inquiry through isa, cast, and dyn_cast: 5099d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer static inline bool classof(const ConstantVector *) { return true; } 510715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke static bool classof(const Value *V) { 511a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantVectorVal; 512715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke } 513715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke}; 514715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke 515efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 51667c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<ConstantVector> : 51767c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public VariadicOperandTraits<ConstantVector> { 518efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 519efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 520efe65369a74871c3140a540a6c95ce5d1f080954Gabor GreifDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantVector, Constant) 521efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 52286e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 52393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantPointerNull - a constant pointer value that points to null 52493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 52548babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattnerclass ConstantPointerNull : public Constant { 5266cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantPointerNull, PointerType, char>; 527051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 528e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT 5295ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerprotected: 530423c2260f95883f7c84ac962e58ac66c3a11efacDan Gohman explicit ConstantPointerNull(const PointerType *T) 5315181ac8081dd6c7d78613a5da8829f81a81e9e63Chris Lattner : Constant(reinterpret_cast<const Type*>(T), 532225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner Value::ConstantPointerNullVal, 0, 0) {} 533afba8fe662d65b25b4baf46bb26cc18e1f9cc0a5Gordon Henriksen 534051a950000e21935165db56695e35bade668193bGabor Greifprotected: 535051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 536051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 537051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 538051a950000e21935165db56695e35bade668193bGabor Greif } 5395ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerpublic: 54093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// get() - Static factory methods - Return objects of the specified value 54104fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static ConstantPointerNull *get(const PointerType *T); 5425ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 54393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 54493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getNullValue. 5450eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner virtual bool isNullValue() const { return true; } 5460eca13bf58e0a1d6b492ca257d01abc19c4024daChris Lattner 54704fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 548e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner 5490f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// getType - Specialize the getType() method to always return an PointerType, 5500f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// which reduces the amount of casting needed in parts of the compiler. 5510f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// 5520f42ba67771627453187e44fea935d6bab7a8152Chris Lattner inline const PointerType *getType() const { 5530f42ba67771627453187e44fea935d6bab7a8152Chris Lattner return reinterpret_cast<const PointerType*>(Value::getType()); 5540f42ba67771627453187e44fea935d6bab7a8152Chris Lattner } 5550f42ba67771627453187e44fea935d6bab7a8152Chris Lattner 55693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 557e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner static inline bool classof(const ConstantPointerNull *) { return true; } 55852eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 559a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantPointerNullVal; 5605ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 5614cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner}; 5624cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner 5632ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner/// BlockAddress - The address of a basic block. 5642ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner/// 5652ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnerclass BlockAddress : public Constant { 5662ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 5672ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner void *operator new(size_t s) { return User::operator new(s, 2); } 5682ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner BlockAddress(Function *F, BasicBlock *BB); 5692ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnerpublic: 5702ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// get - Return a BlockAddress for the specified function and basic block. 5712ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static BlockAddress *get(Function *F, BasicBlock *BB); 5722ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5732ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// get - Return a BlockAddress for the specified basic block. The basic 5742ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// block must be embedded into a function. 5752ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static BlockAddress *get(BasicBlock *BB); 5762ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5772ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// Transparently provide more efficient getOperand methods. 5780eeb913aa17a68b1f2963b02ca1d68f09dba0b78Chris Lattner DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 5792ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5802ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner Function *getFunction() const { return (Function*)Op<0>().get(); } 5812ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); } 5822ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5832ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// isNullValue - Return true if this is the value that would be returned by 5842ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// getNullValue. 5852ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner virtual bool isNullValue() const { return false; } 5862ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5872ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner virtual void destroyConstant(); 5882ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 5892ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5902ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 5912ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static inline bool classof(const BlockAddress *) { return true; } 5922ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static inline bool classof(const Value *V) { 5932ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner return V->getValueID() == BlockAddressVal; 5942ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner } 5952ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner}; 5962ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 5972ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnertemplate <> 59867c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<BlockAddress> : 59967c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public FixedNumOperandTraits<BlockAddress, 2> { 6002ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner}; 601f4ba6c710c298fe9b492b9cde82ce5efd46afd5dChris Lattner 6020eeb913aa17a68b1f2963b02ca1d68f09dba0b78Chris LattnerDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(BlockAddress, Value) 6032ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 6041c5730facaefbacd66badea74c83571a16611bd4Jin-Gu Kang 6052ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner//===----------------------------------------------------------------------===// 60686e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// ConstantExpr - a constant value that is initialized with an expression using 607eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// other constant values. 60886e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// 609eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// This class uses the standard Instruction opcodes to define the various 610eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// constant expressions. The Opcode field for the ConstantExpr class is 611eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// maintained in the Value::SubclassData field. 61229ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adveclass ConstantExpr : public Constant { 6136cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantExpr,Type, 6146cc89aad25155ecd93b5318414851aa46351196dChris Lattner std::pair<unsigned, std::vector<Constant*> > >; 6155f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patel friend struct ConvertConstantType<ConstantExpr, Type>; 6169769ab22265b313171d201b5928688524a01bd87Misha Brukman 6176cc89aad25155ecd93b5318414851aa46351196dChris Lattnerprotected: 61813d57320bd212483463d4f8992d5787b29eda5dfBill Wendling ConstantExpr(const Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps) 61913d57320bd212483463d4f8992d5787b29eda5dfBill Wendling : Constant(ty, ConstantExprVal, Ops, NumOps) { 620eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner // Operation type (an Instruction opcode) is stored as the SubclassData. 621cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner setValueSubclassData(Opcode); 622eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner } 6235133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner 6245133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner // These private methods are used by the type resolution code to create 6255133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner // ConstantExprs in intermediate forms. 6265133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner static Constant *getTy(const Type *Ty, unsigned Opcode, 627f8dbee7cea072eb63ae343759975109553697bcbDan Gohman Constant *C1, Constant *C2, 628f8dbee7cea072eb63ae343759975109553697bcbDan Gohman unsigned Flags = 0); 629ff795a80a35dc99a1971646de11f088e71d0a2c6Nate Begeman static Constant *getCompareTy(unsigned short pred, Constant *C1, 630ff795a80a35dc99a1971646de11f088e71d0a2c6Nate Begeman Constant *C2); 63104fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getSelectTy(const Type *Ty, 63204fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson Constant *C1, Constant *C2, Constant *C3); 63325052d8d64f18a85d6a84e0e010f6ba3eba0760dJay Foad template<typename IndexTy> 6345133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner static Constant *getGetElementPtrTy(const Type *Ty, Constant *C, 6351f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner IndexTy const *Idxs, unsigned NumIdxs, 6361f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner bool InBounds); 63749b78a569609881811d905960baa7dd1ab801383Robert Bocchino static Constant *getExtractElementTy(const Type *Ty, Constant *Val, 63849b78a569609881811d905960baa7dd1ab801383Robert Bocchino Constant *Idx); 639f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino static Constant *getInsertElementTy(const Type *Ty, Constant *Val, 640f999344fa74199f5acefbc492af2b60e67d0ba24Robert Bocchino Constant *Elt, Constant *Idx); 6419fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getShuffleVectorTy(const Type *Ty, Constant *V1, 6429fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner Constant *V2, Constant *Mask); 643041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getExtractValueTy(const Type *Ty, Constant *Agg, 64481a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const unsigned *Idxs, unsigned NumIdxs); 645041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getInsertValueTy(const Type *Ty, Constant *Agg, 646041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman Constant *Val, 64781a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const unsigned *Idxs, unsigned NumIdxs); 64825052d8d64f18a85d6a84e0e010f6ba3eba0760dJay Foad template<typename IndexTy> 64925052d8d64f18a85d6a84e0e010f6ba3eba0760dJay Foad static Constant *getGetElementPtrImpl(Constant *C, 65025052d8d64f18a85d6a84e0e010f6ba3eba0760dJay Foad IndexTy const *IdxList, 6511f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner unsigned NumIdx, bool InBounds); 6529769ab22265b313171d201b5928688524a01bd87Misha Brukman 65329ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Advepublic: 654fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner // Static methods to construct a ConstantExpr of different kinds. Note that 655baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // these methods may return a object that is not an instance of the 656baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // ConstantExpr class, because they will attempt to fold the constant 657baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // expression into something simpler if possible. 6589769ab22265b313171d201b5928688524a01bd87Misha Brukman 659baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// getAlignOf constant expr - computes the alignment of a type in a target 66006ed3e788ab3d71350b7cc7d077f4bd9a2b57799Dan Gohman /// independent way (Note: the return type is an i64). 66181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getAlignOf(const Type *Ty); 662baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson 663a5a23046cbea6d011f84c97ac61743cb8f6a58c6Dan Gohman /// getSizeOf constant expr - computes the (alloc) size of a type (in 664a5a23046cbea6d011f84c97ac61743cb8f6a58c6Dan Gohman /// address-units, not bits) in a target independent way (Note: the return 665a5a23046cbea6d011f84c97ac61743cb8f6a58c6Dan Gohman /// type is an i64). 666baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// 66781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getSizeOf(const Type *Ty); 6683778f21b17e675c2fd1600901361fa4a73888ebaDan Gohman 6692544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// getOffsetOf constant expr - computes the offset of a struct field in a 6702544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// target independent way (Note: the return type is an i64). 6712544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// 67281baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getOffsetOf(const StructType *STy, unsigned FieldNo); 6732544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman 6742544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// getOffsetOf constant expr - This is a generalized form of getOffsetOf, 6752544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// which supports any aggregate type, and any Constant index. 6763778f21b17e675c2fd1600901361fa4a73888ebaDan Gohman /// 67781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getOffsetOf(const Type *Ty, Constant *FieldNo); 678baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson 67981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false); 6802c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFNeg(Constant *C); 6812c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getNot(Constant *C); 68281baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getAdd(Constant *C1, Constant *C2, 68381baf14fdfa29c22a08d609144c285169e23a247Chris Lattner bool HasNUW = false, bool HasNSW = false); 6842c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFAdd(Constant *C1, Constant *C2); 68581baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getSub(Constant *C1, Constant *C2, 68681baf14fdfa29c22a08d609144c285169e23a247Chris Lattner bool HasNUW = false, bool HasNSW = false); 6872c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFSub(Constant *C1, Constant *C2); 68881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getMul(Constant *C1, Constant *C2, 68981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner bool HasNUW = false, bool HasNSW = false); 6902c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFMul(Constant *C1, Constant *C2); 69174f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false); 69274f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false); 6932c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFDiv(Constant *C1, Constant *C2); 6942c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getURem(Constant *C1, Constant *C2); 6952c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getSRem(Constant *C1, Constant *C2); 6962c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFRem(Constant *C1, Constant *C2); 6972c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getAnd(Constant *C1, Constant *C2); 6982c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getOr(Constant *C1, Constant *C2); 6992c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getXor(Constant *C1, Constant *C2); 70081baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getShl(Constant *C1, Constant *C2, 70181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner bool HasNUW = false, bool HasNSW = false); 70274f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false); 70374f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false); 70404fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getTrunc (Constant *C, const Type *Ty); 70504fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getSExt (Constant *C, const Type *Ty); 70604fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getZExt (Constant *C, const Type *Ty); 70704fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getFPTrunc (Constant *C, const Type *Ty); 70804fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getFPExtend(Constant *C, const Type *Ty); 70904fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getUIToFP (Constant *C, const Type *Ty); 71004fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getSIToFP (Constant *C, const Type *Ty); 71104fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getFPToUI (Constant *C, const Type *Ty); 71204fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getFPToSI (Constant *C, const Type *Ty); 71304fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getPtrToInt(Constant *C, const Type *Ty); 71404fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getIntToPtr(Constant *C, const Type *Ty); 71504fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getBitCast (Constant *C, const Type *Ty); 7163da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 71781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); } 71881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); } 71981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWAdd(Constant *C1, Constant *C2) { 72081baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getAdd(C1, C2, false, true); 72181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 72281baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWAdd(Constant *C1, Constant *C2) { 72381baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getAdd(C1, C2, true, false); 72481baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 72581baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWSub(Constant *C1, Constant *C2) { 72681baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getSub(C1, C2, false, true); 72781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 72881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWSub(Constant *C1, Constant *C2) { 72981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getSub(C1, C2, true, false); 73081baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 73181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWMul(Constant *C1, Constant *C2) { 73281baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getMul(C1, C2, false, true); 73381baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 73481baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWMul(Constant *C1, Constant *C2) { 73581baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getMul(C1, C2, true, false); 73681baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 73781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWShl(Constant *C1, Constant *C2) { 73881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getShl(C1, C2, false, true); 73981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 74081baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWShl(Constant *C1, Constant *C2) { 74181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getShl(C1, C2, true, false); 74281baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 74374f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getExactSDiv(Constant *C1, Constant *C2) { 74474f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner return getSDiv(C1, C2, true); 74574f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner } 74674f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getExactUDiv(Constant *C1, Constant *C2) { 74774f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner return getUDiv(C1, C2, true); 74874f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner } 74974f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getExactAShr(Constant *C1, Constant *C2) { 75074f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner return getAShr(C1, C2, true); 75174f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner } 75274f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getExactLShr(Constant *C1, Constant *C2) { 75374f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner return getLShr(C1, C2, true); 75474f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner } 7556e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman 756efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 757efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 758efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 7593da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer // @brief Convenience function for getting one of the casting operations 7603da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer // using a CastOps opcode. 7613da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer static Constant *getCast( 7623da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer unsigned ops, ///< The opcode for the conversion 7633da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer Constant *C, ///< The constant to be converted 76404fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson const Type *Ty ///< The type to which the constant is converted 7653da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer ); 7663da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 767848414e49c7600e3002a4366de52d03a9638b327Reid Spencer // @brief Create a ZExt or BitCast cast constant expression 768848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getZExtOrBitCast( 769848414e49c7600e3002a4366de52d03a9638b327Reid Spencer Constant *C, ///< The constant to zext or bitcast 770848414e49c7600e3002a4366de52d03a9638b327Reid Spencer const Type *Ty ///< The type to zext or bitcast C to 771848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 772848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 773848414e49c7600e3002a4366de52d03a9638b327Reid Spencer // @brief Create a SExt or BitCast cast constant expression 774848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getSExtOrBitCast( 77590fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer Constant *C, ///< The constant to sext or bitcast 77604fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson const Type *Ty ///< The type to sext or bitcast C to 777848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 778848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 779848414e49c7600e3002a4366de52d03a9638b327Reid Spencer // @brief Create a Trunc or BitCast cast constant expression 780848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getTruncOrBitCast( 78190fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer Constant *C, ///< The constant to trunc or bitcast 78290fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer const Type *Ty ///< The type to trunc or bitcast C to 783848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 784848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 785887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer /// @brief Create a BitCast or a PtrToInt cast constant expression 786887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer static Constant *getPointerCast( 787887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer Constant *C, ///< The pointer value to be casted (operand 0) 78804fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson const Type *Ty ///< The type to which cast should be made 789887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer ); 790887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer 79184f3eab017d56b6854155f2350759dc77ac48aadReid Spencer /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts 79284f3eab017d56b6854155f2350759dc77ac48aadReid Spencer static Constant *getIntegerCast( 79384f3eab017d56b6854155f2350759dc77ac48aadReid Spencer Constant *C, ///< The integer constant to be casted 79484f3eab017d56b6854155f2350759dc77ac48aadReid Spencer const Type *Ty, ///< The integer type to cast to 79584f3eab017d56b6854155f2350759dc77ac48aadReid Spencer bool isSigned ///< Whether C should be treated as signed or not 79684f3eab017d56b6854155f2350759dc77ac48aadReid Spencer ); 79784f3eab017d56b6854155f2350759dc77ac48aadReid Spencer 79884f3eab017d56b6854155f2350759dc77ac48aadReid Spencer /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts 79984f3eab017d56b6854155f2350759dc77ac48aadReid Spencer static Constant *getFPCast( 80084f3eab017d56b6854155f2350759dc77ac48aadReid Spencer Constant *C, ///< The integer constant to be casted 80184f3eab017d56b6854155f2350759dc77ac48aadReid Spencer const Type *Ty ///< The integer type to cast to 80284f3eab017d56b6854155f2350759dc77ac48aadReid Spencer ); 80384f3eab017d56b6854155f2350759dc77ac48aadReid Spencer 8043da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer /// @brief Return true if this is a convert constant expression 8053da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer bool isCast() const; 8063da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 8074b94f49091be8e26ce6e49db1268458995299b82Reid Spencer /// @brief Return true if this is a compare constant expression 8084b94f49091be8e26ce6e49db1268458995299b82Reid Spencer bool isCompare() const; 8094b94f49091be8e26ce6e49db1268458995299b82Reid Spencer 81081a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// @brief Return true if this is an insertvalue or extractvalue expression, 81181a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// and the getIndices() method may be used. 81281a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman bool hasIndices() const; 81381a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman 814e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// @brief Return true if this is a getelementptr expression and all 815e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// the index operands are compile-time known integers within the 816e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// corresponding notional static array extents. Note that this is 817e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// not equivalant to, a subset of, or a superset of the "inbounds" 818e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// property. 819e6992f728a94654e43269580a10a667f18dadba9Dan Gohman bool isGEPWithNoNotionalOverIndexing() const; 820e6992f728a94654e43269580a10a667f18dadba9Dan Gohman 82146a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner /// Select constant expr 82246a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner /// 82346a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner static Constant *getSelect(Constant *C, Constant *V1, Constant *V2) { 82446a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner return getSelectTy(V1->getType(), C, V1, V2); 82546a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner } 82646a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner 827baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// get - Return a binary or shift operator constant expression, 8287e208904ae8eeef888c3a6eecd38daa779ca36c9Chris Lattner /// folding if possible. 8295133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner /// 830f8dbee7cea072eb63ae343759975109553697bcbDan Gohman static Constant *get(unsigned Opcode, Constant *C1, Constant *C2, 831f8dbee7cea072eb63ae343759975109553697bcbDan Gohman unsigned Flags = 0); 83290fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer 8337f6aa2b162e5daaf7b9ccf05d749597d3d7cf460Nick Lewycky /// @brief Return an ICmp or FCmp comparison operator constant expression. 834e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2); 835e8e4605021141d689493132a9c7c6fce6294937fChris Lattner 836baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// get* - Return some common constants without having to 8374dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner /// specify the full Instruction::OPCODE identifier. 8384dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner /// 8394647569fe7706e76135a08ca0e5f90a447ccc5b4Gordon Henriksen static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS); 8404647569fe7706e76135a08ca0e5f90a447ccc5b4Gordon Henriksen static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS); 84102140b025d821ca8cefe5086f90f4d8e0c52ae5bChris Lattner 8427fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner /// Getelementptr form. std::vector<Value*> is only accepted for convenience: 8437fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner /// all elements must be Constant's. 8445133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner /// 84504fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getGetElementPtr(Constant *C, 8461f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner Constant *const *IdxList, unsigned NumIdx, 8471f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner bool InBounds = false); 84804fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getGetElementPtr(Constant *C, 8491f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner Value *const *IdxList, unsigned NumIdx, 8501f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner bool InBounds = false); 851e2574d3215c412a15763d26aee9aa5d856764c2cDan Gohman 8526e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman /// Create an "inbounds" getelementptr. See the documentation for the 8536e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman /// "inbounds" flag in LangRef.html for details. 8546e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman static Constant *getInBoundsGetElementPtr(Constant *C, 8552c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner Constant *const *IdxList, 8561f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner unsigned NumIdx) { 8571f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner return getGetElementPtr(C, IdxList, NumIdx, true); 8581f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner } 8596e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman static Constant *getInBoundsGetElementPtr(Constant *C, 8606e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman Value* const *IdxList, 8611f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner unsigned NumIdx) { 8621f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner return getGetElementPtr(C, IdxList, NumIdx, true); 8631f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner } 8646e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman 8659fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getExtractElement(Constant *Vec, Constant *Idx); 8669fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx); 8679fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask); 868041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getExtractValue(Constant *Agg, 86981a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const unsigned *IdxList, unsigned NumIdx); 870041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getInsertValue(Constant *Agg, Constant *Val, 87181a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const unsigned *IdxList, unsigned NumIdx); 872728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer 87393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 87493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getNullValue. 87529ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve virtual bool isNullValue() const { return false; } 8769769ab22265b313171d201b5928688524a01bd87Misha Brukman 87793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getOpcode - Return the opcode at the root of this constant expression 878cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner unsigned getOpcode() const { return getSubclassDataFromValue(); } 87929ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve 880728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is 881728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer /// not an ICMP or FCMP constant expression. 882728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer unsigned getPredicate() const; 883728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer 88481a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// getIndices - Assert that this is an insertvalue or exactvalue 88581a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// expression and return the list of indices. 88681a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman const SmallVector<unsigned, 4> &getIndices() const; 88781a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman 88893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getOpcodeName - Return a string representation for an opcode. 889e8e4605021141d689493132a9c7c6fce6294937fChris Lattner const char *getOpcodeName() const; 8909769ab22265b313171d201b5928688524a01bd87Misha Brukman 89179ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner /// getWithOperandReplaced - Return a constant expression identical to this 89279ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner /// one, but with the specified operand set to the specified value. 89379ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const; 89479ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner 8956b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner /// getWithOperands - This returns the current constant expression with the 8966b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner /// operands replaced with the specified values. The specified operands must 8976b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner /// match count and type with the existing ones. 898b054bfd3ea50d599fe14bce1b74e39b686724dd9Chris Lattner Constant *getWithOperands(const std::vector<Constant*> &Ops) const { 899135ccbd74f041caccfbc26a0c935006dfa828e84Bill Wendling return getWithOperands(&Ops[0], (unsigned)Ops.size()); 900b054bfd3ea50d599fe14bce1b74e39b686724dd9Chris Lattner } 9012c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner Constant *getWithOperands(Constant *const *Ops, unsigned NumOps) const; 90279ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner 90304fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 90440cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 9059769ab22265b313171d201b5928688524a01bd87Misha Brukman 90693aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 90729ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve static inline bool classof(const ConstantExpr *) { return true; } 90829ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve static inline bool classof(const Value *V) { 909a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantExprVal; 91029ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve } 911cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner 912cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattnerprivate: 913cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner // Shadow Value::setValueSubclassData with a private forwarding method so that 914cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner // subclasses cannot accidentally use it. 915cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner void setValueSubclassData(unsigned short D) { 916cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner Value::setValueSubclassData(D); 917cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner } 91829ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve}; 91929ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve 920efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 92167c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<ConstantExpr> : 92267c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public VariadicOperandTraits<ConstantExpr, 1> { 923efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 924efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 925efe65369a74871c3140a540a6c95ce5d1f080954Gabor GreifDEFINE_TRANSPARENT_CASTED_OPERAND_ACCESSORS(ConstantExpr, Constant) 926e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 927e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner//===----------------------------------------------------------------------===// 928e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// UndefValue - 'undef' values are things that do not have specified contents. 929e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// These are used for a variety of purposes, including global variable 930e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// initializers and operands to instructions. 'undef' values can occur with 931fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// any first-class type. 932fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// 933fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// Undef values aren't exactly constants; if they have multiple uses, they 934fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// can appear to have different bit patterns at each use. See 935fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// LangRef.html#undefvalues for details. 936e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// 937e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerclass UndefValue : public Constant { 938e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner friend struct ConstantCreator<UndefValue, Type, char>; 939051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t, unsigned); // DO NOT IMPLEMENT 940e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner UndefValue(const UndefValue &); // DO NOT IMPLEMENT 941e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerprotected: 942423c2260f95883f7c84ac962e58ac66c3a11efacDan Gohman explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {} 943051a950000e21935165db56695e35bade668193bGabor Greifprotected: 944051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 945051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 946051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 947051a950000e21935165db56695e35bade668193bGabor Greif } 948e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerpublic: 949e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// get() - Static factory methods - Return an 'undef' object of the specified 950e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// type. 951e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// 95204fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static UndefValue *get(const Type *T); 953e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 954e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// isNullValue - Return true if this is the value that would be returned by 955e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// getNullValue. 956e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner virtual bool isNullValue() const { return false; } 957e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 95804fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 959e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 960e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 961e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner static inline bool classof(const UndefValue *) { return true; } 962e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner static bool classof(const Value *V) { 963a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == UndefValueVal; 964e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner } 965e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner}; 966fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman 967d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 968d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 969009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif 970