From d023661115e2b878f5b68a31d092ea3619a77754 Mon Sep 17 00:00:00 2001 From: River Riddle Date: Thu, 17 Nov 2022 20:44:27 -0800 Subject: [PATCH] [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. --- mlir/include/mlir-c/IR.h | 9 +++++---- mlir/include/mlir/IR/OperationSupport.h | 9 +++++---- mlir/lib/Bindings/Python/IRCore.cpp | 3 ++- mlir/lib/CAPI/IR/IR.cpp | 4 ++-- mlir/lib/IR/AsmPrinter.cpp | 5 +++-- mlir/test/CAPI/ir.c | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/mlir/include/mlir-c/IR.h b/mlir/include/mlir-c/IR.h index daf097d..b4266bd 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 24732dec..aa34cd3 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -768,10 +768,11 @@ public: /// 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 f706951..a183809 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 98a3ff3..53b530d 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 248d0f4..c06e96d 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 308a3d8..a4a036c 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); -- 2.7.4