diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -79,7 +79,7 @@ APInt Val; - ConstantInt(IntegerType *Ty, const APInt& V); + ConstantInt(IntegerType *Ty, const APInt &V); void destroyConstantImpl(); @@ -95,16 +95,15 @@ /// If Ty is a vector type, return a Constant with a splat of the given /// value. Otherwise return a ConstantInt for the given value. - static Constant *get(Type *Ty, uint64_t V, bool isSigned = false); + static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false); /// Return a ConstantInt with the specified integer value for the specified /// type. If the type is wider than 64 bits, the value will be zero-extended - /// to fit the type, unless isSigned is true, in which case the value will + /// to fit the type, unless IsSigned is true, in which case the value will /// be interpreted as a 64-bit signed integer and sign-extended to fit /// the type. /// Get a ConstantInt for a specific value. - static ConstantInt *get(IntegerType *Ty, uint64_t V, - bool isSigned = false); + static ConstantInt *get(IntegerType *Ty, uint64_t V, bool IsSigned = false); /// Return a ConstantInt with the specified value for the specified type. The /// value V will be canonicalized to a an unsigned APInt. Accessing it with @@ -120,19 +119,16 @@ /// Return a ConstantInt constructed from the string strStart with the given /// radix. - static ConstantInt *get(IntegerType *Ty, StringRef Str, - uint8_t radix); + static ConstantInt *get(IntegerType *Ty, StringRef Str, uint8_t Radix); /// If Ty is a vector type, return a Constant with a splat of the given /// value. Otherwise return a ConstantInt for the given value. - static Constant *get(Type* Ty, const APInt& V); + static Constant *get(Type *Ty, const APInt &V); /// Return the constant as an APInt value reference. This allows clients to /// obtain a full-precision copy of the value. /// Return the constant's value. - inline const APInt &getValue() const { - return Val; - } + inline const APInt &getValue() const { return Val; } /// getBitWidth - Return the bitwidth of this constant. unsigned getBitWidth() const { return Val.getBitWidth(); } @@ -141,17 +137,13 @@ /// has been zero extended as appropriate for the type of this constant. Note /// that this method can assert if the value does not fit in 64 bits. /// Return the zero extended value. - inline uint64_t getZExtValue() const { - return Val.getZExtValue(); - } + inline uint64_t getZExtValue() const { return Val.getZExtValue(); } /// Return the constant as a 64-bit integer value after it has been sign /// extended as appropriate for the type of this constant. Note that /// this method can assert if the value does not fit in 64 bits. /// Return the sign extended value. - inline int64_t getSExtValue() const { - return Val.getSExtValue(); - } + inline int64_t getSExtValue() const { return Val.getSExtValue(); } /// Return the constant as an llvm::MaybeAlign. /// Note that this method can assert if the value does not fit in 64 bits or @@ -171,9 +163,7 @@ /// within is equal to a constant. This only works for very small values, /// because this is all that can be represented with all types. /// Determine if this constant's value is same as an unsigned char. - bool equalsInt(uint64_t V) const { - return Val == V; - } + bool equalsInt(uint64_t V) const { return Val == V; } /// getType - Specialize the getType() method to always return an IntegerType, /// which reduces the amount of casting needed in parts of the compiler. @@ -199,33 +189,27 @@ /// This is just a convenience method to make client code smaller for a /// common code. It also correctly performs the comparison without the /// potential for an assertion from getZExtValue(). - bool isZero() const { - return Val.isNullValue(); - } + bool isZero() const { return Val.isNullValue(); } /// This is just a convenience method to make client code smaller for a /// common case. It also correctly performs the comparison without the /// potential for an assertion from getZExtValue(). /// Determine if the value is one. - bool isOne() const { - return Val.isOneValue(); - } + bool isOne() const { return Val.isOneValue(); } /// This function will return true iff every bit in this constant is set /// to true. /// @returns true iff this constant's bits are all set to true. /// Determine if the value is all ones. - bool isMinusOne() const { - return Val.isAllOnesValue(); - } + bool isMinusOne() const { return Val.isAllOnesValue(); } /// This function will return true iff this constant represents the largest /// value that may be represented by the constant's type. /// @returns true iff this is the largest value that may be represented /// by this type. /// Determine if the value is maximal. - bool isMaxValue(bool isSigned) const { - if (isSigned) + bool isMaxValue(bool IsSigned) const { + if (IsSigned) return Val.isMaxSignedValue(); else return Val.isMaxValue(); @@ -236,8 +220,8 @@ /// @returns true if this is the smallest value that may be represented by /// this type. /// Determine if the value is minimal. - bool isMinValue(bool isSigned) const { - if (isSigned) + bool isMinValue(bool IsSigned) const { + if (IsSigned) return Val.isMinSignedValue(); else return Val.isMinValue(); @@ -248,9 +232,7 @@ /// value. /// @returns true iff this constant is greater or equal to the given number. /// Determine if the value is greater or equal to the given number. - bool uge(uint64_t Num) const { - return Val.uge(Num); - } + bool uge(uint64_t Num) const { return Val.uge(Num); } /// getLimitedValue - If the value is smaller than the specified limit, /// return it, otherwise return the limit value. This causes the value @@ -275,7 +257,7 @@ APFloat Val; - ConstantFP(Type *Ty, const APFloat& V); + ConstantFP(Type *Ty, const APFloat &V); void destroyConstantImpl(); @@ -291,15 +273,16 @@ /// for the specified value in the specified type. This should only be used /// for simple constant values like 2.0/1.0 etc, that are known-valid both as /// host double and as the target format. - static Constant *get(Type* Ty, double V); + static Constant *get(Type *Ty, double V); /// If Ty is a vector type, return a Constant with a splat of the given /// value. Otherwise return a ConstantFP for the given value. static Constant *get(Type *Ty, const APFloat &V); - static Constant *get(Type* Ty, StringRef Str); + static Constant *get(Type *Ty, StringRef Str); static ConstantFP *get(LLVMContext &Context, const APFloat &V); - static Constant *getNaN(Type *Ty, bool Negative = false, uint64_t Payload = 0); + static Constant *getNaN(Type *Ty, bool Negative = false, + uint64_t Payload = 0); static Constant *getQNaN(Type *Ty, bool Negative = false, APInt *Payload = nullptr); static Constant *getSNaN(Type *Ty, bool Negative = false, @@ -432,7 +415,7 @@ public: // ConstantArray accessors - static Constant *get(ArrayType *T, ArrayRef V); + static Constant *get(ArrayType *T, ArrayRef V); private: static Constant *getImpl(ArrayType *T, ArrayRef V); @@ -464,7 +447,7 @@ public: // ConstantStruct accessors - static Constant *get(StructType *T, ArrayRef V); + static Constant *get(StructType *T, ArrayRef V); template static std::enable_if_t::value, Constant *> @@ -475,21 +458,21 @@ /// Return an anonymous struct that has the specified elements. /// If the struct is possibly empty, then you must specify a context. - static Constant *getAnon(ArrayRef V, bool Packed = false) { + static Constant *getAnon(ArrayRef V, bool Packed = false) { return get(getTypeForElements(V, Packed), V); } - static Constant *getAnon(LLVMContext &Ctx, - ArrayRef V, bool Packed = false) { + static Constant *getAnon(LLVMContext &Ctx, ArrayRef V, + bool Packed = false) { return get(getTypeForElements(Ctx, V, Packed), V); } /// Return an anonymous struct type to use for a constant with the specified /// set of elements. The list must not be empty. - static StructType *getTypeForElements(ArrayRef V, + static StructType *getTypeForElements(ArrayRef V, bool Packed = false); /// This version of the method allows an empty list. static StructType *getTypeForElements(LLVMContext &Ctx, - ArrayRef V, + ArrayRef V, bool Packed = false); /// Specialization - reduce amount of casting. @@ -517,7 +500,7 @@ public: // ConstantVector accessors - static Constant *get(ArrayRef V); + static Constant *get(ArrayRef V); private: static Constant *getImpl(ArrayRef V); @@ -575,10 +558,10 @@ //===----------------------------------------------------------------------===// /// ConstantDataSequential - A vector or array constant whose element type is a -/// simple 1/2/4/8-byte integer or float/double, and whose elements are just -/// simple data values (i.e. ConstantInt/ConstantFP). This Constant node has no -/// operands because it stores all of the elements of the constant as densely -/// packed data, instead of as Value*'s. +/// simple 1/2/4/8-byte integer or half/bloat/float/double, and whose elements +/// are just simple data values (i.e. ConstantInt/ConstantFP). This Constant +/// node has no operands because it stores all of the elements of the constant +/// as densely packed data, instead of as Value*'s. /// /// This is the common base class of ConstantDataArray and ConstantDataVector. /// @@ -667,7 +650,7 @@ StringRef getAsCString() const { assert(isCString() && "Isn't a C string"); StringRef Str = getAsString(); - return Str.substr(0, Str.size()-1); + return Str.substr(0, Str.size() - 1); } /// Return the raw, underlying, bytes of this data. Note that this is an @@ -717,13 +700,14 @@ return ConstantDataArray::get(Context, makeArrayRef(Elts)); } - /// get() constructor - Return a constant with array type with an element + /// getRaw() constructor - Return a constant with array type with an element /// count and element type matching the NumElements and ElementTy parameters /// passed in. Note that this can return a ConstantAggregateZero object. - /// ElementTy needs to be one of i8/i16/i32/i64/float/double. Data is the - /// buffer containing the elements. Be careful to make sure Data uses the + /// ElementTy must be one of i8/i16/i32/i64/half/bfloat/float/double. Data is + /// the buffer containing the elements. Be careful to make sure Data uses the /// right endianness, the buffer will be used as-is. - static Constant *getRaw(StringRef Data, uint64_t NumElements, Type *ElementTy) { + static Constant *getRaw(StringRef Data, uint64_t NumElements, + Type *ElementTy) { Type *Ty = ArrayType::get(ElementTy, NumElements); return getImpl(Data, Ty); } @@ -788,6 +772,18 @@ static Constant *get(LLVMContext &Context, ArrayRef Elts); static Constant *get(LLVMContext &Context, ArrayRef Elts); + /// getRaw() constructor - Return a constant with vector type with an element + /// count and element type matching the NumElements and ElementTy parameters + /// passed in. Note that this can return a ConstantAggregateZero object. + /// ElementTy must be one of i8/i16/i32/i64/half/bfloat/float/double. Data is + /// the buffer containing the elements. Be careful to make sure Data uses the + /// right endianness, the buffer will be used as-is. + static Constant *getRaw(StringRef Data, uint64_t NumElements, + Type *ElementTy) { + Type *Ty = VectorType::get(ElementTy, ElementCount::getFixed(NumElements)); + return getImpl(Data, Ty); + } + /// getFP() constructors - Return a constant of vector type with a float /// element type taken from argument `ElementType', and count taken from /// argument `Elts'. The amount of bits of the contained type must match the @@ -800,7 +796,7 @@ /// Return a ConstantVector with the specified constant in each element. /// The specified constant has to be a of a compatible type (i8/i16/ - /// i32/i64/float/double) and must be a ConstantFP or ConstantInt. + /// i32/i64/half/bfloat/float/double) and must be a ConstantFP or ConstantInt. static Constant *getSplat(unsigned NumElts, Constant *Elt); /// Returns true if this is a splat constant, meaning that all elements have @@ -874,8 +870,8 @@ /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); - Function *getFunction() const { return (Function*)Op<0>().get(); } - BasicBlock *getBasicBlock() const { return (BasicBlock*)Op<1>().get(); } + Function *getFunction() const { return (Function *)Op<0>().get(); } + BasicBlock *getBasicBlock() const { return (BasicBlock *)Op<1>().get(); } /// Methods for support type inquiry through isa, cast, and dyn_cast: static bool classof(const Value *V) { @@ -884,9 +880,8 @@ }; template <> -struct OperandTraits : - public FixedNumOperandTraits { -}; +struct OperandTraits + : public FixedNumOperandTraits {}; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BlockAddress, Value) @@ -975,17 +970,18 @@ /// static Constant *getOffsetOf(Type *Ty, Constant *FieldNo); - static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW =false); + static Constant *getNeg(Constant *C, bool HasNUW = false, + bool HasNSW = false); static Constant *getFNeg(Constant *C); static Constant *getNot(Constant *C); - static Constant *getAdd(Constant *C1, Constant *C2, - bool HasNUW = false, bool HasNSW = false); + static Constant *getAdd(Constant *C1, Constant *C2, bool HasNUW = false, + bool HasNSW = false); static Constant *getFAdd(Constant *C1, Constant *C2); - static Constant *getSub(Constant *C1, Constant *C2, - bool HasNUW = false, bool HasNSW = false); + static Constant *getSub(Constant *C1, Constant *C2, bool HasNUW = false, + bool HasNSW = false); static Constant *getFSub(Constant *C1, Constant *C2); - static Constant *getMul(Constant *C1, Constant *C2, - bool HasNUW = false, bool HasNSW = false); + static Constant *getMul(Constant *C1, Constant *C2, bool HasNUW = false, + bool HasNSW = false); static Constant *getFMul(Constant *C1, Constant *C2); static Constant *getUDiv(Constant *C1, Constant *C2, bool isExact = false); static Constant *getSDiv(Constant *C1, Constant *C2, bool isExact = false); @@ -997,8 +993,8 @@ static Constant *getOr(Constant *C1, Constant *C2); static Constant *getXor(Constant *C1, Constant *C2); static Constant *getUMin(Constant *C1, Constant *C2); - static Constant *getShl(Constant *C1, Constant *C2, - bool HasNUW = false, bool HasNSW = false); + static Constant *getShl(Constant *C1, Constant *C2, bool HasNUW = false, + bool HasNSW = false); static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false); static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false); static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false); @@ -1107,48 +1103,47 @@ bool OnlyIfReduced = false); // Create a ZExt or BitCast cast constant expression - static Constant *getZExtOrBitCast( - Constant *C, ///< The constant to zext or bitcast - Type *Ty ///< The type to zext or bitcast C to + static Constant * + getZExtOrBitCast(Constant *C, ///< The constant to zext or bitcast + Type *Ty ///< The type to zext or bitcast C to ); // Create a SExt or BitCast cast constant expression - static Constant *getSExtOrBitCast( - Constant *C, ///< The constant to sext or bitcast - Type *Ty ///< The type to sext or bitcast C to + static Constant * + getSExtOrBitCast(Constant *C, ///< The constant to sext or bitcast + Type *Ty ///< The type to sext or bitcast C to ); // Create a Trunc or BitCast cast constant expression - static Constant *getTruncOrBitCast( - Constant *C, ///< The constant to trunc or bitcast - Type *Ty ///< The type to trunc or bitcast C to + static Constant * + getTruncOrBitCast(Constant *C, ///< The constant to trunc or bitcast + Type *Ty ///< The type to trunc or bitcast C to ); /// Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant /// expression. - static Constant *getPointerCast( - Constant *C, ///< The pointer value to be casted (operand 0) - Type *Ty ///< The type to which cast should be made + static Constant * + getPointerCast(Constant *C, ///< The pointer value to be casted (operand 0) + Type *Ty ///< The type to which cast should be made ); /// Create a BitCast or AddrSpaceCast for a pointer type depending on /// the address space. static Constant *getPointerBitCastOrAddrSpaceCast( - Constant *C, ///< The constant to addrspacecast or bitcast - Type *Ty ///< The type to bitcast or addrspacecast C to + Constant *C, ///< The constant to addrspacecast or bitcast + Type *Ty ///< The type to bitcast or addrspacecast C to ); /// Create a ZExt, Bitcast or Trunc for integer -> integer casts - static Constant *getIntegerCast( - Constant *C, ///< The integer constant to be casted - Type *Ty, ///< The integer type to cast to - bool isSigned ///< Whether C should be treated as signed or not + static Constant * + getIntegerCast(Constant *C, ///< The integer constant to be casted + Type *Ty, ///< The integer type to cast to + bool IsSigned ///< Whether C should be treated as signed or not ); /// Create a FPExt, Bitcast or FPTrunc for fp -> fp casts - static Constant *getFPCast( - Constant *C, ///< The integer constant to be casted - Type *Ty ///< The integer type to cast to + static Constant *getFPCast(Constant *C, ///< The integer constant to be casted + Type *Ty ///< The integer type to cast to ); /// Return true if this is a convert constant expression @@ -1178,7 +1173,7 @@ /// folding if possible. /// /// \param OnlyIfReducedTy see \a getWithOperands() docs. - static Constant *get(unsigned Opcode, Constant *C1, unsigned Flags = 0, + static Constant *get(unsigned Opcode, Constant *C1, unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr); /// get - Return a binary or shift operator constant expression, @@ -1213,7 +1208,7 @@ Optional InRangeIndex = None, Type *OnlyIfReducedTy = nullptr) { return getGetElementPtr( - Ty, C, makeArrayRef((Value * const *)IdxList.data(), IdxList.size()), + Ty, C, makeArrayRef((Value *const *)IdxList.data(), IdxList.size()), InBounds, InRangeIndex, OnlyIfReducedTy); } static Constant *getGetElementPtr(Type *Ty, Constant *C, Constant *Idx, @@ -1294,7 +1289,7 @@ /// This returns the current constant expression with the operands replaced /// with the specified values. The specified array must have the same number /// of operands as our current one. - Constant *getWithOperands(ArrayRef Ops) const { + Constant *getWithOperands(ArrayRef Ops) const { return getWithOperands(Ops, getType()); } @@ -1334,9 +1329,8 @@ }; template <> -struct OperandTraits : - public VariadicOperandTraits { -}; +struct OperandTraits + : public VariadicOperandTraits {}; DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantExpr, Constant) diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp --- a/llvm/unittests/IR/ConstantsTest.cpp +++ b/llvm/unittests/IR/ConstantsTest.cpp @@ -23,11 +23,11 @@ TEST(ConstantsTest, Integer_i1) { LLVMContext Context; IntegerType *Int1 = IntegerType::get(Context, 1); - Constant* One = ConstantInt::get(Int1, 1, true); - Constant* Zero = ConstantInt::get(Int1, 0); - Constant* NegOne = ConstantInt::get(Int1, static_cast(-1), true); + Constant *One = ConstantInt::get(Int1, 1, true); + Constant *Zero = ConstantInt::get(Int1, 0); + Constant *NegOne = ConstantInt::get(Int1, static_cast(-1), true); EXPECT_EQ(NegOne, ConstantInt::getSigned(Int1, -1)); - Constant* Undef = UndefValue::get(Int1); + Constant *Undef = UndefValue::get(Int1); // Input: @b = constant i1 add(i1 1 , i1 1) // Output: @b = constant i1 false @@ -136,35 +136,33 @@ VectorType *Int64VecTy = FixedVectorType::get(Int64Ty, 4); // ptrtoint i8* to i64 - EXPECT_EQ(Constant::getNullValue(Int64Ty), - ConstantExpr::getPointerCast( - Constant::getNullValue(Int8PtrTy), Int64Ty)); + EXPECT_EQ( + Constant::getNullValue(Int64Ty), + ConstantExpr::getPointerCast(Constant::getNullValue(Int8PtrTy), Int64Ty)); // bitcast i8* to i32* EXPECT_EQ(Constant::getNullValue(Int32PtrTy), - ConstantExpr::getPointerCast( - Constant::getNullValue(Int8PtrTy), Int32PtrTy)); + ConstantExpr::getPointerCast(Constant::getNullValue(Int8PtrTy), + Int32PtrTy)); // ptrtoint <4 x i8*> to <4 x i64> EXPECT_EQ(Constant::getNullValue(Int64VecTy), - ConstantExpr::getPointerCast( - Constant::getNullValue(Int8PtrVecTy), Int64VecTy)); + ConstantExpr::getPointerCast(Constant::getNullValue(Int8PtrVecTy), + Int64VecTy)); // bitcast <4 x i8*> to <4 x i32*> EXPECT_EQ(Constant::getNullValue(Int32PtrVecTy), - ConstantExpr::getPointerCast( - Constant::getNullValue(Int8PtrVecTy), Int32PtrVecTy)); + ConstantExpr::getPointerCast(Constant::getNullValue(Int8PtrVecTy), + Int32PtrVecTy)); Type *Int32Ptr1Ty = Type::getInt32PtrTy(C, 1); ConstantInt *K = ConstantInt::get(Type::getInt64Ty(C), 1234); // Make sure that addrspacecast of inttoptr is not folded away. - EXPECT_NE(K, - ConstantExpr::getAddrSpaceCast( - ConstantExpr::getIntToPtr(K, Int32PtrTy), Int32Ptr1Ty)); - EXPECT_NE(K, - ConstantExpr::getAddrSpaceCast( - ConstantExpr::getIntToPtr(K, Int32Ptr1Ty), Int32PtrTy)); + EXPECT_NE(K, ConstantExpr::getAddrSpaceCast( + ConstantExpr::getIntToPtr(K, Int32PtrTy), Int32Ptr1Ty)); + EXPECT_NE(K, ConstantExpr::getAddrSpaceCast( + ConstantExpr::getIntToPtr(K, Int32Ptr1Ty), Int32PtrTy)); Constant *NullInt32Ptr0 = Constant::getNullValue(Int32PtrTy); Constant *NullInt32Ptr1 = Constant::getNullValue(Int32Ptr1Ty); @@ -199,10 +197,10 @@ Type *FloatTy = Type::getFloatTy(Context); Type *DoubleTy = Type::getDoubleTy(Context); - Constant *Global = M->getOrInsertGlobal("dummy", - PointerType::getUnqual(Int32Ty)); - Constant *Global2 = M->getOrInsertGlobal("dummy2", - PointerType::getUnqual(Int32Ty)); + Constant *Global = + M->getOrInsertGlobal("dummy", PointerType::getUnqual(Int32Ty)); + Constant *Global2 = + M->getOrInsertGlobal("dummy2", PointerType::getUnqual(Int32Ty)); Constant *P0 = ConstantExpr::getPtrToInt(Global, Int32Ty); Constant *P1 = ConstantExpr::getUIToFP(P0, FloatTy); @@ -217,26 +215,26 @@ Constant *Big = ConstantInt::get(Context, APInt{256, uint64_t(-1), true}); Constant *Elt = ConstantInt::get(Int16Ty, 2015); Constant *Poison16 = PoisonValue::get(Int16Ty); - Constant *Undef64 = UndefValue::get(Int64Ty); + Constant *Undef64 = UndefValue::get(Int64Ty); Constant *UndefV16 = UndefValue::get(P6->getType()); Constant *PoisonV16 = PoisonValue::get(P6->getType()); - #define P0STR "ptrtoint (i32** @dummy to i32)" - #define P1STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to float)" - #define P2STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to double)" - #define P3STR "ptrtoint (i32** @dummy to i1)" - #define P4STR "ptrtoint (i32** @dummy2 to i32)" - #define P5STR "uitofp (i32 ptrtoint (i32** @dummy2 to i32) to float)" - #define P6STR "bitcast (i32 ptrtoint (i32** @dummy2 to i32) to <2 x i16>)" +#define P0STR "ptrtoint (i32** @dummy to i32)" +#define P1STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to float)" +#define P2STR "uitofp (i32 ptrtoint (i32** @dummy to i32) to double)" +#define P3STR "ptrtoint (i32** @dummy to i1)" +#define P4STR "ptrtoint (i32** @dummy2 to i32)" +#define P5STR "uitofp (i32 ptrtoint (i32** @dummy2 to i32) to float)" +#define P6STR "bitcast (i32 ptrtoint (i32** @dummy2 to i32) to <2 x i16>)" CHECK(ConstantExpr::getNeg(P0), "sub i32 0, " P0STR); CHECK(ConstantExpr::getFNeg(P1), "fneg float " P1STR); CHECK(ConstantExpr::getNot(P0), "xor i32 " P0STR ", -1"); CHECK(ConstantExpr::getAdd(P0, P0), "add i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getAdd(P0, P0, false, true), "add nsw i32 " P0STR ", " - P0STR); - CHECK(ConstantExpr::getAdd(P0, P0, true, true), "add nuw nsw i32 " P0STR ", " - P0STR); + CHECK(ConstantExpr::getAdd(P0, P0, false, true), + "add nsw i32 " P0STR ", " P0STR); + CHECK(ConstantExpr::getAdd(P0, P0, true, true), + "add nuw nsw i32 " P0STR ", " P0STR); CHECK(ConstantExpr::getFAdd(P1, P1), "fadd float " P1STR ", " P1STR); CHECK(ConstantExpr::getSub(P0, P0), "sub i32 " P0STR ", " P0STR); CHECK(ConstantExpr::getFSub(P1, P1), "fsub float " P1STR ", " P1STR); @@ -253,48 +251,50 @@ CHECK(ConstantExpr::getXor(P0, P0), "xor i32 " P0STR ", " P0STR); CHECK(ConstantExpr::getShl(P0, P0), "shl i32 " P0STR ", " P0STR); CHECK(ConstantExpr::getShl(P0, P0, true), "shl nuw i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getShl(P0, P0, false, true), "shl nsw i32 " P0STR ", " - P0STR); + CHECK(ConstantExpr::getShl(P0, P0, false, true), + "shl nsw i32 " P0STR ", " P0STR); CHECK(ConstantExpr::getLShr(P0, P0, false), "lshr i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getLShr(P0, P0, true), "lshr exact i32 " P0STR ", " P0STR); + CHECK(ConstantExpr::getLShr(P0, P0, true), + "lshr exact i32 " P0STR ", " P0STR); CHECK(ConstantExpr::getAShr(P0, P0, false), "ashr i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getAShr(P0, P0, true), "ashr exact i32 " P0STR ", " P0STR); + CHECK(ConstantExpr::getAShr(P0, P0, true), + "ashr exact i32 " P0STR ", " P0STR); CHECK(ConstantExpr::getSExt(P0, Int64Ty), "sext i32 " P0STR " to i64"); CHECK(ConstantExpr::getZExt(P0, Int64Ty), "zext i32 " P0STR " to i64"); - CHECK(ConstantExpr::getFPTrunc(P2, FloatTy), "fptrunc double " P2STR - " to float"); - CHECK(ConstantExpr::getFPExtend(P1, DoubleTy), "fpext float " P1STR - " to double"); + CHECK(ConstantExpr::getFPTrunc(P2, FloatTy), + "fptrunc double " P2STR " to float"); + CHECK(ConstantExpr::getFPExtend(P1, DoubleTy), + "fpext float " P1STR " to double"); CHECK(ConstantExpr::getExactUDiv(P0, P0), "udiv exact i32 " P0STR ", " P0STR); - CHECK(ConstantExpr::getSelect(P3, P0, P4), "select i1 " P3STR ", i32 " P0STR - ", i32 " P4STR); - CHECK(ConstantExpr::getICmp(CmpInst::ICMP_EQ, P0, P4), "icmp eq i32 " P0STR - ", " P4STR); - CHECK(ConstantExpr::getFCmp(CmpInst::FCMP_ULT, P1, P5), "fcmp ult float " - P1STR ", " P5STR); + CHECK(ConstantExpr::getSelect(P3, P0, P4), + "select i1 " P3STR ", i32 " P0STR ", i32 " P4STR); + CHECK(ConstantExpr::getICmp(CmpInst::ICMP_EQ, P0, P4), + "icmp eq i32 " P0STR ", " P4STR); + CHECK(ConstantExpr::getFCmp(CmpInst::FCMP_ULT, P1, P5), + "fcmp ult float " P1STR ", " P5STR); - std::vector V; + std::vector V; V.push_back(One); // FIXME: getGetElementPtr() actually creates an inbounds ConstantGEP, // not a normal one! - //CHECK(ConstantExpr::getGetElementPtr(Global, V, false), - // "getelementptr i32*, i32** @dummy, i32 1"); + // CHECK(ConstantExpr::getGetElementPtr(Global, V, false), + // "getelementptr i32*, i32** @dummy, i32 1"); CHECK(ConstantExpr::getInBoundsGetElementPtr(PointerType::getUnqual(Int32Ty), Global, V), "getelementptr inbounds i32*, i32** @dummy, i32 1"); - CHECK(ConstantExpr::getExtractElement(P6, One), "extractelement <2 x i16> " - P6STR ", i32 1"); + CHECK(ConstantExpr::getExtractElement(P6, One), + "extractelement <2 x i16> " P6STR ", i32 1"); EXPECT_EQ(Poison16, ConstantExpr::getExtractElement(P6, Two)); EXPECT_EQ(Poison16, ConstantExpr::getExtractElement(P6, Big)); EXPECT_EQ(Poison16, ConstantExpr::getExtractElement(P6, Undef64)); EXPECT_EQ(Elt, ConstantExpr::getExtractElement( - ConstantExpr::getInsertElement(P6, Elt, One), One)); + ConstantExpr::getInsertElement(P6, Elt, One), One)); EXPECT_EQ(UndefV16, ConstantExpr::getInsertElement(P6, Elt, Two)); EXPECT_EQ(UndefV16, ConstantExpr::getInsertElement(P6, Elt, Big)); EXPECT_EQ(PoisonV16, ConstantExpr::getInsertElement(P6, Elt, Undef64)); @@ -418,45 +418,55 @@ TEST(ConstantsTest, BuildConstantDataArrays) { LLVMContext Context; - std::unique_ptr M(new Module("MyModule", Context)); for (Type *T : {Type::getInt8Ty(Context), Type::getInt16Ty(Context), Type::getInt32Ty(Context), Type::getInt64Ty(Context)}) { ArrayType *ArrayTy = ArrayType::get(T, 2); Constant *Vals[] = {ConstantInt::get(T, 0), ConstantInt::get(T, 1)}; - Constant *CDV = ConstantArray::get(ArrayTy, Vals); - ASSERT_TRUE(dyn_cast(CDV) != nullptr) - << " T = " << getNameOfType(T); + Constant *CA = ConstantArray::get(ArrayTy, Vals); + ASSERT_TRUE(isa(CA)) << " T = " << getNameOfType(T); + auto *CDA = cast(CA); + Constant *CA2 = ConstantDataArray::getRaw( + CDA->getRawDataValues(), CDA->getNumElements(), CDA->getElementType()); + ASSERT_TRUE(CA == CA2) << " T = " << getNameOfType(T); } - for (Type *T : {Type::getHalfTy(Context), Type::getFloatTy(Context), - Type::getDoubleTy(Context)}) { + for (Type *T : {Type::getHalfTy(Context), Type::getBFloatTy(Context), + Type::getFloatTy(Context), Type::getDoubleTy(Context)}) { ArrayType *ArrayTy = ArrayType::get(T, 2); Constant *Vals[] = {ConstantFP::get(T, 0), ConstantFP::get(T, 1)}; - Constant *CDV = ConstantArray::get(ArrayTy, Vals); - ASSERT_TRUE(dyn_cast(CDV) != nullptr) - << " T = " << getNameOfType(T); + Constant *CA = ConstantArray::get(ArrayTy, Vals); + ASSERT_TRUE(isa(CA)) << " T = " << getNameOfType(T); + auto *CDA = cast(CA); + Constant *CA2 = ConstantDataArray::getRaw( + CDA->getRawDataValues(), CDA->getNumElements(), CDA->getElementType()); + ASSERT_TRUE(CA == CA2) << " T = " << getNameOfType(T); } } TEST(ConstantsTest, BuildConstantDataVectors) { LLVMContext Context; - std::unique_ptr M(new Module("MyModule", Context)); for (Type *T : {Type::getInt8Ty(Context), Type::getInt16Ty(Context), Type::getInt32Ty(Context), Type::getInt64Ty(Context)}) { Constant *Vals[] = {ConstantInt::get(T, 0), ConstantInt::get(T, 1)}; - Constant *CDV = ConstantVector::get(Vals); - ASSERT_TRUE(dyn_cast(CDV) != nullptr) - << " T = " << getNameOfType(T); + Constant *CV = ConstantVector::get(Vals); + ASSERT_TRUE(isa(CV)) << " T = " << getNameOfType(T); + auto *CDV = cast(CV); + Constant *CV2 = ConstantDataVector::getRaw( + CDV->getRawDataValues(), CDV->getNumElements(), CDV->getElementType()); + ASSERT_TRUE(CV == CV2) << " T = " << getNameOfType(T); } - for (Type *T : {Type::getHalfTy(Context), Type::getFloatTy(Context), - Type::getDoubleTy(Context)}) { + for (Type *T : {Type::getHalfTy(Context), Type::getBFloatTy(Context), + Type::getFloatTy(Context), Type::getDoubleTy(Context)}) { Constant *Vals[] = {ConstantFP::get(T, 0), ConstantFP::get(T, 1)}; - Constant *CDV = ConstantVector::get(Vals); - ASSERT_TRUE(dyn_cast(CDV) != nullptr) - << " T = " << getNameOfType(T); + Constant *CV = ConstantVector::get(Vals); + ASSERT_TRUE(isa(CV)) << " T = " << getNameOfType(T); + auto *CDV = cast(CV); + Constant *CV2 = ConstantDataVector::getRaw( + CDV->getRawDataValues(), CDV->getNumElements(), CDV->getElementType()); + ASSERT_TRUE(CV == CV2) << " T = " << getNameOfType(T); } } @@ -469,8 +479,8 @@ Type *EltTys[] = {i32, U}; auto *S = StructType::create(EltTys); - auto *G = new GlobalVariable(*M, S, false, - GlobalValue::ExternalLinkage, nullptr); + auto *G = + new GlobalVariable(*M, S, false, GlobalValue::ExternalLinkage, nullptr); auto *PtrTy = PointerType::get(i32, 0); auto *C = ConstantExpr::getBitCast(G, PtrTy); ASSERT_EQ(cast(C)->getOpcode(), Instruction::BitCast); @@ -481,8 +491,8 @@ MaybeAlign FunctionAlign = llvm::None) { Type *VoidType(Type::getVoidTy(Context)); FunctionType *FuncType(FunctionType::get(VoidType, false)); - Function *Func(Function::Create( - FuncType, GlobalValue::ExternalLinkage, "", TheModule)); + Function *Func( + Function::Create(FuncType, GlobalValue::ExternalLinkage, "", TheModule)); if (FunctionAlign) Func->setAlignment(*FunctionAlign); @@ -490,19 +500,18 @@ IntegerType *ConstantIntType(Type::getInt32Ty(Context)); ConstantInt *TheConstant(ConstantInt::get(ConstantIntType, AndValue)); - Constant *TheConstantExpr( - ConstantExpr::getPtrToInt(Func, ConstantIntType)); - + Constant *TheConstantExpr(ConstantExpr::getPtrToInt(Func, ConstantIntType)); - bool result = ConstantExpr::get(Instruction::And, TheConstantExpr, - TheConstant)->isNullValue(); + bool Result = + ConstantExpr::get(Instruction::And, TheConstantExpr, TheConstant) + ->isNullValue(); if (!TheModule) { // If the Module exists then it will delete the Function. delete Func; } - return result; + return Result; } TEST(ConstantsTest, FoldFunctionPtrAlignUnknownAnd2) { @@ -525,7 +534,7 @@ TEST(ConstantsTest, FoldFunctionPtrAlign4) { LLVMContext Context; Module TheModule("TestModule", Context); - const char* AlignmentStrings[] = { "Fi32", "Fn32" }; + const char *AlignmentStrings[] = {"Fi32", "Fn32"}; for (unsigned AndValue = 1; AndValue <= 2; ++AndValue) { for (const char *AlignmentString : AlignmentStrings) { @@ -538,9 +547,9 @@ TEST(ConstantsTest, DontFoldFunctionPtrAlign1) { LLVMContext Context; Module TheModule("TestModule", Context); - const char* AlignmentStrings[] = { "Fi8", "Fn8" }; + const char *AlignmentStrings[] = {"Fi8", "Fn8"}; - for (const char* AlignmentString : AlignmentStrings) { + for (const char *AlignmentString : AlignmentStrings) { TheModule.setDataLayout(AlignmentString); ASSERT_FALSE(foldFuncPtrAndConstToNull(Context, &TheModule, 2)); } @@ -579,11 +588,10 @@ ConstantInt *TheConstant(ConstantInt::get(IntType, 2)); - Constant *TheConstantExpr( - ConstantExpr::getPtrToInt(Global.get(), IntType)); + Constant *TheConstantExpr(ConstantExpr::getPtrToInt(Global.get(), IntType)); - ASSERT_TRUE(ConstantExpr::get( \ - Instruction::And, TheConstantExpr, TheConstant)->isNullValue()); + ASSERT_TRUE(ConstantExpr::get(Instruction::And, TheConstantExpr, TheConstant) + ->isNullValue()); } // Check that containsUndefOrPoisonElement and containsPoisonElement is working @@ -713,5 +721,5 @@ } } -} // end anonymous namespace -} // end namespace llvm +} // end anonymous namespace +} // end namespace llvm