[Mlir-commits] [mlir] 19ced83 - Check if an attribute is in the builtin dialect before going through all the possible combinations (NFC)

Mehdi Amini llvmlistbot at llvm.org
Mon Nov 1 22:57:52 PDT 2021


Author: Mehdi Amini
Date: 2021-11-02T05:57:40Z
New Revision: 19ced834ccc5adb93ee7ea2c6dbb128bd62af2ac

URL: https://github.com/llvm/llvm-project/commit/19ced834ccc5adb93ee7ea2c6dbb128bd62af2ac
DIFF: https://github.com/llvm/llvm-project/commit/19ced834ccc5adb93ee7ea2c6dbb128bd62af2ac.diff

LOG: Check if an attribute is in the builtin dialect before going through all the possible combinations (NFC)

This is just a "micro-optimization" noticed through code review.

Differential Revision: https://reviews.llvm.org/D112984

Added: 
    

Modified: 
    mlir/lib/IR/AsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index cf1eb8b56d807..15625255f3374 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -16,6 +16,7 @@
 #include "mlir/IR/AsmState.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/Builders.h"
+#include "mlir/IR/BuiltinDialect.h"
 #include "mlir/IR/BuiltinTypes.h"
 #include "mlir/IR/Dialect.h"
 #include "mlir/IR/DialectImplementation.h"
@@ -1608,6 +1609,9 @@ void AsmPrinter::Impl::printAttribute(Attribute attr,
   if (state && succeeded(state->getAliasState().getAlias(attr, os)))
     return;
 
+  if (!isa<BuiltinDialect>(attr.getDialect()))
+    return printDialectAttribute(attr);
+
   auto attrType = attr.getType();
   if (auto opaqueAttr = attr.dyn_cast<OpaqueAttr>()) {
     printDialectSymbol(os, "#", opaqueAttr.getDialectNamespace(),
@@ -1728,11 +1732,7 @@ void AsmPrinter::Impl::printAttribute(Attribute attr,
 
   } else if (auto locAttr = attr.dyn_cast<LocationAttr>()) {
     printLocation(locAttr);
-
-  } else {
-    return printDialectAttribute(attr);
   }
-
   // Don't print the type if we must elide it, or if it is a None type.
   if (typeElision != AttrTypeElision::Must && !attrType.isa<NoneType>()) {
     os << " : ";


        


More information about the Mlir-commits mailing list