Skip to content

Commit a2b8e2d

Browse files
committed
some cleanup
1 parent cfd792c commit a2b8e2d

File tree

13 files changed

+68
-104
lines changed

13 files changed

+68
-104
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5944,9 +5944,9 @@ def save_temps : Flag<["-", "--"], "save-temps">, Flags<[NoXarchOption]>,
59445944
def summaries_dir_EQ : Joined<["-", "--"], "summaries-dir=">, Flags<[NoXarchOption]>,
59455945
Visibility<[ClangOption, CC1Option]>,
59465946
HelpText<"Read summaries about different functions from this directory">,
5947-
MarshallingInfoString<FrontendOpts<"SummaryDirPath">>;
5947+
MarshallingInfoString<FrontendOpts<"ReadSummaryDir">>;
59485948
def emit_summaries_EQ : Joined<["-", "--"], "emit-summaries=">, Flags<[NoXarchOption]>,
5949-
Visibility<[ClangOption, CC1Option]>,
5949+
Visibility<[ClangOption]>,
59505950
HelpText<"Save summaries about the different functions. <arg> can be set to 'cwd' for "
59515951
"current working directory, or 'obj' which will save temporary files in the "
59525952
"same directory as the final output file">;
@@ -8164,10 +8164,9 @@ defm emit_llvm_uselists : BoolOption<"", "emit-llvm-uselists",
81648164
NegFlag<SetFalse, [], [ClangOption], "Don't preserve">,
81658165
BothFlags<[], [ClangOption], " order of LLVM use-lists when serializing">>;
81668166

8167-
def summary_file : Joined<["-"], "summary-file=">,
8168-
HelpText<"Filename to write summaries about function definitions to">,
8169-
MarshallingInfoString<FrontendOpts<"SummaryFile">>;
8170-
8167+
def emit_summary_dir : Joined<["-"], "emit-summary-dir=">,
8168+
HelpText<"Directory to write summaries about function definitions to">,
8169+
MarshallingInfoString<FrontendOpts<"EmitSummaryDir">>;
81718170
def print_stats : Flag<["-"], "print-stats">,
81728171
HelpText<"Print performance metrics and statistics">,
81738172
MarshallingInfoFlag<FrontendOpts<"ShowStats">>;

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -632,22 +632,17 @@ class CompilerInstance : public ModuleLoader {
632632

633633
bool hasSummaryContext() { return (bool)SummaryCtx; }
634634

635-
SummaryContext &getSummaryContext() {
636-
assert(SummaryCtx && "Compiler instance has no summary context!");
637-
return *SummaryCtx;
638-
}
635+
SummaryContext *getSummaryContext() { return SummaryCtx.get(); }
639636

640637
void createSummaryContext() { SummaryCtx.reset(new SummaryContext()); }
641638

642639
bool hasSummaryConsumer() const { return (bool)TheSummaryConsumer; }
643640

644-
SummaryConsumer &getSummaryConsumer() const {
645-
assert(TheSummaryConsumer &&
646-
"Compiler instance has no code summary consumer!");
647-
return *TheSummaryConsumer;
641+
SummaryConsumer *getSummaryConsumer() const {
642+
return TheSummaryConsumer.get();
648643
}
649644

650-
void createSummaryConsumer();
645+
void createSummaryConsumer(FrontendInputFile Input);
651646

652647
bool hasSummarySerializer() const { return (bool)TheSummarySerializer; }
653648

@@ -786,8 +781,7 @@ class CompilerInstance : public ModuleLoader {
786781

787782
/// Create the Sema object to be used for parsing.
788783
void createSema(TranslationUnitKind TUKind,
789-
CodeCompleteConsumer *CompletionConsumer,
790-
SummaryConsumer *SummaryConsumer = nullptr);
784+
CodeCompleteConsumer *CompletionConsumer);
791785

792786
/// Create the frontend timer and replace any existing one with it.
793787
void createFrontendTimer();

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,13 @@ class FrontendOptions {
534534
/// minimization hints.
535535
std::string DumpMinimizationHintsPath;
536536

537-
/// Filename to write summaries about function definitions to.
538-
std::string SummaryFile;
537+
/// The directory used to write summary files to.
538+
std::string EmitSummaryDir;
539539

540-
/// The directory used to load summary files.
541-
std::string SummaryDirPath;
540+
/// The directory used to load summary files from.
541+
std::string ReadSummaryDir;
542542

543-
/// The format of the emitted summary files.
543+
/// The format of the summary files.
544544
std::string SummaryFormat;
545545

546546
public:

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ class Sema final : public SemaBase {
12651265
SourceManager &SourceMgr;
12661266
api_notes::APINotesManager APINotes;
12671267
SummaryContext *SummaryCtx;
1268-
SummaryConsumer *SummaryCnsmr;
1268+
SummaryConsumer *TheSummaryConsumer;
12691269

12701270
/// A RAII object to enter scope of a compound statement.
12711271
class CompoundScopeRAII {

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5473,45 +5473,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
54735473
if (Args.getLastArg(options::OPT_summaries_dir_EQ))
54745474
Args.AddLastArg(CmdArgs, options::OPT_summaries_dir_EQ);
54755475

5476-
std::string SummaryFormat = "json";
5477-
if (Arg *A = Args.getLastArg(options::OPT_summary_format_EQ)) {
5478-
// FIXME: This logic is duplicated, so something is clearly wrong here...
5479-
StringRef Format = A->getValue();
5480-
if (Format == "json" || Format == "yaml")
5481-
SummaryFormat = Format;
5482-
5476+
if (Arg *A = Args.getLastArg(options::OPT_summary_format_EQ))
54835477
Args.AddLastArg(CmdArgs, options::OPT_summary_format_EQ);
5484-
}
54855478

5486-
// FIXME: This arg shouldn't exist...
54875479
if (const Arg *A = Args.getLastArg(options::OPT_emit_summaries_EQ)) {
5488-
llvm::SmallString<10> input;
5489-
for (const auto &II : Inputs) {
5490-
if (!II.isFilename())
5491-
continue;
5492-
5493-
input = II.getFilename();
5494-
break;
5495-
}
5480+
std::string EmitSummaryDir = ".";
54965481

5497-
if (!input.empty()) {
5498-
Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
5499-
StringRef filename = llvm::sys::path::filename(input);
5500-
llvm::SmallString<10> summaryFile;
5482+
if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
5483+
A->containsValue("obj") && FinalOutput)
5484+
EmitSummaryDir = llvm::sys::path::parent_path(FinalOutput->getValue());
55015485

5502-
if (A->containsValue("cwd") || !FinalOutput) {
5503-
summaryFile = filename;
5504-
} else if (A->containsValue("obj") && FinalOutput) {
5505-
summaryFile = llvm::sys::path::parent_path(FinalOutput->getValue());
5506-
llvm::sys::path::append(summaryFile, filename);
5507-
}
5508-
5509-
if (!summaryFile.empty()) {
5510-
llvm::sys::path::replace_extension(summaryFile, SummaryFormat);
5511-
CmdArgs.push_back(
5512-
Args.MakeArgString(Twine("-summary-file=") + summaryFile));
5513-
}
5514-
}
5486+
CmdArgs.push_back(
5487+
Args.MakeArgString(Twine("-emit-summary-dir=") + EmitSummaryDir));
55155488
}
55165489

55175490
auto *MemProfArg = Args.getLastArg(options::OPT_fmemory_profile,

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,16 @@ CompilerInstance::createCodeCompletionConsumer(Preprocessor &PP,
743743
return new PrintingCodeCompleteConsumer(Opts, OS);
744744
}
745745

746-
void CompilerInstance::createSummaryConsumer() {
747-
const std::string &SummaryFile = getFrontendOpts().SummaryFile;
748-
if (SummaryFile.empty())
746+
void CompilerInstance::createSummaryConsumer(FrontendInputFile Input) {
747+
StringRef EmitSummaryDir = getFrontendOpts().EmitSummaryDir;
748+
if (EmitSummaryDir.empty() || !Input.isFile())
749749
return;
750750

751+
llvm::SmallString<32> SummaryFile = EmitSummaryDir;
752+
llvm::sys::path::append(SummaryFile, Input.getFile());
753+
llvm::sys::path::replace_extension(SummaryFile,
754+
getFrontendOpts().SummaryFormat);
755+
751756
std::error_code EC;
752757
SummaryOS.reset(new llvm::raw_fd_ostream(SummaryFile, EC,
753758
llvm::sys::fs::CD_CreateAlways));
@@ -768,21 +773,22 @@ void CompilerInstance::createSummarySerializer() {
768773
StringRef Format = getFrontendOpts().SummaryFormat;
769774
SummarySerializer *Serializer;
770775

776+
if (!hasSummaryContext())
777+
createSummaryContext();
778+
771779
if (Format == "yaml")
772-
Serializer = new YAMLSummarySerializer(getSummaryContext());
780+
Serializer = new YAMLSummarySerializer(*getSummaryContext());
773781
else
774-
Serializer = new JSONSummarySerializer(getSummaryContext());
782+
Serializer = new JSONSummarySerializer(*getSummaryContext());
775783

776784
TheSummarySerializer.reset(Serializer);
777785
}
778786

779787
void CompilerInstance::createSema(TranslationUnitKind TUKind,
780-
CodeCompleteConsumer *CompletionConsumer,
781-
SummaryConsumer *SummaryConsumer) {
788+
CodeCompleteConsumer *CompletionConsumer) {
782789
TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(),
783-
TUKind, CompletionConsumer,
784-
hasSummaryContext() ? &getSummaryContext() : nullptr,
785-
SummaryConsumer));
790+
TUKind, CompletionConsumer, getSummaryContext(),
791+
getSummaryConsumer()));
786792

787793
// Set up API notes.
788794
TheSema->APINotes.setSwiftVersion(getAPINotesOpts().SwiftVersion);

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3270,7 +3270,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
32703270
StringRef Format = A->getValue();
32713271

32723272
// FIXME: don't hardcode these values
3273-
if (Format == "json" || Format == "yaml")
3273+
if (Format == "yaml")
32743274
Opts.SummaryFormat = Format;
32753275
};
32763276

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -966,16 +966,21 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
966966
}
967967
}
968968

969-
bool ProcessesSummaries = !CI.getFrontendOpts().SummaryDirPath.empty() ||
970-
!CI.getFrontendOpts().SummaryFile.empty();
971-
if (ProcessesSummaries && !CI.hasSummaryContext())
972-
CI.createSummaryContext();
969+
bool EmitSummaries = !CI.getFrontendOpts().EmitSummaryDir.empty();
970+
bool ReadSummaries = !CI.getFrontendOpts().ReadSummaryDir.empty();
973971

974-
if (ProcessesSummaries && !CI.hasSummarySerializer())
975-
CI.createSummarySerializer();
972+
if (EmitSummaries || ReadSummaries) {
973+
if (!CI.hasSummaryContext())
974+
CI.createSummaryContext();
976975

977-
// FIXME: cleanup and lookup dirs recursively
978-
if (!CI.getFrontendOpts().SummaryDirPath.empty()) {
976+
if (!CI.hasSummarySerializer())
977+
CI.createSummarySerializer();
978+
}
979+
980+
if (EmitSummaries)
981+
CI.createSummaryConsumer(getCurrentInput());
982+
983+
if (ReadSummaries) {
979984
// FIXME: this is a quick shortcut so large summaries are only evaluated
980985
// once, we should think about implementing it in a reasonable way...
981986
static const char *reducedCacheName =
@@ -984,7 +989,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
984989
'.' + CI.getFrontendOpts().SummaryFormat;
985990

986991
FileManager &FileMgr = CI.getFileManager();
987-
StringRef SummaryDirPath = CI.getFrontendOpts().SummaryDirPath;
992+
StringRef SummaryDirPath = CI.getFrontendOpts().ReadSummaryDir;
988993
if (auto SummaryDir = FileMgr.getOptionalDirectoryRef(SummaryDirPath)) {
989994
std::error_code EC;
990995
SmallString<128> DirNative;
@@ -1017,13 +1022,13 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
10171022
CI.getSummarySerializer().parse(buffer.str());
10181023
}
10191024

1020-
CI.getSummaryContext().ReduceSummaries();
1025+
CI.getSummaryContext()->ReduceSummaries();
10211026

10221027
if (!FS.exists(cacheFile)) {
10231028
// FIXME: very quick printing of the summary to the cache file
10241029
llvm::raw_fd_ostream fd(cacheFile, EC, llvm::sys::fs::CD_CreateAlways);
10251030
CI.getSummarySerializer().serialize(
1026-
CI.getSummaryContext().FunctionSummaries, fd);
1031+
CI.getSummaryContext()->FunctionSummaries, fd);
10271032
}
10281033
}
10291034
}
@@ -1399,17 +1404,8 @@ void ASTFrontendAction::ExecuteAction() {
13991404
if (CI.hasCodeCompletionConsumer())
14001405
CompletionConsumer = &CI.getCodeCompletionConsumer();
14011406

1402-
if (!CI.getFrontendOpts().SummaryFile.empty())
1403-
CI.createSummaryConsumer();
1404-
1405-
// Use a code summary consumer?
1406-
SummaryConsumer *SummaryConsumer = nullptr;
1407-
if (CI.hasSummaryConsumer())
1408-
SummaryConsumer = &CI.getSummaryConsumer();
1409-
14101407
if (!CI.hasSema())
1411-
CI.createSema(getTranslationUnitKind(), CompletionConsumer,
1412-
SummaryConsumer);
1408+
CI.createSema(getTranslationUnitKind(), CompletionConsumer);
14131409

14141410
ParseAST(CI.getSema(), CI.getFrontendOpts().ShowStats,
14151411
CI.getFrontendOpts().SkipFunctionBodies);

clang/lib/Sema/Sema.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
255255
CurFPFeatures(pp.getLangOpts()), LangOpts(pp.getLangOpts()), PP(pp),
256256
Context(ctxt), Consumer(consumer), Diags(PP.getDiagnostics()),
257257
SourceMgr(PP.getSourceManager()), APINotes(SourceMgr, LangOpts),
258-
SummaryCtx(SummaryCtx), SummaryCnsmr(SummaryConsumer),
258+
SummaryCtx(SummaryCtx), TheSummaryConsumer(SummaryConsumer),
259259
AnalysisWarnings(*this), ThreadSafetyDeclCache(nullptr),
260260
LateTemplateParser(nullptr), LateTemplateParserCleanup(nullptr),
261261
OpaqueParser(nullptr), CurContext(nullptr), ExternalSource(nullptr),
@@ -1148,8 +1148,8 @@ void Sema::ActOnStartOfTranslationUnit() {
11481148
getLangOpts().getCompilingModule() == LangOptions::CMK_HeaderUnit)
11491149
HandleStartOfHeaderUnit();
11501150

1151-
if (SummaryCnsmr)
1152-
SummaryCnsmr->ProcessStartOfSourceFile();
1151+
if (TheSummaryConsumer)
1152+
TheSummaryConsumer->ProcessStartOfSourceFile();
11531153
}
11541154

11551155
void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
@@ -1225,8 +1225,8 @@ void Sema::ActOnEndOfTranslationUnit() {
12251225
assert(DelayedDiagnostics.getCurrentPool() == nullptr
12261226
&& "reached end of translation unit with a pool attached?");
12271227

1228-
if (SummaryCnsmr)
1229-
SummaryCnsmr->ProcessEndOfSourceFile();
1228+
if (TheSummaryConsumer)
1229+
TheSummaryConsumer->ProcessEndOfSourceFile();
12301230

12311231
// If code completion is enabled, don't perform any end-of-translation-unit
12321232
// work.

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16695,11 +16695,10 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1669516695
if (FD && !FD->isDeleted())
1669616696
checkTypeSupport(FD->getType(), FD->getLocation(), FD);
1669716697

16698-
// FIXME: checking this should be done by the summary context
16699-
if (SummaryCnsmr && !LateTemplateParser && FD &&
16698+
if (TheSummaryConsumer && !LateTemplateParser && FD &&
1670016699
!SourceMgr.isInSystemHeader(FD->getLocation()) && !FD->getBuiltinID()) {
1670116700
SummaryCtx->SummarizeFunctionBody(FD);
16702-
SummaryCnsmr->ProcessFunctionSummary(*SummaryCtx->GetSummary(FD));
16701+
TheSummaryConsumer->ProcessFunctionSummary(*SummaryCtx->GetSummary(FD));
1670316702
}
1670416703

1670516704
return dcl;

0 commit comments

Comments
 (0)