[Mlir-commits] [mlir] 36b538f - [mlir][NFC] Move several small methods from .cpp to .h to allow more aggressive inlining

River Riddle llvmlistbot at llvm.org
Tue Jun 22 17:53:06 PDT 2021


Author: River Riddle
Date: 2021-06-23T00:52:26Z
New Revision: 36b538f583a7dfadf8f6c677b61110ee239e7e4d

URL: https://github.com/llvm/llvm-project/commit/36b538f583a7dfadf8f6c677b61110ee239e7e4d
DIFF: https://github.com/llvm/llvm-project/commit/36b538f583a7dfadf8f6c677b61110ee239e7e4d.diff

LOG: [mlir][NFC] Move several small methods from .cpp to .h to allow more aggressive inlining

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/Attributes.h
    mlir/include/mlir/IR/Operation.h
    mlir/include/mlir/IR/Region.h
    mlir/include/mlir/IR/Types.h
    mlir/lib/IR/Attributes.cpp
    mlir/lib/IR/Operation.cpp
    mlir/lib/IR/Region.cpp
    mlir/lib/IR/Types.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/Attributes.h b/mlir/include/mlir/IR/Attributes.h
index 590faed466a8e..2bc294b3609f6 100644
--- a/mlir/include/mlir/IR/Attributes.h
+++ b/mlir/include/mlir/IR/Attributes.h
@@ -67,7 +67,9 @@ class Attribute {
   MLIRContext *getContext() const;
 
   /// Get the dialect this attribute is registered to.
-  Dialect &getDialect() const;
+  Dialect &getDialect() const {
+    return impl->getAbstractAttribute().getDialect();
+  }
 
   /// Print the attribute.
   void print(raw_ostream &os) const;

diff  --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h
index 00eb2c5d973ff..6baa799f2c639 100644
--- a/mlir/include/mlir/IR/Operation.h
+++ b/mlir/include/mlir/IR/Operation.h
@@ -96,11 +96,11 @@ class alignas(8) Operation final
   Block *getBlock() { return block; }
 
   /// Return the context this operation is associated with.
-  MLIRContext *getContext();
+  MLIRContext *getContext() { return location->getContext(); }
 
   /// Return the dialect this operation is associated with, or nullptr if the
   /// associated dialect is not registered.
-  Dialect *getDialect();
+  Dialect *getDialect() { return getName().getDialect(); }
 
   /// The source location the operation was defined or derived from.
   Location getLoc() { return location; }
@@ -110,11 +110,11 @@ class alignas(8) Operation final
 
   /// Returns the region to which the instruction belongs. Returns nullptr if
   /// the instruction is unlinked.
-  Region *getParentRegion();
+  Region *getParentRegion() { return block ? block->getParent() : nullptr; }
 
   /// Returns the closest surrounding operation that contains this operation
   /// or nullptr if this is a top-level operation.
-  Operation *getParentOp();
+  Operation *getParentOp() { return block ? block->getParentOp() : nullptr; }
 
   /// Return the closest surrounding parent operation that is of type 'OpTy'.
   template <typename OpTy> OpTy getParentOfType() {

diff  --git a/mlir/include/mlir/IR/Region.h b/mlir/include/mlir/IR/Region.h
index 720a5ae09eefe..f2a4aeb8e5f1e 100644
--- a/mlir/include/mlir/IR/Region.h
+++ b/mlir/include/mlir/IR/Region.h
@@ -191,7 +191,7 @@ class Region {
   Region *getParentRegion();
 
   /// Return the parent operation this region is attached to.
-  Operation *getParentOp();
+  Operation *getParentOp() { return container; }
 
   /// Find the first parent operation of the given type, or nullptr if there is
   /// no ancestor operation.

diff  --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h
index 3b714ab808e6e..a260aa5fc3636 100644
--- a/mlir/include/mlir/IR/Types.h
+++ b/mlir/include/mlir/IR/Types.h
@@ -111,7 +111,7 @@ class Type {
   MLIRContext *getContext() const;
 
   /// Get the dialect this type is registered to.
-  Dialect &getDialect() const;
+  Dialect &getDialect() const { return impl->getAbstractType().getDialect(); }
 
   // Convenience predicates.  This is only for floating point types,
   // derived types should use isa/dyn_cast.

diff  --git a/mlir/lib/IR/Attributes.cpp b/mlir/lib/IR/Attributes.cpp
index cb79aabfbcce9..4cc501d5819a6 100644
--- a/mlir/lib/IR/Attributes.cpp
+++ b/mlir/lib/IR/Attributes.cpp
@@ -37,11 +37,6 @@ Type Attribute::getType() const { return impl->getType(); }
 /// Return the context this attribute belongs to.
 MLIRContext *Attribute::getContext() const { return getDialect().getContext(); }
 
-/// Get the dialect this attribute is registered to.
-Dialect &Attribute::getDialect() const {
-  return impl->getAbstractAttribute().getDialect();
-}
-
 //===----------------------------------------------------------------------===//
 // NamedAttribute
 //===----------------------------------------------------------------------===//

diff  --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp
index 74d8b4450e3e3..cff686574efb9 100644
--- a/mlir/lib/IR/Operation.cpp
+++ b/mlir/lib/IR/Operation.cpp
@@ -216,21 +216,6 @@ void Operation::destroy() {
   free(rawMem);
 }
 
-/// Return the context this operation is associated with.
-MLIRContext *Operation::getContext() { return location->getContext(); }
-
-/// Return the dialect this operation is associated with, or nullptr if the
-/// associated dialect is not registered.
-Dialect *Operation::getDialect() { return getName().getDialect(); }
-
-Region *Operation::getParentRegion() {
-  return block ? block->getParent() : nullptr;
-}
-
-Operation *Operation::getParentOp() {
-  return block ? block->getParentOp() : nullptr;
-}
-
 /// Return true if this operation is a proper ancestor of the `other`
 /// operation.
 bool Operation::isProperAncestor(Operation *other) {

diff  --git a/mlir/lib/IR/Region.cpp b/mlir/lib/IR/Region.cpp
index b2600b58e9422..698e40582c92e 100644
--- a/mlir/lib/IR/Region.cpp
+++ b/mlir/lib/IR/Region.cpp
@@ -48,8 +48,6 @@ Region *Region::getParentRegion() {
   return container->getParentRegion();
 }
 
-Operation *Region::getParentOp() { return container; }
-
 bool Region::isProperAncestor(Region *other) {
   if (this == other)
     return false;

diff  --git a/mlir/lib/IR/Types.cpp b/mlir/lib/IR/Types.cpp
index ec32f367e76dc..defe2dacfac29 100644
--- a/mlir/lib/IR/Types.cpp
+++ b/mlir/lib/IR/Types.cpp
@@ -16,10 +16,6 @@ using namespace mlir::detail;
 // Type
 //===----------------------------------------------------------------------===//
 
-Dialect &Type::getDialect() const {
-  return impl->getAbstractType().getDialect();
-}
-
 MLIRContext *Type::getContext() const { return getDialect().getContext(); }
 
 bool Type::isBF16() const { return isa<BFloat16Type>(); }


        


More information about the Mlir-commits mailing list