Skip to content

[mlir][NFC] update mlir create APIs (34/n) #150660

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

Merged
merged 1 commit into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ class CastConversion : public OpConversionPattern<ArithOp> {
Value actualOp = adaptValueType(adaptor.getIn(), rewriter, castSrcType);

// Actual cast (may change bitwidth)
auto cast = rewriter.template create<emitc::CastOp>(op.getLoc(),
castDestType, actualOp);
auto cast =
emitc::CastOp::create(rewriter, op.getLoc(), castDestType, actualOp);

// Cast to the expected output type
auto result = adaptValueType(cast, rewriter, opReturnType);
Expand Down Expand Up @@ -507,8 +507,8 @@ class IntegerOpConversion final : public OpConversionPattern<ArithOp> {
Value lhs = adaptValueType(adaptor.getLhs(), rewriter, arithmeticType);
Value rhs = adaptValueType(adaptor.getRhs(), rewriter, arithmeticType);

Value arithmeticResult = rewriter.template create<EmitCOp>(
op.getLoc(), arithmeticType, lhs, rhs);
Value arithmeticResult =
EmitCOp::create(rewriter, op.getLoc(), arithmeticType, lhs, rhs);

Value result = adaptValueType(arithmeticResult, rewriter, type);

Expand Down Expand Up @@ -547,8 +547,8 @@ class BitwiseOpConversion : public OpConversionPattern<ArithOp> {
Value lhs = adaptValueType(adaptor.getLhs(), rewriter, arithmeticType);
Value rhs = adaptValueType(adaptor.getRhs(), rewriter, arithmeticType);

Value arithmeticResult = rewriter.template create<EmitCOp>(
op.getLoc(), arithmeticType, lhs, rhs);
Value arithmeticResult =
EmitCOp::create(rewriter, op.getLoc(), arithmeticType, lhs, rhs);

Value result = adaptValueType(arithmeticResult, rewriter, type);

Expand Down Expand Up @@ -748,8 +748,8 @@ class ItoFCastOpConversion : public OpConversionPattern<CastOp> {
}
Value fpCastOperand = adaptor.getIn();
if (actualOperandType != operandType) {
fpCastOperand = rewriter.template create<emitc::CastOp>(
castOp.getLoc(), actualOperandType, fpCastOperand);
fpCastOperand = emitc::CastOp::create(rewriter, castOp.getLoc(),
actualOperandType, fpCastOperand);
}
rewriter.replaceOpWithNewOp<emitc::CastOp>(castOp, dstType, fpCastOperand);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ struct CloneOpConversion : public OpConversionPattern<bufferization::CloneOp> {

scf::YieldOp::create(rewriter, loc, acc);
};
auto size = rewriter
.create<scf::ForOp>(loc, zero, rank, one, ValueRange(one),
loopBody)
auto size = scf::ForOp::create(rewriter, loc, zero, rank, one,
ValueRange(one), loopBody)
.getResult(0);

MemRefType memrefType = MemRefType::get({ShapedType::kDynamic},
Expand Down
11 changes: 5 additions & 6 deletions mlir/lib/Conversion/ControlFlowToSCF/ControlFlowToSCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,11 @@ ControlFlowToSCFTransformation::createUnreachableTerminator(Location loc,
return emitError(loc, "Cannot create unreachable terminator for '")
<< parentOp->getName() << "'";

return builder
.create<func::ReturnOp>(
loc, llvm::map_to_vector(funcOp.getResultTypes(),
[&](Type type) {
return getUndefValue(loc, builder, type);
}))
return func::ReturnOp::create(
builder, loc,
llvm::map_to_vector(
funcOp.getResultTypes(),
[&](Type type) { return getUndefValue(loc, builder, type); }))
.getOperation();
}

Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Conversion/GPUToSPIRV/GPUToSPIRV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ static Value createGroupReduceOpImpl(OpBuilder &builder, Location loc,
builder, loc, builder.getI32Type(),
builder.getIntegerAttr(builder.getI32Type(), *clusterSize));

return builder
.create<NonUniformOp>(loc, type, scope, groupOp, arg, clusterSizeValue)
return NonUniformOp::create(builder, loc, type, scope, groupOp, arg,
clusterSizeValue)
.getResult();
}

Expand Down
15 changes: 7 additions & 8 deletions mlir/lib/Conversion/LLVMCommon/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,13 @@ LogicalResult ConvertToLLVMPattern::copyUnrankedDescriptors(

// Allocate memory, copy, and free the source if necessary.
Value memory =
toDynamic
? builder
.create<LLVM::CallOp>(loc, mallocFunc.value(), allocationSize)
.getResult()
: LLVM::AllocaOp::create(builder, loc, getPtrType(),
IntegerType::get(getContext(), 8),
allocationSize,
/*alignment=*/0);
toDynamic ? LLVM::CallOp::create(builder, loc, mallocFunc.value(),
allocationSize)
.getResult()
: LLVM::AllocaOp::create(builder, loc, getPtrType(),
IntegerType::get(getContext(), 8),
allocationSize,
/*alignment=*/0);
Value source = desc.memRefDescPtr(builder, loc);
LLVM::MemcpyOp::create(builder, loc, memory, source, allocationSize, false);
if (!toDynamic)
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Conversion/MPIToLLVM/MPIToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static Op getOrDefineGlobal(ModuleOp &moduleOp, const Location loc,
if (!(ret = moduleOp.lookupSymbol<Op>(name))) {
ConversionPatternRewriter::InsertionGuard guard(rewriter);
rewriter.setInsertionPointToStart(moduleOp.getBody());
ret = rewriter.template create<Op>(loc, std::forward<Args>(args)...);
ret = Op::create(rewriter, loc, std::forward<Args>(args)...);
}
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ struct DimOpLowering : public ConvertOpToLLVMPattern<memref::DimOp> {
Value sizePtr = LLVM::GEPOp::create(rewriter, loc, indexPtrTy,
getTypeConverter()->getIndexType(),
offsetPtr, idxPlusOne);
return rewriter
.create<LLVM::LoadOp>(loc, getTypeConverter()->getIndexType(), sizePtr)
return LLVM::LoadOp::create(rewriter, loc,
getTypeConverter()->getIndexType(), sizePtr)
.getResult();
}

Expand Down
12 changes: 6 additions & 6 deletions mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1493,20 +1493,20 @@ class ShiftPattern : public SPIRVToLLVMConversion<SPIRVOp> {
Value extended;
if (op2TypeWidth < dstTypeWidth) {
if (isUnsignedIntegerOrVector(op2Type)) {
extended = rewriter.template create<LLVM::ZExtOp>(
loc, dstType, adaptor.getOperand2());
extended =
LLVM::ZExtOp::create(rewriter, loc, dstType, adaptor.getOperand2());
} else {
extended = rewriter.template create<LLVM::SExtOp>(
loc, dstType, adaptor.getOperand2());
extended =
LLVM::SExtOp::create(rewriter, loc, dstType, adaptor.getOperand2());
}
} else if (op2TypeWidth == dstTypeWidth) {
extended = adaptor.getOperand2();
} else {
return failure();
}

Value result = rewriter.template create<LLVMOp>(
loc, dstType, adaptor.getOperand1(), extended);
Value result =
LLVMOp::create(rewriter, loc, dstType, adaptor.getOperand1(), extended);
rewriter.replaceOp(op, result);
return success();
}
Expand Down
29 changes: 12 additions & 17 deletions mlir/lib/Conversion/ShardToMPI/ShardToMPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ struct ConvertShardingOp : public OpConversionPattern<ShardingOp> {
auto type = RankedTensorType::get({nSplits, 2}, i64);
Value resHaloSizes =
haloSizes.empty()
? rewriter
.create<tensor::EmptyOp>(loc, std::array<int64_t, 2>{0, 0},
i64)
? tensor::EmptyOp::create(rewriter, loc,
std::array<int64_t, 2>{0, 0}, i64)
.getResult()
: tensor::FromElementsOp::create(rewriter, loc, type, haloSizes)
.getResult();
Expand Down Expand Up @@ -306,13 +305,11 @@ class ConvertProcessLinearIndexOp
auto ctx = op.getContext();
Value commWorld =
mpi::CommWorldOp::create(rewriter, loc, mpi::CommType::get(ctx));
auto rank =
rewriter
.create<mpi::CommRankOp>(
loc,
TypeRange{mpi::RetvalType::get(ctx), rewriter.getI32Type()},
commWorld)
.getRank();
auto rank = mpi::CommRankOp::create(
rewriter, loc,
TypeRange{mpi::RetvalType::get(ctx), rewriter.getI32Type()},
commWorld)
.getRank();
rewriter.replaceOpWithNewOp<arith::IndexCastOp>(op, rewriter.getIndexType(),
rank);
return success();
Expand Down Expand Up @@ -703,10 +700,9 @@ struct ConvertUpdateHaloOp : public OpConversionPattern<UpdateHaloOp> {
// subviews need Index values
for (auto &sz : haloSizes) {
if (auto value = dyn_cast<Value>(sz))
sz =
rewriter
.create<arith::IndexCastOp>(loc, rewriter.getIndexType(), value)
.getResult();
sz = arith::IndexCastOp::create(rewriter, loc, rewriter.getIndexType(),
value)
.getResult();
}

// most of the offset/size/stride data is the same for all dims
Expand Down Expand Up @@ -758,9 +754,8 @@ struct ConvertUpdateHaloOp : public OpConversionPattern<UpdateHaloOp> {
assert(currHaloDim >= 0 && (size_t)currHaloDim < haloSizes.size() / 2);
// Get the linearized ids of the neighbors (down and up) for the
// given split
auto tmp = rewriter
.create<NeighborsLinearIndicesOp>(loc, grid, myMultiIndex,
splitAxes)
auto tmp = NeighborsLinearIndicesOp::create(rewriter, loc, grid,
myMultiIndex, splitAxes)
.getResults();
// MPI operates on i32...
Value neighbourIDs[2] = {
Expand Down
Loading