diff options
| author | Feng Liu <fengliuai@google.com> | 2018-10-19 09:07:58 -0700 |
|---|---|---|
| committer | jpienaar <jpienaar@google.com> | 2019-03-29 13:33:41 -0700 |
| commit | 34927e2474bfec5c3f50a9694432816096f2df1c (patch) | |
| tree | 2c52801aa596509193ae422a05c9a33dfcbd7de3 /mlir/lib | |
| parent | 8c7478d10ce588c562992415bcaf21287b7f4686 (diff) | |
| download | bcm5719-llvm-34927e2474bfec5c3f50a9694432816096f2df1c.tar.gz bcm5719-llvm-34927e2474bfec5c3f50a9694432816096f2df1c.zip | |
Rename Operation::getAs to Operation::dyn_cast
Also rename Operation::is to Operation::isa
Introduce Operation::cast
All of these are for consistency with global dyn_cast/cast/isa operators.
PiperOrigin-RevId: 217878786
Diffstat (limited to 'mlir/lib')
| -rw-r--r-- | mlir/lib/Analysis/AffineAnalysis.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/Analysis/LoopAnalysis.cpp | 6 | ||||
| -rw-r--r-- | mlir/lib/Analysis/MLFunctionMatcher.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/IR/AsmPrinter.cpp | 6 | ||||
| -rw-r--r-- | mlir/lib/IR/Operation.cpp | 36 | ||||
| -rw-r--r-- | mlir/lib/IR/Statement.cpp | 12 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Canonicalizer.cpp | 8 | ||||
| -rw-r--r-- | mlir/lib/Transforms/ComposeAffineMaps.cpp | 2 | ||||
| -rw-r--r-- | mlir/lib/Transforms/ConstantFold.cpp | 4 | ||||
| -rw-r--r-- | mlir/lib/Transforms/PipelineDataTransfer.cpp | 16 | ||||
| -rw-r--r-- | mlir/lib/Transforms/Utils.cpp | 14 |
11 files changed, 54 insertions, 56 deletions
diff --git a/mlir/lib/Analysis/AffineAnalysis.cpp b/mlir/lib/Analysis/AffineAnalysis.cpp index ee1641b575e..a16997c08d3 100644 --- a/mlir/lib/Analysis/AffineAnalysis.cpp +++ b/mlir/lib/Analysis/AffineAnalysis.cpp @@ -322,11 +322,11 @@ void mlir::getReachableAffineApplyOps( auto *opStmt = state.value->getDefiningStmt(); // Note: getDefiningStmt will return nullptr if the operand is not an // OperationStmt (i.e. ForStmt), which is a terminator for the search. - if (opStmt == nullptr || !opStmt->is<AffineApplyOp>()) { + if (opStmt == nullptr || !opStmt->isa<AffineApplyOp>()) { worklist.pop_back(); continue; } - if (auto affineApplyOp = opStmt->getAs<AffineApplyOp>()) { + if (auto affineApplyOp = opStmt->dyn_cast<AffineApplyOp>()) { if (state.operandIndex == 0) { // Pre-Visit: Add 'opStmt' to reachable sequence. affineApplyOps.push_back(opStmt); diff --git a/mlir/lib/Analysis/LoopAnalysis.cpp b/mlir/lib/Analysis/LoopAnalysis.cpp index 9e65e7b4d9e..5f1b7f2f826 100644 --- a/mlir/lib/Analysis/LoopAnalysis.cpp +++ b/mlir/lib/Analysis/LoopAnalysis.cpp @@ -145,7 +145,7 @@ static bool isAccessInvariant(MLValue *input, MemRefType *memRefType, assert(affineApplyOps.size() == 1 && "CompositionAffineMapsPass must have " "been run: there should be at most one AffineApplyOp"); - auto composeOp = affineApplyOps[0]->getAs<AffineApplyOp>(); + auto composeOp = affineApplyOps[0]->cast<AffineApplyOp>(); return !AffineValueMap(*composeOp).isFunctionOf(dim, input); } @@ -186,8 +186,8 @@ bool mlir::isVectorizableLoop(const ForStmt &loop) { auto &matches = loadAndStores.match(forStmt); for (auto ls : matches) { auto *op = cast<OperationStmt>(ls.first); - auto load = op->getAs<LoadOp>(); - auto store = op->getAs<StoreOp>(); + auto load = op->dyn_cast<LoadOp>(); + auto store = op->dyn_cast<StoreOp>(); bool contiguous = load ? isContiguousAccess(forStmt, load) : isContiguousAccess(forStmt, store); if (!contiguous) { diff --git a/mlir/lib/Analysis/MLFunctionMatcher.cpp b/mlir/lib/Analysis/MLFunctionMatcher.cpp index 8739edb259d..fdd1b019612 100644 --- a/mlir/lib/Analysis/MLFunctionMatcher.cpp +++ b/mlir/lib/Analysis/MLFunctionMatcher.cpp @@ -250,7 +250,7 @@ MLFunctionMatcher Red(MutableArrayRef<MLFunctionMatcher> children) { FilterFunctionType isLoadOrStore = [](Statement *stmt) { auto *opStmt = dyn_cast<OperationStmt>(stmt); - return opStmt && (opStmt->is<LoadOp>() || opStmt->is<StoreOp>()); + return opStmt && (opStmt->isa<LoadOp>() || opStmt->isa<StoreOp>()); }; MLFunctionMatcher LoadStores() { return MLFunctionMatcher(Statement::Kind::Operation, {}, isLoadOrStore); diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index ada8f1cebd8..e70dcae2936 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -977,16 +977,16 @@ protected: // Give constant integers special names. if (auto *op = value->getDefiningOperation()) { - if (auto intOp = op->getAs<ConstantIntOp>()) { + if (auto intOp = op->dyn_cast<ConstantIntOp>()) { // i1 constants get special names. if (intOp->getType()->isInteger(1)) { specialName << (intOp->getValue() ? "true" : "false"); } else { specialName << 'c' << intOp->getValue() << '_' << *intOp->getType(); } - } else if (auto intOp = op->getAs<ConstantIndexOp>()) { + } else if (auto intOp = op->dyn_cast<ConstantIndexOp>()) { specialName << 'c' << intOp->getValue(); - } else if (auto constant = op->getAs<ConstantOp>()) { + } else if (auto constant = op->dyn_cast<ConstantOp>()) { if (isa<FunctionAttr>(constant->getValue())) specialName << 'f'; else diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp index e7a012a8a58..de7688c4ea3 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -71,64 +71,64 @@ Operation::~Operation() {} /// Return the context this operation is associated with. MLIRContext *Operation::getContext() const { - if (auto *inst = dyn_cast<OperationInst>(this)) + if (auto *inst = llvm::dyn_cast<OperationInst>(this)) return inst->getContext(); - return cast<OperationStmt>(this)->getContext(); + return llvm::cast<OperationStmt>(this)->getContext(); } /// The source location the operation was defined or derived from. Note that /// it is possible for this pointer to be null. Location *Operation::getLoc() const { - if (auto *inst = dyn_cast<OperationInst>(this)) + if (auto *inst = llvm::dyn_cast<OperationInst>(this)) return inst->getLoc(); - return cast<OperationStmt>(this)->getLoc(); + return llvm::cast<OperationStmt>(this)->getLoc(); } /// Return the function this operation is defined in. Function *Operation::getOperationFunction() { - if (auto *inst = dyn_cast<OperationInst>(this)) + if (auto *inst = llvm::dyn_cast<OperationInst>(this)) return inst->getFunction(); - return cast<OperationStmt>(this)->findFunction(); + return llvm::cast<OperationStmt>(this)->findFunction(); } /// Return the number of operands this operation has. unsigned Operation::getNumOperands() const { - if (auto *inst = dyn_cast<OperationInst>(this)) + if (auto *inst = llvm::dyn_cast<OperationInst>(this)) return inst->getNumOperands(); - return cast<OperationStmt>(this)->getNumOperands(); + return llvm::cast<OperationStmt>(this)->getNumOperands(); } SSAValue *Operation::getOperand(unsigned idx) { - if (auto *inst = dyn_cast<OperationInst>(this)) + if (auto *inst = llvm::dyn_cast<OperationInst>(this)) return inst->getOperand(idx); - return cast<OperationStmt>(this)->getOperand(idx); + return llvm::cast<OperationStmt>(this)->getOperand(idx); } void Operation::setOperand(unsigned idx, SSAValue *value) { - if (auto *inst = dyn_cast<OperationInst>(this)) { - inst->setOperand(idx, cast<CFGValue>(value)); + if (auto *inst = llvm::dyn_cast<OperationInst>(this)) { + inst->setOperand(idx, llvm::cast<CFGValue>(value)); } else { - auto *stmt = cast<OperationStmt>(this); - stmt->setOperand(idx, cast<MLValue>(value)); + auto *stmt = llvm::cast<OperationStmt>(this); + stmt->setOperand(idx, llvm::cast<MLValue>(value)); } } /// Return the number of results this operation has. unsigned Operation::getNumResults() const { - if (auto *inst = dyn_cast<OperationInst>(this)) + if (auto *inst = llvm::dyn_cast<OperationInst>(this)) return inst->getNumResults(); - return cast<OperationStmt>(this)->getNumResults(); + return llvm::cast<OperationStmt>(this)->getNumResults(); } /// Return the indicated result. SSAValue *Operation::getResult(unsigned idx) { - if (auto *inst = dyn_cast<OperationInst>(this)) + if (auto *inst = llvm::dyn_cast<OperationInst>(this)) return inst->getResult(idx); - return cast<OperationStmt>(this)->getResult(idx); + return llvm::cast<OperationStmt>(this)->getResult(idx); } /// Return true if there are no users of any results of this operation. diff --git a/mlir/lib/IR/Statement.cpp b/mlir/lib/IR/Statement.cpp index 9dd22852bac..5ca2763640b 100644 --- a/mlir/lib/IR/Statement.cpp +++ b/mlir/lib/IR/Statement.cpp @@ -98,10 +98,10 @@ const MLValue *Statement::getOperand(unsigned idx) const { bool MLValue::isValidDim() const { if (auto *stmt = getDefiningStmt()) { // Top level statement or constant operation is ok. - if (stmt->getParentStmt() == nullptr || stmt->is<ConstantOp>()) + if (stmt->getParentStmt() == nullptr || stmt->isa<ConstantOp>()) return true; // Affine apply operation is ok if all of its operands are ok. - if (auto op = stmt->getAs<AffineApplyOp>()) + if (auto op = stmt->dyn_cast<AffineApplyOp>()) return op->isValidDim(); return false; } @@ -116,10 +116,10 @@ bool MLValue::isValidDim() const { bool MLValue::isValidSymbol() const { if (auto *stmt = getDefiningStmt()) { // Top level statement or constant operation is ok. - if (stmt->getParentStmt() == nullptr || stmt->is<ConstantOp>()) + if (stmt->getParentStmt() == nullptr || stmt->isa<ConstantOp>()) return true; // Affine apply operation is ok if all of its operands are ok. - if (auto op = stmt->getAs<AffineApplyOp>()) + if (auto op = stmt->dyn_cast<AffineApplyOp>()) return op->isValidSymbol(); return false; } @@ -291,7 +291,7 @@ MLIRContext *OperationStmt::getContext() const { return findFunction()->getContext(); } -bool OperationStmt::isReturn() const { return is<ReturnOp>(); } +bool OperationStmt::isReturn() const { return isa<ReturnOp>(); } //===----------------------------------------------------------------------===// // ForStmt @@ -444,7 +444,7 @@ bool ForStmt::constantFoldBound(bool lower) { for (const auto *operand : boundOperands) { Attribute *operandCst = nullptr; if (auto *operandOp = operand->getDefiningOperation()) { - if (auto operandConstantOp = operandOp->getAs<ConstantOp>()) + if (auto operandConstantOp = operandOp->dyn_cast<ConstantOp>()) operandCst = operandConstantOp->getValue(); } operandConstants.push_back(operandCst); diff --git a/mlir/lib/Transforms/Canonicalizer.cpp b/mlir/lib/Transforms/Canonicalizer.cpp index d78572bd49c..eddc57687bc 100644 --- a/mlir/lib/Transforms/Canonicalizer.cpp +++ b/mlir/lib/Transforms/Canonicalizer.cpp @@ -45,8 +45,7 @@ struct SimplifyXMinusX : public Pattern { std::pair<PatternBenefit, std::unique_ptr<PatternState>> match(Operation *op) const override { - // TODO: Rename getAs -> dyn_cast, and add a cast<> method. - auto subi = op->getAs<SubIOp>(); + auto subi = op->dyn_cast<SubIOp>(); assert(subi && "Matcher should have produced this"); if (subi->getOperand(0) == subi->getOperand(1)) @@ -61,8 +60,7 @@ struct SimplifyXMinusX : public Pattern { // compiler error), it is emitted through the normal MLIR diagnostic // hooks and the IR is left in a valid state. virtual void rewrite(Operation *op, FuncBuilder &builder) const override { - // TODO: Rename getAs -> dyn_cast, and add a cast<> method. - auto subi = op->getAs<SubIOp>(); + auto subi = op->dyn_cast<SubIOp>(); assert(subi && "Matcher should have produced this"); auto result = @@ -172,7 +170,7 @@ void Canonicalizer::simplifyFunction(std::vector<Operation *> &worklist, for (auto *operand : op->getOperands()) { Attribute *operandCst = nullptr; if (auto *operandOp = operand->getDefiningOperation()) { - if (auto operandConstantOp = operandOp->getAs<ConstantOp>()) + if (auto operandConstantOp = operandOp->dyn_cast<ConstantOp>()) operandCst = operandConstantOp->getValue(); } operandConstants.push_back(operandCst); diff --git a/mlir/lib/Transforms/ComposeAffineMaps.cpp b/mlir/lib/Transforms/ComposeAffineMaps.cpp index cce5df98348..eb00489c8e6 100644 --- a/mlir/lib/Transforms/ComposeAffineMaps.cpp +++ b/mlir/lib/Transforms/ComposeAffineMaps.cpp @@ -70,7 +70,7 @@ void ComposeAffineMaps::walk(StmtListType::iterator Start, } void ComposeAffineMaps::visitOperationStmt(OperationStmt *opStmt) { - if (auto affineApplyOp = opStmt->getAs<AffineApplyOp>()) { + if (auto affineApplyOp = opStmt->dyn_cast<AffineApplyOp>()) { forwardSubstitute(affineApplyOp); bool allUsesEmpty = true; for (auto *result : affineApplyOp->getOperation()->getResults()) { diff --git a/mlir/lib/Transforms/ConstantFold.cpp b/mlir/lib/Transforms/ConstantFold.cpp index 550609b38eb..2f5ec383f93 100644 --- a/mlir/lib/Transforms/ConstantFold.cpp +++ b/mlir/lib/Transforms/ConstantFold.cpp @@ -53,7 +53,7 @@ bool ConstantFold::foldOperation(Operation *op, // If this operation is already a constant, just remember it for cleanup // later, and don't try to fold it. - if (auto constant = op->getAs<ConstantOp>()) { + if (auto constant = op->dyn_cast<ConstantOp>()) { existingConstants.push_back(constant); return true; } @@ -64,7 +64,7 @@ bool ConstantFold::foldOperation(Operation *op, for (auto *operand : op->getOperands()) { Attribute *operandCst = nullptr; if (auto *operandOp = operand->getDefiningOperation()) { - if (auto operandConstantOp = operandOp->getAs<ConstantOp>()) + if (auto operandConstantOp = operandOp->dyn_cast<ConstantOp>()) operandCst = operandConstantOp->getValue(); } operandConstants.push_back(operandCst); diff --git a/mlir/lib/Transforms/PipelineDataTransfer.cpp b/mlir/lib/Transforms/PipelineDataTransfer.cpp index d6a064988fb..442096dc7fa 100644 --- a/mlir/lib/Transforms/PipelineDataTransfer.cpp +++ b/mlir/lib/Transforms/PipelineDataTransfer.cpp @@ -61,8 +61,8 @@ MLFunctionPass *mlir::createPipelineDataTransferPass() { // Temporary utility: will be replaced when DmaStart/DmaFinish abstract op's are // added. TODO(b/117228571) static unsigned getTagMemRefPos(const OperationStmt &dmaStmt) { - assert(dmaStmt.is<DmaStartOp>() || dmaStmt.is<DmaWaitOp>()); - if (dmaStmt.is<DmaStartOp>()) { + assert(dmaStmt.isa<DmaStartOp>() || dmaStmt.isa<DmaWaitOp>()); + if (dmaStmt.isa<DmaStartOp>()) { // Second to last operand. return dmaStmt.getNumOperands() - 2; } @@ -166,12 +166,12 @@ static void findMatchingStartFinishStmts( if (!opStmt) continue; // Collect DMA finish statements. - if (opStmt->is<DmaWaitOp>()) { + if (opStmt->isa<DmaWaitOp>()) { dmaFinishStmts.push_back(opStmt); continue; } OpPointer<DmaStartOp> dmaStartOp; - if (!(dmaStartOp = opStmt->getAs<DmaStartOp>())) + if (!(dmaStartOp = opStmt->dyn_cast<DmaStartOp>())) continue; // Only DMAs incoming into higher memory spaces. // TODO(bondhugula): outgoing DMAs. @@ -197,8 +197,8 @@ static void findMatchingStartFinishStmts( // For each start statement, we look for a matching finish statement. for (auto *dmaStartStmt : dmaStartStmts) { for (auto *dmaFinishStmt : dmaFinishStmts) { - if (checkTagMatch(dmaStartStmt->getAs<DmaStartOp>(), - dmaFinishStmt->getAs<DmaWaitOp>())) { + if (checkTagMatch(dmaStartStmt->cast<DmaStartOp>(), + dmaFinishStmt->cast<DmaWaitOp>())) { startWaitPairs.push_back({dmaStartStmt, dmaFinishStmt}); break; } @@ -235,7 +235,7 @@ PassResult PipelineDataTransfer::runOnForStmt(ForStmt *forStmt) { for (auto &pair : startWaitPairs) { auto *dmaStartStmt = pair.first; const MLValue *oldMemRef = cast<MLValue>(dmaStartStmt->getOperand( - dmaStartStmt->getAs<DmaStartOp>()->getFasterMemPos())); + dmaStartStmt->cast<DmaStartOp>()->getFasterMemPos())); if (!doubleBuffer(oldMemRef, forStmt)) { // Normally, double buffering should not fail because we already checked // that there are no uses outside. @@ -264,7 +264,7 @@ PassResult PipelineDataTransfer::runOnForStmt(ForStmt *forStmt) { DenseMap<const Statement *, unsigned> stmtDelayMap; for (auto &pair : startWaitPairs) { auto *dmaStartStmt = pair.first; - assert(dmaStartStmt->is<DmaStartOp>()); + assert(dmaStartStmt->isa<DmaStartOp>()); stmtDelayMap[dmaStartStmt] = 0; // Set shifts for DMA start stmt's affine operand computation slices to 0. if (auto *slice = mlir::createAffineComputationSlice(dmaStartStmt)) { diff --git a/mlir/lib/Transforms/Utils.cpp b/mlir/lib/Transforms/Utils.cpp index 5df6e99b592..7ed33331258 100644 --- a/mlir/lib/Transforms/Utils.cpp +++ b/mlir/lib/Transforms/Utils.cpp @@ -35,8 +35,8 @@ using namespace mlir; // Temporary utility: will be replaced when this is modeled through // side-effects/op traits. TODO(b/117228571) static bool isMemRefDereferencingOp(const Operation &op) { - if (op.is<LoadOp>() || op.is<StoreOp>() || op.is<DmaStartOp>() || - op.is<DmaWaitOp>()) + if (op.isa<LoadOp>() || op.isa<StoreOp>() || op.isa<DmaStartOp>() || + op.isa<DmaWaitOp>()) return true; return false; } @@ -175,8 +175,8 @@ mlir::createComposedAffineApplyOp(MLFuncBuilder *builder, Location *loc, AffineValueMap valueMap(map, operands); for (auto *opStmt : affineApplyOps) { - assert(opStmt->is<AffineApplyOp>()); - auto affineApplyOp = opStmt->getAs<AffineApplyOp>(); + assert(opStmt->isa<AffineApplyOp>()); + auto affineApplyOp = opStmt->cast<AffineApplyOp>(); // Forward substitute 'affineApplyOp' into 'valueMap'. valueMap.forwardSubstitute(*affineApplyOp); } @@ -231,7 +231,7 @@ OperationStmt *mlir::createAffineComputationSlice(OperationStmt *opStmt) { subOperands.reserve(opStmt->getNumOperands()); for (auto *operand : opStmt->getOperands()) { auto *defStmt = operand->getDefiningStmt(); - if (defStmt && defStmt->is<AffineApplyOp>()) { + if (defStmt && defStmt->isa<AffineApplyOp>()) { subOperands.push_back(operand); } } @@ -307,7 +307,7 @@ void mlir::forwardSubstitute(OpPointer<AffineApplyOp> affineApplyOp) { auto *useStmt = use.getOwner(); auto *useOpStmt = dyn_cast<OperationStmt>(useStmt); // Skip if use is not AffineApplyOp. - if (useOpStmt == nullptr || !useOpStmt->is<AffineApplyOp>()) + if (useOpStmt == nullptr || !useOpStmt->isa<AffineApplyOp>()) continue; // Advance iterator past 'opStmt' operands which also use 'result'. while (it != result->use_end() && it->getOwner() == useStmt) @@ -315,7 +315,7 @@ void mlir::forwardSubstitute(OpPointer<AffineApplyOp> affineApplyOp) { MLFuncBuilder builder(useOpStmt); // Initialize AffineValueMap with 'affineApplyOp' which uses 'result'. - auto oldAffineApplyOp = useOpStmt->getAs<AffineApplyOp>(); + auto oldAffineApplyOp = useOpStmt->cast<AffineApplyOp>(); AffineValueMap valueMap(*oldAffineApplyOp); // Forward substitute 'result' at index 'i' into 'valueMap'. valueMap.forwardSubstituteSingle(*affineApplyOp, resultIndex); |

