[Mlir-commits] [mlir] d023661 - [mlir][AsmPrinter] Allow explicitly disabling debug info
River Riddle
llvmlistbot at llvm.org
Fri Nov 18 02:10:13 PST 2022
Author: River Riddle
Date: 2022-11-18T02:09:57-08:00
New Revision: d023661115e2b878f5b68a31d092ea3619a77754
URL: https://github.com/llvm/llvm-project/commit/d023661115e2b878f5b68a31d092ea3619a77754
DIFF: https://github.com/llvm/llvm-project/commit/d023661115e2b878f5b68a31d092ea3619a77754.diff
LOG: [mlir][AsmPrinter] Allow explicitly disabling debug info
This adds an `enable` flag to OpPrintingFlags::enableDebugInfo
that allows for overriding any command line flags for debug printing,
and matches the format that we use for other `enableBlah` API.
Added:
Modified:
mlir/include/mlir-c/IR.h
mlir/include/mlir/IR/OperationSupport.h
mlir/lib/Bindings/Python/IRCore.cpp
mlir/lib/CAPI/IR/IR.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/test/CAPI/ir.c
Removed:
################################################################################
diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h
index daf097da233f3..b4266bd0a1f59 100644
--- a/mlir/include/mlir-c/IR.h
+++ b/mlir/include/mlir-c/IR.h
@@ -376,11 +376,12 @@ MLIR_CAPI_EXPORTED void
mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags,
intptr_t largeElementLimit);
-/// Enable printing of debug information. If 'prettyForm' is set to true,
-/// debug information is printed in a more readable 'pretty' form. Note: The
-/// IR generated with 'prettyForm' is not parsable.
+/// Enable or disable printing of debug information (based on `enable`). If
+/// 'prettyForm' is set to true, debug information is printed in a more readable
+/// 'pretty' form. Note: The IR generated with 'prettyForm' is not parsable.
MLIR_CAPI_EXPORTED void
-mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool prettyForm);
+mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable,
+ bool prettyForm);
/// Always print operations in the generic form.
MLIR_CAPI_EXPORTED void
diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index 24732decc856a..aa34cd3a960d5 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -768,10 +768,11 @@ class OpPrintingFlags {
/// elements.
OpPrintingFlags &elideLargeElementsAttrs(int64_t largeElementLimit = 16);
- /// Enable printing of debug information. If 'prettyForm' is set to true,
- /// debug information is printed in a more readable 'pretty' form. Note: The
- /// IR generated with 'prettyForm' is not parsable.
- OpPrintingFlags &enableDebugInfo(bool prettyForm = false);
+ /// Enable or disable printing of debug information (based on `enable`). If
+ /// 'prettyForm' is set to true, debug information is printed in a more
+ /// readable 'pretty' form. Note: The IR generated with 'prettyForm' is not
+ /// parsable.
+ OpPrintingFlags &enableDebugInfo(bool enable = true, bool prettyForm = false);
/// Always print operations in the generic form.
OpPrintingFlags &printGenericOpForm();
diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp
index f706951e6702c..a183809a3cf3c 100644
--- a/mlir/lib/Bindings/Python/IRCore.cpp
+++ b/mlir/lib/Bindings/Python/IRCore.cpp
@@ -1017,7 +1017,8 @@ void PyOperationBase::print(py::object fileObject, bool binary,
if (largeElementsLimit)
mlirOpPrintingFlagsElideLargeElementsAttrs(flags, *largeElementsLimit);
if (enableDebugInfo)
- mlirOpPrintingFlagsEnableDebugInfo(flags, /*prettyForm=*/prettyDebugInfo);
+ mlirOpPrintingFlagsEnableDebugInfo(flags, /*enable=*/true,
+ /*prettyForm=*/prettyDebugInfo);
if (printGenericOpForm)
mlirOpPrintingFlagsPrintGenericOpForm(flags);
if (useLocalScope)
diff --git a/mlir/lib/CAPI/IR/IR.cpp b/mlir/lib/CAPI/IR/IR.cpp
index 98a3ff348e4f0..53b530d3f27d2 100644
--- a/mlir/lib/CAPI/IR/IR.cpp
+++ b/mlir/lib/CAPI/IR/IR.cpp
@@ -127,9 +127,9 @@ void mlirOpPrintingFlagsElideLargeElementsAttrs(MlirOpPrintingFlags flags,
unwrap(flags)->elideLargeElementsAttrs(largeElementLimit);
}
-void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags,
+void mlirOpPrintingFlagsEnableDebugInfo(MlirOpPrintingFlags flags, bool enable,
bool prettyForm) {
- unwrap(flags)->enableDebugInfo(/*prettyForm=*/prettyForm);
+ unwrap(flags)->enableDebugInfo(enable, /*prettyForm=*/prettyForm);
}
void mlirOpPrintingFlagsPrintGenericOpForm(MlirOpPrintingFlags flags) {
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 248d0f4703dcb..c06e96db32bbf 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -210,8 +210,9 @@ OpPrintingFlags::elideLargeElementsAttrs(int64_t largeElementLimit) {
/// Enable printing of debug information. If 'prettyForm' is set to true,
/// debug information is printed in a more readable 'pretty' form.
-OpPrintingFlags &OpPrintingFlags::enableDebugInfo(bool prettyForm) {
- printDebugInfoFlag = true;
+OpPrintingFlags &OpPrintingFlags::enableDebugInfo(bool enable,
+ bool prettyForm) {
+ printDebugInfoFlag = enable;
printDebugInfoPrettyFormFlag = prettyForm;
return *this;
}
diff --git a/mlir/test/CAPI/ir.c b/mlir/test/CAPI/ir.c
index 308a3d87a8d1d..a4a036c699f9b 100644
--- a/mlir/test/CAPI/ir.c
+++ b/mlir/test/CAPI/ir.c
@@ -467,7 +467,7 @@ static void printFirstOfEach(MlirContext ctx, MlirOperation operation) {
MlirOpPrintingFlags flags = mlirOpPrintingFlagsCreate();
mlirOpPrintingFlagsElideLargeElementsAttrs(flags, 2);
mlirOpPrintingFlagsPrintGenericOpForm(flags);
- mlirOpPrintingFlagsEnableDebugInfo(flags, /*prettyForm=*/0);
+ mlirOpPrintingFlagsEnableDebugInfo(flags, /*enable=*/1, /*prettyForm=*/0);
mlirOpPrintingFlagsUseLocalScope(flags);
fprintf(stderr, "Op print with all flags: ");
mlirOperationPrintWithFlags(operation, flags, printToStderr, NULL);
More information about the Mlir-commits
mailing list