[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.
This commit is contained in:
River Riddle
2022-11-17 20:44:27 -08:00
parent 446fc42d7c
commit d023661115
6 changed files with 18 additions and 14 deletions

View File

@@ -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

View File

@@ -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();

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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);