[Remarks] Add a specialized RemarkStreamer for SIL remarks

This allows the usage of the whole remark infrastructure developed in
LLVM, which includes a new binary format, metadata in object files, etc.

This gets rid of the YAMLTraits-based remark serialization and does the
plumbing for hooking to LLVM's main remark streamer.

For more about the idea behind LLVM's main remark streamer, see the
docs/Remarks.rst changes in https://reviews.llvm.org/D73676.

The flags are now:

* -save-optimization-record: enable remarks, defaults to YAML
* -save-optimization-record=<format>: enable remarks, use <format> for
serialization
* -save-optimization-record-passes <regex>: only serialize passes that
match <regex>.

The YAMLTraits in swift had a different `flow` setting for the debug
location, resulting in some test changes.
This commit is contained in:
Francis Visoiu Mistrih
2019-10-28 18:06:17 -07:00
parent e7b2850f52
commit e724ebab6b
29 changed files with 505 additions and 230 deletions

View File

@@ -63,6 +63,7 @@
#include "swift/Serialization/SerializationOptions.h"
#include "swift/Serialization/SerializedModuleLoader.h"
#include "swift/SILOptimizer/PassManager/Passes.h"
#include "swift/SIL/SILRemarkStreamer.h"
#include "swift/Syntax/Serialization/SyntaxSerialization.h"
#include "swift/Syntax/SyntaxNodes.h"
#include "swift/TBDGen/TBDGen.h"
@@ -75,6 +76,8 @@
#include "llvm/IRReader/IRReader.h"
#include "llvm/Option/Option.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Remarks/RemarkSerializer.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
@@ -708,21 +711,6 @@ static void countStatsPostSILGen(UnifiedStatsReporter &Stats,
C.NumSILGenGlobalVariables += Module.getSILGlobalList().size();
}
static std::unique_ptr<llvm::raw_fd_ostream>
createOptRecordFile(StringRef Filename, DiagnosticEngine &DE) {
if (Filename.empty())
return nullptr;
std::error_code EC;
auto File = std::make_unique<llvm::raw_fd_ostream>(Filename, EC,
llvm::sys::fs::F_None);
if (EC) {
DE.diagnose(SourceLoc(), diag::cannot_open_file, Filename, EC.message());
return nullptr;
}
return File;
}
static bool precompileBridgingHeader(const CompilerInvocation &Invocation,
const CompilerInstance &Instance) {
auto clangImporter = static_cast<ClangImporter *>(
@@ -1532,14 +1520,10 @@ static bool performCompileStepsPostSILGen(
return Context.hadError();
}
std::unique_ptr<llvm::raw_fd_ostream> OptRecordFile =
createOptRecordFile(SILOpts.OptRecordFile, Instance.getDiags());
if (OptRecordFile) {
auto Output =
std::make_unique<llvm::yaml::Output>(*OptRecordFile,
&Instance.getSourceMgr());
SM->setOptRecordStream(std::move(Output), std::move(OptRecordFile));
}
auto pair = createSILRemarkStreamer(
*SM, SILOpts.OptRecordFile, SILOpts.OptRecordPasses,
SILOpts.OptRecordFormat, Instance.getDiags(), Instance.getSourceMgr());
SM->setSILRemarkStreamer(std::move(pair.first), std::move(pair.second));
// This is the action to be used to serialize SILModule.
// It may be invoked multiple times, but it will perform