Skip to content

Commit 7b9c9c0

Browse files
authored
Merge pull request #365 from Xilinx/bump_to_4b7f07a0
[AutoBump] Merge with 4b7f07a (Aug 27) (12)
2 parents a439f4c + 3db25fc commit 7b9c9c0

File tree

508 files changed

+17079
-5125
lines changed

Some content is hidden

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

508 files changed

+17079
-5125
lines changed

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,17 +2415,15 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
24152415
Fragments.insert(BF);
24162416
for (const BinaryFunction *F : Fragments) {
24172417
const uint64_t FuncAddr = F->getAddress();
2418-
const auto &FragmentProbes =
2419-
llvm::make_range(ProbeMap.lower_bound(FuncAddr),
2420-
ProbeMap.lower_bound(FuncAddr + F->getSize()));
2421-
for (const auto &[OutputAddress, Probes] : FragmentProbes) {
2418+
for (const MCDecodedPseudoProbe &Probe :
2419+
ProbeMap.find(FuncAddr, FuncAddr + F->getSize())) {
2420+
const uint32_t OutputAddress = Probe.getAddress();
24222421
const uint32_t InputOffset = BAT->translate(
24232422
FuncAddr, OutputAddress - FuncAddr, /*IsBranchSrc=*/true);
24242423
const unsigned BlockIndex = getBlock(InputOffset).second;
2425-
for (const MCDecodedPseudoProbe &Probe : Probes)
2426-
YamlBF.Blocks[BlockIndex].PseudoProbes.emplace_back(
2427-
yaml::bolt::PseudoProbeInfo{Probe.getGuid(), Probe.getIndex(),
2428-
Probe.getType()});
2424+
YamlBF.Blocks[BlockIndex].PseudoProbes.emplace_back(
2425+
yaml::bolt::PseudoProbeInfo{Probe.getGuid(), Probe.getIndex(),
2426+
Probe.getType()});
24292427
}
24302428
}
24312429
}

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,10 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS,
193193
const uint64_t FuncAddr = BF.getAddress();
194194
const std::pair<uint64_t, uint64_t> &BlockRange =
195195
BB->getInputAddressRange();
196-
const auto &BlockProbes =
197-
llvm::make_range(ProbeMap.lower_bound(FuncAddr + BlockRange.first),
198-
ProbeMap.lower_bound(FuncAddr + BlockRange.second));
199-
for (const auto &[_, Probes] : BlockProbes)
200-
for (const MCDecodedPseudoProbe &Probe : Probes)
201-
YamlBB.PseudoProbes.emplace_back(yaml::bolt::PseudoProbeInfo{
202-
Probe.getGuid(), Probe.getIndex(), Probe.getType()});
196+
for (const MCDecodedPseudoProbe &Probe : ProbeMap.find(
197+
FuncAddr + BlockRange.first, FuncAddr + BlockRange.second))
198+
YamlBB.PseudoProbes.emplace_back(yaml::bolt::PseudoProbeInfo{
199+
Probe.getGuid(), Probe.getIndex(), Probe.getType()});
203200
}
204201

205202
YamlBF.Blocks.emplace_back(YamlBB);

bolt/lib/Rewrite/PseudoProbeRewriter.cpp

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ void PseudoProbeRewriter::parsePseudoProbe() {
143143
if (!ProbeDecoder.buildAddress2ProbeMap(
144144
reinterpret_cast<const uint8_t *>(Contents.data()), Contents.size(),
145145
GuidFilter, FuncStartAddrs)) {
146-
ProbeDecoder.getAddress2ProbesMap().clear();
147146
errs() << "BOLT-WARNING: fail in building Address2ProbeMap\n";
148147
return;
149148
}
@@ -156,7 +155,8 @@ void PseudoProbeRewriter::parsePseudoProbe() {
156155
ProbeDecoder.printProbesForAllAddresses(outs());
157156
}
158157

159-
for (const auto &[GUID, FuncDesc] : ProbeDecoder.getGUID2FuncDescMap()) {
158+
for (const auto &FuncDesc : ProbeDecoder.getGUID2FuncDescMap()) {
159+
uint64_t GUID = FuncDesc.FuncGUID;
160160
if (!FuncStartAddrs.contains(GUID))
161161
continue;
162162
BinaryFunction *BF = BC.getBinaryFunctionAtAddress(FuncStartAddrs[GUID]);
@@ -174,59 +174,50 @@ void PseudoProbeRewriter::updatePseudoProbes() {
174174
AddressProbesMap &Address2ProbesMap = ProbeDecoder.getAddress2ProbesMap();
175175
const GUIDProbeFunctionMap &GUID2Func = ProbeDecoder.getGUID2FuncDescMap();
176176

177-
for (auto &AP : Address2ProbesMap) {
178-
BinaryFunction *F = BC.getBinaryFunctionContainingAddress(AP.first);
177+
for (MCDecodedPseudoProbe &Probe : Address2ProbesMap) {
178+
uint64_t Address = Probe.getAddress();
179+
BinaryFunction *F = BC.getBinaryFunctionContainingAddress(Address);
179180
// If F is removed, eliminate all probes inside it from inline tree
180181
// Setting probes' addresses as INT64_MAX means elimination
181182
if (!F) {
182-
for (MCDecodedPseudoProbe &Probe : AP.second)
183-
Probe.setAddress(INT64_MAX);
183+
Probe.setAddress(INT64_MAX);
184184
continue;
185185
}
186186
// If F is not emitted, the function will remain in the same address as its
187187
// input
188188
if (!F->isEmitted())
189189
continue;
190190

191-
uint64_t Offset = AP.first - F->getAddress();
191+
uint64_t Offset = Address - F->getAddress();
192192
const BinaryBasicBlock *BB = F->getBasicBlockContainingOffset(Offset);
193193
uint64_t BlkOutputAddress = BB->getOutputAddressRange().first;
194194
// Check if block output address is defined.
195195
// If not, such block is removed from binary. Then remove the probes from
196196
// inline tree
197197
if (BlkOutputAddress == 0) {
198-
for (MCDecodedPseudoProbe &Probe : AP.second)
199-
Probe.setAddress(INT64_MAX);
198+
Probe.setAddress(INT64_MAX);
200199
continue;
201200
}
202201

203-
unsigned ProbeTrack = AP.second.size();
204-
std::list<MCDecodedPseudoProbe>::iterator Probe = AP.second.begin();
205-
while (ProbeTrack != 0) {
206-
if (Probe->isBlock()) {
207-
Probe->setAddress(BlkOutputAddress);
208-
} else if (Probe->isCall()) {
209-
// A call probe may be duplicated due to ICP
210-
// Go through output of InputOffsetToAddressMap to collect all related
211-
// probes
212-
auto CallOutputAddresses = BC.getIOAddressMap().lookupAll(AP.first);
213-
auto CallOutputAddress = CallOutputAddresses.first;
214-
if (CallOutputAddress == CallOutputAddresses.second) {
215-
Probe->setAddress(INT64_MAX);
216-
} else {
217-
Probe->setAddress(CallOutputAddress->second);
218-
CallOutputAddress = std::next(CallOutputAddress);
219-
}
220-
221-
while (CallOutputAddress != CallOutputAddresses.second) {
222-
AP.second.push_back(*Probe);
223-
AP.second.back().setAddress(CallOutputAddress->second);
224-
Probe->getInlineTreeNode()->addProbes(&(AP.second.back()));
225-
CallOutputAddress = std::next(CallOutputAddress);
226-
}
202+
if (Probe.isBlock()) {
203+
Probe.setAddress(BlkOutputAddress);
204+
} else if (Probe.isCall()) {
205+
// A call probe may be duplicated due to ICP
206+
// Go through output of InputOffsetToAddressMap to collect all related
207+
// probes
208+
auto CallOutputAddresses = BC.getIOAddressMap().lookupAll(Address);
209+
auto CallOutputAddress = CallOutputAddresses.first;
210+
if (CallOutputAddress == CallOutputAddresses.second) {
211+
Probe.setAddress(INT64_MAX);
212+
} else {
213+
Probe.setAddress(CallOutputAddress->second);
214+
CallOutputAddress = std::next(CallOutputAddress);
215+
}
216+
217+
while (CallOutputAddress != CallOutputAddresses.second) {
218+
ProbeDecoder.addInjectedProbe(Probe, CallOutputAddress->second);
219+
CallOutputAddress = std::next(CallOutputAddress);
227220
}
228-
Probe = std::next(Probe);
229-
ProbeTrack--;
230221
}
231222
}
232223

@@ -242,22 +233,16 @@ void PseudoProbeRewriter::updatePseudoProbes() {
242233
BinaryBlock.getName();
243234

244235
// scan all addresses -> correlate probe to block when print out
245-
std::vector<uint64_t> Addresses;
246-
for (auto &Entry : Address2ProbesMap)
247-
Addresses.push_back(Entry.first);
248-
llvm::sort(Addresses);
249-
for (uint64_t Key : Addresses) {
250-
for (MCDecodedPseudoProbe &Probe : Address2ProbesMap[Key]) {
251-
if (Probe.getAddress() == INT64_MAX)
252-
outs() << "Deleted Probe: ";
253-
else
254-
outs() << "Address: " << format_hex(Probe.getAddress(), 8) << " ";
255-
Probe.print(outs(), GUID2Func, true);
256-
// print block name only if the probe is block type and undeleted.
257-
if (Probe.isBlock() && Probe.getAddress() != INT64_MAX)
258-
outs() << format_hex(Probe.getAddress(), 8) << " Probe is in "
259-
<< Addr2BlockNames[Probe.getAddress()] << "\n";
260-
}
236+
for (MCDecodedPseudoProbe &Probe : Address2ProbesMap) {
237+
if (Probe.getAddress() == INT64_MAX)
238+
outs() << "Deleted Probe: ";
239+
else
240+
outs() << "Address: " << format_hex(Probe.getAddress(), 8) << " ";
241+
Probe.print(outs(), GUID2Func, true);
242+
// print block name only if the probe is block type and undeleted.
243+
if (Probe.isBlock() && Probe.getAddress() != INT64_MAX)
244+
outs() << format_hex(Probe.getAddress(), 8) << " Probe is in "
245+
<< Addr2BlockNames[Probe.getAddress()] << "\n";
261246
}
262247
outs() << "=======================================\n";
263248
}
@@ -333,7 +318,7 @@ void PseudoProbeRewriter::encodePseudoProbes() {
333318
ProbeDecoder.getDummyInlineRoot();
334319
for (auto Child = Root.getChildren().begin();
335320
Child != Root.getChildren().end(); ++Child)
336-
Inlinees[Child->first] = Child->second.get();
321+
Inlinees[Child->getInlineSite()] = &*Child;
337322

338323
for (auto Inlinee : Inlinees)
339324
// INT64_MAX is "placeholder" of unused callsite index field in the pair
@@ -359,25 +344,37 @@ void PseudoProbeRewriter::encodePseudoProbes() {
359344
EmitInt(Cur->Guid, 8);
360345
// Emit number of probes in this node
361346
uint64_t Deleted = 0;
362-
for (MCDecodedPseudoProbe *&Probe : Cur->getProbes())
347+
for (MCDecodedPseudoProbe *&Probe :
348+
llvm::make_pointer_range(Cur->getProbes()))
363349
if (Probe->getAddress() == INT64_MAX)
364350
Deleted++;
365351
LLVM_DEBUG(dbgs() << "Deleted Probes:" << Deleted << "\n");
366-
uint64_t ProbesSize = Cur->getProbes().size() - Deleted;
352+
size_t InjectedProbes = ProbeDecoder.getNumInjectedProbes(Cur);
353+
uint64_t ProbesSize = Cur->getProbes().size() - Deleted + InjectedProbes;
367354
EmitULEB128IntValue(ProbesSize);
368355
// Emit number of direct inlinees
369356
EmitULEB128IntValue(Cur->getChildren().size());
370357
// Emit probes in this group
371-
for (MCDecodedPseudoProbe *&Probe : Cur->getProbes()) {
358+
for (MCDecodedPseudoProbe *&Probe :
359+
llvm::make_pointer_range(Cur->getProbes())) {
372360
if (Probe->getAddress() == INT64_MAX)
373361
continue;
374362
EmitDecodedPseudoProbe(Probe);
375363
LastProbe = Probe;
376364
}
365+
if (InjectedProbes) {
366+
for (MCDecodedPseudoProbe *&Probe :
367+
llvm::make_pointer_range(ProbeDecoder.getInjectedProbes(Cur))) {
368+
if (Probe->getAddress() == INT64_MAX)
369+
continue;
370+
EmitDecodedPseudoProbe(Probe);
371+
LastProbe = Probe;
372+
}
373+
}
377374

378375
for (auto Child = Cur->getChildren().begin();
379376
Child != Cur->getChildren().end(); ++Child)
380-
Inlinees[Child->first] = Child->second.get();
377+
Inlinees[Child->getInlineSite()] = &*Child;
381378
for (const auto &Inlinee : Inlinees) {
382379
assert(Cur->Guid != 0 && "non root tree node must have nonzero Guid");
383380
NextNodes.push_back({std::get<1>(Inlinee.first), Inlinee.second});

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ bool isUnaryLogicalNotOperator(const Stmt *Statement) {
6666

6767
void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
6868
const ImplicitCastExpr *Cast, const Stmt *Parent,
69-
ASTContext &Context) {
69+
ASTContext &Context,
70+
bool UseUpperCaseLiteralSuffix) {
7071
// In case of expressions like (! integer), we should remove the redundant not
7172
// operator and use inverted comparison (integer == 0).
7273
bool InvertComparison =
@@ -112,9 +113,14 @@ void fixGenericExprCastToBool(DiagnosticBuilder &Diag,
112113
EndLocInsertion += " != ";
113114
}
114115

115-
EndLocInsertion += getZeroLiteralToCompareWithForType(
116+
const StringRef ZeroLiteral = getZeroLiteralToCompareWithForType(
116117
Cast->getCastKind(), SubExpr->getType(), Context);
117118

119+
if (UseUpperCaseLiteralSuffix)
120+
EndLocInsertion += ZeroLiteral.upper();
121+
else
122+
EndLocInsertion += ZeroLiteral;
123+
118124
if (NeedOuterParens) {
119125
EndLocInsertion += ")";
120126
}
@@ -248,12 +254,15 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck(
248254
StringRef Name, ClangTidyContext *Context)
249255
: ClangTidyCheck(Name, Context),
250256
AllowIntegerConditions(Options.get("AllowIntegerConditions", false)),
251-
AllowPointerConditions(Options.get("AllowPointerConditions", false)) {}
257+
AllowPointerConditions(Options.get("AllowPointerConditions", false)),
258+
UseUpperCaseLiteralSuffix(
259+
Options.get("UseUpperCaseLiteralSuffix", false)) {}
252260

253261
void ImplicitBoolConversionCheck::storeOptions(
254262
ClangTidyOptions::OptionMap &Opts) {
255263
Options.store(Opts, "AllowIntegerConditions", AllowIntegerConditions);
256264
Options.store(Opts, "AllowPointerConditions", AllowPointerConditions);
265+
Options.store(Opts, "UseUpperCaseLiteralSuffix", UseUpperCaseLiteralSuffix);
257266
}
258267

259268
void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
@@ -378,7 +387,8 @@ void ImplicitBoolConversionCheck::handleCastToBool(const ImplicitCastExpr *Cast,
378387
if (!EquivalentLiteral.empty()) {
379388
Diag << tooling::fixit::createReplacement(*Cast, EquivalentLiteral);
380389
} else {
381-
fixGenericExprCastToBool(Diag, Cast, Parent, Context);
390+
fixGenericExprCastToBool(Diag, Cast, Parent, Context,
391+
UseUpperCaseLiteralSuffix);
382392
}
383393
}
384394

@@ -392,8 +402,16 @@ void ImplicitBoolConversionCheck::handleCastFromBool(
392402

393403
if (const auto *BoolLiteral =
394404
dyn_cast<CXXBoolLiteralExpr>(Cast->getSubExpr()->IgnoreParens())) {
395-
Diag << tooling::fixit::createReplacement(
396-
*Cast, getEquivalentForBoolLiteral(BoolLiteral, DestType, Context));
405+
406+
const auto EquivalentForBoolLiteral =
407+
getEquivalentForBoolLiteral(BoolLiteral, DestType, Context);
408+
if (UseUpperCaseLiteralSuffix)
409+
Diag << tooling::fixit::createReplacement(
410+
*Cast, EquivalentForBoolLiteral.upper());
411+
else
412+
Diag << tooling::fixit::createReplacement(*Cast,
413+
EquivalentForBoolLiteral);
414+
397415
} else {
398416
fixGenericExprCastFromBool(Diag, Cast, Context, DestType.getAsString());
399417
}

clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck {
3636

3737
const bool AllowIntegerConditions;
3838
const bool AllowPointerConditions;
39+
const bool UseUpperCaseLiteralSuffix;
3940
};
4041

4142
} // namespace clang::tidy::readability

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ Changes in existing checks
112112
<clang-tidy/checks/modernize/use-std-print>` check to support replacing
113113
member function calls too.
114114

115+
- Improved :doc:`readablility-implicit-bool-conversion
116+
<clang-tidy/checks/readability/implicit-bool-conversion>` check
117+
by adding the option `UseUpperCaseLiteralSuffix` to select the
118+
case of the literal suffix in fixes.
119+
115120
- Improved :doc:`readability-redundant-smartptr-get
116121
<clang-tidy/checks/readability/redundant-smartptr-get>` check to
117122
remove `->`, when redundant `get()` is removed.

clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,17 @@ Options
133133

134134
When `true`, the check will allow conditional pointer conversions. Default
135135
is `false`.
136+
137+
.. option:: UseUpperCaseLiteralSuffix
138+
139+
When `true`, the replacements will use an uppercase literal suffix in the
140+
provided fixes. Default is `false`.
141+
142+
Example
143+
144+
.. code-block:: c++
145+
146+
uint32_t foo;
147+
if (foo) {}
148+
// ^ propose replacement default: if (foo != 0u) {}
149+
// ^ propose replacement with option `UseUpperCaseLiteralSuffix`: if (foo != 0U) {}

clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// RUN: %check_clang_tidy %s readability-implicit-bool-conversion %t -- -- -std=c23
2+
// RUN: %check_clang_tidy -check-suffix=UPPER-CASE %s readability-implicit-bool-conversion %t -- \
3+
// RUN: -config='{CheckOptions: { \
4+
// RUN: readability-implicit-bool-conversion.UseUpperCaseLiteralSuffix: true \
5+
// RUN: }}' -- -std=c23
26

37
#undef NULL
48
#define NULL 0L
@@ -95,6 +99,7 @@ void implicitConversionFromBoolLiterals() {
9599
functionTakingUnsignedLong(false);
96100
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: implicit conversion 'bool' -> 'unsigned long'
97101
// CHECK-FIXES: functionTakingUnsignedLong(0u);
102+
// CHECK-FIXES-UPPER-CASE: functionTakingUnsignedLong(0U);
98103

99104
functionTakingSignedChar(true);
100105
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: implicit conversion 'bool' -> 'signed char'
@@ -103,6 +108,7 @@ void implicitConversionFromBoolLiterals() {
103108
functionTakingFloat(false);
104109
// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: implicit conversion 'bool' -> 'float'
105110
// CHECK-FIXES: functionTakingFloat(0.0f);
111+
// CHECK-FIXES-UPPER-CASE: functionTakingFloat(0.0F);
106112

107113
functionTakingDouble(true);
108114
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicit conversion 'bool' -> 'double'
@@ -160,11 +166,13 @@ void implicitConversionToBoolSimpleCases() {
160166
functionTakingBool(unsignedLong);
161167
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: implicit conversion 'unsigned long' -> 'bool'
162168
// CHECK-FIXES: functionTakingBool(unsignedLong != 0u);
169+
// CHECK-FIXES-UPPER-CASE: functionTakingBool(unsignedLong != 0U);
163170

164171
float floating = 0.0f;
165172
functionTakingBool(floating);
166173
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: implicit conversion 'float' -> 'bool'
167174
// CHECK-FIXES: functionTakingBool(floating != 0.0f);
175+
// CHECK-FIXES-UPPER-CASE: functionTakingBool(floating != 0.0F);
168176

169177
double doubleFloating = 1.0f;
170178
functionTakingBool(doubleFloating);
@@ -194,6 +202,7 @@ void implicitConversionToBoolInSingleExpressions() {
194202
boolComingFromFloat = floating;
195203
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicit conversion 'float' -> 'bool'
196204
// CHECK-FIXES: boolComingFromFloat = (floating != 0.0f);
205+
// CHECK-FIXES-UPPER-CASE: boolComingFromFloat = (floating != 0.0F);
197206

198207
signed char character = 'a';
199208
bool boolComingFromChar;
@@ -288,6 +297,7 @@ void implicitConversionToBoolFromUnaryMinusAndZeroLiterals() {
288297
functionTakingBool(-0.0f);
289298
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: implicit conversion 'float' -> 'bool'
290299
// CHECK-FIXES: functionTakingBool((-0.0f) != 0.0f);
300+
// CHECK-FIXES-UPPER-CASE: functionTakingBool((-0.0f) != 0.0F);
291301

292302
functionTakingBool(-0.0);
293303
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: implicit conversion 'double' -> 'bool'

0 commit comments

Comments
 (0)