From 6ab2984b23c86de626f2c99473e1733cc2ebfad0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 21 Mar 2019 11:57:14 -0700 Subject: [PATCH] Remove const support from mlir::Region PiperOrigin-RevId: 239642194 --- mlir/include/mlir/AffineOps/AffineOps.h | 6 +++--- mlir/include/mlir/Analysis/Dominance.h | 4 ++-- mlir/include/mlir/IR/Block.h | 19 +++---------------- mlir/include/mlir/IR/Instruction.h | 13 ++++--------- mlir/include/mlir/IR/OpImplementation.h | 3 +-- mlir/lib/AffineOps/AffineOps.cpp | 6 +++--- mlir/lib/IR/AsmPrinter.cpp | 2 +- mlir/lib/IR/Block.cpp | 4 ++-- 8 files changed, 19 insertions(+), 38 deletions(-) diff --git a/mlir/include/mlir/AffineOps/AffineOps.h b/mlir/include/mlir/AffineOps/AffineOps.h index 0cb270a..a9b93ba 100644 --- a/mlir/include/mlir/AffineOps/AffineOps.h +++ b/mlir/include/mlir/AffineOps/AffineOps.h @@ -147,7 +147,7 @@ public: /// Get the body region of the AffineForOp. Region &getRegion() { return getInstruction()->getRegion(0); } - const Region &getRegion() const { return getInstruction()->getRegion(0); } + Region &getRegion() const { return getInstruction()->getRegion(0); } /// Returns the induction variable for this loop. Value *getInductionVar(); @@ -331,13 +331,13 @@ public: /// Returns the 'then' region. Region &getThenBlocks(); - const Region &getThenBlocks() const { + Region &getThenBlocks() const { return const_cast(this)->getThenBlocks(); } /// Returns the 'else' blocks. Region &getElseBlocks(); - const Region &getElseBlocks() const { + Region &getElseBlocks() const { return const_cast(this)->getElseBlocks(); } diff --git a/mlir/include/mlir/Analysis/Dominance.h b/mlir/include/mlir/Analysis/Dominance.h index ab4022c..39c95b8 100644 --- a/mlir/include/mlir/Analysis/Dominance.h +++ b/mlir/include/mlir/Analysis/Dominance.h @@ -44,7 +44,7 @@ public: void recalculate(Function *function); /// Get the root dominance node of the given region. - DominanceInfoNode *getRootNode(const Region *region) { + DominanceInfoNode *getRootNode(Region *region) { assert(dominanceInfos.count(region) != 0); return dominanceInfos[region]->getRootNode(); } @@ -56,7 +56,7 @@ protected: bool properlyDominates(const Block *a, const Block *b); /// A mapping of regions to their base dominator tree. - llvm::DenseMap> dominanceInfos; + llvm::DenseMap> dominanceInfos; }; } // end namespace detail diff --git a/mlir/include/mlir/IR/Block.h b/mlir/include/mlir/IR/Block.h index 9269c25..6f1196b 100644 --- a/mlir/include/mlir/IR/Block.h +++ b/mlir/include/mlir/IR/Block.h @@ -384,32 +384,22 @@ public: using RegionType = llvm::iplist; RegionType &getBlocks() { return blocks; } - const RegionType &getBlocks() const { return blocks; } // Iteration over the block in the function. 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(); } - 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(); } + bool empty() { 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(); } - const Block &back() const { return const_cast(this)->back(); } - Block &front() { return blocks.front(); } - const Block &front() const { return const_cast(this)->front(); } /// getSublistAccess() - Returns pointer to member of region. static RegionType Region::*getSublistAccess(Block *) { @@ -419,20 +409,17 @@ public: /// 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(this)->getContainingInst(); - } /// 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(); /// 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(Region *dest, BlockAndValueMapping &mapper, - MLIRContext *context) const; + MLIRContext *context); private: RegionType blocks; diff --git a/mlir/include/mlir/IR/Instruction.h b/mlir/include/mlir/IR/Instruction.h index ccc5472..7a12d4f 100644 --- a/mlir/include/mlir/IR/Instruction.h +++ b/mlir/include/mlir/IR/Instruction.h @@ -291,21 +291,16 @@ public: unsigned getNumRegions() const { return numRegions; } /// Returns the regions held by this operation. - MutableArrayRef getRegions() { - return {getTrailingObjects(), numRegions}; - } - ArrayRef getRegions() const { - return const_cast(this)->getRegions(); + MutableArrayRef getRegions() const { + auto *regions = getTrailingObjects(); + return {const_cast(regions), numRegions}; } /// Returns the region held by this operation at position 'index'. - Region &getRegion(unsigned index) { + Region &getRegion(unsigned index) const { assert(index < numRegions && "invalid region index"); return getRegions()[index]; } - const Region &getRegion(unsigned index) const { - return const_cast(this)->getRegion(index); - } //===--------------------------------------------------------------------===// // Terminators diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index 5ad22e6..f8465af 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -90,8 +90,7 @@ public: virtual void printGenericOp(const Instruction *op) = 0; /// Prints a region. - virtual void printRegion(const Region &blocks, - bool printEntryBlockArgs = true) = 0; + virtual void printRegion(Region &blocks, bool printEntryBlockArgs = true) = 0; private: OpAsmPrinter(const OpAsmPrinter &) = delete; diff --git a/mlir/lib/AffineOps/AffineOps.cpp b/mlir/lib/AffineOps/AffineOps.cpp index ab75909..cd73916 100644 --- a/mlir/lib/AffineOps/AffineOps.cpp +++ b/mlir/lib/AffineOps/AffineOps.cpp @@ -568,7 +568,7 @@ void AffineForOp::build(Builder *builder, OperationState *result, int64_t lb, } bool AffineForOp::verify() const { - const auto &bodyRegion = getInstruction()->getRegion(0); + auto &bodyRegion = getInstruction()->getRegion(0); // The body region must contain a single basic block. if (bodyRegion.empty() || std::next(bodyRegion.begin()) != bodyRegion.end()) @@ -1057,7 +1057,7 @@ bool AffineIfOp::verify() const { return true; // Verify that the entry of each child region does not have arguments. - for (const auto ®ion : getInstruction()->getRegions()) { + for (auto ®ion : getInstruction()->getRegions()) { if (region.empty()) continue; @@ -1123,7 +1123,7 @@ void AffineIfOp::print(OpAsmPrinter *p) const { p->printRegion(getInstruction()->getRegion(0)); // Print the 'else' regions if it has any blocks. - const auto &elseRegion = getInstruction()->getRegion(1); + auto &elseRegion = getInstruction()->getRegion(1); if (!elseRegion.empty()) { *p << " else"; p->printRegion(elseRegion); diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index b93fe0d..78f40a5 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -1111,7 +1111,7 @@ public: unsigned index) override; /// Print a region. - void printRegion(const Region &blocks, bool printEntryBlockArgs) override { + void printRegion(Region &blocks, bool printEntryBlockArgs) override { os << " {\n"; if (!blocks.empty()) { auto *entryBlock = &blocks.front(); diff --git a/mlir/lib/IR/Block.cpp b/mlir/lib/IR/Block.cpp index 4d407fd..1e3c79f 100644 --- a/mlir/lib/IR/Block.cpp +++ b/mlir/lib/IR/Block.cpp @@ -273,14 +273,14 @@ Instruction *Region::getContainingInst() { return container.dyn_cast(); } -Function *Region::getContainingFunction() const { +Function *Region::getContainingFunction() { return container.dyn_cast(); } /// Clone the internal blocks from this region into `dest`. Any /// cloned blocks are appended to the back of dest. void Region::cloneInto(Region *dest, BlockAndValueMapping &mapper, - MLIRContext *context) const { + MLIRContext *context) { assert(dest && "expected valid region to clone into"); // If the list is empty there is nothing to clone. -- 2.7.4