MLIR 24.0.0git
LLVMRemarkImport.h
Go to the documentation of this file.
1//===- LLVMRemarkImport.h - Import LLVM remarks into MLIR -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Utilities to import LLVM optimization remarks into the MLIR remark engine,
10// either as they are emitted by LLVM passes or from a serialized remark file.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_REMARK_LLVMREMARKIMPORT_H
15#define MLIR_REMARK_LLVMREMARKIMPORT_H
16
17#include "mlir/IR/Location.h"
18#include "mlir/IR/Remarks.h"
19#include "llvm/ADT/StringMap.h"
20#include "llvm/IR/DiagnosticHandler.h"
21#include "llvm/Remarks/RemarkFormat.h"
22
23namespace mlir {
24class Operation;
25
26namespace remark {
27
28/// Prefix of the category of remarks imported from LLVM. The category is the
29/// prefix followed by the LLVM pass name, e.g. `llvm-inline`, so that remark
30/// filters can select LLVM remarks (`llvm-.*`) or a single LLVM pass.
31constexpr llvm::StringLiteral llvmRemarkCategoryPrefix = "llvm-";
32
33/// Parses `buffer`, a serialized LLVM remark file, and reports its remarks into
34/// the remark engine of the context of `anchor`, the operation the remarks
35/// refer to. The category is the prefixed LLVM pass name, the LLVM remark name
36/// becomes the remark name and the message is stored under the "Remark"
37/// argument. A remark is attached to its debug location if it has one,
38/// otherwise to the symbol named after its LLVM function inside `anchor`,
39/// otherwise to `anchor`. Fails if the buffer cannot be parsed.
40LogicalResult importLLVMRemarks(Operation *anchor, StringRef buffer,
41 llvm::remarks::Format format);
42
43/// Diagnostic handler forwarding LLVM diagnostics to MLIR. Optimization remarks
44/// enabled in the remark engine of the context of `anchor` are imported as
45/// described for `importLLVMRemarks`, so the remark filters of the engine
46/// select LLVM remarks by their prefixed pass name. Other remarks are left to
47/// LLVM, which prints those enabled with its own `-pass-remarks` flags. All
48/// other diagnostics are reported as MLIR diagnostics. Install the handler with
49/// `RespectFilters` set, so that LLVM only forwards enabled remarks.
50class LLVMToMLIRDiagnosticHandler : public llvm::DiagnosticHandler {
51public:
52 explicit LLVMToMLIRDiagnosticHandler(Operation *anchor);
53
54 bool handleDiagnostics(const llvm::DiagnosticInfo &diag) override;
55 bool isAnalysisRemarkEnabled(StringRef passName) const override;
56 bool isMissedOptRemarkEnabled(StringRef passName) const override;
57 bool isPassedOptRemarkEnabled(StringRef passName) const override;
58 using llvm::DiagnosticHandler::isAnyRemarkEnabled;
59 bool isAnyRemarkEnabled() const override;
60
61private:
62 Operation *anchor;
64 llvm::StringMap<Location> functionLocations;
65};
66
67} // namespace remark
68} // namespace mlir
69
70#endif // MLIR_REMARK_LLVMREMARKIMPORT_H
static std::string diag(const llvm::Value &value)
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
bool isMissedOptRemarkEnabled(StringRef passName) const override
bool isAnalysisRemarkEnabled(StringRef passName) const override
bool handleDiagnostics(const llvm::DiagnosticInfo &diag) override
bool isPassedOptRemarkEnabled(StringRef passName) const override
constexpr llvm::StringLiteral llvmRemarkCategoryPrefix
Prefix of the category of remarks imported from LLVM.
LogicalResult importLLVMRemarks(Operation *anchor, StringRef buffer, llvm::remarks::Format format)
Parses buffer, a serialized LLVM remark file, and reports its remarks into the remark engine of the c...
Include the generated interface declarations.