Delicately re-layer Operation, Statement, and OperationStmt, reworking
authorChris Lattner <clattner@google.com>
Thu, 27 Dec 2018 23:53:49 +0000 (15:53 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 21:41:05 +0000 (14:41 -0700)
#includes so Statements.h includes Operation.h but nothing else does.  This is
in preparation to eliminate the Operation class and the complexity it brings
with it.  I split this patch off because it is just moving stuff around, the
next patch will be more complex.

This is step 14/n towards merging instructions and statements, NFC.

PiperOrigin-RevId: 227071777

mlir/include/mlir/Analysis/AffineStructures.h
mlir/include/mlir/IR/Function.h
mlir/include/mlir/IR/Matchers.h
mlir/include/mlir/IR/OpDefinition.h
mlir/include/mlir/IR/Operation.h
mlir/include/mlir/IR/Statement.h
mlir/include/mlir/IR/Statements.h
mlir/include/mlir/IR/StmtBlock.h
mlir/lib/IR/AttributeListStorage.h

index a954dacc3f332ca975f8cdda541fc259bad9d115..70786a14444a5d43fe23edff776d36238aa4c202 100644 (file)
@@ -23,9 +23,6 @@
 #define MLIR_ANALYSIS_AFFINE_STRUCTURES_H
 
 #include "mlir/IR/AffineExpr.h"
-#include "mlir/IR/Operation.h"
-#include "mlir/Support/LLVM.h"
-#include "llvm/ADT/SmallVector.h"
 
 namespace mlir {
 
@@ -38,6 +35,7 @@ class IntegerSet;
 class MLIRContext;
 class Value;
 class HyperRectangularSet;
+class MemRefType;
 
 /// A mutable affine map. Its affine expressions are however unique.
 struct MutableAffineMap {
index 1a4e64fbc434654dc42fecc08ba7bfb977d9814d..ece70f3ef929945e9aa578f6ee57fed7fa75c66c 100644 (file)
@@ -27,7 +27,6 @@
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/Identifier.h"
 #include "mlir/IR/Location.h"
-#include "mlir/IR/Operation.h"
 #include "mlir/IR/StmtBlock.h"
 #include "mlir/IR/Types.h"
 #include "mlir/Support/LLVM.h"
@@ -39,6 +38,7 @@ class FunctionType;
 class MLIRContext;
 class Module;
 template <typename ObjectType, typename ElementType> class ArgumentIterator;
+using BasicBlock = StmtBlock;
 
 /// NamedAttribute is used for function attribute lists, it holds an
 /// identifier for the name and a value for the attribute.  The attribute
index 9ebe226600fb00743639555e164ede1bfed35c53..b8e947fbf99b0d3b305009d6435a385e1cd0c685 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinOps.h"
-#include "mlir/IR/Operation.h"
 #include "mlir/IR/Types.h"
 #include "mlir/IR/Value.h"
 #include <type_traits>
index 5262ba5975bf4be7e06e0d3ae43a1b87f8799efe..aa3be30d7d4a433175ce9c68b0c9028d8f21dd96 100644 (file)
@@ -28,8 +28,7 @@
 #ifndef MLIR_IR_OPDEFINITION_H
 #define MLIR_IR_OPDEFINITION_H
 
-#include "mlir/IR/Operation.h"
-#include "mlir/IR/Value.h"
+#include "mlir/IR/Statements.h"
 #include <type_traits>
 
 namespace mlir {
index eeee62cb647eca091ba0dbe0f380d6127ed794c5..d4ab877c473bedd5f21fbf85062a2a6abec36424 100644 (file)
@@ -19,6 +19,7 @@
 #define MLIR_IR_OPERATION_H
 
 #include "mlir/IR/OperationSupport.h"
+#include "mlir/IR/Statement.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/Twine.h"
 
@@ -315,67 +316,6 @@ private:
   AttributeListStorage *attrs;
 };
 
-/// This is a helper template used to implement an iterator that contains a
-/// pointer to some object and an index into it.  The iterator moves the
-/// index but keeps the object constant.
-template <typename ConcreteType, typename ObjectType, typename ElementType>
-class IndexedAccessorIterator
-    : public llvm::iterator_facade_base<
-          ConcreteType, std::random_access_iterator_tag, ElementType *,
-          std::ptrdiff_t, ElementType *, ElementType *> {
-public:
-  ptrdiff_t operator-(const IndexedAccessorIterator &rhs) const {
-    assert(object == rhs.object && "incompatible iterators");
-    return index - rhs.index;
-  }
-  bool operator==(const IndexedAccessorIterator &rhs) const {
-    return object == rhs.object && index == rhs.index;
-  }
-  bool operator<(const IndexedAccessorIterator &rhs) const {
-    assert(object == rhs.object && "incompatible iterators");
-    return index < rhs.index;
-  }
-
-  ConcreteType &operator+=(ptrdiff_t offset) {
-    this->index += offset;
-    return static_cast<ConcreteType &>(*this);
-  }
-  ConcreteType &operator-=(ptrdiff_t offset) {
-    this->index -= offset;
-    return static_cast<ConcreteType &>(*this);
-  }
-
-protected:
-  IndexedAccessorIterator(ObjectType *object, unsigned index)
-      : object(object), index(index) {}
-  ObjectType *object;
-  unsigned index;
-};
-
-/// This template implements the operand iterators for the various IR classes
-/// in terms of getOperand(idx).
-template <typename ObjectType, typename ElementType>
-class OperandIterator final
-    : public IndexedAccessorIterator<OperandIterator<ObjectType, ElementType>,
-                                     ObjectType, ElementType> {
-public:
-  /// Initializes the operand iterator to the specified operand index.
-  OperandIterator(ObjectType *object, unsigned index)
-      : IndexedAccessorIterator<OperandIterator<ObjectType, ElementType>,
-                                ObjectType, ElementType>(object, index) {}
-
-  /// Support converting to the const variant. This will be a no-op for const
-  /// variant.
-  operator OperandIterator<const ObjectType, const ElementType>() const {
-    return OperandIterator<const ObjectType, const ElementType>(this->object,
-                                                                this->index);
-  }
-
-  ElementType *operator*() const {
-    return this->object->getOperand(this->index);
-  }
-};
-
 /// This template implements the result iterators for the various IR classes
 /// in terms of getResult(idx).
 template <typename ObjectType, typename ElementType>
index 2871b274de1afecd44f68577810e354d11f18336..97d35cf79bc3817e1748b240e55d4301b0ccbcfd 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef MLIR_IR_STATEMENT_H
 #define MLIR_IR_STATEMENT_H
 
-#include "mlir/IR/Operation.h"
 #include "mlir/IR/Value.h"
 #include "mlir/Support/LLVM.h"
 #include "llvm/ADT/ilist.h"
@@ -63,6 +62,7 @@ private:
 } // end namespace llvm
 
 namespace mlir {
+template <typename ObjectType, typename ElementType> class OperandIterator;
 
 /// Statement is a basic unit of execution within an ML function.
 /// Statements can be nested within for and if statements effectively
@@ -143,32 +143,22 @@ public:
   // Support non-const operand iteration.
   using operand_iterator = OperandIterator<Statement, Value>;
 
-  operand_iterator operand_begin() { return operand_iterator(this, 0); }
+  operand_iterator operand_begin();
 
-  operand_iterator operand_end() {
-    return operand_iterator(this, getNumOperands());
-  }
+  operand_iterator operand_end();
 
-  /// Returns an iterator on the underlying Value's (Value *).
-  llvm::iterator_range<operand_iterator> getOperands() {
-    return {operand_begin(), operand_end()};
-  }
+  /// Returns an iterator on the underlying Values.
+  llvm::iterator_range<operand_iterator> getOperands();
 
   // Support const operand iteration.
   using const_operand_iterator = OperandIterator<const Statement, const Value>;
 
-  const_operand_iterator operand_begin() const {
-    return const_operand_iterator(this, 0);
-  }
+  const_operand_iterator operand_begin() const;
 
-  const_operand_iterator operand_end() const {
-    return const_operand_iterator(this, getNumOperands());
-  }
+  const_operand_iterator operand_end() const;
 
-  /// Returns a const iterator on the underlying Value's (Value *).
-  llvm::iterator_range<const_operand_iterator> getOperands() const {
-    return {operand_begin(), operand_end()};
-  }
+  /// Returns a const iterator on the underlying Values.
+  llvm::iterator_range<const_operand_iterator> getOperands() const;
 
   MutableArrayRef<StmtOperand> getStmtOperands();
   ArrayRef<StmtOperand> getStmtOperands() const {
@@ -219,6 +209,94 @@ inline raw_ostream &operator<<(raw_ostream &os, const Statement &stmt) {
   stmt.print(os);
   return os;
 }
+
+/// This is a helper template used to implement an iterator that contains a
+/// pointer to some object and an index into it.  The iterator moves the
+/// index but keeps the object constant.
+template <typename ConcreteType, typename ObjectType, typename ElementType>
+class IndexedAccessorIterator
+    : public llvm::iterator_facade_base<
+          ConcreteType, std::random_access_iterator_tag, ElementType *,
+          std::ptrdiff_t, ElementType *, ElementType *> {
+public:
+  ptrdiff_t operator-(const IndexedAccessorIterator &rhs) const {
+    assert(object == rhs.object && "incompatible iterators");
+    return index - rhs.index;
+  }
+  bool operator==(const IndexedAccessorIterator &rhs) const {
+    return object == rhs.object && index == rhs.index;
+  }
+  bool operator<(const IndexedAccessorIterator &rhs) const {
+    assert(object == rhs.object && "incompatible iterators");
+    return index < rhs.index;
+  }
+
+  ConcreteType &operator+=(ptrdiff_t offset) {
+    this->index += offset;
+    return static_cast<ConcreteType &>(*this);
+  }
+  ConcreteType &operator-=(ptrdiff_t offset) {
+    this->index -= offset;
+    return static_cast<ConcreteType &>(*this);
+  }
+
+protected:
+  IndexedAccessorIterator(ObjectType *object, unsigned index)
+      : object(object), index(index) {}
+  ObjectType *object;
+  unsigned index;
+};
+
+/// This template implements the const/non-const operand iterators for the
+/// Instruction class in terms of getOperand(idx).
+template <typename ObjectType, typename ElementType>
+class OperandIterator final
+    : public IndexedAccessorIterator<OperandIterator<ObjectType, ElementType>,
+                                     ObjectType, ElementType> {
+public:
+  /// Initializes the operand iterator to the specified operand index.
+  OperandIterator(ObjectType *object, unsigned index)
+      : IndexedAccessorIterator<OperandIterator<ObjectType, ElementType>,
+                                ObjectType, ElementType>(object, index) {}
+
+  /// Support converting to the const variant. This will be a no-op for const
+  /// variant.
+  operator OperandIterator<const ObjectType, const ElementType>() const {
+    return OperandIterator<const ObjectType, const ElementType>(this->object,
+                                                                this->index);
+  }
+
+  ElementType *operator*() const {
+    return this->object->getOperand(this->index);
+  }
+};
+
+// Implement the inline operand iterator methods.
+inline auto Statement::operand_begin() -> operand_iterator {
+  return operand_iterator(this, 0);
+}
+
+inline auto Statement::operand_end() -> operand_iterator {
+  return operand_iterator(this, getNumOperands());
+}
+
+inline auto Statement::getOperands() -> llvm::iterator_range<operand_iterator> {
+  return {operand_begin(), operand_end()};
+}
+
+inline auto Statement::operand_begin() const -> const_operand_iterator {
+  return const_operand_iterator(this, 0);
+}
+
+inline auto Statement::operand_end() const -> const_operand_iterator {
+  return const_operand_iterator(this, getNumOperands());
+}
+
+inline auto Statement::getOperands() const
+    -> llvm::iterator_range<const_operand_iterator> {
+  return {operand_begin(), operand_end()};
+}
+
 } // end namespace mlir
 
 #endif  // MLIR_IR_STATEMENT_H
index 1ca511c00fa1effdbcb1c8519edd477f864ceb76..b224ab0b1f5d217d7bc19a7b48a1640e5cb30881 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "mlir/IR/AffineMap.h"
 #include "mlir/IR/IntegerSet.h"
+#include "mlir/IR/Operation.h"
 #include "mlir/IR/StmtBlock.h"
 #include "llvm/Support/TrailingObjects.h"
 
index e2885430c6c017ab2f039a6e6c62728f0a70f37d..a5487319da48d5aded428f19058647a85831629f 100644 (file)
@@ -23,6 +23,7 @@
 #define MLIR_IR_STMTBLOCK_H
 
 #include "mlir/IR/Statement.h"
+#include "llvm/ADT/PointerUnion.h"
 
 namespace mlir {
 class IfStmt;
@@ -218,7 +219,7 @@ public:
   // Other
   //===--------------------------------------------------------------------===//
 
-  /// Unlink this BasicBlock from its CFGFunction and delete it.
+  /// Unlink this Block from its Function and delete it.
   void eraseFromFunction();
 
   /// Split the basic block into two basic blocks before the specified
@@ -228,11 +229,11 @@ public:
   /// the original basic block, an unconditional branch is added to the original
   /// block (going to the new block), and the rest of the instructions in the
   /// original block are moved to the new BB, including the old terminator.  The
-  /// newly formed BasicBlock is returned.
+  /// newly formed Block is returned.
   ///
   /// This function invalidates the specified iterator.
-  BasicBlock *splitBasicBlock(iterator splitBefore);
-  BasicBlock *splitBasicBlock(Instruction *splitBeforeInst) {
+  StmtBlock *splitBasicBlock(iterator splitBefore);
+  StmtBlock *splitBasicBlock(Instruction *splitBeforeInst) {
     return splitBasicBlock(iterator(splitBeforeInst));
   }
 
index d4a6298f481aa9e9bf8909c05bac500c43e6c9a5..de6e4a0557cfc27d8a146bc457061e3eeef6d7a5 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef ATTRIBUTELISTSTORAGE_H
 #define ATTRIBUTELISTSTORAGE_H
 
-#include "mlir/IR/Operation.h"
+#include "mlir/IR/OperationSupport.h"
 #include "llvm/Support/TrailingObjects.h"
 
 namespace mlir {