diff options
| author | River Riddle <riverriddle@google.com> | 2019-10-14 16:21:17 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-10-14 16:21:51 -0700 |
| commit | f29731d17f469722c73e33b6d503be0ab39cf907 (patch) | |
| tree | b72f6fa604a6716f35073856513cb9c66957cbfb /mlir/lib/IR | |
| parent | 96de7091bcac2086fb3be55169ec4e826145c574 (diff) | |
| download | bcm5719-llvm-f29731d17f469722c73e33b6d503be0ab39cf907.tar.gz bcm5719-llvm-f29731d17f469722c73e33b6d503be0ab39cf907.zip | |
NFC: Replace usages of Value::getKind with explicit isa/casts.
It is more idiomatic to use the llvm::cast infrastructure for checking the type of a value.
PiperOrigin-RevId: 274684945
Diffstat (limited to 'mlir/lib/IR')
| -rw-r--r-- | mlir/lib/IR/AsmPrinter.cpp | 42 | ||||
| -rw-r--r-- | mlir/lib/IR/Value.cpp | 10 |
2 files changed, 23 insertions, 29 deletions
diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index 8fcc618cd26..a98b872ec48 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -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; } @@ -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() { diff --git a/mlir/lib/IR/Value.cpp b/mlir/lib/IR/Value.cpp index 4ad1460e90b..4c2ea5ac69c 100644 --- a/mlir/lib/IR/Value.cpp +++ b/mlir/lib/IR/Value.cpp @@ -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(); } //===----------------------------------------------------------------------===// |

