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
/// region, i.e. a function body region.
/// region.
Region *getContainingRegion();
/// Return the parent operation this region is attached to.
@ -85,10 +85,6 @@ public:
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.
bool isProperAncestor(Region *other);

View File

@ -41,12 +41,17 @@ AffineOpsDialect::AffineOpsDialect(MLIRContext *context)
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
/// function. A value defined at the top level is always a valid symbol.
bool mlir::isTopLevelSymbol(Value *value) {
if (auto *arg = dyn_cast<BlockArgument>(value))
return arg->getOwner()->getParent()->getContainingFunction();
return value->getDefiningOp()->getParentOp() == nullptr;
return isFunctionRegion(arg->getOwner()->getParent());
return isFunctionRegion(value->getDefiningOp()->getContainingRegion());
}
// 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()) {
// Top level operation or constant operation is ok.
if (op->getParentOp() == nullptr || isa<ConstantOp>(op))
if (isFunctionRegion(op->getContainingRegion()) || isa<ConstantOp>(op))
return true;
// Affine apply operation is ok if all of its operands are ok.
if (auto applyOp = dyn_cast<AffineApplyOp>(op))
@ -84,7 +89,7 @@ bool mlir::isValidSymbol(Value *value) {
if (auto *op = value->getDefiningOp()) {
// Top level operation or constant operation is ok.
if (op->getParentOp() == nullptr || isa<ConstantOp>(op))
if (isFunctionRegion(op->getContainingRegion()) || isa<ConstantOp>(op))
return true;
// Affine apply operation is ok if all of its operands are ok.
if (auto applyOp = dyn_cast<AffineApplyOp>(op))
@ -95,9 +100,8 @@ bool mlir::isValidSymbol(Value *value) {
return isTopLevelSymbol(dimOp.getOperand());
return false;
}
// Otherwise, the only valid symbol is a top level block argument.
auto *arg = cast<BlockArgument>(value);
return arg->getOwner()->getParent()->getContainingFunction();
// Otherwise, check that the value is a top level symbol.
return isTopLevelSymbol(value);
}
/// 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())
return AffineForOp();
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

View File

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

View File

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

View File

@ -49,17 +49,7 @@ Region *Region::getContainingRegion() {
return container->getContainingRegion();
}
Operation *Region::getContainingOp() {
// 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();
}
Operation *Region::getContainingOp() { return container; }
bool Region::isProperAncestor(Region *other) {
if (this == other)

View File

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

View File

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

View File

@ -34,12 +34,11 @@ using namespace mlir;
static Region *getInsertionRegion(Operation *op) {
while (Region *region = op->getContainingRegion()) {
// 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 a top-level operation.
auto *parentOp = region->getContainingOp();
if (!parentOp || !parentOp->isRegistered() ||
parentOp->isKnownIsolatedFromAbove() || !parentOp->getBlock())
if (!parentOp->isRegistered() || parentOp->isKnownIsolatedFromAbove() ||
!parentOp->getBlock())
return region;
// Traverse up the parent looking for an insertion region.
op = parentOp;

View File

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