Skip to content

Commit 83b29b8

Browse files
Merge branch 'llvm:main' into gh-101657
2 parents 558a128 + 38d9a44 commit 83b29b8

File tree

143 files changed

+3411
-2297
lines changed

Some content is hidden

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

143 files changed

+3411
-2297
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ Bug Fixes to C++ Support
359359
- Fixed C++20 aggregate initialization rules being incorrectly applied in certain contexts. (#GH131320)
360360
- Clang was previously coalescing volatile writes to members of volatile base class subobjects.
361361
The issue has been addressed by propagating qualifiers during derived-to-base conversions in the AST. (#GH127824)
362+
- Correctly propagates the instantiated array type to the ``DeclRefExpr`` that refers to it. (#GH79750), (#GH113936), (#GH133047)
362363
- Fixed a Clang regression in C++20 mode where unresolved dependent call expressions were created inside non-dependent contexts (#GH122892)
363364
- Clang now emits the ``-Wunused-variable`` warning when some structured bindings are unused
364365
and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)

clang/lib/AST/NestedNameSpecifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ NestedNameSpecifier::translateToType(const ASTContext &Context) const {
289289
// These are not representable as types.
290290
return nullptr;
291291
}
292+
llvm_unreachable("Unhandled SpecifierKind enum");
292293
}
293294

294295
/// Print this nested name specifier to the given output

clang/lib/CodeGen/CGLoopInfo.cpp

Lines changed: 58 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ using namespace clang::CodeGen;
2222
using namespace llvm;
2323

2424
MDNode *
25-
LoopInfo::createLoopPropertiesMetadata(ArrayRef<Metadata *> LoopProperties) {
25+
LoopInfo::createFollowupMetadata(const char *FollowupName,
26+
ArrayRef<llvm::Metadata *> LoopProperties) {
2627
LLVMContext &Ctx = Header->getContext();
27-
SmallVector<Metadata *, 4> NewLoopProperties;
28-
NewLoopProperties.push_back(nullptr);
29-
NewLoopProperties.append(LoopProperties.begin(), LoopProperties.end());
3028

31-
MDNode *LoopID = MDNode::getDistinct(Ctx, NewLoopProperties);
32-
LoopID->replaceOperandWith(0, LoopID);
33-
return LoopID;
29+
SmallVector<Metadata *, 4> Args;
30+
Args.push_back(MDString::get(Ctx, FollowupName));
31+
Args.append(LoopProperties.begin(), LoopProperties.end());
32+
return MDNode::get(Ctx, Args);
3433
}
3534

36-
MDNode *LoopInfo::createPipeliningMetadata(const LoopAttributes &Attrs,
37-
ArrayRef<Metadata *> LoopProperties,
38-
bool &HasUserTransforms) {
35+
SmallVector<Metadata *, 4>
36+
LoopInfo::createPipeliningMetadata(const LoopAttributes &Attrs,
37+
ArrayRef<Metadata *> LoopProperties,
38+
bool &HasUserTransforms) {
3939
LLVMContext &Ctx = Header->getContext();
4040

4141
std::optional<bool> Enabled;
@@ -44,23 +44,19 @@ MDNode *LoopInfo::createPipeliningMetadata(const LoopAttributes &Attrs,
4444
else if (Attrs.PipelineInitiationInterval != 0)
4545
Enabled = true;
4646

47+
SmallVector<Metadata *, 4> Args;
48+
Args.append(LoopProperties.begin(), LoopProperties.end());
49+
4750
if (Enabled != true) {
48-
SmallVector<Metadata *, 4> NewLoopProperties;
4951
if (Enabled == false) {
50-
NewLoopProperties.append(LoopProperties.begin(), LoopProperties.end());
51-
NewLoopProperties.push_back(
52+
Args.push_back(
5253
MDNode::get(Ctx, {MDString::get(Ctx, "llvm.loop.pipeline.disable"),
5354
ConstantAsMetadata::get(ConstantInt::get(
5455
llvm::Type::getInt1Ty(Ctx), 1))}));
55-
LoopProperties = NewLoopProperties;
5656
}
57-
return createLoopPropertiesMetadata(LoopProperties);
57+
return Args;
5858
}
5959

60-
SmallVector<Metadata *, 4> Args;
61-
Args.push_back(nullptr);
62-
Args.append(LoopProperties.begin(), LoopProperties.end());
63-
6460
if (Attrs.PipelineInitiationInterval > 0) {
6561
Metadata *Vals[] = {
6662
MDString::get(Ctx, "llvm.loop.pipeline.initiationinterval"),
@@ -71,13 +67,11 @@ MDNode *LoopInfo::createPipeliningMetadata(const LoopAttributes &Attrs,
7167

7268
// No follow-up: This is the last transformation.
7369

74-
MDNode *LoopID = MDNode::getDistinct(Ctx, Args);
75-
LoopID->replaceOperandWith(0, LoopID);
7670
HasUserTransforms = true;
77-
return LoopID;
71+
return Args;
7872
}
7973

80-
MDNode *
74+
SmallVector<Metadata *, 4>
8175
LoopInfo::createPartialUnrollMetadata(const LoopAttributes &Attrs,
8276
ArrayRef<Metadata *> LoopProperties,
8377
bool &HasUserTransforms) {
@@ -108,11 +102,10 @@ LoopInfo::createPartialUnrollMetadata(const LoopAttributes &Attrs,
108102
MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.unroll.disable")));
109103

110104
bool FollowupHasTransforms = false;
111-
MDNode *Followup = createPipeliningMetadata(Attrs, FollowupLoopProperties,
112-
FollowupHasTransforms);
105+
SmallVector<Metadata *, 4> Followup = createPipeliningMetadata(
106+
Attrs, FollowupLoopProperties, FollowupHasTransforms);
113107

114108
SmallVector<Metadata *, 4> Args;
115-
Args.push_back(nullptr);
116109
Args.append(LoopProperties.begin(), LoopProperties.end());
117110

118111
// Setting unroll.count
@@ -130,16 +123,14 @@ LoopInfo::createPartialUnrollMetadata(const LoopAttributes &Attrs,
130123
}
131124

132125
if (FollowupHasTransforms)
133-
Args.push_back(MDNode::get(
134-
Ctx, {MDString::get(Ctx, "llvm.loop.unroll.followup_all"), Followup}));
126+
Args.push_back(
127+
createFollowupMetadata("llvm.loop.unroll.followup_all", Followup));
135128

136-
MDNode *LoopID = MDNode::getDistinct(Ctx, Args);
137-
LoopID->replaceOperandWith(0, LoopID);
138129
HasUserTransforms = true;
139-
return LoopID;
130+
return Args;
140131
}
141132

142-
MDNode *
133+
SmallVector<Metadata *, 4>
143134
LoopInfo::createUnrollAndJamMetadata(const LoopAttributes &Attrs,
144135
ArrayRef<Metadata *> LoopProperties,
145136
bool &HasUserTransforms) {
@@ -170,11 +161,10 @@ LoopInfo::createUnrollAndJamMetadata(const LoopAttributes &Attrs,
170161
MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.unroll_and_jam.disable")));
171162

172163
bool FollowupHasTransforms = false;
173-
MDNode *Followup = createPartialUnrollMetadata(Attrs, FollowupLoopProperties,
174-
FollowupHasTransforms);
164+
SmallVector<Metadata *, 4> Followup = createPartialUnrollMetadata(
165+
Attrs, FollowupLoopProperties, FollowupHasTransforms);
175166

176167
SmallVector<Metadata *, 4> Args;
177-
Args.push_back(nullptr);
178168
Args.append(LoopProperties.begin(), LoopProperties.end());
179169

180170
// Setting unroll_and_jam.count
@@ -192,22 +182,18 @@ LoopInfo::createUnrollAndJamMetadata(const LoopAttributes &Attrs,
192182
}
193183

194184
if (FollowupHasTransforms)
195-
Args.push_back(MDNode::get(
196-
Ctx, {MDString::get(Ctx, "llvm.loop.unroll_and_jam.followup_outer"),
197-
Followup}));
185+
Args.push_back(createFollowupMetadata(
186+
"llvm.loop.unroll_and_jam.followup_outer", Followup));
198187

199-
if (UnrollAndJamInnerFollowup)
200-
Args.push_back(MDNode::get(
201-
Ctx, {MDString::get(Ctx, "llvm.loop.unroll_and_jam.followup_inner"),
202-
UnrollAndJamInnerFollowup}));
188+
if (UnrollAndJamInnerFollowup.has_value())
189+
Args.push_back(createFollowupMetadata(
190+
"llvm.loop.unroll_and_jam.followup_inner", *UnrollAndJamInnerFollowup));
203191

204-
MDNode *LoopID = MDNode::getDistinct(Ctx, Args);
205-
LoopID->replaceOperandWith(0, LoopID);
206192
HasUserTransforms = true;
207-
return LoopID;
193+
return Args;
208194
}
209195

210-
MDNode *
196+
SmallVector<Metadata *, 4>
211197
LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs,
212198
ArrayRef<Metadata *> LoopProperties,
213199
bool &HasUserTransforms) {
@@ -244,11 +230,10 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs,
244230
MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.isvectorized")));
245231

246232
bool FollowupHasTransforms = false;
247-
MDNode *Followup = createUnrollAndJamMetadata(Attrs, FollowupLoopProperties,
248-
FollowupHasTransforms);
233+
SmallVector<Metadata *, 4> Followup = createUnrollAndJamMetadata(
234+
Attrs, FollowupLoopProperties, FollowupHasTransforms);
249235

250236
SmallVector<Metadata *, 4> Args;
251-
Args.push_back(nullptr);
252237
Args.append(LoopProperties.begin(), LoopProperties.end());
253238

254239
// Setting vectorize.predicate when it has been specified and vectorization
@@ -315,17 +300,14 @@ LoopInfo::createLoopVectorizeMetadata(const LoopAttributes &Attrs,
315300
}
316301

317302
if (FollowupHasTransforms)
318-
Args.push_back(MDNode::get(
319-
Ctx,
320-
{MDString::get(Ctx, "llvm.loop.vectorize.followup_all"), Followup}));
303+
Args.push_back(
304+
createFollowupMetadata("llvm.loop.vectorize.followup_all", Followup));
321305

322-
MDNode *LoopID = MDNode::getDistinct(Ctx, Args);
323-
LoopID->replaceOperandWith(0, LoopID);
324306
HasUserTransforms = true;
325-
return LoopID;
307+
return Args;
326308
}
327309

328-
MDNode *
310+
SmallVector<Metadata *, 4>
329311
LoopInfo::createLoopDistributeMetadata(const LoopAttributes &Attrs,
330312
ArrayRef<Metadata *> LoopProperties,
331313
bool &HasUserTransforms) {
@@ -352,11 +334,10 @@ LoopInfo::createLoopDistributeMetadata(const LoopAttributes &Attrs,
352334
}
353335

354336
bool FollowupHasTransforms = false;
355-
MDNode *Followup =
337+
SmallVector<Metadata *, 4> Followup =
356338
createLoopVectorizeMetadata(Attrs, LoopProperties, FollowupHasTransforms);
357339

358340
SmallVector<Metadata *, 4> Args;
359-
Args.push_back(nullptr);
360341
Args.append(LoopProperties.begin(), LoopProperties.end());
361342

362343
Metadata *Vals[] = {MDString::get(Ctx, "llvm.loop.distribute.enable"),
@@ -366,19 +347,17 @@ LoopInfo::createLoopDistributeMetadata(const LoopAttributes &Attrs,
366347
Args.push_back(MDNode::get(Ctx, Vals));
367348

368349
if (FollowupHasTransforms)
369-
Args.push_back(MDNode::get(
370-
Ctx,
371-
{MDString::get(Ctx, "llvm.loop.distribute.followup_all"), Followup}));
350+
Args.push_back(
351+
createFollowupMetadata("llvm.loop.distribute.followup_all", Followup));
372352

373-
MDNode *LoopID = MDNode::getDistinct(Ctx, Args);
374-
LoopID->replaceOperandWith(0, LoopID);
375353
HasUserTransforms = true;
376-
return LoopID;
354+
return Args;
377355
}
378356

379-
MDNode *LoopInfo::createFullUnrollMetadata(const LoopAttributes &Attrs,
380-
ArrayRef<Metadata *> LoopProperties,
381-
bool &HasUserTransforms) {
357+
SmallVector<Metadata *, 4>
358+
LoopInfo::createFullUnrollMetadata(const LoopAttributes &Attrs,
359+
ArrayRef<Metadata *> LoopProperties,
360+
bool &HasUserTransforms) {
382361
LLVMContext &Ctx = Header->getContext();
383362

384363
std::optional<bool> Enabled;
@@ -400,20 +379,17 @@ MDNode *LoopInfo::createFullUnrollMetadata(const LoopAttributes &Attrs,
400379
}
401380

402381
SmallVector<Metadata *, 4> Args;
403-
Args.push_back(nullptr);
404382
Args.append(LoopProperties.begin(), LoopProperties.end());
405383
Args.push_back(MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.unroll.full")));
406384

407385
// No follow-up: there is no loop after full unrolling.
408386
// TODO: Warn if there are transformations after full unrolling.
409387

410-
MDNode *LoopID = MDNode::getDistinct(Ctx, Args);
411-
LoopID->replaceOperandWith(0, LoopID);
412388
HasUserTransforms = true;
413-
return LoopID;
389+
return Args;
414390
}
415391

416-
MDNode *LoopInfo::createMetadata(
392+
SmallVector<Metadata *, 4> LoopInfo::createMetadata(
417393
const LoopAttributes &Attrs,
418394
llvm::ArrayRef<llvm::Metadata *> AdditionalLoopProperties,
419395
bool &HasUserTransforms) {
@@ -579,8 +555,8 @@ void LoopInfo::finish() {
579555
MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.isvectorized")));
580556

581557
bool InnerFollowupHasTransform = false;
582-
MDNode *InnerFollowup = createMetadata(AfterJam, BeforeLoopProperties,
583-
InnerFollowupHasTransform);
558+
SmallVector<Metadata *, 4> InnerFollowup = createMetadata(
559+
AfterJam, BeforeLoopProperties, InnerFollowupHasTransform);
584560
if (InnerFollowupHasTransform)
585561
Parent->UnrollAndJamInnerFollowup = InnerFollowup;
586562
}
@@ -589,7 +565,14 @@ void LoopInfo::finish() {
589565
}
590566

591567
bool HasUserTransforms = false;
592-
LoopID = createMetadata(CurLoopAttr, {}, HasUserTransforms);
568+
SmallVector<Metadata *, 4> Properties =
569+
createMetadata(CurLoopAttr, {}, HasUserTransforms);
570+
SmallVector<Metadata *, 4> Args;
571+
Args.push_back(nullptr);
572+
Args.append(Properties.begin(), Properties.end());
573+
LoopID = MDNode::getDistinct(Ctx, Args);
574+
LoopID->replaceOperandWith(0, LoopID);
575+
593576
TempLoopID->replaceAllUsesWith(LoopID);
594577
}
595578

clang/lib/CodeGen/CGLoopInfo.h

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,19 @@ class LoopInfo {
132132
/// If this loop has unroll-and-jam metadata, this can be set by the inner
133133
/// loop's LoopInfo to set the llvm.loop.unroll_and_jam.followup_inner
134134
/// metadata.
135-
llvm::MDNode *UnrollAndJamInnerFollowup = nullptr;
135+
std::optional<llvm::SmallVector<llvm::Metadata *, 4>>
136+
UnrollAndJamInnerFollowup;
136137

137-
/// Create a LoopID without any transformations.
138+
/// Create a followup MDNode that has @p LoopProperties as its attributes.
138139
llvm::MDNode *
139-
createLoopPropertiesMetadata(llvm::ArrayRef<llvm::Metadata *> LoopProperties);
140+
createFollowupMetadata(const char *FollowupName,
141+
llvm::ArrayRef<llvm::Metadata *> LoopProperties);
140142

141-
/// Create a LoopID for transformations.
143+
/// Create a metadata list for transformations.
142144
///
143145
/// The methods call each other in case multiple transformations are applied
144-
/// to a loop. The transformation first to be applied will use LoopID of the
145-
/// next transformation in its followup attribute.
146+
/// to a loop. The transformation first to be applied will use metadata list
147+
/// of the next transformation in its followup attribute.
146148
///
147149
/// @param Attrs The loop's transformations.
148150
/// @param LoopProperties Non-transformation properties such as debug
@@ -152,36 +154,37 @@ class LoopInfo {
152154
/// @param HasUserTransforms [out] Set to true if the returned MDNode encodes
153155
/// at least one transformation.
154156
///
155-
/// @return A LoopID (metadata node) that can be used for the llvm.loop
156-
/// annotation or followup-attribute.
157+
/// @return A metadata list that can be used for the llvm.loop annotation or
158+
/// followup-attribute.
157159
/// @{
158-
llvm::MDNode *
160+
llvm::SmallVector<llvm::Metadata *, 4>
159161
createPipeliningMetadata(const LoopAttributes &Attrs,
160162
llvm::ArrayRef<llvm::Metadata *> LoopProperties,
161163
bool &HasUserTransforms);
162-
llvm::MDNode *
164+
llvm::SmallVector<llvm::Metadata *, 4>
163165
createPartialUnrollMetadata(const LoopAttributes &Attrs,
164166
llvm::ArrayRef<llvm::Metadata *> LoopProperties,
165167
bool &HasUserTransforms);
166-
llvm::MDNode *
168+
llvm::SmallVector<llvm::Metadata *, 4>
167169
createUnrollAndJamMetadata(const LoopAttributes &Attrs,
168170
llvm::ArrayRef<llvm::Metadata *> LoopProperties,
169171
bool &HasUserTransforms);
170-
llvm::MDNode *
172+
llvm::SmallVector<llvm::Metadata *, 4>
171173
createLoopVectorizeMetadata(const LoopAttributes &Attrs,
172174
llvm::ArrayRef<llvm::Metadata *> LoopProperties,
173175
bool &HasUserTransforms);
174-
llvm::MDNode *
176+
llvm::SmallVector<llvm::Metadata *, 4>
175177
createLoopDistributeMetadata(const LoopAttributes &Attrs,
176178
llvm::ArrayRef<llvm::Metadata *> LoopProperties,
177179
bool &HasUserTransforms);
178-
llvm::MDNode *
180+
llvm::SmallVector<llvm::Metadata *, 4>
179181
createFullUnrollMetadata(const LoopAttributes &Attrs,
180182
llvm::ArrayRef<llvm::Metadata *> LoopProperties,
181183
bool &HasUserTransforms);
184+
182185
/// @}
183186

184-
/// Create a LoopID for this loop, including transformation-unspecific
187+
/// Create a metadata list for this loop, including transformation-unspecific
185188
/// metadata such as debug location.
186189
///
187190
/// @param Attrs This loop's attributes and transformations.
@@ -191,11 +194,11 @@ class LoopInfo {
191194
/// @param HasUserTransforms [out] Set to true if the returned MDNode encodes
192195
/// at least one transformation.
193196
///
194-
/// @return A LoopID (metadata node) that can be used for the llvm.loop
195-
/// annotation.
196-
llvm::MDNode *createMetadata(const LoopAttributes &Attrs,
197-
llvm::ArrayRef<llvm::Metadata *> LoopProperties,
198-
bool &HasUserTransforms);
197+
/// @return A metadata list that can be used for the llvm.loop annotation.
198+
llvm::SmallVector<llvm::Metadata *, 4>
199+
createMetadata(const LoopAttributes &Attrs,
200+
llvm::ArrayRef<llvm::Metadata *> LoopProperties,
201+
bool &HasUserTransforms);
199202
};
200203

201204
/// A stack of loop information corresponding to loop nesting levels.

0 commit comments

Comments
 (0)