summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/Expr.h6
-rw-r--r--include/clang/AST/ExprCXX.h4
-rw-r--r--include/clang/Basic/LangOptions.def3
-rw-r--r--include/clang/Basic/LangOptions.h31
-rw-r--r--include/clang/Frontend/CodeGenOptions.def2
-rw-r--r--include/clang/Frontend/CodeGenOptions.h6
-rw-r--r--lib/CodeGen/BackendUtil.cpp8
-rw-r--r--lib/CodeGen/CGExprScalar.cpp7
-rw-r--r--lib/Frontend/CompilerInvocation.cpp33
-rw-r--r--lib/Sema/SemaAttr.cpp9
10 files changed, 49 insertions, 60 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 4d2b37efe6..efeeffcef2 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -2920,7 +2920,7 @@ private:
// This is only meaningful for operations on floating point types and 0
// otherwise.
- unsigned FPFeatures : 2;
+ unsigned FPFeatures : 1;
SourceLocation OpLoc;
enum { LHS, RHS, END_EXPR };
@@ -3078,8 +3078,8 @@ public:
// Get the FP contractability status of this operator. Only meaningful for
// operations on floating point types.
- bool isFPContractableWithinStatement() const {
- return FPOptions(FPFeatures).allowFPContractWithinStatement();
+ bool isFPContractable() const {
+ return FPOptions(FPFeatures).isFPContractable();
}
protected:
diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h
index 79d2c58099..c284918585 100644
--- a/include/clang/AST/ExprCXX.h
+++ b/include/clang/AST/ExprCXX.h
@@ -117,9 +117,7 @@ public:
// Get the FP contractability status of this operator. Only meaningful for
// operations on floating point types.
- bool isFPContractableWithinStatement() const {
- return FPFeatures.allowFPContractWithinStatement();
- }
+ bool isFPContractable() const { return FPFeatures.isFPContractable(); }
friend class ASTStmtReader;
friend class ASTStmtWriter;
diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def
index d00aa411de..7126275503 100644
--- a/include/clang/Basic/LangOptions.def
+++ b/include/clang/Basic/LangOptions.def
@@ -216,8 +216,7 @@ BENIGN_LANGOPT(DebuggerObjCLiteral , 1, 0, "debugger Objective-C literals and su
BENIGN_LANGOPT(SpellChecking , 1, 1, "spell-checking")
LANGOPT(SinglePrecisionConstants , 1, 0, "treating double-precision floating point constants as single precision constants")
LANGOPT(FastRelaxedMath , 1, 0, "OpenCL fast relaxed math")
-/// \brief FP_CONTRACT mode (on/off/fast).
-ENUM_LANGOPT(DefaultFPContractMode, FPContractModeKind, 2, FPC_Off, "FP contraction type")
+LANGOPT(DefaultFPContract , 1, 0, "FP_CONTRACT")
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")
diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h
index 16abf9b7bb..cfbcbecc5f 100644
--- a/include/clang/Basic/LangOptions.h
+++ b/include/clang/Basic/LangOptions.h
@@ -88,12 +88,6 @@ public:
MSVC2015 = 19
};
- enum FPContractModeKind {
- FPC_Off, // Form fused FP ops only where result will not be affected.
- FPC_On, // Form fused FP ops according to FP_CONTRACT rules.
- FPC_Fast // Aggressively fuse FP ops (E.g. FMA).
- };
-
public:
/// \brief Set of enabled sanitizers.
SanitizerSet Sanitize;
@@ -186,35 +180,22 @@ public:
/// \brief Floating point control options
class FPOptions {
public:
- FPOptions() : fp_contract(LangOptions::FPC_Off) {}
+ FPOptions() : fp_contract(0) {}
- // Used for serializing.
- explicit FPOptions(unsigned I)
- : fp_contract(static_cast<LangOptions::FPContractModeKind>(I)) {}
+ explicit FPOptions(unsigned I) : fp_contract(I) {}
explicit FPOptions(const LangOptions &LangOpts)
- : fp_contract(LangOpts.getDefaultFPContractMode()) {}
+ : fp_contract(LangOpts.DefaultFPContract) {}
- bool allowFPContractWithinStatement() const {
- return fp_contract == LangOptions::FPC_On;
- }
- bool allowFPContractAcrossStatement() const {
- return fp_contract == LangOptions::FPC_Fast;
- }
- void setAllowFPContractWithinStatement() {
- fp_contract = LangOptions::FPC_On;
- }
- void setAllowFPContractAcrossStatement() {
- fp_contract = LangOptions::FPC_Fast;
- }
- void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
+ void setFPContractable(bool V) { fp_contract = V; }
+ bool isFPContractable() const { return fp_contract; }
/// Used to serialize this.
unsigned getInt() const { return fp_contract; }
private:
/// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
- LangOptions::FPContractModeKind fp_contract : 2;
+ unsigned fp_contract : 1;
};
/// \brief Describes the kind of translation unit being processed.
diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def
index 751f5e2944..172380c00e 100644
--- a/include/clang/Frontend/CodeGenOptions.def
+++ b/include/clang/Frontend/CodeGenOptions.def
@@ -65,6 +65,8 @@ CODEGENOPT(EmitGcovArcs , 1, 0) ///< Emit coverage data files, aka. GCDA.
CODEGENOPT(EmitGcovNotes , 1, 0) ///< Emit coverage "notes" files, aka GCNO.
CODEGENOPT(EmitOpenCLArgMetadata , 1, 0) ///< Emit OpenCL kernel arg metadata.
CODEGENOPT(EmulatedTLS , 1, 0) ///< Set when -femulated-tls is enabled.
+/// \brief FP_CONTRACT mode (on/off/fast).
+ENUM_CODEGENOPT(FPContractMode, FPContractModeKind, 2, FPC_On)
/// \brief Embed Bitcode mode (off/all/bitcode/marker).
ENUM_CODEGENOPT(EmbedBitcode, EmbedBitcodeKind, 2, Embed_Off)
CODEGENOPT(ForbidGuardVariables , 1, 0) ///< Issue errors if C++ guard variables
diff --git a/include/clang/Frontend/CodeGenOptions.h b/include/clang/Frontend/CodeGenOptions.h
index 08c02c2cd0..b17f19075e 100644
--- a/include/clang/Frontend/CodeGenOptions.h
+++ b/include/clang/Frontend/CodeGenOptions.h
@@ -69,6 +69,12 @@ public:
LocalExecTLSModel
};
+ enum FPContractModeKind {
+ FPC_Off, // Form fused FP ops only where result will not be affected.
+ FPC_On, // Form fused FP ops according to FP_CONTRACT rules.
+ FPC_Fast // Aggressively fuse FP ops (E.g. FMA).
+ };
+
enum StructReturnConventionKind {
SRCK_Default, // No special option was passed.
SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).
diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp
index f34c8cabc6..35de1a4580 100644
--- a/lib/CodeGen/BackendUtil.cpp
+++ b/lib/CodeGen/BackendUtil.cpp
@@ -561,14 +561,14 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
.Default(llvm::FloatABI::Default);
// Set FP fusion mode.
- switch (LangOpts.getDefaultFPContractMode()) {
- case LangOptions::FPC_Off:
+ switch (CodeGenOpts.getFPContractMode()) {
+ case CodeGenOptions::FPC_Off:
Options.AllowFPOpFusion = llvm::FPOpFusion::Strict;
break;
- case LangOptions::FPC_On:
+ case CodeGenOptions::FPC_On:
Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
break;
- case LangOptions::FPC_Fast:
+ case CodeGenOptions::FPC_Fast:
Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
break;
}
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index e9041b282f..9eb21b8086 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -2672,7 +2672,12 @@ static Value* tryEmitFMulAdd(const BinOpInfo &op,
"Only fadd/fsub can be the root of an fmuladd.");
// Check whether this op is marked as fusable.
- if (!op.FPFeatures.allowFPContractWithinStatement())
+ if (!op.FPFeatures.isFPContractable())
+ return nullptr;
+
+ // Check whether -ffp-contract=on. (If -ffp-contract=off/fast, fusing is
+ // either disabled, or handled entirely by the LLVM backend).
+ if (CGF.CGM.getCodeGenOpts().getFPContractMode() != CodeGenOptions::FPC_On)
return nullptr;
// We have a potentially fusable op. Look for a mul on one of the operands.
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 0c1d6d0d85..ab2ba9287c 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -816,6 +816,18 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
}
}
+ if (Arg *A = Args.getLastArg(OPT_ffp_contract)) {
+ StringRef Val = A->getValue();
+ if (Val == "fast")
+ Opts.setFPContractMode(CodeGenOptions::FPC_Fast);
+ else if (Val == "on")
+ Opts.setFPContractMode(CodeGenOptions::FPC_On);
+ else if (Val == "off")
+ Opts.setFPContractMode(CodeGenOptions::FPC_Off);
+ else
+ Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
+ }
+
if (Arg *A = Args.getLastArg(OPT_fdenormal_fp_math_EQ)) {
StringRef Val = A->getValue();
if (Val == "ieee")
@@ -1635,7 +1647,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
Opts.AltiVec = 0;
Opts.ZVector = 0;
Opts.LaxVectorConversions = 0;
- Opts.setDefaultFPContractMode(LangOptions::FPC_On);
+ Opts.DefaultFPContract = 1;
Opts.NativeHalfType = 1;
Opts.NativeHalfArgsAndReturns = 1;
// Include default header file for OpenCL.
@@ -1646,9 +1658,6 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
Opts.CUDA = IK == IK_CUDA || IK == IK_PreprocessedCuda ||
LangStd == LangStandard::lang_cuda;
- if (Opts.CUDA)
- // Set default FP_CONTRACT to FAST.
- Opts.setDefaultFPContractMode(LangOptions::FPC_Fast);
Opts.RenderScript = IK == IK_RenderScript;
if (Opts.RenderScript) {
@@ -2273,18 +2282,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
Args.hasArg(OPT_cl_fast_relaxed_math);
- if (Arg *A = Args.getLastArg(OPT_ffp_contract)) {
- StringRef Val = A->getValue();
- if (Val == "fast")
- Opts.setDefaultFPContractMode(LangOptions::FPC_Fast);
- else if (Val == "on")
- Opts.setDefaultFPContractMode(LangOptions::FPC_On);
- else if (Val == "off")
- Opts.setDefaultFPContractMode(LangOptions::FPC_Off);
- else
- Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
- }
-
Opts.RetainCommentsFromSystemHeaders =
Args.hasArg(OPT_fretain_comments_from_system_headers);
@@ -2539,6 +2536,10 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
// triple used for host compilation.
if (LangOpts.CUDAIsDevice)
Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple;
+
+ // Set default FP_CONTRACT to FAST.
+ if (!Args.hasArg(OPT_ffp_contract))
+ Res.getCodeGenOpts().setFPContractMode(CodeGenOptions::FPC_Fast);
}
// FIXME: Override value name discarding when asan or msan is used because the
diff --git a/lib/Sema/SemaAttr.cpp b/lib/Sema/SemaAttr.cpp
index 34744cbdd9..992eac9019 100644
--- a/lib/Sema/SemaAttr.cpp
+++ b/lib/Sema/SemaAttr.cpp
@@ -450,16 +450,13 @@ void Sema::ActOnPragmaVisibility(const IdentifierInfo* VisType,
void Sema::ActOnPragmaFPContract(tok::OnOffSwitch OOS) {
switch (OOS) {
case tok::OOS_ON:
- FPFeatures.setAllowFPContractWithinStatement();
+ FPFeatures.setFPContractable(true);
break;
case tok::OOS_OFF:
- FPFeatures.setDisallowFPContract();
+ FPFeatures.setFPContractable(false);
break;
case tok::OOS_DEFAULT:
- if (getLangOpts().getDefaultFPContractMode() == LangOptions::FPC_On)
- FPFeatures.setAllowFPContractWithinStatement();
- else
- FPFeatures.setDisallowFPContract();
+ FPFeatures.setFPContractable(getLangOpts().DefaultFPContract);
break;
}
}