forked from GPUOpen-Drivers/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged main:202d359753d1 into amd-gfx:e2ab3cde433e
Local branch amd-gfx e2ab3cd Merged main:7c9c2a2ea5e3 into amd-gfx:357c325e0649 Remote branch main 202d359 [X86] Add the FSRM feature (Fast Short Rep Mov) to Zen3.
- Loading branch information
Showing
53 changed files
with
1,237 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//===--- ASTSignals.cpp ------------------------------------------*- C++-*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "ASTSignals.h" | ||
#include "AST.h" | ||
#include "FindTarget.h" | ||
|
||
namespace clang { | ||
namespace clangd { | ||
ASTSignals ASTSignals::derive(const ParsedAST &AST) { | ||
ASTSignals Signals; | ||
const SourceManager &SM = AST.getSourceManager(); | ||
findExplicitReferences(AST.getASTContext(), [&](ReferenceLoc Ref) { | ||
for (const NamedDecl *ND : Ref.Targets) { | ||
if (!isInsideMainFile(Ref.NameLoc, SM)) | ||
continue; | ||
SymbolID ID = getSymbolID(ND); | ||
if (!ID) | ||
continue; | ||
unsigned &SymbolCount = Signals.ReferencedSymbols[ID]; | ||
SymbolCount++; | ||
// Process namespace only when we see the symbol for the first time. | ||
if (SymbolCount != 1) | ||
continue; | ||
if (const auto *NSD = dyn_cast<NamespaceDecl>(ND->getDeclContext())) { | ||
if (NSD->isAnonymousNamespace()) | ||
continue; | ||
std::string NS = printNamespaceScope(*NSD); | ||
if (!NS.empty()) | ||
Signals.RelatedNamespaces[NS]++; | ||
} | ||
} | ||
}); | ||
return Signals; | ||
} | ||
} // namespace clangd | ||
} // namespace clang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===--- ASTSignals.h --------------------------------------------*- C++-*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_ASTSIGNALS_H | ||
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_ASTSIGNALS_H | ||
|
||
#include "ParsedAST.h" | ||
#include "index/SymbolID.h" | ||
#include "llvm/ADT/DenseMap.h" | ||
#include "llvm/ADT/StringMap.h" | ||
|
||
namespace clang { | ||
namespace clangd { | ||
|
||
/// Signals derived from a valid AST of a file. | ||
/// Provides information that can only be extracted from the AST to actions that | ||
/// can't access an AST. The signals are computed and updated asynchronously by | ||
/// the ASTWorker and thus they are always stale and also can be absent. | ||
/// Example usage: Information about the declarations used in a file affects | ||
/// code-completion ranking in that file. | ||
struct ASTSignals { | ||
/// Number of occurrences of each symbol present in the file. | ||
llvm::DenseMap<SymbolID, unsigned> ReferencedSymbols; | ||
/// Namespaces whose symbols are used in the file, and the number of such | ||
/// distinct symbols. | ||
llvm::StringMap<unsigned> RelatedNamespaces; | ||
|
||
static ASTSignals derive(const ParsedAST &AST); | ||
}; | ||
|
||
} // namespace clangd | ||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_ASTSIGNALS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===-- ASTSignalsTests.cpp -------------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "AST.h" | ||
|
||
#include "ParsedAST.h" | ||
#include "TestIndex.h" | ||
#include "TestTU.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
|
||
namespace clang { | ||
namespace clangd { | ||
namespace { | ||
|
||
using ::testing::_; | ||
using ::testing::Pair; | ||
using ::testing::UnorderedElementsAre; | ||
|
||
TEST(ASTSignals, Derive) { | ||
TestTU TU = TestTU::withCode(R"cpp( | ||
namespace ns1 { | ||
namespace ns2 { | ||
namespace { | ||
int func() { | ||
tar::X a; | ||
a.Y = 1; | ||
return ADD(tar::kConst, a.Y, tar::foo()) + fooInNS2() + tar::foo(); | ||
} | ||
} // namespace | ||
} // namespace ns2 | ||
} // namespace ns1 | ||
)cpp"); | ||
|
||
TU.HeaderCode = R"cpp( | ||
#define ADD(x, y, z) (x + y + z) | ||
namespace tar { // A related namespace. | ||
int kConst = 5; | ||
int foo(); | ||
void bar(); // Unused symbols are not recorded. | ||
class X { | ||
public: int Y; | ||
}; | ||
} // namespace tar | ||
namespace ns1::ns2 { int fooInNS2(); }} | ||
)cpp"; | ||
ASTSignals Signals = ASTSignals::derive(TU.build()); | ||
std::vector<std::pair<StringRef, int>> NS; | ||
for (const auto &P : Signals.RelatedNamespaces) | ||
NS.emplace_back(P.getKey(), P.getValue()); | ||
EXPECT_THAT(NS, UnorderedElementsAre(Pair("ns1::", 1), Pair("ns1::ns2::", 1), | ||
Pair("tar::", /*foo, kConst, X*/ 3))); | ||
|
||
std::vector<std::pair<SymbolID, int>> Sym; | ||
for (const auto &P : Signals.ReferencedSymbols) | ||
Sym.emplace_back(P.getFirst(), P.getSecond()); | ||
EXPECT_THAT( | ||
Sym, | ||
UnorderedElementsAre( | ||
Pair(ns("tar").ID, 4), Pair(ns("ns1").ID, 1), | ||
Pair(ns("ns1::ns2").ID, 1), Pair(_ /*int func();*/, 1), | ||
Pair(cls("tar::X").ID, 1), Pair(var("tar::kConst").ID, 1), | ||
Pair(func("tar::foo").ID, 2), Pair(func("ns1::ns2::fooInNS2").ID, 1), | ||
Pair(sym("Y", index::SymbolKind::Variable, "@N@tar@S@X@FI@\\0").ID, | ||
2), | ||
Pair(_ /*a*/, 3))); | ||
} | ||
} // namespace | ||
} // namespace clangd | ||
} // namespace clang |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.