Skip to content

Commit 1765d73

Browse files
committed
merge main into amd-staging
Change-Id: I0931f2df5f29d468d3c2674aba07eb67e889ecf5
2 parents 3f450c5 + 2a9208b commit 1765d73

File tree

160 files changed

+2656
-1580
lines changed

Some content is hidden

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

160 files changed

+2656
-1580
lines changed

bolt/include/bolt/Utils/Utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ std::string getEscapedName(const StringRef &Name);
4141
/// Return the unescaped name
4242
std::string getUnescapedName(const StringRef &Name);
4343

44+
/// Return a common part for a given \p Name wrt a given \p Suffixes list.
45+
/// Preserve the suffix if \p KeepSuffix is set, only dropping characters
46+
/// following it, otherwise drop the suffix as well.
47+
std::optional<StringRef> getCommonName(const StringRef Name, bool KeepSuffix,
48+
ArrayRef<StringRef> Suffixes);
4449
/// LTO-generated function names take a form:
4550
///
4651
/// <function_name>.lto_priv.<decimal_number>/...

bolt/lib/Rewrite/PseudoProbeRewriter.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "bolt/Rewrite/MetadataRewriter.h"
1515
#include "bolt/Rewrite/MetadataRewriters.h"
1616
#include "bolt/Utils/CommandLineOpts.h"
17+
#include "bolt/Utils/Utils.h"
1718
#include "llvm/IR/Function.h"
1819
#include "llvm/MC/MCPseudoProbe.h"
1920
#include "llvm/Support/CommandLine.h"
@@ -133,10 +134,19 @@ void PseudoProbeRewriter::parsePseudoProbe() {
133134

134135
MCPseudoProbeDecoder::Uint64Set GuidFilter;
135136
MCPseudoProbeDecoder::Uint64Map FuncStartAddrs;
137+
SmallVector<StringRef, 0> Suffixes(
138+
{".destroy", ".resume", ".llvm.", ".cold", ".warm"});
136139
for (const BinaryFunction *F : BC.getAllBinaryFunctions()) {
137140
for (const MCSymbol *Sym : F->getSymbols()) {
138-
FuncStartAddrs[Function::getGUID(NameResolver::restore(Sym->getName()))] =
139-
F->getAddress();
141+
StringRef SymName = Sym->getName();
142+
for (auto Name : {std::optional(NameResolver::restore(SymName)),
143+
getCommonName(SymName, false, Suffixes)}) {
144+
if (!Name)
145+
continue;
146+
SymName = *Name;
147+
uint64_t GUID = Function::getGUID(SymName);
148+
FuncStartAddrs[GUID] = F->getAddress();
149+
}
140150
}
141151
}
142152
Contents = PseudoProbeSection->getContents();
@@ -155,13 +165,25 @@ void PseudoProbeRewriter::parsePseudoProbe() {
155165
ProbeDecoder.printProbesForAllAddresses(outs());
156166
}
157167

158-
for (const auto &FuncDesc : ProbeDecoder.getGUID2FuncDescMap()) {
159-
uint64_t GUID = FuncDesc.FuncGUID;
160-
if (!FuncStartAddrs.contains(GUID))
161-
continue;
162-
BinaryFunction *BF = BC.getBinaryFunctionAtAddress(FuncStartAddrs[GUID]);
163-
assert(BF);
164-
BF->setGUID(GUID);
168+
const GUIDProbeFunctionMap &GUID2Func = ProbeDecoder.getGUID2FuncDescMap();
169+
// Checks GUID in GUID2Func and returns it if it's present or null otherwise.
170+
auto checkGUID = [&](StringRef SymName) -> uint64_t {
171+
uint64_t GUID = Function::getGUID(SymName);
172+
if (GUID2Func.find(GUID) == GUID2Func.end())
173+
return 0;
174+
return GUID;
175+
};
176+
for (BinaryFunction *F : BC.getAllBinaryFunctions()) {
177+
for (const MCSymbol *Sym : F->getSymbols()) {
178+
StringRef SymName = NameResolver::restore(Sym->getName());
179+
uint64_t GUID = checkGUID(SymName);
180+
std::optional<StringRef> CommonName =
181+
getCommonName(SymName, false, Suffixes);
182+
if (!GUID && CommonName)
183+
GUID = checkGUID(*CommonName);
184+
if (GUID)
185+
F->setGUID(GUID);
186+
}
165187
}
166188
}
167189

bolt/lib/Utils/Utils.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,21 @@ std::string getUnescapedName(const StringRef &Name) {
6666
return Output;
6767
}
6868

69-
std::optional<StringRef> getLTOCommonName(const StringRef Name) {
70-
for (StringRef Suffix : {".__uniq.", ".lto_priv.", ".constprop.", ".llvm."}) {
69+
std::optional<StringRef> getCommonName(const StringRef Name, bool KeepSuffix,
70+
ArrayRef<StringRef> Suffixes) {
71+
for (StringRef Suffix : Suffixes) {
7172
size_t LTOSuffixPos = Name.find(Suffix);
7273
if (LTOSuffixPos != StringRef::npos)
73-
return Name.substr(0, LTOSuffixPos + Suffix.size());
74+
return Name.substr(0, LTOSuffixPos + (KeepSuffix ? Suffix.size() : 0));
7475
}
7576
return std::nullopt;
7677
}
7778

79+
std::optional<StringRef> getLTOCommonName(const StringRef Name) {
80+
return getCommonName(Name, true,
81+
{".__uniq.", ".lto_priv.", ".constprop.", ".llvm."});
82+
}
83+
7884
std::optional<uint8_t> readDWARFExpressionTargetReg(StringRef ExprBytes) {
7985
uint8_t Opcode = ExprBytes[0];
8086
if (Opcode == dwarf::DW_CFA_def_cfa_expression)

clang/docs/RealtimeSanitizer.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,53 @@ non-zero exit code.
8383
#13 0x00010230dd64 in main main.cpp:9
8484
#14 0x0001958960dc (<unknown module>)
8585
#15 0x2f557ffffffffffc (<unknown module>)
86+
87+
Disabling
88+
---------
89+
90+
In some circumstances, you may want to suppress error reporting in a specific scope.
91+
92+
In C++, this is achieved via ``__rtsan::ScopedDisabler``. Within the scope where the ``ScopedDisabler`` object is instantiated, all sanitizer error reports are suppressed. This suppression applies to the current scope as well as all invoked functions, including any functions called transitively.
93+
94+
.. code-block:: c++
95+
96+
#include <sanitizer/rtsan_interface.h>
97+
98+
void process(const std::vector<float>& buffer) [[clang::nonblocking]] {
99+
{
100+
__rtsan::ScopedDisabler d;
101+
...
102+
}
103+
}
104+
105+
If RealtimeSanitizer is not enabled at compile time (i.e., the code is not compiled with the ``-fsanitize=realtime`` flag), the ``ScopedDisabler`` is compiled as a no-op.
106+
107+
In C, you can use the ``__rtsan_disable()`` and ``rtsan_enable()`` functions to manually disable and re-enable RealtimeSanitizer checks.
108+
109+
.. code-block:: c++
110+
111+
#include <sanitizer/rtsan_interface.h>
112+
113+
int process(const float* buffer) [[clang::nonblocking]]
114+
{
115+
{
116+
__rtsan_disable();
117+
118+
...
119+
120+
__rtsan_enable();
121+
}
122+
}
123+
124+
Each call to ``__rtsan_disable()`` must be paired with a subsequent call to ``__rtsan_enable()`` to restore normal sanitizer functionality. If a corresponding ``rtsan_enable()`` call is not made, the behavior is undefined.
125+
126+
Compile-time sanitizer detection
127+
--------------------------------
128+
129+
Clang provides the pre-processor macro ``__has_feature`` which may be used to detect if RealtimeSanitizer is enabled at compile-time.
130+
131+
.. code-block:: c++
132+
133+
#if defined(__has_feature) && __has_feature(realtime_sanitizer)
134+
...
135+
#endif

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ C++ Language Changes
108108
- Allow single element access of GCC vector/ext_vector_type object to be
109109
constant expression. Supports the `V.xyzw` syntax and other tidbits
110110
as seen in OpenCL. Selecting multiple elements is left as a future work.
111+
- Implement `CWG1815 <https://wg21.link/CWG1815>`_. Support lifetime extension
112+
of temporary created by aggregate initialization using a default member
113+
initializer.
111114

112115
- Accept C++26 user-defined ``static_assert`` messages in C++11 as an extension.
113116

clang/include/clang/Basic/BuiltinsWebAssembly.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f"
209209
TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "fp16")
210210
TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "n", "fp16")
211211
TARGET_BUILTIN(__builtin_wasm_splat_f16x8, "V8hf", "nc", "fp16")
212-
TARGET_BUILTIN(__builtin_wasm_extract_lane_f16x8, "fV8hi", "nc", "fp16")
213-
TARGET_BUILTIN(__builtin_wasm_replace_lane_f16x8, "V8hV8hif", "nc", "fp16")
212+
TARGET_BUILTIN(__builtin_wasm_extract_lane_f16x8, "fV8hIi", "nc", "fp16")
213+
TARGET_BUILTIN(__builtin_wasm_replace_lane_f16x8, "V8hV8hIif", "nc", "fp16")
214214

215215
// Reference Types builtins
216216
// Some builtins are custom type-checked - see 't' as part of the third argument,

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10165,13 +10165,6 @@ def warn_dangling_pointer_assignment : Warning<
1016510165
"will be destroyed at the end of the full-expression">,
1016610166
InGroup<DanglingAssignment>;
1016710167

10168-
def warn_unsupported_lifetime_extension : Warning<
10169-
"lifetime extension of "
10170-
"%select{temporary|backing array of initializer list}0 created "
10171-
"by aggregate initialization using a default member initializer "
10172-
"is not yet supported; lifetime of %select{temporary|backing array}0 "
10173-
"will end at the end of the full-expression">, InGroup<Dangling>;
10174-
1017510168
// For non-floating point, expressions of the form x == x or x != x
1017610169
// should result in a warning, since these always evaluate to a constant.
1017710170
// Array comparisons have similar warnings

clang/include/clang/Sema/Sema.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6407,6 +6407,9 @@ class Sema final : public SemaBase {
64076407
/// example, in a for-range initializer).
64086408
bool InLifetimeExtendingContext = false;
64096409

6410+
/// Whether we should rebuild CXXDefaultArgExpr and CXXDefaultInitExpr.
6411+
bool RebuildDefaultArgOrDefaultInit = false;
6412+
64106413
// When evaluating immediate functions in the initializer of a default
64116414
// argument or default member initializer, this is the declaration whose
64126415
// default initializer is being evaluated and the location of the call
@@ -7810,9 +7813,11 @@ class Sema final : public SemaBase {
78107813
}
78117814

78127815
bool isInLifetimeExtendingContext() const {
7813-
assert(!ExprEvalContexts.empty() &&
7814-
"Must be in an expression evaluation context");
7815-
return ExprEvalContexts.back().InLifetimeExtendingContext;
7816+
return currentEvaluationContext().InLifetimeExtendingContext;
7817+
}
7818+
7819+
bool needsRebuildOfDefaultArgOrInit() const {
7820+
return currentEvaluationContext().RebuildDefaultArgOrDefaultInit;
78167821
}
78177822

78187823
bool isCheckingDefaultArgumentOrInitializer() const {
@@ -7854,18 +7859,6 @@ class Sema final : public SemaBase {
78547859
return Res;
78557860
}
78567861

7857-
/// keepInLifetimeExtendingContext - Pull down InLifetimeExtendingContext
7858-
/// flag from previous context.
7859-
void keepInLifetimeExtendingContext() {
7860-
if (ExprEvalContexts.size() > 2 &&
7861-
parentEvaluationContext().InLifetimeExtendingContext) {
7862-
auto &LastRecord = ExprEvalContexts.back();
7863-
auto &PrevRecord = parentEvaluationContext();
7864-
LastRecord.InLifetimeExtendingContext =
7865-
PrevRecord.InLifetimeExtendingContext;
7866-
}
7867-
}
7868-
78697862
DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) {
78707863
return getDefaultedFunctionKind(FD).asComparison();
78717864
}

clang/lib/AST/Expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,7 +1924,6 @@ bool CastExpr::CastConsistency() const {
19241924
case CK_FixedPointToIntegral:
19251925
case CK_IntegralToFixedPoint:
19261926
case CK_MatrixCast:
1927-
case CK_HLSLVectorTruncation:
19281927
assert(!getType()->isBooleanType() && "unheralded conversion to bool");
19291928
goto CheckNoBasePath;
19301929

@@ -1945,6 +1944,7 @@ bool CastExpr::CastConsistency() const {
19451944
case CK_BuiltinFnToFnPtr:
19461945
case CK_FixedPointToBoolean:
19471946
case CK_HLSLArrayRValue:
1947+
case CK_HLSLVectorTruncation:
19481948
CheckNoBasePath:
19491949
assert(path_empty() && "Cast kind should not have a base path!");
19501950
break;

clang/lib/AST/ExprConstant.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10935,6 +10935,15 @@ bool VectorExprEvaluator::VisitCastExpr(const CastExpr *E) {
1093510935

1093610936
return true;
1093710937
}
10938+
case CK_HLSLVectorTruncation: {
10939+
APValue Val;
10940+
SmallVector<APValue, 4> Elements;
10941+
if (!EvaluateVector(SE, Val, Info))
10942+
return Error(E);
10943+
for (unsigned I = 0; I < NElts; I++)
10944+
Elements.push_back(Val.getVectorElt(I));
10945+
return Success(Elements, E);
10946+
}
1093810947
default:
1093910948
return ExprEvaluatorBaseTy::VisitCastExpr(E);
1094010949
}
@@ -14478,7 +14487,6 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
1447814487
case CK_FixedPointCast:
1447914488
case CK_IntegralToFixedPoint:
1448014489
case CK_MatrixCast:
14481-
case CK_HLSLVectorTruncation:
1448214490
llvm_unreachable("invalid cast kind for integral value");
1448314491

1448414492
case CK_BitCast:
@@ -14651,6 +14659,12 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
1465114659
return false;
1465214660
return Success(Value, E);
1465314661
}
14662+
case CK_HLSLVectorTruncation: {
14663+
APValue Val;
14664+
if (!EvaluateVector(SubExpr, Val, Info))
14665+
return Error(E);
14666+
return Success(Val.getVectorElt(0), E);
14667+
}
1465414668
}
1465514669

1465614670
llvm_unreachable("unknown cast resulting in integral value");
@@ -15177,6 +15191,12 @@ bool FloatExprEvaluator::VisitCastExpr(const CastExpr *E) {
1517715191
Result = V.getComplexFloatReal();
1517815192
return true;
1517915193
}
15194+
case CK_HLSLVectorTruncation: {
15195+
APValue Val;
15196+
if (!EvaluateVector(SubExpr, Val, Info))
15197+
return Error(E);
15198+
return Success(Val.getVectorElt(0), E);
15199+
}
1518015200
}
1518115201
}
1518215202

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,14 +2709,19 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
27092709
return CGF.CGM.createOpenCLIntToSamplerConversion(E, CGF);
27102710

27112711
case CK_HLSLVectorTruncation: {
2712-
assert(DestTy->isVectorType() && "Expected dest type to be vector type");
2712+
assert((DestTy->isVectorType() || DestTy->isBuiltinType()) &&
2713+
"Destination type must be a vector or builtin type.");
27132714
Value *Vec = Visit(const_cast<Expr *>(E));
2714-
SmallVector<int, 16> Mask;
2715-
unsigned NumElts = DestTy->castAs<VectorType>()->getNumElements();
2716-
for (unsigned I = 0; I != NumElts; ++I)
2717-
Mask.push_back(I);
2715+
if (auto *VecTy = DestTy->getAs<VectorType>()) {
2716+
SmallVector<int> Mask;
2717+
unsigned NumElts = VecTy->getNumElements();
2718+
for (unsigned I = 0; I != NumElts; ++I)
2719+
Mask.push_back(I);
27182720

2719-
return Builder.CreateShuffleVector(Vec, Mask, "trunc");
2721+
return Builder.CreateShuffleVector(Vec, Mask, "trunc");
2722+
}
2723+
llvm::Value *Zero = llvm::Constant::getNullValue(CGF.SizeTy);
2724+
return Builder.CreateExtractElement(Vec, Zero, "cast.vtrunc");
27202725
}
27212726

27222727
} // end of switch

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ bool AArch64SwiftABIInfo::isLegalVectorType(CharUnits VectorSize,
500500
bool AArch64ABIInfo::isHomogeneousAggregateBaseType(QualType Ty) const {
501501
// For the soft-float ABI variant, no types are considered to be homogeneous
502502
// aggregates.
503-
if (Kind == AArch64ABIKind::AAPCSSoft)
503+
if (isSoftFloat())
504504
return false;
505505

506506
// Homogeneous aggregates for AAPCS64 must have base types of a floating
@@ -555,8 +555,8 @@ RValue AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty,
555555
BaseTy = ArrTy->getElementType();
556556
NumRegs = ArrTy->getNumElements();
557557
}
558-
bool IsFPR = Kind != AArch64ABIKind::AAPCSSoft &&
559-
(BaseTy->isFloatingPointTy() || BaseTy->isVectorTy());
558+
bool IsFPR =
559+
!isSoftFloat() && (BaseTy->isFloatingPointTy() || BaseTy->isVectorTy());
560560

561561
// The AArch64 va_list type and handling is specified in the Procedure Call
562562
// Standard, section B.4:

clang/lib/Headers/wasm_simd128.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,18 +1888,17 @@ static __inline__ v128_t __FP16_FN_ATTRS wasm_f16x8_splat(float __a) {
18881888
return (v128_t)__builtin_wasm_splat_f16x8(__a);
18891889
}
18901890

1891-
static __inline__ float __FP16_FN_ATTRS wasm_f16x8_extract_lane(v128_t __a,
1892-
int __i)
1893-
__REQUIRE_CONSTANT(__i) {
1894-
return __builtin_wasm_extract_lane_f16x8((__f16x8)__a, __i);
1895-
}
1891+
#ifdef __wasm_fp16__
1892+
// TODO Replace the following macros with regular C functions and use normal
1893+
// target-independent vector code like the other replace/extract instructions.
18961894

1897-
static __inline__ v128_t __FP16_FN_ATTRS wasm_f16x8_replace_lane(v128_t __a,
1898-
int __i,
1899-
float __b)
1900-
__REQUIRE_CONSTANT(__i) {
1901-
return (v128_t)__builtin_wasm_replace_lane_f16x8((__f16x8)__a, __i, __b);
1902-
}
1895+
#define wasm_f16x8_extract_lane(__a, __i) \
1896+
(__builtin_wasm_extract_lane_f16x8((__f16x8)(__a), __i))
1897+
1898+
#define wasm_f16x8_replace_lane(__a, __i, __b) \
1899+
((v128_t)__builtin_wasm_replace_lane_f16x8((__f16x8)(__a), __i, __b))
1900+
1901+
#endif
19031902

19041903
static __inline__ v128_t __FP16_FN_ATTRS wasm_f16x8_abs(v128_t __a) {
19051904
return (v128_t)__builtin_wasm_abs_f16x8((__f16x8)__a);

clang/lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2509,8 +2509,9 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
25092509

25102510
// P2718R0 - Lifetime extension in range-based for loops.
25112511
if (getLangOpts().CPlusPlus23) {
2512-
auto &LastRecord = Actions.ExprEvalContexts.back();
2512+
auto &LastRecord = Actions.currentEvaluationContext();
25132513
LastRecord.InLifetimeExtendingContext = true;
2514+
LastRecord.RebuildDefaultArgOrDefaultInit = true;
25142515
}
25152516

25162517
if (getLangOpts().OpenMP)

0 commit comments

Comments
 (0)