-
Notifications
You must be signed in to change notification settings - Fork 1
[llvm][DFP] Add support for DFP encoding in llvm::DataLayout. #40
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
base: dfp
Are you sure you want to change the base?
Changes from 4 commits
7b404ff
60a6a1c
e4f4016
ee642f5
69e623b
e92106f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -719,13 +719,33 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { | |
| Int64Type = IsX32 ? SignedLongLong : SignedLong; | ||
| RegParmMax = 6; | ||
|
|
||
| bool isBIDEncoding = Opts.DFPEncoding == TargetOptions::BinaryEncoding::BID; | ||
| bool isDPDEncoding = Opts.DFPEncoding == TargetOptions::BinaryEncoding::DPD; | ||
|
||
|
|
||
| // Pointers are 32-bit in x32. | ||
| resetDataLayout(IsX32 ? "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-" | ||
| "i64:64-f80:128-n8:16:32:64-S128" | ||
| : IsWinCOFF ? "e-m:w-p270:32:32-p271:32:32-p272:64:" | ||
| "64-i64:64-f80:128-n8:16:32:64-S128" | ||
| : "e-m:e-p270:32:32-p271:32:32-p272:64:" | ||
| "64-i64:64-f80:128-n8:16:32:64-S128"); | ||
| if (isBIDEncoding) | ||
| resetDataLayout( | ||
| IsX32 ? "e-d:-bid-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-" | ||
| "i64:64-f80:128-n8:16:32:64-S128" | ||
| : IsWinCOFF ? "e-d:bid-m:w-p270:32:32-p271:32:32-p272:64:" | ||
| "64-i64:64-f80:128-n8:16:32:64-S128" | ||
| : "e-d:bid-m:e-p270:32:32-p271:32:32-p272:64:" | ||
| "64-i64:64-f80:128-n8:16:32:64-S128"); | ||
| else if (isDPDEncoding) | ||
| resetDataLayout( | ||
| IsX32 ? "e-d:dpd-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-" | ||
| "i64:64-f80:128-n8:16:32:64-S128" | ||
| : IsWinCOFF ? "e-d:dpd-m:w-p270:32:32-p271:32:32-p272:64:" | ||
| "64-i64:64-f80:128-n8:16:32:64-S128" | ||
| : "e-d:dpd-m:e-p270:32:32-p271:32:32-p272:64:" | ||
| "64-i64:64-f80:128-n8:16:32:64-S128"); | ||
| else | ||
| resetDataLayout(IsX32 ? "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-" | ||
| "i64:64-f80:128-n8:16:32:64-S128" | ||
| : IsWinCOFF ? "e-m:w-p270:32:32-p271:32:32-p272:64:" | ||
| "64-i64:64-f80:128-n8:16:32:64-S128" | ||
| : "e-m:e-p270:32:32-p271:32:32-p272:64:" | ||
| "64-i64:64-f80:128-n8:16:32:64-S128"); | ||
|
||
|
|
||
| // Use fpret only for long double. | ||
| RealTypeUsesObjCFPRetMask = (unsigned)FloatModeKind::LongDouble; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -370,6 +370,13 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, | |
| break; | ||
| } | ||
|
|
||
| if (TargetOpts.DFPEncoding == clang::TargetOptions::BinaryEncoding::BID) | ||
| Options.DFPEncoding = llvm::BinaryEncoding::BID; | ||
| else if (TargetOpts.DFPEncoding == clang::TargetOptions::BinaryEncoding::DPD) | ||
| Options.DFPEncoding = llvm::BinaryEncoding::DPD; | ||
| else | ||
| Options.DFPEncoding = llvm::BinaryEncoding::None; | ||
|
|
||
|
||
| Options.BinutilsVersion = | ||
| llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.BinutilsVersion); | ||
| Options.UseInitArray = CodeGenOpts.UseInitArray; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,15 @@ void CompilerInstance::setTarget(TargetInfo *Value) { Target = Value; } | |
| void CompilerInstance::setAuxTarget(TargetInfo *Value) { AuxTarget = Value; } | ||
|
|
||
| bool CompilerInstance::createTarget() { | ||
| if (getLangOpts().DecimalFloatingPoint) { | ||
| if (getInvocation().getTargetOpts().CPU == "x86" || | ||
| getInvocation().getTargetOpts().CPU == "x86-64") | ||
| getInvocation().getTargetOpts().DFPEncoding = | ||
| TargetOptions::BinaryEncoding::BID; | ||
| else | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know that this logic is correct for most targets. libdfp only mentions x86(-64), PPC and s390 in its documentation (see https://github.com/libdfp/libdfp), but helpfully, the most recent commit suggests that aarch64 is going to go with BID. The AArch64 suggests that it's using BID: https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#decimal-floating-point (there's nothing corresponding I could find for 32-bit arm). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't right. I suspect Zahira derived this from similar code I added to the I think our plan for prior to upstreaming should be to focus on just Intel support (perhaps IBM too given Ariel's involvement) and then let maintainers for other architectures enable support for other targets following appropriate testing after our changes are accepted upstream. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again the change you are suggesting implies that the encoding info is in TargetInfo but I don't think we can do that there. See comments above. |
||
| getInvocation().getTargetOpts().DFPEncoding = | ||
| TargetOptions::BinaryEncoding::DPD; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be addressed by the code changes I've been taking forever to finish. There is already code that does similarly to populate |
||
| // Create the target instance. | ||
| setTarget(TargetInfo::CreateTargetInfo(getDiagnostics(), | ||
| getInvocation().TargetOpts)); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // RUN: %clang_cc1 -emit-llvm -triple x86_64 -target-cpu x86-64 -emit-llvm -o - %s | FileCheck %s | ||
|
|
||
| // RUN: %clang_cc1 -emit-llvm -triple x86_64 -target-cpu x86-64 -emit-llvm -fexperimental-decimal-floating-point -o - %s | FileCheck %s --check-prefixes=DFP | ||
|
|
||
| // CHECK: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
| // DFP: target datalayout = "e-d:bid-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
| void foo() { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -117,10 +117,18 @@ static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) { | |
| return std::make_unique<X86ELFTargetObjectFile>(); | ||
| } | ||
|
|
||
| static std::string computeDataLayout(const Triple &TT) { | ||
| static std::string computeDataLayout(const Triple &TT, | ||
| const TargetOptions &Options) { | ||
| // X86 is little endian | ||
| std::string Ret = "e"; | ||
|
|
||
| // Decimal floating-point encoding. | ||
| if (Options.DFPEncoding != BinaryEncoding::None) { | ||
| assert(Options.DFPEncoding == BinaryEncoding::BID && | ||
| "Decimal floating-point on x86 is BID!"); | ||
| Ret += "-d:bid"; | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are multiple places where these strings have to be built for each target? That seems very unfortunate. |
||
| Ret += DataLayout::getManglingComponent(TT); | ||
| // X86 and x32 have 32 bit pointers. | ||
| if (!TT.isArch64Bit() || TT.isX32() || TT.isOSNaCl()) | ||
|
|
@@ -226,7 +234,7 @@ X86TargetMachine::X86TargetMachine(const Target &T, const Triple &TT, | |
| std::optional<CodeModel::Model> CM, | ||
| CodeGenOptLevel OL, bool JIT) | ||
| : LLVMTargetMachine( | ||
| T, computeDataLayout(TT), TT, CPU, FS, Options, | ||
| T, computeDataLayout(TT, Options), TT, CPU, FS, Options, | ||
| getEffectiveRelocModel(TT, JIT, RM), | ||
| getEffectiveX86CodeModel(CM, JIT, TT.getArch() == Triple::x86_64), | ||
| OL), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have something similar in the
TargetInfo.hheader as shown below. I still haven't been able to get a good understanding for whenTargetInfois used vsTargetOptions. Can you look to see if it makes sense to use the data already present inTargetInfo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned this in the chat earlier today, but it should probably go in include/llvm/ADT/FloatingPointMode.h, which contains the other FP env modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, yes, that looks exactly right.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the enum to FloatingPointMode.h. Tried to rest into TargetInfo but that doesn't seem to work. It needs to be in clang::TargetOptions. The reason being that in initTargetOptions we are passing the info from clang::TargetOptions to llvm::TargetOptions and there is no access to TargetInfo here. So the info about the encoding needs to reside in targetOptions. Will keep looking at it.