Skip to content

Commit c0bf19d

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-to-uniform-transforms
2 parents cd4b3bf + ad6bb70 commit c0bf19d

File tree

145 files changed

+3203
-1336
lines changed

Some content is hidden

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

145 files changed

+3203
-1336
lines changed

clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ bool MagicNumbersCheck::isIgnoredValue(const IntegerLiteral *Literal) const {
202202
if (IgnorePowersOf2IntegerValues && IntValue.isPowerOf2())
203203
return true;
204204

205-
return std::binary_search(IgnoredIntegerValues.begin(),
206-
IgnoredIntegerValues.end(), Value);
205+
return llvm::binary_search(IgnoredIntegerValues, Value);
207206
}
208207

209208
bool MagicNumbersCheck::isIgnoredValue(const FloatingLiteral *Literal) const {
@@ -213,14 +212,12 @@ bool MagicNumbersCheck::isIgnoredValue(const FloatingLiteral *Literal) const {
213212

214213
if (&FloatValue.getSemantics() == &llvm::APFloat::IEEEsingle()) {
215214
const float Value = FloatValue.convertToFloat();
216-
return std::binary_search(IgnoredFloatingPointValues.begin(),
217-
IgnoredFloatingPointValues.end(), Value);
215+
return llvm::binary_search(IgnoredFloatingPointValues, Value);
218216
}
219217

220218
if (&FloatValue.getSemantics() == &llvm::APFloat::IEEEdouble()) {
221219
const double Value = FloatValue.convertToDouble();
222-
return std::binary_search(IgnoredDoublePointValues.begin(),
223-
IgnoredDoublePointValues.end(), Value);
220+
return llvm::binary_search(IgnoredDoublePointValues, Value);
224221
}
225222

226223
return false;

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ New Compiler Flags
313313

314314
- New option ``-ftime-report-json`` added which outputs the same timing data as ``-ftime-report`` but formatted as JSON.
315315

316+
- New option ``-Wnrvo`` added and disabled by default to warn about missed NRVO opportunites.
317+
316318
Deprecated Compiler Flags
317319
-------------------------
318320

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12445,6 +12445,10 @@ def warn_zero_as_null_pointer_constant : Warning<
1244512445
"zero as null pointer constant">,
1244612446
InGroup<DiagGroup<"zero-as-null-pointer-constant">>, DefaultIgnore;
1244712447

12448+
def warn_not_eliding_copy_on_return : Warning<
12449+
"not eliding copy on return">,
12450+
InGroup<DiagGroup<"nrvo">>, DefaultIgnore;
12451+
1244812452
def err_nullability_cs_multilevel : Error<
1244912453
"nullability keyword %0 cannot be applied to multi-level pointer type %1">;
1245012454
def note_nullability_type_specifier : Note<

clang/include/clang/Basic/JsonSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ inline void printSourceLocationAsJson(raw_ostream &Out, SourceLocation Loc,
106106
return llvm::is_contained(ForbiddenChars, Char);
107107
});
108108
// Handle windows-specific path delimiters.
109-
std::replace(filename.begin(), filename.end(), '\\', '/');
109+
llvm::replace(filename, '\\', '/');
110110
}
111111
Out << "\"line\": " << PLoc.getLine()
112112
<< ", \"column\": " << PLoc.getColumn()

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,52 @@ def SwitchOp : CIR_Op<"switch",
971971
}];
972972
}
973973

974+
//===----------------------------------------------------------------------===//
975+
// SwitchFlatOp
976+
//===----------------------------------------------------------------------===//
977+
978+
def SwitchFlatOp : CIR_Op<"switch.flat", [AttrSizedOperandSegments,
979+
Terminator]> {
980+
981+
let description = [{
982+
The `cir.switch.flat` operation is a region-less and simplified
983+
version of the `cir.switch`.
984+
Its representation is closer to LLVM IR dialect
985+
than the C/C++ language feature.
986+
}];
987+
988+
let arguments = (ins
989+
CIR_IntType:$condition,
990+
Variadic<AnyType>:$defaultOperands,
991+
VariadicOfVariadic<AnyType, "case_operand_segments">:$caseOperands,
992+
ArrayAttr:$caseValues,
993+
DenseI32ArrayAttr:$case_operand_segments
994+
);
995+
996+
let successors = (successor
997+
AnySuccessor:$defaultDestination,
998+
VariadicSuccessor<AnySuccessor>:$caseDestinations
999+
);
1000+
1001+
let assemblyFormat = [{
1002+
$condition `:` type($condition) `,`
1003+
$defaultDestination (`(` $defaultOperands^ `:` type($defaultOperands) `)`)?
1004+
custom<SwitchFlatOpCases>(ref(type($condition)), $caseValues,
1005+
$caseDestinations, $caseOperands,
1006+
type($caseOperands))
1007+
attr-dict
1008+
}];
1009+
1010+
let builders = [
1011+
OpBuilder<(ins "mlir::Value":$condition,
1012+
"mlir::Block *":$defaultDestination,
1013+
"mlir::ValueRange":$defaultOperands,
1014+
CArg<"llvm::ArrayRef<llvm::APInt>", "{}">:$caseValues,
1015+
CArg<"mlir::BlockRange", "{}">:$caseDestinations,
1016+
CArg<"llvm::ArrayRef<mlir::ValueRange>", "{}">:$caseOperands)>
1017+
];
1018+
}
1019+
9741020
//===----------------------------------------------------------------------===//
9751021
// BrOp
9761022
//===----------------------------------------------------------------------===//

clang/include/clang/Sema/Overload.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ class Sema;
435435

436436
// A function pointer type can be resolved to a member function type,
437437
// which is still an identity conversion.
438-
if (auto *N = T->getAs<MemberPointerType>())
438+
if (auto *N = T->getAs<MemberPointerType>();
439+
N && N->isMemberFunctionPointer())
439440
T = C.getDecayedType(N->getPointeeType());
440441
return T;
441442
};

clang/lib/Basic/Diagnostic.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,24 +533,28 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
533533
// Drop the default section introduced by special case list, we only support
534534
// exact diagnostic group names.
535535
// FIXME: We should make this configurable in the parser instead.
536-
Sections.erase("*");
536+
// FIXME: C++20 can use std::erase_if(Sections, [](Section &sec) { return
537+
// sec.SectionStr == "*"; });
538+
Sections.erase(
539+
std::remove_if(Sections.begin(), Sections.end(),
540+
[](Section &sec) { return sec.SectionStr == "*"; }),
541+
Sections.end());
537542
// Make sure we iterate sections by their line numbers.
538-
std::vector<std::pair<unsigned, const llvm::StringMapEntry<Section> *>>
539-
LineAndSectionEntry;
543+
std::vector<std::pair<unsigned, const Section *>> LineAndSectionEntry;
540544
LineAndSectionEntry.reserve(Sections.size());
541545
for (const auto &Entry : Sections) {
542-
StringRef DiagName = Entry.getKey();
546+
StringRef DiagName = Entry.SectionStr;
543547
// Each section has a matcher with that section's name, attached to that
544548
// line.
545-
const auto &DiagSectionMatcher = Entry.getValue().SectionMatcher;
549+
const auto &DiagSectionMatcher = Entry.SectionMatcher;
546550
unsigned DiagLine = DiagSectionMatcher->Globs.at(DiagName).second;
547551
LineAndSectionEntry.emplace_back(DiagLine, &Entry);
548552
}
549553
llvm::sort(LineAndSectionEntry);
550554
static constexpr auto WarningFlavor = clang::diag::Flavor::WarningOrError;
551555
for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
552556
SmallVector<diag::kind> GroupDiags;
553-
StringRef DiagGroup = SectionEntry->getKey();
557+
StringRef DiagGroup = SectionEntry->SectionStr;
554558
if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(
555559
WarningFlavor, DiagGroup, GroupDiags)) {
556560
StringRef Suggestion =
@@ -563,7 +567,7 @@ void WarningsSpecialCaseList::processSections(DiagnosticsEngine &Diags) {
563567
for (diag::kind Diag : GroupDiags)
564568
// We're intentionally overwriting any previous mappings here to make sure
565569
// latest one takes precedence.
566-
DiagToSection[Diag] = &SectionEntry->getValue();
570+
DiagToSection[Diag] = SectionEntry;
567571
}
568572
}
569573

clang/lib/Basic/ProfileList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ProfileSpecialCaseList : public llvm::SpecialCaseList {
3737

3838
bool hasPrefix(StringRef Prefix) const {
3939
for (const auto &It : Sections)
40-
if (It.second.Entries.count(Prefix) > 0)
40+
if (It.Entries.count(Prefix) > 0)
4141
return true;
4242
return false;
4343
}

clang/lib/Basic/SanitizerSpecialCaseList.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ SanitizerSpecialCaseList::createOrDie(const std::vector<std::string> &Paths,
3737
}
3838

3939
void SanitizerSpecialCaseList::createSanitizerSections() {
40-
for (auto &It : Sections) {
41-
auto &S = It.second;
40+
for (auto &S : Sections) {
4241
SanitizerMask Mask;
4342

4443
#define SANITIZER(NAME, ID) \

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
310310
// e.g. gfx10-1-generic -> gfx10_1_generic
311311
if (GPUKind >= llvm::AMDGPU::GK_AMDGCN_GENERIC_FIRST &&
312312
GPUKind <= llvm::AMDGPU::GK_AMDGCN_GENERIC_LAST) {
313-
std::replace(CanonName.begin(), CanonName.end(), '-', '_');
313+
llvm::replace(CanonName, '-', '_');
314314
}
315315

316316
Builder.defineMacro(Twine("__") + Twine(CanonName) + Twine("__"));
@@ -329,7 +329,7 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
329329
auto Loc = OffloadArchFeatures.find(F);
330330
if (Loc != OffloadArchFeatures.end()) {
331331
std::string NewF = F.str();
332-
std::replace(NewF.begin(), NewF.end(), '-', '_');
332+
llvm::replace(NewF, '-', '_');
333333
Builder.defineMacro(Twine("__amdgcn_feature_") + Twine(NewF) +
334334
Twine("__"),
335335
Loc->second ? "1" : "0");

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@ CIRGenFunctionInfo::create(CanQualType resultType,
4444

4545
cir::FuncType CIRGenTypes::getFunctionType(const CIRGenFunctionInfo &fi) {
4646
mlir::Type resultType = convertType(fi.getReturnType());
47+
SmallVector<mlir::Type, 8> argTypes;
48+
argTypes.reserve(fi.getNumRequiredArgs());
4749

48-
SmallVector<mlir::Type, 8> argTypes(fi.getNumRequiredArgs());
49-
50-
unsigned argNo = 0;
51-
llvm::ArrayRef<CIRGenFunctionInfoArgInfo> argInfos(fi.argInfoBegin(),
52-
fi.getNumRequiredArgs());
53-
for (const auto &argInfo : argInfos)
54-
argTypes[argNo++] = convertType(argInfo.type);
50+
for (const CIRGenFunctionInfoArgInfo &argInfo : fi.requiredArguments())
51+
argTypes.push_back(convertType(argInfo.type));
5552

5653
return cir::FuncType::get(argTypes,
5754
(resultType ? resultType : builder.getVoidTy()),
@@ -63,6 +60,35 @@ CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const {
6360
return *this;
6461
}
6562

63+
/// Adds the formal parameters in FPT to the given prefix. If any parameter in
64+
/// FPT has pass_object_size_attrs, then we'll add parameters for those, too.
65+
/// TODO(cir): this should be shared with LLVM codegen
66+
static void appendParameterTypes(const CIRGenTypes &cgt,
67+
SmallVectorImpl<CanQualType> &prefix,
68+
CanQual<FunctionProtoType> fpt) {
69+
assert(!cir::MissingFeatures::opCallExtParameterInfo());
70+
// Fast path: don't touch param info if we don't need to.
71+
if (!fpt->hasExtParameterInfos()) {
72+
prefix.append(fpt->param_type_begin(), fpt->param_type_end());
73+
return;
74+
}
75+
76+
cgt.getCGModule().errorNYI("appendParameterTypes: hasExtParameterInfos");
77+
}
78+
79+
/// Arrange the CIR function layout for a value of the given function type, on
80+
/// top of any implicit parameters already stored.
81+
static const CIRGenFunctionInfo &
82+
arrangeCIRFunctionInfo(CIRGenTypes &cgt, SmallVectorImpl<CanQualType> &prefix,
83+
CanQual<FunctionProtoType> ftp) {
84+
RequiredArgs required =
85+
RequiredArgs::getFromProtoWithExtraSlots(ftp, prefix.size());
86+
assert(!cir::MissingFeatures::opCallExtParameterInfo());
87+
appendParameterTypes(cgt, prefix, ftp);
88+
CanQualType resultType = ftp->getReturnType().getUnqualifiedType();
89+
return cgt.arrangeCIRFunctionInfo(resultType, prefix, required);
90+
}
91+
6692
static const CIRGenFunctionInfo &
6793
arrangeFreeFunctionLikeCall(CIRGenTypes &cgt, CIRGenModule &cgm,
6894
const CallArgList &args,
@@ -95,6 +121,34 @@ CIRGenTypes::arrangeFreeFunctionCall(const CallArgList &args,
95121
return arrangeFreeFunctionLikeCall(*this, cgm, args, fnType);
96122
}
97123

124+
/// Arrange the argument and result information for the declaration or
125+
/// definition of the given function.
126+
const CIRGenFunctionInfo &
127+
CIRGenTypes::arrangeFunctionDeclaration(const FunctionDecl *fd) {
128+
if (const auto *md = dyn_cast<CXXMethodDecl>(fd)) {
129+
if (md->isInstance()) {
130+
cgm.errorNYI("arrangeFunctionDeclaration: instance method");
131+
}
132+
}
133+
134+
CanQualType funcTy = fd->getType()->getCanonicalTypeUnqualified();
135+
136+
assert(isa<FunctionType>(funcTy));
137+
// TODO: setCUDAKernelCallingConvention
138+
assert(!cir::MissingFeatures::cudaSupport());
139+
140+
// When declaring a function without a prototype, always use a non-variadic
141+
// type.
142+
if (CanQual<FunctionNoProtoType> noProto =
143+
funcTy.getAs<FunctionNoProtoType>()) {
144+
assert(!cir::MissingFeatures::opCallCIRGenFuncInfoExtParamInfo());
145+
return arrangeCIRFunctionInfo(noProto->getReturnType(), std::nullopt,
146+
RequiredArgs::All);
147+
}
148+
149+
return arrangeFreeFunctionType(funcTy.castAs<FunctionProtoType>());
150+
}
151+
98152
static cir::CIRCallOpInterface
99153
emitCallLikeOp(CIRGenFunction &cgf, mlir::Location callLoc,
100154
cir::FuncOp directFuncOp,
@@ -112,13 +166,8 @@ emitCallLikeOp(CIRGenFunction &cgf, mlir::Location callLoc,
112166

113167
const CIRGenFunctionInfo &
114168
CIRGenTypes::arrangeFreeFunctionType(CanQual<FunctionProtoType> fpt) {
115-
SmallVector<CanQualType, 8> argTypes;
116-
for (unsigned i = 0, e = fpt->getNumParams(); i != e; ++i)
117-
argTypes.push_back(fpt->getParamType(i));
118-
RequiredArgs required = RequiredArgs::forPrototypePlus(fpt);
119-
120-
CanQualType resultType = fpt->getReturnType().getUnqualifiedType();
121-
return arrangeCIRFunctionInfo(resultType, argTypes, required);
169+
SmallVector<CanQualType, 16> argTypes;
170+
return ::arrangeCIRFunctionInfo(*this, argTypes, fpt);
122171
}
123172

124173
const CIRGenFunctionInfo &

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ void CIRGenFunction::emitDecl(const Decl &d) {
322322
case Decl::ObjCTypeParam:
323323
case Decl::Binding:
324324
case Decl::UnresolvedUsingIfExists:
325+
case Decl::HLSLBuffer:
326+
case Decl::HLSLRootSignature:
325327
llvm_unreachable("Declaration should not be in declstmts!");
326328

327329
case Decl::Function: // void X();
@@ -374,7 +376,6 @@ void CIRGenFunction::emitDecl(const Decl &d) {
374376
return;
375377
}
376378
case Decl::ImplicitConceptSpecialization:
377-
case Decl::HLSLBuffer:
378379
case Decl::TopLevelStmt:
379380
case Decl::UsingPack:
380381
case Decl::Decomposition: // This could be moved to join Decl::Var

clang/lib/CIR/CodeGen/CIRGenFunctionInfo.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,21 @@ class RequiredArgs {
4747
///
4848
/// If FD is not null, this will consider pass_object_size params in FD.
4949
static RequiredArgs
50-
forPrototypePlus(const clang::FunctionProtoType *prototype) {
50+
getFromProtoWithExtraSlots(const clang::FunctionProtoType *prototype,
51+
unsigned additional) {
5152
if (!prototype->isVariadic())
5253
return All;
5354

5455
if (prototype->hasExtParameterInfos())
5556
llvm_unreachable("NYI");
5657

57-
return RequiredArgs(prototype->getNumParams());
58+
return RequiredArgs(prototype->getNumParams() + additional);
5859
}
5960

6061
static RequiredArgs
61-
forPrototypePlus(clang::CanQual<clang::FunctionProtoType> prototype) {
62-
return forPrototypePlus(prototype.getTypePtr());
62+
getFromProtoWithExtraSlots(clang::CanQual<clang::FunctionProtoType> prototype,
63+
unsigned additional) {
64+
return getFromProtoWithExtraSlots(prototype.getTypePtr(), additional);
6365
}
6466

6567
unsigned getNumRequiredArgs() const {
@@ -114,6 +116,14 @@ class CIRGenFunctionInfo final
114116
getReturnType().Profile(id);
115117
}
116118

119+
llvm::ArrayRef<ArgInfo> arguments() const {
120+
return llvm::ArrayRef<ArgInfo>(argInfoBegin(), numArgs);
121+
}
122+
123+
llvm::ArrayRef<ArgInfo> requiredArguments() const {
124+
return llvm::ArrayRef<ArgInfo>(argInfoBegin(), getNumRequiredArgs());
125+
}
126+
117127
CanQualType getReturnType() const { return getArgsBuffer()[0].type; }
118128

119129
const_arg_iterator argInfoBegin() const { return getArgsBuffer() + 1; }

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -249,21 +249,8 @@ void CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl gd,
249249
return;
250250
}
251251

252-
cir::FuncType funcType;
253-
// TODO: Move this to arrangeFunctionDeclaration when it is
254-
// implemented.
255-
// When declaring a function without a prototype, always use a
256-
// non-variadic type.
257-
if (CanQual<FunctionNoProtoType> noProto =
258-
funcDecl->getType()
259-
->getCanonicalTypeUnqualified()
260-
.getAs<FunctionNoProtoType>()) {
261-
const CIRGenFunctionInfo &fi = getTypes().arrangeCIRFunctionInfo(
262-
noProto->getReturnType(), {}, RequiredArgs::All);
263-
funcType = getTypes().getFunctionType(fi);
264-
} else {
265-
funcType = cast<cir::FuncType>(convertType(funcDecl->getType()));
266-
}
252+
const CIRGenFunctionInfo &fi = getTypes().arrangeGlobalDeclaration(gd);
253+
cir::FuncType funcType = getTypes().getFunctionType(fi);
267254

268255
cir::FuncOp funcOp = dyn_cast_if_present<cir::FuncOp>(op);
269256
if (!funcOp || funcOp.getFunctionType() != funcType) {

0 commit comments

Comments
 (0)