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 114d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak/// This file contains the declarations for the subclasses of Constant, 120b5a504d105514178c80b886321221fbe5ac1131Reid Spencer/// which represent the different flavors of constant values that live in LLVM. 134d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak/// 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 21674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#ifndef LLVM_IR_CONSTANTS_H 22674be02d525d4e24bc6943ed9274958c580bcfbcJakub Staszak#define LLVM_IR_CONSTANTS_H 23009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 24343e770983dcf53a1ea2dfca4e04d28ebc41138aDale Johannesen#include "llvm/ADT/APFloat.h" 25255f89faee13dc491cb64fbeae3c763e7e2ea4e6Chandler Carruth#include "llvm/ADT/APInt.h" 262ca5c8644e6c35b3a7910a576ed89cddb7b82c3bChris Lattner#include "llvm/ADT/ArrayRef.h" 270b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Constant.h" 280b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/OperandTraits.h" 29ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng#include "llvm/IR/DerivedTypes.h" 30009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 31d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm { 32d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 33009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass ArrayType; 34174101e13a6f24f6f2737e043194f0ffae925bb3Benjamin Kramerclass IntegerType; 35009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerclass StructType; 364cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattnerclass PointerType; 379d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencerclass VectorType; 3827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerclass SequentialType; 39009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 406cc89aad25155ecd93b5318414851aa46351196dChris Lattnertemplate<class ConstantClass, class TypeClass, class ValType> 416cc89aad25155ecd93b5318414851aa46351196dChris Lattnerstruct ConstantCreator; 425133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattnertemplate<class ConstantClass, class TypeClass> 432cb395eae71dacda49ca3fe758618fc3e0701659Talinstruct ConstantArrayCreator; 442cb395eae71dacda49ca3fe758618fc3e0701659Talintemplate<class ConstantClass, class TypeClass> 455f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patelstruct ConvertConstantType; 465133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner 4786e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 484d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak/// This is the shared class of boolean and integer constants. This class 496b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// represents both boolean and integral constants. 506b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng/// @brief Class for constant integers. 516b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Shengclass ConstantInt : public Constant { 522d24e2a396a1d211baaeedf32148a3b657240170David Blaikie virtual void anchor(); 530cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 540cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantInt(const ConstantInt &) LLVM_DELETED_FUNCTION; 55db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner ConstantInt(IntegerType *Ty, const APInt& V); 56532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer APInt Val; 57051a950000e21935165db56695e35bade668193bGabor Greifprotected: 58051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 59051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 60051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 61051a950000e21935165db56695e35bade668193bGabor Greif } 62994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattnerpublic: 632c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *getTrue(LLVMContext &Context); 642c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *getFalse(LLVMContext &Context); 65db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getTrue(Type *Ty); 66db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getFalse(Type *Ty); 674d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 68eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// If Ty is a vector type, return a Constant with a splat of the given 69eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value. Otherwise return a ConstantInt for the given value. 70db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *get(Type *Ty, uint64_t V, bool isSigned = false); 714d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 72eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified integer value for the specified 73eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// type. If the type is wider than 64 bits, the value will be zero-extended 74eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// to fit the type, unless isSigned is true, in which case the value will 75eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// be interpreted as a 64-bit signed integer and sign-extended to fit 76eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// the type. 77eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// @brief Get a ConstantInt for a specific value. 78db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static ConstantInt *get(IntegerType *Ty, uint64_t V, 79eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson bool isSigned = false); 80eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson 81eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified value for the specified type. The 82eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value V will be canonicalized to a an unsigned APInt. Accessing it with 83eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// either getSExtValue() or getZExtValue() will yield a correctly sized and 84eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// signed value for the type Ty. 85eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// @brief Get a ConstantInt for a specific signed value. 86db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static ConstantInt *getSigned(IntegerType *Ty, int64_t V); 87db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getSigned(Type *Ty, int64_t V); 884d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 89eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// Return a ConstantInt with the specified value and an implied Type. The 90eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// type is the integer type that corresponds to the bit width of the value. 912c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantInt *get(LLVMContext &Context, const APInt &V); 920e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar 930e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar /// Return a ConstantInt constructed from the string strStart with the given 944d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// radix. 95db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static ConstantInt *get(IntegerType *Ty, StringRef Str, 960e81f660dbb7c437a3c95427bb495eb18822e42cErick Tryzelaar uint8_t radix); 974d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 98eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// If Ty is a vector type, return a Constant with a splat of the given 99eed707b1e6097aac2bb6b3d47271f6300ace7f2eOwen Anderson /// value. Otherwise return a ConstantInt for the given value. 100db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *get(Type* Ty, const APInt& V); 1014d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 102532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// Return the constant as an APInt value reference. This allows clients to 103532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// obtain a copy of the value, with all its precision in tact. 104532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// @brief Return the constant's value. 1052c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner inline const APInt &getValue() const { 106532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val; 107532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer } 1084d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 109e51f2a59d93336b2be46b9663af317b96a7e045bChris Lattner /// getBitWidth - Return the bitwidth of this constant. 110e51f2a59d93336b2be46b9663af317b96a7e045bChris Lattner unsigned getBitWidth() const { return Val.getBitWidth(); } 111532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer 1120b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// Return the constant as a 64-bit unsigned integer value after it 113532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// has been zero extended as appropriate for the type of this constant. Note 114532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// that this method can assert if the value does not fit in 64 bits. 1150b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Return the zero extended value. 116a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner inline uint64_t getZExtValue() const { 117532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.getZExtValue(); 118a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner } 119c2dfb8bb909b0ba08733be94821513aef9467fa0Chris Lattner 1200b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// Return the constant as a 64-bit integer value after it has been sign 1217b048b391f9ded004170a67780d1c6a5eedeb604Bob Wilson /// extended as appropriate for the type of this constant. Note that 122532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer /// this method can assert if the value does not fit in 64 bits. 1236c6b6a77c0f68d5a41e94d8ef0b1093089e683faChris Lattner /// @brief Return the sign extended value. 124a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner inline int64_t getSExtValue() const { 125532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.getSExtValue(); 126a58ef7b6526ee30f4793fe91686899c602b4f9b9Chris Lattner } 127532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer 1284d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// A helper method that can be used to determine if the constant contained 1294d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// within is equal to a constant. This only works for very small values, 1300b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// because this is all that can be represented with all types. 1310b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Determine if this constant's value is same as an unsigned char. 132532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer bool equalsInt(uint64_t V) const { 133b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer return Val == V; 1342ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner } 1352ce0cbbbe1d53448ddbdaaedf0da28f68dd92ea0Chris Lattner 136c10305743c313558405079452138f03124e87581Reid Spencer /// getType - Specialize the getType() method to always return an IntegerType, 137c10305743c313558405079452138f03124e87581Reid Spencer /// which reduces the amount of casting needed in parts of the compiler. 138c10305743c313558405079452138f03124e87581Reid Spencer /// 139db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner inline IntegerType *getType() const { 140ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng return cast<IntegerType>(Value::getType()); 141c10305743c313558405079452138f03124e87581Reid Spencer } 142c10305743c313558405079452138f03124e87581Reid Spencer 1434d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// This static method returns true if the type Ty is big enough to 1444d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// represent the value V. This can be used to avoid having the get method 1456d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// assert when V is larger than Ty can represent. Note that there are two 1466d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// versions of this method, one for unsigned and one for signed integers. 1474d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// Although ConstantInt canonicalizes everything to an unsigned integer, 1486d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// the signed version avoids callers having to convert a signed quantity 1496d0483a7a365338e17537366c6c934edef2ef726Reid Spencer /// to the appropriate unsigned type before calling the method. 1500b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @returns true if V is a valid value for type Ty 1510b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// @brief Determine if the value is in range for the given type. 152db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static bool isValueValidForType(Type *Ty, uint64_t V); 153db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static bool isValueValidForType(Type *Ty, int64_t V); 15493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner 155b447387726ff94ddb2a23408f39e22714c42f79bChris Lattner bool isNegative() const { return Val.isNegative(); } 1565ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 15734da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// This is just a convenience method to make client code smaller for a 15834da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// common code. It also correctly performs the comparison without the 15934da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// potential for an assertion from getZExtValue(). 16034da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer bool isZero() const { 16134da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer return Val == 0; 16234da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer } 16334da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer 1644d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// This is just a convenience method to make client code smaller for a 16534da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// common case. It also correctly performs the comparison without the 16634da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer /// potential for an assertion from getZExtValue(). 16737eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer /// @brief Determine if the value is one. 16834da0ac28f7bfe737f92d3a098697a6ebc09a25eReid Spencer bool isOne() const { 16937eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer return Val == 1; 17037eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer } 17137eeaa729bc70258166a675ee00bbe95e608d519Reid Spencer 17294c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru /// This function will return true iff every bit in this constant is set 1736b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// to true. 17494c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru /// @returns true iff this constant's bits are all set to true. 1756b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is all ones. 1764d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak bool isMinusOne() const { 177532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isAllOnesValue(); 1786b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng } 1791680312867fffeb9369800949b809e0b9e29a914Chris Lattner 18094c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru /// This function will return true iff this constant represents the largest 1816b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// value that may be represented by the constant's type. 1824d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// @returns true iff this is the largest value that may be represented 1830b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// by this type. 1846b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is maximal. 185579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer bool isMaxValue(bool isSigned) const { 1864d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak if (isSigned) 187532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMaxSignedValue(); 188532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer else 189532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMaxValue(); 190994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner } 191994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner 19294c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru /// This function will return true iff this constant represents the smallest 1936b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// value that may be represented by this constant's type. 1944d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// @returns true if this is the smallest value that may be represented by 1950b5a504d105514178c80b886321221fbe5ac1131Reid Spencer /// this type. 1966b6b6ef1677fa71b1072c2911b4c1f9524a558c9Zhou Sheng /// @brief Determine if the value is minimal. 197579dca12c2cfd60bc18aaadbd5331897d48fec29Reid Spencer bool isMinValue(bool isSigned) const { 1984d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak if (isSigned) 199532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMinSignedValue(); 200532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer else 201532d0ce208809545dc46d2de70c0384c036470d1Reid Spencer return Val.isMinValue(); 202994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner } 203994b9f337ba9e15f3fa537c2a2d443b890c2a617Chris Lattner 20494c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru /// This function will return true iff this constant represents a value with 205b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// active bits bigger than 64 bits or a value greater than the given uint64_t 206b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// value. 20794c22716d60ff5edf6a98a3c67e0faa001be1142Sylvestre Ledru /// @returns true iff this constant is greater or equal to the given number. 208b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng /// @brief Determine if the value is greater or equal to the given number. 20932c371f0dff32dc127f6701c8737aad46b207d1eDavid Greene bool uge(uint64_t Num) const { 2100642f75836960afd547a6b98fad33026d0c355beZhou Sheng return Val.getActiveBits() > 64 || Val.getZExtValue() >= Num; 211b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng } 212b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng 213edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// getLimitedValue - If the value is smaller than the specified limit, 214edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// return it, otherwise return the limit value. This causes the value 215edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// to saturate to the limit. 216edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// @returns the min of the value of the constant and the specified value 217edf22b97d0d525ed4ec89eda1708c24c45c54b57Dan Gohman /// @brief Get the constant's value with a saturation limit 21899b1b38818e3a1628e39af40500bad47d5207d0dChris Lattner uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const { 21999b1b38818e3a1628e39af40500bad47d5207d0dChris Lattner return Val.getLimitedValue(Limit); 220b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng } 221b422d2d9e5632585adb0c1855b217f3123cbdfefZhou Sheng 222b83eb6447ba155342598f0fabe1f08f5baa9164aReid Spencer /// @brief Methods to support type inquiry through isa, cast, and dyn_cast. 22352eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 224a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantIntVal; 2255ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 226009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 227009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 228009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 22986e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 23093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantFP - Floating Point Values [float, double] 23193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 232e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantFP : public Constant { 233343e770983dcf53a1ea2dfca4e04d28ebc41138aDale Johannesen APFloat Val; 2342d24e2a396a1d211baaeedf32148a3b657240170David Blaikie virtual void anchor(); 2350cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 2360cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantFP(const ConstantFP &) LLVM_DELETED_FUNCTION; 23712ddd409535b52a7fa5157ded9a4cedd161fedb6Benjamin Kramer friend class LLVMContextImpl; 2383e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 239db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner ConstantFP(Type *Ty, const APFloat& V); 240051a950000e21935165db56695e35bade668193bGabor Greifprotected: 241051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 242051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 243051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 244051a950000e21935165db56695e35bade668193bGabor Greif } 245009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 2466f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// Floating point negation must be implemented with f(x) = -0.0 - x. This 2476f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// method returns the negative zero constant for floating point or vector 2486f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// floating point types; for all other types, it returns the null value. 249db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getZeroValueForNegation(Type *Ty); 2504d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 2516f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// get() - This returns a ConstantFP, or a vector containing a splat of a 2526f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// ConstantFP, for the specified value in the specified type. This should 2536f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// only be used for simple constant values like 2.0/1.0 etc, that are 2546f83c9c6ef0e7f79825a0a8f22941815e4b684c7Owen Anderson /// known-valid both as host double and as the target format. 255db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *get(Type* Ty, double V); 256db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *get(Type* Ty, StringRef Str); 2572c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static ConstantFP *get(LLVMContext &Context, const APFloat &V); 258db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static ConstantFP *getNegativeZero(Type* Ty); 259db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static ConstantFP *getInfinity(Type *Ty, bool Negative = false); 2604d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 26193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// isValueValidForType - return true if Ty is big enough to represent V. 262db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static bool isValueValidForType(Type *Ty, const APFloat &V); 263b447387726ff94ddb2a23408f39e22714c42f79bChris Lattner inline const APFloat &getValueAPF() const { return Val; } 2645ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 265e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman /// isZero - Return true if the value is positive or negative zero. 266e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman bool isZero() const { return Val.isZero(); } 267e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman 268b447387726ff94ddb2a23408f39e22714c42f79bChris Lattner /// isNegative - Return true if the sign bit is set. 269b447387726ff94ddb2a23408f39e22714c42f79bChris Lattner bool isNegative() const { return Val.isNegative(); } 270b447387726ff94ddb2a23408f39e22714c42f79bChris Lattner 271e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman /// isNaN - Return true if the value is a NaN. 272e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman bool isNaN() const { return Val.isNaN(); } 273e832693acbfc713bcaf44720efa8149e93a38027Dan Gohman 274f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// isExactlyValue - We don't rely on operator== working on double values, as 275f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// it returns true for things that are clearly not equal, like -0.0 and 0.0. 276f0fd6845eee799f62ac69297c9fd7086a0156cfaChris Lattner /// As such, this method can be used to do an exact bit-for-bit comparison of 27743421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen /// two floating point values. The version with a double operand is retained 27843421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen /// because it's so convenient to write isExactlyValue(2.0), but please use 279def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner /// it only for simple constants. 2802c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner bool isExactlyValue(const APFloat &V) const; 28143421b3dd70af5b70e71816521f37502c397cc65Dale Johannesen 282f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen bool isExactlyValue(double V) const { 2838aaec36fa760c9dd50627e397ca85798d9eb6e79Dale Johannesen bool ignored; 284def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner APFloat FV(V); 2858aaec36fa760c9dd50627e397ca85798d9eb6e79Dale Johannesen FV.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &ignored); 286def286408f4ddd0511164d231dfeddcc5fe12008Chris Lattner return isExactlyValue(FV); 287f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen } 28893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 28952eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 290a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantFPVal; 2915ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 292009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 293009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 29486e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 29540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// ConstantAggregateZero - All zero aggregate value 29640bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner/// 29740bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerclass ConstantAggregateZero : public Constant { 2980cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 2990cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantAggregateZero(const ConstantAggregateZero &) LLVM_DELETED_FUNCTION; 30040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerprotected: 301db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner explicit ConstantAggregateZero(Type *ty) 30213d57320bd212483463d4f8992d5787b29eda5dfBill Wendling : Constant(ty, ConstantAggregateZeroVal, 0, 0) {} 303051a950000e21935165db56695e35bade668193bGabor Greifprotected: 304051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 305051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 306051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 307051a950000e21935165db56695e35bade668193bGabor Greif } 30840bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattnerpublic: 309ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner static ConstantAggregateZero *get(Type *Ty); 3104d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 31104fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 31240bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner 313ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// getSequentialElement - If this CAZ has array or vector type, return a zero 314ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// with the right element type. 3153d5ed2250e78c3e849232398cb550238155dbb72Chris Lattner Constant *getSequentialElement() const; 316ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner 317ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// getStructElement - If this CAZ has struct type, return a zero with the 318ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// right element type for the specified element. 3193d5ed2250e78c3e849232398cb550238155dbb72Chris Lattner Constant *getStructElement(unsigned Elt) const; 320ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner 321ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// getElementValue - Return a zero of the right value for the specified GEP 322ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// index. 3233d5ed2250e78c3e849232398cb550238155dbb72Chris Lattner Constant *getElementValue(Constant *C) const; 324df39028607ca751f0a3f50a76144464b825ff97aChris Lattner 325df39028607ca751f0a3f50a76144464b825ff97aChris Lattner /// getElementValue - Return a zero of the right value for the specified GEP 326df39028607ca751f0a3f50a76144464b825ff97aChris Lattner /// index. 3273d5ed2250e78c3e849232398cb550238155dbb72Chris Lattner Constant *getElementValue(unsigned Idx) const; 328df39028607ca751f0a3f50a76144464b825ff97aChris Lattner 32940bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 33040bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner /// 33152eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 332a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantAggregateZeroVal; 33340bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner } 33440bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner}; 33540bbeb5d077b1bc2b933d8c8628024dfa9b428c3Chris Lattner 336009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 33786e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 33893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantArray - Constant Array Declarations 33993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 340e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantArray : public Constant { 3412cb395eae71dacda49ca3fe758618fc3e0701659Talin friend struct ConstantArrayCreator<ConstantArray, ArrayType>; 3420cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantArray(const ConstantArray &) LLVM_DELETED_FUNCTION; 3433e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 344166579e287a38d907acafc24243146e9f3ee9799Jay Foad ConstantArray(ArrayType *T, ArrayRef<Constant *> Val); 345009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 3461fd7096407d5e598ed3366a1141548e71273f1c5Owen Anderson // ConstantArray accessors 347db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *get(ArrayType *T, ArrayRef<Constant*> V); 3484d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 349efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 350efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 351efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 35293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getType - Specialize the getType() method to always return an ArrayType, 35393aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// which reduces the amount of casting needed in parts of the compiler. 35493aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// 355db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner inline ArrayType *getType() const { 356ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng return cast<ArrayType>(Value::getType()); 357682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner } 358009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 35904fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 36040cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 361e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner 36293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 36352eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 364a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantArrayVal; 3655ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 366009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 367009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 368efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 36967c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<ConstantArray> : 37067c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public VariadicOperandTraits<ConstantArray> { 371efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 372efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 373ff7782bcc9235b1dc4c7fcb0497c52e4717eeffcJay FoadDEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantArray, Constant) 374009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 37586e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 376e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattner// ConstantStruct - Constant Struct Declarations 377009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner// 378e9bb2df410f7a22decad9a883f7139d5857c1520Chris Lattnerclass ConstantStruct : public Constant { 3792cb395eae71dacda49ca3fe758618fc3e0701659Talin friend struct ConstantArrayCreator<ConstantStruct, StructType>; 3800cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantStruct(const ConstantStruct &) LLVM_DELETED_FUNCTION; 3813e22bed21110e9ca591a476ff2feea8790c67b13Chris Lattnerprotected: 382166579e287a38d907acafc24243146e9f3ee9799Jay Foad ConstantStruct(StructType *T, ArrayRef<Constant *> Val); 383009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattnerpublic: 3848fa3338ed2400c1352b137613d2c2c70d1ead695Owen Anderson // ConstantStruct accessors 385db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *get(StructType *T, ArrayRef<Constant*> V); 386db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *get(StructType *T, ...) END_WITH_NULL; 387b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner 388b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner /// getAnon - Return an anonymous struct that has the specified 389b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner /// elements. If the struct is possibly empty, then you must specify a 390b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner /// context. 391b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner static Constant *getAnon(ArrayRef<Constant*> V, bool Packed = false) { 392b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner return get(getTypeForElements(V, Packed), V); 393b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner } 3944d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak static Constant *getAnon(LLVMContext &Ctx, 395b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner ArrayRef<Constant*> V, bool Packed = false) { 396b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner return get(getTypeForElements(Ctx, V, Packed), V); 397b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner } 398c332fba8285e35a5a11463c34795af84f3960759Nick Lewycky 399b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner /// getTypeForElements - Return an anonymous struct type to use for a constant 400b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner /// with the specified set of elements. The list must not be empty. 401b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner static StructType *getTypeForElements(ArrayRef<Constant*> V, 402b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner bool Packed = false); 403b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner /// getTypeForElements - This version of the method allows an empty list. 404b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner static StructType *getTypeForElements(LLVMContext &Ctx, 405b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner ArrayRef<Constant*> V, 406b065b06c12dba6001b8140df2744d0c856ef6ea1Chris Lattner bool Packed = false); 4074d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 408efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 409efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 410efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 41193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getType() specialization - Reduce amount of casting... 412c78631f0e2cfd7808233176c638c7f9a50ccaff2Chris Lattner /// 413db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner inline StructType *getType() const { 414ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng return cast<StructType>(Value::getType()); 415682ea21397436e49eabbe13432e527869f07b0e0Chris Lattner } 416009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 41704fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 41840cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 4199769ab22265b313171d201b5928688524a01bd87Misha Brukman 42093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 42152eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 422a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantStructVal; 4235ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 424009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner}; 425009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner 426efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 42767c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<ConstantStruct> : 42867c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public VariadicOperandTraits<ConstantStruct> { 429efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 430efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 431ff7782bcc9235b1dc4c7fcb0497c52e4717eeffcJay FoadDEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantStruct, Constant) 432efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 433fdfeb6976f07ad10d809b922ed7376ba2a3539beChris Lattner 434fdfeb6976f07ad10d809b922ed7376ba2a3539beChris Lattner//===----------------------------------------------------------------------===// 4359d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencer/// ConstantVector - Constant Vector Declarations 436715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke/// 4379d6565a5b1fbc4286d6ee638d8f47a3171a9ed7eReid Spencerclass ConstantVector : public Constant { 4382cb395eae71dacda49ca3fe758618fc3e0701659Talin friend struct ConstantArrayCreator<ConstantVector, VectorType>; 4390cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantVector(const ConstantVector &) LLVM_DELETED_FUNCTION; 440715c90ba524e736190a6380695ab337eeb5148beBrian Gaekeprotected: 441166579e287a38d907acafc24243146e9f3ee9799Jay Foad ConstantVector(VectorType *T, ArrayRef<Constant *> Val); 442715c90ba524e736190a6380695ab337eeb5148beBrian Gaekepublic: 443af7ec975870f92245f1f1484ac80a1e2db6a0afaOwen Anderson // ConstantVector accessors 4442ca5c8644e6c35b3a7910a576ed89cddb7b82c3bChris Lattner static Constant *get(ArrayRef<Constant*> V); 4454d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 4463c2c954e0baf4c5029f87277d75cc6ca38916f71Chris Lattner /// getSplat - Return a ConstantVector with the specified constant in each 4473c2c954e0baf4c5029f87277d75cc6ca38916f71Chris Lattner /// element. 4483c2c954e0baf4c5029f87277d75cc6ca38916f71Chris Lattner static Constant *getSplat(unsigned NumElts, Constant *Elt); 4494d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 450efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 451efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 452efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 453fa73ea2d9fd785a214256ca44488407b26c5a3dbDan Gohman /// getType - Specialize the getType() method to always return a VectorType, 454715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// which reduces the amount of casting needed in parts of the compiler. 455715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// 456db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner inline VectorType *getType() const { 457ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng return cast<VectorType>(Value::getType()); 458715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke } 459fa30182eb84ee70d9f52120d653d63374b99cee6Jim Laskey 4603b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman /// getSplatValue - If this is a splat constant, meaning that all of the 4613b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman /// elements have the same value, return that value. Otherwise return NULL. 4627681c6da606efcc392f76b8acea8301cb5fc7a0aDuncan Sands Constant *getSplatValue() const; 4633b7cf0aabafc1c7a89a5a978d4a4307c891027ceDan Gohman 46404fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 46540cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 466715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke 467715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke /// Methods for support type inquiry through isa, cast, and dyn_cast: 468715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke static bool classof(const Value *V) { 469a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantVectorVal; 470715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke } 471715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke}; 472715c90ba524e736190a6380695ab337eeb5148beBrian Gaeke 473efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 47467c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<ConstantVector> : 47567c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public VariadicOperandTraits<ConstantVector> { 476efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 477efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 478ff7782bcc9235b1dc4c7fcb0497c52e4717eeffcJay FoadDEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantVector, Constant) 479efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 48086e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner//===----------------------------------------------------------------------===// 48193aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// ConstantPointerNull - a constant pointer value that points to null 48293aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner/// 48348babfa60d3ee1854f33ad93e07abb2b22cf8ab8Chris Lattnerclass ConstantPointerNull : public Constant { 4840cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 4850cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantPointerNull(const ConstantPointerNull &) LLVM_DELETED_FUNCTION; 4865ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerprotected: 487db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner explicit ConstantPointerNull(PointerType *T) 488ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng : Constant(T, 489225e8dd2f512e3e6840ba7cb1570fdc4d56a853fChris Lattner Value::ConstantPointerNullVal, 0, 0) {} 490afba8fe662d65b25b4baf46bb26cc18e1f9cc0a5Gordon Henriksen 491051a950000e21935165db56695e35bade668193bGabor Greifprotected: 492051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 493051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 494051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 495051a950000e21935165db56695e35bade668193bGabor Greif } 4965ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattnerpublic: 49793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// get() - Static factory methods - Return objects of the specified value 498db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static ConstantPointerNull *get(PointerType *T); 4995ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner 50004fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 501e0fbb497ee44f86ec108e4ff8787a848c6ee8655Chris Lattner 5020f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// getType - Specialize the getType() method to always return an PointerType, 5030f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// which reduces the amount of casting needed in parts of the compiler. 5040f42ba67771627453187e44fea935d6bab7a8152Chris Lattner /// 505db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner inline PointerType *getType() const { 506ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng return cast<PointerType>(Value::getType()); 5070f42ba67771627453187e44fea935d6bab7a8152Chris Lattner } 5080f42ba67771627453187e44fea935d6bab7a8152Chris Lattner 50993aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 51052eb13c58e63e277e83f94f3015dfc0e39a211eeChris Lattner static bool classof(const Value *V) { 511a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantPointerNullVal; 5125ef35fdb72f7800e65e27311e38f028e3d400693Chris Lattner } 5134cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner}; 5144d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 51527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner//===----------------------------------------------------------------------===// 5168cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// ConstantDataSequential - A vector or array constant whose element type is a 5178cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// simple 1/2/4/8-byte integer or float/double, and whose elements are just 5188cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// simple data values (i.e. ConstantInt/ConstantFP). This Constant node has no 5198cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// operands because it stores all of the elements of the constant as densely 5208cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// packed data, instead of as Value*'s. 5218cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// 5228cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// This is the common base class of ConstantDataArray and ConstantDataVector. 52327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner/// 52427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerclass ConstantDataSequential : public Constant { 52527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner friend class LLVMContextImpl; 52627dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// DataElements - A pointer to the bytes underlying this constant (which is 52727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// owned by the uniquing StringMap). 52827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner const char *DataElements; 5294d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 53027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// Next - This forms a link list of ConstantDataSequential nodes that have 53127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// the same value but different type. For example, 0,0,0,1 could be a 4 53227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// element array of i8, or a 1-element array of i32. They'll both end up in 53327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// the same StringMap bucket, linked up. 53427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner ConstantDataSequential *Next; 5350cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 5360cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantDataSequential(const ConstantDataSequential &) LLVM_DELETED_FUNCTION; 53727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerprotected: 53827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner explicit ConstantDataSequential(Type *ty, ValueTy VT, const char *Data) 53957af41e78c244951459c001dc37a92837a1c8f66Chris Lattner : Constant(ty, VT, 0, 0), DataElements(Data), Next(0) {} 54027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner ~ConstantDataSequential() { delete Next; } 5414d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 54227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner static Constant *getImpl(StringRef Bytes, Type *Ty); 54327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 54427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerprotected: 54527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner // allocate space for exactly zero operands. 54627dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner void *operator new(size_t s) { 54727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner return User::operator new(s, 0); 54827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 54927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerpublic: 5504d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 551ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// isElementTypeCompatible - Return true if a ConstantDataSequential can be 552ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// formed with a vector or array of the specified element type. 553ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// ConstantDataArray only works with normal float and int types that are 554ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// stored densely in memory, not with things like i42 or x86_f80. 555ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner static bool isElementTypeCompatible(const Type *Ty); 5564d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 55727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// getElementAsInteger - If this is a sequential container of integers (of 55827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// any size), return the specified element in the low bits of a uint64_t. 55927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner uint64_t getElementAsInteger(unsigned i) const; 56027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 56127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// getElementAsAPFloat - If this is a sequential container of floating point 56227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// type, return the specified element as an APFloat. 56327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner APFloat getElementAsAPFloat(unsigned i) const; 56427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 56527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// getElementAsFloat - If this is an sequential container of floats, return 56627dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// the specified element as a float. 56727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner float getElementAsFloat(unsigned i) const; 5684d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 56927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// getElementAsDouble - If this is an sequential container of doubles, return 5708cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner /// the specified element as a double. 57127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner double getElementAsDouble(unsigned i) const; 5724d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 57327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// getElementAsConstant - Return a Constant for a specified index's element. 57427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// Note that this has to compute a new constant to return, so it isn't as 57527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// efficient as getElementAsInteger/Float/Double. 57627dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner Constant *getElementAsConstant(unsigned i) const; 5774d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 57827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// getType - Specialize the getType() method to always return a 57927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// SequentialType, which reduces the amount of casting needed in parts of the 58027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// compiler. 58127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner inline SequentialType *getType() const { 582ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng return cast<SequentialType>(Value::getType()); 58327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 5844d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 58545bb5c5333fba7e9909cca178d785bf2c1d2b0c1Chris Lattner /// getElementType - Return the element type of the array/vector. 58645bb5c5333fba7e9909cca178d785bf2c1d2b0c1Chris Lattner Type *getElementType() const; 5874d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 5881ee0ecf84a07693c3a517ba030fac8ac1f9f3fbcChris Lattner /// getNumElements - Return the number of elements in the array or vector. 5891ee0ecf84a07693c3a517ba030fac8ac1f9f3fbcChris Lattner unsigned getNumElements() const; 59045bb5c5333fba7e9909cca178d785bf2c1d2b0c1Chris Lattner 591ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// getElementByteSize - Return the size (in bytes) of each element in the 592ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// array/vector. The size of the elements is known to be a multiple of one 593ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// byte. 594ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner uint64_t getElementByteSize() const; 59527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 5964d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 59762339073127df4579905f551f61c132cf21d2aadChris Lattner /// isString - This method returns true if this is an array of i8. 59862339073127df4579905f551f61c132cf21d2aadChris Lattner bool isString() const; 5994d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 60062339073127df4579905f551f61c132cf21d2aadChris Lattner /// isCString - This method returns true if the array "isString", ends with a 60162339073127df4579905f551f61c132cf21d2aadChris Lattner /// nul byte, and does not contains any other nul bytes. 60262339073127df4579905f551f61c132cf21d2aadChris Lattner bool isCString() const; 6034d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 60462339073127df4579905f551f61c132cf21d2aadChris Lattner /// getAsString - If this array is isString(), then this method returns the 60562339073127df4579905f551f61c132cf21d2aadChris Lattner /// array as a StringRef. Otherwise, it asserts out. 60662339073127df4579905f551f61c132cf21d2aadChris Lattner /// 6079e631da253bff90d9da5ace21bd73f1c838e72ebChris Lattner StringRef getAsString() const { 6089e631da253bff90d9da5ace21bd73f1c838e72ebChris Lattner assert(isString() && "Not a string"); 6099e631da253bff90d9da5ace21bd73f1c838e72ebChris Lattner return getRawDataValues(); 6109e631da253bff90d9da5ace21bd73f1c838e72ebChris Lattner } 6114d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 61262339073127df4579905f551f61c132cf21d2aadChris Lattner /// getAsCString - If this array is isCString(), then this method returns the 61362339073127df4579905f551f61c132cf21d2aadChris Lattner /// array (without the trailing null byte) as a StringRef. Otherwise, it 61462339073127df4579905f551f61c132cf21d2aadChris Lattner /// asserts out. 61562339073127df4579905f551f61c132cf21d2aadChris Lattner /// 61662339073127df4579905f551f61c132cf21d2aadChris Lattner StringRef getAsCString() const { 61762339073127df4579905f551f61c132cf21d2aadChris Lattner assert(isCString() && "Isn't a C string"); 61862339073127df4579905f551f61c132cf21d2aadChris Lattner StringRef Str = getAsString(); 61962339073127df4579905f551f61c132cf21d2aadChris Lattner return Str.substr(0, Str.size()-1); 62062339073127df4579905f551f61c132cf21d2aadChris Lattner } 6214d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 6229e631da253bff90d9da5ace21bd73f1c838e72ebChris Lattner /// getRawDataValues - Return the raw, underlying, bytes of this data. Note 6239e631da253bff90d9da5ace21bd73f1c838e72ebChris Lattner /// that this is an extremely tricky thing to work with, as it exposes the 6249e631da253bff90d9da5ace21bd73f1c838e72ebChris Lattner /// host endianness of the data elements. 6259e631da253bff90d9da5ace21bd73f1c838e72ebChris Lattner StringRef getRawDataValues() const; 6264d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 627ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner virtual void destroyConstant(); 6284d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 62927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 63027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// 63127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner static bool classof(const Value *V) { 63227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner return V->getValueID() == ConstantDataArrayVal || 63327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner V->getValueID() == ConstantDataVectorVal; 63427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 63545bb5c5333fba7e9909cca178d785bf2c1d2b0c1Chris Lattnerprivate: 63645bb5c5333fba7e9909cca178d785bf2c1d2b0c1Chris Lattner const char *getElementPointer(unsigned Elt) const; 63727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner}; 63827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 63927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner//===----------------------------------------------------------------------===// 6408cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// ConstantDataArray - An array constant whose element type is a simple 6418cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// 1/2/4/8-byte integer or float/double, and whose elements are just simple 6428cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// data values (i.e. ConstantInt/ConstantFP). This Constant node has no 6438cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// operands because it stores all of the elements of the constant as densely 6448cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// packed data, instead of as Value*'s. 64527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerclass ConstantDataArray : public ConstantDataSequential { 6460cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 6470cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantDataArray(const ConstantDataArray &) LLVM_DELETED_FUNCTION; 64827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner virtual void anchor(); 64927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner friend class ConstantDataSequential; 65027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner explicit ConstantDataArray(Type *ty, const char *Data) 65127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner : ConstantDataSequential(ty, ConstantDataArrayVal, Data) {} 65227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerprotected: 65327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner // allocate space for exactly zero operands. 65427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner void *operator new(size_t s) { 65527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner return User::operator new(s, 0); 65627dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 65727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerpublic: 6584d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 65927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// get() constructors - Return a constant with array type with an element 66027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// count and element type matching the ArrayRef passed in. Note that this 66127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// can return a ConstantAggregateZero object. 66232100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts); 66332100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts); 66432100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts); 66532100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts); 66632100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<float> Elts); 66732100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<double> Elts); 6684d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 66932100602432657b188db603ca3ab50b487938027Chris Lattner /// getString - This method constructs a CDS and initializes it with a text 67032100602432657b188db603ca3ab50b487938027Chris Lattner /// string. The default behavior (AddNull==true) causes a null terminator to 67132100602432657b188db603ca3ab50b487938027Chris Lattner /// be placed at the end of the array (increasing the length of the string by 67232100602432657b188db603ca3ab50b487938027Chris Lattner /// one more than the StringRef would normally indicate. Pass AddNull=false 67332100602432657b188db603ca3ab50b487938027Chris Lattner /// to disable this behavior. 67432100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *getString(LLVMContext &Context, StringRef Initializer, 67532100602432657b188db603ca3ab50b487938027Chris Lattner bool AddNull = true); 67632100602432657b188db603ca3ab50b487938027Chris Lattner 67727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// getType - Specialize the getType() method to always return an ArrayType, 67827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// which reduces the amount of casting needed in parts of the compiler. 67927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// 68027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner inline ArrayType *getType() const { 681ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng return cast<ArrayType>(Value::getType()); 68227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 6834d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 68427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 68527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// 68627dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner static bool classof(const Value *V) { 68727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner return V->getValueID() == ConstantDataArrayVal; 68827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 68927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner}; 6904d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 69127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner//===----------------------------------------------------------------------===// 6928cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// ConstantDataVector - A vector constant whose element type is a simple 6938cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// 1/2/4/8-byte integer or float/double, and whose elements are just simple 6948cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// data values (i.e. ConstantInt/ConstantFP). This Constant node has no 6958cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// operands because it stores all of the elements of the constant as densely 6968cf27efe4000c194efec4004afa83d12031c6d55Chris Lattner/// packed data, instead of as Value*'s. 69727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerclass ConstantDataVector : public ConstantDataSequential { 6980cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 6990cb0a3533788c6c622518cb030048012eb69af15Craig Topper ConstantDataVector(const ConstantDataVector &) LLVM_DELETED_FUNCTION; 70027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner virtual void anchor(); 70127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner friend class ConstantDataSequential; 70227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner explicit ConstantDataVector(Type *ty, const char *Data) 70327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner : ConstantDataSequential(ty, ConstantDataVectorVal, Data) {} 70427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerprotected: 70527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner // allocate space for exactly zero operands. 70627dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner void *operator new(size_t s) { 70727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner return User::operator new(s, 0); 70827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 70927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattnerpublic: 7104d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 71127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// get() constructors - Return a constant with vector type with an element 71227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// count and element type matching the ArrayRef passed in. Note that this 71327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// can return a ConstantAggregateZero object. 71432100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<uint8_t> Elts); 71532100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<uint16_t> Elts); 71632100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<uint32_t> Elts); 71732100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<uint64_t> Elts); 71832100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<float> Elts); 71932100602432657b188db603ca3ab50b487938027Chris Lattner static Constant *get(LLVMContext &Context, ArrayRef<double> Elts); 7204d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 7213c2c954e0baf4c5029f87277d75cc6ca38916f71Chris Lattner /// getSplat - Return a ConstantVector with the specified constant in each 7223c2c954e0baf4c5029f87277d75cc6ca38916f71Chris Lattner /// element. The specified constant has to be a of a compatible type (i8/i16/ 7233c2c954e0baf4c5029f87277d75cc6ca38916f71Chris Lattner /// i32/i64/float/double) and must be a ConstantFP or ConstantInt. 7243c2c954e0baf4c5029f87277d75cc6ca38916f71Chris Lattner static Constant *getSplat(unsigned NumElts, Constant *Elt); 7253c2c954e0baf4c5029f87277d75cc6ca38916f71Chris Lattner 726e150e2df424b162710b36a1ec5ef90270ffb435bChris Lattner /// getSplatValue - If this is a splat constant, meaning that all of the 727e150e2df424b162710b36a1ec5ef90270ffb435bChris Lattner /// elements have the same value, return that value. Otherwise return NULL. 728e150e2df424b162710b36a1ec5ef90270ffb435bChris Lattner Constant *getSplatValue() const; 7294d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 73027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// getType - Specialize the getType() method to always return a VectorType, 73127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// which reduces the amount of casting needed in parts of the compiler. 73227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// 73327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner inline VectorType *getType() const { 734ae2a1dacb7fed0d037db2116f5790be3b69b73fbPeng Cheng return cast<VectorType>(Value::getType()); 73527dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 7364d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 73727dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 73827dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner /// 73927dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner static bool classof(const Value *V) { 74027dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner return V->getValueID() == ConstantDataVectorVal; 74127dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner } 74227dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner}; 74327dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 74427dd9cf5d1ec831a1cd0766580e6d1177a9800a3Chris Lattner 7454cfb15331652f9a2f7e5f755485a2f6eb87a20c6Chris Lattner 7462ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner/// BlockAddress - The address of a basic block. 7472ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner/// 7482ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnerclass BlockAddress : public Constant { 7490cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 7502ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner void *operator new(size_t s) { return User::operator new(s, 2); } 7512ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner BlockAddress(Function *F, BasicBlock *BB); 7522ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnerpublic: 7532ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// get - Return a BlockAddress for the specified function and basic block. 7542ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static BlockAddress *get(Function *F, BasicBlock *BB); 7554d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 7562ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// get - Return a BlockAddress for the specified basic block. The basic 7572ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// block must be embedded into a function. 7582ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static BlockAddress *get(BasicBlock *BB); 7594d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 7602ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// Transparently provide more efficient getOperand methods. 7610eeb913aa17a68b1f2963b02ca1d68f09dba0b78Chris Lattner DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); 7624d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 7632ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner Function *getFunction() const { return (Function*)Op<0>().get(); } 7642ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); } 7654d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 7662ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner virtual void destroyConstant(); 7672ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 7684d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 7692ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 7702ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner static inline bool classof(const Value *V) { 7712ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner return V->getValueID() == BlockAddressVal; 7722ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner } 7732ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner}; 7742ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner 7752ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattnertemplate <> 77667c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<BlockAddress> : 77767c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public FixedNumOperandTraits<BlockAddress, 2> { 7782ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner}; 779f4ba6c710c298fe9b492b9cde82ce5efd46afd5dChris Lattner 780ff7782bcc9235b1dc4c7fcb0497c52e4717eeffcJay FoadDEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value) 7814d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 7821c5730facaefbacd66badea74c83571a16611bd4Jin-Gu Kang 7832ee11eccdde14c95c78773be76b02bb5fd09d7eeChris Lattner//===----------------------------------------------------------------------===// 78486e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// ConstantExpr - a constant value that is initialized with an expression using 785eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// other constant values. 78686e100bd9bf1a1a838902c46de926c79c68cdde3Chris Lattner/// 787eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// This class uses the standard Instruction opcodes to define the various 788eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// constant expressions. The Opcode field for the ConstantExpr class is 789eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner/// maintained in the Value::SubclassData field. 79029ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adveclass ConstantExpr : public Constant { 7916cc89aad25155ecd93b5318414851aa46351196dChris Lattner friend struct ConstantCreator<ConstantExpr,Type, 7926cc89aad25155ecd93b5318414851aa46351196dChris Lattner std::pair<unsigned, std::vector<Constant*> > >; 7935f4ac848d94b0a92e19ac7f2b3d0284d7d323173Devang Patel friend struct ConvertConstantType<ConstantExpr, Type>; 7949769ab22265b313171d201b5928688524a01bd87Misha Brukman 7956cc89aad25155ecd93b5318414851aa46351196dChris Lattnerprotected: 796db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner ConstantExpr(Type *ty, unsigned Opcode, Use *Ops, unsigned NumOps) 79713d57320bd212483463d4f8992d5787b29eda5dfBill Wendling : Constant(ty, ConstantExprVal, Ops, NumOps) { 798eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner // Operation type (an Instruction opcode) is stored as the SubclassData. 799cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner setValueSubclassData(Opcode); 800eecfea4da6771b01997d3dc9648e699b476a3079Chris Lattner } 8015133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner 80229ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Advepublic: 803fb242b6edc3d92daf49c7d5b2c19d81447aa61bcChris Lattner // Static methods to construct a ConstantExpr of different kinds. Note that 804baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // these methods may return a object that is not an instance of the 805baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // ConstantExpr class, because they will attempt to fold the constant 806baf850a51a253a39c60196343d756197bfbb27dbChris Lattner // expression into something simpler if possible. 8079769ab22265b313171d201b5928688524a01bd87Misha Brukman 808baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// getAlignOf constant expr - computes the alignment of a type in a target 80906ed3e788ab3d71350b7cc7d077f4bd9a2b57799Dan Gohman /// independent way (Note: the return type is an i64). 810db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getAlignOf(Type *Ty); 8114d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 812a5a23046cbea6d011f84c97ac61743cb8f6a58c6Dan Gohman /// getSizeOf constant expr - computes the (alloc) size of a type (in 813a5a23046cbea6d011f84c97ac61743cb8f6a58c6Dan Gohman /// address-units, not bits) in a target independent way (Note: the return 814a5a23046cbea6d011f84c97ac61743cb8f6a58c6Dan Gohman /// type is an i64). 815baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// 816db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getSizeOf(Type *Ty); 8173778f21b17e675c2fd1600901361fa4a73888ebaDan Gohman 8184d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak /// getOffsetOf constant expr - computes the offset of a struct field in a 8192544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// target independent way (Note: the return type is an i64). 8202544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// 821db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getOffsetOf(StructType *STy, unsigned FieldNo); 8222544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman 8232544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// getOffsetOf constant expr - This is a generalized form of getOffsetOf, 8242544a1de666ad7197c755b4dab6419f42df01f65Dan Gohman /// which supports any aggregate type, and any Constant index. 8253778f21b17e675c2fd1600901361fa4a73888ebaDan Gohman /// 826db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getOffsetOf(Type *Ty, Constant *FieldNo); 8274d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 82881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false); 8292c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFNeg(Constant *C); 8302c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getNot(Constant *C); 83181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getAdd(Constant *C1, Constant *C2, 83281baf14fdfa29c22a08d609144c285169e23a247Chris Lattner bool HasNUW = false, bool HasNSW = false); 8332c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFAdd(Constant *C1, Constant *C2); 83481baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getSub(Constant *C1, Constant *C2, 83581baf14fdfa29c22a08d609144c285169e23a247Chris Lattner bool HasNUW = false, bool HasNSW = false); 8362c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFSub(Constant *C1, Constant *C2); 83781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getMul(Constant *C1, Constant *C2, 83881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner bool HasNUW = false, bool HasNSW = false); 8392c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFMul(Constant *C1, Constant *C2); 84074f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false); 84174f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false); 8422c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFDiv(Constant *C1, Constant *C2); 8432c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getURem(Constant *C1, Constant *C2); 8442c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getSRem(Constant *C1, Constant *C2); 8452c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getFRem(Constant *C1, Constant *C2); 8462c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getAnd(Constant *C1, Constant *C2); 8472c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getOr(Constant *C1, Constant *C2); 8482c5060dbde67422420cd81f3ce3f15127641c87dChris Lattner static Constant *getXor(Constant *C1, Constant *C2); 84981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getShl(Constant *C1, Constant *C2, 85081baf14fdfa29c22a08d609144c285169e23a247Chris Lattner bool HasNUW = false, bool HasNSW = false); 85174f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false); 85274f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false); 853db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getTrunc (Constant *C, Type *Ty); 854db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getSExt (Constant *C, Type *Ty); 855db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getZExt (Constant *C, Type *Ty); 856db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getFPTrunc (Constant *C, Type *Ty); 857db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getFPExtend(Constant *C, Type *Ty); 858db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getUIToFP (Constant *C, Type *Ty); 859db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getSIToFP (Constant *C, Type *Ty); 860db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getFPToUI (Constant *C, Type *Ty); 861db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getFPToSI (Constant *C, Type *Ty); 862db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getPtrToInt(Constant *C, Type *Ty); 863db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getIntToPtr(Constant *C, Type *Ty); 864db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static Constant *getBitCast (Constant *C, Type *Ty); 8653da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 86681baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); } 86781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); } 86881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWAdd(Constant *C1, Constant *C2) { 86981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getAdd(C1, C2, false, true); 87081baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 87181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWAdd(Constant *C1, Constant *C2) { 87281baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getAdd(C1, C2, true, false); 87381baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 87481baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWSub(Constant *C1, Constant *C2) { 87581baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getSub(C1, C2, false, true); 87681baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 87781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWSub(Constant *C1, Constant *C2) { 87881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getSub(C1, C2, true, false); 87981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 88081baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWMul(Constant *C1, Constant *C2) { 88181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getMul(C1, C2, false, true); 88281baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 88381baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWMul(Constant *C1, Constant *C2) { 88481baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getMul(C1, C2, true, false); 88581baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 88681baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNSWShl(Constant *C1, Constant *C2) { 88781baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getShl(C1, C2, false, true); 88881baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 88981baf14fdfa29c22a08d609144c285169e23a247Chris Lattner static Constant *getNUWShl(Constant *C1, Constant *C2) { 89081baf14fdfa29c22a08d609144c285169e23a247Chris Lattner return getShl(C1, C2, true, false); 89181baf14fdfa29c22a08d609144c285169e23a247Chris Lattner } 89274f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getExactSDiv(Constant *C1, Constant *C2) { 89374f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner return getSDiv(C1, C2, true); 89474f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner } 89574f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getExactUDiv(Constant *C1, Constant *C2) { 89674f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner return getUDiv(C1, C2, true); 89774f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner } 89874f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getExactAShr(Constant *C1, Constant *C2) { 89974f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner return getAShr(C1, C2, true); 90074f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner } 90174f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner static Constant *getExactLShr(Constant *C1, Constant *C2) { 90274f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner return getLShr(C1, C2, true); 90374f5c5abeafeaabefab470390ce0e7a36754c592Chris Lattner } 9046e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman 905c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// getBinOpIdentity - Return the identity for the given binary operation, 906c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands /// i.e. a constant C such that X op C = X and C op X = X for every X. It 907ee5a094ccf1f04d3fcc92ac4d2fc8a2926cbb232Duncan Sands /// returns null if the operator doesn't have an identity. 908c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands static Constant *getBinOpIdentity(unsigned Opcode, Type *Ty); 909c038a7833565ecf92a699371d448135a097c9e2fDuncan Sands 910ee5a094ccf1f04d3fcc92ac4d2fc8a2926cbb232Duncan Sands /// getBinOpAbsorber - Return the absorbing element for the given binary 911ee5a094ccf1f04d3fcc92ac4d2fc8a2926cbb232Duncan Sands /// operation, i.e. a constant C such that X op C = C and C op X = C for 912ee5a094ccf1f04d3fcc92ac4d2fc8a2926cbb232Duncan Sands /// every X. For example, this returns zero for integer multiplication. 913ee5a094ccf1f04d3fcc92ac4d2fc8a2926cbb232Duncan Sands /// It returns null if the operator doesn't have an absorbing element. 914ee5a094ccf1f04d3fcc92ac4d2fc8a2926cbb232Duncan Sands static Constant *getBinOpAbsorber(unsigned Opcode, Type *Ty); 915ee5a094ccf1f04d3fcc92ac4d2fc8a2926cbb232Duncan Sands 916efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif /// Transparently provide more efficient getOperand methods. 917efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); 918efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 9193da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer // @brief Convenience function for getting one of the casting operations 9203da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer // using a CastOps opcode. 9213da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer static Constant *getCast( 9223da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer unsigned ops, ///< The opcode for the conversion 9233da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer Constant *C, ///< The constant to be converted 924db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty ///< The type to which the constant is converted 9253da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer ); 9263da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 927848414e49c7600e3002a4366de52d03a9638b327Reid Spencer // @brief Create a ZExt or BitCast cast constant expression 928848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getZExtOrBitCast( 929848414e49c7600e3002a4366de52d03a9638b327Reid Spencer Constant *C, ///< The constant to zext or bitcast 930db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty ///< The type to zext or bitcast C to 931848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 932848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 9334d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak // @brief Create a SExt or BitCast cast constant expression 934848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getSExtOrBitCast( 93590fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer Constant *C, ///< The constant to sext or bitcast 936db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty ///< The type to sext or bitcast C to 937848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 938848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 939848414e49c7600e3002a4366de52d03a9638b327Reid Spencer // @brief Create a Trunc or BitCast cast constant expression 940848414e49c7600e3002a4366de52d03a9638b327Reid Spencer static Constant *getTruncOrBitCast( 94190fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer Constant *C, ///< The constant to trunc or bitcast 942db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty ///< The type to trunc or bitcast C to 943848414e49c7600e3002a4366de52d03a9638b327Reid Spencer ); 944848414e49c7600e3002a4366de52d03a9638b327Reid Spencer 945887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer /// @brief Create a BitCast or a PtrToInt cast constant expression 946887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer static Constant *getPointerCast( 947887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer Constant *C, ///< The pointer value to be casted (operand 0) 948db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty ///< The type to which cast should be made 949887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer ); 950887ee06f94c5b36ddbe22f54ff816fbc13bb2703Reid Spencer 95184f3eab017d56b6854155f2350759dc77ac48aadReid Spencer /// @brief Create a ZExt, Bitcast or Trunc for integer -> integer casts 95284f3eab017d56b6854155f2350759dc77ac48aadReid Spencer static Constant *getIntegerCast( 9534d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak Constant *C, ///< The integer constant to be casted 954db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty, ///< The integer type to cast to 95584f3eab017d56b6854155f2350759dc77ac48aadReid Spencer bool isSigned ///< Whether C should be treated as signed or not 95684f3eab017d56b6854155f2350759dc77ac48aadReid Spencer ); 95784f3eab017d56b6854155f2350759dc77ac48aadReid Spencer 95884f3eab017d56b6854155f2350759dc77ac48aadReid Spencer /// @brief Create a FPExt, Bitcast or FPTrunc for fp -> fp casts 95984f3eab017d56b6854155f2350759dc77ac48aadReid Spencer static Constant *getFPCast( 9604d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak Constant *C, ///< The integer constant to be casted 961db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Type *Ty ///< The integer type to cast to 96284f3eab017d56b6854155f2350759dc77ac48aadReid Spencer ); 96384f3eab017d56b6854155f2350759dc77ac48aadReid Spencer 9643da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer /// @brief Return true if this is a convert constant expression 9653da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer bool isCast() const; 9663da59db637a887474c1b1346c1f3ccf53b6c4663Reid Spencer 9674b94f49091be8e26ce6e49db1268458995299b82Reid Spencer /// @brief Return true if this is a compare constant expression 9684b94f49091be8e26ce6e49db1268458995299b82Reid Spencer bool isCompare() const; 9694b94f49091be8e26ce6e49db1268458995299b82Reid Spencer 97081a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// @brief Return true if this is an insertvalue or extractvalue expression, 97181a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// and the getIndices() method may be used. 97281a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman bool hasIndices() const; 97381a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman 974e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// @brief Return true if this is a getelementptr expression and all 975e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// the index operands are compile-time known integers within the 976e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// corresponding notional static array extents. Note that this is 977e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// not equivalant to, a subset of, or a superset of the "inbounds" 978e6992f728a94654e43269580a10a667f18dadba9Dan Gohman /// property. 979e6992f728a94654e43269580a10a667f18dadba9Dan Gohman bool isGEPWithNoNotionalOverIndexing() const; 980e6992f728a94654e43269580a10a667f18dadba9Dan Gohman 98146a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner /// Select constant expr 98246a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner /// 983eaf79809e8a78bf407bb26b9d7c59f32c142188aChris Lattner static Constant *getSelect(Constant *C, Constant *V1, Constant *V2); 98446a57d8f144af82be46ac925f1c53a3405bcfb3aChris Lattner 985baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// get - Return a binary or shift operator constant expression, 9867e208904ae8eeef888c3a6eecd38daa779ca36c9Chris Lattner /// folding if possible. 9875133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner /// 988f8dbee7cea072eb63ae343759975109553697bcbDan Gohman static Constant *get(unsigned Opcode, Constant *C1, Constant *C2, 989f8dbee7cea072eb63ae343759975109553697bcbDan Gohman unsigned Flags = 0); 99090fdf9c6debbdcc61076a1e020c3dff4dc71d838Reid Spencer 9917f6aa2b162e5daaf7b9ccf05d749597d3d7cf460Nick Lewycky /// @brief Return an ICmp or FCmp comparison operator constant expression. 992e4d87aa2de6e52952dca73716386db09aad5a8fdReid Spencer static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2); 993e8e4605021141d689493132a9c7c6fce6294937fChris Lattner 994baf3c404409d5e47b13984a7f95bfbd6d1f2e79eOwen Anderson /// get* - Return some common constants without having to 9954dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner /// specify the full Instruction::OPCODE identifier. 9964dcb5401e4f6248eb546e4da444ba8e8cf306666Chris Lattner /// 9974647569fe7706e76135a08ca0e5f90a447ccc5b4Gordon Henriksen static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS); 9984647569fe7706e76135a08ca0e5f90a447ccc5b4Gordon Henriksen static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS); 99902140b025d821ca8cefe5086f90f4d8e0c52ae5bChris Lattner 1000cda60cec1642fa7c4d9e34511c14fc37d8055733Jay Foad /// Getelementptr form. Value* is only accepted for convenience; 10017fa6e666ece60455cf9d75eff6e6915bebf05cbcChris Lattner /// all elements must be Constant's. 10025133a5cf2ee42b5a4d4c7af2d90b41af769cc307Chris Lattner /// 100304fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getGetElementPtr(Constant *C, 1004dab3d29605a5c83db41b28176273ef55961120c1Jay Foad ArrayRef<Constant *> IdxList, 1005eaf79809e8a78bf407bb26b9d7c59f32c142188aChris Lattner bool InBounds = false) { 1006dab3d29605a5c83db41b28176273ef55961120c1Jay Foad return getGetElementPtr(C, makeArrayRef((Value * const *)IdxList.data(), 1007dab3d29605a5c83db41b28176273ef55961120c1Jay Foad IdxList.size()), 1008dab3d29605a5c83db41b28176273ef55961120c1Jay Foad InBounds); 1009eaf79809e8a78bf407bb26b9d7c59f32c142188aChris Lattner } 101004fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson static Constant *getGetElementPtr(Constant *C, 1011dab3d29605a5c83db41b28176273ef55961120c1Jay Foad Constant *Idx, 1012dab3d29605a5c83db41b28176273ef55961120c1Jay Foad bool InBounds = false) { 1013dab3d29605a5c83db41b28176273ef55961120c1Jay Foad // This form of the function only exists to avoid ambiguous overload 1014dab3d29605a5c83db41b28176273ef55961120c1Jay Foad // warnings about whether to convert Idx to ArrayRef<Constant *> or 1015dab3d29605a5c83db41b28176273ef55961120c1Jay Foad // ArrayRef<Value *>. 1016dab3d29605a5c83db41b28176273ef55961120c1Jay Foad return getGetElementPtr(C, cast<Value>(Idx), InBounds); 1017dab3d29605a5c83db41b28176273ef55961120c1Jay Foad } 1018dab3d29605a5c83db41b28176273ef55961120c1Jay Foad static Constant *getGetElementPtr(Constant *C, 1019dab3d29605a5c83db41b28176273ef55961120c1Jay Foad ArrayRef<Value *> IdxList, 10201f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner bool InBounds = false); 1021e2574d3215c412a15763d26aee9aa5d856764c2cDan Gohman 10226e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman /// Create an "inbounds" getelementptr. See the documentation for the 10236e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman /// "inbounds" flag in LangRef.html for details. 10246e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman static Constant *getInBoundsGetElementPtr(Constant *C, 1025dab3d29605a5c83db41b28176273ef55961120c1Jay Foad ArrayRef<Constant *> IdxList) { 1026dab3d29605a5c83db41b28176273ef55961120c1Jay Foad return getGetElementPtr(C, IdxList, true); 1027dab3d29605a5c83db41b28176273ef55961120c1Jay Foad } 1028dab3d29605a5c83db41b28176273ef55961120c1Jay Foad static Constant *getInBoundsGetElementPtr(Constant *C, 1029dab3d29605a5c83db41b28176273ef55961120c1Jay Foad Constant *Idx) { 1030dab3d29605a5c83db41b28176273ef55961120c1Jay Foad // This form of the function only exists to avoid ambiguous overload 1031dab3d29605a5c83db41b28176273ef55961120c1Jay Foad // warnings about whether to convert Idx to ArrayRef<Constant *> or 1032dab3d29605a5c83db41b28176273ef55961120c1Jay Foad // ArrayRef<Value *>. 1033dab3d29605a5c83db41b28176273ef55961120c1Jay Foad return getGetElementPtr(C, Idx, true); 10341f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner } 10356e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman static Constant *getInBoundsGetElementPtr(Constant *C, 1036dab3d29605a5c83db41b28176273ef55961120c1Jay Foad ArrayRef<Value *> IdxList) { 1037dab3d29605a5c83db41b28176273ef55961120c1Jay Foad return getGetElementPtr(C, IdxList, true); 10381f78d51be69964b38c5fc76ceb2147b737d09857Chris Lattner } 10396e7ad958683f34bf6c014c88fef723e5a2d741beDan Gohman 10409fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getExtractElement(Constant *Vec, Constant *Idx); 10419fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getInsertElement(Constant *Vec, Constant *Elt,Constant *Idx); 10429fc18d24ae525a0047718d28e7a8735e8582ddb2Chris Lattner static Constant *getShuffleVector(Constant *V1, Constant *V2, Constant *Mask); 1043fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad static Constant *getExtractValue(Constant *Agg, ArrayRef<unsigned> Idxs); 1044041e2eb51721bcfecee5d9c9fc409ff185526e47Dan Gohman static Constant *getInsertValue(Constant *Agg, Constant *Val, 1045fc6d3a49867cd38954dc40936a88f1907252c6d2Jay Foad ArrayRef<unsigned> Idxs); 1046728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer 104793aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getOpcode - Return the opcode at the root of this constant expression 1048cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner unsigned getOpcode() const { return getSubclassDataFromValue(); } 104929ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve 1050728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer /// getPredicate - Return the ICMP or FCMP predicate value. Assert if this is 1051728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer /// not an ICMP or FCMP constant expression. 1052728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer unsigned getPredicate() const; 1053728b6db6fbd3caee7fa25b377f4592160476bb9cReid Spencer 105481a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// getIndices - Assert that this is an insertvalue or exactvalue 105581a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman /// expression and return the list of indices. 1056d30aa5a1edac5256573e8d76dd155df3d3fdec84Jay Foad ArrayRef<unsigned> getIndices() const; 105781a0c0b44e582baca8b68754a7fcabfc3aef2e7aDan Gohman 105893aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// getOpcodeName - Return a string representation for an opcode. 1059e8e4605021141d689493132a9c7c6fce6294937fChris Lattner const char *getOpcodeName() const; 10609769ab22265b313171d201b5928688524a01bd87Misha Brukman 106179ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner /// getWithOperandReplaced - Return a constant expression identical to this 106279ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner /// one, but with the specified operand set to the specified value. 106379ce587cda552abf85f02282cf6cfe36afcaafd8Chris Lattner Constant *getWithOperandReplaced(unsigned OpNo, Constant *Op) const; 10644d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 10656b8408e9103328b82affbfdf3d3bca236c61f514Chris Lattner /// getWithOperands - This returns the current constant expression with the 10661afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// operands replaced with the specified values. The specified array must 10671afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// have the same number of operands as our current one. 10681afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner Constant *getWithOperands(ArrayRef<Constant*> Ops) const { 10691afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner return getWithOperands(Ops, getType()); 10701afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner } 10711afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 10721afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// getWithOperands - This returns the current constant expression with the 10731afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// operands replaced with the specified values and with the specified result 10741afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// type. The specified array must have the same number of operands as our 10751afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner /// current one. 1076db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner Constant *getWithOperands(ArrayRef<Constant*> Ops, Type *Ty) const; 10771afcace3a3a138b1b18e5c6270caa8dae2261ae2Chris Lattner 1078b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy /// getAsInstruction - Returns an Instruction which implements the same operation 1079b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy /// as this ConstantExpr. The instruction is not linked to any basic block. 1080b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy /// 1081b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy /// A better approach to this could be to have a constructor for Instruction 1082b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy /// which would take a ConstantExpr parameter, but that would have spread 1083b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy /// implementation details of ConstantExpr outside of Constants.cpp, which 10844fe6d0341daa95c639db8e70450bd8ae243fe344James Molloy /// would make it harder to remove ConstantExprs altogether. 1085b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy Instruction *getAsInstruction(); 1086b9478c2aef060aa6b0ede41c05859c34b1527bf8James Molloy 108704fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 108840cdedecf5d871a83363cb7d69a6f6eed525651cChris Lattner virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U); 10899769ab22265b313171d201b5928688524a01bd87Misha Brukman 109093aeea3748b11fa213b345edf3c86275a4936a31Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 109129ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve static inline bool classof(const Value *V) { 1092a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == ConstantExprVal; 109329ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve } 10944d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 1095cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattnerprivate: 1096cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner // Shadow Value::setValueSubclassData with a private forwarding method so that 1097cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner // subclasses cannot accidentally use it. 1098cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner void setValueSubclassData(unsigned short D) { 1099cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner Value::setValueSubclassData(D); 1100cafe9bba32aeed16e8e3db28b4cd4ff13160438fChris Lattner } 110129ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve}; 110229ab9f83481cd21abf3055c7c32ea1df953ae167Vikram S. Adve 1103efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greiftemplate <> 110467c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foadstruct OperandTraits<ConstantExpr> : 110567c619ba3eae68dcdb3f9340d82b33173aa0c256Jay Foad public VariadicOperandTraits<ConstantExpr, 1> { 1106efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif}; 1107efe65369a74871c3140a540a6c95ce5d1f080954Gabor Greif 1108ff7782bcc9235b1dc4c7fcb0497c52e4717eeffcJay FoadDEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant) 1109e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 1110e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner//===----------------------------------------------------------------------===// 1111e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// UndefValue - 'undef' values are things that do not have specified contents. 1112e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// These are used for a variety of purposes, including global variable 1113e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// initializers and operands to instructions. 'undef' values can occur with 1114fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// any first-class type. 1115fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// 1116fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// Undef values aren't exactly constants; if they have multiple uses, they 1117fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// can appear to have different bit patterns at each use. See 1118fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman/// LangRef.html#undefvalues for details. 1119e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner/// 1120e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerclass UndefValue : public Constant { 11210cb0a3533788c6c622518cb030048012eb69af15Craig Topper void *operator new(size_t, unsigned) LLVM_DELETED_FUNCTION; 11220cb0a3533788c6c622518cb030048012eb69af15Craig Topper UndefValue(const UndefValue &) LLVM_DELETED_FUNCTION; 1123e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerprotected: 1124db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner explicit UndefValue(Type *T) : Constant(T, UndefValueVal, 0, 0) {} 1125051a950000e21935165db56695e35bade668193bGabor Greifprotected: 1126051a950000e21935165db56695e35bade668193bGabor Greif // allocate space for exactly zero operands 1127051a950000e21935165db56695e35bade668193bGabor Greif void *operator new(size_t s) { 1128051a950000e21935165db56695e35bade668193bGabor Greif return User::operator new(s, 0); 1129051a950000e21935165db56695e35bade668193bGabor Greif } 1130e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattnerpublic: 1131e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// get() - Static factory methods - Return an 'undef' object of the specified 1132e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// type. 1133e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// 1134db125cfaf57cc83e7dd7453de2d509bc8efd0e5eChris Lattner static UndefValue *get(Type *T); 1135e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 1136ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// getSequentialElement - If this Undef has array or vector type, return a 1137ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// undef with the right element type. 11383d5ed2250e78c3e849232398cb550238155dbb72Chris Lattner UndefValue *getSequentialElement() const; 11394d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 1140ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// getStructElement - If this undef has struct type, return a undef with the 1141ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// right element type for the specified element. 11423d5ed2250e78c3e849232398cb550238155dbb72Chris Lattner UndefValue *getStructElement(unsigned Elt) const; 11434d7f70cbb5611bb9f840377ddb65ca78f3afa8e2Jakub Staszak 1144ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// getElementValue - Return an undef of the right value for the specified GEP 1145ff2b7f3cd66793e36a36500acb36b9d1a0489d4cChris Lattner /// index. 11463d5ed2250e78c3e849232398cb550238155dbb72Chris Lattner UndefValue *getElementValue(Constant *C) const; 1147df39028607ca751f0a3f50a76144464b825ff97aChris Lattner 1148df39028607ca751f0a3f50a76144464b825ff97aChris Lattner /// getElementValue - Return an undef of the right value for the specified GEP 1149df39028607ca751f0a3f50a76144464b825ff97aChris Lattner /// index. 11503d5ed2250e78c3e849232398cb550238155dbb72Chris Lattner UndefValue *getElementValue(unsigned Idx) const; 1151df39028607ca751f0a3f50a76144464b825ff97aChris Lattner 115204fb7c36a9977127f32558dc01c39a9c2388bc39Owen Anderson virtual void destroyConstant(); 1153e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner 1154e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner /// Methods for support type inquiry through isa, cast, and dyn_cast: 1155e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner static bool classof(const Value *V) { 1156a1a702cdd23221e6e3f36632be91150138958e9dDan Gohman return V->getValueID() == UndefValueVal; 1157e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner } 1158e1e922e09007f15aa01b438e5cf6a69c5a67afe4Chris Lattner}; 1159fd726176886b946ff4eaaf85bd254c5fbbacabfdDan Gohman 1160d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke} // End llvm namespace 1161d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke 1162009505452b713ed2e3a8e99c5545a6e721c65495Chris Lattner#endif 1163