Rename BlockList into Region
authorAlex Zinenko <zinenko@google.com>
Thu, 14 Mar 2019 17:38:44 +0000 (10:38 -0700)
committerjpienaar <jpienaar@google.com>
Sat, 30 Mar 2019 00:18:04 +0000 (17:18 -0700)
NFC.  This is step 1/n to specifying regions as parts of any operation.

PiperOrigin-RevId: 238472370

28 files changed:
mlir/include/mlir/AffineOps/AffineOps.h
mlir/include/mlir/Analysis/Dominance.h
mlir/include/mlir/IR/Block.h
mlir/include/mlir/IR/Function.h
mlir/include/mlir/IR/FunctionGraphTraits.h
mlir/include/mlir/IR/Instruction.h
mlir/include/mlir/IR/OpImplementation.h
mlir/include/mlir/IR/OperationSupport.h
mlir/lib/AffineOps/AffineOps.cpp
mlir/lib/Analysis/Dominance.cpp
mlir/lib/Analysis/LoopAnalysis.cpp
mlir/lib/Analysis/Utils.cpp
mlir/lib/Analysis/Verifier.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/Block.cpp
mlir/lib/IR/Builders.cpp
mlir/lib/IR/Function.cpp
mlir/lib/IR/Instruction.cpp
mlir/lib/Parser/Parser.cpp
mlir/lib/Transforms/CSE.cpp
mlir/lib/Transforms/DialectConversion.cpp
mlir/lib/Transforms/LoopFusion.cpp
mlir/lib/Transforms/LoopUnroll.cpp
mlir/lib/Transforms/LoopUnrollAndJam.cpp
mlir/lib/Transforms/MaterializeVectors.cpp
mlir/lib/Transforms/Vectorize.cpp
mlir/test/IR/invalid.mlir
mlir/test/IR/parser.mlir

index 487b0a3..a70d810 100644 (file)
@@ -142,14 +142,12 @@ public:
   Block *createBody();
 
   /// Get the body of the AffineForOp.
-  Block *getBody() { return &getBlockList().front(); }
-  const Block *getBody() const { return &getBlockList().front(); }
+  Block *getBody() { return &getRegion().front(); }
+  const Block *getBody() const { return &getRegion().front(); }
 
-  /// Get the blocklist containing the body.
-  BlockList &getBlockList() { return getInstruction()->getBlockList(0); }
-  const BlockList &getBlockList() const {
-    return getInstruction()->getBlockList(0);
-  }
+  /// Get the body region of the AffineForOp.
+  Region &getRegion() { return getInstruction()->getRegion(0); }
+  const Region &getRegion() const { return getInstruction()->getRegion(0); }
 
   /// Returns the induction variable for this loop.
   Value *getInductionVar();
@@ -332,15 +330,15 @@ public:
   IntegerSet getIntegerSet() const;
   void setIntegerSet(IntegerSet newSet);
 
-  /// Returns the list of 'then' blocks.
-  BlockList &getThenBlocks();
-  const BlockList &getThenBlocks() const {
+  /// Returns the 'then' region.
+  Region &getThenBlocks();
+  const Region &getThenBlocks() const {
     return const_cast<AffineIfOp *>(this)->getThenBlocks();
   }
 
-  /// Returns the list of 'else' blocks.
-  BlockList &getElseBlocks();
-  const BlockList &getElseBlocks() const {
+  /// Returns the 'else' blocks.
+  Region &getElseBlocks();
+  const Region &getElseBlocks() const {
     return const_cast<AffineIfOp *>(this)->getElseBlocks();
   }
 
index edf5a36..6ab1b87 100644 (file)
@@ -43,10 +43,10 @@ public:
   /// Recalculate the dominance info for the provided function.
   void recalculate(Function *function);
 
-  /// Get the root dominance node of the given block list.
-  DominanceInfoNode *getRootNode(const BlockList *blockList) {
-    assert(dominanceInfos.count(blockList) != 0);
-    return dominanceInfos[blockList]->getRootNode();
+  /// Get the root dominance node of the given region.
+  DominanceInfoNode *getRootNode(const Region *region) {
+    assert(dominanceInfos.count(region) != 0);
+    return dominanceInfos[region]->getRootNode();
   }
 
 protected:
@@ -55,8 +55,8 @@ protected:
   /// Return true if the specified block A properly dominates block B.
   bool properlyDominates(const Block *a, const Block *b);
 
-  /// A mapping of block lists to their base dominator tree.
-  DenseMap<const BlockList *, std::unique_ptr<base>> dominanceInfos;
+  /// A mapping of regions to their base dominator tree.
+  DenseMap<const Region *, std::unique_ptr<base>> dominanceInfos;
 };
 } // end namespace detail
 
index da02db8..babc150 100644 (file)
@@ -1,4 +1,4 @@
-//===- Block.h - MLIR Block and BlockList Classes ---------------*- C++ -*-===//
+//===- Block.h - MLIR Block and Region Classes ------------------*- C++ -*-===//
 //
 // Copyright 2019 The MLIR Authors.
 //
@@ -15,7 +15,7 @@
 // limitations under the License.
 // =============================================================================
 //
-// This file defines Block and BlockList classes.
+// This file defines Block and Region classes.
 //
 //===----------------------------------------------------------------------===//
 
@@ -35,7 +35,7 @@ namespace llvm {
 namespace ilist_detail {
 // Explicitly define the node access for the instruction list so that we can
 // break the dependence on the Instruction class in this header. This allows for
-// instructions to have trailing BlockLists without a circular include
+// instructions to have trailing Regions without a circular include
 // dependence.
 template <>
 struct SpecificNodeAccess<
@@ -71,7 +71,7 @@ private:
 
 namespace mlir {
 class BlockAndValueMapping;
-class BlockList;
+class Region;
 class Function;
 
 using BlockOperand = IROperandImpl<Block>;
@@ -81,7 +81,7 @@ template <typename BlockType> class SuccessorIterator;
 
 /// `Block` represents an ordered list of `Instruction`s.
 class Block : public IRObjectWithUseList,
-              public llvm::ilist_node_with_parent<Block, BlockList> {
+              public llvm::ilist_node_with_parent<Block, Region> {
 public:
   explicit Block() {}
   ~Block();
@@ -96,8 +96,8 @@ public:
       instructions.pop_back();
   }
 
-  /// Blocks are maintained in a list of BlockList type.
-  BlockList *getParent() const { return parentValidInstOrderPair.getPointer(); }
+  /// Blocks are maintained in a Region.
+  Region *getParent() const { return parentValidInstOrderPair.getPointer(); }
 
   /// Returns the closest surrounding instruction that contains this block or
   /// nullptr if this is a top-level block.
@@ -339,8 +339,7 @@ public:
 private:
   /// Pair of the parent object that owns this block and a bit that signifies if
   /// the instructions within this block have a valid ordering.
-  llvm::PointerIntPair<BlockList *, /*IntBits=*/1, bool>
-      parentValidInstOrderPair;
+  llvm::PointerIntPair<Region *, /*IntBits=*/1, bool> parentValidInstOrderPair;
 
   /// This is the list of instructions in the block.
   InstListType instructions;
@@ -373,7 +372,7 @@ struct ilist_traits<::mlir::Block> : public ilist_alloc_traits<::mlir::Block> {
                              block_iterator first, block_iterator last);
 
 private:
-  mlir::BlockList *getContainingBlockList();
+  mlir::Region *getContainingRegion();
 };
 } // end namespace llvm
 
@@ -381,20 +380,20 @@ namespace mlir {
 
 /// This class contains a list of basic blocks and has a notion of the object it
 /// is part of - a Function or an operation region.
-class BlockList {
+class Region {
 public:
-  explicit BlockList(Function *container);
-  explicit BlockList(Instruction *container);
+  explicit Region(Function *container);
+  explicit Region(Instruction *container);
 
-  using BlockListType = llvm::iplist<Block>;
-  BlockListType &getBlocks() { return blocks; }
-  const BlockListType &getBlocks() const { return blocks; }
+  using RegionType = llvm::iplist<Block>;
+  RegionType &getBlocks() { return blocks; }
+  const RegionType &getBlocks() const { return blocks; }
 
   // Iteration over the block in the function.
-  using iterator = BlockListType::iterator;
-  using const_iterator = BlockListType::const_iterator;
-  using reverse_iterator = BlockListType::reverse_iterator;
-  using const_reverse_iterator = BlockListType::const_reverse_iterator;
+  using iterator = RegionType::iterator;
+  using const_iterator = RegionType::const_iterator;
+  using reverse_iterator = RegionType::reverse_iterator;
+  using const_reverse_iterator = RegionType::const_reverse_iterator;
 
   iterator begin() { return blocks.begin(); }
   iterator end() { return blocks.end(); }
@@ -410,40 +409,39 @@ public:
   void push_front(Block *block) { blocks.push_front(block); }
 
   Block &back() { return blocks.back(); }
-  const Block &back() const { return const_cast<BlockList *>(this)->back(); }
+  const Block &back() const { return const_cast<Region *>(this)->back(); }
 
   Block &front() { return blocks.front(); }
-  const Block &front() const { return const_cast<BlockList *>(this)->front(); }
+  const Block &front() const { return const_cast<Region *>(this)->front(); }
 
-  /// getSublistAccess() - Returns pointer to member of block list.
-  static BlockListType BlockList::*getSublistAccess(Block *) {
-    return &BlockList::blocks;
+  /// getSublistAccess() - Returns pointer to member of region.
+  static RegionType Region::*getSublistAccess(Block *) {
+    return &Region::blocks;
   }
 
-  /// A BlockList is part of a function or an operation region.  If it is
-  /// part of an operation region, then return the operation, otherwise return
-  /// null.
+  /// A Region is either a function body or a part of an operation.  If it is
+  /// part of an operation, then return the operation, otherwise return null.
   Instruction *getContainingInst();
   const Instruction *getContainingInst() const {
-    return const_cast<BlockList *>(this)->getContainingInst();
+    return const_cast<Region *>(this)->getContainingInst();
   }
 
-  /// A BlockList is part of a function or an operation region.  If it is part
-  /// of a Function, then return it, otherwise return null.
+  /// A Region is either a function body or a part of an operation.  If it is
+  /// a Function body, then return this function, otherwise return null.
   Function *getContainingFunction();
   const Function *getContainingFunction() const {
-    return const_cast<BlockList *>(this)->getContainingFunction();
+    return const_cast<Region *>(this)->getContainingFunction();
   }
 
-  /// Clone the internal blocks from this block list into dest. Any
+  /// Clone the internal blocks from this region into dest. Any
   /// cloned blocks are appended to the back of dest. If the mapper
   /// contains entries for block arguments, these arguments are not included
   /// in the respective cloned block.
-  void cloneInto(BlockList *dest, BlockAndValueMapping &mapper,
+  void cloneInto(Region *dest, BlockAndValueMapping &mapper,
                  MLIRContext *context) const;
 
 private:
-  BlockListType blocks;
+  RegionType blocks;
 
   /// This is the object we are part of.
   llvm::PointerUnion<Function *, Instruction *> container;
index 4a86640..221c5c4 100644 (file)
@@ -80,37 +80,37 @@ public:
   // Body Handling
   //===--------------------------------------------------------------------===//
 
-  BlockList &getBlockList() { return blocks; }
-  const BlockList &getBlockList() const { return blocks; }
+  Region &getBody() { return body; }
+  const Region &getBody() const { return body; }
 
   /// This is the list of blocks in the function.
-  using BlockListType = llvm::iplist<Block>;
-  BlockListType &getBlocks() { return blocks.getBlocks(); }
-  const BlockListType &getBlocks() const { return blocks.getBlocks(); }
+  using RegionType = llvm::iplist<Block>;
+  RegionType &getBlocks() { return body.getBlocks(); }
+  const RegionType &getBlocks() const { return body.getBlocks(); }
 
   // Iteration over the block in the function.
-  using iterator = BlockListType::iterator;
-  using const_iterator = BlockListType::const_iterator;
-  using reverse_iterator = BlockListType::reverse_iterator;
-  using const_reverse_iterator = BlockListType::const_reverse_iterator;
-
-  iterator begin() { return blocks.begin(); }
-  iterator end() { return blocks.end(); }
-  const_iterator begin() const { return blocks.begin(); }
-  const_iterator end() const { return blocks.end(); }
-  reverse_iterator rbegin() { return blocks.rbegin(); }
-  reverse_iterator rend() { return blocks.rend(); }
-  const_reverse_iterator rbegin() const { return blocks.rbegin(); }
-  const_reverse_iterator rend() const { return blocks.rend(); }
-
-  bool empty() const { return blocks.empty(); }
-  void push_back(Block *block) { blocks.push_back(block); }
-  void push_front(Block *block) { blocks.push_front(block); }
-
-  Block &back() { return blocks.back(); }
+  using iterator = RegionType::iterator;
+  using const_iterator = RegionType::const_iterator;
+  using reverse_iterator = RegionType::reverse_iterator;
+  using const_reverse_iterator = RegionType::const_reverse_iterator;
+
+  iterator begin() { return body.begin(); }
+  iterator end() { return body.end(); }
+  const_iterator begin() const { return body.begin(); }
+  const_iterator end() const { return body.end(); }
+  reverse_iterator rbegin() { return body.rbegin(); }
+  reverse_iterator rend() { return body.rend(); }
+  const_reverse_iterator rbegin() const { return body.rbegin(); }
+  const_reverse_iterator rend() const { return body.rend(); }
+
+  bool empty() const { return body.empty(); }
+  void push_back(Block *block) { body.push_back(block); }
+  void push_front(Block *block) { body.push_front(block); }
+
+  Block &back() { return body.back(); }
   const Block &back() const { return const_cast<Function *>(this)->back(); }
 
-  Block &front() { return blocks.front(); }
+  Block &front() { return body.front(); }
   const Block &front() const { return const_cast<Function *>(this)->front(); }
 
   //===--------------------------------------------------------------------===//
@@ -329,8 +329,8 @@ private:
   /// The attributes lists for each of the function arguments.
   std::vector<NamedAttributeList> argAttrs;
 
-  /// The contents of the body.
-  BlockList blocks;
+  /// The body of the function.
+  Region body;
 
   void operator=(const Function &) = delete;
   friend struct llvm::ilist_traits<Function>;
index 6ba50e7..b8a0d7e 100644 (file)
@@ -153,8 +153,8 @@ struct GraphTraits<Inverse<const mlir::Function *>>
 };
 
 template <>
-struct GraphTraits<mlir::BlockList *> : public GraphTraits<mlir::Block *> {
-  using GraphType = mlir::BlockList *;
+struct GraphTraits<mlir::Region *> : public GraphTraits<mlir::Block *> {
+  using GraphType = mlir::Region *;
   using NodeRef = mlir::Block *;
 
   static NodeRef getEntryNode(GraphType fn) { return &fn->front(); }
@@ -169,9 +169,9 @@ struct GraphTraits<mlir::BlockList *> : public GraphTraits<mlir::Block *> {
 };
 
 template <>
-struct GraphTraits<const mlir::BlockList *>
+struct GraphTraits<const mlir::Region *>
     : public GraphTraits<const mlir::Block *> {
-  using GraphType = const mlir::BlockList *;
+  using GraphType = const mlir::Region *;
   using NodeRef = const mlir::Block *;
 
   static NodeRef getEntryNode(GraphType fn) { return &fn->front(); }
@@ -186,9 +186,9 @@ struct GraphTraits<const mlir::BlockList *>
 };
 
 template <>
-struct GraphTraits<Inverse<mlir::BlockList *>>
+struct GraphTraits<Inverse<mlir::Region *>>
     : public GraphTraits<Inverse<mlir::Block *>> {
-  using GraphType = Inverse<mlir::BlockList *>;
+  using GraphType = Inverse<mlir::Region *>;
   using NodeRef = NodeRef;
 
   static NodeRef getEntryNode(GraphType fn) { return &fn.Graph->front(); }
@@ -203,9 +203,9 @@ struct GraphTraits<Inverse<mlir::BlockList *>>
 };
 
 template <>
-struct GraphTraits<Inverse<const mlir::BlockList *>>
+struct GraphTraits<Inverse<const mlir::Region *>>
     : public GraphTraits<Inverse<const mlir::Block *>> {
-  using GraphType = Inverse<const mlir::BlockList *>;
+  using GraphType = Inverse<const mlir::Region *>;
   using NodeRef = NodeRef;
 
   static NodeRef getEntryNode(GraphType fn) { return &fn.Graph->front(); }
index f9a3ac0..2bcbd8a 100644 (file)
@@ -49,15 +49,15 @@ using BlockOperand = IROperandImpl<Block>;
 class Instruction final
     : public llvm::ilist_node_with_parent<Instruction, Block>,
       private llvm::TrailingObjects<Instruction, InstResult, BlockOperand,
-                                    unsigned, BlockList,
-                                    detail::OperandStorage> {
+                                    unsigned, Region, detail::OperandStorage> {
 public:
   /// Create a new Instruction with the specific fields.
-  static Instruction *
-  create(Location location, OperationName name, ArrayRef<Value *> operands,
-         ArrayRef<Type> resultTypes, ArrayRef<NamedAttribute> attributes,
-         ArrayRef<Block *> successors, unsigned numBlockLists,
-         bool resizableOperandList, MLIRContext *context);
+  static Instruction *create(Location location, OperationName name,
+                             ArrayRef<Value *> operands,
+                             ArrayRef<Type> resultTypes,
+                             ArrayRef<NamedAttribute> attributes,
+                             ArrayRef<Block *> successors, unsigned numRegions,
+                             bool resizableOperandList, MLIRContext *context);
 
   /// The name of an operation is the key identifier for it.
   OperationName getName() const { return name; }
@@ -279,24 +279,24 @@ public:
   // Blocks
   //===--------------------------------------------------------------------===//
 
-  /// Returns the number of block lists held by this operation.
-  unsigned getNumBlockLists() const { return numBlockLists; }
+  /// Returns the number of regions held by this operation.
+  unsigned getNumRegions() const { return numRegions; }
 
-  /// Returns the block lists held by this operation.
-  MutableArrayRef<BlockList> getBlockLists() {
-    return {getTrailingObjects<BlockList>(), numBlockLists};
+  /// Returns the regions held by this operation.
+  MutableArrayRef<Region> getRegions() {
+    return {getTrailingObjects<Region>(), numRegions};
   }
-  ArrayRef<BlockList> getBlockLists() const {
-    return const_cast<Instruction *>(this)->getBlockLists();
+  ArrayRef<Region> getRegions() const {
+    return const_cast<Instruction *>(this)->getRegions();
   }
 
-  /// Returns the block list held by this operation at position 'index'.
-  BlockList &getBlockList(unsigned index) {
-    assert(index < numBlockLists && "invalid block list index");
-    return getBlockLists()[index];
+  /// Returns the region held by this operation at position 'index'.
+  Region &getRegion(unsigned index) {
+    assert(index < numRegions && "invalid region index");
+    return getRegions()[index];
   }
-  const BlockList &getBlockList(unsigned index) const {
-    return const_cast<Instruction *>(this)->getBlockList(index);
+  const Region &getRegion(unsigned index) const {
+    return const_cast<Instruction *>(this)->getRegion(index);
   }
 
   //===--------------------------------------------------------------------===//
@@ -528,7 +528,7 @@ public:
 
 protected:
   Instruction(Location location, OperationName name, unsigned numResults,
-              unsigned numSuccessors, unsigned numBlockLists,
+              unsigned numSuccessors, unsigned numRegions,
               ArrayRef<NamedAttribute> attributes, MLIRContext *context);
 
   // Instructions are deleted through the destroy() member because they are
@@ -558,7 +558,7 @@ private:
   /// O(1) local dominance checks between instructions.
   mutable unsigned orderIndex = 0;
 
-  const unsigned numResults, numSuccs, numBlockLists;
+  const unsigned numResults, numSuccs, numRegions;
 
   /// This holds the name of the operation.
   OperationName name;
@@ -577,16 +577,14 @@ private:
 
   // This stuff is used by the TrailingObjects template.
   friend llvm::TrailingObjects<Instruction, InstResult, BlockOperand, unsigned,
-                               BlockList, detail::OperandStorage>;
+                               Region, detail::OperandStorage>;
   size_t numTrailingObjects(OverloadToken<InstResult>) const {
     return numResults;
   }
   size_t numTrailingObjects(OverloadToken<BlockOperand>) const {
     return numSuccs;
   }
-  size_t numTrailingObjects(OverloadToken<BlockList>) const {
-    return numBlockLists;
-  }
+  size_t numTrailingObjects(OverloadToken<Region>) const { return numRegions; }
   size_t numTrailingObjects(OverloadToken<unsigned>) const { return numSuccs; }
 };
 
index c507832..fcdf2b6 100644 (file)
@@ -89,9 +89,9 @@ public:
   /// Print the entire operation with the default generic assembly form.
   virtual void printGenericOp(const Instruction *op) = 0;
 
-  /// Prints a block list.
-  virtual void printBlockList(const BlockList &blocks,
-                              bool printEntryBlockArgs = true) = 0;
+  /// Prints a region.
+  virtual void printRegion(const Region &blocks,
+                           bool printEntryBlockArgs = true) = 0;
 
 private:
   OpAsmPrinter(const OpAsmPrinter &) = delete;
@@ -314,13 +314,12 @@ public:
                            int requiredOperandCount = -1,
                            Delimiter delimiter = Delimiter::None) = 0;
 
-  /// Parses a block list. Any parsed blocks are filled in to the
-  /// operation's block lists after the operation is created.
-  virtual bool parseBlockList() = 0;
+  /// Parses a region. Any parsed blocks are filled in to the operation's
+  /// regions after the operation is created.
+  virtual bool parseRegion() = 0;
 
-  /// Parses an argument for the entry block of the next block list to be
-  /// parsed.
-  virtual bool parseBlockListEntryBlockArgument(Type argType) = 0;
+  /// Parses an argument for the entry block of the next region to be parsed.
+  virtual bool parseRegionEntryBlockArgument(Type argType) = 0;
 
   //===--------------------------------------------------------------------===//
   // Methods for interacting with the parser
index a3e2911..5c45bd6 100644 (file)
@@ -229,7 +229,7 @@ struct OperationState {
   SmallVector<NamedAttribute, 4> attributes;
   /// Successors of this operation and their respective operands.
   SmallVector<Block *, 1> successors;
-  unsigned numBlockLists = 0;
+  unsigned numRegions = 0;
   /// If the operation has a resizable operand list.
   bool resizableOperandList = false;
 
@@ -243,14 +243,14 @@ public:
   OperationState(MLIRContext *context, Location location, StringRef name,
                  ArrayRef<Value *> operands, ArrayRef<Type> types,
                  ArrayRef<NamedAttribute> attributes,
-                 ArrayRef<Block *> successors = {}, unsigned numBlockLists = 0,
+                 ArrayRef<Block *> successors = {}, unsigned numRegions = 0,
                  bool resizableOperandList = false)
       : context(context), location(location), name(name, context),
         operands(operands.begin(), operands.end()),
         types(types.begin(), types.end()),
         attributes(attributes.begin(), attributes.end()),
         successors(successors.begin(), successors.end()),
-        numBlockLists(numBlockLists) {}
+        numRegions(numRegions) {}
 
   void addOperands(ArrayRef<Value *> newOperands) {
     assert(successors.empty() &&
@@ -279,8 +279,8 @@ public:
     operands.append(succOperands.begin(), succOperands.end());
   }
 
-  /// Add a new block list with the specified blocks.
-  void reserveBlockLists(unsigned numReserved) { numBlockLists += numReserved; }
+  /// Reserve space for new regions.
+  void reserveRegions(unsigned numReserved) { numRegions += numReserved; }
 
   /// Sets the operand list of the operation as resizable.
   void setOperandListToResizable(bool isResizable = true) {
index a9de42e..16fddb4 100644 (file)
@@ -553,8 +553,8 @@ void AffineForOp::build(Builder *builder, OperationState *result,
                        builder->getAffineMapAttr(ubMap));
   result->addOperands(ubOperands);
 
-  // Reserve a block list for the body.
-  result->reserveBlockLists(/*numReserved=*/1);
+  // Reserve a region for the body.
+  result->reserveRegions(/*numReserved=*/1);
 
   // Set the operands list as resizable so that we can freely modify the bounds.
   result->setOperandListToResizable();
@@ -568,12 +568,11 @@ void AffineForOp::build(Builder *builder, OperationState *result, int64_t lb,
 }
 
 bool AffineForOp::verify() const {
-  const auto &bodyBlockList = getInstruction()->getBlockList(0);
+  const auto &bodyRegion = getInstruction()->getRegion(0);
 
-  // The body block list must contain a single basic block.
-  if (bodyBlockList.empty() ||
-      std::next(bodyBlockList.begin()) != bodyBlockList.end())
-    return emitOpError("expected body block list to have a single block");
+  // The body region must contain a single basic block.
+  if (bodyRegion.empty() || std::next(bodyRegion.begin()) != bodyRegion.end())
+    return emitOpError("expected body region to have a single block");
 
   // Check that the body defines as single block argument for the induction
   // variable.
@@ -701,7 +700,7 @@ static bool parseBound(bool isLower, OperationState *result, OpAsmParser *p) {
 bool AffineForOp::parse(OpAsmParser *parser, OperationState *result) {
   auto &builder = parser->getBuilder();
   // Parse the induction variable followed by '='.
-  if (parser->parseBlockListEntryBlockArgument(builder.getIndexType()) ||
+  if (parser->parseRegionEntryBlockArgument(builder.getIndexType()) ||
       parser->parseEqual())
     return true;
 
@@ -730,9 +729,9 @@ bool AffineForOp::parse(OpAsmParser *parser, OperationState *result) {
           "expected step to be representable as a positive signed integer");
   }
 
-  // Parse the body block list.
-  result->reserveBlockLists(/*numReserved=*/1);
-  if (parser->parseBlockList())
+  // Parse the body region.
+  result->reserveRegions(/*numReserved=*/1);
+  if (parser->parseRegion())
     return true;
 
   // Parse the optional attribute list.
@@ -793,8 +792,8 @@ void AffineForOp::print(OpAsmPrinter *p) const {
 
   if (getStep() != 1)
     *p << " step " << getStep();
-  p->printBlockList(getInstruction()->getBlockList(0),
-                    /*printEntryBlockArgs=*/false);
+  p->printRegion(getInstruction()->getRegion(0),
+                 /*printEntryBlockArgs=*/false);
   p->printOptionalAttrDict(getAttrs(),
                            /*elidedAttrs=*/{getLowerBoundAttrName(),
                                             getUpperBoundAttrName(),
@@ -872,14 +871,14 @@ void AffineForOp::getCanonicalizationPatterns(OwningRewritePatternList &results,
 }
 
 Block *AffineForOp::createBody() {
-  auto &bodyBlockList = getBlockList();
-  assert(bodyBlockList.empty() && "expected no existing body blocks");
+  auto &bodyRegion = getRegion();
+  assert(bodyRegion.empty() && "expected no existing body blocks");
 
   // Create a new block for the body, and add an argument for the induction
   // variable.
   Block *body = new Block();
   body->addArgument(IndexType::get(getInstruction()->getContext()));
-  bodyBlockList.push_back(body);
+  bodyRegion.push_back(body);
   return body;
 }
 
@@ -1040,8 +1039,8 @@ void AffineIfOp::build(Builder *builder, OperationState *result,
   result->addAttribute(getConditionAttrName(), IntegerSetAttr::get(condition));
   result->addOperands(conditionOperands);
 
-  // Reserve 2 block lists, one for the 'then' and one for the 'else' regions.
-  result->reserveBlockLists(2);
+  // Reserve 2 regions, one for the 'then' and one for the 'else' regions.
+  result->reserveRegions(2);
 }
 
 bool AffineIfOp::verify() const {
@@ -1061,20 +1060,19 @@ bool AffineIfOp::verify() const {
                                     condition.getNumDims()))
     return true;
 
-  // Verify that the entry of each child blocklist does not have arguments.
-  for (const auto &blockList : getInstruction()->getBlockLists()) {
-    if (blockList.empty())
+  // Verify that the entry of each child region does not have arguments.
+  for (const auto &region : getInstruction()->getRegions()) {
+    if (region.empty())
       continue;
 
     // TODO(riverriddle) We currently do not allow multiple blocks in child
-    // block lists.
-    if (std::next(blockList.begin()) != blockList.end())
-      return emitOpError(
-          "expects only one block per 'then' or 'else' block list");
-    if (blockList.front().back().isKnownTerminator())
+    // regions.
+    if (std::next(region.begin()) != region.end())
+      return emitOpError("expects only one block per 'then' or 'else' regions");
+    if (region.front().back().isKnownTerminator())
       return emitOpError("expects region block to not have a terminator");
 
-    for (const auto &b : blockList)
+    for (const auto &b : region)
       if (b.getNumArguments() != 0)
         return emitOpError(
             "requires that child entry blocks have no arguments");
@@ -1102,13 +1100,13 @@ bool AffineIfOp::parse(OpAsmParser *parser, OperationState *result) {
         parser->getNameLoc(),
         "symbol operand count and integer set symbol count must match");
 
-  // Parse the 'then' block list.
-  if (parser->parseBlockList())
+  // Parse the 'then' region.
+  if (parser->parseRegion())
     return true;
 
-  // If we find an 'else' keyword then parse the else block list.
+  // If we find an 'else' keyword then parse the 'else' region.
   if (!parser->parseOptionalKeyword("else")) {
-    if (parser->parseBlockList())
+    if (parser->parseRegion())
       return true;
   }
 
@@ -1116,8 +1114,8 @@ bool AffineIfOp::parse(OpAsmParser *parser, OperationState *result) {
   if (parser->parseOptionalAttributeDict(result->attributes))
     return true;
 
-  // Reserve 2 block lists, one for the 'then' and one for the 'else' regions.
-  result->reserveBlockLists(2);
+  // Reserve 2 regions, one for the 'then' and one for the 'else' regions.
+  result->reserveRegions(2);
   return false;
 }
 
@@ -1126,13 +1124,13 @@ void AffineIfOp::print(OpAsmPrinter *p) const {
   *p << "if " << conditionAttr;
   printDimAndSymbolList(operand_begin(), operand_end(),
                         conditionAttr.getValue().getNumDims(), p);
-  p->printBlockList(getInstruction()->getBlockList(0));
+  p->printRegion(getInstruction()->getRegion(0));
 
-  // Print the 'else' block list if it has any blocks.
-  const auto &elseBlockList = getInstruction()->getBlockList(1);
-  if (!elseBlockList.empty()) {
+  // Print the 'else' regions if it has any blocks.
+  const auto &elseRegion = getInstruction()->getRegion(1);
+  if (!elseRegion.empty()) {
     *p << " else";
-    p->printBlockList(elseBlockList);
+    p->printRegion(elseRegion);
   }
 
   // Print the attribute list.
@@ -1148,11 +1146,7 @@ void AffineIfOp::setIntegerSet(IntegerSet newSet) {
 }
 
 /// Returns the list of 'then' blocks.
-BlockList &AffineIfOp::getThenBlocks() {
-  return getInstruction()->getBlockList(0);
-}
+Region &AffineIfOp::getThenBlocks() { return getInstruction()->getRegion(0); }
 
 /// Returns the list of 'else' blocks.
-BlockList &AffineIfOp::getElseBlocks() {
-  return getInstruction()->getBlockList(1);
-}
+Region &AffineIfOp::getElseBlocks() { return getInstruction()->getRegion(1); }
index b3c9d82..a6f6845 100644 (file)
@@ -41,19 +41,19 @@ void DominanceInfoBase<IsPostDom>::recalculate(Function *function) {
 
   // Build the top level function dominance.
   auto functionDominance = std::make_unique<base>();
-  functionDominance->recalculate(function->getBlockList());
-  dominanceInfos.try_emplace(&function->getBlockList(),
+  functionDominance->recalculate(function->getBody());
+  dominanceInfos.try_emplace(&function->getBody(),
                              std::move(functionDominance));
 
-  /// Build the dominance for each of the internal region block lists.
+  /// Build the dominance for each of the operation regions.
   function->walk([&](Instruction *inst) {
-    for (auto &blockList : inst->getBlockLists()) {
+    for (auto &region : inst->getRegions()) {
       // Don't compute dominance if the region is empty.
-      if (blockList.empty())
+      if (region.empty())
         continue;
       auto opDominance = std::make_unique<base>();
-      opDominance->recalculate(blockList);
-      dominanceInfos.try_emplace(&blockList, std::move(opDominance));
+      opDominance->recalculate(region);
+      dominanceInfos.try_emplace(&region, std::move(opDominance));
     }
   });
 }
@@ -66,21 +66,21 @@ bool DominanceInfoBase<IsPostDom>::properlyDominates(const Block *a,
   if (a == b)
     return false;
 
-  // If both blocks are not in the same block list, 'a' properly dominates 'b'
-  // if 'b' is defined in an instruction region that (recursively) ends up being
+  // If both blocks are not in the same region, 'a' properly dominates 'b' if
+  // 'b' is defined in an instruction region that (recursively) ends up being
   // dominated by 'a'. Walk up the list of containers enclosing B.
-  auto *blockListA = a->getParent(), *blockListB = b->getParent();
-  if (blockListA != blockListB) {
+  auto *regionA = a->getParent(), *regionB = b->getParent();
+  if (regionA != regionB) {
     Instruction *bAncestor;
     do {
-      bAncestor = blockListB->getContainingInst();
+      bAncestor = regionB->getContainingInst();
       // If 'bAncestor' is the top level function, then 'a' is a block
       // that post dominates 'b'.
       if (!bAncestor)
         return IsPostDom;
 
-      blockListB = bAncestor->getBlock()->getParent();
-    } while (blockListA != blockListB);
+      regionB = bAncestor->getBlock()->getParent();
+    } while (regionA != regionB);
 
     // Check to see if the ancestor of 'b' is the same block as 'a'.
     b = bAncestor->getBlock();
@@ -89,8 +89,8 @@ bool DominanceInfoBase<IsPostDom>::properlyDominates(const Block *a,
   }
 
   // Otherwise, use the standard dominance functionality.
-  auto baseInfoIt = dominanceInfos.find(blockListA);
-  assert(baseInfoIt != dominanceInfos.end() && "block list info not found");
+  auto baseInfoIt = dominanceInfos.find(regionA);
+  assert(baseInfoIt != dominanceInfos.end() && "region info not found");
   return baseInfoIt->second->properlyDominates(a, b);
 }
 
index 727ce18..0df51eb 100644 (file)
@@ -303,7 +303,7 @@ static bool isVectorizableLoopWithCond(ConstOpPointer<AffineForOp> loop,
 
   // No vectorization across unknown regions.
   auto regions = matcher::Op([](const Instruction &inst) -> bool {
-    return inst.getNumBlockLists() != 0 &&
+    return inst.getNumRegions() != 0 &&
            !(inst.isa<AffineIfOp>() || inst.isa<AffineForOp>());
   });
   SmallVector<NestedMatch, 8> regionsMatched;
index e330a01..3399c7d 100644 (file)
@@ -462,8 +462,8 @@ static Instruction *getInstAtPosition(ArrayRef<unsigned> positions,
       return getInstAtPosition(positions, level + 1,
                                childAffineForOp->getBody());
 
-    for (auto &blockList : inst.getBlockLists()) {
-      for (auto &b : blockList)
+    for (auto &region : inst.getRegions()) {
+      for (auto &b : region)
         if (auto *ret = getInstAtPosition(positions, level + 1, &b))
           return ret;
     }
index 0f9365a..cab6758 100644 (file)
@@ -306,8 +306,8 @@ bool FuncVerifier::verifyOperation(const Instruction &op) {
   }
 
   // Verify that all child blocks are ok.
-  for (auto &blockList : op.getBlockLists())
-    for (auto &b : blockList)
+  for (auto &region : op.getRegions())
+    for (auto &b : region)
       if (verifyBlock(b, /*isTopLevel=*/false))
         return true;
 
@@ -338,8 +338,8 @@ bool FuncVerifier::verifyInstDominance(const Instruction &inst) {
   }
 
   // Verify the dominance of each of the nested blocks within this instruction.
-  for (auto &blockList : inst.getBlockLists())
-    for (auto &block : blockList)
+  for (auto &region : inst.getRegions())
+    for (auto &block : region)
       if (verifyDominance(block))
         return true;
 
index b88de85..4454f69 100644 (file)
@@ -1103,9 +1103,8 @@ public:
   void printSuccessorAndUseList(const Instruction *term,
                                 unsigned index) override;
 
-  /// Print a block list.
-  void printBlockList(const BlockList &blocks,
-                      bool printEntryBlockArgs) override {
+  /// Print a region.
+  void printRegion(const Region &blocks, bool printEntryBlockArgs) override {
     os << " {\n";
     if (!blocks.empty()) {
       auto *entryBlock = &blocks.front();
@@ -1164,7 +1163,9 @@ FunctionPrinter::FunctionPrinter(const Function *function,
     numberValuesInBlock(block);
 }
 
-/// Number all of the SSA values in the specified block list.
+/// Number all of the SSA values in the specified block.  Values get numbered
+/// continuously throughout regions.  In particular, we traverse the regions
+/// held by operations and number values in depth-first pre-order.
 void FunctionPrinter::numberValuesInBlock(const Block &block) {
   // Each block gets a unique ID, and all of the instructions within it get
   // numbered as well.
@@ -1178,8 +1179,8 @@ void FunctionPrinter::numberValuesInBlock(const Block &block) {
     // result.
     if (inst.getNumResults() != 0)
       numberValueID(inst.getResult(0));
-    for (auto &blockList : inst.getBlockLists())
-      for (const auto &block : blockList)
+    for (auto &region : inst.getRegions())
+      for (const auto &block : region)
         numberValuesInBlock(block);
   }
 }
@@ -1219,9 +1220,9 @@ void FunctionPrinter::numberValueID(const Value *value) {
       // argument is to an entry block of an operation region, give it an 'i'
       // name.
       if (auto *block = cast<BlockArgument>(value)->getOwner()) {
-        auto *parentBlockList = block->getParent();
-        if (parentBlockList && block == &parentBlockList->front()) {
-          if (parentBlockList->getContainingFunction())
+        auto *parentRegion = block->getParent();
+        if (parentRegion && block == &parentRegion->front()) {
+          if (parentRegion->getContainingFunction())
             specialName << "arg" << nextArgumentID++;
           else
             specialName << "i" << nextRegionArgumentID++;
@@ -1279,7 +1280,7 @@ void FunctionPrinter::print() {
   printTrailingLocation(function->getLoc());
 
   if (!function->empty()) {
-    printBlockList(function->getBlockList(), /*printEntryBlockArgs=*/false);
+    printRegion(function->getBody(), /*printEntryBlockArgs=*/false);
     os << "\n";
   }
   os << '\n';
@@ -1496,9 +1497,9 @@ void FunctionPrinter::printGenericOp(const Instruction *op) {
     os << ')';
   }
 
-  // Print any trailing block lists.
-  for (auto &blockList : op->getBlockLists())
-    printBlockList(blockList, /*printEntryBlockArgs=*/true);
+  // Print any trailing regions.
+  for (auto &region : op->getRegions())
+    printRegion(region, /*printEntryBlockArgs=*/true);
 }
 
 void FunctionPrinter::printSuccessorAndUseList(const Instruction *term,
index 60c382f..eddf124 100644 (file)
@@ -1,4 +1,4 @@
-//===- Block.cpp - MLIR Block and BlockList Classes -----------------------===//
+//===- Block.cpp - MLIR Block and Region Classes --------------------------===//
 //
 // Copyright 2019 The MLIR Authors.
 //
@@ -66,7 +66,7 @@ Function *Block::getFunction() {
 void Block::insertBefore(Block *block) {
   assert(!getParent() && "already inserted into a block!");
   assert(block->getParent() && "cannot insert before a block without a parent");
-  block->getParent()->getBlocks().insert(BlockList::iterator(block), this);
+  block->getParent()->getBlocks().insert(Region::iterator(block), this);
 }
 
 /// Unlink this Block from its Function and delete it.
@@ -262,26 +262,26 @@ Block *Block::splitBlock(iterator splitBefore) {
 }
 
 //===----------------------------------------------------------------------===//
-// BlockList
+// Region
 //===----------------------------------------------------------------------===//
 
-BlockList::BlockList(Function *container) : container(container) {}
+Region::Region(Function *container) : container(container) {}
 
-BlockList::BlockList(Instruction *container) : container(container) {}
+Region::Region(Instruction *container) : container(container) {}
 
-Instruction *BlockList::getContainingInst() {
+Instruction *Region::getContainingInst() {
   return container.dyn_cast<Instruction *>();
 }
 
-Function *BlockList::getContainingFunction() {
+Function *Region::getContainingFunction() {
   return container.dyn_cast<Function *>();
 }
 
-/// Clone the internal blocks from this block list into dest. Any
+/// Clone the internal blocks from this region into `dest`. Any
 /// cloned blocks are appended to the back of dest.
-void BlockList::cloneInto(BlockList *dest, BlockAndValueMapping &mapper,
-                          MLIRContext *context) const {
-  assert(dest && "expected valid block list to clone into");
+void Region::cloneInto(Region *dest, BlockAndValueMapping &mapper,
+                       MLIRContext *context) const {
+  assert(dest && "expected valid region to clone into");
 
   // If the list is empty there is nothing to clone.
   if (empty())
@@ -321,25 +321,24 @@ void BlockList::cloneInto(BlockList *dest, BlockAndValueMapping &mapper,
     it->walk(remapOperands);
 }
 
-BlockList *llvm::ilist_traits<::mlir::Block>::getContainingBlockList() {
+Region *llvm::ilist_traits<::mlir::Block>::getContainingRegion() {
   size_t Offset(
-      size_t(&((BlockList *)nullptr->*BlockList::getSublistAccess(nullptr))));
+      size_t(&((Region *)nullptr->*Region::getSublistAccess(nullptr))));
   iplist<Block> *Anchor(static_cast<iplist<Block> *>(this));
-  return reinterpret_cast<BlockList *>(reinterpret_cast<char *>(Anchor) -
-                                       Offset);
+  return reinterpret_cast<Region *>(reinterpret_cast<char *>(Anchor) - Offset);
 }
 
-/// This is a trait method invoked when a basic block is added to a function.
-/// We keep the function pointer up to date.
+/// This is a trait method invoked when a basic block is added to a region.
+/// We keep the region pointer up to date.
 void llvm::ilist_traits<::mlir::Block>::addNodeToList(Block *block) {
-  assert(!block->getParent() && "already in a function!");
-  block->parentValidInstOrderPair.setPointer(getContainingBlockList());
+  assert(!block->getParent() && "already in a region!");
+  block->parentValidInstOrderPair.setPointer(getContainingRegion());
 }
 
 /// This is a trait method invoked when an instruction is removed from a
-/// function.  We keep the function pointer up to date.
+/// region.  We keep the region pointer up to date.
 void llvm::ilist_traits<::mlir::Block>::removeNodeFromList(Block *block) {
-  assert(block->getParent() && "not already in a function!");
+  assert(block->getParent() && "not already in a region!");
   block->parentValidInstOrderPair.setPointer(nullptr);
 }
 
@@ -349,8 +348,8 @@ void llvm::ilist_traits<::mlir::Block>::transferNodesFromList(
     ilist_traits<Block> &otherList, block_iterator first, block_iterator last) {
   // If we are transferring instructions within the same function, the parent
   // pointer doesn't need to be updated.
-  auto *curParent = getContainingBlockList();
-  if (curParent == otherList.getContainingBlockList())
+  auto *curParent = getContainingRegion();
+  if (curParent == otherList.getContainingRegion())
     return;
 
   // Update the 'parent' member of each Block.
index 1100a2b..56d0ad0 100644 (file)
@@ -311,10 +311,9 @@ Block *FuncBuilder::createBlock(Block *insertBefore) {
 /// Create an operation given the fields represented as an OperationState.
 Instruction *FuncBuilder::createOperation(const OperationState &state) {
   assert(block && "createOperation() called without setting builder's block");
-  auto *op = Instruction::create(state.location, state.name, state.operands,
-                                 state.types, state.attributes,
-                                 state.successors, state.numBlockLists,
-                                 state.resizableOperandList, context);
+  auto *op = Instruction::create(
+      state.location, state.name, state.operands, state.types, state.attributes,
+      state.successors, state.numRegions, state.resizableOperandList, context);
   block->getInstructions().insert(insertPoint, op);
   return op;
 }
index 8ad8139..107f1b5 100644 (file)
@@ -30,14 +30,14 @@ Function::Function(Location location, StringRef name, FunctionType type,
                    ArrayRef<NamedAttribute> attrs)
     : name(Identifier::get(name, type.getContext())), location(location),
       type(type), attrs(type.getContext(), attrs),
-      argAttrs(type.getNumInputs()), blocks(this) {}
+      argAttrs(type.getNumInputs()), body(this) {}
 
 Function::Function(Location location, StringRef name, FunctionType type,
                    ArrayRef<NamedAttribute> attrs,
                    ArrayRef<NamedAttributeList> argAttrs)
     : name(Identifier::get(name, type.getContext())), location(location),
       type(type), attrs(type.getContext(), attrs), argAttrs(argAttrs),
-      blocks(this) {}
+      body(this) {}
 
 Function::~Function() {
   // Instructions may have cyclic references, which need to be dropped before we
@@ -160,8 +160,8 @@ void Function::cloneInto(Function *dest, BlockAndValueMapping &mapper) const {
   }
   dest->setAttrs(newAttrs.takeVector());
 
-  // Clone the block list.
-  blocks.cloneInto(&dest->blocks, mapper, dest->getContext());
+  // Clone the body.
+  body.cloneInto(&dest->body, mapper, dest->getContext());
 }
 
 /// Create a deep copy of this function and all of its blocks, remapping
index 36a0449..b38ea6a 100644 (file)
@@ -134,12 +134,13 @@ void detail::OperandStorage::grow(ResizableStorage &resizeUtil,
 //===----------------------------------------------------------------------===//
 
 /// Create a new Instruction with the specific fields.
-Instruction *
-Instruction::create(Location location, OperationName name,
-                    ArrayRef<Value *> operands, ArrayRef<Type> resultTypes,
-                    ArrayRef<NamedAttribute> attributes,
-                    ArrayRef<Block *> successors, unsigned numBlockLists,
-                    bool resizableOperandList, MLIRContext *context) {
+Instruction *Instruction::create(Location location, OperationName name,
+                                 ArrayRef<Value *> operands,
+                                 ArrayRef<Type> resultTypes,
+                                 ArrayRef<NamedAttribute> attributes,
+                                 ArrayRef<Block *> successors,
+                                 unsigned numRegions, bool resizableOperandList,
+                                 MLIRContext *context) {
   unsigned numSuccessors = successors.size();
 
   // Input operands are nullptr-separated for each successor, the null operands
@@ -147,9 +148,9 @@ Instruction::create(Location location, OperationName name,
   unsigned numOperands = operands.size() - numSuccessors;
 
   // Compute the byte size for the instruction and the operand storage.
-  auto byteSize = totalSizeToAlloc<InstResult, BlockOperand, unsigned,
-                                   BlockList, detail::OperandStorage>(
-      resultTypes.size(), numSuccessors, numSuccessors, numBlockLists,
+  auto byteSize = totalSizeToAlloc<InstResult, BlockOperand, unsigned, Region,
+                                   detail::OperandStorage>(
+      resultTypes.size(), numSuccessors, numSuccessors, numRegions,
       /*detail::OperandStorage*/ 1);
   byteSize += llvm::alignTo(detail::OperandStorage::additionalAllocSize(
                                 numOperands, resizableOperandList),
@@ -158,15 +159,15 @@ Instruction::create(Location location, OperationName name,
 
   // Create the new Instruction.
   auto inst = ::new (rawMem)
-      Instruction(location, name, resultTypes.size(), numSuccessors,
-                  numBlockLists, attributes, context);
+      Instruction(location, name, resultTypes.size(), numSuccessors, numRegions,
+                  attributes, context);
 
   assert((numSuccessors == 0 || !inst->isKnownNonTerminator()) &&
          "unexpected successors in a non-terminator operation");
 
-  // Initialize the block lists.
-  for (unsigned i = 0; i != numBlockLists; ++i)
-    new (&inst->getBlockList(i)) BlockList(inst);
+  // Initialize the regions.
+  for (unsigned i = 0; i != numRegions; ++i)
+    new (&inst->getRegion(i)) Region(inst);
 
   // Initialize the results and operands.
   new (&inst->getOperandStorage())
@@ -238,11 +239,11 @@ Instruction::create(Location location, OperationName name,
 
 Instruction::Instruction(Location location, OperationName name,
                          unsigned numResults, unsigned numSuccessors,
-                         unsigned numBlockLists,
+                         unsigned numRegions,
                          ArrayRef<NamedAttribute> attributes,
                          MLIRContext *context)
     : location(location), numResults(numResults), numSuccs(numSuccessors),
-      numBlockLists(numBlockLists), name(name), attrs(context, attributes) {}
+      numRegions(numRegions), name(name), attrs(context, attributes) {}
 
 // Instructions are deleted through the destroy() member because they are
 // allocated via malloc.
@@ -259,9 +260,9 @@ Instruction::~Instruction() {
   for (auto &successor : getBlockOperands())
     successor.~BlockOperand();
 
-  // Explicitly destroy the block list.
-  for (auto &blockList : getBlockLists())
-    blockList.~BlockList();
+  // Explicitly destroy the regions.
+  for (auto &region : getRegions())
+    region.~Region();
 }
 
 /// Destroy this instruction or one of its subclasses.
@@ -301,16 +302,16 @@ void Instruction::walk(const std::function<void(Instruction *)> &callback) {
   callback(this);
 
   // Visit any internal instructions.
-  for (auto &blockList : getBlockLists())
-    for (auto &block : blockList)
+  for (auto &region : getRegions())
+    for (auto &block : region)
       block.walk(callback);
 }
 
 void Instruction::walkPostOrder(
     const std::function<void(Instruction *)> &callback) {
   // Visit any internal instructions.
-  for (auto &blockList : llvm::reverse(getBlockLists()))
-    for (auto &block : llvm::reverse(blockList))
+  for (auto &region : llvm::reverse(getRegions()))
+    for (auto &block : llvm::reverse(region))
       block.walkPostOrder(callback);
 
   // Visit the current instruction.
@@ -465,8 +466,8 @@ void Instruction::dropAllReferences() {
   for (auto &op : getInstOperands())
     op.drop();
 
-  for (auto &blockList : getBlockLists())
-    for (Block &block : blockList)
+  for (auto &region : getRegions())
+    for (Block &block : region)
       block.dropAllReferences();
 
   for (auto &dest : getBlockOperands())
@@ -603,14 +604,14 @@ Instruction *Instruction::clone(BlockAndValueMapping &mapper,
   for (auto *result : getResults())
     resultTypes.push_back(result->getType());
 
-  unsigned numBlockLists = getNumBlockLists();
+  unsigned numRegions = getNumRegions();
   auto *newOp = Instruction::create(getLoc(), getName(), operands, resultTypes,
-                                    getAttrs(), successors, numBlockLists,
+                                    getAttrs(), successors, numRegions,
                                     hasResizableOperandsList(), context);
 
-  // Clone the block lists.
-  for (unsigned i = 0; i != numBlockLists; ++i)
-    getBlockList(i).cloneInto(&newOp->getBlockList(i), mapper, context);
+  // Clone the regions.
+  for (unsigned i = 0; i != numRegions; ++i)
+    getRegion(i).cloneInto(&newOp->getRegion(i), mapper, context);
 
   // Remember the mapping of any results.
   for (unsigned i = 0, e = getNumResults(); i != e; ++i)
index 7d977ae..7b5050b 100644 (file)
@@ -2196,9 +2196,9 @@ public:
   // Block references.
 
   ParseResult
-  parseOperationBlockList(SmallVectorImpl<Block *> &results,
-                          ArrayRef<std::pair<SSAUseInfo, Type>> entryArguments);
-  ParseResult parseBlockListBody(SmallVectorImpl<Block *> &results);
+  parseOperationRegion(SmallVectorImpl<Block *> &results,
+                       ArrayRef<std::pair<SSAUseInfo, Type>> entryArguments);
+  ParseResult parseRegionBody(SmallVectorImpl<Block *> &results);
   ParseResult parseBlock(Block *&block);
   ParseResult parseBlockBody(Block *block);
 
@@ -2279,7 +2279,7 @@ ParseResult FunctionParser::parseFunctionBody(bool hadNamedArguments) {
 
   // Parse the remaining list of blocks.
   SmallVector<Block *, 16> blocks;
-  if (parseBlockListBody(blocks))
+  if (parseRegionBody(blocks))
     return ParseFailure;
   function->getBlocks().insert(function->end(), blocks.begin(), blocks.end());
 
@@ -2307,14 +2307,14 @@ ParseResult FunctionParser::parseFunctionBody(bool hadNamedArguments) {
 ///
 ///   block-list ::= '{' block-list-body
 ///
-ParseResult FunctionParser::parseOperationBlockList(
+ParseResult FunctionParser::parseOperationRegion(
     SmallVectorImpl<Block *> &results,
     ArrayRef<std::pair<FunctionParser::SSAUseInfo, Type>> entryArguments) {
   // Parse the '{'.
-  if (parseToken(Token::l_brace, "expected '{' to begin block list"))
+  if (parseToken(Token::l_brace, "expected '{' to begin a region"))
     return ParseFailure;
 
-  // Check for an empty block list.
+  // Check for an empty region.
   if (entryArguments.empty() && consumeIf(Token::r_brace))
     return ParseSuccess;
   Block *currentBlock = builder.getInsertionBlock();
@@ -2342,9 +2342,9 @@ ParseResult FunctionParser::parseOperationBlockList(
     return emitError("entry block arguments were already defined");
   }
 
-  // Parse the rest of the block list.
+  // Parse the rest of the region.
   results.push_back(block);
-  if (parseBlockListBody(results))
+  if (parseRegionBody(results))
     return ParseFailure;
 
   // Reset insertion point to the current block.
@@ -2352,13 +2352,12 @@ ParseResult FunctionParser::parseOperationBlockList(
   return ParseSuccess;
 }
 
-/// Block list.
+/// Region.
 ///
-///   block-list-body ::= block* '}'
+///   region-body ::= block* '}'
 ///
-ParseResult
-FunctionParser::parseBlockListBody(SmallVectorImpl<Block *> &results) {
-  // Parse the block list.
+ParseResult FunctionParser::parseRegionBody(SmallVectorImpl<Block *> &results) {
+  // Parse the list of blocks.
   while (!consumeIf(Token::r_brace)) {
     Block *newBlock = nullptr;
     if (parseBlock(newBlock)) {
@@ -2440,7 +2439,7 @@ Value *FunctionParser::createForwardReferencePlaceholder(SMLoc loc, Type type) {
   auto name = OperationName("placeholder", getContext());
   auto *inst = Instruction::create(
       getEncodedSourceLocation(loc), name, /*operands=*/{}, type,
-      /*attributes=*/{}, /*successors=*/{}, /*numBlockLists=*/0,
+      /*attributes=*/{}, /*successors=*/{}, /*numRegions=*/0,
       /*resizableOperandList=*/false, getContext());
   forwardReferencePlaceholders[inst->getResult(0)] = loc;
   return inst->getResult(0);
@@ -2888,25 +2887,25 @@ Instruction *FunctionParser::parseGenericOperation() {
     result.addSuccessor(successor, operands);
   }
 
-  // Parse the optional block lists for this operation.
+  // Parse the optional regions for this operation.
   std::vector<SmallVector<Block *, 2>> blocks;
   while (getToken().is(Token::l_brace)) {
     SmallVector<Block *, 2> newBlocks;
-    if (parseOperationBlockList(newBlocks, /*entryArguments=*/llvm::None)) {
-      for (auto &blockList : blocks)
-        cleanupInvalidBlocks(blockList);
+    if (parseOperationRegion(newBlocks, /*entryArguments=*/llvm::None)) {
+      for (auto &region : blocks)
+        cleanupInvalidBlocks(region);
       return nullptr;
     }
     blocks.emplace_back(newBlocks);
   }
-  result.reserveBlockLists(blocks.size());
+  result.reserveRegions(blocks.size());
 
   auto *opInst = builder.createOperation(result);
 
-  // Initialize the parsed block lists.
+  // Initialize the parsed regions.
   for (unsigned i = 0, e = blocks.size(); i != e; ++i) {
-    auto &blockList = opInst->getBlockList(i).getBlocks();
-    blockList.insert(blockList.end(), blocks[i].begin(), blocks[i].end());
+    auto &region = opInst->getRegion(i).getBlocks();
+    region.insert(region.end(), blocks[i].begin(), blocks[i].end());
   }
   return opInst;
 }
@@ -2922,23 +2921,22 @@ public:
     if (opDefinition->parseAssembly(this, opState))
       return true;
 
-    // Check that enough block lists were reserved for those that were parsed.
-    if (parsedBlockLists.size() > opState->numBlockLists) {
+    // Check that enough regions were reserved for those that were parsed.
+    if (parsedRegions.size() > opState->numRegions) {
       return emitError(
           nameLoc,
-          "parsed more block lists than those reserved in the operation state");
+          "parsed more regions than those reserved in the operation state");
     }
 
     // Check there were no dangling entry block arguments.
-    if (!parsedBlockListEntryArguments.empty()) {
+    if (!parsedRegionEntryArguments.empty()) {
       return emitError(
-          nameLoc,
-          "no block list was attached to parsed entry block arguments");
+          nameLoc, "no region was attached to parsed entry block arguments");
     }
 
     // Check that none of the operands of the current operation reference an
-    // entry block argument for any of the block lists.
-    for (auto *entryArg : parsedBlockListEntryArgumentPlaceholders)
+    // entry block argument for any of the region.
+    for (auto *entryArg : parsedRegionEntryArgumentPlaceholders)
       if (llvm::is_contained(opState->operands, entryArg))
         return emitError(nameLoc, "operand use before it's defined");
 
@@ -3144,21 +3142,19 @@ public:
     return result == nullptr;
   }
 
-  /// Parses a list of blocks.
-  bool parseBlockList() override {
-    // Parse the block list.
+  /// Parses a region.
+  bool parseRegion() override {
     SmallVector<Block *, 2> results;
-    if (parser.parseOperationBlockList(results, parsedBlockListEntryArguments))
+    if (parser.parseOperationRegion(results, parsedRegionEntryArguments))
       return true;
 
-    parsedBlockListEntryArguments.clear();
-    parsedBlockLists.emplace_back(results);
+    parsedRegionEntryArguments.clear();
+    parsedRegions.emplace_back(results);
     return false;
   }
 
-  /// Parses an argument for the entry block of the next block list to be
-  /// parsed.
-  bool parseBlockListEntryBlockArgument(Type argType) override {
+  /// Parses an argument for the entry block of the next region to be parsed.
+  bool parseRegionEntryBlockArgument(Type argType) override {
     SmallVector<Value *, 1> argValues;
     OperandType operand;
     if (parseOperand(operand))
@@ -3168,10 +3164,10 @@ public:
     FunctionParser::SSAUseInfo operandInfo = {operand.name, operand.number,
                                               operand.location};
     if (auto *value = parser.resolveSSAUse(operandInfo, argType)) {
-      parsedBlockListEntryArguments.emplace_back(operandInfo, argType);
+      parsedRegionEntryArguments.emplace_back(operandInfo, argType);
       // Track each of the placeholders so that we can detect invalid references
-      // to block list arguments.
-      parsedBlockListEntryArgumentPlaceholders.emplace_back(value);
+      // to region arguments.
+      parsedRegionEntryArgumentPlaceholders.emplace_back(value);
       return false;
     }
 
@@ -3199,10 +3195,10 @@ public:
 
   /// Emit a diagnostic at the specified location and return true.
   bool emitError(llvm::SMLoc loc, const Twine &message) override {
-    // If we emit an error, then cleanup any parsed block lists.
-    for (auto &blockList : parsedBlockLists)
-      parser.cleanupInvalidBlocks(blockList);
-    parsedBlockLists.clear();
+    // If we emit an error, then cleanup any parsed regions.
+    for (auto &region : parsedRegions)
+      parser.cleanupInvalidBlocks(region);
+    parsedRegions.clear();
 
     parser.emitError(loc, "custom op '" + Twine(opName) + "' " + message);
     emittedError = true;
@@ -3211,16 +3207,16 @@ public:
 
   bool didEmitError() const { return emittedError; }
 
-  /// Returns the block lists that were parsed.
-  MutableArrayRef<SmallVector<Block *, 2>> getParsedBlockLists() {
-    return parsedBlockLists;
+  /// Returns the regions that were parsed.
+  MutableArrayRef<SmallVector<Block *, 2>> getParsedRegions() {
+    return parsedRegions;
   }
 
 private:
-  std::vector<SmallVector<Block *, 2>> parsedBlockLists;
+  std::vector<SmallVector<Block *, 2>> parsedRegions;
   SmallVector<std::pair<FunctionParser::SSAUseInfo, Type>, 2>
-      parsedBlockListEntryArguments;
-  SmallVector<Value *, 2> parsedBlockListEntryArgumentPlaceholders;
+      parsedRegionEntryArguments;
+  SmallVector<Value *, 2> parsedRegionEntryArgumentPlaceholders;
   SMLoc nameLoc;
   StringRef opName;
   FunctionParser &parser;
@@ -3271,12 +3267,12 @@ Instruction *FunctionParser::parseCustomOperation() {
   // Otherwise, we succeeded.  Use the state it parsed as our op information.
   auto *opInst = builder.createOperation(opState);
 
-  // Resolve any parsed block lists.
-  auto parsedBlockLists = opAsmParser.getParsedBlockLists();
-  for (unsigned i = 0, e = parsedBlockLists.size(); i != e; ++i) {
-    auto &opBlockList = opInst->getBlockList(i).getBlocks();
-    opBlockList.insert(opBlockList.end(), parsedBlockLists[i].begin(),
-                       parsedBlockLists[i].end());
+  // Resolve any parsed regions.
+  auto parsedRegions = opAsmParser.getParsedRegions();
+  for (unsigned i = 0, e = parsedRegions.size(); i != e; ++i) {
+    auto &opRegion = opInst->getRegion(i).getBlocks();
+    opRegion.insert(opRegion.end(), parsedRegions[i].begin(),
+                    parsedRegions[i].end());
   }
   return opInst;
 }
index 37dfce1..02fbda0 100644 (file)
@@ -109,7 +109,7 @@ struct CSE : public FunctionPass<CSE> {
   bool simplifyOperation(Instruction *op);
 
   void simplifyBlock(DominanceInfo &domInfo, Block *bb);
-  void simplifyBlockList(DominanceInfo &domInfo, BlockList &blockList);
+  void simplifyRegion(DominanceInfo &domInfo, Region &region);
 
   void runOnFunction() override;
 
@@ -127,7 +127,7 @@ bool CSE::simplifyOperation(Instruction *op) {
   // Don't simplify operations with nested blocks. We don't currently model
   // equality comparisons correctly among other things. It is also unclear
   // whether we would want to CSE such operations.
-  if (op->getNumBlockLists() != 0)
+  if (op->getNumRegions() != 0)
     return false;
 
   // TODO(riverriddle) We currently only eliminate non side-effecting
@@ -166,25 +166,25 @@ bool CSE::simplifyOperation(Instruction *op) {
 
 void CSE::simplifyBlock(DominanceInfo &domInfo, Block *bb) {
   for (auto &i : *bb) {
-    // If the operation is simplified, we don't process any held block lists.
+    // If the operation is simplified, we don't process any held regions.
     if (simplifyOperation(&i))
       continue;
 
     // Simplify any held blocks.
-    for (auto &blockList : i.getBlockLists())
-      simplifyBlockList(domInfo, blockList);
+    for (auto &region : i.getRegions())
+      simplifyRegion(domInfo, region);
   }
 }
 
-void CSE::simplifyBlockList(DominanceInfo &domInfo, BlockList &blockList) {
-  // If the block list is empty there is nothing to do.
-  if (blockList.empty())
+void CSE::simplifyRegion(DominanceInfo &domInfo, Region &region) {
+  // If the region is empty there is nothing to do.
+  if (region.empty())
     return;
 
-  // If the block list only contains one block, then simplify it directly.
-  if (std::next(blockList.begin()) == blockList.end()) {
+  // If the region only contains one block, then simplify it directly.
+  if (std::next(region.begin()) == region.end()) {
     ScopedMapTy::ScopeTy scope(knownValues);
-    simplifyBlock(domInfo, &blockList.front());
+    simplifyBlock(domInfo, &region.front());
     return;
   }
 
@@ -196,9 +196,9 @@ void CSE::simplifyBlockList(DominanceInfo &domInfo, BlockList &blockList) {
   // http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20120116/135228.html
   std::deque<std::unique_ptr<CFGStackNode>> stack;
 
-  // Process the nodes of the dom tree for this blocklist.
+  // Process the nodes of the dom tree for this region.
   stack.emplace_back(std::make_unique<CFGStackNode>(
-      knownValues, domInfo.getRootNode(&blockList)));
+      knownValues, domInfo.getRootNode(&region)));
 
   while (!stack.empty()) {
     auto &currentNode = stack.back();
@@ -223,8 +223,7 @@ void CSE::simplifyBlockList(DominanceInfo &domInfo, BlockList &blockList) {
 }
 
 void CSE::runOnFunction() {
-  simplifyBlockList(getAnalysis<DominanceInfo>(),
-                    getFunction()->getBlockList());
+  simplifyRegion(getAnalysis<DominanceInfo>(), getFunction()->getBody());
 
   // If no operations were erased, then we mark all analyses as preserved.
   if (opsToErase.empty()) {
index a621db4..72a378b 100644 (file)
@@ -172,7 +172,7 @@ impl::FunctionConversion::convertBlock(Block *block, FuncBuilder &builder,
 
   // Iterate over ops and convert them.
   for (Instruction &inst : *block) {
-    if (inst.getNumBlockLists() != 0) {
+    if (inst.getNumRegions() != 0) {
       inst.emitError("unsupported region instruction");
       return failure();
     }
index e05af79..12e52ea 100644 (file)
@@ -130,7 +130,7 @@ struct LoopNestStateCollector {
     instToWalk->walk([&](Instruction *opInst) {
       if (opInst->isa<AffineForOp>())
         forOps.push_back(opInst->cast<AffineForOp>());
-      else if (opInst->getNumBlockLists() != 0)
+      else if (opInst->getNumRegions() != 0)
         hasNonForRegion = true;
       else if (opInst->isa<LoadOp>())
         loadOpInsts.push_back(opInst);
@@ -670,7 +670,7 @@ bool MemRefDependenceGraph::init(Function *f) {
       auto *memref = inst.cast<StoreOp>()->getMemRef();
       memrefAccesses[memref].insert(node.id);
       nodes.insert({node.id, node});
-    } else if (inst.getNumBlockLists() != 0) {
+    } else if (inst.getNumRegions() != 0) {
       // Return false if another region is found (not currently supported).
       return false;
     } else if (inst.getNumResults() > 0 && !inst.use_empty()) {
index 4682923..b1a306d 100644 (file)
@@ -109,8 +109,8 @@ void LoopUnroll::runOnFunction() {
     }
     bool walkPostOrder(Instruction *opInst) {
       bool hasInnerLoops = false;
-      for (auto &blockList : opInst->getBlockLists())
-        for (auto &block : blockList)
+      for (auto &region : opInst->getRegions())
+        for (auto &block : region)
           hasInnerLoops |= walkPostOrder(block.begin(), block.end());
       if (opInst->isa<AffineForOp>()) {
         if (!hasInnerLoops)
index f1cc7c6..2b92b2a 100644 (file)
@@ -132,8 +132,8 @@ LogicalResult mlir::loopUnrollJamByFactor(OpPointer<AffineForOp> forOp,
 
     // This is a linear time walk.
     void walk(Instruction *inst) {
-      for (auto &blockList : inst->getBlockLists())
-        for (auto &block : blockList)
+      for (auto &region : inst->getRegions())
+        for (auto &block : region)
           walk(block);
     }
     void walk(Block &block) {
index 0d54ead..804991a 100644 (file)
@@ -411,7 +411,7 @@ instantiate(FuncBuilder *b, Instruction *opInst, VectorType hwVectorType,
          "Should call the function specialized for VectorTransferReadOp");
   assert(!opInst->isa<VectorTransferWriteOp>() &&
          "Should call the function specialized for VectorTransferWriteOp");
-  if (opInst->getNumBlockLists() != 0)
+  if (opInst->getNumRegions() != 0)
     return nullptr;
 
   bool fail = false;
@@ -553,7 +553,7 @@ static bool instantiateMaterialization(Instruction *inst,
   if (inst->isa<AffineApplyOp>()) {
     return false;
   }
-  if (inst->getNumBlockLists() != 0)
+  if (inst->getNumRegions() != 0)
     return inst->emitError("NYI path Op with region");
 
   if (auto write = inst->dyn_cast<VectorTransferWriteOp>()) {
index b084b01..e7e72fd 100644 (file)
@@ -1087,7 +1087,7 @@ static Instruction *vectorizeOneInstruction(FuncBuilder *b, Instruction *opInst,
     opInst->erase();
     return res;
   }
-  if (opInst->getNumBlockLists() != 0)
+  if (opInst->getNumRegions() != 0)
     return nullptr;
 
   auto types = map([state](Value *v) { return getVectorType(v, *state); },
@@ -1112,7 +1112,7 @@ static Instruction *vectorizeOneInstruction(FuncBuilder *b, Instruction *opInst,
   OperationState newOp(b->getContext(), opInst->getLoc(),
                        opInst->getName().getStringRef(), operands, types,
                        opInst->getAttrs(), /*successors=*/{},
-                       /*numBlockLists=*/0, opInst->hasResizableOperandsList());
+                       /*numRegions=*/0, opInst->hasResizableOperandsList());
   return b->createOperation(newOp);
 }
 
index b96eaaa..cebcdf6 100644 (file)
@@ -222,7 +222,7 @@ func @malformed_for_to() {
 
 func @incomplete_for() {
   for %i = 1 to 10 step 2
-}        // expected-error {{expected '{' to begin block list}}
+}        // expected-error {{expected '{' to begin a region}}
 
 // -----
 
index 34b7462..a9aa477 100644 (file)
@@ -787,7 +787,7 @@ func @verbose_if(%N: index) {
     // CHECK-NEXT: "add"
     %y = "add"(%c, %N) : (index, index) -> index
     // CHECK-NEXT: } else {
-  } { // The else block list.
+  } { // The else region.
     // CHECK-NEXT: "add"
     %z = "add"(%c, %c) : (index, index) -> index
   }