Skip to content

Commit 6ffda03

Browse files
authored
merge main into amd-staging (#361)
2 parents 832dd1e + ad2718d commit 6ffda03

File tree

154 files changed

+11702
-726
lines changed

Some content is hidden

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

154 files changed

+11702
-726
lines changed

clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ namespace find_all_symbols {
1313

1414
const HeaderMapCollector::RegexHeaderMap *getSTLPostfixHeaderMap() {
1515
static const HeaderMapCollector::RegexHeaderMap STLPostfixHeaderMap = {
16+
{"include/__float_float.h$", "<cfloat>"},
17+
{"include/__float_header_macro.h$", "<cfloat>"},
18+
{"include/__float_infinity_nan.h$", "<cfloat>"},
1619
{"include/__stdarg___gnuc_va_list.h$", "<cstdarg>"},
1720
{"include/__stdarg___va_copy.h$", "<cstdarg>"},
1821
{"include/__stdarg_header_macro.h$", "<cstdarg>"},

clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace clang {
1616
namespace clangd {
1717
namespace {
1818
const std::pair<llvm::StringRef, llvm::StringRef> IncludeMappings[] = {
19+
{"include/__float_float.h", "<cfloat>"},
20+
{"include/__float_header_macro.h", "<cfloat>"},
21+
{"include/__float_infinity_nan.h", "<cfloat>"},
1922
{"include/__stdarg___gnuc_va_list.h", "<cstdarg>"},
2023
{"include/__stdarg___va_copy.h", "<cstdarg>"},
2124
{"include/__stdarg_header_macro.h", "<cstdarg>"},

clang/include/clang/AST/StmtOpenACC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,9 @@ class OpenACCAtomicConstruct final
821821
struct StmtInfo {
822822
const Expr *V;
823823
const Expr *X;
824+
// Listed as 'expr' in the standard, this is typically a generic expression
825+
// as a component.
826+
const Expr *RefExpr;
824827
// TODO: OpenACC: We should expand this as we're implementing the other
825828
// atomic construct kinds.
826829
};

clang/include/clang/Basic/BuiltinsX86.td

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ let Attributes = [Const, NoThrow, RequiredVectorWidth<128>] in {
123123
}
124124
}
125125

126-
let Features = "ssse3" in {
127-
def psignb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>)">;
128-
def psignw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
129-
def psignd128 : X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
130-
}
131-
132126
let Features = "ssse3", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWidth<128>] in {
127+
def psignb128
128+
: X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>)">;
129+
def psignw128
130+
: X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
131+
def psignd128
132+
: X86Builtin<"_Vector<4, int>(_Vector<4, int>, _Vector<4, int>)">;
133133
def pmulhrsw128 : X86Builtin<"_Vector<8, short>(_Vector<8, short>, _Vector<8, short>)">;
134134
def pmaddubsw128 : X86Builtin<"_Vector<8, short>(_Vector<16, char>, _Vector<16, char>)">;
135135
def pshufb128 : X86Builtin<"_Vector<16, char>(_Vector<16, char>, _Vector<16, char>)">;
@@ -603,10 +603,9 @@ let Features = "avx2", Attributes = [NoThrow, Const, RequiredVectorWidth<256>] i
603603
def mpsadbw256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>, _Constant char)">;
604604
def palignr256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, "
605605
"_Vector<32, char>, _Constant int)">;
606-
def psadbw256 : X86Builtin<"_Vector<4, long long int>(_Vector<32, char>, _Vector<32, char>)">;
607-
def psignb256 : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>)">;
608-
def psignw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
609-
def psignd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>)">;
606+
def psadbw256
607+
: X86Builtin<
608+
"_Vector<4, long long int>(_Vector<32, char>, _Vector<32, char>)">;
610609
def psllw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<8, short>)">;
611610
def pslldqi256_byteshift : X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Constant int)">;
612611
def pslld256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<4, int>)">;
@@ -677,7 +676,15 @@ let Features = "avx2", Attributes = [NoThrow, Const, Constexpr, RequiredVectorWi
677676
def phsubw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
678677
def phsubd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>)">;
679678
def phsubsw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
680-
679+
680+
def psignb256
681+
: X86Builtin<"_Vector<32, char>(_Vector<32, char>, _Vector<32, char>)">;
682+
def psignw256
683+
: X86Builtin<
684+
"_Vector<16, short>(_Vector<16, short>, _Vector<16, short>)">;
685+
def psignd256
686+
: X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Vector<8, int>)">;
687+
681688
def pshuflw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Constant int)">;
682689
def pshufhw256 : X86Builtin<"_Vector<16, short>(_Vector<16, short>, _Constant int)">;
683690
def pshufd256 : X86Builtin<"_Vector<8, int>(_Vector<8, int>, _Constant int)">;

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ def note_constexpr_assumption_failed : Note<
403403
def note_constexpr_countzeroes_zero : Note<
404404
"evaluation of %select{__builtin_elementwise_clzg|__builtin_elementwise_ctzg}0 "
405405
"with a zero value is undefined">;
406+
def note_constexpr_infer_alloc_token_type_inference_failed : Note<
407+
"could not infer allocation type for __builtin_infer_alloc_token">;
408+
def note_constexpr_infer_alloc_token_no_metadata : Note<
409+
"could not get token metadata for inferred type">;
410+
def note_constexpr_infer_alloc_token_stateful_mode : Note<
411+
"stateful alloc token mode not supported in constexpr">;
406412
def err_experimental_clang_interp_failed : Error<
407413
"the experimental clang interpreter failed to evaluate an expression">;
408414

clang/include/clang/Driver/CommonArgs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
8989
const JobAction &JA, const llvm::opt::ArgList &Args,
9090
const InputInfo &Output, const char *OutFile);
9191

92+
void addDTLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
93+
llvm::opt::ArgStringList &CmdArgs);
94+
9295
void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
9396
llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
9497
const InputInfoList &Inputs, bool IsThinLTO);

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
#include "InterpHelpers.h"
1313
#include "PrimType.h"
1414
#include "Program.h"
15+
#include "clang/AST/InferAlloc.h"
1516
#include "clang/AST/OSLog.h"
1617
#include "clang/AST/RecordLayout.h"
1718
#include "clang/Basic/Builtins.h"
1819
#include "clang/Basic/TargetBuiltins.h"
1920
#include "clang/Basic/TargetInfo.h"
2021
#include "llvm/ADT/StringExtras.h"
22+
#include "llvm/Support/AllocToken.h"
2123
#include "llvm/Support/ErrorHandling.h"
2224
#include "llvm/Support/SipHash.h"
2325

@@ -1307,6 +1309,45 @@ interp__builtin_ptrauth_string_discriminator(InterpState &S, CodePtr OpPC,
13071309
return true;
13081310
}
13091311

1312+
static bool interp__builtin_infer_alloc_token(InterpState &S, CodePtr OpPC,
1313+
const InterpFrame *Frame,
1314+
const CallExpr *Call) {
1315+
const ASTContext &ASTCtx = S.getASTContext();
1316+
uint64_t BitWidth = ASTCtx.getTypeSize(ASTCtx.getSizeType());
1317+
auto Mode =
1318+
ASTCtx.getLangOpts().AllocTokenMode.value_or(llvm::DefaultAllocTokenMode);
1319+
uint64_t MaxTokens =
1320+
ASTCtx.getLangOpts().AllocTokenMax.value_or(~0ULL >> (64 - BitWidth));
1321+
1322+
// We do not read any of the arguments; discard them.
1323+
for (int I = Call->getNumArgs() - 1; I >= 0; --I)
1324+
discard(S.Stk, *S.getContext().classify(Call->getArg(I)));
1325+
1326+
// Note: Type inference from a surrounding cast is not supported in
1327+
// constexpr evaluation.
1328+
QualType AllocType = infer_alloc::inferPossibleType(Call, ASTCtx, nullptr);
1329+
if (AllocType.isNull()) {
1330+
S.CCEDiag(Call,
1331+
diag::note_constexpr_infer_alloc_token_type_inference_failed);
1332+
return false;
1333+
}
1334+
1335+
auto ATMD = infer_alloc::getAllocTokenMetadata(AllocType, ASTCtx);
1336+
if (!ATMD) {
1337+
S.CCEDiag(Call, diag::note_constexpr_infer_alloc_token_no_metadata);
1338+
return false;
1339+
}
1340+
1341+
auto MaybeToken = llvm::getAllocToken(Mode, *ATMD, MaxTokens);
1342+
if (!MaybeToken) {
1343+
S.CCEDiag(Call, diag::note_constexpr_infer_alloc_token_stateful_mode);
1344+
return false;
1345+
}
1346+
1347+
pushInteger(S, llvm::APInt(BitWidth, *MaybeToken), ASTCtx.getSizeType());
1348+
return true;
1349+
}
1350+
13101351
static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
13111352
const InterpFrame *Frame,
13121353
const CallExpr *Call) {
@@ -3694,6 +3735,9 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
36943735
case Builtin::BI__builtin_ptrauth_string_discriminator:
36953736
return interp__builtin_ptrauth_string_discriminator(S, OpPC, Frame, Call);
36963737

3738+
case Builtin::BI__builtin_infer_alloc_token:
3739+
return interp__builtin_infer_alloc_token(S, OpPC, Frame, Call);
3740+
36973741
case Builtin::BI__noop:
36983742
pushInteger(S, 0, Call->getType());
36993743
return true;
@@ -3809,6 +3853,21 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
38093853
return interp__builtin_ia32_movmsk_op(S, OpPC, Call);
38103854
}
38113855

3856+
case X86::BI__builtin_ia32_psignb128:
3857+
case X86::BI__builtin_ia32_psignb256:
3858+
case X86::BI__builtin_ia32_psignw128:
3859+
case X86::BI__builtin_ia32_psignw256:
3860+
case X86::BI__builtin_ia32_psignd128:
3861+
case X86::BI__builtin_ia32_psignd256:
3862+
return interp__builtin_elementwise_int_binop(
3863+
S, OpPC, Call, [](const APInt &AElem, const APInt &BElem) {
3864+
if (BElem.isZero())
3865+
return APInt::getZero(AElem.getBitWidth());
3866+
if (BElem.isNegative())
3867+
return -AElem;
3868+
return AElem;
3869+
});
3870+
38123871
case clang::X86::BI__builtin_ia32_pavgb128:
38133872
case clang::X86::BI__builtin_ia32_pavgw128:
38143873
case clang::X86::BI__builtin_ia32_pavgb256:

clang/lib/AST/ExprConstant.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "clang/AST/CharUnits.h"
4545
#include "clang/AST/CurrentSourceLocExprScope.h"
4646
#include "clang/AST/Expr.h"
47+
#include "clang/AST/InferAlloc.h"
4748
#include "clang/AST/OSLog.h"
4849
#include "clang/AST/OptionalDiagnostic.h"
4950
#include "clang/AST/RecordLayout.h"
@@ -12312,6 +12313,20 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr *E) {
1231212313
return Success(APValue(ResultElements.data(), ResultElements.size()), E);
1231312314
}
1231412315

12316+
case X86::BI__builtin_ia32_psignb128:
12317+
case X86::BI__builtin_ia32_psignb256:
12318+
case X86::BI__builtin_ia32_psignw128:
12319+
case X86::BI__builtin_ia32_psignw256:
12320+
case X86::BI__builtin_ia32_psignd128:
12321+
case X86::BI__builtin_ia32_psignd256:
12322+
return EvaluateBinOpExpr([](const APInt &AElem, const APInt &BElem) {
12323+
if (BElem.isZero())
12324+
return APInt::getZero(AElem.getBitWidth());
12325+
if (BElem.isNegative())
12326+
return -AElem;
12327+
return AElem;
12328+
});
12329+
1231512330
case X86::BI__builtin_ia32_blendvpd:
1231612331
case X86::BI__builtin_ia32_blendvpd256:
1231712332
case X86::BI__builtin_ia32_blendvps:
@@ -14649,6 +14664,27 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
1464914664
return Success(Result, E);
1465014665
}
1465114666

14667+
case Builtin::BI__builtin_infer_alloc_token: {
14668+
// If we fail to infer a type, this fails to be a constant expression; this
14669+
// can be checked with __builtin_constant_p(...).
14670+
QualType AllocType = infer_alloc::inferPossibleType(E, Info.Ctx, nullptr);
14671+
if (AllocType.isNull())
14672+
return Error(
14673+
E, diag::note_constexpr_infer_alloc_token_type_inference_failed);
14674+
auto ATMD = infer_alloc::getAllocTokenMetadata(AllocType, Info.Ctx);
14675+
if (!ATMD)
14676+
return Error(E, diag::note_constexpr_infer_alloc_token_no_metadata);
14677+
auto Mode =
14678+
Info.getLangOpts().AllocTokenMode.value_or(llvm::DefaultAllocTokenMode);
14679+
uint64_t BitWidth = Info.Ctx.getTypeSize(Info.Ctx.getSizeType());
14680+
uint64_t MaxTokens =
14681+
Info.getLangOpts().AllocTokenMax.value_or(~0ULL >> (64 - BitWidth));
14682+
auto MaybeToken = llvm::getAllocToken(Mode, *ATMD, MaxTokens);
14683+
if (!MaybeToken)
14684+
return Error(E, diag::note_constexpr_infer_alloc_token_stateful_mode);
14685+
return Success(llvm::APInt(BitWidth, *MaybeToken), E);
14686+
}
14687+
1465214688
case Builtin::BI__builtin_ffs:
1465314689
case Builtin::BI__builtin_ffsl:
1465414690
case Builtin::BI__builtin_ffsll: {

clang/lib/AST/StmtOpenACC.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,18 @@ OpenACCAtomicConstruct *OpenACCAtomicConstruct::Create(
324324
return Inst;
325325
}
326326

327+
static std::pair<const Expr *, const Expr *> getBinaryOpArgs(const Expr *Op) {
328+
if (const auto *BO = dyn_cast<BinaryOperator>(Op)) {
329+
assert(BO->getOpcode() == BO_Assign);
330+
return {BO->getLHS(), BO->getRHS()};
331+
}
332+
333+
const auto *OO = cast<CXXOperatorCallExpr>(Op);
334+
assert(OO->getOperator() == OO_Equal);
335+
336+
return {OO->getArg(0), OO->getArg(1)};
337+
}
338+
327339
const OpenACCAtomicConstruct::StmtInfo
328340
OpenACCAtomicConstruct::getAssociatedStmtInfo() const {
329341
// This ends up being a vastly simplified version of SemaOpenACCAtomic, since
@@ -333,27 +345,35 @@ OpenACCAtomicConstruct::getAssociatedStmtInfo() const {
333345

334346
switch (AtomicKind) {
335347
case OpenACCAtomicKind::None:
336-
case OpenACCAtomicKind::Write:
337348
case OpenACCAtomicKind::Update:
338349
case OpenACCAtomicKind::Capture:
339-
assert(false && "Only 'read' has been implemented here");
350+
assert(false && "Only 'read'/'write' have been implemented here");
340351
return {};
341352
case OpenACCAtomicKind::Read: {
342353
// Read only supports the format 'v = x'; where both sides are a scalar
343354
// expression. This can come in 2 forms; BinaryOperator or
344355
// CXXOperatorCallExpr (rarely).
345-
const Expr *AssignExpr = cast<const Expr>(getAssociatedStmt());
346-
if (const auto *BO = dyn_cast<BinaryOperator>(AssignExpr)) {
347-
assert(BO->getOpcode() == BO_Assign);
348-
return {BO->getLHS()->IgnoreImpCasts(), BO->getRHS()->IgnoreImpCasts()};
349-
}
350-
351-
const auto *OO = cast<CXXOperatorCallExpr>(AssignExpr);
352-
assert(OO->getOperator() == OO_Equal);
353-
354-
return {OO->getArg(0)->IgnoreImpCasts(), OO->getArg(1)->IgnoreImpCasts()};
356+
std::pair<const Expr *, const Expr *> BinaryArgs =
357+
getBinaryOpArgs(cast<const Expr>(getAssociatedStmt()));
358+
// We want the L-value for each side, so we ignore implicit casts.
359+
return {BinaryArgs.first->IgnoreImpCasts(),
360+
BinaryArgs.second->IgnoreImpCasts(), /*expr=*/nullptr};
355361
}
362+
case OpenACCAtomicKind::Write: {
363+
// Write supports only the format 'x = expr', where the expression is scalar
364+
// type, and 'x' is a scalar l value. As above, this can come in 2 forms;
365+
// Binary Operator or CXXOperatorCallExpr.
366+
std::pair<const Expr *, const Expr *> BinaryArgs =
367+
getBinaryOpArgs(cast<const Expr>(getAssociatedStmt()));
368+
// We want the L-value for ONLY the X side, so we ignore implicit casts. For
369+
// the right side (the expr), we emit it as an r-value so we need to
370+
// maintain implicit casts.
371+
return {/*v=*/nullptr, BinaryArgs.first->IgnoreImpCasts(),
372+
BinaryArgs.second};
356373
}
374+
}
375+
376+
llvm_unreachable("unknown OpenACC atomic kind");
357377
}
358378

359379
OpenACCCacheConstruct *OpenACCCacheConstruct::CreateEmpty(const ASTContext &C,

0 commit comments

Comments
 (0)