Skip to content

[mlir][resources] Add elideLargeResourceString OpPrintingFlags API #71829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

mfrancio
Copy link
Contributor

@mfrancio mfrancio commented Nov 9, 2023

Allows to set resourceStringCharLimit through an OpPrintingFlags API
to avoid printing resources larger than the privided limit.

Allows to set `resourceStringCharLimit` through an OpPrintingFlags API
to avoid printing resources larger than the privided limit.
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Nov 9, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 9, 2023

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: Matteo Franciolini (mfrancio)

Changes

Allows to set resourceStringCharLimit through an OpPrintingFlags API
to avoid printing resources larger than the privided limit.


Full diff: https://github.com/llvm/llvm-project/pull/71829.diff

2 Files Affected:

  • (modified) mlir/include/mlir/IR/OperationSupport.h (+6)
  • (modified) mlir/lib/IR/AsmPrinter.cpp (+6)
diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h
index bb3d1643e1687ab..6a5ec129ad564b4 100644
--- a/mlir/include/mlir/IR/OperationSupport.h
+++ b/mlir/include/mlir/IR/OperationSupport.h
@@ -1131,6 +1131,12 @@ class OpPrintingFlags {
   /// elements.
   OpPrintingFlags &elideLargeElementsAttrs(int64_t largeElementLimit = 16);
 
+  /// Enables the elision of large resources strings by omitting them from the
+  /// `dialect_resources` section. The `largeResourceLimit` is used to configure
+  /// what is considered to be a "large" resource by providing an upper limit to
+  /// the string size.
+  OpPrintingFlags &elideLargeResourceString(int64_t largeResourceLimit = 64);
+
   /// 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
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index 82e1e96229b79e0..dae7fdd40b5456c 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -226,6 +226,12 @@ OpPrintingFlags::elideLargeElementsAttrs(int64_t largeElementLimit) {
   return *this;
 }
 
+OpPrintingFlags &
+OpPrintingFlags::elideLargeResourceString(int64_t largeResourceLimit) {
+  resourceStringCharLimit = largeResourceLimit;
+  return *this;
+}
+
 /// 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 enable,

Copy link
Member

@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funnily I was about to send a PR like this, so biasedly approved :)

@mfrancio mfrancio merged commit 5195d45 into llvm:main Nov 10, 2023
@mfrancio mfrancio deleted the dev/mfrancio/elideLargeResources branch November 10, 2023 00:30
@joker-eph
Copy link
Collaborator

Can we parse back the result of using this flag?
This was an important aspect of designing the “elide attr” feature.

@mfrancio
Copy link
Contributor Author

Can we parse back the result of using this flag? This was an important aspect of designing the “elide attr” feature.

Thanks for the note. Yes, this flag simply exposes the work done here:
https://reviews.llvm.org/D157928

We did not notice any roundtripping issue.

zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
…lvm#71829)

Allows to set `resourceStringCharLimit` through an OpPrintingFlags API
to avoid printing resources larger than the privided limit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:core MLIR Core Infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants