Skip to content

Commit e6ec92c

Browse files
rebase
Created using spr 1.3.6
2 parents d0e5bce + 984c352 commit e6ec92c

File tree

974 files changed

+32018
-20322
lines changed

Some content is hidden

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

974 files changed

+32018
-20322
lines changed

bolt/include/bolt/Profile/DataAggregator.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,6 @@ class DataAggregator : public DataReader {
502502
/// entries).
503503
void imputeFallThroughs();
504504

505-
/// Register profiled functions for lite mode.
506-
void registerProfiledFunctions();
507-
508505
/// Debugging dump methods
509506
void dump() const;
510507
void dump(const PerfBranchSample &Sample) const;

bolt/lib/Passes/FrameOptimizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ Error FrameOptimizerPass::runOnFunctions(BinaryContext &BC) {
224224
if (opts::FrameOptimization == FOP_NONE)
225225
return Error::success();
226226

227+
if (!BC.isX86()) {
228+
BC.errs() << "BOLT-ERROR: " << getName() << " is supported only on X86\n";
229+
exit(1);
230+
}
231+
227232
std::unique_ptr<BinaryFunctionCallGraph> CG;
228233
std::unique_ptr<FrameAnalysis> FA;
229234
std::unique_ptr<RegAnalysis> RA;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -581,26 +581,6 @@ void DataAggregator::imputeFallThroughs() {
581581
outs() << "BOLT-INFO: imputed " << InferredTraces << " traces\n";
582582
}
583583

584-
void DataAggregator::registerProfiledFunctions() {
585-
DenseSet<uint64_t> Addrs;
586-
for (const auto &Trace : llvm::make_first_range(Traces)) {
587-
if (Trace.Branch != Trace::FT_ONLY &&
588-
Trace.Branch != Trace::FT_EXTERNAL_ORIGIN)
589-
Addrs.insert(Trace.Branch);
590-
Addrs.insert(Trace.From);
591-
}
592-
593-
for (const auto [PC, _] : BasicSamples)
594-
Addrs.insert(PC);
595-
596-
for (const PerfMemSample &MemSample : MemSamples)
597-
Addrs.insert(MemSample.PC);
598-
599-
for (const uint64_t Addr : Addrs)
600-
if (BinaryFunction *Func = getBinaryFunctionContainingAddress(Addr))
601-
Func->setHasProfileAvailable();
602-
}
603-
604584
Error DataAggregator::preprocessProfile(BinaryContext &BC) {
605585
this->BC = &BC;
606586

@@ -623,7 +603,6 @@ Error DataAggregator::preprocessProfile(BinaryContext &BC) {
623603
exit(0);
624604
}
625605

626-
registerProfiledFunctions();
627606
return Error::success();
628607
}
629608

@@ -1368,6 +1347,10 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13681347
}
13691348

13701349
const uint64_t FromOffset = Addr[0]->Offset;
1350+
BinaryFunction *FromFunc = getBinaryFunctionContainingAddress(FromOffset);
1351+
if (FromFunc)
1352+
FromFunc->setHasProfileAvailable();
1353+
13711354
int64_t Count = Counters[0];
13721355
int64_t Mispreds = Counters[1];
13731356

@@ -1378,6 +1361,11 @@ std::error_code DataAggregator::parseAggregatedLBREntry() {
13781361
return std::error_code();
13791362
}
13801363

1364+
const uint64_t ToOffset = Addr[1]->Offset;
1365+
BinaryFunction *ToFunc = getBinaryFunctionContainingAddress(ToOffset);
1366+
if (ToFunc)
1367+
ToFunc->setHasProfileAvailable();
1368+
13811369
/// For fall-through types, adjust locations to match Trace container.
13821370
if (Type == FT || Type == FT_EXTERNAL_ORIGIN || Type == FT_EXTERNAL_RETURN) {
13831371
Addr[2] = Location(Addr[1]->Offset); // Trace To
@@ -1625,6 +1613,9 @@ std::error_code DataAggregator::parseBranchEvents() {
16251613
Traces.reserve(TraceMap.size());
16261614
for (const auto &[Trace, Info] : TraceMap) {
16271615
Traces.emplace_back(Trace, Info);
1616+
for (const uint64_t Addr : {Trace.Branch, Trace.From})
1617+
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Addr))
1618+
BF->setHasProfileAvailable();
16281619
}
16291620
clear(TraceMap);
16301621

@@ -1685,6 +1676,9 @@ std::error_code DataAggregator::parseBasicEvents() {
16851676
continue;
16861677
++NumTotalSamples;
16871678

1679+
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
1680+
BF->setHasProfileAvailable();
1681+
16881682
++BasicSamples[Sample->PC];
16891683
EventNames.insert(Sample->EventName);
16901684
}
@@ -1722,6 +1716,9 @@ std::error_code DataAggregator::parseMemEvents() {
17221716
if (std::error_code EC = Sample.getError())
17231717
return EC;
17241718

1719+
if (BinaryFunction *BF = getBinaryFunctionContainingAddress(Sample->PC))
1720+
BF->setHasProfileAvailable();
1721+
17251722
MemSamples.emplace_back(std::move(Sample.get()));
17261723
}
17271724

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Checks that non-fully supported passes on AArch64 are handled appropriately.
2+
3+
// REQUIRES: system-linux,asserts,target=aarch64{{.*}}
4+
5+
RUN: %clang %cflags %p/../Inputs/hello.c -o %t -Wl,-q
6+
RUN: not llvm-bolt %t -o %t.bolt --frame-opt=all 2>&1 | FileCheck %s
7+
8+
CHECK: BOLT-ERROR: frame-optimizer is supported only on X86

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,22 @@ bool NarrowingConversionsCheck::handleConditionalOperator(
555555
// We have an expression like so: `output = cond ? lhs : rhs`
556556
// From the point of view of narrowing conversion we treat it as two
557557
// expressions `output = lhs` and `output = rhs`.
558-
handleBinaryOperator(Context, CO->getLHS()->getExprLoc(), Lhs,
559-
*CO->getLHS());
560-
handleBinaryOperator(Context, CO->getRHS()->getExprLoc(), Lhs,
561-
*CO->getRHS());
558+
handleConditionalOperatorArgument(Context, Lhs, CO->getLHS());
559+
handleConditionalOperatorArgument(Context, Lhs, CO->getRHS());
562560
return true;
563561
}
564562
return false;
565563
}
566564

565+
void NarrowingConversionsCheck::handleConditionalOperatorArgument(
566+
const ASTContext &Context, const Expr &Lhs, const Expr *Arg) {
567+
if (const auto *ICE = llvm::dyn_cast<ImplicitCastExpr>(Arg))
568+
if (!Arg->getIntegerConstantExpr(Context))
569+
Arg = ICE->getSubExpr();
570+
571+
handleBinaryOperator(Context, Arg->getExprLoc(), Lhs, *Arg);
572+
}
573+
567574
void NarrowingConversionsCheck::handleImplicitCast(
568575
const ASTContext &Context, const ImplicitCastExpr &Cast) {
569576
if (Cast.getExprLoc().isMacroID())

clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
8585
bool handleConditionalOperator(const ASTContext &Context, const Expr &Lhs,
8686
const Expr &Rhs);
8787

88+
void handleConditionalOperatorArgument(const ASTContext &Context,
89+
const Expr &Lhs, const Expr *Arg);
8890
void handleImplicitCast(const ASTContext &Context,
8991
const ImplicitCastExpr &Cast);
9092

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ add_clang_library(clangDaemon STATIC
108108
SemanticHighlighting.cpp
109109
SemanticSelection.cpp
110110
SourceCode.cpp
111+
SymbolDocumentation.cpp
111112
SystemIncludeExtractor.cpp
112113
TidyProvider.cpp
113114
TUScheduler.cpp

clang-tools-extra/clangd/CodeCompletionStrings.cpp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "CodeCompletionStrings.h"
10+
#include "Config.h"
11+
#include "SymbolDocumentation.h"
1012
#include "clang-c/Index.h"
1113
#include "clang/AST/ASTContext.h"
14+
#include "clang/AST/Comment.h"
15+
#include "clang/AST/Decl.h"
1216
#include "clang/AST/RawCommentList.h"
1317
#include "clang/Basic/SourceManager.h"
1418
#include "clang/Sema/CodeCompleteConsumer.h"
1519
#include "llvm/Support/Compiler.h"
1620
#include "llvm/Support/JSON.h"
21+
#include "llvm/Support/raw_ostream.h"
1722
#include <limits>
1823
#include <utility>
1924

@@ -100,16 +105,51 @@ std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl) {
100105
// the comments for namespaces.
101106
return "";
102107
}
103-
const RawComment *RC = getCompletionComment(Ctx, &Decl);
104-
if (!RC)
105-
return "";
106-
// Sanity check that the comment does not come from the PCH. We choose to not
107-
// write them into PCH, because they are racy and slow to load.
108-
assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
109-
std::string Doc =
110-
RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
111-
if (!looksLikeDocComment(Doc))
112-
return "";
108+
109+
const RawComment *RC = nullptr;
110+
const Config &Cfg = Config::current();
111+
112+
std::string Doc;
113+
114+
if (Cfg.Documentation.CommentFormat == Config::CommentFormatPolicy::Doxygen &&
115+
isa<ParmVarDecl>(Decl)) {
116+
// Parameters are documented in their declaration context (function or
117+
// template function).
118+
const NamedDecl *ND = dyn_cast<NamedDecl>(Decl.getDeclContext());
119+
if (!ND)
120+
return "";
121+
122+
RC = getCompletionComment(Ctx, ND);
123+
if (!RC)
124+
return "";
125+
126+
// Sanity check that the comment does not come from the PCH. We choose to
127+
// not write them into PCH, because they are racy and slow to load.
128+
assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
129+
130+
comments::FullComment *FC = RC->parse(Ctx, /*PP=*/nullptr, ND);
131+
if (!FC)
132+
return "";
133+
134+
SymbolDocCommentVisitor V(FC, Ctx.getLangOpts().CommentOpts);
135+
std::string RawDoc;
136+
llvm::raw_string_ostream OS(RawDoc);
137+
138+
V.parameterDocToString(dyn_cast<ParmVarDecl>(&Decl)->getName(), OS);
139+
140+
Doc = StringRef(RawDoc).trim().str();
141+
} else {
142+
RC = getCompletionComment(Ctx, &Decl);
143+
if (!RC)
144+
return "";
145+
// Sanity check that the comment does not come from the PCH. We choose to
146+
// not write them into PCH, because they are racy and slow to load.
147+
assert(!Ctx.getSourceManager().isLoadedSourceLocation(RC->getBeginLoc()));
148+
Doc = RC->getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics());
149+
if (!looksLikeDocComment(Doc))
150+
return "";
151+
}
152+
113153
// Clang requires source to be UTF-8, but doesn't enforce this in comments.
114154
if (!llvm::json::isUTF8(Doc))
115155
Doc = llvm::json::fixUTF8(Doc);

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,15 @@ struct Fragment {
315315
/// AngledHeaders (i.e. a header matches a regex in both QuotedHeaders and
316316
/// AngledHeaders), system headers use <> and non-system headers use "".
317317
/// These can match any suffix of the header file in question.
318-
/// Matching is performed against the header text, not its absolute path
318+
/// Matching is performed against the absolute path of the header
319319
/// within the project.
320320
std::vector<Located<std::string>> QuotedHeaders;
321321
/// List of regexes for headers that should always be included with a
322322
/// <>-style include. By default, and in case of a conflict with
323323
/// AngledHeaders (i.e. a header matches a regex in both QuotedHeaders and
324324
/// AngledHeaders), system headers use <> and non-system headers use "".
325325
/// These can match any suffix of the header file in question.
326-
/// Matching is performed against the header text, not its absolute path
326+
/// Matching is performed against the absolute path of the header
327327
/// within the project.
328328
std::vector<Located<std::string>> AngledHeaders;
329329
};

clang-tools-extra/clangd/Headers.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,17 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader,
304304
// FIXME: should we allow (some limited number of) "../header.h"?
305305
if (llvm::sys::path::is_absolute(Suggested))
306306
return std::nullopt;
307+
auto HeaderPath = llvm::sys::path::convert_to_slash(InsertedHeader.File);
307308
bool IsAngled = false;
308309
for (auto &Filter : AngledHeaders) {
309-
if (Filter(Suggested)) {
310+
if (Filter(HeaderPath)) {
310311
IsAngled = true;
311312
break;
312313
}
313314
}
314315
bool IsQuoted = false;
315316
for (auto &Filter : QuotedHeaders) {
316-
if (Filter(Suggested)) {
317+
if (Filter(HeaderPath)) {
317318
IsQuoted = true;
318319
break;
319320
}
@@ -324,7 +325,7 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader,
324325
if (IsAngled && IsQuoted) {
325326
elog("Header '{0}' matches both quoted and angled regexes, default will "
326327
"be used.",
327-
Suggested);
328+
HeaderPath);
328329
}
329330
IsAngled = IsAngledByDefault;
330331
}

0 commit comments

Comments
 (0)