Skip to content

Commit

Permalink
NFC: Replace usages of Value::getKind with explicit isa/casts.
Browse files Browse the repository at this point in the history
It is more idiomatic to use the llvm::cast infrastructure for checking the type of a value.

PiperOrigin-RevId: 274684945
  • Loading branch information
River707 authored and tensorflower-gardener committed Oct 14, 2019
1 parent 96de709 commit f29731d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
42 changes: 20 additions & 22 deletions mlir/lib/IR/AsmPrinter.cpp
Expand Up @@ -1519,23 +1519,24 @@ void OperationPrinter::numberValueID(Value *value) {
}

if (specialNameBuffer.empty()) {
switch (value->getKind()) {
case Value::Kind::BlockArgument:
// If this is an argument to the entry block of a region, give it an 'arg'
// name.
if (auto *block = cast<BlockArgument>(value)->getOwner()) {
auto *parentRegion = block->getParent();
if (parentRegion && block == &parentRegion->front()) {
specialName << "arg" << nextArgumentID++;
break;
}
}
// Otherwise number it normally.
auto *blockArg = dyn_cast<BlockArgument>(value);
if (!blockArg) {
// This is an uninteresting operation result, give it a boring number and
// be done with it.
valueIDs[value] = nextValueID++;
return;
case Value::Kind::OpResult:
// This is an uninteresting result, give it a boring number and be
// done with it.
}

// Otherwise, if this is an argument to the entry block of a region, give it
// an 'arg' name.
if (auto *block = blockArg->getOwner()) {
auto *parentRegion = block->getParent();
if (parentRegion && block == &parentRegion->front())
specialName << "arg" << nextArgumentID++;
}

// Otherwise number it normally.
if (specialNameBuffer.empty()) {
valueIDs[value] = nextValueID++;
return;
}
Expand Down Expand Up @@ -1860,14 +1861,11 @@ void IntegerSet::print(raw_ostream &os) const {
}

void Value::print(raw_ostream &os) {
switch (getKind()) {
case Value::Kind::BlockArgument:
// TODO: Improve this.
os << "<block argument>\n";
return;
case Value::Kind::OpResult:
if (auto *op = getDefiningOp())
return getDefiningOp()->print(os);
}
// TODO: Improve this.
assert(isa<BlockArgument>(*this));
os << "<block argument>\n";
}

void Value::dump() {
Expand Down
10 changes: 3 additions & 7 deletions mlir/lib/IR/Value.cpp
Expand Up @@ -36,13 +36,9 @@ Location Value::getLoc() {

/// Return the Region in which this Value is defined.
Region *Value::getParentRegion() {
switch (getKind()) {
case Value::Kind::BlockArgument:
return cast<BlockArgument>(this)->getOwner()->getParent();
case Value::Kind::OpResult:
return getDefiningOp()->getParentRegion();
}
llvm_unreachable("Unknown Value Kind");
if (auto *op = getDefiningOp())
return op->getParentRegion();
return cast<BlockArgument>(this)->getOwner()->getParent();
}

//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit f29731d

Please sign in to comment.