Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR] Add support for long double type #536

Merged
merged 2 commits into from
Apr 19, 2024
Merged

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Apr 6, 2024

This PR adds support for the long double type in C/C++. It includes a new CIR type !cir.long_double to represent the long double type. CIRGen and LLVMIR lowering support for the new type is also added.

Since the underlying floating point format used by a long double value is implementation-defined, the !cir.long_double type is parameterized to include information about the underlying floating point format. Specifically, a long double value may have one of the following formats:

  1. IEEE-754 binary64 format (i.e. the same format used by double);
  2. x87 80-bit floating point format;
  3. IEEE-754 binary128 format;
  4. PowerPC double double format.

This PR invents 3 more CIR types to represent the above floating-point formats, and !cir.long_double is parameterized by another CIR floating-point type which represents its underlying format:

  • !cir.long_double<!cir.double> represents the 1st variant above;
  • !cir.long_double<!cir.f80> represents the 2nd variant above;
  • !cir.long_double<!cir.f128> represents the 3rd variant above;
  • !cir.long_double<!cir.ppc_doubledouble> represents the 4th variant above.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, thanks! Comments inline.

@sitio-couto you might want to take a look in this PR, given our previous discussions on floating point support.

clang/lib/CIR/Dialect/IR/CIRTypes.cpp Outdated Show resolved Hide resolved
@Lancern Lancern force-pushed the long-double branch 2 times, most recently from 1ee6dfd to d6e918a Compare April 16, 2024 13:28
@Lancern
Copy link
Member Author

Lancern commented Apr 16, 2024

According to:

switch (Triple.getArch()) {
default:
assert(false && "Target not yet supported!");
case llvm::Triple::aarch64: {
AArch64ABIInfo::ABIKind Kind = AArch64ABIInfo::AAPCS;
assert(getTarget().getABI() == "aapcs" ||
getTarget().getABI() == "darwinpcs" &&
"Only Darwin supported for aarch64");
Kind = AArch64ABIInfo::DarwinPCS;
return SetCIRGenInfo(new AArch64TargetCIRGenInfo(genTypes, Kind));
}
case llvm::Triple::x86_64: {
StringRef ABI = getTarget().getABI();
X86AVXABILevel AVXLevel = (ABI == "avx512" ? X86AVXABILevel::AVX512
: ABI == "avx" ? X86AVXABILevel::AVX
: X86AVXABILevel::None);
switch (Triple.getOS()) {
default:
assert(false && "OSType NYI");
case llvm::Triple::Linux:
return SetCIRGenInfo(new X86_64TargetCIRGenInfo(genTypes, AVXLevel));
}
}

Seems like that CIR now only supports x86_64-*-linux-* or aarch64-*-darwin-* target triples. For the former targets, long double always use !cir.f80 as the underlying format. For the latter, long double always use double as the underlying format. Thus for now I cannot add tests for !cir.f128 or !cir.ppc_doubledouble. So in the latest commit I removed these two types from the PR and only keeps a single new type !cir.f80. !cir.f128 and !cir.ppc_doubledouble may be added in the future when we add support for more targets.

@Lancern
Copy link
Member Author

Lancern commented Apr 16, 2024

Rebased onto the latest main.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, LGTM. It would be nice to get some aliases if you have suggestions and would feel like adding them in a follow up PR.

@bcardosolopes
Copy link
Member

I tried to solve the merge conflict over the interface but maybe that wasn't enough. Once you fix this I'll land!

This patch adds support for the long double type in C/C++. It includes a new CIR
type `!cir.long_double` to represent the `long double` type. CIRGen and LLVMIR
lowering support for the new type is also added.

Since the underlying floating point format used by a `long double` value is
implementation-defined, the `!cir.long_double` type is parameterized to include
information about the underlying floating point format. Specifically, a
`long double` value may have one of the following formats:

  1) IEEE-754 binary64 format (i.e. the same format used by `double`);
  2) x87 80-bit floating point format;
  3) IEEE-754 binary128 format;
  4) PowerPC double double format.

This patch invents 1 more CIR type `!cir.f80` to represent the first two of the
above floating-point formats, and `!cir.long_double` is parameterized by another
CIR floating-point type which represents its underlying format:

  - `!cir.long_double<!cir.double>` represents the 1st variant above;
  - `!cir.long_double<!cir.f80>` represents the 2nd variant above.

The 3rd and 4th variants above are not yet supported since the targets that
generate such long double formats are not yet supported by CIR.
@Lancern
Copy link
Member Author

Lancern commented Apr 18, 2024

Rebased onto the latest main.

@bcardosolopes bcardosolopes merged commit 4a2955e into llvm:main Apr 19, 2024
6 checks passed
@Lancern Lancern deleted the long-double branch April 19, 2024 05:15
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds support for the `long double` type in C/C++. It includes a
new CIR type `!cir.long_double` to represent the `long double` type.
CIRGen and LLVMIR lowering support for the new type is also added.

Since the underlying floating point format used by a `long double` value
is implementation-defined, the `!cir.long_double` type is parameterized
to include information about the underlying floating point format.
Specifically, a `long double` value may have one of the following
formats:

  1) IEEE-754 binary64 format (i.e. the same format used by `double`);
  2) x87 80-bit floating point format;
  3) IEEE-754 binary128 format;
  4) PowerPC double double format.

This PR invents 3 more CIR types to represent the above floating-point
formats, and `!cir.long_double` is parameterized by another CIR
floating-point type which represents its underlying format:

  - `!cir.long_double<!cir.double>` represents the 1st variant above;
  - `!cir.long_double<!cir.f80>` represents the 2nd variant above;
  - `!cir.long_double<!cir.f128>` represents the 3rd variant above;
- `!cir.long_double<!cir.ppc_doubledouble>` represents the 4th variant
above.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds support for the `long double` type in C/C++. It includes a
new CIR type `!cir.long_double` to represent the `long double` type.
CIRGen and LLVMIR lowering support for the new type is also added.

Since the underlying floating point format used by a `long double` value
is implementation-defined, the `!cir.long_double` type is parameterized
to include information about the underlying floating point format.
Specifically, a `long double` value may have one of the following
formats:

  1) IEEE-754 binary64 format (i.e. the same format used by `double`);
  2) x87 80-bit floating point format;
  3) IEEE-754 binary128 format;
  4) PowerPC double double format.

This PR invents 3 more CIR types to represent the above floating-point
formats, and `!cir.long_double` is parameterized by another CIR
floating-point type which represents its underlying format:

  - `!cir.long_double<!cir.double>` represents the 1st variant above;
  - `!cir.long_double<!cir.f80>` represents the 2nd variant above;
  - `!cir.long_double<!cir.f128>` represents the 3rd variant above;
- `!cir.long_double<!cir.ppc_doubledouble>` represents the 4th variant
above.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR adds support for the `long double` type in C/C++. It includes a
new CIR type `!cir.long_double` to represent the `long double` type.
CIRGen and LLVMIR lowering support for the new type is also added.

Since the underlying floating point format used by a `long double` value
is implementation-defined, the `!cir.long_double` type is parameterized
to include information about the underlying floating point format.
Specifically, a `long double` value may have one of the following
formats:

  1) IEEE-754 binary64 format (i.e. the same format used by `double`);
  2) x87 80-bit floating point format;
  3) IEEE-754 binary128 format;
  4) PowerPC double double format.

This PR invents 3 more CIR types to represent the above floating-point
formats, and `!cir.long_double` is parameterized by another CIR
floating-point type which represents its underlying format:

  - `!cir.long_double<!cir.double>` represents the 1st variant above;
  - `!cir.long_double<!cir.f80>` represents the 2nd variant above;
  - `!cir.long_double<!cir.f128>` represents the 3rd variant above;
- `!cir.long_double<!cir.ppc_doubledouble>` represents the 4th variant
above.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
This PR adds support for the `long double` type in C/C++. It includes a
new CIR type `!cir.long_double` to represent the `long double` type.
CIRGen and LLVMIR lowering support for the new type is also added.

Since the underlying floating point format used by a `long double` value
is implementation-defined, the `!cir.long_double` type is parameterized
to include information about the underlying floating point format.
Specifically, a `long double` value may have one of the following
formats:

  1) IEEE-754 binary64 format (i.e. the same format used by `double`);
  2) x87 80-bit floating point format;
  3) IEEE-754 binary128 format;
  4) PowerPC double double format.

This PR invents 3 more CIR types to represent the above floating-point
formats, and `!cir.long_double` is parameterized by another CIR
floating-point type which represents its underlying format:

  - `!cir.long_double<!cir.double>` represents the 1st variant above;
  - `!cir.long_double<!cir.f80>` represents the 2nd variant above;
  - `!cir.long_double<!cir.f128>` represents the 3rd variant above;
- `!cir.long_double<!cir.ppc_doubledouble>` represents the 4th variant
above.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This PR adds support for the `long double` type in C/C++. It includes a
new CIR type `!cir.long_double` to represent the `long double` type.
CIRGen and LLVMIR lowering support for the new type is also added.

Since the underlying floating point format used by a `long double` value
is implementation-defined, the `!cir.long_double` type is parameterized
to include information about the underlying floating point format.
Specifically, a `long double` value may have one of the following
formats:

  1) IEEE-754 binary64 format (i.e. the same format used by `double`);
  2) x87 80-bit floating point format;
  3) IEEE-754 binary128 format;
  4) PowerPC double double format.

This PR invents 3 more CIR types to represent the above floating-point
formats, and `!cir.long_double` is parameterized by another CIR
floating-point type which represents its underlying format:

  - `!cir.long_double<!cir.double>` represents the 1st variant above;
  - `!cir.long_double<!cir.f80>` represents the 2nd variant above;
  - `!cir.long_double<!cir.f128>` represents the 3rd variant above;
- `!cir.long_double<!cir.ppc_doubledouble>` represents the 4th variant
above.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
This PR adds support for the `long double` type in C/C++. It includes a
new CIR type `!cir.long_double` to represent the `long double` type.
CIRGen and LLVMIR lowering support for the new type is also added.

Since the underlying floating point format used by a `long double` value
is implementation-defined, the `!cir.long_double` type is parameterized
to include information about the underlying floating point format.
Specifically, a `long double` value may have one of the following
formats:

  1) IEEE-754 binary64 format (i.e. the same format used by `double`);
  2) x87 80-bit floating point format;
  3) IEEE-754 binary128 format;
  4) PowerPC double double format.

This PR invents 3 more CIR types to represent the above floating-point
formats, and `!cir.long_double` is parameterized by another CIR
floating-point type which represents its underlying format:

  - `!cir.long_double<!cir.double>` represents the 1st variant above;
  - `!cir.long_double<!cir.f80>` represents the 2nd variant above;
  - `!cir.long_double<!cir.f128>` represents the 3rd variant above;
- `!cir.long_double<!cir.ppc_doubledouble>` represents the 4th variant
above.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
lanza pushed a commit that referenced this pull request Nov 5, 2024
This PR adds support for the `long double` type in C/C++. It includes a
new CIR type `!cir.long_double` to represent the `long double` type.
CIRGen and LLVMIR lowering support for the new type is also added.

Since the underlying floating point format used by a `long double` value
is implementation-defined, the `!cir.long_double` type is parameterized
to include information about the underlying floating point format.
Specifically, a `long double` value may have one of the following
formats:

  1) IEEE-754 binary64 format (i.e. the same format used by `double`);
  2) x87 80-bit floating point format;
  3) IEEE-754 binary128 format;
  4) PowerPC double double format.

This PR invents 3 more CIR types to represent the above floating-point
formats, and `!cir.long_double` is parameterized by another CIR
floating-point type which represents its underlying format:

  - `!cir.long_double<!cir.double>` represents the 1st variant above;
  - `!cir.long_double<!cir.f80>` represents the 2nd variant above;
  - `!cir.long_double<!cir.f128>` represents the 3rd variant above;
- `!cir.long_double<!cir.ppc_doubledouble>` represents the 4th variant
above.

Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants