forked from swiftlang/swift
-
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.
[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.
- Loading branch information
Showing
29 changed files
with
505 additions
and
230 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
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
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,104 @@ | ||
//===--- SILRemarkStreamer.h - Interface for streaming remarks --*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
/// \file | ||
/// This file defines the interface used to stream SIL optimization diagnostics | ||
/// through LLVM's RemarkStreamer interface. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_SIL_SILREMARKSTREAMER_H | ||
#define SWIFT_SIL_SILREMARKSTREAMER_H | ||
|
||
#include "swift/SIL/OptimizationRemark.h" | ||
#include "llvm/Remarks/RemarkStreamer.h" | ||
|
||
namespace swift { | ||
|
||
class SILRemarkStreamer { | ||
llvm::remarks::RemarkStreamer &llvmStreamer; | ||
// Source manager for resolving source locations. | ||
const SourceManager &srcMgr; | ||
/// Convert diagnostics into LLVM remark objects. | ||
/// The lifetime of the members of the result is bound to the lifetime of | ||
/// the SIL remarks. | ||
template <typename RemarkT> | ||
llvm::remarks::Remark | ||
toLLVMRemark(const OptRemark::Remark<RemarkT> &remark) const; | ||
|
||
public: | ||
SILRemarkStreamer(llvm::remarks::RemarkStreamer &llvmStreamer, | ||
const SourceManager &srcMgr) | ||
: llvmStreamer(llvmStreamer), srcMgr(srcMgr) {} | ||
/// Emit a remark through the streamer. | ||
template <typename RemarkT> | ||
void emit(const OptRemark::Remark<RemarkT> &remark); | ||
}; | ||
|
||
std::pair<std::unique_ptr<llvm::raw_fd_ostream>, | ||
std::unique_ptr<SILRemarkStreamer>> | ||
createSILRemarkStreamer(SILModule &srcMgr, StringRef filename, StringRef passes, | ||
llvm::remarks::Format format, | ||
DiagnosticEngine &diagEngine, SourceManager &sourceMgr); | ||
|
||
// Implementation for template member functions. | ||
|
||
// OptRemark type -> llvm::remarks::Type | ||
template <typename RemarkT> static llvm::remarks::Type toRemarkType() { | ||
if (std::is_same<RemarkT, OptRemark::RemarkPassed>::value) | ||
return llvm::remarks::Type::Passed; | ||
if (std::is_same<RemarkT, OptRemark::RemarkMissed>::value) | ||
return llvm::remarks::Type::Missed; | ||
llvm_unreachable("Unknown remark type"); | ||
} | ||
|
||
static inline Optional<llvm::remarks::RemarkLocation> | ||
toRemarkLocation(const SourceLoc &loc, const SourceManager &srcMgr) { | ||
if (!loc.isValid()) | ||
return None; | ||
|
||
StringRef file = srcMgr.getDisplayNameForLoc(loc); | ||
unsigned line, col; | ||
std::tie(line, col) = srcMgr.getLineAndColumn(loc); | ||
return llvm::remarks::RemarkLocation{file, line, col}; | ||
} | ||
|
||
template <typename RemarkT> | ||
llvm::remarks::Remark SILRemarkStreamer::toLLVMRemark( | ||
const OptRemark::Remark<RemarkT> &optRemark) const { | ||
llvm::remarks::Remark llvmRemark; // The result. | ||
llvmRemark.RemarkType = toRemarkType<RemarkT>(); | ||
llvmRemark.PassName = optRemark.getPassName(); | ||
llvmRemark.RemarkName = optRemark.getIdentifier(); | ||
llvmRemark.FunctionName = optRemark.getDemangledFunctionName(); | ||
llvmRemark.Loc = toRemarkLocation(optRemark.getLocation(), srcMgr); | ||
|
||
for (const OptRemark::Argument &arg : optRemark.getArgs()) { | ||
llvmRemark.Args.emplace_back(); | ||
llvmRemark.Args.back().Key = arg.key; | ||
llvmRemark.Args.back().Val = arg.val; | ||
llvmRemark.Args.back().Loc = toRemarkLocation(arg.loc, srcMgr); | ||
} | ||
|
||
return llvmRemark; | ||
} | ||
|
||
template <typename RemarkT> | ||
void SILRemarkStreamer::emit(const OptRemark::Remark<RemarkT> &optRemark) { | ||
if (!llvmStreamer.matchesFilter(optRemark.getPassName())) | ||
return; | ||
|
||
return llvmStreamer.getSerializer().emit(toLLVMRemark(optRemark)); | ||
} | ||
|
||
} // namespace swift | ||
#endif |
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
Oops, something went wrong.