Skip to content

Commit

Permalink
Merged main:c4fc8a21d1db into amd-gfx:c1b970ee7769
Browse files Browse the repository at this point in the history
Local branch amd-gfx c1b970e Merged main:554eb1f6dc49 into amd-gfx:1a3dda5a9257
Remote branch main c4fc8a2 [clang-format] NFC keep the code clang-formatted
  • Loading branch information
Sw authored and Sw committed Dec 22, 2020
2 parents c1b970e + c4fc8a2 commit 30a3e79
Show file tree
Hide file tree
Showing 322 changed files with 67,094 additions and 4,747 deletions.
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ if (NOT DEFINED CLANGD_BUILD_XPC)
unset(CLANGD_BUILD_XPC_DEFAULT)
endif ()

option(CLANGD_MALLOC_TRIM "Call malloc_trim(3) periodically in Clangd. (only takes effect when using glibc)" ON)

llvm_canonicalize_cmake_booleans(
CLANGD_BUILD_XPC
CLANGD_ENABLE_REMOTE
CLANGD_MALLOC_TRIM
LLVM_ENABLE_ZLIB
)

Expand Down
32 changes: 30 additions & 2 deletions clang-tools-extra/clangd/ClangdLSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
} else if (auto Handler = Notifications.lookup(Method)) {
Handler(std::move(Params));
Server.maybeExportMemoryProfile();
Server.maybeCleanupMemory();
} else {
log("unhandled notification {0}", Method);
}
Expand Down Expand Up @@ -453,6 +454,7 @@ void ClangdLSPServer::callRaw(StringRef Method, llvm::json::Value Params,

void ClangdLSPServer::notify(llvm::StringRef Method, llvm::json::Value Params) {
log("--> {0}", Method);
maybeCleanupMemory();
std::lock_guard<std::mutex> Lock(TranspWriter);
Transp.notify(Method, std::move(Params));
}
Expand Down Expand Up @@ -1301,6 +1303,27 @@ void ClangdLSPServer::maybeExportMemoryProfile() {
NextProfileTime = Now + ProfileInterval;
}

void ClangdLSPServer::maybeCleanupMemory() {
// Memory cleanup is probably expensive, throttle it
static constexpr auto MemoryCleanupInterval = std::chrono::minutes(1);

if (!Opts.MemoryCleanup)
return;

// FIXME: this can probably be done without a mutex
// and the logic could be shared with maybeExportMemoryProfile
{
auto Now = std::chrono::steady_clock::now();
std::lock_guard<std::mutex> Lock(NextMemoryCleanupTimeMutex);
if (Now < NextMemoryCleanupTime)
return;
NextMemoryCleanupTime = Now + MemoryCleanupInterval;
}

vlog("Calling memory cleanup callback");
Opts.MemoryCleanup();
}

// FIXME: This function needs to be properly tested.
void ClangdLSPServer::onChangeConfiguration(
const DidChangeConfigurationParams &Params) {
Expand Down Expand Up @@ -1507,8 +1530,9 @@ ClangdLSPServer::ClangdLSPServer(class Transport &Transp,
MsgHandler->bind("textDocument/foldingRange", &ClangdLSPServer::onFoldingRange);
// clang-format on

// Delay first profile until we've finished warming up.
NextProfileTime = std::chrono::steady_clock::now() + std::chrono::minutes(1);
// Delay first profile and memory cleanup until we've finished warming up.
NextMemoryCleanupTime = NextProfileTime =
std::chrono::steady_clock::now() + std::chrono::minutes(1);
}

ClangdLSPServer::~ClangdLSPServer() {
Expand Down Expand Up @@ -1621,6 +1645,10 @@ void ClangdLSPServer::onDiagnosticsReady(PathRef File, llvm::StringRef Version,
void ClangdLSPServer::onBackgroundIndexProgress(
const BackgroundQueue::Stats &Stats) {
static const char ProgressToken[] = "backgroundIndexProgress";

// The background index did some work, maybe we need to cleanup
maybeCleanupMemory();

std::lock_guard<std::mutex> Lock(BackgroundIndexProgressMutex);

auto NotifyProgress = [this](const BackgroundQueue::Stats &Stats) {
Expand Down
11 changes: 11 additions & 0 deletions clang-tools-extra/clangd/ClangdLSPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
llvm::Optional<Path> CompileCommandsDir;
/// The offset-encoding to use, or None to negotiate it over LSP.
llvm::Optional<OffsetEncoding> Encoding;
/// If set, periodically called to release memory.
/// Consider malloc_trim(3)
std::function<void()> MemoryCleanup = nullptr;

/// Per-feature options. Generally ClangdServer lets these vary
/// per-request, but LSP allows limited/no customizations.
Expand Down Expand Up @@ -184,10 +187,18 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
/// profiling hasn't happened recently.
void maybeExportMemoryProfile();

/// Run the MemoryCleanup callback if it's time.
/// This method is thread safe.
void maybeCleanupMemory();

/// Timepoint until which profiling is off. It is used to throttle profiling
/// requests.
std::chrono::steady_clock::time_point NextProfileTime;

/// Next time we want to call the MemoryCleanup callback.
std::mutex NextMemoryCleanupTimeMutex;
std::chrono::steady_clock::time_point NextMemoryCleanupTime;

/// Since initialization of CDBs and ClangdServer is done lazily, the
/// following context captures the one used while creating ClangdLSPServer and
/// passes it to above mentioned object instances to make sure they share the
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void ClangdServer::typeHierarchy(PathRef File, Position Pos, int Resolve,
File));
};

WorkScheduler.runWithAST("Type Hierarchy", File, std::move(Action));
WorkScheduler.runWithAST("TypeHierarchy", File, std::move(Action));
}

void ClangdServer::resolveTypeHierarchy(
Expand All @@ -642,7 +642,7 @@ void ClangdServer::prepareCallHierarchy(
return CB(InpAST.takeError());
CB(clangd::prepareCallHierarchy(InpAST->AST, Pos, File));
};
WorkScheduler.runWithAST("Call Hierarchy", File, std::move(Action));
WorkScheduler.runWithAST("CallHierarchy", File, std::move(Action));
}

void ClangdServer::incomingCalls(
Expand Down Expand Up @@ -678,7 +678,7 @@ void ClangdServer::documentSymbols(llvm::StringRef File,
return CB(InpAST.takeError());
CB(clangd::getDocumentSymbols(InpAST->AST));
};
WorkScheduler.runWithAST("documentSymbols", File, std::move(Action),
WorkScheduler.runWithAST("DocumentSymbols", File, std::move(Action),
TUScheduler::InvalidateOnUpdate);
}

Expand All @@ -690,7 +690,7 @@ void ClangdServer::foldingRanges(llvm::StringRef File,
return CB(InpAST.takeError());
CB(clangd::getFoldingRanges(InpAST->AST));
};
WorkScheduler.runWithAST("foldingRanges", File, std::move(Action),
WorkScheduler.runWithAST("FoldingRanges", File, std::move(Action),
TUScheduler::InvalidateOnUpdate);
}

Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/Features.inc.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@
#define CLANGD_MALLOC_TRIM @CLANGD_MALLOC_TRIM@
11 changes: 6 additions & 5 deletions clang-tools-extra/clangd/JSONTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ class JSONTransport : public Transport {
bool handleMessage(llvm::json::Value Message, MessageHandler &Handler);
// Writes outgoing message to Out stream.
void sendMessage(llvm::json::Value Message) {
std::string S;
llvm::raw_string_ostream OS(S);
OutputBuffer.clear();
llvm::raw_svector_ostream OS(OutputBuffer);
OS << llvm::formatv(Pretty ? "{0:2}" : "{0}", Message);
OS.flush();
Out << "Content-Length: " << S.size() << "\r\n\r\n" << S;
Out << "Content-Length: " << OutputBuffer.size() << "\r\n\r\n"
<< OutputBuffer;
Out.flush();
vlog(">>> {0}\n", S);
vlog(">>> {0}\n", OutputBuffer);
}

// Read raw string messages from input stream.
Expand All @@ -143,6 +143,7 @@ class JSONTransport : public Transport {
llvm::Optional<std::string> readDelimitedMessage();
llvm::Optional<std::string> readStandardMessage();

llvm::SmallVector<char, 0> OutputBuffer;
std::FILE *In;
llvm::raw_ostream &Out;
llvm::raw_ostream &InMirror;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/TUScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ std::string renderTUAction(const PreambleAction PA, const ASTAction &AA) {
}
if (Result.empty())
return "idle";
return llvm::join(Result, ",");
return llvm::join(Result, ", ");
}

} // namespace
Expand Down
28 changes: 28 additions & 0 deletions clang-tools-extra/clangd/tool/ClangdMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#include <unistd.h>
#endif

#ifdef __GLIBC__
#include <malloc.h>
#endif

namespace clang {
namespace clangd {

Expand Down Expand Up @@ -497,6 +501,29 @@ opt<bool> CollectMainFileRefs{
init(ClangdServer::Options().CollectMainFileRefs),
};

#if defined(__GLIBC__) && CLANGD_MALLOC_TRIM
opt<bool> EnableMallocTrim{
"malloc-trim",
cat(Misc),
desc("Release memory periodically via malloc_trim(3)."),
init(true),
};

std::function<void()> getMemoryCleanupFunction() {
if (!EnableMallocTrim)
return nullptr;
// Leave a few MB at the top of the heap: it is insignificant
// and will most likely be needed by the main thread
constexpr size_t MallocTrimPad = 20'000'000;
return []() {
if (malloc_trim(MallocTrimPad))
vlog("Released memory via malloc_trim");
};
}
#else
std::function<void()> getMemoryCleanupFunction() { return nullptr; }
#endif

#if CLANGD_ENABLE_REMOTE
opt<std::string> RemoteIndexAddress{
"remote-index-address",
Expand Down Expand Up @@ -797,6 +824,7 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
Opts.BuildRecoveryAST = RecoveryAST;
Opts.PreserveRecoveryASTType = RecoveryASTType;
Opts.FoldingRanges = FoldingRanges;
Opts.MemoryCleanup = getMemoryCleanupFunction();

Opts.CodeComplete.IncludeIneligibleResults = IncludeIneligibleResults;
Opts.CodeComplete.Limit = LimitResults;
Expand Down
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ Modified Compiler Flags
`-fno-delete-null-pointer-checks` has gained the power to remove the
`nonnull` attribute on `this` for configurations that need it to be nullable.
- ``-gsplit-dwarf`` no longer implies ``-g2``.
- ``-fasynchronous-unwind-tables`` is now the default on Linux AArch64/PowerPC.
This behavior matches newer GCC.
(`D91760 <https://reviews.llvm.org/D91760>`_)
(`D92054 <https://reviews.llvm.org/D92054>`_)

Removed Compiler Flags
-------------------------
Expand Down
3 changes: 2 additions & 1 deletion clang/include/clang/AST/RecursiveASTVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ template <typename Derived> class RecursiveASTVisitor {
DEF_TRAVERSE_TMPL_INST(Function)
#undef DEF_TRAVERSE_TMPL_INST

bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);

private:
// These are helper methods used by more than one Traverse* method.
bool TraverseTemplateParameterListHelper(TemplateParameterList *TPL);
Expand Down Expand Up @@ -497,7 +499,6 @@ template <typename Derived> class RecursiveASTVisitor {
bool VisitOMPClauseWithPreInit(OMPClauseWithPreInit *Node);
bool VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *Node);

bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue);
bool PostVisitStmt(Stmt *S);
};

Expand Down
16 changes: 16 additions & 0 deletions clang/lib/ASTMatchers/ASTMatchFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,22 @@ class MatchASTVisitor : public RecursiveASTVisitor<MatchASTVisitor>,
bool TraverseConstructorInitializer(CXXCtorInitializer *CtorInit);
bool TraverseTemplateArgumentLoc(TemplateArgumentLoc TAL);

bool dataTraverseNode(Stmt *S, DataRecursionQueue *Queue) {
if (auto *RF = dyn_cast<CXXForRangeStmt>(S)) {
for (auto *SubStmt : RF->children()) {
if (SubStmt == RF->getInit() || SubStmt == RF->getLoopVarStmt() ||
SubStmt == RF->getRangeInit() || SubStmt == RF->getBody()) {
TraverseStmt(SubStmt, Queue);
} else {
ASTNodeNotSpelledInSourceScope RAII(this, true);
TraverseStmt(SubStmt, Queue);
}
}
return true;
}
return RecursiveASTVisitor<MatchASTVisitor>::dataTraverseNode(S, Queue);
}

// Matches children or descendants of 'Node' with 'BaseMatcher'.
bool memoizedMatchesRecursively(const DynTypedNode &Node, ASTContext &Ctx,
const DynTypedMatcher &Matcher,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/AMDGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
public:
AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
unsigned GetDefaultDwarfVersion() const override { return 5; }
unsigned GetDefaultDwarfVersion() const override { return 4; }
bool IsIntegratedAssemblerDefault() const override { return true; }
bool IsMathErrnoDefault() const override { return false; }

Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2674,6 +2674,9 @@ void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
bool Generic_GCC::IsUnwindTablesDefault(const ArgList &Args) const {
switch (getArch()) {
case llvm::Triple::aarch64:
case llvm::Triple::ppc:
case llvm::Triple::ppc64:
case llvm::Triple::ppc64le:
case llvm::Triple::x86_64:
return true;
default:
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/HIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LLVM_LIBRARY_VISIBILITY HIPToolChain final : public ROCMToolChain {
computeMSVCVersion(const Driver *D,
const llvm::opt::ArgList &Args) const override;

unsigned GetDefaultDwarfVersion() const override { return 5; }
unsigned GetDefaultDwarfVersion() const override { return 4; }

const ToolChain &HostTC;

Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Format/TokenAnnotator.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1964,9 +1964,9 @@ class AnnotatingParser {

if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
tok::comma, tok::semi, tok::kw_return, tok::colon,
tok::kw_co_return, tok::kw_co_await, tok::kw_co_yield,
tok::equal, tok::kw_delete, tok::kw_sizeof,
tok::kw_throw) ||
tok::kw_co_return, tok::kw_co_await,
tok::kw_co_yield, tok::equal, tok::kw_delete,
tok::kw_sizeof, tok::kw_throw) ||
PrevToken->isOneOf(TT_BinaryOperator, TT_ConditionalExpr,
TT_UnaryOperator, TT_CastRParen))
return TT_UnaryOperator;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Headers/cuda_wrappers/algorithm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===---- complex - CUDA wrapper for <algorithm> ----------------------------===
/*===---- algorithm - CUDA wrapper for <algorithm> -------------------------===
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Headers/cuda_wrappers/new
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===---- complex - CUDA wrapper for <new> ------------------------------===
/*===---- new - CUDA wrapper for <new> -------------------------------------===
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/amdgpu-toolchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// AS_LINK: clang{{.*}} "-cc1as"
// AS_LINK: ld.lld{{.*}} "-shared"

// DWARF_VER: "-dwarf-version=5"
// DWARF_VER: "-dwarf-version=4"

// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
// RUN: -flto %s 2>&1 | FileCheck -check-prefix=LTO %s
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/hip-toolchain-dwarf.hip
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
// RUN: -x hip --cuda-gpu-arch=gfx803 %s \
// RUN: -Xarch_gfx803 -g 2>&1 | FileCheck %s -check-prefix=DWARF_VER

// DWARF_VER: "-dwarf-version=5"
// DWARF_VER: "-dwarf-version=4"
12 changes: 7 additions & 5 deletions clang/test/Driver/ppc-features.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// Check default CC1 and linker options for ppc32.
// RUN: %clang -### -target powerpc-unknown-linux-gnu %s 2>&1 | FileCheck --check-prefix=PPC32 %s
// PPC32: "-mfloat-abi" "hard"
// PPC32: "-munwind-tables"
// PPC32-SAME: "-mfloat-abi" "hard"

// PPC32: "-m" "elf32ppclinux"

Expand Down Expand Up @@ -38,11 +39,12 @@


/// Check default CC1 and linker options for ppc64.
// RUN: %clang -### -target powerpc64le-unknown-linux-gnu %s 2>&1 | FileCheck --check-prefix=PPC64 %s
// RUN: %clang -### -target powerpc64-unknown-linux-gnu %s 2>&1 | FileCheck -check-prefix=PPC64BE %s
// PPC64: "-mfloat-abi" "hard"
// RUN: %clang -### -target powerpc64le-unknown-linux-gnu %s 2>&1 | FileCheck --check-prefixes=PPC64,PPC64LE %s
// RUN: %clang -### -target powerpc64-unknown-linux-gnu %s 2>&1 | FileCheck --check-prefixes=PPC64,PPC64BE %s
// PPC64: "-munwind-tables"
// PPC64-SAME: "-mfloat-abi" "hard"

// PPC64: "-m" "elf64lppc"
// PPC64LE: "-m" "elf64lppc"
// PPC64BE: "-m" "elf64ppc"

// check -msoft-float option for ppc64
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Frontend/plugin-attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ int var1 __attribute__((example("otherstring"))) = 1; // expected-warning {{'exa
class Example {
void __attribute__((example)) fn3(); // expected-error {{'example' attribute only allowed at file scope}}
};
void fn4() __attribute__((example(123))) { } // expected-error {{'example's first argument should be a string literal}}
void fn5() __attribute__((example("a","b", 3, 4.0))) { } // expected-error {{'example' attribute only allowed at most three arguments}}
void fn4() __attribute__((example(123))) { } // expected-error {{first argument to the 'example' attribute must be a string literal}}
void fn5() __attribute__((example("a","b", 3, 4.0))) { } // expected-error {{'example' attribute only accepts at most three arguments}}
3 changes: 0 additions & 3 deletions clang/tools/scan-view/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ set(BinFiles

set(ShareFiles
ScanView.py
Reporter.py
startfile.py
FileRadar.scpt
GetRadarVersion.scpt
bugcatcher.ico)

if(CLANG_INSTALL_SCANVIEW)
Expand Down
Binary file removed clang/tools/scan-view/share/FileRadar.scpt
Binary file not shown.
Empty file.
Loading

0 comments on commit 30a3e79

Please sign in to comment.