long double in AST

Hi all,

I was looking at the following function from clang/lib/AST/ASTContext.cpp:1649

/// getFloatTypeSemantics - Return the APFloat ‘semantics’ for the specified

/// scalar floating point type.

const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const {

switch (T->castAs()->getKind()) {

default:

llvm_unreachable(“Not a floating point type!”);

case BuiltinType::Float16:

case BuiltinType::Half:

return Target->getHalfFormat();

case BuiltinType::Float: return Target->getFloatFormat();

case BuiltinType::Double: return Target->getDoubleFormat();

case BuiltinType::LongDouble:

if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)

return AuxTarget->getLongDoubleFormat();

return Target->getLongDoubleFormat();

case BuiltinType::Float128:

if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)

return AuxTarget->getFloat128Format();

return Target->getFloat128Format();

}

}

For long double and float128, when we are on the device we get the “semantics” for those datatypes from AuxTarget instead of Target. Why is that?

Thanks!

George

Hi George,

Because the target might not support them but we need the size anyway.
The reasons is unavailable types in a structure which is mapped. While
we could bail, the user might have a hard time breaking the structure
apart. Instead, we allow it as long as you don't interact with the type
as such. You basically have an array of bytes on the device side, not
a thing with an unavailable type. Does this make sense?

You should also take a look at this conversation: https://reviews.llvm.org/D74387

I explained my preferred solution, and he shortcomings of the OpenMP implementation so far.

FWIW, I was hoping Intel would now implement this for SYCL and OpenMP in the same way :slight_smile:

WDYT?

Cheers,

 Johannes

> Hi all,
>
> I was looking at the following function from clang/lib/AST/ASTContext.cpp:1649
>
> /// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
> /// scalar floating point type.
> const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const {
>Â Â switch (T->castAs<BuiltinType>()->getKind()) {
>Â Â default:
>Â Â Â Â llvm_unreachable("Not a floating point type!");
>Â Â case BuiltinType::Float16:
>Â Â case BuiltinType::Half:
>Â Â Â Â return Target->getHalfFormat();
>Â Â case BuiltinType::Float:Â Â Â Â Â return Target->getFloatFormat();
>Â Â case BuiltinType::Double:Â Â Â Â return Target->getDoubleFormat();
>Â Â case BuiltinType::LongDouble:
>Â Â Â Â if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
>Â Â Â Â Â Â return AuxTarget->getLongDoubleFormat();
>Â Â Â Â return Target->getLongDoubleFormat();
>Â Â case BuiltinType::Float128:
>Â Â Â Â if (getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice)
>Â Â Â Â Â Â return AuxTarget->getFloat128Format();
>Â Â Â Â return Target->getFloat128Format();
>Â Â }
> }
>
> For long double and float128, when we are on the device we get the "semantics" for those datatypes from AuxTarget instead of Target. Why is that?