11 #include "llvm/IR/Constant.h" 12 #include "llvm/IR/Type.h" 23 const uint64_t IntValue =
25 ? 0xFFFFFFFFFFFFFFFFull
26 : 0xAAAAAAAAAAAAAAAAull;
33 constexpr
bool NegativeNaN =
true;
34 constexpr uint64_t NaNPayload = 0xFFFFFFFFFFFFFFFFull;
35 if (Ty->isIntOrIntVectorTy()) {
36 unsigned BitWidth = cast<llvm::IntegerType>(
37 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty)
40 return llvm::ConstantInt::get(Ty, IntValue);
41 return llvm::ConstantInt::get(
42 Ty, llvm::APInt::getSplat(BitWidth, llvm::APInt(64, IntValue)));
44 if (Ty->isPtrOrPtrVectorTy()) {
45 auto *PtrTy = cast<llvm::PointerType>(
46 Ty->isVectorTy() ? Ty->getVectorElementType() : Ty);
48 PtrTy->getAddressSpace());
50 llvm_unreachable(
"pattern initialization of unsupported pointer width");
51 llvm::Type *IntTy = llvm::IntegerType::get(CGM.
getLLVMContext(), PtrWidth);
52 auto *Int = llvm::ConstantInt::get(IntTy, IntValue);
53 return llvm::ConstantExpr::getIntToPtr(Int, PtrTy);
55 if (Ty->isFPOrFPVectorTy()) {
56 unsigned BitWidth = llvm::APFloat::semanticsSizeInBits(
57 (Ty->isVectorTy() ? Ty->getVectorElementType() : Ty)
59 llvm::APInt Payload(64, NaNPayload);
61 Payload = llvm::APInt::getSplat(BitWidth, Payload);
62 return llvm::ConstantFP::getQNaN(Ty, NegativeNaN, &Payload);
64 if (Ty->isArrayTy()) {
67 auto *ArrTy = cast<llvm::ArrayType>(Ty);
69 ArrTy->getNumElements(),
71 return llvm::ConstantArray::get(ArrTy, Element);
80 auto *StructTy = cast<llvm::StructType>(Ty);
82 for (
unsigned El = 0; El != Struct.size(); ++El)
84 return llvm::ConstantStruct::get(StructTy, Struct);
llvm::Constant * initializationPatternFor(CodeGenModule &, llvm::Type *)
llvm::LLVMContext & getLLVMContext()
const TargetInfo & getTargetInfo() const
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
ASTContext & getContext() const
This class organizes the cross-function state that is used while generating LLVM code.
virtual uint64_t getMaxPointerWidth() const
Return the maximum width of pointers on this target.