NFC: Remove Region::getContainingFunction as Functions are now Operations.

PiperOrigin-RevId: 256579717
This commit is contained in:
River Riddle 2019-07-04 13:22:42 -07:00 committed by A. Unique TensorFlower
parent fa6b49b095
commit 474e354179
9 changed files with 21 additions and 34 deletions

View File

@ -68,7 +68,7 @@ public:
} }
/// Return the region containing this region or nullptr if it is a top-level /// Return the region containing this region or nullptr if it is a top-level
/// region, i.e. a function body region. /// region.
Region *getContainingRegion(); Region *getContainingRegion();
/// Return the parent operation this region is attached to. /// Return the parent operation this region is attached to.
@ -85,10 +85,6 @@ public:
return ParentT(); return ParentT();
} }
/// 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();
/// Return true if this region is a proper ancestor of the `other` region. /// Return true if this region is a proper ancestor of the `other` region.
bool isProperAncestor(Region *other); bool isProperAncestor(Region *other);

View File

@ -41,12 +41,17 @@ AffineOpsDialect::AffineOpsDialect(MLIRContext *context)
AffineIfOp, AffineLoadOp, AffineStoreOp, AffineTerminatorOp>(); AffineIfOp, AffineLoadOp, AffineStoreOp, AffineTerminatorOp>();
} }
/// A utility function to check if a given region is attached to a function.
static bool isFunctionRegion(Region *region) {
return llvm::isa<FuncOp>(region->getContainingOp());
}
/// A utility function to check if a value is defined at the top level of a /// A utility function to check if a value is defined at the top level of a
/// function. A value defined at the top level is always a valid symbol. /// function. A value defined at the top level is always a valid symbol.
bool mlir::isTopLevelSymbol(Value *value) { bool mlir::isTopLevelSymbol(Value *value) {
if (auto *arg = dyn_cast<BlockArgument>(value)) if (auto *arg = dyn_cast<BlockArgument>(value))
return arg->getOwner()->getParent()->getContainingFunction(); return isFunctionRegion(arg->getOwner()->getParent());
return value->getDefiningOp()->getParentOp() == nullptr; return isFunctionRegion(value->getDefiningOp()->getContainingRegion());
} }
// Value can be used as a dimension id if it is valid as a symbol, or // Value can be used as a dimension id if it is valid as a symbol, or
@ -59,7 +64,7 @@ bool mlir::isValidDim(Value *value) {
if (auto *op = value->getDefiningOp()) { if (auto *op = value->getDefiningOp()) {
// Top level operation or constant operation is ok. // Top level operation or constant operation is ok.
if (op->getParentOp() == nullptr || isa<ConstantOp>(op)) if (isFunctionRegion(op->getContainingRegion()) || isa<ConstantOp>(op))
return true; return true;
// Affine apply operation is ok if all of its operands are ok. // Affine apply operation is ok if all of its operands are ok.
if (auto applyOp = dyn_cast<AffineApplyOp>(op)) if (auto applyOp = dyn_cast<AffineApplyOp>(op))
@ -84,7 +89,7 @@ bool mlir::isValidSymbol(Value *value) {
if (auto *op = value->getDefiningOp()) { if (auto *op = value->getDefiningOp()) {
// Top level operation or constant operation is ok. // Top level operation or constant operation is ok.
if (op->getParentOp() == nullptr || isa<ConstantOp>(op)) if (isFunctionRegion(op->getContainingRegion()) || isa<ConstantOp>(op))
return true; return true;
// Affine apply operation is ok if all of its operands are ok. // Affine apply operation is ok if all of its operands are ok.
if (auto applyOp = dyn_cast<AffineApplyOp>(op)) if (auto applyOp = dyn_cast<AffineApplyOp>(op))
@ -95,9 +100,8 @@ bool mlir::isValidSymbol(Value *value) {
return isTopLevelSymbol(dimOp.getOperand()); return isTopLevelSymbol(dimOp.getOperand());
return false; return false;
} }
// Otherwise, the only valid symbol is a top level block argument. // Otherwise, check that the value is a top level symbol.
auto *arg = cast<BlockArgument>(value); return isTopLevelSymbol(value);
return arg->getOwner()->getParent()->getContainingFunction();
} }
/// Utility function to verify that a set of operands are valid dimension and /// Utility function to verify that a set of operands are valid dimension and
@ -1445,7 +1449,7 @@ AffineForOp mlir::getForInductionVarOwner(Value *val) {
if (!ivArg || !ivArg->getOwner()) if (!ivArg || !ivArg->getOwner())
return AffineForOp(); return AffineForOp();
auto *containingInst = ivArg->getOwner()->getParent()->getContainingOp(); auto *containingInst = ivArg->getOwner()->getParent()->getContainingOp();
return dyn_cast_or_null<AffineForOp>(containingInst); return dyn_cast<AffineForOp>(containingInst);
} }
/// Extracts the induction variables from a list of AffineForOps and returns /// Extracts the induction variables from a list of AffineForOps and returns

View File

@ -547,7 +547,7 @@ static Block *getCommonBlock(const MemRefAccess &srcAccess,
unsigned numCommonLoops) { unsigned numCommonLoops) {
if (numCommonLoops == 0) { if (numCommonLoops == 0) {
auto *block = srcAccess.opInst->getBlock(); auto *block = srcAccess.opInst->getBlock();
while (block->getContainingOp()) { while (!llvm::isa<FuncOp>(block->getContainingOp())) {
block = block->getContainingOp()->getBlock(); block = block->getContainingOp()->getBlock();
} }
return block; return block;

View File

@ -1357,7 +1357,7 @@ void OperationPrinter::numberValueID(Value *value) {
if (auto *block = cast<BlockArgument>(value)->getOwner()) { if (auto *block = cast<BlockArgument>(value)->getOwner()) {
auto *parentRegion = block->getParent(); auto *parentRegion = block->getParent();
if (parentRegion && block == &parentRegion->front()) { if (parentRegion && block == &parentRegion->front()) {
if (parentRegion->getContainingFunction()) if (llvm::isa<FuncOp>(parentRegion->getContainingOp()))
specialName << "arg" << nextArgumentID++; specialName << "arg" << nextArgumentID++;
else else
specialName << "i" << nextRegionArgumentID++; specialName << "i" << nextRegionArgumentID++;

View File

@ -49,17 +49,7 @@ Region *Region::getContainingRegion() {
return container->getContainingRegion(); return container->getContainingRegion();
} }
Operation *Region::getContainingOp() { Operation *Region::getContainingOp() { return container; }
// TODO: Several usages of getContainingOp need to be updated to handle
// functions operations.
return getContainingFunction() ? nullptr : container;
}
Function Region::getContainingFunction() {
if (auto func = llvm::dyn_cast<FuncOp>(container))
return func;
return FuncOp();
}
bool Region::isProperAncestor(Region *other) { bool Region::isProperAncestor(Region *other) {
if (this == other) if (this == other)

View File

@ -148,8 +148,7 @@ mlir::linalg::ForOp mlir::linalg::getForInductionVarOwner(Value *val) {
if (!ivArg) if (!ivArg)
return ForOp(); return ForOp();
assert(ivArg->getOwner() && "unlinked block argument"); assert(ivArg->getOwner() && "unlinked block argument");
auto *containingInst = ivArg->getOwner()->getContainingOp(); return dyn_cast<ForOp>(ivArg->getOwner()->getContainingOp());
return dyn_cast_or_null<ForOp>(containingInst);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -428,8 +428,7 @@ static LogicalResult verify(spirv::ModuleOp moduleOp) {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
static LogicalResult verifyReturn(spirv::ReturnOp returnOp) { static LogicalResult verifyReturn(spirv::ReturnOp returnOp) {
auto funcOp = auto funcOp = llvm::dyn_cast<FuncOp>(returnOp.getOperation()->getParentOp());
returnOp.getOperation()->getContainingRegion()->getContainingFunction();
if (!funcOp) if (!funcOp)
return returnOp.emitOpError("must appear in a 'func' op"); return returnOp.emitOpError("must appear in a 'func' op");

View File

@ -34,12 +34,11 @@ using namespace mlir;
static Region *getInsertionRegion(Operation *op) { static Region *getInsertionRegion(Operation *op) {
while (Region *region = op->getContainingRegion()) { while (Region *region = op->getContainingRegion()) {
// Insert in this region for any of the following scenarios: // Insert in this region for any of the following scenarios:
// * The parent is not an operation, i.e. is a Function.
// * The parent is unregistered, or is known to be isolated from above. // * The parent is unregistered, or is known to be isolated from above.
// * The parent is a top-level operation. // * The parent is a top-level operation.
auto *parentOp = region->getContainingOp(); auto *parentOp = region->getContainingOp();
if (!parentOp || !parentOp->isRegistered() || if (!parentOp->isRegistered() || parentOp->isKnownIsolatedFromAbove() ||
parentOp->isKnownIsolatedFromAbove() || !parentOp->getBlock()) !parentOp->getBlock())
return region; return region;
// Traverse up the parent looking for an insertion region. // Traverse up the parent looking for an insertion region.
op = parentOp; op = parentOp;

View File

@ -260,7 +260,7 @@ bool mlir::getLoopNestStats(AffineForOp forOpRoot, LoopNestStats *stats) {
forOpRoot.getOperation()->walk<AffineForOp>([&](AffineForOp forOp) { forOpRoot.getOperation()->walk<AffineForOp>([&](AffineForOp forOp) {
auto *childForOp = forOp.getOperation(); auto *childForOp = forOp.getOperation();
auto *parentForOp = forOp.getOperation()->getParentOp(); auto *parentForOp = forOp.getOperation()->getParentOp();
if (parentForOp != nullptr) { if (!llvm::isa<FuncOp>(parentForOp)) {
if (!isa<AffineForOp>(parentForOp)) { if (!isa<AffineForOp>(parentForOp)) {
LLVM_DEBUG(llvm::dbgs() << "Expected parent AffineForOp"); LLVM_DEBUG(llvm::dbgs() << "Expected parent AffineForOp");
ret = false; ret = false;