Skip to content

Commit a9a0b54

Browse files
committed
add test
1 parent a3e2893 commit a9a0b54

File tree

6 files changed

+156
-7
lines changed

6 files changed

+156
-7
lines changed

mlir/include/mlir/Tools/mlir-opt/MlirOptMain.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ class MlirOptMainConfig {
231231
bool shouldEmitRemarks() const {
232232
// Emit all remarks only when no filters are specified.
233233
const bool hasFilters =
234-
!remarksPassedFlag.empty() || !remarksFailedFlag.empty() ||
235-
!remarksMissedFlag.empty() || !remarksAnalyseFlag.empty();
234+
!remarksAllFlag.empty() || !remarksPassedFlag.empty() ||
235+
!remarksFailedFlag.empty() || !remarksMissedFlag.empty() ||
236+
!remarksAnalyseFlag.empty();
236237
return hasFilters;
237238
}
238239

@@ -241,6 +242,7 @@ class MlirOptMainConfig {
241242

242243
/// Remark options
243244
RemarkFormat remarkFormatFlag;
245+
std::string remarksAllFlag = "";
244246
std::string remarksPassedFlag = "";
245247
std::string remarksFailedFlag = "";
246248
std::string remarksMissedFlag = "";

mlir/lib/Tools/mlir-opt/MlirOptMain.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ struct MlirOptMainConfigCLOptions : public MlirOptMainConfig {
225225
"Print bitstream file")),
226226
llvm::cl::cat(remarkCategory)};
227227

228+
static cl::opt<std::string, /*ExternalStorage=*/true> remarksAll(
229+
"remarks",
230+
cl::desc("Show all remarks: passed, missed, failed, analysis"),
231+
cl::location(remarksAllFlag), cl::init(""), cl::cat(remarkCategory));
232+
228233
static cl::opt<std::string, /*ExternalStorage=*/true> remarksPassed(
229234
"remarks-passed", cl::desc("Show passed remarks"),
230235
cl::location(remarksPassedFlag), cl::init(""), cl::cat(remarkCategory));
@@ -502,15 +507,26 @@ performActions(raw_ostream &os,
502507

503508
// Set up optimization remarks.
504509
if (config.shouldEmitRemarks()) {
510+
auto combine = [](const std::string &a, const std::string &b) {
511+
if (a.empty())
512+
return b;
513+
if (b.empty())
514+
return a;
515+
return a + "|" + b;
516+
};
517+
505518
remark::RemarkCategories cats{
506-
config.remarksPassedFlag, config.remarksFailedFlag,
507-
config.remarksMissedFlag, config.remarksAnalyseFlag};
519+
combine(config.remarksAllFlag, config.remarksPassedFlag),
520+
combine(config.remarksAllFlag, config.remarksMissedFlag),
521+
combine(config.remarksAllFlag, config.remarksAnalyseFlag),
522+
combine(config.remarksAllFlag, config.remarksFailedFlag)};
508523

509524
mlir::MLIRContext &ctx = *context;
510525

511526
switch (config.remarkFormatFlag) {
512527
case REMARK_FORMAT_STDOUT:
513-
if (failed(mlir::remark::enableOptimizationRemarks(ctx, nullptr, cats)))
528+
if (failed(mlir::remark::enableOptimizationRemarks(
529+
ctx, nullptr, cats, true /*printAsEmitRemarks*/)))
514530
return failure();
515531
break;
516532

@@ -523,9 +539,9 @@ performActions(raw_ostream &os,
523539
}
524540

525541
case REMARK_FORMAT_BITSTREAM: {
526-
constexpr llvm::StringLiteral File{"mlir-remarks.bitstream"};
542+
constexpr llvm::StringLiteral file{"mlir-remarks.bitstream"};
527543
if (failed(mlir::remark::enableOptimizationRemarksWithLLVMStreamer(
528-
ctx, File, llvm::remarks::Format::Bitstream, cats)))
544+
ctx, file, llvm::remarks::Format::Bitstream, cats)))
529545
return failure();
530546
break;
531547
}

mlir/test/Pass/remarks.mlir

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: mlir-opt %s --test-remark-pipeline --remarks-passed="category" 2>&1 | FileCheck %s -check-prefix=CHECK-PASSED
2+
// RUN: mlir-opt %s --test-remark-pipeline --remarks-missed="category" 2>&1 | FileCheck %s -check-prefix=CHECK-MISSED
3+
// RUN: mlir-opt %s --test-remark-pipeline --remarks-failed="category" 2>&1 | FileCheck %s -check-prefix=CHECK-FAILED
4+
// RUN: mlir-opt %s --test-remark-pipeline --remarks-analyse="category" 2>&1 | FileCheck %s -check-prefix=CHECK-ANALYSIS
5+
// RUN: mlir-opt %s --test-remark-pipeline --remarks="category" 2>&1 | FileCheck %s -check-prefix=CHECK-ALL
6+
// RUN: mlir-opt %s --test-remark-pipeline --remarks="category-1" 2>&1 | FileCheck %s -check-prefix=CHECK-ALL1
7+
module @foo {
8+
"test.op"() : () -> ()
9+
"test.op2"() : () -> ()
10+
}
11+
12+
13+
// CHECK-PASSED: remarks.mlir:8:3: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"
14+
// CHECK-PASSED: remarks.mlir:9:3: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"
15+
// CHECK-PASSED: remarks.mlir:7:1: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"
16+
17+
// CHECK-MISSED:remarks.mlir:8:3: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
18+
// CHECK-MISSED:remarks.mlir:9:3: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
19+
// CHECK-MISSED:remarks.mlir:7:1: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
20+
21+
// CHECK-FAILED: remarks.mlir:8:3: remark: [Failure] test-remark | Category:category-2-failed | Reason="because we are testing the remark pipeline", Remark="This is a test failed remark", Suggestion="try using the remark pipeline feature"
22+
// CHECK-FAILED: remarks.mlir:9:3: remark: [Failure] test-remark | Category:category-2-failed | Reason="because we are testing the remark pipeline", Remark="This is a test failed remark", Suggestion="try using the remark pipeline feature"
23+
// CHECK-FAILED: remarks.mlir:7:1: remark: [Failure] test-remark | Category:category-2-failed | Reason="because we are testing the remark pipeline", Remark="This is a test failed remark", Suggestion="try using the remark pipeline feature"
24+
25+
// CHECK-ANALYSIS: remarks.mlir:8:3: remark: [Analysis] test-remark | Category:category-2-analysis | Remark="This is a test analysis remark"
26+
// CHECK-ANALYSIS: remarks.mlir:9:3: remark: [Analysis] test-remark | Category:category-2-analysis | Remark="This is a test analysis remark"
27+
// CHECK-ANALYSIS: remarks.mlir:7:1: remark: [Analysis] test-remark | Category:category-2-analysis | Remark="This is a test analysis remark"
28+
29+
30+
// CHECK-ALL: remarks.mlir:8:3: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
31+
// CHECK-ALL: remarks.mlir:8:3: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"
32+
// CHECK-ALL: remarks.mlir:8:3: remark: [Failure] test-remark | Category:category-2-failed | Reason="because we are testing the remark pipeline", Remark="This is a test failed remark", Suggestion="try using the remark pipeline feature"
33+
// CHECK-ALL: remarks.mlir:8:3: remark: [Analysis] test-remark | Category:category-2-analysis | Remark="This is a test analysis remark"
34+
// CHECK-ALL: remarks.mlir:9:3: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
35+
// CHECK-ALL: remarks.mlir:9:3: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"
36+
// CHECK-ALL: remarks.mlir:9:3: remark: [Failure] test-remark | Category:category-2-failed | Reason="because we are testing the remark pipeline", Remark="This is a test failed remark", Suggestion="try using the remark pipeline feature"
37+
// CHECK-ALL: remarks.mlir:9:3: remark: [Analysis] test-remark | Category:category-2-analysis | Remark="This is a test analysis remark"
38+
// CHECK-ALL: remarks.mlir:7:1: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
39+
// CHECK-ALL: remarks.mlir:7:1: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"
40+
// CHECK-ALL: remarks.mlir:7:1: remark: [Failure] test-remark | Category:category-2-failed | Reason="because we are testing the remark pipeline", Remark="This is a test failed remark", Suggestion="try using the remark pipeline feature"
41+
// CHECK-ALL: remarks.mlir:7:1: remark: [Analysis] test-remark | Category:category-2-analysis | Remark="This is a test analysis remark"
42+
43+
// CHECK-ALL1: remarks.mlir:8:3: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
44+
// CHECK-ALL1: remarks.mlir:8:3: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"
45+
// CHECK-ALL1: remarks.mlir:9:3: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
46+
// CHECK-ALL1: remarks.mlir:9:3: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"
47+
// CHECK-ALL1: remarks.mlir:7:1: remark: [Missed] test-remark | Category:category-1-missed | Reason="because we are testing the remark pipeline", Remark="This is a test missed remark", Suggestion="try using the remark pipeline feature"
48+
// CHECK-ALL1: remarks.mlir:7:1: remark: [Passed] test-remark | Category:category-1-passed | Reason="because we are testing the remark pipeline", Remark="This is a test passed remark", Suggestion="try using the remark pipeline feature"

mlir/test/lib/Pass/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_mlir_library(MLIRTestPass
44
TestConvertToSPIRVPass.cpp
55
TestDynamicPipeline.cpp
66
TestPassManager.cpp
7+
TestRemarksPipeline.cpp
78
TestSPIRVCPURunnerPipeline.cpp
89
TestVulkanRunnerPipeline.cpp
910

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//===------ TestRemarkPipeline.cpp --- dynamic pipeline test pass --------===//
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+
// This file implements a pass to test the dynamic pipeline feature.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "mlir/IR/BuiltinOps.h"
14+
#include "mlir/IR/Location.h"
15+
#include "mlir/IR/Remarks.h"
16+
#include "mlir/Pass/Pass.h"
17+
#include "mlir/Pass/PassManager.h"
18+
19+
using namespace mlir;
20+
21+
namespace {
22+
23+
class TestRemarkPipelinePass
24+
: public PassWrapper<TestRemarkPipelinePass, OperationPass<>> {
25+
public:
26+
MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestRemarkPipelinePass)
27+
28+
StringRef getArgument() const final { return "test-remark-pipeline"; }
29+
StringRef getDescription() const final {
30+
return "Tests the remark pipeline feature";
31+
}
32+
void getDependentDialects(DialectRegistry &registry) const override {
33+
OpPassManager pm(ModuleOp::getOperationName(),
34+
OpPassManager::Nesting::Implicit);
35+
36+
pm.getDependentDialects(registry);
37+
}
38+
39+
TestRemarkPipelinePass() = default;
40+
41+
void runOnOperation() override {
42+
43+
getOperation()->walk([](Operation *op) {
44+
Location loc = op->getLoc();
45+
mlir::remark::missed(
46+
loc,
47+
remark::RemarkOpts::name("test-remark").category("category-1-missed"))
48+
<< remark::add("This is a test missed remark")
49+
<< remark::reason("because we are testing the remark pipeline")
50+
<< remark::suggest("try using the remark pipeline feature");
51+
52+
mlir::remark::passed(
53+
loc,
54+
remark::RemarkOpts::name("test-remark").category("category-1-passed"))
55+
<< remark::add("This is a test passed remark")
56+
<< remark::reason("because we are testing the remark pipeline")
57+
<< remark::suggest("try using the remark pipeline feature");
58+
59+
mlir::remark::failed(
60+
loc,
61+
remark::RemarkOpts::name("test-remark").category("category-2-failed"))
62+
<< remark::add("This is a test failed remark")
63+
<< remark::reason("because we are testing the remark pipeline")
64+
<< remark::suggest("try using the remark pipeline feature");
65+
66+
mlir::remark::analysis(loc, remark::RemarkOpts::name("test-remark")
67+
.category("category-2-analysis"))
68+
<< remark::add("This is a test analysis remark");
69+
});
70+
}
71+
};
72+
} // namespace
73+
74+
namespace mlir {
75+
namespace test {
76+
void registerTestRemarkPipelinePass() {
77+
PassRegistration<TestRemarkPipelinePass>();
78+
}
79+
} // namespace test
80+
} // namespace mlir

mlir/tools/mlir-opt/mlir-opt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void registerTestDiagnosticsPass();
9797
void registerTestDiagnosticsMetadataPass();
9898
void registerTestDominancePass();
9999
void registerTestDynamicPipelinePass();
100+
void registerTestRemarkPipelinePass();
100101
void registerTestEmulateNarrowTypePass();
101102
void registerTestFooAnalysisPass();
102103
void registerTestComposeSubView();
@@ -243,6 +244,7 @@ void registerTestPasses() {
243244
mlir::test::registerTestDiagnosticsMetadataPass();
244245
mlir::test::registerTestDominancePass();
245246
mlir::test::registerTestDynamicPipelinePass();
247+
mlir::test::registerTestRemarkPipelinePass();
246248
mlir::test::registerTestEmulateNarrowTypePass();
247249
mlir::test::registerTestFooAnalysisPass();
248250
mlir::test::registerTestComposeSubView();

0 commit comments

Comments
 (0)