Skip to content

Commit fd67e22

Browse files
committed
merge main into amd-staging
2 parents 63aeb06 + 58b5df0 commit fd67e22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+847
-219
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,23 @@ of different sizes and signs is forbidden in binary and ternary builtins.
818818
T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types
819819
matches the sign of x.
820820
T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types
821+
For floating point types, follows semantics of maxNum
822+
in IEEE 754-2008. See `LangRef
823+
<http://llvm.org/docs/LangRef.html#llvm-min-intrinsics-comparation>`_
824+
for the comparison.
821825
T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types
826+
For floating point types, follows semantics of minNum
827+
in IEEE 754-2008. See `LangRef
828+
<http://llvm.org/docs/LangRef.html#llvm-min-intrinsics-comparation>`_
829+
for the comparison.
830+
T __builtin_elementwise_maxnum(T x, T y) return x or y, whichever is larger. Follows IEEE 754-2008 floating point types
831+
semantics (maxNum) with +0.0>-0.0. See `LangRef
832+
<http://llvm.org/docs/LangRef.html#llvm-min-intrinsics-comparation>`_
833+
for the comparison.
834+
T __builtin_elementwise_minnum(T x, T y) return x or y, whichever is smaller. Follows IEEE 754-2008 floating point types
835+
semantics (minNum) with +0.0>-0.0. See `LangRef
836+
<http://llvm.org/docs/LangRef.html#llvm-min-intrinsics-comparation>`_
837+
for the comparison.
822838
T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types
823839
representable values for the signed/unsigned integer type.
824840
T __builtin_elementwise_sub_sat(T x, T y) return the difference of x and y, clamped to the range of integer types

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ Non-comprehensive list of changes in this release
191191
- Support parsing the `cc` operand modifier and alias it to the `c` modifier (#GH127719).
192192
- Added `__builtin_elementwise_exp10`.
193193
- For AMDPGU targets, added `__builtin_v_cvt_off_f32_i4` that maps to the `v_cvt_off_f32_i4` instruction.
194+
- Added `__builtin_elementwise_minnum` and `__builtin_elementwise_maxnum`.
194195

195196
New Compiler Flags
196197
------------------

clang/include/clang/Basic/Builtins.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,18 @@ def ElementwiseMin : Builtin {
13041304
let Prototype = "void(...)";
13051305
}
13061306

1307+
def ElementwiseMaxNum : Builtin {
1308+
let Spellings = ["__builtin_elementwise_maxnum"];
1309+
let Attributes = [NoThrow, Const, CustomTypeChecking];
1310+
let Prototype = "void(...)";
1311+
}
1312+
1313+
def ElementwiseMinNum : Builtin {
1314+
let Spellings = ["__builtin_elementwise_minnum"];
1315+
let Attributes = [NoThrow, Const, CustomTypeChecking];
1316+
let Prototype = "void(...)";
1317+
}
1318+
13071319
def ElementwiseMaximum : Builtin {
13081320
let Spellings = ["__builtin_elementwise_maximum"];
13091321
let Attributes = [NoThrow, Const, CustomTypeChecking];

clang/include/clang/Support/RISCVVIntrinsicUtils.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/ADT/BitmaskEnum.h"
14+
#include "llvm/ADT/Bitset.h"
1415
#include "llvm/ADT/SmallVector.h"
1516
#include "llvm/ADT/StringRef.h"
1617
#include <cstdint>
@@ -376,6 +377,8 @@ enum PolicyScheme : uint8_t {
376377
HasPolicyOperand,
377378
};
378379

380+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum PolicyScheme PS);
381+
379382
// TODO refactor RVVIntrinsic class design after support all intrinsic
380383
// combination. This represents an instantiation of an intrinsic with a
381384
// particular type and prototype
@@ -507,6 +510,23 @@ enum RVVRequire {
507510
RVV_REQ_NUM,
508511
};
509512

513+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum RVVRequire Require);
514+
515+
struct RequiredExtensionBits {
516+
llvm::Bitset<RVV_REQ_NUM> Bits;
517+
RequiredExtensionBits() {}
518+
RequiredExtensionBits(std::initializer_list<RVVRequire> Init) {
519+
for (auto I : Init)
520+
Bits.set(I);
521+
}
522+
523+
void set(unsigned I) { Bits.set(I); }
524+
bool operator[](unsigned I) const { return Bits[I]; }
525+
};
526+
527+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
528+
const RequiredExtensionBits &Exts);
529+
510530
// Raw RVV intrinsic info, used to expand later.
511531
// This struct is highly compact for minimized code size.
512532
struct RVVIntrinsicRecord {
@@ -518,7 +538,7 @@ struct RVVIntrinsicRecord {
518538
const char *OverloadedName;
519539

520540
// Required target features for this intrinsic.
521-
uint32_t RequiredExtensions[(RVV_REQ_NUM + 31) / 32];
541+
RequiredExtensionBits RequiredExtensions;
522542

523543
// Prototype for this intrinsic, index of RVVSignatureTable.
524544
uint16_t PrototypeIndex;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,6 +3818,22 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
38183818
return RValue::get(Result);
38193819
}
38203820

3821+
case Builtin::BI__builtin_elementwise_maxnum: {
3822+
Value *Op0 = EmitScalarExpr(E->getArg(0));
3823+
Value *Op1 = EmitScalarExpr(E->getArg(1));
3824+
Value *Result = Builder.CreateBinaryIntrinsic(llvm::Intrinsic::maxnum, Op0,
3825+
Op1, nullptr, "elt.maxnum");
3826+
return RValue::get(Result);
3827+
}
3828+
3829+
case Builtin::BI__builtin_elementwise_minnum: {
3830+
Value *Op0 = EmitScalarExpr(E->getArg(0));
3831+
Value *Op1 = EmitScalarExpr(E->getArg(1));
3832+
Value *Result = Builder.CreateBinaryIntrinsic(llvm::Intrinsic::minnum, Op0,
3833+
Op1, nullptr, "elt.minnum");
3834+
return RValue::get(Result);
3835+
}
3836+
38213837
case Builtin::BI__builtin_elementwise_maximum: {
38223838
Value *Op0 = EmitScalarExpr(E->getArg(0));
38233839
Value *Op1 = EmitScalarExpr(E->getArg(1));

clang/lib/Sema/SemaChecking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,8 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
27622762

27632763
// These builtins restrict the element type to floating point
27642764
// types only, and take in two arguments.
2765+
case Builtin::BI__builtin_elementwise_minnum:
2766+
case Builtin::BI__builtin_elementwise_maxnum:
27652767
case Builtin::BI__builtin_elementwise_minimum:
27662768
case Builtin::BI__builtin_elementwise_maximum:
27672769
case Builtin::BI__builtin_elementwise_atan2:

clang/lib/Sema/SemaRISCV.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
232232
for (auto &Record : Recs) {
233233
// Check requirements.
234234
if (llvm::any_of(FeatureCheckList, [&](const auto &Item) {
235-
return ((Record.RequiredExtensions[Item.second / 32] &
236-
(1U << (Item.second % 32))) != 0) &&
235+
return Record.RequiredExtensions[Item.second] &&
237236
!TI.hasFeature(Item.first);
238237
}))
239238
continue;

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,42 +1493,45 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
14931493
unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
14941494
RecordData::value_type Record[] = {MODULE_NAME};
14951495
Stream.EmitRecordWithBlob(AbbrevCode, Record, WritingModule->Name);
1496-
}
14971496

1498-
if (WritingModule && WritingModule->Directory) {
1499-
SmallString<128> BaseDir;
1500-
if (PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) {
1501-
// Use the current working directory as the base path for all inputs.
1502-
auto CWD = FileMgr.getOptionalDirectoryRef(".");
1503-
BaseDir.assign(CWD->getName());
1504-
} else {
1505-
BaseDir.assign(WritingModule->Directory->getName());
1506-
}
1507-
cleanPathForOutput(FileMgr, BaseDir);
1508-
1509-
// If the home of the module is the current working directory, then we
1510-
// want to pick up the cwd of the build process loading the module, not
1511-
// our cwd, when we load this module.
1512-
if (!PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd &&
1513-
(!PP.getHeaderSearchInfo()
1514-
.getHeaderSearchOpts()
1515-
.ModuleMapFileHomeIsCwd ||
1516-
WritingModule->Directory->getName() != ".")) {
1517-
// Module directory.
1518-
auto Abbrev = std::make_shared<BitCodeAbbrev>();
1519-
Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
1520-
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory
1521-
unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1497+
auto BaseDir = [&]() -> std::optional<SmallString<128>> {
1498+
if (PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd) {
1499+
// Use the current working directory as the base path for all inputs.
1500+
auto CWD = FileMgr.getOptionalDirectoryRef(".");
1501+
return CWD->getName();
1502+
}
1503+
if (WritingModule->Directory) {
1504+
return WritingModule->Directory->getName();
1505+
}
1506+
return std::nullopt;
1507+
}();
1508+
if (BaseDir) {
1509+
cleanPathForOutput(FileMgr, *BaseDir);
1510+
1511+
// If the home of the module is the current working directory, then we
1512+
// want to pick up the cwd of the build process loading the module, not
1513+
// our cwd, when we load this module.
1514+
if (!PP.getHeaderSearchInfo().getHeaderSearchOpts().ModuleFileHomeIsCwd &&
1515+
(!PP.getHeaderSearchInfo()
1516+
.getHeaderSearchOpts()
1517+
.ModuleMapFileHomeIsCwd ||
1518+
WritingModule->Directory->getName() != ".")) {
1519+
// Module directory.
1520+
auto Abbrev = std::make_shared<BitCodeAbbrev>();
1521+
Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
1522+
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory
1523+
unsigned AbbrevCode = Stream.EmitAbbrev(std::move(Abbrev));
1524+
1525+
RecordData::value_type Record[] = {MODULE_DIRECTORY};
1526+
Stream.EmitRecordWithBlob(AbbrevCode, Record, *BaseDir);
1527+
}
15221528

1523-
RecordData::value_type Record[] = {MODULE_DIRECTORY};
1524-
Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir);
1529+
// Write out all other paths relative to the base directory if possible.
1530+
BaseDirectory.assign(BaseDir->begin(), BaseDir->end());
1531+
} else if (!isysroot.empty()) {
1532+
// Write out paths relative to the sysroot if possible.
1533+
BaseDirectory = std::string(isysroot);
15251534
}
1526-
1527-
// Write out all other paths relative to the base directory if possible.
1528-
BaseDirectory.assign(BaseDir.begin(), BaseDir.end());
1529-
} else if (!isysroot.empty()) {
1530-
// Write out paths relative to the sysroot if possible.
1531-
BaseDirectory = std::string(isysroot);
15321535
}
15331536

15341537
// Module map file

clang/lib/Support/RISCVVIntrinsicUtils.cpp

Lines changed: 80 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,36 +1196,91 @@ SmallVector<PrototypeDescriptor> parsePrototypes(StringRef Prototypes) {
11961196
return PrototypeDescriptors;
11971197
}
11981198

1199+
#define STRINGIFY(NAME) \
1200+
case NAME: \
1201+
OS << #NAME; \
1202+
break;
1203+
1204+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum PolicyScheme PS) {
1205+
switch (PS) {
1206+
STRINGIFY(SchemeNone)
1207+
STRINGIFY(HasPassthruOperand)
1208+
STRINGIFY(HasPolicyOperand)
1209+
}
1210+
return OS;
1211+
}
1212+
1213+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, enum RVVRequire Require) {
1214+
switch (Require) {
1215+
STRINGIFY(RVV_REQ_RV64)
1216+
STRINGIFY(RVV_REQ_Zvfhmin)
1217+
STRINGIFY(RVV_REQ_Xsfvcp)
1218+
STRINGIFY(RVV_REQ_Xsfvfnrclipxfqf)
1219+
STRINGIFY(RVV_REQ_Xsfvfwmaccqqq)
1220+
STRINGIFY(RVV_REQ_Xsfvqmaccdod)
1221+
STRINGIFY(RVV_REQ_Xsfvqmaccqoq)
1222+
STRINGIFY(RVV_REQ_Zvbb)
1223+
STRINGIFY(RVV_REQ_Zvbc)
1224+
STRINGIFY(RVV_REQ_Zvkb)
1225+
STRINGIFY(RVV_REQ_Zvkg)
1226+
STRINGIFY(RVV_REQ_Zvkned)
1227+
STRINGIFY(RVV_REQ_Zvknha)
1228+
STRINGIFY(RVV_REQ_Zvknhb)
1229+
STRINGIFY(RVV_REQ_Zvksed)
1230+
STRINGIFY(RVV_REQ_Zvksh)
1231+
STRINGIFY(RVV_REQ_Zvfbfwma)
1232+
STRINGIFY(RVV_REQ_Zvfbfmin)
1233+
STRINGIFY(RVV_REQ_Zvfh)
1234+
STRINGIFY(RVV_REQ_Experimental)
1235+
default:
1236+
llvm_unreachable("Unsupported RVVRequire!");
1237+
break;
1238+
}
1239+
return OS;
1240+
}
1241+
1242+
#undef STRINGIFY
1243+
1244+
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
1245+
const RequiredExtensionBits &Exts) {
1246+
OS << "{";
1247+
ListSeparator LS;
1248+
for (unsigned I = 0; I < RVV_REQ_NUM; I++)
1249+
if (Exts[I])
1250+
OS << LS << static_cast<RVVRequire>(I);
1251+
OS << "}";
1252+
return OS;
1253+
}
1254+
11991255
raw_ostream &operator<<(raw_ostream &OS, const RVVIntrinsicRecord &Record) {
12001256
OS << "{";
1201-
OS << "\"" << Record.Name << "\",";
1257+
OS << "/*Name=*/\"" << Record.Name << "\", ";
12021258
if (Record.OverloadedName == nullptr ||
12031259
StringRef(Record.OverloadedName).empty())
1204-
OS << "nullptr,";
1260+
OS << "/*OverloadedName=*/nullptr, ";
12051261
else
1206-
OS << "\"" << Record.OverloadedName << "\",";
1207-
OS << "{";
1208-
for (uint32_t Exts : Record.RequiredExtensions)
1209-
OS << Exts << ',';
1210-
OS << "},";
1211-
OS << Record.PrototypeIndex << ",";
1212-
OS << Record.SuffixIndex << ",";
1213-
OS << Record.OverloadedSuffixIndex << ",";
1214-
OS << (int)Record.PrototypeLength << ",";
1215-
OS << (int)Record.SuffixLength << ",";
1216-
OS << (int)Record.OverloadedSuffixSize << ",";
1217-
OS << (int)Record.TypeRangeMask << ",";
1218-
OS << (int)Record.Log2LMULMask << ",";
1219-
OS << (int)Record.NF << ",";
1220-
OS << (int)Record.HasMasked << ",";
1221-
OS << (int)Record.HasVL << ",";
1222-
OS << (int)Record.HasMaskedOffOperand << ",";
1223-
OS << (int)Record.HasTailPolicy << ",";
1224-
OS << (int)Record.HasMaskPolicy << ",";
1225-
OS << (int)Record.HasFRMRoundModeOp << ",";
1226-
OS << (int)Record.IsTuple << ",";
1227-
OS << (int)Record.UnMaskedPolicyScheme << ",";
1228-
OS << (int)Record.MaskedPolicyScheme << ",";
1262+
OS << "/*OverloadedName=*/\"" << Record.OverloadedName << "\", ";
1263+
OS << "/*RequiredExtensions=*/" << Record.RequiredExtensions << ", ";
1264+
OS << "/*PrototypeIndex=*/" << Record.PrototypeIndex << ", ";
1265+
OS << "/*SuffixIndex=*/" << Record.SuffixIndex << ", ";
1266+
OS << "/*OverloadedSuffixIndex=*/" << Record.OverloadedSuffixIndex << ", ";
1267+
OS << "/*PrototypeLength=*/" << (int)Record.PrototypeLength << ", ";
1268+
OS << "/*SuffixLength=*/" << (int)Record.SuffixLength << ", ";
1269+
OS << "/*OverloadedSuffixSize=*/" << (int)Record.OverloadedSuffixSize << ", ";
1270+
OS << "/*TypeRangeMask=*/" << (int)Record.TypeRangeMask << ", ";
1271+
OS << "/*Log2LMULMask=*/" << (int)Record.Log2LMULMask << ", ";
1272+
OS << "/*NF=*/" << (int)Record.NF << ", ";
1273+
OS << "/*HasMasked=*/" << (int)Record.HasMasked << ", ";
1274+
OS << "/*HasVL=*/" << (int)Record.HasVL << ", ";
1275+
OS << "/*HasMaskedOffOperand=*/" << (int)Record.HasMaskedOffOperand << ", ";
1276+
OS << "/*HasTailPolicy=*/" << (int)Record.HasTailPolicy << ", ";
1277+
OS << "/*HasMaskPolicy=*/" << (int)Record.HasMaskPolicy << ", ";
1278+
OS << "/*HasFRMRoundModeOp=*/" << (int)Record.HasFRMRoundModeOp << ", ";
1279+
OS << "/*IsTuple=*/" << (int)Record.IsTuple << ", ";
1280+
OS << "/*UnMaskedPolicyScheme=*/" << (PolicyScheme)Record.UnMaskedPolicyScheme
1281+
<< ", ";
1282+
OS << "/*MaskedPolicyScheme=*/" << (PolicyScheme)Record.MaskedPolicyScheme
1283+
<< ", ";
12291284
OS << "},\n";
12301285
return OS;
12311286
}

0 commit comments

Comments
 (0)