Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from llvm:master #42

Merged
merged 6 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 9 additions & 30 deletions clang-tools-extra/clangd/index/IndexAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,30 +121,6 @@ struct IncludeGraphCollector : public PPCallbacks {
IncludeGraph &IG;
};

/// An ASTConsumer that instructs the parser to skip bodies of functions in the
/// files that should not be processed.
class SkipProcessedFunctions : public ASTConsumer {
public:
SkipProcessedFunctions(std::function<bool(FileID)> FileFilter)
: ShouldIndexFile(std::move(FileFilter)), Context(nullptr) {
assert(this->ShouldIndexFile);
}

void Initialize(ASTContext &Context) override { this->Context = &Context; }
bool shouldSkipFunctionBody(Decl *D) override {
assert(Context && "Initialize() was never called.");
auto &SM = Context->getSourceManager();
auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation()));
if (!FID.isValid())
return false;
return !ShouldIndexFile(FID);
}

private:
std::function<bool(FileID)> ShouldIndexFile;
const ASTContext *Context;
};

// Wraps the index action and reports index data after each translation unit.
class IndexAction : public ASTFrontendAction {
public:
Expand All @@ -169,12 +145,15 @@ class IndexAction : public ASTFrontendAction {
CI.getPreprocessor().addPPCallbacks(
std::make_unique<IncludeGraphCollector>(CI.getSourceManager(), IG));

std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Consumers.push_back(std::make_unique<SkipProcessedFunctions>(
[this](FileID FID) { return Collector->shouldIndexFile(FID); }));
Consumers.push_back(index::createIndexingASTConsumer(
Collector, Opts, CI.getPreprocessorPtr()));
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
return index::createIndexingASTConsumer(
Collector, Opts, CI.getPreprocessorPtr(),
/*ShouldSkipFunctionBody=*/[this](const Decl *D) {
auto &SM = D->getASTContext().getSourceManager();
auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation()));
if (!FID.isValid())
return false;
return !Collector->shouldIndexFile(FID);
});
}

bool BeginInvocation(CompilerInstance &CI) override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const Node *getParentOfRootStmts(const Node *CommonAnc) {
// always unselected.
return Parent->ASTNode.get<DeclStmt>() ? Parent->Parent : Parent;
}
llvm_unreachable("Unhandled SelectionTree::Selection enum");
}

// The ExtractionZone class forms a view of the code wrt Zone.
Expand Down
52 changes: 0 additions & 52 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,52 +73,6 @@ class TemplateDecl;
class TemplateParameterList;
class UsingDecl;

/// Represents any kind of function declaration, whether it is a
/// concrete function or a function template.
class AnyFunctionDecl {
NamedDecl *Function;

AnyFunctionDecl(NamedDecl *ND) : Function(ND) {}

public:
AnyFunctionDecl(FunctionDecl *FD) : Function(FD) {}
AnyFunctionDecl(FunctionTemplateDecl *FTD);

/// Implicily converts any function or function template into a
/// named declaration.
operator NamedDecl *() const { return Function; }

/// Retrieve the underlying function or function template.
NamedDecl *get() const { return Function; }

static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
return AnyFunctionDecl(ND);
}
};

} // namespace clang

namespace llvm {

// Provide PointerLikeTypeTraits for non-cvr pointers.
template<>
struct PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
static void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
return F.get();
}

static ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
return ::clang::AnyFunctionDecl::getFromNamedDecl(
static_cast< ::clang::NamedDecl*>(P));
}

enum { NumLowBitsAvailable = 2 };
};

} // namespace llvm

namespace clang {

/// Represents an access specifier followed by colon ':'.
///
/// An objects of this class represents sugar for the syntactic occurrence
Expand Down Expand Up @@ -3469,12 +3423,6 @@ class ConstructorUsingShadowDecl final : public UsingShadowDecl {
return IsVirtual;
}

/// Get the constructor or constructor template in the derived class
/// correspnding to this using shadow declaration, if it has been implicitly
/// declared already.
CXXConstructorDecl *getConstructor() const;
void setConstructor(NamedDecl *Ctor);

static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
};
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2527,10 +2527,6 @@ class ClassScopeFunctionSpecializationDecl : public Decl {
}
};

/// Implementation of inline functions that require the template declarations
inline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD)
: Function(FTD) {}

/// Represents a variable template specialization, which refers to
/// a variable template with a given set of template arguments.
///
Expand Down
17 changes: 13 additions & 4 deletions clang/include/clang/Index/IndexingAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLVM_CLANG_INDEX_INDEXINGACTION_H
#define LLVM_CLANG_INDEX_INDEXINGACTION_H

#include "clang/AST/ASTConsumer.h"
#include "clang/Basic/LLVM.h"
#include "clang/Lex/PPCallbacks.h"
#include "clang/Lex/Preprocessor.h"
Expand Down Expand Up @@ -51,10 +52,18 @@ struct IndexingOptions {
};

/// Creates an ASTConsumer that indexes all symbols (macros and AST decls).
std::unique_ptr<ASTConsumer>
createIndexingASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
const IndexingOptions &Opts,
std::shared_ptr<Preprocessor> PP);
std::unique_ptr<ASTConsumer> createIndexingASTConsumer(
std::shared_ptr<IndexDataConsumer> DataConsumer,
const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP,
std::function<bool(const Decl *)> ShouldSkipFunctionBody);

inline std::unique_ptr<ASTConsumer> createIndexingASTConsumer(
std::shared_ptr<IndexDataConsumer> DataConsumer,
const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP) {
return createIndexingASTConsumer(
std::move(DataConsumer), Opts, std::move(PP),
/*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
}

/// Creates a frontend action that indexes all symbols (macros and AST decls).
std::unique_ptr<FrontendAction>
Expand Down
27 changes: 18 additions & 9 deletions clang/lib/Index/IndexingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ class IndexASTConsumer final : public ASTConsumer {
std::shared_ptr<IndexDataConsumer> DataConsumer;
std::shared_ptr<IndexingContext> IndexCtx;
std::shared_ptr<Preprocessor> PP;
std::function<bool(const Decl *)> ShouldSkipFunctionBody;

public:
IndexASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
const IndexingOptions &Opts,
std::shared_ptr<Preprocessor> PP)
std::shared_ptr<Preprocessor> PP,
std::function<bool(const Decl *)> ShouldSkipFunctionBody)
: DataConsumer(std::move(DataConsumer)),
IndexCtx(new IndexingContext(Opts, *this->DataConsumer)),
PP(std::move(PP)) {
PP(std::move(PP)),
ShouldSkipFunctionBody(std::move(ShouldSkipFunctionBody)) {
assert(this->DataConsumer != nullptr);
assert(this->PP != nullptr);
}
Expand Down Expand Up @@ -92,6 +95,10 @@ class IndexASTConsumer final : public ASTConsumer {
void HandleTranslationUnit(ASTContext &Ctx) override {
DataConsumer->finish();
}

bool shouldSkipFunctionBody(Decl *D) override {
return ShouldSkipFunctionBody(D);
}
};

class IndexAction final : public ASTFrontendAction {
Expand All @@ -108,18 +115,20 @@ class IndexAction final : public ASTFrontendAction {
protected:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
return std::make_unique<IndexASTConsumer>(DataConsumer, Opts,
CI.getPreprocessorPtr());
return std::make_unique<IndexASTConsumer>(
DataConsumer, Opts, CI.getPreprocessorPtr(),
/*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
}
};

} // anonymous namespace

std::unique_ptr<ASTConsumer>
index::createIndexingASTConsumer(std::shared_ptr<IndexDataConsumer> DataConsumer,
const IndexingOptions &Opts,
std::shared_ptr<Preprocessor> PP) {
return std::make_unique<IndexASTConsumer>(DataConsumer, Opts, PP);
std::unique_ptr<ASTConsumer> index::createIndexingASTConsumer(
std::shared_ptr<IndexDataConsumer> DataConsumer,
const IndexingOptions &Opts, std::shared_ptr<Preprocessor> PP,
std::function<bool(const Decl *)> ShouldSkipFunctionBody) {
return std::make_unique<IndexASTConsumer>(DataConsumer, Opts, PP,
ShouldSkipFunctionBody);
}

std::unique_ptr<FrontendAction>
Expand Down
5 changes: 1 addition & 4 deletions clang/lib/Sema/SemaLambda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,11 +824,8 @@ VarDecl *Sema::createLambdaInitCaptureVarDecl(SourceLocation Loc,
// FIXME: Retain the TypeSourceInfo from buildLambdaInitCaptureInitialization
// rather than reconstructing it here.
TypeSourceInfo *TSI = Context.getTrivialTypeSourceInfo(InitCaptureType, Loc);
bool IsInitCapturePack = false;
if (auto PETL = TSI->getTypeLoc().getAs<PackExpansionTypeLoc>()) {
if (auto PETL = TSI->getTypeLoc().getAs<PackExpansionTypeLoc>())
PETL.setEllipsisLoc(EllipsisLoc);
IsInitCapturePack = true;
}

// Create a dummy variable representing the init-capture. This is not actually
// used as a variable, and only exists as a way to name and refer to the
Expand Down
72 changes: 35 additions & 37 deletions clang/tools/libclang/Indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,54 +297,20 @@ class IndexPPCallbacks : public PPCallbacks {

class IndexingConsumer : public ASTConsumer {
CXIndexDataConsumer &DataConsumer;
ParsedSrcLocationsTracker *ParsedLocsTracker;

public:
IndexingConsumer(CXIndexDataConsumer &dataConsumer,
ParsedSrcLocationsTracker *parsedLocsTracker)
: DataConsumer(dataConsumer), ParsedLocsTracker(parsedLocsTracker) {}

// ASTConsumer Implementation
: DataConsumer(dataConsumer) {}

void Initialize(ASTContext &Context) override {
DataConsumer.setASTContext(Context);
DataConsumer.startedTranslationUnit();
}

void HandleTranslationUnit(ASTContext &Ctx) override {
if (ParsedLocsTracker)
ParsedLocsTracker->syncWithStorage();
}

bool HandleTopLevelDecl(DeclGroupRef DG) override {
return !DataConsumer.shouldAbort();
}

bool shouldSkipFunctionBody(Decl *D) override {
if (!ParsedLocsTracker) {
// Always skip bodies.
return true;
}

const SourceManager &SM = DataConsumer.getASTContext().getSourceManager();
SourceLocation Loc = D->getLocation();
if (Loc.isMacroID())
return false;
if (SM.isInSystemHeader(Loc))
return true; // always skip bodies from system headers.

FileID FID;
unsigned Offset;
std::tie(FID, Offset) = SM.getDecomposedLoc(Loc);
// Don't skip bodies from main files; this may be revisited.
if (SM.getMainFileID() == FID)
return false;
const FileEntry *FE = SM.getFileEntryForID(FID);
if (!FE)
return false;

return ParsedLocsTracker->hasAlredyBeenParsed(Loc, FID, FE);
}
};

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -404,18 +370,50 @@ class IndexingFrontendAction : public ASTFrontendAction {
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Consumers.push_back(std::make_unique<IndexingConsumer>(
*DataConsumer, ParsedLocsTracker.get()));
Consumers.push_back(
createIndexingASTConsumer(DataConsumer, Opts, CI.getPreprocessorPtr()));
Consumers.push_back(createIndexingASTConsumer(
DataConsumer, Opts, CI.getPreprocessorPtr(),
[this](const Decl *D) { return this->shouldSkipFunctionBody(D); }));
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
}

bool shouldSkipFunctionBody(const Decl *D) {
if (!ParsedLocsTracker) {
// Always skip bodies.
return true;
}

const SourceManager &SM = D->getASTContext().getSourceManager();
SourceLocation Loc = D->getLocation();
if (Loc.isMacroID())
return false;
if (SM.isInSystemHeader(Loc))
return true; // always skip bodies from system headers.

FileID FID;
unsigned Offset;
std::tie(FID, Offset) = SM.getDecomposedLoc(Loc);
// Don't skip bodies from main files; this may be revisited.
if (SM.getMainFileID() == FID)
return false;
const FileEntry *FE = SM.getFileEntryForID(FID);
if (!FE)
return false;

return ParsedLocsTracker->hasAlredyBeenParsed(Loc, FID, FE);
}

TranslationUnitKind getTranslationUnitKind() override {
if (DataConsumer->shouldIndexImplicitTemplateInsts())
return TU_Complete;
else
return TU_Prefix;
}
bool hasCodeCompletionSupport() const override { return false; }

void EndSourceFileAction() override {
if (ParsedLocsTracker)
ParsedLocsTracker->syncWithStorage();
}
};

//===----------------------------------------------------------------------===//
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@ class TargetTransformInfoImplCRTPBase : public TargetTransformInfoImplBase {
if (isa<PHINode>(U))
return TTI::TCC_Free; // Model all PHI nodes as free.

if (isa<ExtractValueInst>(U))
return TTI::TCC_Free; // Model all ExtractValue nodes as free.

// Static alloca doesn't generate target instructions.
if (auto *A = dyn_cast<AllocaInst>(U))
if (A->isStaticAlloca())
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,8 @@ int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const {
return getVectorInstrCost(I->getOpcode(),
IE->getType(), Idx);
}
case Instruction::ExtractValue:
return 0; // Model all ExtractValue nodes as free.
case Instruction::ShuffleVector: {
const ShuffleVectorInst *Shuffle = cast<ShuffleVectorInst>(I);
Type *Ty = Shuffle->getType();
Expand Down
Loading