-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[mlir][NFC] update Conversion
create APIs (7/n)
#149889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir][NFC] update Conversion
create APIs (7/n)
#149889
Conversation
See llvm#147168 for more info.
@llvm/pr-subscribers-mlir-tosa @llvm/pr-subscribers-flang-openmp Author: Maksim Levental (makslevental) ChangesSee #147168 for more info. Patch is 358.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149889.diff 23 Files Affected:
diff --git a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
index 0df91a243d07a..240491a51d2b9 100644
--- a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
+++ b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
@@ -340,7 +340,7 @@ LogicalResult ForLowering::matchAndRewrite(ForOp forOp,
Operation *terminator = lastBodyBlock->getTerminator();
rewriter.setInsertionPointToEnd(lastBodyBlock);
auto step = forOp.getStep();
- auto stepped = rewriter.create<arith::AddIOp>(loc, iv, step).getResult();
+ auto stepped = arith::AddIOp::create(rewriter, loc, iv, step).getResult();
if (!stepped)
return failure();
@@ -348,7 +348,7 @@ LogicalResult ForLowering::matchAndRewrite(ForOp forOp,
loopCarried.push_back(stepped);
loopCarried.append(terminator->operand_begin(), terminator->operand_end());
auto branchOp =
- rewriter.create<cf::BranchOp>(loc, conditionBlock, loopCarried);
+ cf::BranchOp::create(rewriter, loc, conditionBlock, loopCarried);
// Let the CondBranchOp carry the LLVM attributes from the ForOp, such as the
// llvm.loop_annotation attribute.
@@ -375,16 +375,15 @@ LogicalResult ForLowering::matchAndRewrite(ForOp forOp,
SmallVector<Value, 8> destOperands;
destOperands.push_back(lowerBound);
llvm::append_range(destOperands, forOp.getInitArgs());
- rewriter.create<cf::BranchOp>(loc, conditionBlock, destOperands);
+ cf::BranchOp::create(rewriter, loc, conditionBlock, destOperands);
// With the body block done, we can fill in the condition block.
rewriter.setInsertionPointToEnd(conditionBlock);
- auto comparison = rewriter.create<arith::CmpIOp>(
- loc, arith::CmpIPredicate::slt, iv, upperBound);
+ auto comparison = arith::CmpIOp::create(
+ rewriter, loc, arith::CmpIPredicate::slt, iv, upperBound);
- rewriter.create<cf::CondBranchOp>(loc, comparison, firstBodyBlock,
- ArrayRef<Value>(), endBlock,
- ArrayRef<Value>());
+ cf::CondBranchOp::create(rewriter, loc, comparison, firstBodyBlock,
+ ArrayRef<Value>(), endBlock, ArrayRef<Value>());
// The result of the loop operation is the values of the condition block
// arguments except the induction variable on the last iteration.
@@ -409,7 +408,7 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
continueBlock =
rewriter.createBlock(remainingOpsBlock, ifOp.getResultTypes(),
SmallVector<Location>(ifOp.getNumResults(), loc));
- rewriter.create<cf::BranchOp>(loc, remainingOpsBlock);
+ cf::BranchOp::create(rewriter, loc, remainingOpsBlock);
}
// Move blocks from the "then" region to the region containing 'scf.if',
@@ -419,7 +418,7 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
Operation *thenTerminator = thenRegion.back().getTerminator();
ValueRange thenTerminatorOperands = thenTerminator->getOperands();
rewriter.setInsertionPointToEnd(&thenRegion.back());
- rewriter.create<cf::BranchOp>(loc, continueBlock, thenTerminatorOperands);
+ cf::BranchOp::create(rewriter, loc, continueBlock, thenTerminatorOperands);
rewriter.eraseOp(thenTerminator);
rewriter.inlineRegionBefore(thenRegion, continueBlock);
@@ -433,15 +432,15 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
Operation *elseTerminator = elseRegion.back().getTerminator();
ValueRange elseTerminatorOperands = elseTerminator->getOperands();
rewriter.setInsertionPointToEnd(&elseRegion.back());
- rewriter.create<cf::BranchOp>(loc, continueBlock, elseTerminatorOperands);
+ cf::BranchOp::create(rewriter, loc, continueBlock, elseTerminatorOperands);
rewriter.eraseOp(elseTerminator);
rewriter.inlineRegionBefore(elseRegion, continueBlock);
}
rewriter.setInsertionPointToEnd(condBlock);
- rewriter.create<cf::CondBranchOp>(loc, ifOp.getCondition(), thenBlock,
- /*trueArgs=*/ArrayRef<Value>(), elseBlock,
- /*falseArgs=*/ArrayRef<Value>());
+ cf::CondBranchOp::create(rewriter, loc, ifOp.getCondition(), thenBlock,
+ /*trueArgs=*/ArrayRef<Value>(), elseBlock,
+ /*falseArgs=*/ArrayRef<Value>());
// Ok, we're done!
rewriter.replaceOp(ifOp, continueBlock->getArguments());
@@ -459,13 +458,14 @@ ExecuteRegionLowering::matchAndRewrite(ExecuteRegionOp op,
auto ®ion = op.getRegion();
rewriter.setInsertionPointToEnd(condBlock);
- rewriter.create<cf::BranchOp>(loc, ®ion.front());
+ cf::BranchOp::create(rewriter, loc, ®ion.front());
for (Block &block : region) {
if (auto terminator = dyn_cast<scf::YieldOp>(block.getTerminator())) {
ValueRange terminatorOperands = terminator->getOperands();
rewriter.setInsertionPointToEnd(&block);
- rewriter.create<cf::BranchOp>(loc, remainingOpsBlock, terminatorOperands);
+ cf::BranchOp::create(rewriter, loc, remainingOpsBlock,
+ terminatorOperands);
rewriter.eraseOp(terminator);
}
}
@@ -503,7 +503,7 @@ ParallelLowering::matchAndRewrite(ParallelOp parallelOp,
for (auto [iv, lower, upper, step] :
llvm::zip(parallelOp.getInductionVars(), parallelOp.getLowerBound(),
parallelOp.getUpperBound(), parallelOp.getStep())) {
- ForOp forOp = rewriter.create<ForOp>(loc, lower, upper, step, iterArgs);
+ ForOp forOp = ForOp::create(rewriter, loc, lower, upper, step, iterArgs);
ivs.push_back(forOp.getInductionVar());
auto iterRange = forOp.getRegionIterArgs();
iterArgs.assign(iterRange.begin(), iterRange.end());
@@ -517,7 +517,7 @@ ParallelLowering::matchAndRewrite(ParallelOp parallelOp,
// A loop is constructed with an empty "yield" terminator if there are
// no results.
rewriter.setInsertionPointToEnd(rewriter.getInsertionBlock());
- rewriter.create<scf::YieldOp>(loc, forOp.getResults());
+ scf::YieldOp::create(rewriter, loc, forOp.getResults());
}
rewriter.setInsertionPointToStart(forOp.getBody());
@@ -549,7 +549,7 @@ ParallelLowering::matchAndRewrite(ParallelOp parallelOp,
// has been already created in loop construction).
if (!yieldOperands.empty()) {
rewriter.setInsertionPointToEnd(rewriter.getInsertionBlock());
- rewriter.create<scf::YieldOp>(loc, yieldOperands);
+ scf::YieldOp::create(rewriter, loc, yieldOperands);
}
rewriter.replaceOp(parallelOp, loopResults);
@@ -575,7 +575,7 @@ LogicalResult WhileLowering::matchAndRewrite(WhileOp whileOp,
// Branch to the "before" region.
rewriter.setInsertionPointToEnd(currentBlock);
- rewriter.create<cf::BranchOp>(loc, before, whileOp.getInits());
+ cf::BranchOp::create(rewriter, loc, before, whileOp.getInits());
// Replace terminators with branches. Assuming bodies are SESE, which holds
// given only the patterns from this file, we only need to look at the last
@@ -625,14 +625,14 @@ DoWhileLowering::matchAndRewrite(WhileOp whileOp,
// Branch to the "before" region.
rewriter.setInsertionPointToEnd(currentBlock);
- rewriter.create<cf::BranchOp>(whileOp.getLoc(), before, whileOp.getInits());
+ cf::BranchOp::create(rewriter, whileOp.getLoc(), before, whileOp.getInits());
// Loop around the "before" region based on condition.
rewriter.setInsertionPointToEnd(before);
auto condOp = cast<ConditionOp>(before->getTerminator());
- rewriter.create<cf::CondBranchOp>(condOp.getLoc(), condOp.getCondition(),
- before, condOp.getArgs(), continuation,
- ValueRange());
+ cf::CondBranchOp::create(rewriter, condOp.getLoc(), condOp.getCondition(),
+ before, condOp.getArgs(), continuation,
+ ValueRange());
// Replace the op with values "yielded" from the "before" region, which are
// visible by dominance.
@@ -695,12 +695,12 @@ IndexSwitchLowering::matchAndRewrite(IndexSwitchOp op,
SmallVector<ValueRange> caseOperands(caseSuccessors.size(), {});
// Cast switch index to integer case value.
- Value caseValue = rewriter.create<arith::IndexCastOp>(
- op.getLoc(), rewriter.getI32Type(), op.getArg());
+ Value caseValue = arith::IndexCastOp::create(
+ rewriter, op.getLoc(), rewriter.getI32Type(), op.getArg());
- rewriter.create<cf::SwitchOp>(
- op.getLoc(), caseValue, *defaultBlock, ValueRange(),
- rewriter.getDenseI32ArrayAttr(caseValues), caseSuccessors, caseOperands);
+ cf::SwitchOp::create(rewriter, op.getLoc(), caseValue, *defaultBlock,
+ ValueRange(), rewriter.getDenseI32ArrayAttr(caseValues),
+ caseSuccessors, caseOperands);
rewriter.replaceOp(op, continueBlock->getArguments());
return success();
}
diff --git a/mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp b/mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp
index dcb48529a74e6..84cbd869c78ef 100644
--- a/mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp
+++ b/mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp
@@ -91,7 +91,7 @@ createVariablesForResults(T op, const TypeConverter *typeConverter,
Type varType = emitc::LValueType::get(resultType);
emitc::OpaqueAttr noInit = emitc::OpaqueAttr::get(context, "");
emitc::VariableOp var =
- rewriter.create<emitc::VariableOp>(loc, varType, noInit);
+ emitc::VariableOp::create(rewriter, loc, varType, noInit);
resultVariables.push_back(var);
}
@@ -103,14 +103,14 @@ createVariablesForResults(T op, const TypeConverter *typeConverter,
static void assignValues(ValueRange values, ValueRange variables,
ConversionPatternRewriter &rewriter, Location loc) {
for (auto [value, var] : llvm::zip(values, variables))
- rewriter.create<emitc::AssignOp>(loc, var, value);
+ emitc::AssignOp::create(rewriter, loc, var, value);
}
SmallVector<Value> loadValues(const SmallVector<Value> &variables,
PatternRewriter &rewriter, Location loc) {
return llvm::map_to_vector<>(variables, [&](Value var) {
Type type = cast<emitc::LValueType>(var.getType()).getValueType();
- return rewriter.create<emitc::LoadOp>(loc, type, var).getResult();
+ return emitc::LoadOp::create(rewriter, loc, type, var).getResult();
});
}
@@ -129,7 +129,7 @@ static LogicalResult lowerYield(Operation *op, ValueRange resultVariables,
assignValues(yieldOperands, resultVariables, rewriter, loc);
- rewriter.create<emitc::YieldOp>(loc);
+ emitc::YieldOp::create(rewriter, loc);
rewriter.eraseOp(yield);
return success();
@@ -164,8 +164,9 @@ ForLowering::matchAndRewrite(ForOp forOp, OpAdaptor adaptor,
assignValues(adaptor.getInitArgs(), resultVariables, rewriter, loc);
- emitc::ForOp loweredFor = rewriter.create<emitc::ForOp>(
- loc, adaptor.getLowerBound(), adaptor.getUpperBound(), adaptor.getStep());
+ emitc::ForOp loweredFor =
+ emitc::ForOp::create(rewriter, loc, adaptor.getLowerBound(),
+ adaptor.getUpperBound(), adaptor.getStep());
Block *loweredBody = loweredFor.getBody();
@@ -257,7 +258,7 @@ IfLowering::matchAndRewrite(IfOp ifOp, OpAdaptor adaptor,
bool hasElseBlock = !elseRegion.empty();
auto loweredIf =
- rewriter.create<emitc::IfOp>(loc, adaptor.getCondition(), false, false);
+ emitc::IfOp::create(rewriter, loc, adaptor.getCondition(), false, false);
Region &loweredThenRegion = loweredIf.getThenRegion();
auto result = lowerRegion(thenRegion, loweredThenRegion);
@@ -304,8 +305,9 @@ LogicalResult IndexSwitchOpLowering::matchAndRewrite(
"create variables for results failed");
}
- auto loweredSwitch = rewriter.create<emitc::SwitchOp>(
- loc, adaptor.getArg(), adaptor.getCases(), indexSwitchOp.getNumCases());
+ auto loweredSwitch =
+ emitc::SwitchOp::create(rewriter, loc, adaptor.getArg(),
+ adaptor.getCases(), indexSwitchOp.getNumCases());
// Lowering all case regions.
for (auto pair :
diff --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
index 844e66e927c4d..f191f3502cf5a 100644
--- a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
+++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
@@ -84,8 +84,8 @@ static Operation::operand_range getUpperBoundOperands(AffineForOp forOp) {
// Get a Value that corresponds to the loop step. If the step is an attribute,
// materialize a corresponding constant using builder.
static Value getOrCreateStep(AffineForOp forOp, OpBuilder &builder) {
- return builder.create<arith::ConstantIndexOp>(forOp.getLoc(),
- forOp.getStepAsInt());
+ return arith::ConstantIndexOp::create(builder, forOp.getLoc(),
+ forOp.getStepAsInt());
}
// Get a Value for the loop lower bound. If the value requires computation,
@@ -190,12 +190,12 @@ AffineLoopToGpuConverter::collectBounds(AffineForOp forOp, unsigned numLoops) {
return std::nullopt;
}
- Value range = builder.create<arith::SubIOp>(currentLoop.getLoc(),
- upperBound, lowerBound);
+ Value range = arith::SubIOp::create(builder, currentLoop.getLoc(),
+ upperBound, lowerBound);
Value step = getOrCreateStep(currentLoop, builder);
if (getConstantIntValue(step) != static_cast<int64_t>(1))
- range =
- builder.create<arith::CeilDivSIOp>(currentLoop.getLoc(), range, step);
+ range = arith::CeilDivSIOp::create(builder, currentLoop.getLoc(), range,
+ step);
dims.push_back(range);
lbs.push_back(lowerBound);
@@ -221,7 +221,7 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
// no loop mapped to a specific dimension, use constant "1" as its size.
Value constOne =
(numBlockDims < 3 || numThreadDims < 3)
- ? builder.create<arith::ConstantIndexOp>(rootForOp.getLoc(), 1)
+ ? arith::ConstantIndexOp::create(builder, rootForOp.getLoc(), 1)
: nullptr;
Value gridSizeX = numBlockDims > 0 ? dims[0] : constOne;
Value gridSizeY = numBlockDims > 1 ? dims[1] : constOne;
@@ -232,9 +232,9 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
// Create a launch op and move the body region of the innermost loop to the
// launch op.
- auto launchOp = builder.create<gpu::LaunchOp>(
- rootForOp.getLoc(), gridSizeX, gridSizeY, gridSizeZ, blockSizeX,
- blockSizeY, blockSizeZ);
+ auto launchOp =
+ gpu::LaunchOp::create(builder, rootForOp.getLoc(), gridSizeX, gridSizeY,
+ gridSizeZ, blockSizeX, blockSizeY, blockSizeZ);
// Replace the loop terminator (loops contain only a single block) with the
// gpu terminator and move the operations from the loop body block to the gpu
@@ -244,7 +244,7 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
Location terminatorLoc = terminator.getLoc();
terminator.erase();
builder.setInsertionPointToEnd(innermostForOp.getBody());
- builder.create<gpu::TerminatorOp>(terminatorLoc, TypeRange());
+ gpu::TerminatorOp::create(builder, terminatorLoc, TypeRange());
launchOp.getBody().front().getOperations().splice(
launchOp.getBody().front().begin(),
innermostForOp.getBody()->getOperations());
@@ -263,10 +263,10 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
: getDim3Value(launchOp.getThreadIds(), en.index() - numBlockDims);
Value step = steps[en.index()];
if (getConstantIntValue(step) != static_cast<int64_t>(1))
- id = builder.create<arith::MulIOp>(rootForOp.getLoc(), step, id);
+ id = arith::MulIOp::create(builder, rootForOp.getLoc(), step, id);
Value ivReplacement =
- builder.create<arith::AddIOp>(rootForOp.getLoc(), *lbArgumentIt, id);
+ arith::AddIOp::create(builder, rootForOp.getLoc(), *lbArgumentIt, id);
en.value().replaceAllUsesWith(ivReplacement);
std::advance(lbArgumentIt, 1);
std::advance(stepArgumentIt, 1);
@@ -319,8 +319,8 @@ static Value deriveStaticUpperBound(Value upperBound,
if (auto minOp = upperBound.getDefiningOp<AffineMinOp>()) {
for (const AffineExpr &result : minOp.getMap().getResults()) {
if (auto constExpr = dyn_cast<AffineConstantExpr>(result)) {
- return rewriter.create<arith::ConstantIndexOp>(minOp.getLoc(),
- constExpr.getValue());
+ return arith::ConstantIndexOp::create(rewriter, minOp.getLoc(),
+ constExpr.getValue());
}
}
}
@@ -344,8 +344,8 @@ static Value deriveStaticUpperBound(Value upperBound,
if ((lhs.value() < 0) != (rhs.value() < 0))
return {};
- return rewriter.create<arith::ConstantIndexOp>(
- multiplyOp.getLoc(), lhs.value() * rhs.value());
+ return arith::ConstantIndexOp::create(rewriter, multiplyOp.getLoc(),
+ lhs.value() * rhs.value());
}
}
@@ -422,8 +422,8 @@ static LogicalResult processParallelLoop(
if (launchIndependent(val))
return val;
if (auto constOp = val.getDefiningOp<arith::ConstantOp>())
- return rewriter.create<arith::ConstantOp>(constOp.getLoc(),
- constOp.getValue());
+ return arith::ConstantOp::create(rewriter, constOp.getLoc(),
+ constOp.getValue());
return {};
};
@@ -453,8 +453,8 @@ static LogicalResult processParallelLoop(
1, 2,
rewriter.getAffineDimExpr(0) * rewriter.getAffineSymbolExpr(0) +
rewriter.getAffineSymbolExpr(1));
- newIndex = rewriter.create<AffineApplyOp>(
- loc, annotation.getMap().compose(lowerAndStep),
+ newIndex = AffineApplyOp::create(
+ rewriter, loc, annotation.getMap().compose(lowerAndStep),
ValueRange{operand, ensureLaunchIndependent(step),
ensureLaunchIndependent(lowerBound)});
// If there was also a bound, insert that, too.
@@ -498,8 +498,8 @@ static LogicalResult processParallelLoop(
1, 2,
((rewriter.getAffineDimExpr(0) - rewriter.getAffineSymbolExpr(0))
.ceilDiv(rewriter.getAffineSymbolExpr(1))));
- Value launchBound = rewriter.create<AffineApplyOp>(
- loc, annotation.getBound().compose(stepMap),
+ Value launchBound = AffineApplyOp::create(
+ rewriter, loc, annotation.getBound().compose(stepMap),
ValueRange{
ensureLaunchIndependent(
cloningMap.lookupOrDefault(upperBound)),
@@ -517,10 +517,10 @@ static LogicalResult processParallelLoop(
if (!boundIsPrecise) {
// We are using an approximation, create a surrounding conditional.
Value originalBound = std::get<3>(config);
- arith::CmpIOp pred = rewriter.create<arith::CmpIOp>(
- loc, arith::CmpIPredicate::slt, newIndex,
+ arith::CmpIOp pred = arith::CmpIOp::create(
+ rewriter, loc, arith::CmpIPredicate::slt, newIndex,
cloningMap.lookupOrDefault(originalBound));
- scf::IfOp ifOp = rewriter.create<scf::IfOp>(loc, pred, false);
+ scf::IfOp ifOp = scf::IfOp::create(rewriter, loc, pred, false);
rewriter.setInsertionPointToStart(&ifOp.getThenRegion().front());
// Put a sentinel into the worklist so we know when to pop out of the
// if body again. We use the launchOp here, as that cannot be part of
@@ -530,10 +530,10 @@ static LogicalResult processParallelLoop(
}
} else {
// Create a sequential for loop.
- auto loopOp = rewriter.create<scf::ForOp>(
- loc, cloningMap.lookupOrDefault(lowerBound),
- cloningMap.lookupOrDefault(upperBound),
- cloningMap.lookupOrDefault(step));
+ auto loopOp = scf::ForOp::create(rewriter, loc,
+ cloningMap.lookupOrDefault(lowerBound),
+...
[truncated]
|
@llvm/pr-subscribers-mlir-spirv Author: Maksim Levental (makslevental) ChangesSee #147168 for more info. Patch is 358.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149889.diff 23 Files Affected:
diff --git a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
index 0df91a243d07a..240491a51d2b9 100644
--- a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
+++ b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
@@ -340,7 +340,7 @@ LogicalResult ForLowering::matchAndRewrite(ForOp forOp,
Operation *terminator = lastBodyBlock->getTerminator();
rewriter.setInsertionPointToEnd(lastBodyBlock);
auto step = forOp.getStep();
- auto stepped = rewriter.create<arith::AddIOp>(loc, iv, step).getResult();
+ auto stepped = arith::AddIOp::create(rewriter, loc, iv, step).getResult();
if (!stepped)
return failure();
@@ -348,7 +348,7 @@ LogicalResult ForLowering::matchAndRewrite(ForOp forOp,
loopCarried.push_back(stepped);
loopCarried.append(terminator->operand_begin(), terminator->operand_end());
auto branchOp =
- rewriter.create<cf::BranchOp>(loc, conditionBlock, loopCarried);
+ cf::BranchOp::create(rewriter, loc, conditionBlock, loopCarried);
// Let the CondBranchOp carry the LLVM attributes from the ForOp, such as the
// llvm.loop_annotation attribute.
@@ -375,16 +375,15 @@ LogicalResult ForLowering::matchAndRewrite(ForOp forOp,
SmallVector<Value, 8> destOperands;
destOperands.push_back(lowerBound);
llvm::append_range(destOperands, forOp.getInitArgs());
- rewriter.create<cf::BranchOp>(loc, conditionBlock, destOperands);
+ cf::BranchOp::create(rewriter, loc, conditionBlock, destOperands);
// With the body block done, we can fill in the condition block.
rewriter.setInsertionPointToEnd(conditionBlock);
- auto comparison = rewriter.create<arith::CmpIOp>(
- loc, arith::CmpIPredicate::slt, iv, upperBound);
+ auto comparison = arith::CmpIOp::create(
+ rewriter, loc, arith::CmpIPredicate::slt, iv, upperBound);
- rewriter.create<cf::CondBranchOp>(loc, comparison, firstBodyBlock,
- ArrayRef<Value>(), endBlock,
- ArrayRef<Value>());
+ cf::CondBranchOp::create(rewriter, loc, comparison, firstBodyBlock,
+ ArrayRef<Value>(), endBlock, ArrayRef<Value>());
// The result of the loop operation is the values of the condition block
// arguments except the induction variable on the last iteration.
@@ -409,7 +408,7 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
continueBlock =
rewriter.createBlock(remainingOpsBlock, ifOp.getResultTypes(),
SmallVector<Location>(ifOp.getNumResults(), loc));
- rewriter.create<cf::BranchOp>(loc, remainingOpsBlock);
+ cf::BranchOp::create(rewriter, loc, remainingOpsBlock);
}
// Move blocks from the "then" region to the region containing 'scf.if',
@@ -419,7 +418,7 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
Operation *thenTerminator = thenRegion.back().getTerminator();
ValueRange thenTerminatorOperands = thenTerminator->getOperands();
rewriter.setInsertionPointToEnd(&thenRegion.back());
- rewriter.create<cf::BranchOp>(loc, continueBlock, thenTerminatorOperands);
+ cf::BranchOp::create(rewriter, loc, continueBlock, thenTerminatorOperands);
rewriter.eraseOp(thenTerminator);
rewriter.inlineRegionBefore(thenRegion, continueBlock);
@@ -433,15 +432,15 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
Operation *elseTerminator = elseRegion.back().getTerminator();
ValueRange elseTerminatorOperands = elseTerminator->getOperands();
rewriter.setInsertionPointToEnd(&elseRegion.back());
- rewriter.create<cf::BranchOp>(loc, continueBlock, elseTerminatorOperands);
+ cf::BranchOp::create(rewriter, loc, continueBlock, elseTerminatorOperands);
rewriter.eraseOp(elseTerminator);
rewriter.inlineRegionBefore(elseRegion, continueBlock);
}
rewriter.setInsertionPointToEnd(condBlock);
- rewriter.create<cf::CondBranchOp>(loc, ifOp.getCondition(), thenBlock,
- /*trueArgs=*/ArrayRef<Value>(), elseBlock,
- /*falseArgs=*/ArrayRef<Value>());
+ cf::CondBranchOp::create(rewriter, loc, ifOp.getCondition(), thenBlock,
+ /*trueArgs=*/ArrayRef<Value>(), elseBlock,
+ /*falseArgs=*/ArrayRef<Value>());
// Ok, we're done!
rewriter.replaceOp(ifOp, continueBlock->getArguments());
@@ -459,13 +458,14 @@ ExecuteRegionLowering::matchAndRewrite(ExecuteRegionOp op,
auto ®ion = op.getRegion();
rewriter.setInsertionPointToEnd(condBlock);
- rewriter.create<cf::BranchOp>(loc, ®ion.front());
+ cf::BranchOp::create(rewriter, loc, ®ion.front());
for (Block &block : region) {
if (auto terminator = dyn_cast<scf::YieldOp>(block.getTerminator())) {
ValueRange terminatorOperands = terminator->getOperands();
rewriter.setInsertionPointToEnd(&block);
- rewriter.create<cf::BranchOp>(loc, remainingOpsBlock, terminatorOperands);
+ cf::BranchOp::create(rewriter, loc, remainingOpsBlock,
+ terminatorOperands);
rewriter.eraseOp(terminator);
}
}
@@ -503,7 +503,7 @@ ParallelLowering::matchAndRewrite(ParallelOp parallelOp,
for (auto [iv, lower, upper, step] :
llvm::zip(parallelOp.getInductionVars(), parallelOp.getLowerBound(),
parallelOp.getUpperBound(), parallelOp.getStep())) {
- ForOp forOp = rewriter.create<ForOp>(loc, lower, upper, step, iterArgs);
+ ForOp forOp = ForOp::create(rewriter, loc, lower, upper, step, iterArgs);
ivs.push_back(forOp.getInductionVar());
auto iterRange = forOp.getRegionIterArgs();
iterArgs.assign(iterRange.begin(), iterRange.end());
@@ -517,7 +517,7 @@ ParallelLowering::matchAndRewrite(ParallelOp parallelOp,
// A loop is constructed with an empty "yield" terminator if there are
// no results.
rewriter.setInsertionPointToEnd(rewriter.getInsertionBlock());
- rewriter.create<scf::YieldOp>(loc, forOp.getResults());
+ scf::YieldOp::create(rewriter, loc, forOp.getResults());
}
rewriter.setInsertionPointToStart(forOp.getBody());
@@ -549,7 +549,7 @@ ParallelLowering::matchAndRewrite(ParallelOp parallelOp,
// has been already created in loop construction).
if (!yieldOperands.empty()) {
rewriter.setInsertionPointToEnd(rewriter.getInsertionBlock());
- rewriter.create<scf::YieldOp>(loc, yieldOperands);
+ scf::YieldOp::create(rewriter, loc, yieldOperands);
}
rewriter.replaceOp(parallelOp, loopResults);
@@ -575,7 +575,7 @@ LogicalResult WhileLowering::matchAndRewrite(WhileOp whileOp,
// Branch to the "before" region.
rewriter.setInsertionPointToEnd(currentBlock);
- rewriter.create<cf::BranchOp>(loc, before, whileOp.getInits());
+ cf::BranchOp::create(rewriter, loc, before, whileOp.getInits());
// Replace terminators with branches. Assuming bodies are SESE, which holds
// given only the patterns from this file, we only need to look at the last
@@ -625,14 +625,14 @@ DoWhileLowering::matchAndRewrite(WhileOp whileOp,
// Branch to the "before" region.
rewriter.setInsertionPointToEnd(currentBlock);
- rewriter.create<cf::BranchOp>(whileOp.getLoc(), before, whileOp.getInits());
+ cf::BranchOp::create(rewriter, whileOp.getLoc(), before, whileOp.getInits());
// Loop around the "before" region based on condition.
rewriter.setInsertionPointToEnd(before);
auto condOp = cast<ConditionOp>(before->getTerminator());
- rewriter.create<cf::CondBranchOp>(condOp.getLoc(), condOp.getCondition(),
- before, condOp.getArgs(), continuation,
- ValueRange());
+ cf::CondBranchOp::create(rewriter, condOp.getLoc(), condOp.getCondition(),
+ before, condOp.getArgs(), continuation,
+ ValueRange());
// Replace the op with values "yielded" from the "before" region, which are
// visible by dominance.
@@ -695,12 +695,12 @@ IndexSwitchLowering::matchAndRewrite(IndexSwitchOp op,
SmallVector<ValueRange> caseOperands(caseSuccessors.size(), {});
// Cast switch index to integer case value.
- Value caseValue = rewriter.create<arith::IndexCastOp>(
- op.getLoc(), rewriter.getI32Type(), op.getArg());
+ Value caseValue = arith::IndexCastOp::create(
+ rewriter, op.getLoc(), rewriter.getI32Type(), op.getArg());
- rewriter.create<cf::SwitchOp>(
- op.getLoc(), caseValue, *defaultBlock, ValueRange(),
- rewriter.getDenseI32ArrayAttr(caseValues), caseSuccessors, caseOperands);
+ cf::SwitchOp::create(rewriter, op.getLoc(), caseValue, *defaultBlock,
+ ValueRange(), rewriter.getDenseI32ArrayAttr(caseValues),
+ caseSuccessors, caseOperands);
rewriter.replaceOp(op, continueBlock->getArguments());
return success();
}
diff --git a/mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp b/mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp
index dcb48529a74e6..84cbd869c78ef 100644
--- a/mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp
+++ b/mlir/lib/Conversion/SCFToEmitC/SCFToEmitC.cpp
@@ -91,7 +91,7 @@ createVariablesForResults(T op, const TypeConverter *typeConverter,
Type varType = emitc::LValueType::get(resultType);
emitc::OpaqueAttr noInit = emitc::OpaqueAttr::get(context, "");
emitc::VariableOp var =
- rewriter.create<emitc::VariableOp>(loc, varType, noInit);
+ emitc::VariableOp::create(rewriter, loc, varType, noInit);
resultVariables.push_back(var);
}
@@ -103,14 +103,14 @@ createVariablesForResults(T op, const TypeConverter *typeConverter,
static void assignValues(ValueRange values, ValueRange variables,
ConversionPatternRewriter &rewriter, Location loc) {
for (auto [value, var] : llvm::zip(values, variables))
- rewriter.create<emitc::AssignOp>(loc, var, value);
+ emitc::AssignOp::create(rewriter, loc, var, value);
}
SmallVector<Value> loadValues(const SmallVector<Value> &variables,
PatternRewriter &rewriter, Location loc) {
return llvm::map_to_vector<>(variables, [&](Value var) {
Type type = cast<emitc::LValueType>(var.getType()).getValueType();
- return rewriter.create<emitc::LoadOp>(loc, type, var).getResult();
+ return emitc::LoadOp::create(rewriter, loc, type, var).getResult();
});
}
@@ -129,7 +129,7 @@ static LogicalResult lowerYield(Operation *op, ValueRange resultVariables,
assignValues(yieldOperands, resultVariables, rewriter, loc);
- rewriter.create<emitc::YieldOp>(loc);
+ emitc::YieldOp::create(rewriter, loc);
rewriter.eraseOp(yield);
return success();
@@ -164,8 +164,9 @@ ForLowering::matchAndRewrite(ForOp forOp, OpAdaptor adaptor,
assignValues(adaptor.getInitArgs(), resultVariables, rewriter, loc);
- emitc::ForOp loweredFor = rewriter.create<emitc::ForOp>(
- loc, adaptor.getLowerBound(), adaptor.getUpperBound(), adaptor.getStep());
+ emitc::ForOp loweredFor =
+ emitc::ForOp::create(rewriter, loc, adaptor.getLowerBound(),
+ adaptor.getUpperBound(), adaptor.getStep());
Block *loweredBody = loweredFor.getBody();
@@ -257,7 +258,7 @@ IfLowering::matchAndRewrite(IfOp ifOp, OpAdaptor adaptor,
bool hasElseBlock = !elseRegion.empty();
auto loweredIf =
- rewriter.create<emitc::IfOp>(loc, adaptor.getCondition(), false, false);
+ emitc::IfOp::create(rewriter, loc, adaptor.getCondition(), false, false);
Region &loweredThenRegion = loweredIf.getThenRegion();
auto result = lowerRegion(thenRegion, loweredThenRegion);
@@ -304,8 +305,9 @@ LogicalResult IndexSwitchOpLowering::matchAndRewrite(
"create variables for results failed");
}
- auto loweredSwitch = rewriter.create<emitc::SwitchOp>(
- loc, adaptor.getArg(), adaptor.getCases(), indexSwitchOp.getNumCases());
+ auto loweredSwitch =
+ emitc::SwitchOp::create(rewriter, loc, adaptor.getArg(),
+ adaptor.getCases(), indexSwitchOp.getNumCases());
// Lowering all case regions.
for (auto pair :
diff --git a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
index 844e66e927c4d..f191f3502cf5a 100644
--- a/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
+++ b/mlir/lib/Conversion/SCFToGPU/SCFToGPU.cpp
@@ -84,8 +84,8 @@ static Operation::operand_range getUpperBoundOperands(AffineForOp forOp) {
// Get a Value that corresponds to the loop step. If the step is an attribute,
// materialize a corresponding constant using builder.
static Value getOrCreateStep(AffineForOp forOp, OpBuilder &builder) {
- return builder.create<arith::ConstantIndexOp>(forOp.getLoc(),
- forOp.getStepAsInt());
+ return arith::ConstantIndexOp::create(builder, forOp.getLoc(),
+ forOp.getStepAsInt());
}
// Get a Value for the loop lower bound. If the value requires computation,
@@ -190,12 +190,12 @@ AffineLoopToGpuConverter::collectBounds(AffineForOp forOp, unsigned numLoops) {
return std::nullopt;
}
- Value range = builder.create<arith::SubIOp>(currentLoop.getLoc(),
- upperBound, lowerBound);
+ Value range = arith::SubIOp::create(builder, currentLoop.getLoc(),
+ upperBound, lowerBound);
Value step = getOrCreateStep(currentLoop, builder);
if (getConstantIntValue(step) != static_cast<int64_t>(1))
- range =
- builder.create<arith::CeilDivSIOp>(currentLoop.getLoc(), range, step);
+ range = arith::CeilDivSIOp::create(builder, currentLoop.getLoc(), range,
+ step);
dims.push_back(range);
lbs.push_back(lowerBound);
@@ -221,7 +221,7 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
// no loop mapped to a specific dimension, use constant "1" as its size.
Value constOne =
(numBlockDims < 3 || numThreadDims < 3)
- ? builder.create<arith::ConstantIndexOp>(rootForOp.getLoc(), 1)
+ ? arith::ConstantIndexOp::create(builder, rootForOp.getLoc(), 1)
: nullptr;
Value gridSizeX = numBlockDims > 0 ? dims[0] : constOne;
Value gridSizeY = numBlockDims > 1 ? dims[1] : constOne;
@@ -232,9 +232,9 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
// Create a launch op and move the body region of the innermost loop to the
// launch op.
- auto launchOp = builder.create<gpu::LaunchOp>(
- rootForOp.getLoc(), gridSizeX, gridSizeY, gridSizeZ, blockSizeX,
- blockSizeY, blockSizeZ);
+ auto launchOp =
+ gpu::LaunchOp::create(builder, rootForOp.getLoc(), gridSizeX, gridSizeY,
+ gridSizeZ, blockSizeX, blockSizeY, blockSizeZ);
// Replace the loop terminator (loops contain only a single block) with the
// gpu terminator and move the operations from the loop body block to the gpu
@@ -244,7 +244,7 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
Location terminatorLoc = terminator.getLoc();
terminator.erase();
builder.setInsertionPointToEnd(innermostForOp.getBody());
- builder.create<gpu::TerminatorOp>(terminatorLoc, TypeRange());
+ gpu::TerminatorOp::create(builder, terminatorLoc, TypeRange());
launchOp.getBody().front().getOperations().splice(
launchOp.getBody().front().begin(),
innermostForOp.getBody()->getOperations());
@@ -263,10 +263,10 @@ void AffineLoopToGpuConverter::createLaunch(AffineForOp rootForOp,
: getDim3Value(launchOp.getThreadIds(), en.index() - numBlockDims);
Value step = steps[en.index()];
if (getConstantIntValue(step) != static_cast<int64_t>(1))
- id = builder.create<arith::MulIOp>(rootForOp.getLoc(), step, id);
+ id = arith::MulIOp::create(builder, rootForOp.getLoc(), step, id);
Value ivReplacement =
- builder.create<arith::AddIOp>(rootForOp.getLoc(), *lbArgumentIt, id);
+ arith::AddIOp::create(builder, rootForOp.getLoc(), *lbArgumentIt, id);
en.value().replaceAllUsesWith(ivReplacement);
std::advance(lbArgumentIt, 1);
std::advance(stepArgumentIt, 1);
@@ -319,8 +319,8 @@ static Value deriveStaticUpperBound(Value upperBound,
if (auto minOp = upperBound.getDefiningOp<AffineMinOp>()) {
for (const AffineExpr &result : minOp.getMap().getResults()) {
if (auto constExpr = dyn_cast<AffineConstantExpr>(result)) {
- return rewriter.create<arith::ConstantIndexOp>(minOp.getLoc(),
- constExpr.getValue());
+ return arith::ConstantIndexOp::create(rewriter, minOp.getLoc(),
+ constExpr.getValue());
}
}
}
@@ -344,8 +344,8 @@ static Value deriveStaticUpperBound(Value upperBound,
if ((lhs.value() < 0) != (rhs.value() < 0))
return {};
- return rewriter.create<arith::ConstantIndexOp>(
- multiplyOp.getLoc(), lhs.value() * rhs.value());
+ return arith::ConstantIndexOp::create(rewriter, multiplyOp.getLoc(),
+ lhs.value() * rhs.value());
}
}
@@ -422,8 +422,8 @@ static LogicalResult processParallelLoop(
if (launchIndependent(val))
return val;
if (auto constOp = val.getDefiningOp<arith::ConstantOp>())
- return rewriter.create<arith::ConstantOp>(constOp.getLoc(),
- constOp.getValue());
+ return arith::ConstantOp::create(rewriter, constOp.getLoc(),
+ constOp.getValue());
return {};
};
@@ -453,8 +453,8 @@ static LogicalResult processParallelLoop(
1, 2,
rewriter.getAffineDimExpr(0) * rewriter.getAffineSymbolExpr(0) +
rewriter.getAffineSymbolExpr(1));
- newIndex = rewriter.create<AffineApplyOp>(
- loc, annotation.getMap().compose(lowerAndStep),
+ newIndex = AffineApplyOp::create(
+ rewriter, loc, annotation.getMap().compose(lowerAndStep),
ValueRange{operand, ensureLaunchIndependent(step),
ensureLaunchIndependent(lowerBound)});
// If there was also a bound, insert that, too.
@@ -498,8 +498,8 @@ static LogicalResult processParallelLoop(
1, 2,
((rewriter.getAffineDimExpr(0) - rewriter.getAffineSymbolExpr(0))
.ceilDiv(rewriter.getAffineSymbolExpr(1))));
- Value launchBound = rewriter.create<AffineApplyOp>(
- loc, annotation.getBound().compose(stepMap),
+ Value launchBound = AffineApplyOp::create(
+ rewriter, loc, annotation.getBound().compose(stepMap),
ValueRange{
ensureLaunchIndependent(
cloningMap.lookupOrDefault(upperBound)),
@@ -517,10 +517,10 @@ static LogicalResult processParallelLoop(
if (!boundIsPrecise) {
// We are using an approximation, create a surrounding conditional.
Value originalBound = std::get<3>(config);
- arith::CmpIOp pred = rewriter.create<arith::CmpIOp>(
- loc, arith::CmpIPredicate::slt, newIndex,
+ arith::CmpIOp pred = arith::CmpIOp::create(
+ rewriter, loc, arith::CmpIPredicate::slt, newIndex,
cloningMap.lookupOrDefault(originalBound));
- scf::IfOp ifOp = rewriter.create<scf::IfOp>(loc, pred, false);
+ scf::IfOp ifOp = scf::IfOp::create(rewriter, loc, pred, false);
rewriter.setInsertionPointToStart(&ifOp.getThenRegion().front());
// Put a sentinel into the worklist so we know when to pop out of the
// if body again. We use the launchOp here, as that cannot be part of
@@ -530,10 +530,10 @@ static LogicalResult processParallelLoop(
}
} else {
// Create a sequential for loop.
- auto loopOp = rewriter.create<scf::ForOp>(
- loc, cloningMap.lookupOrDefault(lowerBound),
- cloningMap.lookupOrDefault(upperBound),
- cloningMap.lookupOrDefault(step));
+ auto loopOp = scf::ForOp::create(rewriter, loc,
+ cloningMap.lookupOrDefault(lowerBound),
+...
[truncated]
|
Conversion
create APIs (7/n) (#149687)Conversion
create APIs (7/n)
See #147168 for more info.