Skip to content

Commit e7b9a89

Browse files
authored
Merge branch 'main' into BOLTProfileQualityPass
2 parents 681369b + 7a03666 commit e7b9a89

File tree

7 files changed

+71
-106
lines changed

7 files changed

+71
-106
lines changed

flang/runtime/matmul.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,25 @@ static inline RT_API_ATTRS void DoMatmul(
288288
}
289289
SubscriptValue n{x.GetDimension(xRank - 1).Extent()};
290290
if (n != y.GetDimension(0).Extent()) {
291-
terminator.Crash("MATMUL: unacceptable operand shapes (%jdx%jd, %jdx%jd)",
292-
static_cast<std::intmax_t>(x.GetDimension(0).Extent()),
293-
static_cast<std::intmax_t>(n),
294-
static_cast<std::intmax_t>(y.GetDimension(0).Extent()),
295-
static_cast<std::intmax_t>(y.GetDimension(1).Extent()));
291+
// At this point, we know that there's a shape error. There are three
292+
// possibilities, x is rank 1, y is rank 1, or both are rank 2.
293+
if (xRank == 1) {
294+
terminator.Crash("MATMUL: unacceptable operand shapes (%jd, %jdx%jd)",
295+
static_cast<std::intmax_t>(n),
296+
static_cast<std::intmax_t>(y.GetDimension(0).Extent()),
297+
static_cast<std::intmax_t>(y.GetDimension(1).Extent()));
298+
} else if (yRank == 1) {
299+
terminator.Crash("MATMUL: unacceptable operand shapes (%jdx%jd, %jd)",
300+
static_cast<std::intmax_t>(x.GetDimension(0).Extent()),
301+
static_cast<std::intmax_t>(n),
302+
static_cast<std::intmax_t>(y.GetDimension(0).Extent()));
303+
} else {
304+
terminator.Crash("MATMUL: unacceptable operand shapes (%jdx%jd, %jdx%jd)",
305+
static_cast<std::intmax_t>(x.GetDimension(0).Extent()),
306+
static_cast<std::intmax_t>(n),
307+
static_cast<std::intmax_t>(y.GetDimension(0).Extent()),
308+
static_cast<std::intmax_t>(y.GetDimension(1).Extent()));
309+
}
296310
}
297311
using WriteResult =
298312
CppTypeFor<RCAT == TypeCategory::Logical ? TypeCategory::Integer : RCAT,

libc/src/__support/FPUtil/NearestIntegerOperations.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ round_using_specific_rounding_mode(T x, int rnd) {
199199
return x;
200200

201201
StorageType trim_value =
202-
bits.get_mantissa() & ((StorageType(1) << trim_size) - 1);
202+
bits.get_mantissa() &
203+
static_cast<StorageType>(((StorageType(1) << trim_size) - 1));
203204
StorageType half_value =
204205
static_cast<StorageType>((StorageType(1) << (trim_size - 1)));
205206
// If exponent is 0, trimSize will be equal to the mantissa width, and

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ template <size_t Bits> struct DyadicFloat {
110110
.get_val();
111111
// volatile prevents constant propagation that would result in infinity
112112
// always being returned no matter the current rounding mode.
113-
volatile T two(2.0);
113+
volatile T two = static_cast<T>(2.0);
114114
T r = two * d_hi;
115115

116116
// TODO: Whether rounding down the absolute value to max_normal should

libc/src/__support/FPUtil/generic/FMA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fma(InType x, InType y, InType z) {
266266
}
267267

268268
DyadicFloat result(prod_sign, prod_lsb_exp - InFPBits::EXP_BIAS, prod_mant);
269-
result.mantissa |= sticky_bits;
269+
result.mantissa |= static_cast<unsigned int>(sticky_bits);
270270
return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
271271
}
272272

libc/src/__support/FPUtil/generic/div.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ div(InType x, InType y) {
9797

9898
// Number of iterations = full output precision + 1 rounding bit + 1 potential
9999
// leading 0.
100-
constexpr size_t NUM_ITERS = OutFPBits::FRACTION_LEN + 3;
100+
constexpr int NUM_ITERS = OutFPBits::FRACTION_LEN + 3;
101101
int result_exp = xd.exponent - yd.exponent - (NUM_ITERS - 1);
102102

103103
InStorageType q = 0;
104104
InStorageType r = static_cast<InStorageType>(xd.mantissa >> 2);
105105
InStorageType yd_mant_in = static_cast<InStorageType>(yd.mantissa >> 1);
106106

107-
for (size_t i = 0; i < NUM_ITERS; ++i) {
107+
for (int i = 0; i < NUM_ITERS; ++i) {
108108
q <<= 1;
109109
r <<= 1;
110110
if (r >= yd_mant_in) {
@@ -114,8 +114,7 @@ div(InType x, InType y) {
114114
}
115115

116116
DyadicFloat result(result_sign, result_exp, q);
117-
result.mantissa += r != 0;
118-
117+
result.mantissa |= static_cast<unsigned int>(r != 0);
119118
return result.template as<OutType, /*ShouldSignalExceptions=*/true>();
120119
}
121120

libc/src/__support/big_int.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ struct BigInt {
387387
}
388388

389389
// Initialize the first word to |v| and the rest to 0.
390-
template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T>>>
390+
template <typename T, typename = cpp::enable_if_t<cpp::is_integral_v<T> &&
391+
!cpp::is_same_v<T, bool>>>
391392
LIBC_INLINE constexpr BigInt(T v) {
392393
constexpr size_t T_SIZE = sizeof(T) * CHAR_BIT;
393394
const bool is_neg = Signed && (v < 0);
@@ -440,7 +441,7 @@ struct BigInt {
440441
constexpr size_t MAX_COUNT =
441442
T_SIZE > Bits ? WORD_COUNT : T_SIZE / WORD_SIZE;
442443
for (size_t i = 1; i < MAX_COUNT; ++i)
443-
lo += static_cast<T>(val[i]) << (WORD_SIZE * i);
444+
lo += static_cast<T>(static_cast<T>(val[i]) << (WORD_SIZE * i));
444445
if constexpr (Signed && (T_SIZE > Bits)) {
445446
// Extend sign for negative numbers.
446447
constexpr T MASK = (~T(0) << Bits);

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 42 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -521,87 +521,6 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
521521
return std::move(ISAInfo);
522522
}
523523

524-
static Error processMultiLetterExtension(
525-
StringRef RawExt,
526-
MapVector<std::string, RISCVISAUtils::ExtensionVersion,
527-
std::map<std::string, unsigned>> &SeenExtMap,
528-
bool IgnoreUnknown, bool EnableExperimentalExtension,
529-
bool ExperimentalExtensionVersionCheck) {
530-
StringRef Type = getExtensionType(RawExt);
531-
StringRef Desc = getExtensionTypeDesc(RawExt);
532-
auto Pos = findLastNonVersionCharacter(RawExt) + 1;
533-
StringRef Name(RawExt.substr(0, Pos));
534-
StringRef Vers(RawExt.substr(Pos));
535-
536-
if (Type.empty()) {
537-
if (IgnoreUnknown)
538-
return Error::success();
539-
return createStringError(errc::invalid_argument,
540-
"invalid extension prefix '" + RawExt + "'");
541-
}
542-
543-
if (!IgnoreUnknown && Name.size() == Type.size())
544-
return createStringError(errc::invalid_argument,
545-
Desc + " name missing after '" + Type + "'");
546-
547-
unsigned Major, Minor, ConsumeLength;
548-
if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
549-
EnableExperimentalExtension,
550-
ExperimentalExtensionVersionCheck)) {
551-
if (IgnoreUnknown) {
552-
consumeError(std::move(E));
553-
return Error::success();
554-
}
555-
return E;
556-
}
557-
558-
// Check if duplicated extension.
559-
if (!IgnoreUnknown && SeenExtMap.contains(Name.str()))
560-
return createStringError(errc::invalid_argument,
561-
"duplicated " + Desc + " '" + Name + "'");
562-
563-
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
564-
return Error::success();
565-
566-
SeenExtMap[Name.str()] = {Major, Minor};
567-
return Error::success();
568-
}
569-
570-
static Error processSingleLetterExtension(
571-
StringRef &RawExt,
572-
MapVector<std::string, RISCVISAUtils::ExtensionVersion,
573-
std::map<std::string, unsigned>> &SeenExtMap,
574-
bool IgnoreUnknown, bool EnableExperimentalExtension,
575-
bool ExperimentalExtensionVersionCheck) {
576-
unsigned Major, Minor, ConsumeLength;
577-
StringRef Name = RawExt.take_front(1);
578-
RawExt.consume_front(Name);
579-
if (auto E = getExtensionVersion(Name, RawExt, Major, Minor, ConsumeLength,
580-
EnableExperimentalExtension,
581-
ExperimentalExtensionVersionCheck)) {
582-
if (IgnoreUnknown) {
583-
consumeError(std::move(E));
584-
RawExt = RawExt.substr(ConsumeLength);
585-
return Error::success();
586-
}
587-
return E;
588-
}
589-
590-
RawExt = RawExt.substr(ConsumeLength);
591-
592-
// Check if duplicated extension.
593-
if (!IgnoreUnknown && SeenExtMap.contains(Name.str()))
594-
return createStringError(errc::invalid_argument,
595-
"duplicated standard user-level extension '" +
596-
Name + "'");
597-
598-
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
599-
return Error::success();
600-
601-
SeenExtMap[Name.str()] = {Major, Minor};
602-
return Error::success();
603-
}
604-
605524
llvm::Expected<std::unique_ptr<RISCVISAInfo>>
606525
RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
607526
bool ExperimentalExtensionVersionCheck,
@@ -738,11 +657,12 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
738657
Exts = Exts.slice(Idx, StringRef::npos);
739658

740659
do {
660+
StringRef Name, Vers, Desc;
741661
if (RISCVISAUtils::AllStdExts.contains(Ext.front())) {
742-
if (auto E = processSingleLetterExtension(
743-
Ext, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
744-
ExperimentalExtensionVersionCheck))
745-
return std::move(E);
662+
Name = Ext.take_front(1);
663+
Ext = Ext.drop_front();
664+
Vers = Ext;
665+
Desc = "standard user-level extension";
746666
} else if (Ext.front() == 'z' || Ext.front() == 's' ||
747667
Ext.front() == 'x') {
748668
// Handle other types of extensions other than the standard
@@ -753,19 +673,49 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
753673
// These extensions start with 'z', 's', 'x' prefixes, might have a
754674
// version number (major, minor) and are separated by a single
755675
// underscore '_'. We do not enforce a canonical order for them.
756-
if (auto E = processMultiLetterExtension(
757-
Ext, SeenExtMap, IgnoreUnknown, EnableExperimentalExtension,
758-
ExperimentalExtensionVersionCheck))
759-
return std::move(E);
760-
// Multi-letter extension must be separate following extension with
761-
// underscore
762-
break;
676+
StringRef Type = getExtensionType(Ext);
677+
Desc = getExtensionTypeDesc(Ext);
678+
auto Pos = findLastNonVersionCharacter(Ext) + 1;
679+
Name = Ext.substr(0, Pos);
680+
Vers = Ext.substr(Pos);
681+
Ext = StringRef();
682+
683+
assert(!Type.empty() && "Empty type?");
684+
if (!IgnoreUnknown && Name.size() == Type.size())
685+
return createStringError(errc::invalid_argument,
686+
Desc + " name missing after '" + Type + "'");
763687
} else {
764688
// FIXME: Could it be ignored by IgnoreUnknown?
765689
return createStringError(errc::invalid_argument,
766690
"invalid standard user-level extension '" +
767691
Twine(Ext.front()) + "'");
768692
}
693+
694+
unsigned Major, Minor, ConsumeLength;
695+
if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
696+
EnableExperimentalExtension,
697+
ExperimentalExtensionVersionCheck)) {
698+
if (IgnoreUnknown) {
699+
consumeError(std::move(E));
700+
if (Name.size() == 1)
701+
Ext = Ext.substr(ConsumeLength);
702+
continue;
703+
}
704+
return E;
705+
}
706+
707+
if (Name.size() == 1)
708+
Ext = Ext.substr(ConsumeLength);
709+
710+
// Check if duplicated extension.
711+
if (!IgnoreUnknown && SeenExtMap.contains(Name.str()))
712+
return createStringError(errc::invalid_argument,
713+
"duplicated " + Desc + " '" + Name + "'");
714+
715+
if (IgnoreUnknown && !RISCVISAInfo::isSupportedExtension(Name))
716+
continue;
717+
718+
SeenExtMap[Name.str()] = {Major, Minor};
769719
} while (!Ext.empty());
770720
}
771721

0 commit comments

Comments
 (0)