Skip to content

Commit e4292d1

Browse files
committed
[MLIR] MLIR Integrate LLVM Optimization Remarks Infrastructure
This patch hooks LLVM’s remarks infrastructure into MLIR. * Disabled by default, zero-cost when off. Enable per context with `MLIRContext::setupOptimizationRemarks(...)`. * YAML or bitstream output: via new `MLIRRemarkStreamer` (subclasses `llvm::remarks::RemarkStreamer`). * Implements simple APIs for passes: User-code can directly prints remarks like: ``` reportOptimizationPass(loc, categoryName, "MyPass") << "vectorized"; reportOptimizationMiss(loc, categoryLoopUnroll, "MyPass", "try increasing unroll factor") << "..."; reportOptimizationFail(loc, categoryLoopUnroll, "MyPass") << "..."; reportOptimizationAnalysis(loc, categoryLoopUnroll, "MyPass") << "estimated trip count: " << tripCount; ```
1 parent 5f86456 commit e4292d1

File tree

7 files changed

+913
-0
lines changed

7 files changed

+913
-0
lines changed

mlir/include/mlir/IR/MLIRContext.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class InFlightDiagnostic;
3232
class Location;
3333
class MLIRContextImpl;
3434
class RegisteredOperationName;
35+
class RemarkEngine;
3536
class StorageUniquer;
3637
class IRUnit;
3738

@@ -212,6 +213,9 @@ class MLIRContext {
212213
/// Returns the diagnostic engine for this context.
213214
DiagnosticEngine &getDiagEngine();
214215

216+
/// Returns the remark engine for this context.
217+
std::unique_ptr<RemarkEngine> &getRemarkEngine();
218+
215219
/// Returns the storage uniquer used for creating affine constructs.
216220
StorageUniquer &getAffineUniquer();
217221

@@ -245,6 +249,14 @@ class MLIRContext {
245249
/// (attributes, operations, types, etc.).
246250
llvm::hash_code getRegistryHash();
247251

252+
/// Set up optimization remarks for the context.
253+
void setupOptimizationRemarks(
254+
StringRef outputPath, StringRef outputFormat, bool printAsEmitRemarks,
255+
const std::optional<std::string> &categoryPassName = std::nullopt,
256+
const std::optional<std::string> &categoryMissName = std::nullopt,
257+
const std::optional<std::string> &categoryAnalysisName = std::nullopt,
258+
const std::optional<std::string> &categoryFailedName = std::nullopt);
259+
248260
//===--------------------------------------------------------------------===//
249261
// Action API
250262
//===--------------------------------------------------------------------===//
@@ -281,6 +293,9 @@ class MLIRContext {
281293
}
282294

283295
private:
296+
/// Set the remark engine for this context.
297+
void setRemarkEngine(std::unique_ptr<RemarkEngine> engine);
298+
284299
/// Return true if the given dialect is currently loading.
285300
bool isDialectLoading(StringRef dialectNamespace);
286301

0 commit comments

Comments
 (0)