Skip to content

Commit

Permalink
Modify FPFeatures to use delta not absolute settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Melanie Blower committed Jun 26, 2020
1 parent c8295de commit 3a748cb
Show file tree
Hide file tree
Showing 38 changed files with 578 additions and 419 deletions.
77 changes: 46 additions & 31 deletions clang/include/clang/AST/Expr.h
Expand Up @@ -2118,21 +2118,21 @@ class ParenExpr : public Expr {
///
class UnaryOperator final
: public Expr,
private llvm::TrailingObjects<UnaryOperator, FPOptions> {
private llvm::TrailingObjects<UnaryOperator, FPOptionsOverride> {
Stmt *Val;

size_t numTrailingObjects(OverloadToken<FPOptions>) const {
size_t numTrailingObjects(OverloadToken<FPOptionsOverride>) const {
return UnaryOperatorBits.HasFPFeatures ? 1 : 0;
}

FPOptions &getTrailingFPFeatures() {
FPOptionsOverride &getTrailingFPFeatures() {
assert(UnaryOperatorBits.HasFPFeatures);
return *getTrailingObjects<FPOptions>();
return *getTrailingObjects<FPOptionsOverride>();
}

const FPOptions &getTrailingFPFeatures() const {
const FPOptionsOverride &getTrailingFPFeatures() const {
assert(UnaryOperatorBits.HasFPFeatures);
return *getTrailingObjects<FPOptions>();
return *getTrailingObjects<FPOptionsOverride>();
}

public:
Expand All @@ -2141,7 +2141,7 @@ class UnaryOperator final
protected:
UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc, QualType type,
ExprValueKind VK, ExprObjectKind OK, SourceLocation l,
bool CanOverflow, FPOptions FPFeatures);
bool CanOverflow, FPOptionsOverride FPFeatures);

/// Build an empty unary operator.
explicit UnaryOperator(bool HasFPFeatures, EmptyShell Empty)
Expand All @@ -2156,7 +2156,7 @@ class UnaryOperator final
static UnaryOperator *Create(const ASTContext &C, Expr *input, Opcode opc,
QualType type, ExprValueKind VK,
ExprObjectKind OK, SourceLocation l,
bool CanOverflow, FPOptions FPFeatures);
bool CanOverflow, FPOptionsOverride FPFeatures);

Opcode getOpcode() const {
return static_cast<Opcode>(UnaryOperatorBits.Opc);
Expand All @@ -2182,13 +2182,13 @@ class UnaryOperator final
// Get the FP contractability status of this operator. Only meaningful for
// operations on floating point types.
bool isFPContractableWithinStatement(const LangOptions &LO) const {
return getFPFeatures(LO).allowFPContractWithinStatement();
return getFPFeaturesInEffect(LO).allowFPContractWithinStatement();
}

// Get the FENV_ACCESS status of this operator. Only meaningful for
// operations on floating point types.
bool isFEnvAccessOn(const LangOptions &LO) const {
return getFPFeatures(LO).allowFEnvAccess();
return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
}

/// isPostfix - Return true if this is a postfix operation, like x++.
Expand Down Expand Up @@ -2263,19 +2263,26 @@ class UnaryOperator final

protected:
/// Get FPFeatures from trailing storage
FPOptions getStoredFPFeatures() const { return getTrailingFPFeatures(); }
FPOptionsOverride getStoredFPFeatures() const {
return getTrailingFPFeatures();
}

/// Set FPFeatures in trailing storage, used only by Serialization
void setStoredFPFeatures(FPOptions F) { getTrailingFPFeatures() = F; }
void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }

public:
// Get the FP features status of this operator. Only meaningful for
// operations on floating point types.
FPOptions getFPFeatures(const LangOptions &LO) const {
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const {
if (UnaryOperatorBits.HasFPFeatures)
return getStoredFPFeatures();
return getStoredFPFeatures().applyOverrides(LO);
return FPOptions::defaultWithoutTrailingStorage(LO);
}
FPOptionsOverride getFPOptionsOverride() const {
if (UnaryOperatorBits.HasFPFeatures)
return getStoredFPFeatures();
return FPOptionsOverride();
}

friend TrailingObjects;
friend class ASTReader;
Expand Down Expand Up @@ -3633,22 +3640,22 @@ class BinaryOperator : public Expr {
size_t offsetOfTrailingStorage() const;

/// Return a pointer to the trailing FPOptions
FPOptions *getTrailingFPFeatures() {
FPOptionsOverride *getTrailingFPFeatures() {
assert(BinaryOperatorBits.HasFPFeatures);
return reinterpret_cast<FPOptions *>(reinterpret_cast<char *>(this) +
offsetOfTrailingStorage());
return reinterpret_cast<FPOptionsOverride *>(
reinterpret_cast<char *>(this) + offsetOfTrailingStorage());
}
const FPOptions *getTrailingFPFeatures() const {
const FPOptionsOverride *getTrailingFPFeatures() const {
assert(BinaryOperatorBits.HasFPFeatures);
return reinterpret_cast<const FPOptions *>(
return reinterpret_cast<const FPOptionsOverride *>(
reinterpret_cast<const char *>(this) + offsetOfTrailingStorage());
}

/// Build a binary operator, assuming that appropriate storage has been
/// allocated for the trailing objects when needed.
BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
QualType ResTy, ExprValueKind VK, ExprObjectKind OK,
SourceLocation opLoc, FPOptions FPFeatures);
SourceLocation opLoc, FPOptionsOverride FPFeatures);

/// Construct an empty binary operator.
explicit BinaryOperator(EmptyShell Empty) : Expr(BinaryOperatorClass, Empty) {
Expand All @@ -3661,7 +3668,7 @@ class BinaryOperator : public Expr {
static BinaryOperator *Create(const ASTContext &C, Expr *lhs, Expr *rhs,
Opcode opc, QualType ResTy, ExprValueKind VK,
ExprObjectKind OK, SourceLocation opLoc,
FPOptions FPFeatures);
FPOptionsOverride FPFeatures);
SourceLocation getExprLoc() const { return getOperatorLoc(); }
SourceLocation getOperatorLoc() const { return BinaryOperatorBits.OpLoc; }
void setOperatorLoc(SourceLocation L) { BinaryOperatorBits.OpLoc = L; }
Expand Down Expand Up @@ -3808,40 +3815,48 @@ class BinaryOperator : public Expr {
bool hasStoredFPFeatures() const { return BinaryOperatorBits.HasFPFeatures; }

/// Get FPFeatures from trailing storage
FPOptions getStoredFPFeatures() const {
FPOptionsOverride getStoredFPFeatures() const {
assert(hasStoredFPFeatures());
return *getTrailingFPFeatures();
}
/// Set FPFeatures in trailing storage, used only by Serialization
void setStoredFPFeatures(FPOptions F) {
void setStoredFPFeatures(FPOptionsOverride F) {
assert(BinaryOperatorBits.HasFPFeatures);
*getTrailingFPFeatures() = F;
}

// Get the FP features status of this operator. Only meaningful for
// operations on floating point types.
FPOptions getFPFeatures(const LangOptions &LO) const {
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const {
if (BinaryOperatorBits.HasFPFeatures)
return getStoredFPFeatures();
return getStoredFPFeatures().applyOverrides(LO);
return FPOptions::defaultWithoutTrailingStorage(LO);
}

// This is used in ASTImporter
FPOptionsOverride getFPFeatures(const LangOptions &LO) const {
if (BinaryOperatorBits.HasFPFeatures)
return getStoredFPFeatures();
return FPOptionsOverride();
}

// Get the FP contractability status of this operator. Only meaningful for
// operations on floating point types.
bool isFPContractableWithinStatement(const LangOptions &LO) const {
return getFPFeatures(LO).allowFPContractWithinStatement();
return getFPFeaturesInEffect(LO).allowFPContractWithinStatement();
}

// Get the FENV_ACCESS status of this operator. Only meaningful for
// operations on floating point types.
bool isFEnvAccessOn(const LangOptions &LO) const {
return getFPFeatures(LO).allowFEnvAccess();
return getFPFeaturesInEffect(LO).getAllowFEnvAccess();
}

protected:
BinaryOperator(const ASTContext &Ctx, Expr *lhs, Expr *rhs, Opcode opc,
QualType ResTy, ExprValueKind VK, ExprObjectKind OK,
SourceLocation opLoc, FPOptions FPFeatures, bool dead2);
SourceLocation opLoc, FPOptionsOverride FPFeatures,
bool dead2);

/// Construct an empty BinaryOperator, SC is CompoundAssignOperator.
BinaryOperator(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) {
Expand All @@ -3851,7 +3866,7 @@ class BinaryOperator : public Expr {
/// Return the size in bytes needed for the trailing objects.
/// Used to allocate the right amount of storage.
static unsigned sizeOfTrailingObjects(bool HasFPFeatures) {
return HasFPFeatures * sizeof(FPOptions);
return HasFPFeatures * sizeof(FPOptionsOverride);
}
};

Expand All @@ -3873,7 +3888,7 @@ class CompoundAssignOperator : public BinaryOperator {
protected:
CompoundAssignOperator(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc,
QualType ResType, ExprValueKind VK, ExprObjectKind OK,
SourceLocation OpLoc, FPOptions FPFeatures,
SourceLocation OpLoc, FPOptionsOverride FPFeatures,
QualType CompLHSType, QualType CompResultType)
: BinaryOperator(C, lhs, rhs, opc, ResType, VK, OK, OpLoc, FPFeatures,
true),
Expand All @@ -3889,7 +3904,7 @@ class CompoundAssignOperator : public BinaryOperator {
static CompoundAssignOperator *
Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc,
FPOptions FPFeatures, QualType CompLHSType = QualType(),
FPOptionsOverride FPFeatures, QualType CompLHSType = QualType(),
QualType CompResultType = QualType());

// The two computation types are the type the LHS is converted
Expand Down
21 changes: 6 additions & 15 deletions clang/include/clang/AST/ExprCXX.h
Expand Up @@ -84,6 +84,7 @@ class CXXOperatorCallExpr final : public CallExpr {
friend class ASTStmtWriter;

SourceRange Range;
FPOptionsOverride Overrides;

// CXXOperatorCallExpr has some trailing objects belonging
// to CallExpr. See CallExpr for the details.
Expand All @@ -92,7 +93,7 @@ class CXXOperatorCallExpr final : public CallExpr {

CXXOperatorCallExpr(OverloadedOperatorKind OpKind, Expr *Fn,
ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
SourceLocation OperatorLoc, FPOptions FPFeatures,
SourceLocation OperatorLoc, FPOptionsOverride FPFeatures,
ADLCallKind UsesADL);

CXXOperatorCallExpr(unsigned NumArgs, EmptyShell Empty);
Expand All @@ -101,7 +102,7 @@ class CXXOperatorCallExpr final : public CallExpr {
static CXXOperatorCallExpr *
Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn,
ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK,
SourceLocation OperatorLoc, FPOptions FPFeatures,
SourceLocation OperatorLoc, FPOptionsOverride FPFeatures,
ADLCallKind UsesADL = NotADL);

static CXXOperatorCallExpr *CreateEmpty(const ASTContext &Ctx,
Expand Down Expand Up @@ -164,20 +165,10 @@ class CXXOperatorCallExpr final : public CallExpr {
return T->getStmtClass() == CXXOperatorCallExprClass;
}

// Set the FP contractability status of this operator. Only meaningful for
// Set the FPFeatures status of this operator. Only meaningful for
// operations on floating point types.
void setFPFeatures(FPOptions F) {
CXXOperatorCallExprBits.FPFeatures = F.getAsOpaqueInt();
}
FPOptions getFPFeatures() const {
return FPOptions(CXXOperatorCallExprBits.FPFeatures);
}

// Get the FP contractability status of this operator. Only meaningful for
// operations on floating point types.
bool isFPContractableWithinStatement() const {
return getFPFeatures().allowFPContractWithinStatement();
}
void setFPFeatures(FPOptionsOverride F) { Overrides = F; }
FPOptionsOverride getFPFeatures() const { return Overrides; }
};

/// Represents a call to a member function that
Expand Down
3 changes: 0 additions & 3 deletions clang/include/clang/AST/Stmt.h
Expand Up @@ -614,9 +614,6 @@ class alignas(void *) Stmt {
/// The kind of this overloaded operator. One of the enumerator
/// value of OverloadedOperatorKind.
unsigned OperatorKind : 6;

// Only meaningful for floating point types.
unsigned FPFeatures : 14;
};

class CXXRewrittenBinaryOperatorBitfields {
Expand Down
26 changes: 26 additions & 0 deletions clang/include/clang/Basic/FPOptions.def
@@ -0,0 +1,26 @@
//===--- FPOptions.def - Floating Point Options database --------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// This file defines the Floating Point language options. Users of this file
// must define the FPOPT macro to make use of this information.
#ifndef OPTION
# error Define the OPTION macro to handle floating point language options
#endif

// OPTION(name, type, width, previousName)
OPTION(FPContractMode, LangOptions::FPModeKind, 2, First)
OPTION(RoundingMode, RoundingMode, 3, FPContractMode)
OPTION(FPExceptionMode, LangOptions::FPExceptionModeKind, 2, RoundingMode)
OPTION(AllowFEnvAccess, bool, 1, FPExceptionMode)
OPTION(AllowFPReassociate, bool, 1, AllowFEnvAccess)
OPTION(NoHonorNaNs, bool, 1, AllowFPReassociate)
OPTION(NoHonorInfs, bool, 1, NoHonorNaNs)
OPTION(NoSignedZero, bool, 1, NoHonorInfs)
OPTION(AllowReciprocal, bool, 1, NoSignedZero)
OPTION(AllowApproxFunc, bool, 1, AllowReciprocal)
#undef OPTION
18 changes: 9 additions & 9 deletions clang/include/clang/Basic/LangOptions.def
Expand Up @@ -193,12 +193,12 @@ COMPATIBLE_LANGOPT(Deprecated , 1, 0, "__DEPRECATED predefined macro")
COMPATIBLE_LANGOPT(FastMath , 1, 0, "fast FP math optimizations, and __FAST_MATH__ predefined macro")
COMPATIBLE_LANGOPT(FiniteMathOnly , 1, 0, "__FINITE_MATH_ONLY__ predefined macro")
COMPATIBLE_LANGOPT(UnsafeFPMath , 1, 0, "Unsafe Floating Point Math")
COMPATIBLE_LANGOPT(AllowFPReassoc , 1, 0, "Permit Floating Point reassociation")
COMPATIBLE_LANGOPT(NoHonorNaNs , 1, 0, "Permit Floating Point optimization without regard to NaN")
COMPATIBLE_LANGOPT(NoHonorInfs , 1, 0, "Permit Floating Point optimization without regard to infinities")
COMPATIBLE_LANGOPT(NoSignedZero , 1, 0, "Permit Floating Point optimization without regard to signed zeros")
COMPATIBLE_LANGOPT(AllowRecip , 1, 0, "Permit Floating Point reciprocal")
COMPATIBLE_LANGOPT(ApproxFunc , 1, 0, "Permit Floating Point approximation")
BENIGN_LANGOPT(AllowFPReassoc , 1, 0, "Permit Floating Point reassociation")
BENIGN_LANGOPT(NoHonorNaNs , 1, 0, "Permit Floating Point optimization without regard to NaN")
BENIGN_LANGOPT(NoHonorInfs , 1, 0, "Permit Floating Point optimization without regard to infinities")
BENIGN_LANGOPT(NoSignedZero , 1, 0, "Permit Floating Point optimization without regard to signed zeros")
BENIGN_LANGOPT(AllowRecip , 1, 0, "Permit Floating Point reciprocal")
BENIGN_LANGOPT(ApproxFunc , 1, 0, "Permit Floating Point approximation")

BENIGN_LANGOPT(ObjCGCBitmapPrint , 1, 0, "printing of GC's bitmap layout for __weak/__strong ivars")

Expand Down Expand Up @@ -271,9 +271,9 @@ 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")
/// FP_CONTRACT mode (on/off/fast).
ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contraction type")
ENUM_LANGOPT(FPRoundingMode, RoundingMode, 3, RoundingMode::NearestTiesToEven, "FP Rounding Mode type")
ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Ignore, "FP Exception Behavior Mode type")
BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contraction type")
BENIGN_ENUM_LANGOPT(FPRoundingMode, RoundingMode, 3, RoundingMode::NearestTiesToEven, "FP Rounding Mode type")
BENIGN_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

0 comments on commit 3a748cb

Please sign in to comment.