-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[flang] Add -fcomplex-arithmetic= option and select complex division algorithm #146641
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: main
Are you sure you want to change the base?
Changes from all commits
baf87a6
60e0cd9
bddb2d3
65c522c
528e1de
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 |
---|---|---|
|
@@ -192,6 +192,31 @@ class CodeGenOptions : public CodeGenOptionsBase { | |
return getProfileUse() == llvm::driver::ProfileCSIRInstr; | ||
} | ||
|
||
/// Controls the various implementations for complex division. | ||
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. If this is exactly the same as the enum in 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. Thank you for providing the example! I understand that your example is about moving Clang's |
||
enum ComplexRangeKind { | ||
/// Implementation of complex division using a call to runtime library | ||
/// functions. Overflow and non-finite values are handled by the library | ||
/// implementation. This is the default value. | ||
CX_Full, | ||
|
||
/// Implementation of complex division offering an improved handling | ||
/// for overflow in intermediate calculations. Overflow and non-finite | ||
/// values are handled by MLIR's implementation of "complex.div", but this | ||
/// may change in the future. | ||
CX_Improved, | ||
|
||
/// Implementation of complex division using algebraic formulas at source | ||
/// precision. No special handling to avoid overflow. NaN and infinite | ||
/// values are not handled. | ||
CX_Basic, | ||
|
||
/// No range rule is enabled. | ||
CX_None | ||
|
||
/// TODO: Implemention of other values as needed. In Clang, "CX_Promoted" | ||
/// is implemented. (See clang/Basic/LangOptions.h) | ||
}; | ||
|
||
// Define accessors/mutators for code generation options of enumeration type. | ||
#define CODEGENOPT(Name, Bits, Default) | ||
#define ENUM_CODEGENOPT(Name, Type, Bits, Default) \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
#ifndef FORTRAN_OPTIMIZER_CODEGEN_CODEGEN_H | ||
#define FORTRAN_OPTIMIZER_CODEGEN_CODEGEN_H | ||
|
||
#include "flang/Frontend/CodeGenOptions.h" | ||
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. Not requesting to do that here, but I feel the CodeGenOptions should be defined in Codegen and used/set in Frontend rather than having Codegen depends on Frontend things I think. 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 think the 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. Thank you for the reviews!
Does this mean that
Yes, I'm including |
||
#include "mlir/IR/BuiltinOps.h" | ||
#include "mlir/Pass/Pass.h" | ||
#include "mlir/Pass/PassRegistry.h" | ||
|
@@ -58,6 +59,11 @@ struct FIRToLLVMPassOptions { | |
// the name of the global variable corresponding to a derived | ||
// type's descriptor. | ||
bool typeDescriptorsRenamedForAssembly = false; | ||
|
||
// Specify the calculation method for complex number division used by the | ||
// Conversion pass of the MLIR complex dialect. | ||
Fortran::frontend::CodeGenOptions::ComplexRangeKind ComplexRange = | ||
Fortran::frontend::CodeGenOptions::ComplexRangeKind::CX_Full; | ||
}; | ||
|
||
/// Convert FIR to the LLVM IR dialect with default options. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
! Test range options for complex multiplication and division. | ||
|
||
! RUN: %flang -### -c %s 2>&1 \ | ||
! RUN: | FileCheck %s --check-prefix=RANGE | ||
|
||
! RUN: %flang -### -fcomplex-arithmetic=full -c %s 2>&1 \ | ||
! RUN: | FileCheck %s --check-prefix=FULL | ||
|
||
! RUN: %flang -### -fcomplex-arithmetic=improved -c %s 2>&1 \ | ||
! RUN: | FileCheck %s --check-prefix=IMPRVD | ||
|
||
! RUN: %flang -### -fcomplex-arithmetic=basic -c %s 2>&1 \ | ||
! RUN: | FileCheck %s --check-prefix=BASIC | ||
|
||
! RUN: not %flang -### -fcomplex-arithmetic=foo -c %s 2>&1 \ | ||
! RUN: | FileCheck %s --check-prefix=ERR | ||
|
||
! RANGE-NOT: -complex-range= | ||
! FULL: -complex-range=full | ||
! IMPRVD: -complex-range=improved | ||
! BASIC: -complex-range=basic | ||
|
||
! ERR: error: unsupported argument 'foo' to option '-fcomplex-arithmetic=' |
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 think this can be moved to
CommonArgs.cpp
as well.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.
Although Clang implements
CX_Promoted
, the corresponding conversion is not implemented in Flang. Therefore I want the driver to emit an error. Since this behavior differs slightly from Clang, moving this toCommonArgs.cpp
might be difficult.