From 19dbb20ac4371fae3190379a7e7bd467af3c00aa Mon Sep 17 00:00:00 2001 From: Joey Gouly Date: Wed, 23 Jan 2013 11:56:20 +0000 Subject: Add a new LangOpt NativeHalfType. This option allows for native half/fp16 operations (as opposed to storage only half/fp16). Also add some semantic checks for OpenCL half types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173254 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenTypes.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'lib/CodeGen/CodeGenTypes.cpp') diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index c186ebff29..e78cbabda8 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -263,9 +263,14 @@ void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) { } static llvm::Type *getTypeForFormat(llvm::LLVMContext &VMContext, - const llvm::fltSemantics &format) { - if (&format == &llvm::APFloat::IEEEhalf) - return llvm::Type::getInt16Ty(VMContext); + const llvm::fltSemantics &format, + bool UseNativeHalf = false) { + if (&format == &llvm::APFloat::IEEEhalf) { + if (UseNativeHalf) + return llvm::Type::getHalfTy(VMContext); + else + return llvm::Type::getInt16Ty(VMContext); + } if (&format == &llvm::APFloat::IEEEsingle) return llvm::Type::getFloatTy(VMContext); if (&format == &llvm::APFloat::IEEEdouble) @@ -344,18 +349,17 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { break; case BuiltinType::Half: - // Half is special: it might be lowered to i16 (and will be storage-only - // type),. or can be represented as a set of native operations. - - // FIXME: Ask target which kind of half FP it prefers (storage only vs - // native). - ResultType = llvm::Type::getInt16Ty(getLLVMContext()); + // Half FP can either be storage-only (lowered to i16) or native. + ResultType = getTypeForFormat(getLLVMContext(), + Context.getFloatTypeSemantics(T), + Context.getLangOpts().NativeHalfType); break; case BuiltinType::Float: case BuiltinType::Double: case BuiltinType::LongDouble: ResultType = getTypeForFormat(getLLVMContext(), - Context.getFloatTypeSemantics(T)); + Context.getFloatTypeSemantics(T), + /* UseNativeHalf = */ false); break; case BuiltinType::NullPtr: -- cgit v1.2.3