Skip to content

Commit 41d7308

Browse files
authored
Cleanup HeapReporter command line options (#2783)
* Cleanup HeapReporter command line options Signed-off-by: philass <[email protected]> * Address comments Signed-off-by: philass <[email protected]> --------- Signed-off-by: philass <[email protected]>
1 parent f563c41 commit 41d7308

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

src/Compiler/CompilerOptions.cpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ bool disableRecomposeOption; // onnx-mlir only
7272
bool enableSimdDataLayout; // onnx-mlir only
7373
bool verifyInputTensors; // onnx-mlir only
7474
bool allowSorting; // onnx-mlir only
75-
std::string reportHeapBefore; // onnx-mlir only
76-
std::string reportHeapAfter; // onnx-mlir only
75+
std::vector<std::string> reportHeapBefore; // onnx-mlir only
76+
std::vector<std::string> reportHeapAfter; // onnx-mlir only
7777
std::string modelTag; // onnx-mlir only
7878
bool enableConvOptPass; // onnx-mlir only
7979
bool disableConstantProp; // onnx-mlir only
@@ -470,20 +470,19 @@ static llvm::cl::opt<bool, true> allowSortingOpt("allowSorting",
470470
llvm::cl::location(allowSorting), llvm::cl::init(true),
471471
llvm::cl::cat(OnnxMlirOptions));
472472

473-
static llvm::cl::opt<std::string, true> reportHeapBeforeOpt(
474-
"report-heap-before",
475-
llvm::cl::desc("Comma separated list of names of passes.\n"
476-
"Before each heap statistics are dumped to "
477-
"<output-files-base-path>.heap.log"),
478-
llvm::cl::location(reportHeapBefore), llvm::cl::init(""),
479-
llvm::cl::cat(OnnxMlirOptions));
480-
481-
static llvm::cl::opt<std::string, true> reportHeapAfterOpt("report-heap-after",
482-
llvm::cl::desc("Comma separated list of names of passes.\n"
473+
static llvm::cl::list<std::string, std::vector<std::string>>
474+
reportHeapBeforeOpt("report-heap-before",
475+
llvm::cl::desc("A list of names of passes.\n"
476+
"Before each heap statistics are dumped to "
477+
"<output-files-base-path>.heap.log"),
478+
llvm::cl::location(reportHeapBefore), llvm::cl::cat(OnnxMlirOptions));
479+
480+
static llvm::cl::list<std::string, std::vector<std::string>> reportHeapAfterOpt(
481+
"report-heap-after",
482+
llvm::cl::desc("A list of names of passes.\n"
483483
"After each heap statistics are dumped to "
484484
"<output-files-base-path>.heap.log"),
485-
llvm::cl::location(reportHeapAfter), llvm::cl::init(""),
486-
llvm::cl::cat(OnnxMlirOptions));
485+
llvm::cl::location(reportHeapAfter), llvm::cl::cat(OnnxMlirOptions));
487486

488487
static llvm::cl::opt<std::string, true> modelTagOpt("tag",
489488
llvm::cl::desc(

src/Compiler/CompilerOptions.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ extern bool disableRecomposeOption; // onnx-mlir only
115115
extern bool enableSimdDataLayout; // onnx-mlir only
116116
extern bool verifyInputTensors; // onnx-mlir only
117117
extern bool allowSorting; // onnx-mlir only
118-
extern std::string reportHeapBefore; // onnx-mlir only
119-
extern std::string reportHeapAfter; // onnx-mlir only
118+
extern std::vector<std::string> reportHeapBefore; // onnx-mlir only
119+
extern std::vector<std::string> reportHeapAfter; // onnx-mlir only
120120
extern std::string modelTag; // onnx-mlir only
121121
extern bool enableConvOptPass; // onnx-mlir only
122122
extern bool disableConstantProp; // onnx-mlir only

src/Compiler/HeapReporter.cpp

+9-16
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
#include "mlir/Pass/Pass.h"
1414
#include "mlir/Support/LLVM.h"
15+
16+
#include "llvm/ADT/StringExtras.h"
1517
#include "llvm/Support/FileSystem.h"
1618
#include "llvm/Support/raw_ostream.h"
1719

18-
#include <string>
19-
2020
#if defined(__APPLE__)
2121
#include <unistd.h> // Unsupported on MSVC.
2222
#endif
@@ -26,13 +26,6 @@ using namespace mlir;
2626
namespace onnx_mlir {
2727

2828
namespace {
29-
void splitToSet(StringRef commaSeparated, llvm::StringSet<> &set) {
30-
SmallVector<StringRef> splits;
31-
commaSeparated.split(splits, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
32-
for (StringRef s : splits)
33-
set.insert(s.trim());
34-
}
35-
3629
#if defined(__APPLE__)
3730
void logMessage(StringRef logFilename, StringRef msg,
3831
llvm::sys::fs::OpenFlags extraFlags = llvm::sys::fs::OF_None) {
@@ -48,15 +41,15 @@ void logMessage(StringRef logFilename, StringRef msg,
4841
#endif
4942
} // namespace
5043

51-
HeapReporter::HeapReporter(
52-
std::string logFilename, StringRef beforePasses, StringRef afterPasses)
53-
: logFilename(logFilename) {
54-
splitToSet(beforePasses, this->beforePassesSet);
55-
splitToSet(afterPasses, this->afterPassesSet);
44+
HeapReporter::HeapReporter(std::string logFilename,
45+
std::vector<std::string> beforePasses, std::vector<std::string> afterPasses)
46+
: logFilename(logFilename), beforePassesSet(beforePasses),
47+
afterPassesSet(afterPasses) {
48+
5649
reportBegin("onnx-mlir heap report"
5750
"\n--report-heap-before='" +
58-
beforePasses.str() + "'\n--report-heap-after='" +
59-
afterPasses.str() + "'");
51+
llvm::join(beforePasses, ",") + "'\n--report-heap-after='" +
52+
llvm::join(afterPasses, ",") + "'");
6053
}
6154

6255
HeapReporter::~HeapReporter() {}

src/Compiler/HeapReporter.hpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212

1313
#pragma once
1414

15+
#include <string>
16+
#include <vector>
17+
1518
#include "mlir/Pass/PassInstrumentation.h"
1619
#include "llvm/ADT/StringSet.h"
1720

1821
namespace onnx_mlir {
1922

2023
struct HeapReporter : public mlir::PassInstrumentation {
21-
HeapReporter(std::string logFilename, llvm::StringRef beforePasses,
22-
llvm::StringRef afterPasses);
24+
HeapReporter(std::string logFilename, std::vector<std::string> beforePasses,
25+
std::vector<std::string> afterPasses);
2326
~HeapReporter() override;
2427

2528
void runBeforePass(mlir::Pass *pass, mlir::Operation *op) override;

0 commit comments

Comments
 (0)