Skip to content

Commit

Permalink
Merged master:a0749842509 into amd-gfx:6fd999d7d0b
Browse files Browse the repository at this point in the history
Local branch amd-gfx 6fd999d Merged master:64363a9d930 into amd-gfx:f6f83e6c43a
Remote branch master a074984 [MIR] Speedup parsing of function with large number of basic blocks
  • Loading branch information
Sw authored and Sw committed Jul 8, 2020
2 parents 6fd999d + a074984 commit 337c021
Show file tree
Hide file tree
Showing 59 changed files with 2,969 additions and 752 deletions.
14 changes: 9 additions & 5 deletions clang-tools-extra/clangd/RIFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,29 @@

#include "RIFF.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"

namespace clang {
namespace clangd {
namespace riff {

static llvm::Error makeError(const char *Msg) {
return llvm::createStringError(llvm::inconvertibleErrorCode(), Msg);
static llvm::Error makeError(const llvm::Twine &Msg) {
return llvm::make_error<llvm::StringError>(Msg,
llvm::inconvertibleErrorCode());
}

llvm::Expected<Chunk> readChunk(llvm::StringRef &Stream) {
if (Stream.size() < 8)
return makeError("incomplete chunk header");
return makeError("incomplete chunk header: " + llvm::Twine(Stream.size()) +
" bytes available");
Chunk C;
std::copy(Stream.begin(), Stream.begin() + 4, C.ID.begin());
Stream = Stream.drop_front(4);
uint32_t Len = llvm::support::endian::read32le(Stream.take_front(4).begin());
Stream = Stream.drop_front(4);
if (Stream.size() < Len)
return makeError("truncated chunk");
return makeError("truncated chunk: want " + llvm::Twine(Len) + ", got " +
llvm::Twine(Stream.size()));
C.Data = Stream.take_front(Len);
Stream = Stream.drop_front(Len);
if (Len % 2 & !Stream.empty()) { // Skip padding byte.
Expand All @@ -53,7 +57,7 @@ llvm::Expected<File> readFile(llvm::StringRef Stream) {
if (!RIFF)
return RIFF.takeError();
if (RIFF->ID != fourCC("RIFF"))
return makeError("not a RIFF container");
return makeError("not a RIFF container: root is " + fourCCStr(RIFF->ID));
if (RIFF->Data.size() < 4)
return makeError("RIFF chunk too short");
File F;
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/RIFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ using FourCC = std::array<char, 4>;
inline constexpr FourCC fourCC(const char (&Literal)[5]) {
return FourCC{{Literal[0], Literal[1], Literal[2], Literal[3]}};
}
inline constexpr llvm::StringRef fourCCStr(const FourCC &Data) {
return llvm::StringRef(&Data[0], Data.size());
}
// A chunk is a section in a RIFF container.
struct Chunk {
FourCC ID;
Expand Down
21 changes: 13 additions & 8 deletions clang-tools-extra/clangd/index/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,20 +426,25 @@ llvm::Expected<IndexFileIn> readRIFF(llvm::StringRef Data) {
if (!RIFF)
return RIFF.takeError();
if (RIFF->Type != riff::fourCC("CdIx"))
return makeError("wrong RIFF type");
return makeError("wrong RIFF filetype: " + riff::fourCCStr(RIFF->Type));
llvm::StringMap<llvm::StringRef> Chunks;
for (const auto &Chunk : RIFF->Chunks)
Chunks.try_emplace(llvm::StringRef(Chunk.ID.data(), Chunk.ID.size()),
Chunk.Data);

for (llvm::StringRef RequiredChunk : {"meta", "stri"})
if (!Chunks.count("meta"))
return makeError("missing meta chunk");
Reader Meta(Chunks.lookup("meta"));
auto SeenVersion = Meta.consume32();
if (SeenVersion != Version)
return makeError("wrong version: want " + llvm::Twine(Version) + ", got " +
llvm::Twine(SeenVersion));

// meta chunk is checked above, as we prefer the "version mismatch" error.
for (llvm::StringRef RequiredChunk : {"stri"})
if (!Chunks.count(RequiredChunk))
return makeError("missing required chunk " + RequiredChunk);

Reader Meta(Chunks.lookup("meta"));
if (Meta.consume32() != Version)
return makeError("wrong version");

auto Strings = readStringTable(Chunks.lookup("stri"));
if (!Strings)
return Strings.takeError();
Expand Down Expand Up @@ -665,7 +670,7 @@ std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename,
trace::Span OverallTracer("LoadIndex");
auto Buffer = llvm::MemoryBuffer::getFile(SymbolFilename);
if (!Buffer) {
elog("Can't open {0}", SymbolFilename);
elog("Can't open {0}: {1}", SymbolFilename, Buffer.getError().message());
return nullptr;
}

Expand All @@ -682,7 +687,7 @@ std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename,
if (I->Relations)
Relations = std::move(*I->Relations);
} else {
elog("Bad Index: {0}", I.takeError());
elog("Bad index file: {0}", I.takeError());
return nullptr;
}
}
Expand Down
36 changes: 35 additions & 1 deletion clang-tools-extra/clangd/tool/ClangdMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ opt<bool> Test{
"lit-test",
cat(Misc),
desc("Abbreviation for -input-style=delimited -pretty -sync "
"-enable-test-scheme -log=verbose. "
"-enable-test-scheme -enable-config=0 -log=verbose. "
"Intended to simplify lit tests"),
init(false),
Hidden,
Expand Down Expand Up @@ -427,6 +427,20 @@ opt<bool> AsyncPreamble{
Hidden,
};

opt<bool> EnableConfig{
"enable-config",
cat(Misc),
desc(
"Read user and project configuration from YAML files.\n"
"Project config is from a .clangd file in the project directory.\n"
"User config is from clangd/config.yaml in the following directories:\n"
"\tWindows: %USERPROFILE%\\AppData\\Local\n"
"\tMac OS: ~/Library/Preferences/\n"
"\tOthers: $XDG_CONFIG_HOME, usually ~/.config\n"
"Configuration is documented at https://clangd.llvm.org/config.html"),
init(false),
};

/// Supports a test URI scheme with relaxed constraints for lit tests.
/// The path in a test URI will be combined with a platform-specific fake
/// directory to form an absolute path. For example, test:///a.cpp is resolved
Expand Down Expand Up @@ -510,6 +524,9 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
InputStyle = JSONStreamStyle::Delimited;
LogLevel = Logger::Verbose;
PrettyPrint = true;
// Disable config system by default to avoid external reads.
if (!EnableConfig.getNumOccurrences())
EnableConfig = false;
// Disable background index on lit tests by default to prevent disk writes.
if (!EnableBackgroundIndex.getNumOccurrences())
EnableBackgroundIndex = false;
Expand Down Expand Up @@ -677,6 +694,23 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
CCOpts.RunParser = CodeCompletionParse;

RealThreadsafeFS TFS;
std::unique_ptr<config::Provider> Config;
if (EnableConfig) {
std::vector<std::unique_ptr<config::Provider>> ProviderStack;
ProviderStack.push_back(
config::Provider::fromAncestorRelativeYAMLFiles(".clangd", TFS));
llvm::SmallString<256> UserConfig;
if (llvm::sys::path::user_config_directory(UserConfig)) {
llvm::sys::path::append(UserConfig, "clangd", "config.yaml");
vlog("User config file is {0}", UserConfig);
ProviderStack.push_back(config::Provider::fromYAMLFile(UserConfig, TFS));
} else {
elog("Couldn't determine user config file, not loading");
}
Config = config::Provider::combine(std::move(ProviderStack));
Opts.ConfigProvider = Config.get();
}

// Initialize and run ClangdLSPServer.
// Change stdin to binary to not lose \r\n on windows.
llvm::sys::ChangeStdinToBinary();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
Address address = Address::invalid();
Address AllocaAddr = Address::invalid();
Address OpenMPLocalAddr = Address::invalid();
if (CGM.getOpenMPIRBuilder())
if (CGM.getLangOpts().OpenMPIRBuilder)
OpenMPLocalAddr = OMPBuilderCBHelpers::getAddressOfLocalVariable(*this, &D);
else
OpenMPLocalAddr =
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,7 @@ EmitBitCastOfLValueToProperType(CodeGenFunction &CGF,
static LValue EmitThreadPrivateVarDeclLValue(
CodeGenFunction &CGF, const VarDecl *VD, QualType T, Address Addr,
llvm::Type *RealVarTy, SourceLocation Loc) {
if (CGF.CGM.getOpenMPIRBuilder())
if (CGF.CGM.getLangOpts().OpenMPIRBuilder)
Addr = CodeGenFunction::OMPBuilderCBHelpers::getAddrOfThreadPrivate(
CGF, VD, Addr, Loc);
else
Expand Down
Loading

0 comments on commit 337c021

Please sign in to comment.