forked from OSchip/llvm-project
Delicately re-layer Operation, Statement, and OperationStmt, reworking
#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
This commit is contained in:
parent
4fbcd1ac52
commit
1b430f1d32
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue