Skip to content

Commit 1a2539e

Browse files
[mlir:bufferization] Make LayoutMapOption CL args enums. (#132121)
This PR changes the type of the command-line arguments representing `LayoutMapOption` from `std::string` to the enum with the same name. This allows for checking the values of programmable usages of the corresponding options at compile time.
1 parent 7dc5504 commit 1a2539e

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_PASSES_H
33

44
#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"
5+
#include "mlir/Dialect/Bufferization/IR/BufferizableOpInterface.h"
56
#include "mlir/Dialect/MemRef/IR/MemRef.h"
67
#include "mlir/Pass/Pass.h"
78

mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ def EmptyTensorToAllocTensorPass : Pass<"empty-tensor-to-alloc-tensor"> {
284284
let dependentDialects = ["tensor::TensorDialect"];
285285
}
286286

287+
def layoutMapClValues {
288+
string values = [{
289+
::llvm::cl::values(
290+
clEnumValN(LayoutMapOption::InferLayoutMap, "infer-layout-map", ""),
291+
clEnumValN(LayoutMapOption::IdentityLayoutMap, "identity-layout-map", ""),
292+
clEnumValN(LayoutMapOption::FullyDynamicLayoutMap, "fully-dynamic-layout-map", "")
293+
)}];
294+
}
295+
287296
def OneShotBufferizePass : Pass<"one-shot-bufferize", "ModuleOp"> {
288297
let summary = "One-Shot Bufferize";
289298
let description = [{
@@ -424,9 +433,10 @@ def OneShotBufferizePass : Pass<"one-shot-bufferize", "ModuleOp"> {
424433
"Skip analysis of functions with these symbol names."
425434
"Set copyBeforeWrite to true when bufferizing them.">,
426435
Option<"functionBoundaryTypeConversion",
427-
"function-boundary-type-conversion", "std::string",
428-
/*default=*/"\"infer-layout-map\"",
429-
"Controls layout maps when bufferizing function signatures.">,
436+
"function-boundary-type-conversion", "LayoutMapOption",
437+
/*default=*/"LayoutMapOption::InferLayoutMap",
438+
"Controls layout maps when bufferizing function signatures.",
439+
layoutMapClValues.values>,
430440
Option<"mustInferMemorySpace", "must-infer-memory-space", "bool",
431441
/*default=*/"false",
432442
"The memory space of an memref types must always be inferred. If "
@@ -444,9 +454,10 @@ def OneShotBufferizePass : Pass<"one-shot-bufferize", "ModuleOp"> {
444454
/*default=*/"false",
445455
"Test only: Annotate IR with RaW conflicts. Requires "
446456
"test-analysis-only.">,
447-
Option<"unknownTypeConversion", "unknown-type-conversion", "std::string",
448-
/*default=*/"\"fully-dynamic-layout-map\"",
449-
"Controls layout maps for non-inferrable memref types.">,
457+
Option<"unknownTypeConversion", "unknown-type-conversion", "LayoutMapOption",
458+
/*default=*/"LayoutMapOption::FullyDynamicLayoutMap",
459+
"Controls layout maps for non-inferrable memref types.",
460+
layoutMapClValues.values>,
450461
Option<"bufferAlignment", "buffer-alignment", "uint64_t",
451462
/*default=*/"64",
452463
"Sets the alignment of newly allocated buffers.">,

mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ using namespace mlir::bufferization;
3838

3939
namespace {
4040

41-
static LayoutMapOption parseLayoutMapOption(const std::string &s) {
42-
if (s == "fully-dynamic-layout-map")
43-
return LayoutMapOption::FullyDynamicLayoutMap;
44-
if (s == "identity-layout-map")
45-
return LayoutMapOption::IdentityLayoutMap;
46-
if (s == "infer-layout-map")
47-
return LayoutMapOption::InferLayoutMap;
48-
llvm_unreachable("invalid layout map option");
49-
}
50-
5141
static OneShotBufferizationOptions::AnalysisHeuristic
5242
parseHeuristicOption(const std::string &s) {
5343
if (s == "bottom-up")
@@ -83,8 +73,7 @@ struct OneShotBufferizePass
8373
opt.analysisHeuristic = parseHeuristicOption(analysisHeuristic);
8474
opt.copyBeforeWrite = copyBeforeWrite;
8575
opt.dumpAliasSets = dumpAliasSets;
86-
opt.setFunctionBoundaryTypeConversion(
87-
parseLayoutMapOption(functionBoundaryTypeConversion));
76+
opt.setFunctionBoundaryTypeConversion(functionBoundaryTypeConversion);
8877

8978
if (mustInferMemorySpace && useEncodingForMemorySpace) {
9079
emitError(getOperation()->getLoc())
@@ -118,8 +107,7 @@ struct OneShotBufferizePass
118107
opt.noAnalysisFuncFilter = noAnalysisFuncFilter;
119108

120109
// Configure type converter.
121-
LayoutMapOption unknownTypeConversionOption =
122-
parseLayoutMapOption(unknownTypeConversion);
110+
LayoutMapOption unknownTypeConversionOption = unknownTypeConversion;
123111
if (unknownTypeConversionOption == LayoutMapOption::InferLayoutMap) {
124112
emitError(UnknownLoc::get(&getContext()),
125113
"Invalid option: 'infer-layout-map' is not a valid value for "

0 commit comments

Comments
 (0)