12#include "llvm/IR/Constant.h"
13#include "llvm/IR/Type.h"
24 const uint64_t IntValue =
26 ? 0xFFFFFFFFFFFFFFFFull
27 : 0xAAAAAAAAAAAAAAAAull;
34 constexpr bool NegativeNaN =
true;
35 constexpr uint64_t NaNPayload = 0xFFFFFFFFFFFFFFFFull;
36 if (Ty->isIntOrIntVectorTy()) {
38 cast<llvm::IntegerType>(Ty->getScalarType())->getBitWidth();
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>(Ty->getScalarType());
47 CGM.
getDataLayout().getPointerSizeInBits(PtrTy->getAddressSpace());
49 llvm_unreachable(
"pattern initialization of unsupported pointer width");
50 llvm::Type *IntTy = llvm::IntegerType::get(CGM.
getLLVMContext(), PtrWidth);
51 auto *Int = llvm::ConstantInt::get(IntTy, IntValue);
52 return llvm::ConstantExpr::getIntToPtr(Int, PtrTy);
54 if (Ty->isFPOrFPVectorTy()) {
55 unsigned BitWidth = llvm::APFloat::semanticsSizeInBits(
56 Ty->getScalarType()->getFltSemantics());
57 llvm::APInt Payload(64, NaNPayload);
59 Payload = llvm::APInt::getSplat(BitWidth, Payload);
60 return llvm::ConstantFP::getQNaN(Ty, NegativeNaN, &Payload);
62 if (Ty->isArrayTy()) {
65 auto *ArrTy = cast<llvm::ArrayType>(Ty);
67 ArrTy->getNumElements(),
69 return llvm::ConstantArray::get(ArrTy, Element);
78 auto *StructTy = cast<llvm::StructType>(Ty);
80 for (
unsigned El = 0; El != Struct.size(); ++El)
82 return llvm::ConstantStruct::get(StructTy, Struct);
const TargetInfo & getTargetInfo() const
This class organizes the cross-function state that is used while generating LLVM code.
const llvm::DataLayout & getDataLayout() const
ASTContext & getContext() const
llvm::LLVMContext & getLLVMContext()
virtual uint64_t getMaxPointerWidth() const
Return the maximum width of pointers on this target.
Defines the clang::TargetInfo interface.
llvm::Constant * initializationPatternFor(CodeGenModule &, llvm::Type *)