forked from OSchip/llvm-project
NFC: Standardize the terminology used for parent ops/regions/etc.
There are currently several different terms used to refer to a parent IR unit in 'get' methods: getParent/getEnclosing/getContaining. This cl standardizes all of these methods to use 'getParent*'. PiperOrigin-RevId: 262680287
This commit is contained in:
parent
ac68637ba9
commit
1e42954032
|
@ -443,7 +443,7 @@ struct LateLoweringPass : public ModulePass<LateLoweringPass> {
|
|||
|
||||
// Insert a `dealloc` operation right before the `return` operations, unless
|
||||
// it is returned itself in which case the caller is responsible for it.
|
||||
alloc.getContainingRegion()->walk([&](Operation *op) {
|
||||
alloc.getParentRegion()->walk([&](Operation *op) {
|
||||
auto returnOp = dyn_cast<ReturnOp>(op);
|
||||
if (!returnOp)
|
||||
return;
|
||||
|
|
|
@ -95,9 +95,8 @@ public:
|
|||
/// Blocks are maintained in a Region.
|
||||
Region *getParent();
|
||||
|
||||
/// Returns the closest surrounding operation that contains this block or
|
||||
/// nullptr if this is a top-level block.
|
||||
Operation *getContainingOp();
|
||||
/// Returns the closest surrounding operation that contains this block.
|
||||
Operation *getParentOp();
|
||||
|
||||
/// Return if this block is the entry block in the parent region.
|
||||
bool isEntryBlock();
|
||||
|
@ -373,7 +372,7 @@ struct ilist_traits<::mlir::Block> : public ilist_alloc_traits<::mlir::Block> {
|
|||
block_iterator first, block_iterator last);
|
||||
|
||||
private:
|
||||
mlir::Region *getContainingRegion();
|
||||
mlir::Region *getParentRegion();
|
||||
};
|
||||
} // end namespace llvm
|
||||
|
||||
|
|
|
@ -890,10 +890,8 @@ public:
|
|||
/// Return the dialect that this refers to.
|
||||
Dialect *getDialect() { return getOperation()->getDialect(); }
|
||||
|
||||
/// Return the Region enclosing this Op.
|
||||
Region *getContainingRegion() {
|
||||
return getOperation()->getContainingRegion();
|
||||
}
|
||||
/// Return the parent Region of this operation.
|
||||
Region *getParentRegion() { return getOperation()->getParentRegion(); }
|
||||
|
||||
/// Return true if this "op class" can match against the specified operation.
|
||||
/// This hook can be overridden with a more specific implementation in
|
||||
|
|
|
@ -116,10 +116,9 @@ public:
|
|||
/// Set the source location the operation was defined or derived from.
|
||||
void setLoc(Location loc) { location = loc; }
|
||||
|
||||
/// Returns the region to which the instruction belongs, which can be a
|
||||
/// function body region or a region that belongs to another operation.
|
||||
/// Returns nullptr if the instruction is unlinked.
|
||||
Region *getContainingRegion() const;
|
||||
/// Returns the region to which the instruction belongs. Returns nullptr if
|
||||
/// the instruction is unlinked.
|
||||
Region *getParentRegion();
|
||||
|
||||
/// Returns the closest surrounding operation that contains this operation
|
||||
/// or nullptr if this is a top-level operation.
|
||||
|
|
|
@ -67,12 +67,12 @@ public:
|
|||
return &Region::blocks;
|
||||
}
|
||||
|
||||
/// Return the region containing this region or nullptr if it is a top-level
|
||||
/// region.
|
||||
Region *getContainingRegion();
|
||||
/// Return the region containing this region or nullptr if the region is
|
||||
/// attached to a top-level operation.
|
||||
Region *getParentRegion();
|
||||
|
||||
/// Return the parent operation this region is attached to.
|
||||
Operation *getContainingOp();
|
||||
Operation *getParentOp();
|
||||
|
||||
/// Find the first parent operation of the given type, or nullptr if there is
|
||||
/// no ancestor operation.
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
do {
|
||||
if (auto parent = dyn_cast_or_null<ParentT>(region->container))
|
||||
return parent;
|
||||
} while ((region = region->getContainingRegion()));
|
||||
} while ((region = region->getParentRegion()));
|
||||
return ParentT();
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
Location getLoc();
|
||||
|
||||
/// Return the Region in which this Value is defined.
|
||||
Region *getContainingRegion();
|
||||
Region *getParentRegion();
|
||||
|
||||
using use_iterator = ValueUseIterator<OpOperand>;
|
||||
using use_range = llvm::iterator_range<use_iterator>;
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace mlir {
|
|||
template <typename Range>
|
||||
bool areValuesDefinedAbove(Range values, Region &limit) {
|
||||
for (Value *v : values)
|
||||
if (!v->getContainingRegion()->isProperAncestor(&limit))
|
||||
if (!v->getParentRegion()->isProperAncestor(&limit))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ AffineOpsDialect::AffineOpsDialect(MLIRContext *context)
|
|||
|
||||
/// 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());
|
||||
return llvm::isa<FuncOp>(region->getParentOp());
|
||||
}
|
||||
|
||||
/// A utility function to check if a value is defined at the top level of a
|
||||
|
@ -55,7 +55,7 @@ static bool isFunctionRegion(Region *region) {
|
|||
bool mlir::isTopLevelSymbol(Value *value) {
|
||||
if (auto *arg = dyn_cast<BlockArgument>(value))
|
||||
return isFunctionRegion(arg->getOwner()->getParent());
|
||||
return isFunctionRegion(value->getDefiningOp()->getContainingRegion());
|
||||
return isFunctionRegion(value->getDefiningOp()->getParentRegion());
|
||||
}
|
||||
|
||||
// Value can be used as a dimension id if it is valid as a symbol, or
|
||||
|
@ -68,7 +68,7 @@ bool mlir::isValidDim(Value *value) {
|
|||
|
||||
if (auto *op = value->getDefiningOp()) {
|
||||
// Top level operation or constant operation is ok.
|
||||
if (isFunctionRegion(op->getContainingRegion()) || isa<ConstantOp>(op))
|
||||
if (isFunctionRegion(op->getParentRegion()) || isa<ConstantOp>(op))
|
||||
return true;
|
||||
// Affine apply operation is ok if all of its operands are ok.
|
||||
if (auto applyOp = dyn_cast<AffineApplyOp>(op))
|
||||
|
@ -93,7 +93,7 @@ bool mlir::isValidSymbol(Value *value) {
|
|||
|
||||
if (auto *op = value->getDefiningOp()) {
|
||||
// Top level operation or constant operation is ok.
|
||||
if (isFunctionRegion(op->getContainingRegion()) || isa<ConstantOp>(op))
|
||||
if (isFunctionRegion(op->getParentRegion()) || isa<ConstantOp>(op))
|
||||
return true;
|
||||
// Affine apply operation is ok if all of its operands are ok.
|
||||
if (auto applyOp = dyn_cast<AffineApplyOp>(op))
|
||||
|
@ -1447,7 +1447,7 @@ AffineForOp mlir::getForInductionVarOwner(Value *val) {
|
|||
auto *ivArg = dyn_cast<BlockArgument>(val);
|
||||
if (!ivArg || !ivArg->getOwner())
|
||||
return AffineForOp();
|
||||
auto *containingInst = ivArg->getOwner()->getParent()->getContainingOp();
|
||||
auto *containingInst = ivArg->getOwner()->getParent()->getParentOp();
|
||||
return dyn_cast<AffineForOp>(containingInst);
|
||||
}
|
||||
|
||||
|
|
|
@ -548,8 +548,8 @@ static Block *getCommonBlock(const MemRefAccess &srcAccess,
|
|||
unsigned numCommonLoops) {
|
||||
if (numCommonLoops == 0) {
|
||||
auto *block = srcAccess.opInst->getBlock();
|
||||
while (!llvm::isa<FuncOp>(block->getContainingOp())) {
|
||||
block = block->getContainingOp()->getBlock();
|
||||
while (!llvm::isa<FuncOp>(block->getParentOp())) {
|
||||
block = block->getParentOp()->getBlock();
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ bool DominanceInfoBase<IsPostDom>::properlyDominates(Block *a, Block *b) {
|
|||
if (regionA != regionB) {
|
||||
Operation *bAncestor;
|
||||
do {
|
||||
bAncestor = regionB->getContainingOp();
|
||||
bAncestor = regionB->getParentOp();
|
||||
// If 'bAncestor' is the top level region, then 'a' is a block that post
|
||||
// dominates 'b'.
|
||||
if (!bAncestor || !bAncestor->getBlock())
|
||||
|
|
|
@ -449,7 +449,7 @@ static void findInstPosition(Operation *op, Block *limitBlock,
|
|||
// rely on linear scans.
|
||||
int instPosInBlock = std::distance(block->begin(), op->getIterator());
|
||||
positions->push_back(instPosInBlock);
|
||||
op = block->getContainingOp();
|
||||
op = block->getParentOp();
|
||||
block = op->getBlock();
|
||||
}
|
||||
std::reverse(positions->begin(), positions->end());
|
||||
|
|
|
@ -118,7 +118,7 @@ ForOp mlir::loop::getForInductionVarOwner(Value *val) {
|
|||
if (!ivArg)
|
||||
return ForOp();
|
||||
assert(ivArg->getOwner() && "unlinked block argument");
|
||||
auto *containingInst = ivArg->getOwner()->getContainingOp();
|
||||
auto *containingInst = ivArg->getOwner()->getParentOp();
|
||||
return dyn_cast_or_null<ForOp>(containingInst);
|
||||
}
|
||||
|
||||
|
|
|
@ -1713,14 +1713,14 @@ void Operation::print(raw_ostream &os) {
|
|||
return;
|
||||
}
|
||||
|
||||
auto region = getContainingRegion();
|
||||
auto region = getParentRegion();
|
||||
if (!region) {
|
||||
os << "<<UNLINKED INSTRUCTION>>\n";
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the top-level region.
|
||||
while (auto *nextRegion = region->getContainingRegion())
|
||||
while (auto *nextRegion = region->getParentRegion())
|
||||
region = nextRegion;
|
||||
|
||||
ModuleState state(getContext());
|
||||
|
@ -1741,7 +1741,7 @@ void Block::print(raw_ostream &os) {
|
|||
}
|
||||
|
||||
// Get the top-level region.
|
||||
while (auto *nextRegion = region->getContainingRegion())
|
||||
while (auto *nextRegion = region->getParentRegion())
|
||||
region = nextRegion;
|
||||
|
||||
ModuleState state(region->getContext());
|
||||
|
@ -1760,7 +1760,7 @@ void Block::printAsOperand(raw_ostream &os, bool printType) {
|
|||
}
|
||||
|
||||
// Get the top-level region.
|
||||
while (auto *nextRegion = region->getContainingRegion())
|
||||
while (auto *nextRegion = region->getParentRegion())
|
||||
region = nextRegion;
|
||||
|
||||
ModuleState state(region->getContext());
|
||||
|
|
|
@ -49,9 +49,9 @@ Block::~Block() {
|
|||
Region *Block::getParent() { return parentValidInstOrderPair.getPointer(); }
|
||||
|
||||
/// Returns the closest surrounding operation that contains this block or
|
||||
/// nullptr if this is a top-level operation block.
|
||||
Operation *Block::getContainingOp() {
|
||||
return getParent() ? getParent()->getContainingOp() : nullptr;
|
||||
/// nullptr if this block is unlinked.
|
||||
Operation *Block::getParentOp() {
|
||||
return getParent() ? getParent()->getParentOp() : nullptr;
|
||||
}
|
||||
|
||||
/// Return if this block is the entry block in the parent region.
|
||||
|
|
|
@ -273,12 +273,12 @@ Dialect *Operation::getDialect() {
|
|||
return getContext()->getRegisteredDialect(getName().getDialect());
|
||||
}
|
||||
|
||||
Region *Operation::getContainingRegion() const {
|
||||
Region *Operation::getParentRegion() {
|
||||
return block ? block->getParent() : nullptr;
|
||||
}
|
||||
|
||||
Operation *Operation::getParentOp() {
|
||||
return block ? block->getContainingOp() : nullptr;
|
||||
return block ? block->getParentOp() : nullptr;
|
||||
}
|
||||
|
||||
/// Replace any uses of 'from' with 'to' within this operation.
|
||||
|
@ -858,7 +858,7 @@ static LogicalResult verifyBBArguments(Operation::operand_range operands,
|
|||
}
|
||||
|
||||
static LogicalResult verifyTerminatorSuccessors(Operation *op) {
|
||||
auto *parent = op->getContainingRegion();
|
||||
auto *parent = op->getParentRegion();
|
||||
|
||||
// Verify that the operands lines up with the BB arguments in the successor.
|
||||
for (unsigned i = 0, e = op->getNumSuccessors(); i != e; ++i) {
|
||||
|
|
|
@ -42,18 +42,18 @@ Location Region::getLoc() {
|
|||
return container->getLoc();
|
||||
}
|
||||
|
||||
Region *Region::getContainingRegion() {
|
||||
Region *Region::getParentRegion() {
|
||||
assert(container && "region is not attached to a container");
|
||||
return container->getContainingRegion();
|
||||
return container->getParentRegion();
|
||||
}
|
||||
|
||||
Operation *Region::getContainingOp() { return container; }
|
||||
Operation *Region::getParentOp() { return container; }
|
||||
|
||||
bool Region::isProperAncestor(Region *other) {
|
||||
if (this == other)
|
||||
return false;
|
||||
|
||||
while ((other = other->getContainingRegion())) {
|
||||
while ((other = other->getParentRegion())) {
|
||||
if (this == other)
|
||||
return true;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ bool Region::isProperAncestor(Region *other) {
|
|||
unsigned Region::getRegionNumber() {
|
||||
// Regions are always stored consecutively, so use pointer subtraction to
|
||||
// figure out what number this is.
|
||||
return this - &getContainingOp()->getRegions()[0];
|
||||
return this - &getParentOp()->getRegions()[0];
|
||||
}
|
||||
|
||||
/// Clone the internal blocks from this region into `dest`. Any
|
||||
|
@ -145,7 +145,7 @@ static bool isIsolatedAbove(Region ®ion, Region &limit,
|
|||
for (Value *operand : op.getOperands()) {
|
||||
// Check that any value that is used by an operation is defined in the
|
||||
// same region as either an operation result or a block argument.
|
||||
if (operand->getContainingRegion()->isProperAncestor(&limit)) {
|
||||
if (operand->getParentRegion()->isProperAncestor(&limit)) {
|
||||
if (noteLoc) {
|
||||
op.emitOpError("using value defined outside the region")
|
||||
.attachNote(noteLoc)
|
||||
|
@ -175,7 +175,7 @@ void Region::walk(llvm::function_ref<void(Operation *)> callback) {
|
|||
block.walk(callback);
|
||||
}
|
||||
|
||||
Region *llvm::ilist_traits<::mlir::Block>::getContainingRegion() {
|
||||
Region *llvm::ilist_traits<::mlir::Block>::getParentRegion() {
|
||||
size_t Offset(
|
||||
size_t(&((Region *)nullptr->*Region::getSublistAccess(nullptr))));
|
||||
iplist<Block> *Anchor(static_cast<iplist<Block> *>(this));
|
||||
|
@ -186,7 +186,7 @@ Region *llvm::ilist_traits<::mlir::Block>::getContainingRegion() {
|
|||
/// We keep the region pointer up to date.
|
||||
void llvm::ilist_traits<::mlir::Block>::addNodeToList(Block *block) {
|
||||
assert(!block->getParent() && "already in a region!");
|
||||
block->parentValidInstOrderPair.setPointer(getContainingRegion());
|
||||
block->parentValidInstOrderPair.setPointer(getParentRegion());
|
||||
}
|
||||
|
||||
/// This is a trait method invoked when an operation is removed from a
|
||||
|
@ -202,8 +202,8 @@ void llvm::ilist_traits<::mlir::Block>::transferNodesFromList(
|
|||
ilist_traits<Block> &otherList, block_iterator first, block_iterator last) {
|
||||
// If we are transferring operations within the same function, the parent
|
||||
// pointer doesn't need to be updated.
|
||||
auto *curParent = getContainingRegion();
|
||||
if (curParent == otherList.getContainingRegion())
|
||||
auto *curParent = getParentRegion();
|
||||
if (curParent == otherList.getParentRegion())
|
||||
return;
|
||||
|
||||
// Update the 'parent' member of each Block.
|
||||
|
|
|
@ -35,12 +35,12 @@ Location Value::getLoc() {
|
|||
}
|
||||
|
||||
/// Return the Region in which this Value is defined.
|
||||
Region *Value::getContainingRegion() {
|
||||
Region *Value::getParentRegion() {
|
||||
switch (getKind()) {
|
||||
case Value::Kind::BlockArgument:
|
||||
return cast<BlockArgument>(this)->getOwner()->getParent();
|
||||
case Value::Kind::OpResult:
|
||||
return getDefiningOp()->getContainingRegion();
|
||||
return getDefiningOp()->getParentRegion();
|
||||
}
|
||||
llvm_unreachable("Unknown Value Kind");
|
||||
}
|
||||
|
|
|
@ -249,7 +249,7 @@ static bool getFullMemRefAsRegion(Operation *opInst, unsigned numParamLoopIVs,
|
|||
|
||||
static InFlightDiagnostic LLVM_ATTRIBUTE_UNUSED
|
||||
emitRemarkForBlock(Block &block) {
|
||||
return block.getContainingOp()->emitRemark();
|
||||
return block.getParentOp()->emitRemark();
|
||||
}
|
||||
|
||||
/// Generates a point-wise copy from/to `memref' to/from `fastMemRef' and
|
||||
|
@ -872,7 +872,7 @@ uint64_t AffineDataCopyGeneration::runOnBlock(Block::iterator begin,
|
|||
if (totalCopyBuffersSizeInBytes > fastMemCapacityBytes) {
|
||||
StringRef str = "Total size of all copy buffers' for this block "
|
||||
"exceeds fast memory capacity\n";
|
||||
block->getContainingOp()->emitError(str);
|
||||
block->getParentOp()->emitError(str);
|
||||
}
|
||||
|
||||
return totalCopyBuffersSizeInBytes;
|
||||
|
|
|
@ -32,11 +32,11 @@ using namespace mlir;
|
|||
/// Given an operation, find the parent region that folded constants should be
|
||||
/// inserted into.
|
||||
static Region *getInsertionRegion(Operation *op) {
|
||||
while (Region *region = op->getContainingRegion()) {
|
||||
while (Region *region = op->getParentRegion()) {
|
||||
// Insert in this region for any of the following scenarios:
|
||||
// * The parent is unregistered, or is known to be isolated from above.
|
||||
// * The parent is a top-level operation.
|
||||
auto *parentOp = region->getContainingOp();
|
||||
auto *parentOp = region->getParentOp();
|
||||
if (!parentOp->isRegistered() || parentOp->isKnownIsolatedFromAbove() ||
|
||||
!parentOp->getBlock())
|
||||
return region;
|
||||
|
|
|
@ -27,7 +27,7 @@ using namespace mlir;
|
|||
void mlir::replaceAllUsesInRegionWith(Value *orig, Value *replacement,
|
||||
Region ®ion) {
|
||||
for (IROperand &use : llvm::make_early_inc_range(orig->getUses())) {
|
||||
if (region.isAncestor(use.getOwner()->getContainingRegion()))
|
||||
if (region.isAncestor(use.getOwner()->getParentRegion()))
|
||||
use.set(replacement);
|
||||
}
|
||||
}
|
||||
|
@ -40,8 +40,8 @@ void mlir::getUsedValuesDefinedAbove(Region ®ion, Region &limit,
|
|||
// Collect proper ancestors of `limit` upfront to avoid traversing the region
|
||||
// tree for every value.
|
||||
llvm::SmallPtrSet<Region *, 4> properAncestors;
|
||||
for (auto *reg = limit.getContainingRegion(); reg != nullptr;
|
||||
reg = reg->getContainingRegion()) {
|
||||
for (auto *reg = limit.getParentRegion(); reg != nullptr;
|
||||
reg = reg->getParentRegion()) {
|
||||
properAncestors.insert(reg);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ void mlir::getUsedValuesDefinedAbove(Region ®ion, Region &limit,
|
|||
for (Value *operand : op->getOperands())
|
||||
// Collect values that are used by an operation and defined in a proper
|
||||
// ancestor of region.
|
||||
if (properAncestors.count(operand->getContainingRegion()))
|
||||
if (properAncestors.count(operand->getParentRegion()))
|
||||
values.insert(operand);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ struct TestRegionRewriteBlockMovement : public ConversionPattern {
|
|||
matchAndRewrite(Operation *op, ArrayRef<Value *> operands,
|
||||
ConversionPatternRewriter &rewriter) const final {
|
||||
// Inline this region into the parent region.
|
||||
auto &parentRegion = *op->getContainingRegion();
|
||||
auto &parentRegion = *op->getParentRegion();
|
||||
rewriter.inlineRegionBefore(op->getRegion(0), parentRegion,
|
||||
parentRegion.end());
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
|
||||
func.walk<loop::ForOp>([&processorIds, &numProcessors](loop::ForOp op) {
|
||||
// Ignore nested loops.
|
||||
if (op.getContainingRegion()->getParentOfType<loop::ForOp>())
|
||||
if (op.getParentRegion()->getParentOfType<loop::ForOp>())
|
||||
return;
|
||||
mapLoopToProcessorIds(op, processorIds, numProcessors);
|
||||
});
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
FuncOp func = getFunction();
|
||||
func.walk<loop::ForOp>([this](loop::ForOp op) {
|
||||
// Ignore nested loops.
|
||||
if (op.getContainingRegion()->getParentOfType<loop::ForOp>())
|
||||
if (op.getParentRegion()->getParentOfType<loop::ForOp>())
|
||||
return;
|
||||
extractFixedOuterLoops(op, sizes);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue