diff options
Diffstat (limited to 'mlir/lib')
-rw-r--r-- | mlir/lib/AffineOps/AffineOps.cpp | 126 | ||||
-rw-r--r-- | mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp | 26 | ||||
-rw-r--r-- | mlir/lib/Dialect/LoopOps/LoopOps.cpp | 2 | ||||
-rw-r--r-- | mlir/lib/Linalg/Utils/Utils.cpp | 4 | ||||
-rw-r--r-- | mlir/lib/Transforms/LoopInvariantCodeMotion.cpp | 8 | ||||
-rw-r--r-- | mlir/lib/Transforms/LowerAffine.cpp | 11 | ||||
-rw-r--r-- | mlir/lib/Transforms/Utils/LoopUtils.cpp | 18 |
7 files changed, 91 insertions, 104 deletions
diff --git a/mlir/lib/AffineOps/AffineOps.cpp b/mlir/lib/AffineOps/AffineOps.cpp index c460d5c..dbc3e93 100644 --- a/mlir/lib/AffineOps/AffineOps.cpp +++ b/mlir/lib/AffineOps/AffineOps.cpp @@ -38,8 +38,8 @@ using llvm::dbgs; AffineOpsDialect::AffineOpsDialect(MLIRContext *context) : Dialect(getDialectNamespace(), context) { - addOperations<AffineApplyOp, AffineDmaStartOp, AffineDmaWaitOp, AffineForOp, - AffineIfOp, AffineLoadOp, AffineStoreOp, + addOperations<AffineApplyOp, AffineDmaStartOp, AffineDmaWaitOp, AffineLoadOp, + AffineStoreOp, #define GET_OP_LIST #include "mlir/AffineOps/AffineOps.cpp.inc" >(); @@ -1030,40 +1030,41 @@ void AffineForOp::build(Builder *builder, OperationState *result, int64_t lb, return build(builder, result, {}, lbMap, {}, ubMap, step); } -LogicalResult AffineForOp::verify() { - auto &bodyRegion = getOperation()->getRegion(0); +static LogicalResult verify(AffineForOp op) { + auto &bodyRegion = op.region(); // The body region must contain a single basic block. if (bodyRegion.empty() || std::next(bodyRegion.begin()) != bodyRegion.end()) - return emitOpError("expected body region to have a single block"); + return op.emitOpError("expected body region to have a single block"); // Check that the body defines as single block argument for the induction // variable. - auto *body = getBody(); + auto *body = op.getBody(); if (body->getNumArguments() != 1 || !body->getArgument(0)->getType().isIndex()) - return emitOpError("expected body to have a single index argument for the " - "induction variable"); + return op.emitOpError( + "expected body to have a single index argument for the " + "induction variable"); - if (failed(checkHasAffineTerminator(*this, *body))) + if (failed(checkHasAffineTerminator(op, *body))) return failure(); // Verify that there are enough operands for the bounds. - AffineMap lowerBoundMap = getLowerBoundMap(), - upperBoundMap = getUpperBoundMap(); - if (getNumOperands() != + AffineMap lowerBoundMap = op.getLowerBoundMap(), + upperBoundMap = op.getUpperBoundMap(); + if (op.getNumOperands() != (lowerBoundMap.getNumInputs() + upperBoundMap.getNumInputs())) - return emitOpError( + return op.emitOpError( "operand count must match with affine map dimension and symbol count"); // Verify that the bound operands are valid dimension/symbols. /// Lower bound. - if (failed(verifyDimAndSymbolIdentifiers(*this, getLowerBoundOperands(), - getLowerBoundMap().getNumDims()))) + if (failed(verifyDimAndSymbolIdentifiers(op, op.getLowerBoundOperands(), + op.getLowerBoundMap().getNumDims()))) return failure(); /// Upper bound. - if (failed(verifyDimAndSymbolIdentifiers(*this, getUpperBoundOperands(), - getUpperBoundMap().getNumDims()))) + if (failed(verifyDimAndSymbolIdentifiers(op, op.getUpperBoundOperands(), + op.getUpperBoundMap().getNumDims()))) return failure(); return success(); } @@ -1160,7 +1161,7 @@ static ParseResult parseBound(bool isLower, OperationState *result, "expected valid affine map representation for loop bounds"); } -ParseResult AffineForOp::parse(OpAsmParser *parser, OperationState *result) { +ParseResult parseAffineForOp(OpAsmParser *parser, OperationState *result) { auto &builder = parser->getBuilder(); OpAsmParser::OperandType inductionVariable; // Parse the induction variable followed by '='. @@ -1176,13 +1177,14 @@ ParseResult AffineForOp::parse(OpAsmParser *parser, OperationState *result) { // Parse the optional loop step, we default to 1 if one is not present. if (parser->parseOptionalKeyword("step")) { result->addAttribute( - getStepAttrName(), + AffineForOp::getStepAttrName(), builder.getIntegerAttr(builder.getIndexType(), /*value=*/1)); } else { llvm::SMLoc stepLoc = parser->getCurrentLocation(); IntegerAttr stepAttr; if (parser->parseAttribute(stepAttr, builder.getIndexType(), - getStepAttrName().data(), result->attributes)) + AffineForOp::getStepAttrName().data(), + result->attributes)) return failure(); if (stepAttr.getValue().getSExtValue() < 0) @@ -1248,23 +1250,23 @@ static void printBound(AffineMapAttr boundMap, map.getNumDims(), p); } -void AffineForOp::print(OpAsmPrinter *p) { +void print(OpAsmPrinter *p, AffineForOp op) { *p << "affine.for "; - p->printOperand(getBody()->getArgument(0)); + p->printOperand(op.getBody()->getArgument(0)); *p << " = "; - printBound(getLowerBoundMapAttr(), getLowerBoundOperands(), "max", p); + printBound(op.getLowerBoundMapAttr(), op.getLowerBoundOperands(), "max", p); *p << " to "; - printBound(getUpperBoundMapAttr(), getUpperBoundOperands(), "min", p); + printBound(op.getUpperBoundMapAttr(), op.getUpperBoundOperands(), "min", p); - if (getStep() != 1) - *p << " step " << getStep(); - p->printRegion(getRegion(), + if (op.getStep() != 1) + *p << " step " << op.getStep(); + p->printRegion(op.region(), /*printEntryBlockArgs=*/false, /*printBlockTerminators=*/false); - p->printOptionalAttrDict(getAttrs(), - /*elidedAttrs=*/{getLowerBoundAttrName(), - getUpperBoundAttrName(), - getStepAttrName()}); + p->printOptionalAttrDict(op.getAttrs(), + /*elidedAttrs=*/{op.getLowerBoundAttrName(), + op.getUpperBoundAttrName(), + op.getStepAttrName()}); } namespace { @@ -1331,11 +1333,6 @@ void AffineForOp::getCanonicalizationPatterns(OwningRewritePatternList &results, results.push_back(llvm::make_unique<AffineForLoopBoundFolder>(context)); } -OpBuilder AffineForOp::getBodyBuilder() { - Block *body = getBody(); - return OpBuilder(body, std::prev(body->end())); -} - AffineBound AffineForOp::getLowerBound() { auto lbMap = getLowerBoundMap(); return AffineBound(AffineForOp(*this), 0, lbMap.getNumInputs(), lbMap); @@ -1438,9 +1435,6 @@ bool AffineForOp::matchingBoundOperandList() { return true; } -/// Returns the induction variable for this loop. -Value *AffineForOp::getInductionVar() { return getBody()->getArgument(0); } - /// Returns if the provided value is the induction variable of a AffineForOp. bool mlir::isForInductionVar(Value *val) { return getForInductionVarOwner(val) != AffineForOp(); @@ -1469,48 +1463,53 @@ void mlir::extractForInductionVars(ArrayRef<AffineForOp> forInsts, // AffineIfOp //===----------------------------------------------------------------------===// -LogicalResult AffineIfOp::verify() { +static LogicalResult verify(AffineIfOp op) { // Verify that we have a condition attribute. - auto conditionAttr = getAttrOfType<IntegerSetAttr>(getConditionAttrName()); + auto conditionAttr = + op.getAttrOfType<IntegerSetAttr>(op.getConditionAttrName()); if (!conditionAttr) - return emitOpError("requires an integer set attribute named 'condition'"); + return op.emitOpError( + "requires an integer set attribute named 'condition'"); // Verify that there are enough operands for the condition. IntegerSet condition = conditionAttr.getValue(); - if (getNumOperands() != condition.getNumOperands()) - return emitOpError("operand count and condition integer set dimension and " - "symbol count must match"); + if (op.getNumOperands() != condition.getNumOperands()) + return op.emitOpError( + "operand count and condition integer set dimension and " + "symbol count must match"); // Verify that the operands are valid dimension/symbols. - if (failed(verifyDimAndSymbolIdentifiers(*this, getOperands(), - condition.getNumDims()))) + if (failed(verifyDimAndSymbolIdentifiers( + op, op.getOperation()->getNonSuccessorOperands(), + condition.getNumDims()))) return failure(); // Verify that the entry of each child region does not have arguments. - for (auto ®ion : getOperation()->getRegions()) { + for (auto ®ion : op.getOperation()->getRegions()) { if (region.empty()) continue; // TODO(riverriddle) We currently do not allow multiple blocks in child // regions. if (std::next(region.begin()) != region.end()) - return emitOpError("expects only one block per 'then' or 'else' regions"); - if (failed(checkHasAffineTerminator(*this, region.front()))) + return op.emitOpError( + "expects only one block per 'then' or 'else' regions"); + if (failed(checkHasAffineTerminator(op, region.front()))) return failure(); for (auto &b : region) if (b.getNumArguments() != 0) - return emitOpError( + return op.emitOpError( "requires that child entry blocks have no arguments"); } return success(); } -ParseResult AffineIfOp::parse(OpAsmParser *parser, OperationState *result) { +ParseResult parseAffineIfOp(OpAsmParser *parser, OperationState *result) { // Parse the condition attribute set. IntegerSetAttr conditionAttr; unsigned numDims; - if (parser->parseAttribute(conditionAttr, getConditionAttrName(), + if (parser->parseAttribute(conditionAttr, AffineIfOp::getConditionAttrName(), result->attributes) || parseDimAndSymbolList(parser, result->operands, numDims)) return failure(); @@ -1551,17 +1550,18 @@ ParseResult AffineIfOp::parse(OpAsmParser *parser, OperationState *result) { return success(); } -void AffineIfOp::print(OpAsmPrinter *p) { - auto conditionAttr = getAttrOfType<IntegerSetAttr>(getConditionAttrName()); +void print(OpAsmPrinter *p, AffineIfOp op) { + auto conditionAttr = + op.getAttrOfType<IntegerSetAttr>(op.getConditionAttrName()); *p << "affine.if " << conditionAttr; - printDimAndSymbolList(operand_begin(), operand_end(), + printDimAndSymbolList(op.operand_begin(), op.operand_end(), conditionAttr.getValue().getNumDims(), p); - p->printRegion(getOperation()->getRegion(0), + p->printRegion(op.thenRegion(), /*printEntryBlockArgs=*/false, /*printBlockTerminators=*/false); // Print the 'else' regions if it has any blocks. - auto &elseRegion = getOperation()->getRegion(1); + auto &elseRegion = op.elseRegion(); if (!elseRegion.empty()) { *p << " else"; p->printRegion(elseRegion, @@ -1570,8 +1570,8 @@ void AffineIfOp::print(OpAsmPrinter *p) { } // Print the attribute list. - p->printOptionalAttrDict(getAttrs(), - /*elidedAttrs=*/getConditionAttrName()); + p->printOptionalAttrDict(op.getAttrs(), + /*elidedAttrs=*/op.getConditionAttrName()); } IntegerSet AffineIfOp::getIntegerSet() { @@ -1581,12 +1581,6 @@ void AffineIfOp::setIntegerSet(IntegerSet newSet) { setAttr(getConditionAttrName(), IntegerSetAttr::get(newSet)); } -/// Returns the list of 'then' blocks. -Region &AffineIfOp::getThenBlocks() { return getOperation()->getRegion(0); } - -/// Returns the list of 'else' blocks. -Region &AffineIfOp::getElseBlocks() { return getOperation()->getRegion(1); } - //===----------------------------------------------------------------------===// // AffineLoadOp //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp b/mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp index ac164ab..9027368 100644 --- a/mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp +++ b/mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp @@ -96,12 +96,6 @@ static Value *getOrEmitUpperBound(ForOp forOp, OpBuilder &) { return forOp.upperBound(); } -// TODO(ntv): uniformize back once AffineForOp is in ODS. -static Region &getRegion(ForOp op) { return op.region(); } -static Region &getRegion(AffineForOp op) { return op.getRegion(); } -static Block *getBody(ForOp op) { return op.body(); } -static Block *getBody(AffineForOp op) { return op.getBody(); } - // Check the structure of the loop nest: // - there are enough loops to map to numBlockDims + numThreadDims; // - the loops are perfectly nested; @@ -127,9 +121,9 @@ LogicalResult checkLoopNestMappable(OpTy forOp, unsigned numBlockDims, } OpTy currentLoop = forOp; - Region &limit = getRegion(forOp); + Region &limit = forOp.region(); for (unsigned i = 0, e = numBlockDims + numThreadDims; i < e; ++i) { - Operation *nested = &getBody(currentLoop)->front(); + Operation *nested = ¤tLoop.getBody()->front(); if (!areValuesDefinedAbove(getLowerBoundOperands(currentLoop), limit) || !areValuesDefinedAbove(getUpperBoundOperands(currentLoop), limit)) return currentLoop.emitError( @@ -141,9 +135,9 @@ LogicalResult checkLoopNestMappable(OpTy forOp, unsigned numBlockDims, if (i == e - 1) break; - auto begin = getBody(currentLoop)->begin(), - end = getBody(currentLoop)->end(); - if (getBody(currentLoop)->empty() || std::next(begin, 2) != end) + auto begin = currentLoop.getBody()->begin(), + end = currentLoop.getBody()->end(); + if (currentLoop.getBody()->empty() || std::next(begin, 2) != end) return currentLoop.emitError( "expected perfectly nested loops in the body"); @@ -216,7 +210,7 @@ Optional<OpTy> LoopToGpuConverter::collectBounds(OpTy forOp, steps.push_back(step); if (i != numLoops - 1) - currentLoop = cast<OpTy>(&getBody(currentLoop)->front()); + currentLoop = cast<OpTy>(¤tLoop.getBody()->front()); } return currentLoop; } @@ -248,7 +242,7 @@ void LoopToGpuConverter::createLaunch(OpTy rootForOp, OpTy innermostForOp, // Still assuming perfect nesting so there are no values other than induction // variables that are defined in one loop and used in deeper loops. llvm::SetVector<Value *> valuesToForwardSet; - getUsedValuesDefinedAbove(getRegion(innermostForOp), getRegion(rootForOp), + getUsedValuesDefinedAbove(innermostForOp.region(), rootForOp.region(), valuesToForwardSet); auto valuesToForward = valuesToForwardSet.takeVector(); auto originallyForwardedValues = valuesToForward.size(); @@ -263,14 +257,14 @@ void LoopToGpuConverter::createLaunch(OpTy rootForOp, OpTy innermostForOp, // gpu return and move the operations from the loop body block to the gpu // launch body block. Do not move the entire block because of the difference // in block arguments. - Operation &terminator = getBody(innermostForOp)->back(); + Operation &terminator = innermostForOp.getBody()->back(); Location terminatorLoc = terminator.getLoc(); terminator.erase(); - builder.setInsertionPointToEnd(getBody(innermostForOp)); + builder.setInsertionPointToEnd(innermostForOp.getBody()); builder.create<gpu::Return>(terminatorLoc); launchOp.getBody().front().getOperations().splice( launchOp.getBody().front().begin(), - getBody(innermostForOp)->getOperations()); + innermostForOp.getBody()->getOperations()); // Remap the loop iterators to use block/thread identifiers instead. Loops // may iterate from LB with step S whereas GPU thread/block ids always iterate diff --git a/mlir/lib/Dialect/LoopOps/LoopOps.cpp b/mlir/lib/Dialect/LoopOps/LoopOps.cpp index f6cfb14..b8ad79a 100644 --- a/mlir/lib/Dialect/LoopOps/LoopOps.cpp +++ b/mlir/lib/Dialect/LoopOps/LoopOps.cpp @@ -81,7 +81,7 @@ LogicalResult verify(ForOp op) { // Check that the body defines as single block argument for the induction // variable. - auto *body = op.body(); + auto *body = op.getBody(); if (body->getNumArguments() != 1 || !body->getArgument(0)->getType().isIndex()) return op.emitOpError("expected body to have a single index argument for " diff --git a/mlir/lib/Linalg/Utils/Utils.cpp b/mlir/lib/Linalg/Utils/Utils.cpp index 3bbfc9b..850aefe 100644 --- a/mlir/lib/Linalg/Utils/Utils.cpp +++ b/mlir/lib/Linalg/Utils/Utils.cpp @@ -52,7 +52,7 @@ mlir::edsc::LoopRangeBuilder::LoopRangeBuilder(ValueHandle *iv, auto step = rangeOp.step(); auto forOp = OperationHandle::createOp<ForOp>(lb, ub, step); *iv = ValueHandle(forOp.getInductionVar()); - auto *body = forOp.body(); + auto *body = forOp.getBody(); enter(body, /*prev=*/1); } @@ -61,7 +61,7 @@ mlir::edsc::LoopRangeBuilder::LoopRangeBuilder(ValueHandle *iv, auto forOp = OperationHandle::createOp<ForOp>(range.min, range.max, range.step); *iv = ValueHandle(forOp.getInductionVar()); - auto *body = forOp.body(); + auto *body = forOp.getBody(); enter(body, /*prev=*/1); } diff --git a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp index 48e97f4..d8b5b2d 100644 --- a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp +++ b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp @@ -186,13 +186,13 @@ bool checkInvarianceOfNestedIfOps(Operation *op, Value *indVar, assert(isa<AffineIfOp>(op)); auto ifOp = cast<AffineIfOp>(op); - if (!areAllOpsInTheBlockListInvariant(ifOp.getThenBlocks(), indVar, - definedOps, opsToHoist)) { + if (!areAllOpsInTheBlockListInvariant(ifOp.thenRegion(), indVar, definedOps, + opsToHoist)) { return false; } - if (!areAllOpsInTheBlockListInvariant(ifOp.getElseBlocks(), indVar, - definedOps, opsToHoist)) { + if (!areAllOpsInTheBlockListInvariant(ifOp.elseRegion(), indVar, definedOps, + opsToHoist)) { return false; } diff --git a/mlir/lib/Transforms/LowerAffine.cpp b/mlir/lib/Transforms/LowerAffine.cpp index 20a9134..f35f963 100644 --- a/mlir/lib/Transforms/LowerAffine.cpp +++ b/mlir/lib/Transforms/LowerAffine.cpp @@ -318,7 +318,7 @@ public: Value *step = rewriter.create<ConstantIndexOp>(loc, op.getStep()); auto f = rewriter.create<loop::ForOp>(loc, lowerBound, upperBound, step); f.region().getBlocks().clear(); - rewriter.inlineRegionBefore(op.getRegion(), f.region(), f.region().end()); + rewriter.inlineRegionBefore(op.region(), f.region(), f.region().end()); rewriter.replaceOp(op, {}); return matchSuccess(); } @@ -335,7 +335,7 @@ public: // Now we just have to handle the condition logic. auto integerSet = op.getIntegerSet(); Value *zeroConstant = rewriter.create<ConstantIndexOp>(loc, 0); - SmallVector<Value *, 8> operands(op.getOperands()); + SmallVector<Value *, 8> operands(op.getOperation()->getOperands()); auto operandsRef = llvm::makeArrayRef(operands); // Calculate cond as a conjunction without short-circuiting. @@ -360,13 +360,12 @@ public: cond = cond ? cond : rewriter.create<ConstantIntOp>(loc, /*value=*/1, /*width=*/1); - bool hasElseRegion = !op.getElseBlocks().empty(); + bool hasElseRegion = !op.elseRegion().empty(); auto ifOp = rewriter.create<loop::IfOp>(loc, cond, hasElseRegion); - rewriter.inlineRegionBefore(op.getThenBlocks(), &ifOp.thenRegion().back()); + rewriter.inlineRegionBefore(op.thenRegion(), &ifOp.thenRegion().back()); ifOp.thenRegion().back().erase(); if (hasElseRegion) { - rewriter.inlineRegionBefore(op.getElseBlocks(), - &ifOp.elseRegion().back()); + rewriter.inlineRegionBefore(op.elseRegion(), &ifOp.elseRegion().back()); ifOp.elseRegion().back().erase(); } diff --git a/mlir/lib/Transforms/Utils/LoopUtils.cpp b/mlir/lib/Transforms/Utils/LoopUtils.cpp index d77f9bf..242538d 100644 --- a/mlir/lib/Transforms/Utils/LoopUtils.cpp +++ b/mlir/lib/Transforms/Utils/LoopUtils.cpp @@ -825,22 +825,22 @@ static void tile(MutableArrayRef<loop::ForOp> forOps, ArrayRef<Value *> sizes) { auto outerForOp = builder.create<loop::ForOp>(forOps[i].getLoc(), forOps[i].lowerBound(), forOps[i].upperBound(), newSteps[i]); - builder.setInsertionPointToStart(outerForOp.body()); + builder.setInsertionPointToStart(outerForOp.getBody()); outerForOps.push_back(outerForOp); } // Move the outermost original loop into the innermost new outer loop. Thus // the body of the original loops does not need updating. auto lastOuterForOp = outerForOps.back(); - lastOuterForOp.body()->getOperations().splice( - lastOuterForOp.body()->getOperations().begin(), + lastOuterForOp.getBody()->getOperations().splice( + lastOuterForOp.getBody()->getOperations().begin(), rootForOp.getOperation()->getBlock()->getOperations(), rootForOp.getOperation()); // Immediately before the (now sunk) outermost original loop, insert the // computation of the upper bounds of the inner loops. Update the bounds of // the orginial loops to make them point loops. - builder.setInsertionPointToStart(lastOuterForOp.body()); + builder.setInsertionPointToStart(lastOuterForOp.getBody()); for (unsigned i = 0, e = sizes.size(); i < e; ++i) { Value *stepped = builder.create<AddIOp>( forOps[i].getLoc(), outerForOps[i].getInductionVar(), newSteps[i]); @@ -992,7 +992,7 @@ static void normalizeLoop(loop::ForOp loop, loop::ForOp outer, // Insert code computing the value of the original loop induction variable // from the "normalized" one. - builder.setInsertionPointToStart(inner.body()); + builder.setInsertionPointToStart(inner.getBody()); Value *scaled = isStepOne ? loop.getInductionVar() : builder.create<MulIOp>(loc, loop.getInductionVar(), step); @@ -1025,7 +1025,7 @@ void mlir::coalesceLoops(MutableArrayRef<loop::ForOp> loops) { upperBound = builder.create<MulIOp>(loc, upperBound, loop.upperBound()); outermost.setUpperBound(upperBound); - builder.setInsertionPointToStart(outermost.body()); + builder.setInsertionPointToStart(outermost.getBody()); // 3. Remap induction variables. For each original loop, the value of the // induction variable can be obtained by dividing the induction variable of @@ -1052,9 +1052,9 @@ void mlir::coalesceLoops(MutableArrayRef<loop::ForOp> loops) { // 4. Move the operations from the innermost just above the second-outermost // loop, delete the extra terminator and the second-outermost loop. loop::ForOp second = loops[1]; - innermost.body()->back().erase(); - outermost.body()->getOperations().splice( + innermost.getBody()->back().erase(); + outermost.getBody()->getOperations().splice( Block::iterator(second.getOperation()), - innermost.body()->getOperations()); + innermost.getBody()->getOperations()); second.erase(); } |