Skip to content

Commit

Permalink
Merged master:bcf754a3212 into amd-gfx:2e774eed464
Browse files Browse the repository at this point in the history
Local branch amd-gfx 2e774ee Merged master:de61aa3118b into amd-gfx:1747a4ec9e6
Remote branch master bcf754a [OPENMP][DOCS] Update OpenMP status (NFC)
  • Loading branch information
Sw authored and Sw committed Nov 7, 2019
2 parents 2e774ee + bcf754a commit fea644e
Show file tree
Hide file tree
Showing 19 changed files with 573 additions and 42 deletions.
6 changes: 4 additions & 2 deletions clang/docs/OpenMPSupport.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ implementation.
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device extension | OMP_TARGET_OFFLOAD environment variable | :good:`done` | D50522 |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device extension | support full 'defaultmap' functionality | :part:`worked on` | |
| device extension | support full 'defaultmap' functionality | :part:`worked on` | D69204 |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device extension | device specific functions | :none:`unclaimed` | |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device extension | clause: device_type | :good:`done` | |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device extension | clause: in_reduction | :none:`unclaimed` | r308768 |
| device extension | clause: in_reduction | :part:`worked on` | r308768 |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device extension | omp_get_device_num() | :part:`worked on` | D54342 |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
Expand Down Expand Up @@ -211,6 +211,8 @@ implementation.
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device extension | teams construct on the host device | :part:`worked on` | Clang part is done, r371553. |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| device extension | support non-contiguous array sections for target update | :part:`worked on` | |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| atomic extension | hints for the atomic construct | :part:`worked on` | D51233 |
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
| base language | C11 support | :none:`unclaimed` | |
Expand Down
54 changes: 50 additions & 4 deletions clang/docs/UsersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,10 @@ are listed below.

**-f[no-]trapping-math**

``-fno-trapping-math`` allows optimizations that assume that
floating point operations cannot generate traps such as divide-by-zero,
overflow and underflow. Defaults to ``-ftrapping-math``.
Currently this option has no effect.
Control floating point exception behavior. ``-fno-trapping-math`` allows optimizations that assume that floating point operations cannot generate traps such as divide-by-zero, overflow and underflow.

- The option ``-ftrapping-math`` behaves identically to ``-ffp-exception-behavior=strict``.
- The option ``-fno-trapping-math`` behaves identically to ``-ffp-exception-behavior=ignore``. This is the default.

.. option:: -ffp-contract=<value>

Expand Down Expand Up @@ -1319,6 +1319,52 @@ are listed below.

Defaults to ``-fno-finite-math``.

.. _opt_frounding-math:

**-f[no-]rounding-math**

Force floating-point operations to honor the dynamically-set rounding mode by default.

The result of a floating-point operation often cannot be exactly represented in the result type and therefore must be rounded. IEEE 754 describes different rounding modes that control how to perform this rounding, not all of which are supported by all implementations. C provides interfaces (``fesetround`` and ``fesetenv``) for dynamically controlling the rounding mode, and while it also recommends certain conventions for changing the rounding mode, these conventions are not typically enforced in the ABI. Since the rounding mode changes the numerical result of operations, the compiler must understand something about it in order to optimize floating point operations.

Note that floating-point operations performed as part of constant initialization are formally performed prior to the start of the program and are therefore not subject to the current rounding mode. This includes the initialization of global variables and local ``static`` variables. Floating-point operations in these contexts will be rounded using ``FE_TONEAREST``.

- The option ``-fno-rounding-math`` allows the compiler to assume that the rounding mode is set to ``FE_TONEAREST``. This is the default.
- The option ``-frounding-math`` forces the compiler to honor the dynamically-set rounding mode. This prevents optimizations which might affect results if the rounding mode changes or is different from the default; for example, it prevents floating-point operations from being reordered across most calls and prevents constant-folding when the result is not exactly representable.

.. option:: -ffp-model=<value>

Specify floating point behavior. ``-ffp-model`` is an umbrella
option that encompasses functionality provided by other, single
purpose, floating point options. Valid values are: ``precise``, ``strict``,
and ``fast``.
Details:

* ``precise`` Disables optimizations that are not value-safe on floating-point data, although FP contraction (FMA) is enabled (``-ffp-contract=fast``). This is the default behavior.
* ``strict`` Enables ``-frounding-math`` and ``-ffp-exception-behavior=strict``, and disables contractions (FMA). All of the ``-ffast-math`` enablements are disabled.
* ``fast`` Behaves identically to specifying both ``-ffast-math`` and ``ffp-contract=fast``

Note: If your command line specifies multiple instances
of the ``-ffp-model`` option, or if your command line option specifies
``-ffp-model`` and later on the command line selects a floating point
option that has the effect of negating part of the ``ffp-model`` that
has been selected, then the compiler will issue a diagnostic warning
that the override has occurred.

.. option:: -ffp-exception-behavior=<value>

Specify the floating-point exception behavior.

Valid values are: ``ignore``, ``maytrap``, and ``strict``.
The default value is ``ignore``. Details:

* ``ignore`` The compiler assumes that the exception status flags will not be read and that floating point exceptions will be masked.
* ``maytrap`` The compiler avoids transformations that may raise exceptions that would not have been raised by the original code. Constant folding performed by the compiler is exempt from this option.
* ``strict`` The compiler ensures that all transformations strictly preserve the floating point exception semantics of the original code.




.. _controlling-code-generation:

Controlling Code Generation
Expand Down
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/LangOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ LANGOPT(SinglePrecisionConstants , 1, 0, "treating double-precision floating poi
LANGOPT(FastRelaxedMath , 1, 0, "OpenCL fast relaxed math")
/// FP_CONTRACT mode (on/off/fast).
ENUM_LANGOPT(DefaultFPContractMode, FPContractModeKind, 2, FPC_Off, "FP contraction type")
ENUM_LANGOPT(FPRoundingMode, FPRoundingModeKind, 3, FPR_ToNearest, "FP Rounding Mode type")
ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Ignore, "FP Exception Behavior Mode type")
LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment")
LANGOPT(HexagonQdsp6Compat , 1, 0, "hexagon-qdsp6 backward compatibility")
LANGOPT(ObjCAutoRefCount , 1, 0, "Objective-C automated reference counting")
Expand Down
28 changes: 28 additions & 0 deletions clang/include/clang/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,34 @@ class LangOptions : public LangOptionsBase {
FEA_On
};

// Values of the following enumerations correspond to metadata arguments
// specified for constrained floating-point intrinsics:
// http://llvm.org/docs/LangRef.html#constrained-floating-point-intrinsics.

/// Possible rounding modes.
enum FPRoundingModeKind {
/// Rounding to nearest, corresponds to "round.tonearest".
FPR_ToNearest,
/// Rounding toward -Inf, corresponds to "round.downward".
FPR_Downward,
/// Rounding toward +Inf, corresponds to "round.upward".
FPR_Upward,
/// Rounding toward zero, corresponds to "round.towardzero".
FPR_TowardZero,
/// Is determined by runtime environment, corresponds to "round.dynamic".
FPR_Dynamic
};

/// Possible floating point exception behavior.
enum FPExceptionModeKind {
/// Assume that floating-point exceptions are masked.
FPE_Ignore,
/// Transformations do not cause new exceptions but may hide some.
FPE_MayTrap,
/// Strictly preserve the floating-point exception semantics.
FPE_Strict
};

enum class LaxVectorConversionKind {
/// Permit no implicit vector bitcasts.
None,
Expand Down
7 changes: 6 additions & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,10 @@ def : Flag<["-"], "fextended-identifiers">, Group<clang_ignored_f_Group>;
def : Flag<["-"], "fno-extended-identifiers">, Group<f_Group>, Flags<[Unsupported]>;
def fhosted : Flag<["-"], "fhosted">, Group<f_Group>;
def fdenormal_fp_math_EQ : Joined<["-"], "fdenormal-fp-math=">, Group<f_Group>, Flags<[CC1Option]>;
def ffp_model_EQ : Joined<["-"], "ffp-model=">, Group<f_Group>, Flags<[DriverOption]>,
HelpText<"Controls the semantics of floating-point calculations.">;
def ffp_exception_behavior_EQ : Joined<["-"], "ffp-exception-behavior=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Specifies the exception behavior of floating-point operations.">;
def ffast_math : Flag<["-"], "ffast-math">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Allow aggressive, lossy floating-point optimizations">;
def fno_fast_math : Flag<["-"], "fno-fast-math">, Group<f_Group>;
Expand Down Expand Up @@ -1150,6 +1154,8 @@ def fno_honor_infinities : Flag<["-"], "fno-honor-infinities">, Group<f_Group>;
// This option was originally misspelt "infinites" [sic].
def : Flag<["-"], "fhonor-infinites">, Alias<fhonor_infinities>;
def : Flag<["-"], "fno-honor-infinites">, Alias<fno_honor_infinities>;
def frounding_math : Flag<["-"], "frounding-math">, Group<f_Group>, Flags<[CC1Option]>;
def fno_rounding_math : Flag<["-"], "fno-rounding-math">, Group<f_Group>, Flags<[CC1Option]>;
def ftrapping_math : Flag<["-"], "ftrapping-math">, Group<f_Group>, Flags<[CC1Option]>;
def fno_trapping_math : Flag<["-"], "fno-trapping-math">, Group<f_Group>, Flags<[CC1Option]>;
def ffp_contract : Joined<["-"], "ffp-contract=">, Group<f_Group>,
Expand Down Expand Up @@ -3228,7 +3234,6 @@ defm profile_values : BooleanFFlag<"profile-values">, Group<clang_ignored_gcc_op
defm regs_graph : BooleanFFlag<"regs-graph">, Group<clang_ignored_f_Group>;
defm rename_registers : BooleanFFlag<"rename-registers">, Group<clang_ignored_gcc_optimization_f_Group>;
defm ripa : BooleanFFlag<"ripa">, Group<clang_ignored_f_Group>;
defm rounding_math : BooleanFFlag<"rounding-math">, Group<clang_ignored_gcc_optimization_f_Group>;
defm schedule_insns : BooleanFFlag<"schedule-insns">, Group<clang_ignored_gcc_optimization_f_Group>;
defm schedule_insns2 : BooleanFFlag<"schedule-insns2">, Group<clang_ignored_gcc_optimization_f_Group>;
defm see : BooleanFFlag<"see">, Group<clang_ignored_f_Group>;
Expand Down
55 changes: 55 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "clang/Frontend/FrontendDiagnostic.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Operator.h"
Expand Down Expand Up @@ -87,6 +88,7 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext)
FMF.setAllowReassoc();
}
Builder.setFastMathFlags(FMF);
SetFPModel();
}

CodeGenFunction::~CodeGenFunction() {
Expand All @@ -102,6 +104,59 @@ CodeGenFunction::~CodeGenFunction() {
CGM.getOpenMPRuntime().functionFinished(*this);
}

// Map the LangOption for rounding mode into
// the corresponding enum in the IR.
static llvm::ConstrainedFPIntrinsic::RoundingMode ToConstrainedRoundingMD(
LangOptions::FPRoundingModeKind Kind) {

switch (Kind) {
case LangOptions::FPR_ToNearest:
return llvm::ConstrainedFPIntrinsic::rmToNearest;
case LangOptions::FPR_Downward:
return llvm::ConstrainedFPIntrinsic::rmDownward;
case LangOptions::FPR_Upward:
return llvm::ConstrainedFPIntrinsic::rmUpward;
case LangOptions::FPR_TowardZero:
return llvm::ConstrainedFPIntrinsic::rmTowardZero;
case LangOptions::FPR_Dynamic:
return llvm::ConstrainedFPIntrinsic::rmDynamic;
}
llvm_unreachable("Unsupported FP RoundingMode");
}

// Map the LangOption for exception behavior into
// the corresponding enum in the IR.
static llvm::ConstrainedFPIntrinsic::ExceptionBehavior ToConstrainedExceptMD(
LangOptions::FPExceptionModeKind Kind) {

switch (Kind) {
case LangOptions::FPE_Ignore:
return llvm::ConstrainedFPIntrinsic::ebIgnore;
case LangOptions::FPE_MayTrap:
return llvm::ConstrainedFPIntrinsic::ebMayTrap;
case LangOptions::FPE_Strict:
return llvm::ConstrainedFPIntrinsic::ebStrict;
}
llvm_unreachable("Unsupported FP Exception Behavior");
}

void CodeGenFunction::SetFPModel() {
auto fpRoundingMode = ToConstrainedRoundingMD(
getLangOpts().getFPRoundingMode());
auto fpExceptionBehavior = ToConstrainedExceptMD(
getLangOpts().getFPExceptionMode());

if (fpExceptionBehavior == llvm::ConstrainedFPIntrinsic::ebIgnore &&
fpRoundingMode == llvm::ConstrainedFPIntrinsic::rmToNearest)
// Constrained intrinsics are not used.
;
else {
Builder.setIsFPConstrained(true);
Builder.setDefaultConstrainedRounding(fpRoundingMode);
Builder.setDefaultConstrainedExcept(fpExceptionBehavior);
}
}

CharUnits CodeGenFunction::getNaturalPointeeTypeAlignment(QualType T,
LValueBaseInfo *BaseInfo,
TBAAAccessInfo *TBAAInfo) {
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4156,6 +4156,9 @@ class CodeGenFunction : public CodeGenTypeCache {
/// point operation, expressed as the maximum relative error in ulp.
void SetFPAccuracy(llvm::Value *Val, float Accuracy);

/// SetFPModel - Control floating point behavior via fp-model settings.
void SetFPModel();

private:
llvm::MDNode *getRangeForLoadFromType(QualType Ty);
void EmitReturnOfRValue(RValue RV, QualType Ty);
Expand Down
Loading

0 comments on commit fea644e

Please sign in to comment.