diff options
Diffstat (limited to 'clang/lib/CodeGen/CodeGenTypes.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenTypes.cpp | 197 |
1 files changed, 156 insertions, 41 deletions
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp b/clang/lib/CodeGen/CodeGenTypes.cpp index a458811d7a30..d431c0263666 100644 --- a/clang/lib/CodeGen/CodeGenTypes.cpp +++ b/clang/lib/CodeGen/CodeGenTypes.cpp @@ -36,8 +36,6 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm) } CodeGenTypes::~CodeGenTypes() { - llvm::DeleteContainerSeconds(CGRecordLayouts); - for (llvm::FoldingSet<CGFunctionInfo>::iterator I = FunctionInfos.begin(), E = FunctionInfos.end(); I != E; ) delete &*I++; @@ -83,19 +81,26 @@ void CodeGenTypes::addRecordTypeName(const RecordDecl *RD, /// ConvertType in that it is used to convert to the memory representation for /// a type. For example, the scalar representation for _Bool is i1, but the /// memory representation is usually i8 or i32, depending on the target. -llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) { +llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T, bool ForBitField) { + if (T->isConstantMatrixType()) { + const Type *Ty = Context.getCanonicalType(T).getTypePtr(); + const ConstantMatrixType *MT = cast<ConstantMatrixType>(Ty); + return llvm::ArrayType::get(ConvertType(MT->getElementType()), + MT->getNumRows() * MT->getNumColumns()); + } + llvm::Type *R = ConvertType(T); - // If this is a non-bool type, don't map it. - if (!R->isIntegerTy(1)) - return R; + // If this is a bool type, or an ExtIntType in a bitfield representation, + // map this integer to the target-specified size. + if ((ForBitField && T->isExtIntType()) || R->isIntegerTy(1)) + return llvm::IntegerType::get(getLLVMContext(), + (unsigned)Context.getTypeSize(T)); - // Otherwise, return an integer of the target-specified size. - return llvm::IntegerType::get(getLLVMContext(), - (unsigned)Context.getTypeSize(T)); + // Else, don't map it. + return R; } - /// isRecordLayoutComplete - Return true if the specified type is already /// completely laid out. bool CodeGenTypes::isRecordLayoutComplete(const Type *Ty) const { @@ -295,6 +300,8 @@ static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext, else return llvm::Type::getInt16Ty(VMContext); } + if (&format == &llvm::APFloat::BFloat()) + return llvm::Type::getBFloatTy(VMContext); if (&format == &llvm::APFloat::IEEEsingle()) return llvm::Type::getFloatTy(VMContext); if (&format == &llvm::APFloat::IEEEdouble()) @@ -383,6 +390,20 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { const Type *Ty = T.getTypePtr(); + // For the device-side compilation, CUDA device builtin surface/texture types + // may be represented in different types. + if (Context.getLangOpts().CUDAIsDevice) { + if (T->isCUDADeviceBuiltinSurfaceType()) { + if (auto *Ty = CGM.getTargetCodeGenInfo() + .getCUDADeviceBuiltinSurfaceDeviceType()) + return Ty; + } else if (T->isCUDADeviceBuiltinTextureType()) { + if (auto *Ty = CGM.getTargetCodeGenInfo() + .getCUDADeviceBuiltinTextureDeviceType()) + return Ty; + } + } + // RecordTypes are cached and processed specially. if (const RecordType *RT = dyn_cast<RecordType>(Ty)) return ConvertRecordDeclType(RT->getDecl()); @@ -479,6 +500,7 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { Context.getLangOpts().NativeHalfType || !Context.getTargetInfo().useFP16ConversionIntrinsics()); break; + case BuiltinType::BFloat16: case BuiltinType::Float: case BuiltinType::Double: case BuiltinType::LongDouble: @@ -511,23 +533,99 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { case BuiltinType::OCLReserveID: ResultType = CGM.getOpenCLRuntime().convertOpenCLSpecificType(Ty); break; - - // TODO: real CodeGen support for SVE types requires more infrastructure - // to be added first. Report an error until then. -#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id: -#include "clang/Basic/AArch64SVEACLETypes.def" - { - unsigned DiagID = CGM.getDiags().getCustomDiagID( - DiagnosticsEngine::Error, - "cannot yet generate code for SVE type '%0'"); - auto *BT = cast<BuiltinType>(Ty); - auto Name = BT->getName(CGM.getContext().getPrintingPolicy()); - CGM.getDiags().Report(DiagID) << Name; - // Return something safe. - ResultType = llvm::IntegerType::get(getLLVMContext(), 32); - break; - } - +#define GET_SVE_INT_VEC(BITS, ELTS) \ + llvm::ScalableVectorType::get( \ + llvm::IntegerType::get(getLLVMContext(), BITS), ELTS); + case BuiltinType::SveInt8: + case BuiltinType::SveUint8: + return GET_SVE_INT_VEC(8, 16); + case BuiltinType::SveInt8x2: + case BuiltinType::SveUint8x2: + return GET_SVE_INT_VEC(8, 32); + case BuiltinType::SveInt8x3: + case BuiltinType::SveUint8x3: + return GET_SVE_INT_VEC(8, 48); + case BuiltinType::SveInt8x4: + case BuiltinType::SveUint8x4: + return GET_SVE_INT_VEC(8, 64); + case BuiltinType::SveInt16: + case BuiltinType::SveUint16: + return GET_SVE_INT_VEC(16, 8); + case BuiltinType::SveInt16x2: + case BuiltinType::SveUint16x2: + return GET_SVE_INT_VEC(16, 16); + case BuiltinType::SveInt16x3: + case BuiltinType::SveUint16x3: + return GET_SVE_INT_VEC(16, 24); + case BuiltinType::SveInt16x4: + case BuiltinType::SveUint16x4: + return GET_SVE_INT_VEC(16, 32); + case BuiltinType::SveInt32: + case BuiltinType::SveUint32: + return GET_SVE_INT_VEC(32, 4); + case BuiltinType::SveInt32x2: + case BuiltinType::SveUint32x2: + return GET_SVE_INT_VEC(32, 8); + case BuiltinType::SveInt32x3: + case BuiltinType::SveUint32x3: + return GET_SVE_INT_VEC(32, 12); + case BuiltinType::SveInt32x4: + case BuiltinType::SveUint32x4: + return GET_SVE_INT_VEC(32, 16); + case BuiltinType::SveInt64: + case BuiltinType::SveUint64: + return GET_SVE_INT_VEC(64, 2); + case BuiltinType::SveInt64x2: + case BuiltinType::SveUint64x2: + return GET_SVE_INT_VEC(64, 4); + case BuiltinType::SveInt64x3: + case BuiltinType::SveUint64x3: + return GET_SVE_INT_VEC(64, 6); + case BuiltinType::SveInt64x4: + case BuiltinType::SveUint64x4: + return GET_SVE_INT_VEC(64, 8); + case BuiltinType::SveBool: + return GET_SVE_INT_VEC(1, 16); +#undef GET_SVE_INT_VEC +#define GET_SVE_FP_VEC(TY, ISFP16, ELTS) \ + llvm::ScalableVectorType::get( \ + getTypeForFormat(getLLVMContext(), \ + Context.getFloatTypeSemantics(Context.TY), \ + /* UseNativeHalf = */ ISFP16), \ + ELTS); + case BuiltinType::SveFloat16: + return GET_SVE_FP_VEC(HalfTy, true, 8); + case BuiltinType::SveFloat16x2: + return GET_SVE_FP_VEC(HalfTy, true, 16); + case BuiltinType::SveFloat16x3: + return GET_SVE_FP_VEC(HalfTy, true, 24); + case BuiltinType::SveFloat16x4: + return GET_SVE_FP_VEC(HalfTy, true, 32); + case BuiltinType::SveFloat32: + return GET_SVE_FP_VEC(FloatTy, false, 4); + case BuiltinType::SveFloat32x2: + return GET_SVE_FP_VEC(FloatTy, false, 8); + case BuiltinType::SveFloat32x3: + return GET_SVE_FP_VEC(FloatTy, false, 12); + case BuiltinType::SveFloat32x4: + return GET_SVE_FP_VEC(FloatTy, false, 16); + case BuiltinType::SveFloat64: + return GET_SVE_FP_VEC(DoubleTy, false, 2); + case BuiltinType::SveFloat64x2: + return GET_SVE_FP_VEC(DoubleTy, false, 4); + case BuiltinType::SveFloat64x3: + return GET_SVE_FP_VEC(DoubleTy, false, 6); + case BuiltinType::SveFloat64x4: + return GET_SVE_FP_VEC(DoubleTy, false, 8); + case BuiltinType::SveBFloat16: + return GET_SVE_FP_VEC(BFloat16Ty, false, 8); + case BuiltinType::SveBFloat16x2: + return GET_SVE_FP_VEC(BFloat16Ty, false, 16); + case BuiltinType::SveBFloat16x3: + return GET_SVE_FP_VEC(BFloat16Ty, false, 24); + case BuiltinType::SveBFloat16x4: + return GET_SVE_FP_VEC(BFloat16Ty, false, 32); +#undef GET_SVE_FP_VEC case BuiltinType::Dependent: #define BUILTIN_TYPE(Id, SingletonId) #define PLACEHOLDER_TYPE(Id, SingletonId) \ @@ -560,7 +658,11 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { llvm::Type *PointeeType = ConvertTypeForMem(ETy); if (PointeeType->isVoidTy()) PointeeType = llvm::Type::getInt8Ty(getLLVMContext()); - unsigned AS = Context.getTargetAddressSpace(ETy); + + unsigned AS = PointeeType->isFunctionTy() + ? getDataLayout().getProgramAddressSpace() + : Context.getTargetAddressSpace(ETy); + ResultType = llvm::PointerType::get(PointeeType, AS); break; } @@ -605,8 +707,15 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { case Type::ExtVector: case Type::Vector: { const VectorType *VT = cast<VectorType>(Ty); - ResultType = llvm::VectorType::get(ConvertType(VT->getElementType()), - VT->getNumElements()); + ResultType = llvm::FixedVectorType::get(ConvertType(VT->getElementType()), + VT->getNumElements()); + break; + } + case Type::ConstantMatrix: { + const ConstantMatrixType *MT = cast<ConstantMatrixType>(Ty); + ResultType = + llvm::FixedVectorType::get(ConvertType(MT->getElementType()), + MT->getNumRows() * MT->getNumColumns()); break; } case Type::FunctionNoProto: @@ -692,6 +801,11 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { ResultType = CGM.getOpenCLRuntime().getPipeType(cast<PipeType>(Ty)); break; } + case Type::ExtInt: { + const auto &EIT = cast<ExtIntType>(Ty); + ResultType = llvm::Type::getIntNTy(getLLVMContext(), EIT->getNumBits()); + break; + } } assert(ResultType && "Didn't convert a type?"); @@ -749,8 +863,8 @@ llvm::StructType *CodeGenTypes::ConvertRecordDeclType(const RecordDecl *RD) { } // Layout fields. - CGRecordLayout *Layout = ComputeRecordLayout(RD, Ty); - CGRecordLayouts[Key] = Layout; + std::unique_ptr<CGRecordLayout> Layout = ComputeRecordLayout(RD, Ty); + CGRecordLayouts[Key] = std::move(Layout); // We're done laying out this struct. bool EraseResult = RecordsBeingLaidOut.erase(Key); (void)EraseResult; @@ -776,17 +890,18 @@ const CGRecordLayout & CodeGenTypes::getCGRecordLayout(const RecordDecl *RD) { const Type *Key = Context.getTagDeclType(RD).getTypePtr(); - const CGRecordLayout *Layout = CGRecordLayouts.lookup(Key); - if (!Layout) { - // Compute the type information. - ConvertRecordDeclType(RD); + auto I = CGRecordLayouts.find(Key); + if (I != CGRecordLayouts.end()) + return *I->second; + // Compute the type information. + ConvertRecordDeclType(RD); - // Now try again. - Layout = CGRecordLayouts.lookup(Key); - } + // Now try again. + I = CGRecordLayouts.find(Key); - assert(Layout && "Unable to find record layout information for type"); - return *Layout; + assert(I != CGRecordLayouts.end() && + "Unable to find record layout information for type"); + return *I->second; } bool CodeGenTypes::isPointerZeroInitializable(QualType T) { |