Skip to content

Commit b828378

Browse files
committed
merge main into amd-staging
Change-Id: Ied5da980c6e7acd5ef81b3de15be695263afab78
2 parents e816d80 + 833a174 commit b828378

File tree

190 files changed

+29854
-24661
lines changed

Some content is hidden

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

190 files changed

+29854
-24661
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -337,33 +337,34 @@ FileOptionsBaseProvider::FileOptionsBaseProvider(
337337
void FileOptionsBaseProvider::addRawFileOptions(
338338
llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
339339
auto CurSize = CurOptions.size();
340-
341340
// Look for a suitable configuration file in all parent directories of the
342341
// file. Start with the immediate parent directory and move up.
343-
StringRef Path = llvm::sys::path::parent_path(AbsolutePath);
344-
for (StringRef CurrentPath = Path; !CurrentPath.empty();
345-
CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
346-
std::optional<OptionsSource> Result;
347-
348-
auto Iter = CachedOptions.find(CurrentPath);
349-
if (Iter != CachedOptions.end())
350-
Result = Iter->second;
351-
352-
if (!Result)
353-
Result = tryReadConfigFile(CurrentPath);
354-
355-
if (Result) {
356-
// Store cached value for all intermediate directories.
357-
while (Path != CurrentPath) {
342+
StringRef RootPath = llvm::sys::path::parent_path(AbsolutePath);
343+
auto MemorizedConfigFile =
344+
[this, &RootPath](StringRef CurrentPath) -> std::optional<OptionsSource> {
345+
const auto Iter = CachedOptions.Memorized.find(CurrentPath);
346+
if (Iter != CachedOptions.Memorized.end())
347+
return CachedOptions.Storage[Iter->second];
348+
std::optional<OptionsSource> OptionsSource = tryReadConfigFile(CurrentPath);
349+
if (OptionsSource) {
350+
const size_t Index = CachedOptions.Storage.size();
351+
CachedOptions.Storage.emplace_back(OptionsSource.value());
352+
while (RootPath != CurrentPath) {
358353
LLVM_DEBUG(llvm::dbgs()
359-
<< "Caching configuration for path " << Path << ".\n");
360-
if (!CachedOptions.count(Path))
361-
CachedOptions[Path] = *Result;
362-
Path = llvm::sys::path::parent_path(Path);
354+
<< "Caching configuration for path " << RootPath << ".\n");
355+
CachedOptions.Memorized[RootPath] = Index;
356+
RootPath = llvm::sys::path::parent_path(RootPath);
363357
}
364-
CachedOptions[Path] = *Result;
365-
366-
CurOptions.push_back(*Result);
358+
CachedOptions.Memorized[CurrentPath] = Index;
359+
RootPath = llvm::sys::path::parent_path(CurrentPath);
360+
}
361+
return OptionsSource;
362+
};
363+
for (StringRef CurrentPath = RootPath; !CurrentPath.empty();
364+
CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
365+
if (std::optional<OptionsSource> Result =
366+
MemorizedConfigFile(CurrentPath)) {
367+
CurOptions.emplace_back(Result.value());
367368
if (!Result->first.InheritParentConfig.value_or(false))
368369
break;
369370
}

clang-tools-extra/clang-tidy/ClangTidyOptions.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
241241
/// \c ConfigHandlers.
242242
std::optional<OptionsSource> tryReadConfigFile(llvm::StringRef Directory);
243243

244-
llvm::StringMap<OptionsSource> CachedOptions;
244+
struct OptionsCache {
245+
llvm::StringMap<size_t> Memorized;
246+
llvm::SmallVector<OptionsSource, 4U> Storage;
247+
} CachedOptions;
245248
ClangTidyOptions OverrideOptions;
246249
ConfigFileHandlers ConfigHandlers;
247250
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,9 @@ Miscellaneous Clang Crashes Fixed
990990
- Fixed internal assertion firing when a declaration in the implicit global
991991
module is found through ADL. (GH#109879)
992992

993+
- Fixed a crash when an unscoped enumeration declared by an opaque-enum-declaration within a class template
994+
with a dependent underlying type is subject to integral promotion. (#GH117960)
995+
993996
OpenACC Specific Changes
994997
------------------------
995998

@@ -1114,6 +1117,12 @@ CUDA Support
11141117
- Clang now supports CUDA SDK up to 12.6
11151118
- Added support for sm_100
11161119
- Added support for `__grid_constant__` attribute.
1120+
- CUDA now uses the new offloading driver by default. The new driver supports
1121+
device-side LTO, interoperability with OpenMP and other languages, and native ``-fgpu-rdc``
1122+
support with static libraries. The old behavior can be returned using the
1123+
``--no-offload-new-driver`` flag. The binary format is no longer compatible
1124+
with the NVIDIA compiler's RDC-mode support. More information can be found at:
1125+
https://clang.llvm.org/docs/OffloadingDesign.html
11171126

11181127
AIX Support
11191128
^^^^^^^^^^^

clang/include/clang/Basic/Builtins.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4865,12 +4865,6 @@ def HLSLIsinf : LangBuiltin<"HLSL_LANG"> {
48654865
let Prototype = "void(...)";
48664866
}
48674867

4868-
def HLSLLength : LangBuiltin<"HLSL_LANG"> {
4869-
let Spellings = ["__builtin_hlsl_length"];
4870-
let Attributes = [NoThrow, Const];
4871-
let Prototype = "void(...)";
4872-
}
4873-
48744868
def HLSLLerp : LangBuiltin<"HLSL_LANG"> {
48754869
let Spellings = ["__builtin_hlsl_lerp"];
48764870
let Attributes = [NoThrow, Const];

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19331,20 +19331,6 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1933119331
/*ReturnType=*/X->getType(), CGM.getHLSLRuntime().getLerpIntrinsic(),
1933219332
ArrayRef<Value *>{X, Y, S}, nullptr, "hlsl.lerp");
1933319333
}
19334-
case Builtin::BI__builtin_hlsl_length: {
19335-
Value *X = EmitScalarExpr(E->getArg(0));
19336-
19337-
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
19338-
"length operand must have a float representation");
19339-
// if the operand is a scalar, we can use the fabs llvm intrinsic directly
19340-
if (!E->getArg(0)->getType()->isVectorType())
19341-
return EmitFAbs(*this, X);
19342-
19343-
return Builder.CreateIntrinsic(
19344-
/*ReturnType=*/X->getType()->getScalarType(),
19345-
CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef<Value *>{X},
19346-
nullptr, "hlsl.length");
19347-
}
1934819334
case Builtin::BI__builtin_hlsl_normalize: {
1934919335
Value *X = EmitScalarExpr(E->getArg(0));
1935019336

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ class CGHLSLRuntime {
7777
GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
7878
GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
7979
GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
80-
GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
8180
GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
8281
GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
8382
GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include "llvm/TargetParser/X86TargetParser.h"
7777
#include "llvm/Transforms/Utils/BuildLibCalls.h"
7878
#include <optional>
79+
#include <set>
7980

8081
using namespace clang;
8182
using namespace CodeGen;
@@ -2758,17 +2759,26 @@ bool CodeGenModule::GetCPUAndFeaturesAttributes(GlobalDecl GD,
27582759
Attrs.addAttribute("target-features", llvm::join(Features, ","));
27592760
AddedAttr = true;
27602761
}
2762+
// Add metadata for AArch64 Function Multi Versioning.
27612763
if (getTarget().getTriple().isAArch64()) {
27622764
llvm::SmallVector<StringRef, 8> Feats;
2763-
if (TV)
2765+
bool IsDefault = false;
2766+
if (TV) {
2767+
IsDefault = TV->isDefaultVersion();
27642768
TV->getFeatures(Feats);
2765-
else if (TC)
2769+
} else if (TC) {
2770+
IsDefault = TC->isDefaultVersion(GD.getMultiVersionIndex());
27662771
TC->getFeatures(Feats, GD.getMultiVersionIndex());
2767-
if (!Feats.empty()) {
2768-
llvm::sort(Feats);
2772+
}
2773+
if (IsDefault) {
2774+
Attrs.addAttribute("fmv-features");
2775+
AddedAttr = true;
2776+
} else if (!Feats.empty()) {
2777+
// Sort features and remove duplicates.
2778+
std::set<StringRef> OrderedFeats(Feats.begin(), Feats.end());
27692779
std::string FMVFeatures;
2770-
for (StringRef F : Feats)
2771-
FMVFeatures.append(",+" + F.str());
2780+
for (StringRef F : OrderedFeats)
2781+
FMVFeatures.append("," + F.str());
27722782
Attrs.addAttribute("fmv-features", FMVFeatures.substr(1));
27732783
AddedAttr = true;
27742784
}
@@ -2810,6 +2820,7 @@ void CodeGenModule::setNonAliasAttributes(GlobalDecl GD,
28102820
llvm::AttributeMask RemoveAttrs;
28112821
RemoveAttrs.addAttribute("target-cpu");
28122822
RemoveAttrs.addAttribute("target-features");
2823+
RemoveAttrs.addAttribute("fmv-features");
28132824
RemoveAttrs.addAttribute("tune-cpu");
28142825
F->removeFnAttrs(RemoveAttrs);
28152826
F->addFnAttrs(Attrs);

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4352,7 +4352,8 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43524352
Args.hasFlag(options::OPT_foffload_via_llvm,
43534353
options::OPT_fno_offload_via_llvm, false) ||
43544354
Args.hasFlag(options::OPT_offload_new_driver,
4355-
options::OPT_no_offload_new_driver, false);
4355+
options::OPT_no_offload_new_driver,
4356+
C.isOffloadingHostKind(Action::OFK_Cuda));
43564357

43574358
if (C.isOffloadingHostKind(Action::OFK_OpenMP) &&
43584359
Args.hasArg(options::OPT_offload_new_driver,
@@ -5123,7 +5124,8 @@ Action *Driver::ConstructPhaseAction(
51235124
offloadDeviceOnly() ||
51245125
(TargetDeviceOffloadKind == Action::OFK_HIP &&
51255126
!Args.hasFlag(options::OPT_offload_new_driver,
5126-
options::OPT_no_offload_new_driver, false)))
5127+
options::OPT_no_offload_new_driver,
5128+
C.isOffloadingHostKind(Action::OFK_Cuda))))
51275129
? types::TY_LLVM_IR
51285130
: types::TY_LLVM_BC;
51295131
return C.MakeAction<BackendJobAction>(Input, Output);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5148,7 +5148,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51485148
JA.isHostOffloading(Action::OFK_SYCL) ||
51495149
(JA.isHostOffloading(C.getActiveOffloadKinds()) &&
51505150
Args.hasFlag(options::OPT_offload_new_driver,
5151-
options::OPT_no_offload_new_driver, false));
5151+
options::OPT_no_offload_new_driver,
5152+
C.isOffloadingHostKind(Action::OFK_Cuda)));
51525153

51535154
bool IsRDCMode =
51545155
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
@@ -5504,7 +5505,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
55045505
CmdArgs.push_back("-emit-llvm-uselists");
55055506

55065507
if (IsUsingLTO) {
5507-
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) && !Triple.isAMDGPU()) {
5508+
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
5509+
!Args.hasFlag(options::OPT_offload_new_driver,
5510+
options::OPT_no_offload_new_driver,
5511+
C.isOffloadingHostKind(Action::OFK_Cuda)) &&
5512+
!Triple.isAMDGPU()) {
55085513
D.Diag(diag::err_drv_unsupported_opt_for_target)
55095514
<< Args.getLastArg(options::OPT_foffload_lto,
55105515
options::OPT_foffload_lto_EQ)
@@ -7062,7 +7067,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
70627067
options::OPT_fno_offload_via_llvm, false)) {
70637068
CmdArgs.append({"--offload-new-driver", "-foffload-via-llvm"});
70647069
} else if (Args.hasFlag(options::OPT_offload_new_driver,
7065-
options::OPT_no_offload_new_driver, false)) {
7070+
options::OPT_no_offload_new_driver,
7071+
C.isOffloadingHostKind(Action::OFK_Cuda))) {
70667072
CmdArgs.push_back("--offload-new-driver");
70677073
}
70687074

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
510510
static bool shouldIncludePTX(const ArgList &Args, StringRef InputArch) {
511511
// The new driver does not include PTX by default to avoid overhead.
512512
bool includePTX = !Args.hasFlag(options::OPT_offload_new_driver,
513-
options::OPT_no_offload_new_driver, false);
513+
options::OPT_no_offload_new_driver, true);
514514
for (Arg *A : Args.filtered(options::OPT_cuda_include_ptx_EQ,
515515
options::OPT_no_cuda_include_ptx_EQ)) {
516516
A->claim();

clang/lib/Driver/ToolChains/SPIRV.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class LLVM_LIBRARY_VISIBILITY Translator : public Tool {
4343

4444
class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
4545
public:
46-
Linker(const ToolChain &TC) : Tool("SPIRV::Linker", "spirv-link", TC) {}
46+
Linker(const ToolChain &TC) : Tool("SPIR-V::Linker", "spirv-link", TC) {}
4747
bool hasIntegratedCPP() const override { return false; }
4848
bool isLinkJob() const override { return true; }
4949
void ConstructJob(Compilation &C, const JobAction &JA,
@@ -54,7 +54,7 @@ class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
5454

5555
class LLVM_LIBRARY_VISIBILITY Assembler final : public Tool {
5656
public:
57-
Assembler(const ToolChain &TC) : Tool("SPIRV::Assembler", "spirv-as", TC) {}
57+
Assembler(const ToolChain &TC) : Tool("SPIR-V::Assembler", "spirv-as", TC) {}
5858
bool hasIntegratedAssembler() const override { return false; }
5959
bool hasIntegratedCPP() const override { return false; }
6060
void ConstructJob(Compilation &C, const JobAction &JA,

clang/lib/Headers/amxintrin.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,15 @@ typedef int _tile1024i_1024a
234234
__attribute__((__vector_size__(1024), __aligned__(1024)));
235235

236236
/// This is internal intrinsic. C/C++ user should avoid calling it directly.
237-
static __inline__ _tile1024i __DEFAULT_FN_ATTRS_INT8
237+
static __inline__ _tile1024i __DEFAULT_FN_ATTRS_TILE
238238
_tile_loadd_internal(unsigned short m, unsigned short n, const void *base,
239239
__SIZE_TYPE__ stride) {
240240
return __builtin_ia32_tileloadd64_internal(m, n, base,
241241
(__SIZE_TYPE__)(stride));
242242
}
243243

244244
/// This is internal intrinsic. C/C++ user should avoid calling it directly.
245-
static __inline__ _tile1024i __DEFAULT_FN_ATTRS_INT8
245+
static __inline__ _tile1024i __DEFAULT_FN_ATTRS_TILE
246246
_tile_loaddt1_internal(unsigned short m, unsigned short n, const void *base,
247247
__SIZE_TYPE__ stride) {
248248
return __builtin_ia32_tileloaddt164_internal(m, n, base,
@@ -278,7 +278,7 @@ _tile_dpbuud_internal(unsigned short m, unsigned short n, unsigned short k,
278278
}
279279

280280
/// This is internal intrinsic. C/C++ user should avoid calling it directly.
281-
static __inline__ void __DEFAULT_FN_ATTRS_INT8
281+
static __inline__ void __DEFAULT_FN_ATTRS_TILE
282282
_tile_stored_internal(unsigned short m, unsigned short n, void *base,
283283
__SIZE_TYPE__ stride, _tile1024i tile) {
284284
return __builtin_ia32_tilestored64_internal(m, n, base,

clang/lib/Headers/hlsl/hlsl_detail.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ namespace hlsl {
1313

1414
namespace __detail {
1515

16+
template <typename T, typename U> struct is_same {
17+
static const bool value = false;
18+
};
19+
20+
template <typename T> struct is_same<T, T> {
21+
static const bool value = true;
22+
};
23+
1624
template <bool B, typename T> struct enable_if {};
1725

1826
template <typename T> struct enable_if<true, T> {
@@ -33,6 +41,18 @@ constexpr enable_if_t<sizeof(U) == sizeof(T), U> bit_cast(T F) {
3341
return __builtin_bit_cast(U, F);
3442
}
3543

44+
template <typename T>
45+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
46+
length_impl(T X) {
47+
return __builtin_elementwise_abs(X);
48+
}
49+
50+
template <typename T, int N>
51+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
52+
length_vec_impl(vector<T, N> X) {
53+
return __builtin_elementwise_sqrt(__builtin_hlsl_dot(X, X));
54+
}
55+
3656
} // namespace __detail
3757
} // namespace hlsl
3858
#endif //_HLSL_HLSL_DETAILS_H_

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,26 +1298,18 @@ float4 lerp(float4, float4, float4);
12981298
/// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
12991299

13001300
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1301-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1302-
half length(half);
1303-
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1304-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1305-
half length(half2);
1306-
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1307-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1308-
half length(half3);
1309-
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1310-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1311-
half length(half4);
1312-
1313-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1314-
float length(float);
1315-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1316-
float length(float2);
1317-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1318-
float length(float3);
1319-
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_length)
1320-
float length(float4);
1301+
const inline half length(half X) { return __detail::length_impl(X); }
1302+
const inline float length(float X) { return __detail::length_impl(X); }
1303+
1304+
template <int N>
1305+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
1306+
const inline half length(vector<half, N> X) {
1307+
return __detail::length_vec_impl(X);
1308+
}
1309+
1310+
template <int N> const inline float length(vector<float, N> X) {
1311+
return __detail::length_vec_impl(X);
1312+
}
13211313

13221314
//===----------------------------------------------------------------------===//
13231315
// log builtins

clang/lib/Parse/ParseDecl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3706,8 +3706,14 @@ void Parser::ParseDeclarationSpecifiers(
37063706
if (PA.isTypeAttr() && PA.getKind() != ParsedAttr::AT_LifetimeBound &&
37073707
PA.getKind() != ParsedAttr::AT_AnyX86NoCfCheck)
37083708
continue;
3709-
Diag(PA.getLoc(), diag::err_attribute_not_type_attr)
3710-
<< PA << PA.isRegularKeywordAttribute();
3709+
3710+
if (PA.getKind() == ParsedAttr::AT_LifetimeBound)
3711+
Diag(PA.getLoc(), diag::err_attribute_wrong_decl_type_str)
3712+
<< PA << PA.isRegularKeywordAttribute()
3713+
<< "parameters and implicit object parameters";
3714+
else
3715+
Diag(PA.getLoc(), diag::err_attribute_not_type_attr)
3716+
<< PA << PA.isRegularKeywordAttribute();
37113717
PA.setInvalid();
37123718
}
37133719

0 commit comments

Comments
 (0)