Skip to content

Commit 58b8c0f

Browse files
authored
merge main into amd-staging (#3127)
2 parents 642c84c + 4b98576 commit 58b8c0f

562 files changed

Lines changed: 171005 additions & 91356 deletions

File tree

Some content is hidden

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

clang/docs/ReleaseNotes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
729729
crash when using it with `-fms-extensions` on other platforms. (#GH184318)
730730
- Fixed a compiler crash due to an unresolved overloaded function type when
731731
calling `__builtin_bit_cast`. (#GH200112)
732+
- Clang now SFINAE friendly when the ``__reference_meows_from_temporary`` builtins
733+
should SFINAE friendly when the 1st type is not a reference type. (#GH206524)
734+
732735

733736
#### Bug Fixes to Attribute Support
734737

clang/include/clang/APINotes/APINotesReader.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#define LLVM_CLANG_APINOTES_READER_H
1717

1818
#include "clang/APINotes/Types.h"
19+
#include "llvm/ADT/ArrayRef.h"
1920
#include "llvm/Support/Error.h"
2021
#include "llvm/Support/MemoryBuffer.h"
2122
#include "llvm/Support/VersionTuple.h"
2223
#include <memory>
24+
#include <optional>
2325

2426
namespace clang {
2527
namespace api_notes {
@@ -159,6 +161,13 @@ class APINotesReader {
159161
VersionedInfo<CXXMethodInfo> lookupCXXMethod(ContextID CtxID,
160162
llvm::StringRef Name);
161163

164+
/// Look for information regarding the given C++ method with an exact
165+
/// parameter selector. An empty parameter list uses an exact zero-parameter
166+
/// key, and a non-empty list uses an exact ordered parameter key.
167+
VersionedInfo<CXXMethodInfo>
168+
lookupCXXMethod(ContextID CtxID, llvm::StringRef Name,
169+
llvm::ArrayRef<llvm::StringRef> Parameters);
170+
162171
/// Look for information regarding the given global variable.
163172
///
164173
/// \param Name The name of the global variable.
@@ -177,6 +186,14 @@ class APINotesReader {
177186
lookupGlobalFunction(llvm::StringRef Name,
178187
std::optional<Context> Ctx = std::nullopt);
179188

189+
/// Look for information regarding the given global function with an exact
190+
/// parameter selector. An empty parameter list uses an exact zero-parameter
191+
/// key, and a non-empty list uses an exact ordered parameter key.
192+
VersionedInfo<GlobalFunctionInfo>
193+
lookupGlobalFunction(llvm::StringRef Name,
194+
llvm::ArrayRef<llvm::StringRef> Parameters,
195+
std::optional<Context> Ctx = std::nullopt);
196+
180197
/// Look for information regarding the given enumerator.
181198
///
182199
/// \param Name The name of the enumerator.
@@ -221,6 +238,20 @@ class APINotesReader {
221238
std::optional<ContextID>
222239
lookupNamespaceID(llvm::StringRef Name,
223240
std::optional<ContextID> ParentNamespaceID = std::nullopt);
241+
242+
private:
243+
VersionedInfo<CXXMethodInfo> lookupCXXMethodImpl(ContextID CtxID,
244+
llvm::StringRef Name);
245+
VersionedInfo<CXXMethodInfo>
246+
lookupCXXMethodImpl(ContextID CtxID, llvm::StringRef Name,
247+
llvm::ArrayRef<llvm::StringRef> Parameters);
248+
249+
VersionedInfo<GlobalFunctionInfo>
250+
lookupGlobalFunctionImpl(llvm::StringRef Name, std::optional<Context> Ctx);
251+
VersionedInfo<GlobalFunctionInfo>
252+
lookupGlobalFunctionImpl(llvm::StringRef Name,
253+
llvm::ArrayRef<llvm::StringRef> Parameters,
254+
std::optional<Context> Ctx);
224255
};
225256

226257
} // end namespace api_notes

clang/include/clang/APINotes/APINotesWriter.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
#define LLVM_CLANG_APINOTES_WRITER_H
1717

1818
#include "clang/APINotes/Types.h"
19+
#include "llvm/ADT/ArrayRef.h"
1920
#include "llvm/ADT/StringRef.h"
2021
#include "llvm/Support/VersionTuple.h"
2122
#include "llvm/Support/raw_ostream.h"
2223

2324
#include <memory>
25+
#include <optional>
2426

2527
namespace clang {
2628
class FileEntry;
@@ -86,6 +88,13 @@ class APINotesWriter {
8688
void addCXXMethod(ContextID CtxID, llvm::StringRef Name,
8789
const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion);
8890

91+
/// Add information about a C++ method with an exact parameter selector. An
92+
/// empty parameter list uses an exact zero-parameter key, and a non-empty
93+
/// list uses an exact ordered parameter key.
94+
void addCXXMethod(ContextID CtxID, llvm::StringRef Name,
95+
llvm::ArrayRef<llvm::StringRef> Parameters,
96+
const CXXMethodInfo &Info, llvm::VersionTuple SwiftVersion);
97+
8998
/// Add information about a specific C record field.
9099
///
91100
/// \param CtxID The context in which this field resides, i.e. a C/C++ tag.
@@ -110,6 +119,14 @@ class APINotesWriter {
110119
const GlobalFunctionInfo &Info,
111120
llvm::VersionTuple SwiftVersion);
112121

122+
/// Add information about a global function with an exact parameter selector.
123+
/// An empty parameter list uses an exact zero-parameter key, and a non-empty
124+
/// list uses an exact ordered parameter key.
125+
void addGlobalFunction(std::optional<Context> Ctx, llvm::StringRef Name,
126+
llvm::ArrayRef<llvm::StringRef> Parameters,
127+
const GlobalFunctionInfo &Info,
128+
llvm::VersionTuple SwiftVersion);
129+
113130
/// Add information about an enumerator.
114131
///
115132
/// \param Name The name of this enumerator.

clang/include/clang/Basic/BuiltinsRISCV.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,24 @@ def pabd_i16x4 : RISCVBuiltin<"_Vector<4, unsigned short>(_Vector<4, short>, _Ve
215215
def pabdu_u8x8 : RISCVBuiltin<"_Vector<8, unsigned char>(_Vector<8, unsigned char>, _Vector<8, unsigned char>)">;
216216
def pabdu_u16x4 : RISCVBuiltin<"_Vector<4, unsigned short>(_Vector<4, unsigned short>, _Vector<4, unsigned short>)">;
217217

218+
// Packed Reduction Sum (32-bit)
219+
def predsum_i8x4_i32 : RISCVBuiltin<"int(_Vector<4, signed char>, int)">;
220+
def predsumu_u8x4_u32 : RISCVBuiltin<"unsigned int(_Vector<4, unsigned char>, unsigned int)">;
221+
def predsum_i16x2_i32 : RISCVBuiltin<"int(_Vector<2, short>, int)">;
222+
def predsumu_u16x2_u32 : RISCVBuiltin<"unsigned int(_Vector<2, unsigned short>, unsigned int)">;
223+
224+
// Packed Reduction Sum (64-bit)
225+
def predsum_i8x8_i32 : RISCVBuiltin<"int(_Vector<8, signed char>, int)">;
226+
def predsumu_u8x8_u32 : RISCVBuiltin<"unsigned int(_Vector<8, unsigned char>, unsigned int)">;
227+
def predsum_i16x4_i32 : RISCVBuiltin<"int(_Vector<4, short>, int)">;
228+
def predsumu_u16x4_u32 : RISCVBuiltin<"unsigned int(_Vector<4, unsigned short>, unsigned int)">;
229+
def predsum_i8x8_i64 : RISCVBuiltin<"int64_t(_Vector<8, signed char>, int64_t)">;
230+
def predsumu_u8x8_u64 : RISCVBuiltin<"uint64_t(_Vector<8, unsigned char>, uint64_t)">;
231+
def predsum_i16x4_i64 : RISCVBuiltin<"int64_t(_Vector<4, short>, int64_t)">;
232+
def predsumu_u16x4_u64 : RISCVBuiltin<"uint64_t(_Vector<4, unsigned short>, uint64_t)">;
233+
def predsum_i32x2_i64 : RISCVBuiltin<"int64_t(_Vector<2, int>, int64_t)">;
234+
def predsumu_u32x2_u64 : RISCVBuiltin<"uint64_t(_Vector<2, unsigned int>, uint64_t)">;
235+
218236
} // Features = "experimental-p"
219237

220238
//===----------------------------------------------------------------------===//

clang/include/clang/CIR/CIRToCIRPasses.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ namespace cir {
3232
mlir::LogicalResult
3333
runCIRToCIRPasses(mlir::ModuleOp theModule, mlir::MLIRContext &mlirCtx,
3434
clang::ASTContext &astCtx, bool enableVerifier,
35-
bool enableIdiomRecognizer, bool enableCIRSimplify);
35+
bool enableIdiomRecognizer, bool enableCIRSimplify,
36+
bool enableLibOpt, llvm::StringRef libOptOptions);
3637

3738
} // namespace cir
3839

clang/include/clang/CIR/Dialect/Passes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ std::unique_ptr<Pass> createLoweringPreparePass(clang::ASTContext *astCtx);
3434
std::unique_ptr<Pass> createGotoSolverPass();
3535
std::unique_ptr<Pass> createIdiomRecognizerPass();
3636
std::unique_ptr<Pass> createIdiomRecognizerPass(clang::ASTContext *astCtx);
37+
std::unique_ptr<Pass> createLibOptPass();
38+
std::unique_ptr<Pass> createLibOptPass(clang::ASTContext *astCtx);
3739

3840
void populateCIRPreLoweringPasses(mlir::OpPassManager &pm);
3941

clang/include/clang/CIR/Dialect/Passes.td

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,18 @@ def IdiomRecognizer : Pass<"cir-idiom-recognizer", "mlir::ModuleOp"> {
195195
let dependentDialects = ["cir::CIRDialect"];
196196
}
197197

198+
def LibOpt : Pass<"cir-lib-opt"> {
199+
let summary = "Optimize C/C++ library calls";
200+
let description = [{
201+
This pass applies transformations on C/C++ standard library idioms,
202+
such as library function calls and structs raised to CIR operations
203+
using the `cir-idiom-recognize` pass.
204+
}];
205+
206+
let constructor = "mlir::createLibOptPass()";
207+
let dependentDialects = ["cir::CIRDialect"];
208+
}
209+
198210
def CallConvLowering : Pass<"cir-call-conv-lowering", "mlir::ModuleOp"> {
199211
let summary = "Lower CIR function signatures and call sites to match target ABI";
200212
let description = [{

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,14 @@ class FrontendOptions {
426426
LLVM_PREFERRED_TYPE(bool)
427427
unsigned ClangIREnableIdiomRecognizer : 1;
428428

429+
/// Enable ClangIR library optimization.
430+
/// Set when -fclangir-lib-opt or -fclangir-lib-opt= was passed.
431+
LLVM_PREFERRED_TYPE(bool)
432+
unsigned ClangIRLibOptEnabled : 1;
433+
434+
/// Options to control ClangIR library optimization
435+
std::string ClangIRLibOptOptions;
436+
429437
CodeCompleteOptions CodeCompleteOpts;
430438

431439
/// Specifies the output format of the AST.
@@ -560,7 +568,8 @@ class FrontendOptions {
560568
EmitPrettySymbolGraphs(false), GenReducedBMI(false),
561569
UseClangIRPipeline(false), ClangIRDisablePasses(false),
562570
ClangIRDisableCIRVerifier(false), ClangIREnableIdiomRecognizer(false),
563-
TimeTraceGranularity(500), TimeTraceVerbose(false) {}
571+
ClangIRLibOptEnabled(false), TimeTraceGranularity(500),
572+
TimeTraceVerbose(false) {}
564573

565574
/// getInputKindForExtension - Return the appropriate input kind for a file
566575
/// extension. For example, "c" would return Language::C.

clang/include/clang/Options/Options.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,6 +3411,16 @@ def clangir_enable_idiom_recognizer : Flag<["-"], "clangir-enable-idiom-recogniz
34113411
HelpText<"ClangIR: Enable Idiom Recognizer pass">,
34123412
MarshallingInfoFlag<FrontendOpts<"ClangIREnableIdiomRecognizer">>;
34133413

3414+
def clangir_lib_opt_EQ : Joined<["-"], "clangir-lib-opt=">,
3415+
Visibility<[ClangOption, CC1Option]>, Group<f_Group>, Values<"all">,
3416+
HelpText<"Enable C/C++ library based optimizations (with options)">,
3417+
MarshallingInfoString<FrontendOpts<"ClangIRLibOptOptions">>;
3418+
3419+
def clangir_lib_opt : Flag<["-"], "clangir-lib-opt">,
3420+
Visibility<[ClangOption, CC1Option]>, Group<f_Group>,
3421+
Alias<clangir_lib_opt_EQ>, AliasArgs<["all"]>,
3422+
HelpText<"Enable C/C++ library based optimizations">;
3423+
34143424
defm clangir : BoolFOption<"clangir",
34153425
FrontendOpts<"UseClangIRPipeline">, DefaultFalse,
34163426
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use the ClangIR pipeline to compile">,

clang/lib/APINotes/APINotesFormat.h

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
#define LLVM_CLANG_LIB_APINOTES_APINOTESFORMAT_H
1111

1212
#include "clang/APINotes/Types.h"
13+
#include "llvm/ADT/ArrayRef.h"
1314
#include "llvm/ADT/PointerEmbeddedInt.h"
15+
#include "llvm/ADT/SmallVector.h"
1416
#include "llvm/Bitcode/BitcodeConvenience.h"
1517

18+
#include <optional>
19+
1620
namespace clang {
1721
namespace api_notes {
1822
/// Magic number for API notes files.
@@ -24,8 +28,9 @@ const uint16_t VERSION_MAJOR = 0;
2428
/// API notes file minor version number.
2529
///
2630
/// When the format changes IN ANY WAY, this number should be incremented.
27-
const uint16_t VERSION_MINOR = 40; // 39 for BoundsSafety;
31+
const uint16_t VERSION_MINOR = 41; // 39 for BoundsSafety;
2832
// 40 for UnsafeBufferUsageAttr
33+
// 41 for FunctionTableKey parameters
2934

3035
const uint8_t kSwiftConforms = 1;
3136
const uint8_t kSwiftDoesNotConform = 2;
@@ -354,6 +359,91 @@ inline bool operator==(const SingleDeclTableKey &lhs,
354359
return lhs.parentContextID == rhs.parentContextID && lhs.nameID == rhs.nameID;
355360
}
356361

362+
/// A stored C or C++ function declaration, represented by the ID of its parent
363+
/// context, the name of the declaration, and optional exact parameter types.
364+
constexpr uint8_t FunctionKeyHasParameterSelector = 0x01;
365+
constexpr unsigned FunctionTableKeyBaseLength =
366+
sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint16_t);
367+
368+
struct FunctionTableKey {
369+
uint32_t parentContextID;
370+
uint32_t nameID;
371+
std::optional<llvm::SmallVector<IdentifierID, 2>> parameterTypeIDs;
372+
373+
FunctionTableKey() : parentContextID(-1), nameID(-1) {}
374+
375+
FunctionTableKey(uint32_t ParentContextID, uint32_t NameID)
376+
: parentContextID(ParentContextID), nameID(NameID) {}
377+
378+
FunctionTableKey(uint32_t ParentContextID, uint32_t NameID,
379+
const llvm::SmallVectorImpl<IdentifierID> &ParameterTypeIDs)
380+
: parentContextID(ParentContextID), nameID(NameID) {
381+
parameterTypeIDs.emplace(ParameterTypeIDs.begin(), ParameterTypeIDs.end());
382+
}
383+
384+
FunctionTableKey(std::optional<Context> ParentCtx, IdentifierID NameID)
385+
: parentContextID(ParentCtx ? ParentCtx->id.Value
386+
: static_cast<uint32_t>(-1)),
387+
nameID(NameID) {}
388+
389+
FunctionTableKey(std::optional<Context> ParentCtx, IdentifierID NameID,
390+
const llvm::SmallVectorImpl<IdentifierID> &ParameterTypeIDs)
391+
: parentContextID(ParentCtx ? ParentCtx->id.Value
392+
: static_cast<uint32_t>(-1)),
393+
nameID(NameID) {
394+
parameterTypeIDs.emplace(ParameterTypeIDs.begin(), ParameterTypeIDs.end());
395+
}
396+
397+
llvm::hash_code hashValue() const {
398+
auto Hash = llvm::hash_combine(parentContextID, nameID,
399+
static_cast<bool>(parameterTypeIDs));
400+
if (parameterTypeIDs) {
401+
Hash = llvm::hash_combine(Hash, parameterTypeIDs->size());
402+
for (IdentifierID TypeID : *parameterTypeIDs)
403+
Hash = llvm::hash_combine(Hash, static_cast<unsigned>(TypeID));
404+
}
405+
return Hash;
406+
}
407+
};
408+
409+
template <typename GetIdentifierFn>
410+
std::optional<FunctionTableKey>
411+
getFunctionKeyImpl(uint32_t ParentContextID, llvm::StringRef Name,
412+
GetIdentifierFn GetIdentifier) {
413+
std::optional<IdentifierID> NameID = GetIdentifier(Name);
414+
if (!NameID)
415+
return std::nullopt;
416+
417+
return FunctionTableKey(ParentContextID, *NameID);
418+
}
419+
420+
template <typename GetIdentifierFn>
421+
std::optional<FunctionTableKey>
422+
getFunctionKeyImpl(uint32_t ParentContextID, llvm::StringRef Name,
423+
llvm::ArrayRef<llvm::StringRef> Parameters,
424+
GetIdentifierFn GetIdentifier) {
425+
std::optional<IdentifierID> NameID = GetIdentifier(Name);
426+
if (!NameID)
427+
return std::nullopt;
428+
429+
llvm::SmallVector<IdentifierID, 2> ParameterTypeIDs;
430+
ParameterTypeIDs.reserve(Parameters.size());
431+
for (llvm::StringRef Parameter : Parameters) {
432+
std::optional<IdentifierID> ParameterID = GetIdentifier(Parameter);
433+
if (!ParameterID)
434+
return std::nullopt;
435+
ParameterTypeIDs.push_back(*ParameterID);
436+
}
437+
return FunctionTableKey(ParentContextID, *NameID, ParameterTypeIDs);
438+
}
439+
440+
inline bool operator==(const FunctionTableKey &lhs,
441+
const FunctionTableKey &rhs) {
442+
return lhs.parentContextID == rhs.parentContextID &&
443+
lhs.nameID == rhs.nameID &&
444+
lhs.parameterTypeIDs == rhs.parameterTypeIDs;
445+
}
446+
357447
} // namespace api_notes
358448
} // namespace clang
359449

@@ -401,6 +491,18 @@ template <> struct DenseMapInfo<clang::api_notes::SingleDeclTableKey> {
401491
}
402492
};
403493

494+
template <> struct DenseMapInfo<clang::api_notes::FunctionTableKey> {
495+
static unsigned
496+
getHashValue(const clang::api_notes::FunctionTableKey &value) {
497+
return value.hashValue();
498+
}
499+
500+
static bool isEqual(const clang::api_notes::FunctionTableKey &lhs,
501+
const clang::api_notes::FunctionTableKey &rhs) {
502+
return lhs == rhs;
503+
}
504+
};
505+
404506
} // namespace llvm
405507

406508
#endif

0 commit comments

Comments
 (0)