Skip to content

Commit 3deb60e

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:23f8fac745bdde70ed4f9c585d19c4913734f1b8 into amd-gfx:f0daa1f61373
Local branch amd-gfx f0daa1f Merged main:89a080cb79972abae240c226090af9a3094e2269 into amd-gfx:93971a479db3 Remote branch main 23f8fac Revert "Repply#2 "[RemoveDIs] Load into new debug info format by default in LLVM (llvm#89799)""
2 parents f0daa1f + 23f8fac commit 3deb60e

File tree

225 files changed

+12835
-5665
lines changed

Some content is hidden

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

225 files changed

+12835
-5665
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: PR Request Release Note
2+
3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
7+
on:
8+
pull_request:
9+
types:
10+
- closed
11+
12+
jobs:
13+
request-release-note:
14+
if: >-
15+
github.repository_owner == 'llvm' &&
16+
startsWith(github.ref, 'refs/heads/release')
17+
18+
runs-on: ubuntu-latest
19+
steps:
20+
# We need to pull the script from the main branch, so that we ensure
21+
# we get the latest version of this script.
22+
- name: Checkout Scripts
23+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
24+
with:
25+
sparse-checkout: |
26+
llvm/utils/git/requirements.txt
27+
llvm/utils/git/github-automation.py
28+
sparse-checkout-cone-mode: false
29+
30+
- name: Install Dependencies
31+
run: |
32+
pip install -r llvm/utils/git/requirements.txt
33+
34+
- name: Request Release Note
35+
env:
36+
# We need to use an llvmbot token here, because we are mentioning a user.
37+
GITHUB_TOKEN: ${{ github.token }}
38+
run: |
39+
python3 llvm/utils/git/github-automation.py \
40+
--repo "$GITHUB_REPOSITORY" \
41+
--token "$GITHUB_TOKEN" \
42+
request-release-note \
43+
--pr-number ${{ github.event.pull_request.number}}

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ static uint64_t fixDoubleJumps(BinaryFunction &Function, bool MarkInvalid) {
715715
Pred->removeSuccessor(&BB);
716716
Pred->eraseInstruction(Pred->findInstruction(Branch));
717717
Pred->addTailCallInstruction(SuccSym);
718+
MCInst *TailCall = Pred->getLastNonPseudoInstr();
719+
assert(TailCall);
720+
MIB->setOffset(*TailCall, BB.getOffset());
718721
} else {
719722
return false;
720723
}

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,30 +2355,6 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
23552355
for (auto BI = BlockMap.begin(), BE = BlockMap.end(); BI != BE; ++BI)
23562356
YamlBF.Blocks[BI->second.getBBIndex()].Hash = BI->second.getBBHash();
23572357

2358-
auto getSuccessorInfo = [&](uint32_t SuccOffset, unsigned SuccDataIdx) {
2359-
const llvm::bolt::BranchInfo &BI = Branches.Data.at(SuccDataIdx);
2360-
yaml::bolt::SuccessorInfo SI;
2361-
SI.Index = BlockMap.getBBIndex(SuccOffset);
2362-
SI.Count = BI.Branches;
2363-
SI.Mispreds = BI.Mispreds;
2364-
return SI;
2365-
};
2366-
2367-
auto getCallSiteInfo = [&](Location CallToLoc, unsigned CallToIdx,
2368-
uint32_t Offset) {
2369-
const llvm::bolt::BranchInfo &BI = Branches.Data.at(CallToIdx);
2370-
yaml::bolt::CallSiteInfo CSI;
2371-
CSI.DestId = 0; // designated for unknown functions
2372-
CSI.EntryDiscriminator = 0;
2373-
CSI.Count = BI.Branches;
2374-
CSI.Mispreds = BI.Mispreds;
2375-
CSI.Offset = Offset;
2376-
if (BinaryData *BD = BC.getBinaryDataByName(CallToLoc.Name))
2377-
YAMLProfileWriter::setCSIDestination(BC, CSI, BD->getSymbol(), BAT,
2378-
CallToLoc.Offset);
2379-
return CSI;
2380-
};
2381-
23822358
// Lookup containing basic block offset and index
23832359
auto getBlock = [&BlockMap](uint32_t Offset) {
23842360
auto BlockIt = BlockMap.upper_bound(Offset);
@@ -2390,25 +2366,26 @@ std::error_code DataAggregator::writeBATYAML(BinaryContext &BC,
23902366
return std::pair(BlockIt->first, BlockIt->second.getBBIndex());
23912367
};
23922368

2393-
for (const auto &[FromOffset, SuccKV] : Branches.IntraIndex) {
2394-
const auto &[_, Index] = getBlock(FromOffset);
2395-
yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[Index];
2396-
for (const auto &[SuccOffset, SuccDataIdx] : SuccKV)
2397-
if (BlockMap.isInputBlock(SuccOffset))
2398-
YamlBB.Successors.emplace_back(
2399-
getSuccessorInfo(SuccOffset, SuccDataIdx));
2400-
}
2401-
for (const auto &[FromOffset, CallTo] : Branches.InterIndex) {
2402-
const auto &[BlockOffset, BlockIndex] = getBlock(FromOffset);
2403-
yaml::bolt::BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
2404-
const uint32_t Offset = FromOffset - BlockOffset;
2405-
for (const auto &[CallToLoc, CallToIdx] : CallTo)
2406-
YamlBB.CallSites.emplace_back(
2407-
getCallSiteInfo(CallToLoc, CallToIdx, Offset));
2408-
llvm::sort(YamlBB.CallSites, [](yaml::bolt::CallSiteInfo &A,
2409-
yaml::bolt::CallSiteInfo &B) {
2410-
return A.Offset < B.Offset;
2411-
});
2369+
for (const llvm::bolt::BranchInfo &BI : Branches.Data) {
2370+
using namespace yaml::bolt;
2371+
const auto &[BlockOffset, BlockIndex] = getBlock(BI.From.Offset);
2372+
BinaryBasicBlockProfile &YamlBB = YamlBF.Blocks[BlockIndex];
2373+
if (BI.To.IsSymbol && BI.To.Name == BI.From.Name && BI.To.Offset != 0) {
2374+
// Internal branch
2375+
const unsigned SuccIndex = getBlock(BI.To.Offset).second;
2376+
auto &SI = YamlBB.Successors.emplace_back(SuccessorInfo{SuccIndex});
2377+
SI.Count = BI.Branches;
2378+
SI.Mispreds = BI.Mispreds;
2379+
} else {
2380+
// Call
2381+
const uint32_t Offset = BI.From.Offset - BlockOffset;
2382+
auto &CSI = YamlBB.CallSites.emplace_back(CallSiteInfo{Offset});
2383+
CSI.Count = BI.Branches;
2384+
CSI.Mispreds = BI.Mispreds;
2385+
if (const BinaryData *BD = BC.getBinaryDataByName(BI.To.Name))
2386+
YAMLProfileWriter::setCSIDestination(BC, CSI, BD->getSymbol(), BAT,
2387+
BI.To.Offset);
2388+
}
24122389
}
24132390
// Set entry counts, similar to DataReader::readProfile.
24142391
for (const llvm::bolt::BranchInfo &BI : Branches.EntryData) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
B 800154 401050 20 0
2+
F 800159 800193 7

bolt/test/X86/bb-with-two-tail-calls.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
# RUN: llvm-strip --strip-unneeded %t.o
1010
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
1111
# RUN: llvm-bolt %t.exe -o %t.out --data %t.fdata --lite=0 --dyno-stats \
12-
# RUN: --print-sctc --print-only=_start 2>&1 | FileCheck %s
12+
# RUN: --print-sctc --print-only=_start -enable-bat 2>&1 | FileCheck %s
1313
# CHECK-NOT: Assertion `BranchInfo.size() == 2 && "could only be called for blocks with 2 successors"' failed.
1414
# Two tail calls in the same basic block after SCTC:
15-
# CHECK: {{.*}}: ja {{.*}} # TAILCALL # CTCTakenCount: {{.*}}
16-
# CHECK-NEXT: {{.*}}: jmp {{.*}} # TAILCALL
15+
# CHECK: {{.*}}: ja {{.*}} # TAILCALL # Offset: 7 # CTCTakenCount: 4
16+
# CHECK-NEXT: {{.*}}: jmp {{.*}} # TAILCALL # Offset: 12
1717

1818
.globl _start
1919
_start:

bolt/test/X86/bolt-address-translation-yaml.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ BRANCHENTRY-YAML-CHECK: - name: SolveCubic
1515
BRANCHENTRY-YAML-CHECK: bid: 0
1616
BRANCHENTRY-YAML-CHECK: hash: 0x700F19D24600000
1717
BRANCHENTRY-YAML-CHECK-NEXT: succ: [ { bid: 7, cnt: 1 }
18+
# Check that the order is correct between BAT YAML and FDATA->YAML.
19+
RUN: perf2bolt %t.out --pa -p %p/Inputs/blarge_new_bat_order.preagg.txt \
20+
RUN: -w %t.yaml -o %t.fdata
21+
RUN: llvm-bolt %t.exe -data %t.fdata -w %t.yaml-fdata -o %t.null
22+
RUN: FileCheck --input-file %t.yaml --check-prefix ORDER-YAML-CHECK %s
23+
RUN: FileCheck --input-file %t.yaml-fdata --check-prefix ORDER-YAML-CHECK %s
24+
ORDER-YAML-CHECK: - name: SolveCubic
25+
ORDER-YAML-CHECK: bid: 3
26+
ORDER-YAML-CHECK: hash: 0xDDA1DC5F69F900AC
27+
ORDER-YAML-CHECK-NEXT: calls: [ { off: 0x26, fid: [[#]], cnt: 20 } ]
28+
ORDER-YAML-CHECK-NEXT: succ: [ { bid: 5, cnt: 7 }
1829
# Large profile test
1930
RUN: perf2bolt %t.out --pa -p %p/Inputs/blarge_new_bat.preagg.txt -w %t.yaml -o %t.fdata \
2031
RUN: 2>&1 | FileCheck --check-prefix READ-BAT-CHECK %s

clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
7171
ofClass(matchers::matchesAnyListedName(OptionalTypes)))),
7272
hasType(ConstructTypeMatcher),
7373
hasArgument(0U, ignoringImpCasts(anyOf(OptionalDereferenceMatcher,
74-
StdMoveCallMatcher))))
74+
StdMoveCallMatcher))),
75+
unless(anyOf(hasAncestor(typeLoc()),
76+
hasAncestor(expr(matchers::hasUnevaluatedContext())))))
7577
.bind("expr"),
7678
this);
7779
}

clang-tools-extra/clang-tidy/modernize/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ add_clang_library(clangTidyModernizeModule
4141
UseNullptrCheck.cpp
4242
UseOverrideCheck.cpp
4343
UseStartsEndsWithCheck.cpp
44+
UseStdFormatCheck.cpp
4445
UseStdNumbersCheck.cpp
4546
UseStdPrintCheck.cpp
4647
UseTrailingReturnTypeCheck.cpp

clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "UseNullptrCheck.h"
4343
#include "UseOverrideCheck.h"
4444
#include "UseStartsEndsWithCheck.h"
45+
#include "UseStdFormatCheck.h"
4546
#include "UseStdNumbersCheck.h"
4647
#include "UseStdPrintCheck.h"
4748
#include "UseTrailingReturnTypeCheck.h"
@@ -76,6 +77,7 @@ class ModernizeModule : public ClangTidyModule {
7677
"modernize-use-designated-initializers");
7778
CheckFactories.registerCheck<UseStartsEndsWithCheck>(
7879
"modernize-use-starts-ends-with");
80+
CheckFactories.registerCheck<UseStdFormatCheck>("modernize-use-std-format");
7981
CheckFactories.registerCheck<UseStdNumbersCheck>(
8082
"modernize-use-std-numbers");
8183
CheckFactories.registerCheck<UseStdPrintCheck>("modernize-use-std-print");
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//===--- UseStdFormatCheck.cpp - clang-tidy -------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "UseStdFormatCheck.h"
10+
#include "../utils/FormatStringConverter.h"
11+
#include "../utils/Matchers.h"
12+
#include "../utils/OptionsUtils.h"
13+
#include "clang/ASTMatchers/ASTMatchFinder.h"
14+
#include "clang/Lex/Lexer.h"
15+
#include "clang/Tooling/FixIt.h"
16+
17+
using namespace clang::ast_matchers;
18+
19+
namespace clang::tidy::modernize {
20+
21+
namespace {
22+
AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
23+
} // namespace
24+
25+
UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
26+
: ClangTidyCheck(Name, Context),
27+
StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
28+
StrFormatLikeFunctions(utils::options::parseStringList(
29+
Options.get("StrFormatLikeFunctions", ""))),
30+
ReplacementFormatFunction(
31+
Options.get("ReplacementFormatFunction", "std::format")),
32+
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
33+
utils::IncludeSorter::IS_LLVM),
34+
areDiagsSelfContained()),
35+
MaybeHeaderToInclude(Options.get("FormatHeader")) {
36+
if (StrFormatLikeFunctions.empty())
37+
StrFormatLikeFunctions.push_back("absl::StrFormat");
38+
39+
if (!MaybeHeaderToInclude && ReplacementFormatFunction == "std::format")
40+
MaybeHeaderToInclude = "<format>";
41+
}
42+
43+
void UseStdFormatCheck::registerPPCallbacks(const SourceManager &SM,
44+
Preprocessor *PP,
45+
Preprocessor *ModuleExpanderPP) {
46+
IncludeInserter.registerPreprocessor(PP);
47+
}
48+
49+
void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
50+
Finder->addMatcher(
51+
callExpr(argumentCountAtLeast(1),
52+
hasArgument(0, stringLiteral(isOrdinary())),
53+
callee(functionDecl(unless(cxxMethodDecl()),
54+
matchers::matchesAnyListedName(
55+
StrFormatLikeFunctions))
56+
.bind("func_decl")))
57+
.bind("strformat"),
58+
this);
59+
}
60+
61+
void UseStdFormatCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
62+
using utils::options::serializeStringList;
63+
Options.store(Opts, "StrictMode", StrictMode);
64+
Options.store(Opts, "StrFormatLikeFunctions",
65+
serializeStringList(StrFormatLikeFunctions));
66+
Options.store(Opts, "ReplacementFormatFunction", ReplacementFormatFunction);
67+
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
68+
if (MaybeHeaderToInclude)
69+
Options.store(Opts, "FormatHeader", *MaybeHeaderToInclude);
70+
}
71+
72+
void UseStdFormatCheck::check(const MatchFinder::MatchResult &Result) {
73+
const unsigned FormatArgOffset = 0;
74+
const auto *OldFunction = Result.Nodes.getNodeAs<FunctionDecl>("func_decl");
75+
const auto *StrFormat = Result.Nodes.getNodeAs<CallExpr>("strformat");
76+
77+
utils::FormatStringConverter::Configuration ConverterConfig;
78+
ConverterConfig.StrictMode = StrictMode;
79+
utils::FormatStringConverter Converter(Result.Context, StrFormat,
80+
FormatArgOffset, ConverterConfig,
81+
getLangOpts());
82+
const Expr *StrFormatCall = StrFormat->getCallee();
83+
if (!Converter.canApply()) {
84+
diag(StrFormat->getBeginLoc(),
85+
"unable to use '%0' instead of %1 because %2")
86+
<< StrFormatCall->getSourceRange() << ReplacementFormatFunction
87+
<< OldFunction->getIdentifier()
88+
<< Converter.conversionNotPossibleReason();
89+
return;
90+
}
91+
92+
DiagnosticBuilder Diag =
93+
diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1")
94+
<< ReplacementFormatFunction << OldFunction->getIdentifier();
95+
Diag << FixItHint::CreateReplacement(
96+
CharSourceRange::getTokenRange(StrFormatCall->getSourceRange()),
97+
ReplacementFormatFunction);
98+
Converter.applyFixes(Diag, *Result.SourceManager);
99+
100+
if (MaybeHeaderToInclude)
101+
Diag << IncludeInserter.createIncludeInsertion(
102+
Result.Context->getSourceManager().getFileID(
103+
StrFormatCall->getBeginLoc()),
104+
*MaybeHeaderToInclude);
105+
}
106+
107+
} // namespace clang::tidy::modernize
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===--- UseStdFormatCheck.h - clang-tidy -----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
#include "../utils/IncludeInserter.h"
14+
15+
namespace clang::tidy::modernize {
16+
17+
/// Converts calls to absl::StrFormat, or other functions via configuration
18+
/// options, to C++20's std::format, or another function via a configuration
19+
/// option, modifying the format string appropriately and removing
20+
/// now-unnecessary calls to std::string::c_str() and std::string::data().
21+
///
22+
/// For the user-facing documentation see:
23+
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize/use-std-format.html
24+
class UseStdFormatCheck : public ClangTidyCheck {
25+
public:
26+
UseStdFormatCheck(StringRef Name, ClangTidyContext *Context);
27+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28+
if (ReplacementFormatFunction == "std::format")
29+
return LangOpts.CPlusPlus20;
30+
return LangOpts.CPlusPlus;
31+
}
32+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
33+
Preprocessor *ModuleExpanderPP) override;
34+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
35+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
36+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
37+
std::optional<TraversalKind> getCheckTraversalKind() const override {
38+
return TK_IgnoreUnlessSpelledInSource;
39+
}
40+
41+
private:
42+
bool StrictMode;
43+
std::vector<StringRef> StrFormatLikeFunctions;
44+
StringRef ReplacementFormatFunction;
45+
utils::IncludeInserter IncludeInserter;
46+
std::optional<StringRef> MaybeHeaderToInclude;
47+
};
48+
49+
} // namespace clang::tidy::modernize
50+
51+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H

clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ void UseStdPrintCheck::check(const MatchFinder::MatchResult &Result) {
129129
FormatArgOffset = 1;
130130
}
131131

132+
utils::FormatStringConverter::Configuration ConverterConfig;
133+
ConverterConfig.StrictMode = StrictMode;
134+
ConverterConfig.AllowTrailingNewlineRemoval = true;
132135
utils::FormatStringConverter Converter(
133-
Result.Context, Printf, FormatArgOffset, StrictMode, getLangOpts());
136+
Result.Context, Printf, FormatArgOffset, ConverterConfig, getLangOpts());
134137
const Expr *PrintfCall = Printf->getCallee();
135138
const StringRef ReplacementFunction = Converter.usePrintNewlineFunction()
136139
? ReplacementPrintlnFunction

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static bool containsDeclInScope(const Stmt *Node) {
113113
}
114114

115115
static void removeElseAndBrackets(DiagnosticBuilder &Diag, ASTContext &Context,
116-
const Stmt *Else, SourceLocation ElseLoc) {
116+
const Stmt *Else, SourceLocation ElseLoc) {
117117
auto Remap = [&](SourceLocation Loc) {
118118
return Context.getSourceManager().getExpansionLoc(Loc);
119119
};
@@ -172,7 +172,7 @@ void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
172172
breakStmt().bind(InterruptingStr), cxxThrowExpr().bind(InterruptingStr)));
173173
Finder->addMatcher(
174174
compoundStmt(
175-
forEach(ifStmt(unless(isConstexpr()),
175+
forEach(ifStmt(unless(isConstexpr()), unless(isConsteval()),
176176
hasThen(stmt(
177177
anyOf(InterruptsControlFlow,
178178
compoundStmt(has(InterruptsControlFlow))))),

0 commit comments

Comments
 (0)