Skip to content

Commit

Permalink
Merged master:bb26838ceffb into amd-gfx:c8f92d00575c
Browse files Browse the repository at this point in the history
Local branch amd-gfx c8f92d0 Merged master:1b10c618e928 into amd-gfx:8504aad041f6
Remote branch master bb26838 [clang driver] Move default module cache from system temporary directory
  • Loading branch information
Sw authored and Sw committed Jun 26, 2020
2 parents c8f92d0 + bb26838 commit d235356
Show file tree
Hide file tree
Showing 58 changed files with 952 additions and 357 deletions.
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ New Compiler Flags
simplify access to the many single purpose floating point options. The default
setting is ``precise``.

- The default module cache has moved from /tmp to a per-user cache directory.
By default, this is ~/.cache but on some platforms or installations, this
might be elsewhere. The -fmodules-cache-path=... flag continues to work.

Deprecated Compiler Flags
-------------------------

Expand Down
3 changes: 3 additions & 0 deletions clang/include/clang/Basic/DiagnosticASTKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ def err_experimental_clang_interp_failed : Error<
def warn_integer_constant_overflow : Warning<
"overflow in expression; result is %0 with type %1">,
InGroup<DiagGroup<"integer-overflow">>;
def warn_fixedpoint_constant_overflow : Warning<
"overflow in expression; result is %0 with type %1">,
InGroup<DiagGroup<"fixed-point-overflow">>;

// This is a temporary diagnostic, and shall be removed once our
// implementation is complete, and like the preceding constexpr notes belongs
Expand Down
9 changes: 6 additions & 3 deletions clang/include/clang/Basic/FixedPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class QualType;
/// The fixed point semantics work similarly to llvm::fltSemantics. The width
/// specifies the whole bit width of the underlying scaled integer (with padding
/// if any). The scale represents the number of fractional bits in this type.
/// When HasUnsignedPadding is true and this type is signed, the first bit
/// in the value this represents is treaded as padding.
/// When HasUnsignedPadding is true and this type is unsigned, the first bit
/// in the value this represents is treated as padding.
class FixedPointSemantics {
public:
FixedPointSemantics(unsigned Width, unsigned Scale, bool IsSigned,
Expand Down Expand Up @@ -125,9 +125,12 @@ class APFixedPoint {

// Perform binary operations on a fixed point type. The resulting fixed point
// value will be in the common, full precision semantics that can represent
// the precision and ranges os both input values. See convert() for an
// the precision and ranges of both input values. See convert() for an
// explanation of the Overflow parameter.
APFixedPoint add(const APFixedPoint &Other, bool *Overflow = nullptr) const;
APFixedPoint sub(const APFixedPoint &Other, bool *Overflow = nullptr) const;
APFixedPoint mul(const APFixedPoint &Other, bool *Overflow = nullptr) const;
APFixedPoint div(const APFixedPoint &Other, bool *Overflow = nullptr) const;

/// Perform a unary negation (-X) on this fixed point type, taking into
/// account saturation if applicable.
Expand Down
12 changes: 11 additions & 1 deletion clang/include/clang/Basic/arm_sve.td
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ def SVST1H_VNUM_U : MInst<"svst1h_vnum[_{d}]", "vPFld", "UiUl", [IsSt
def SVST1W_VNUM_S : MInst<"svst1w_vnum[_{d}]", "vPCld", "l", [IsStore], MemEltTyInt32, "aarch64_sve_st1">;
def SVST1W_VNUM_U : MInst<"svst1w_vnum[_{d}]", "vPGld", "Ul", [IsStore], MemEltTyInt32, "aarch64_sve_st1">;

let ArchGuard = "defined(__ARM_FEATURE_SVE_BF16)" in {
def SVST1_BF : MInst<"svst1[_{d}]", "vPpd", "b", [IsStore], MemEltTyDefault, "aarch64_sve_st1">;
def SVST1_VNUM_BF : MInst<"svst1_vnum[_{d}]", "vPpld", "b", [IsStore], MemEltTyDefault, "aarch64_sve_st1">;
}

// Store one vector (vector base)
def SVST1_SCATTER_BASES_U : MInst<"svst1_scatter[_{2}base_{d}]", "vPud", "ilUiUlfd", [IsScatterStore], MemEltTyDefault, "aarch64_sve_st1_scatter_scalar_offset">;
def SVST1B_SCATTER_BASES_U : MInst<"svst1b_scatter[_{2}base_{d}]", "vPud", "ilUiUl", [IsScatterStore], MemEltTyInt8, "aarch64_sve_st1_scatter_scalar_offset">;
Expand Down Expand Up @@ -654,6 +659,11 @@ def SVSTNT1 : MInst<"svstnt1[_{d}]", "vPpd", "csilUcUsUiUlhfd", [IsStore], MemEl
// Store one vector, with no truncation, non-temporal (scalar base, VL displacement)
def SVSTNT1_VNUM : MInst<"svstnt1_vnum[_{d}]", "vPpld", "csilUcUsUiUlhfd", [IsStore], MemEltTyDefault, "aarch64_sve_stnt1">;

let ArchGuard = "defined(__ARM_FEATURE_SVE_BF16)" in {
def SVSTNT1_BF : MInst<"svstnt1[_{d}]", "vPpd", "b", [IsStore], MemEltTyDefault, "aarch64_sve_stnt1">;
def SVSTNT1_VNUM_BF : MInst<"svstnt1_vnum[_{d}]", "vPpld", "b", [IsStore], MemEltTyDefault, "aarch64_sve_stnt1">;
}

////////////////////////////////////////////////////////////////////////////////
// Prefetches

Expand Down Expand Up @@ -1971,7 +1981,7 @@ def SVWHILEWR_S : SInst<"svwhilewr[_{1}]", "Pcc", "iUif", MergeNone, "aarch64_sv
def SVWHILEWR_D : SInst<"svwhilewr[_{1}]", "Pcc", "lUld", MergeNone, "aarch64_sve_whilewr_d", [IsOverloadWhileRW]>;
}

let ArchGuard = "defined(__ARM_FEATURE_SVE2) && defined(__ARM_FEATURE_SVE_BF16)" in {
let ArchGuard = "defined(__ARM_FEATURE_SVE2) && defined(__ARM_FEATURE_BF16_SCALAR_ARITHMETIC)" in {
def SVWHILERW_H_BF16 : SInst<"svwhilerw[_{1}]", "Pcc", "b", MergeNone, "aarch64_sve_whilerw_h", [IsOverloadWhileRW]>;
def SVWHILEWR_H_BF16 : SInst<"svwhilewr[_{1}]", "Pcc", "b", MergeNone, "aarch64_sve_whilewr_h", [IsOverloadWhileRW]>;
}
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/Driver/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ class Driver {
static bool GetReleaseVersion(StringRef Str,
MutableArrayRef<unsigned> Digits);
/// Compute the default -fmodule-cache-path.
static void getDefaultModuleCachePath(SmallVectorImpl<char> &Result);
/// \return True if the system provides a default cache directory.
static bool getDefaultModuleCachePath(SmallVectorImpl<char> &Result);
};

/// \return True if the last defined optimization level is -Ofast.
Expand Down
60 changes: 48 additions & 12 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12881,8 +12881,14 @@ bool FixedPointExprEvaluator::VisitCastExpr(const CastExpr *E) {
return false;
bool Overflowed;
APFixedPoint Result = Src.convert(DestFXSema, &Overflowed);
if (Overflowed && !HandleOverflow(Info, E, Result, DestType))
return false;
if (Overflowed) {
if (Info.checkingForUndefinedBehavior())
Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_fixedpoint_constant_overflow)
<< Result.toString() << E->getType();
else if (!HandleOverflow(Info, E, Result, E->getType()))
return false;
}
return Success(Result, E);
}
case CK_IntegralToFixedPoint: {
Expand All @@ -12894,8 +12900,14 @@ bool FixedPointExprEvaluator::VisitCastExpr(const CastExpr *E) {
APFixedPoint IntResult = APFixedPoint::getFromIntValue(
Src, Info.Ctx.getFixedPointSemantics(DestType), &Overflowed);

if (Overflowed && !HandleOverflow(Info, E, IntResult, DestType))
return false;
if (Overflowed) {
if (Info.checkingForUndefinedBehavior())
Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_fixedpoint_constant_overflow)
<< IntResult.toString() << E->getType();
else if (!HandleOverflow(Info, E, IntResult, E->getType()))
return false;
}

return Success(IntResult, E);
}
Expand All @@ -12908,6 +12920,9 @@ bool FixedPointExprEvaluator::VisitCastExpr(const CastExpr *E) {
}

bool FixedPointExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma)
return ExprEvaluatorBaseTy::VisitBinaryOperator(E);

const Expr *LHS = E->getLHS();
const Expr *RHS = E->getRHS();
FixedPointSemantics ResultFXSema =
Expand All @@ -12920,20 +12935,41 @@ bool FixedPointExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
if (!EvaluateFixedPointOrInteger(RHS, RHSFX, Info))
return false;

bool OpOverflow = false, ConversionOverflow = false;
APFixedPoint Result(LHSFX.getSemantics());
switch (E->getOpcode()) {
case BO_Add: {
bool AddOverflow, ConversionOverflow;
APFixedPoint Result = LHSFX.add(RHSFX, &AddOverflow)
.convert(ResultFXSema, &ConversionOverflow);
if ((AddOverflow || ConversionOverflow) &&
!HandleOverflow(Info, E, Result, E->getType()))
return false;
return Success(Result, E);
Result = LHSFX.add(RHSFX, &OpOverflow)
.convert(ResultFXSema, &ConversionOverflow);
break;
}
case BO_Sub: {
Result = LHSFX.sub(RHSFX, &OpOverflow)
.convert(ResultFXSema, &ConversionOverflow);
break;
}
case BO_Mul: {
Result = LHSFX.mul(RHSFX, &OpOverflow)
.convert(ResultFXSema, &ConversionOverflow);
break;
}
case BO_Div: {
Result = LHSFX.div(RHSFX, &OpOverflow)
.convert(ResultFXSema, &ConversionOverflow);
break;
}
default:
return false;
}
llvm_unreachable("Should've exited before this");
if (OpOverflow || ConversionOverflow) {
if (Info.checkingForUndefinedBehavior())
Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
diag::warn_fixedpoint_constant_overflow)
<< Result.toString() << E->getType();
else if (!HandleOverflow(Info, E, Result, E->getType()))
return false;
}
return Success(Result, E);
}

//===----------------------------------------------------------------------===//
Expand Down
136 changes: 136 additions & 0 deletions clang/lib/Basic/FixedPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,142 @@ APFixedPoint APFixedPoint::add(const APFixedPoint &Other,
return APFixedPoint(Result, CommonFXSema);
}

APFixedPoint APFixedPoint::sub(const APFixedPoint &Other,
bool *Overflow) const {
auto CommonFXSema = Sema.getCommonSemantics(Other.getSemantics());
APFixedPoint ConvertedThis = convert(CommonFXSema);
APFixedPoint ConvertedOther = Other.convert(CommonFXSema);
llvm::APSInt ThisVal = ConvertedThis.getValue();
llvm::APSInt OtherVal = ConvertedOther.getValue();
bool Overflowed = false;

llvm::APSInt Result;
if (CommonFXSema.isSaturated()) {
Result = CommonFXSema.isSigned() ? ThisVal.ssub_sat(OtherVal)
: ThisVal.usub_sat(OtherVal);
} else {
Result = ThisVal.isSigned() ? ThisVal.ssub_ov(OtherVal, Overflowed)
: ThisVal.usub_ov(OtherVal, Overflowed);
}

if (Overflow)
*Overflow = Overflowed;

return APFixedPoint(Result, CommonFXSema);
}

APFixedPoint APFixedPoint::mul(const APFixedPoint &Other,
bool *Overflow) const {
auto CommonFXSema = Sema.getCommonSemantics(Other.getSemantics());
APFixedPoint ConvertedThis = convert(CommonFXSema);
APFixedPoint ConvertedOther = Other.convert(CommonFXSema);
llvm::APSInt ThisVal = ConvertedThis.getValue();
llvm::APSInt OtherVal = ConvertedOther.getValue();
bool Overflowed = false;

// Widen the LHS and RHS so we can perform a full multiplication.
unsigned Wide = CommonFXSema.getWidth() * 2;
if (CommonFXSema.isSigned()) {
ThisVal = ThisVal.sextOrSelf(Wide);
OtherVal = OtherVal.sextOrSelf(Wide);
} else {
ThisVal = ThisVal.zextOrSelf(Wide);
OtherVal = OtherVal.zextOrSelf(Wide);
}

// Perform the full multiplication and downscale to get the same scale.
//
// Note that the right shifts here perform an implicit downwards rounding.
// This rounding could discard bits that would technically place the result
// outside the representable range. We interpret the spec as allowing us to
// perform the rounding step first, avoiding the overflow case that would
// arise.
llvm::APSInt Result;
if (CommonFXSema.isSigned())
Result = ThisVal.smul_ov(OtherVal, Overflowed)
.ashr(CommonFXSema.getScale());
else
Result = ThisVal.umul_ov(OtherVal, Overflowed)
.lshr(CommonFXSema.getScale());
assert(!Overflowed && "Full multiplication cannot overflow!");
Result.setIsSigned(CommonFXSema.isSigned());

// If our result lies outside of the representative range of the common
// semantic, we either have overflow or saturation.
llvm::APSInt Max = APFixedPoint::getMax(CommonFXSema).getValue()
.extOrTrunc(Wide);
llvm::APSInt Min = APFixedPoint::getMin(CommonFXSema).getValue()
.extOrTrunc(Wide);
if (CommonFXSema.isSaturated()) {
if (Result < Min)
Result = Min;
else if (Result > Max)
Result = Max;
} else
Overflowed = Result < Min || Result > Max;

if (Overflow)
*Overflow = Overflowed;

return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
CommonFXSema);
}

APFixedPoint APFixedPoint::div(const APFixedPoint &Other,
bool *Overflow) const {
auto CommonFXSema = Sema.getCommonSemantics(Other.getSemantics());
APFixedPoint ConvertedThis = convert(CommonFXSema);
APFixedPoint ConvertedOther = Other.convert(CommonFXSema);
llvm::APSInt ThisVal = ConvertedThis.getValue();
llvm::APSInt OtherVal = ConvertedOther.getValue();
bool Overflowed = false;

// Widen the LHS and RHS so we can perform a full division.
unsigned Wide = CommonFXSema.getWidth() * 2;
if (CommonFXSema.isSigned()) {
ThisVal = ThisVal.sextOrSelf(Wide);
OtherVal = OtherVal.sextOrSelf(Wide);
} else {
ThisVal = ThisVal.zextOrSelf(Wide);
OtherVal = OtherVal.zextOrSelf(Wide);
}

// Upscale to compensate for the loss of precision from division, and
// perform the full division.
ThisVal = ThisVal.shl(CommonFXSema.getScale());
llvm::APSInt Result;
if (CommonFXSema.isSigned()) {
llvm::APInt Rem;
llvm::APInt::sdivrem(ThisVal, OtherVal, Result, Rem);
// If the quotient is negative and the remainder is nonzero, round
// towards negative infinity by subtracting epsilon from the result.
if (Result.isNegative() && !Rem.isNullValue())
Result = Result - 1;
} else
Result = ThisVal.udiv(OtherVal);
Result.setIsSigned(CommonFXSema.isSigned());

// If our result lies outside of the representative range of the common
// semantic, we either have overflow or saturation.
llvm::APSInt Max = APFixedPoint::getMax(CommonFXSema).getValue()
.extOrTrunc(Wide);
llvm::APSInt Min = APFixedPoint::getMin(CommonFXSema).getValue()
.extOrTrunc(Wide);
if (CommonFXSema.isSaturated()) {
if (Result < Min)
Result = Min;
else if (Result > Max)
Result = Max;
} else
Overflowed = Result < Min || Result > Max;

if (Overflow)
*Overflow = Overflowed;

return APFixedPoint(Result.sextOrTrunc(CommonFXSema.getWidth()),
CommonFXSema);
}

void APFixedPoint::toString(llvm::SmallVectorImpl<char> &Str) const {
llvm::APSInt Val = getValue();
unsigned Scale = getScale();
Expand Down
Loading

0 comments on commit d235356

Please sign in to comment.