Skip to content

Commit 9a2e825

Browse files
authored
[clang][CIR][mlir] Migrate to free create functions. NFC. (llvm#164656)
See https://discourse.llvm.org/t/psa-opty-create-now-with-100-more-tab-complete/87339. I plan to make these deprecated in llvm#164649.
1 parent 58d4f18 commit 9a2e825

23 files changed

+516
-499
lines changed

clang/lib/CIR/CodeGen/CIRGenAsm.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ mlir::LogicalResult CIRGenFunction::emitAsmStmt(const AsmStmt &s) {
117117

118118
bool hasSideEffect = s.isVolatile() || s.getNumOutputs() == 0;
119119

120-
cir::InlineAsmOp ia = builder.create<cir::InlineAsmOp>(
121-
getLoc(s.getAsmLoc()), resultType, operands, asmString, constraints,
122-
hasSideEffect, inferFlavor(cgm, s), mlir::ArrayAttr());
120+
cir::InlineAsmOp ia = cir::InlineAsmOp::create(
121+
builder, getLoc(s.getAsmLoc()), resultType, operands, asmString,
122+
constraints, hasSideEffect, inferFlavor(cgm, s), mlir::ArrayAttr());
123123

124124
if (isGCCAsmGoto) {
125125
assert(!cir::MissingFeatures::asmGoto());

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ static RValue emitBuiltinBitOp(CIRGenFunction &cgf, const CallExpr *e,
4646
Op op;
4747
if constexpr (std::is_same_v<Op, cir::BitClzOp> ||
4848
std::is_same_v<Op, cir::BitCtzOp>)
49-
op = builder.create<Op>(cgf.getLoc(e->getSourceRange()), arg, poisonZero);
49+
op = Op::create(builder, cgf.getLoc(e->getSourceRange()), arg, poisonZero);
5050
else
51-
op = builder.create<Op>(cgf.getLoc(e->getSourceRange()), arg);
51+
op = Op::create(builder, cgf.getLoc(e->getSourceRange()), arg);
5252

5353
mlir::Value result = op.getResult();
5454
mlir::Type exprTy = cgf.convertType(e->getType());
@@ -67,8 +67,8 @@ RValue CIRGenFunction::emitRotate(const CallExpr *e, bool isRotateLeft) {
6767
// to the type of input when necessary.
6868
assert(!cir::MissingFeatures::msvcBuiltins());
6969

70-
auto r = builder.create<cir::RotateOp>(getLoc(e->getSourceRange()), input,
71-
amount, isRotateLeft);
70+
auto r = cir::RotateOp::create(builder, getLoc(e->getSourceRange()), input,
71+
amount, isRotateLeft);
7272
return RValue::get(r);
7373
}
7474

@@ -227,14 +227,14 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
227227
return RValue::get(nullptr);
228228

229229
mlir::Value argValue = emitCheckedArgForAssume(e->getArg(0));
230-
builder.create<cir::AssumeOp>(loc, argValue);
230+
cir::AssumeOp::create(builder, loc, argValue);
231231
return RValue::get(nullptr);
232232
}
233233

234234
case Builtin::BI__builtin_assume_separate_storage: {
235235
mlir::Value value0 = emitScalarExpr(e->getArg(0));
236236
mlir::Value value1 = emitScalarExpr(e->getArg(1));
237-
builder.create<cir::AssumeSepStorageOp>(loc, value0, value1);
237+
cir::AssumeSepStorageOp::create(builder, loc, value0, value1);
238238
return RValue::get(nullptr);
239239
}
240240

@@ -363,8 +363,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
363363
probability);
364364
}
365365

366-
auto result = builder.create<cir::ExpectOp>(
367-
loc, argValue.getType(), argValue, expectedValue, probAttr);
366+
auto result = cir::ExpectOp::create(builder, loc, argValue.getType(),
367+
argValue, expectedValue, probAttr);
368368
return RValue::get(result);
369369
}
370370

@@ -375,15 +375,15 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
375375
case Builtin::BI_byteswap_ulong:
376376
case Builtin::BI_byteswap_uint64: {
377377
mlir::Value arg = emitScalarExpr(e->getArg(0));
378-
return RValue::get(builder.create<cir::ByteSwapOp>(loc, arg));
378+
return RValue::get(cir::ByteSwapOp::create(builder, loc, arg));
379379
}
380380

381381
case Builtin::BI__builtin_bitreverse8:
382382
case Builtin::BI__builtin_bitreverse16:
383383
case Builtin::BI__builtin_bitreverse32:
384384
case Builtin::BI__builtin_bitreverse64: {
385385
mlir::Value arg = emitScalarExpr(e->getArg(0));
386-
return RValue::get(builder.create<cir::BitReverseOp>(loc, arg));
386+
return RValue::get(cir::BitReverseOp::create(builder, loc, arg));
387387
}
388388

389389
case Builtin::BI__builtin_rotateleft8:

clang/lib/CIR/CodeGen/CIRGenCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static void emitDeclDestroy(CIRGenFunction &cgf, const VarDecl *vd,
151151
// Don't confuse lexical cleanup.
152152
builder.clearInsertionPoint();
153153
} else {
154-
builder.create<cir::YieldOp>(addr.getLoc());
154+
cir::YieldOp::create(builder, addr.getLoc());
155155
}
156156
}
157157

clang/lib/CIR/CodeGen/CIRGenClass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,9 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
725725
// Emit the constructor call that will execute for every array element.
726726
mlir::Value arrayOp =
727727
builder.createPtrBitcast(arrayBase.getPointer(), arrayTy);
728-
builder.create<cir::ArrayCtor>(
729-
*currSrcLoc, arrayOp, [&](mlir::OpBuilder &b, mlir::Location loc) {
728+
cir::ArrayCtor::create(
729+
builder, *currSrcLoc, arrayOp,
730+
[&](mlir::OpBuilder &b, mlir::Location loc) {
730731
mlir::BlockArgument arg =
731732
b.getInsertionBlock()->addArgument(ptrToElmType, loc);
732733
Address curAddr = Address(arg, elementType, eltAlignment);
@@ -738,7 +739,7 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
738739
emitCXXConstructorCall(ctor, Ctor_Complete,
739740
/*ForVirtualBase=*/false,
740741
/*Delegating=*/false, currAVS, e);
741-
builder.create<cir::YieldOp>(loc);
742+
cir::YieldOp::create(builder, loc);
742743
});
743744
}
744745
}

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ void CIRGenFunction::emitStoreThroughLValue(RValue src, LValue dst,
251251
const mlir::Location loc = dst.getVectorPointer().getLoc();
252252
const mlir::Value vector =
253253
builder.createLoad(loc, dst.getVectorAddress());
254-
const mlir::Value newVector = builder.create<cir::VecInsertOp>(
255-
loc, vector, src.getValue(), dst.getVectorIdx());
254+
const mlir::Value newVector = cir::VecInsertOp::create(
255+
builder, loc, vector, src.getValue(), dst.getVectorIdx());
256256
builder.createStore(loc, newVector, dst.getVectorAddress());
257257
return;
258258
}
@@ -615,8 +615,8 @@ RValue CIRGenFunction::emitLoadOfLValue(LValue lv, SourceLocation loc) {
615615
if (lv.isVectorElt()) {
616616
const mlir::Value load =
617617
builder.createLoad(getLoc(loc), lv.getVectorAddress());
618-
return RValue::get(builder.create<cir::VecExtractOp>(getLoc(loc), load,
619-
lv.getVectorIdx()));
618+
return RValue::get(cir::VecExtractOp::create(builder, getLoc(loc), load,
619+
lv.getVectorIdx()));
620620
}
621621

622622
cgm.errorNYI(loc, "emitLoadOfLValue");
@@ -1685,8 +1685,8 @@ CIRGenCallee CIRGenFunction::emitDirectCallee(const GlobalDecl &gd) {
16851685
mlir::OpBuilder::InsertionGuard guard(builder);
16861686
builder.setInsertionPointToStart(cgm.getModule().getBody());
16871687

1688-
clone = builder.create<cir::FuncOp>(calleeFunc.getLoc(), fdInlineName,
1689-
calleeFunc.getFunctionType());
1688+
clone = cir::FuncOp::create(builder, calleeFunc.getLoc(), fdInlineName,
1689+
calleeFunc.getFunctionType());
16901690
clone.setLinkageAttr(cir::GlobalLinkageKindAttr::get(
16911691
&cgm.getMLIRContext(), cir::GlobalLinkageKind::InternalLinkage));
16921692
clone.setSymVisibility("private");
@@ -1778,8 +1778,8 @@ RValue CIRGenFunction::emitCall(clang::QualType calleeTy,
17781778
mlir::Operation *fn = callee.getFunctionPointer();
17791779
mlir::Value addr;
17801780
if (auto funcOp = mlir::dyn_cast<cir::FuncOp>(fn)) {
1781-
addr = builder.create<cir::GetGlobalOp>(
1782-
getLoc(e->getSourceRange()),
1781+
addr = cir::GetGlobalOp::create(
1782+
builder, getLoc(e->getSourceRange()),
17831783
cir::PointerType::get(funcOp.getFunctionType()), funcOp.getSymName());
17841784
} else {
17851785
addr = fn->getResult(0);
@@ -1996,9 +1996,9 @@ cir::IfOp CIRGenFunction::emitIfOnBoolExpr(
19961996

19971997
// Emit the code with the fully general case.
19981998
mlir::Value condV = emitOpOnBoolExpr(loc, cond);
1999-
return builder.create<cir::IfOp>(loc, condV, elseLoc.has_value(),
2000-
/*thenBuilder=*/thenBuilder,
2001-
/*elseBuilder=*/elseBuilder);
1999+
return cir::IfOp::create(builder, loc, condV, elseLoc.has_value(),
2000+
/*thenBuilder=*/thenBuilder,
2001+
/*elseBuilder=*/elseBuilder);
20022002
}
20032003

20042004
/// TODO(cir): see EmitBranchOnBoolExpr for extra ideas).
@@ -2025,12 +2025,12 @@ mlir::Value CIRGenFunction::emitOpOnBoolExpr(mlir::Location loc,
20252025
loc, condV, /*thenBuilder=*/
20262026
[this, trueExpr](mlir::OpBuilder &b, mlir::Location loc) {
20272027
mlir::Value lhs = emitScalarExpr(trueExpr);
2028-
b.create<cir::YieldOp>(loc, lhs);
2028+
cir::YieldOp::create(b, loc, lhs);
20292029
},
20302030
/*elseBuilder=*/
20312031
[this, falseExpr](mlir::OpBuilder &b, mlir::Location loc) {
20322032
mlir::Value rhs = emitScalarExpr(falseExpr);
2033-
b.create<cir::YieldOp>(loc, rhs);
2033+
cir::YieldOp::create(b, loc, rhs);
20342034
})
20352035
.getResult();
20362036

@@ -2211,8 +2211,8 @@ Address CIRGenFunction::emitLoadOfReference(LValue refLVal, mlir::Location loc,
22112211
cgm.errorNYI(loc, "load of volatile reference");
22122212

22132213
cir::LoadOp load =
2214-
builder.create<cir::LoadOp>(loc, refLVal.getAddress().getElementType(),
2215-
refLVal.getAddress().getPointer());
2214+
cir::LoadOp::create(builder, loc, refLVal.getAddress().getElementType(),
2215+
refLVal.getAddress().getPointer());
22162216

22172217
assert(!cir::MissingFeatures::opTBAA());
22182218

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *il) {
390390
}
391391

392392
auto complexAttr = cir::ConstComplexAttr::get(realValueAttr, imagValueAttr);
393-
return builder.create<cir::ConstantOp>(loc, complexAttr);
393+
return cir::ConstantOp::create(builder, loc, complexAttr);
394394
}
395395

396396
mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) {
@@ -601,7 +601,7 @@ mlir::Value ComplexExprEmitter::emitBinAdd(const BinOpInfo &op) {
601601

602602
if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
603603
mlir::isa<cir::ComplexType>(op.rhs.getType()))
604-
return builder.create<cir::ComplexAddOp>(op.loc, op.lhs, op.rhs);
604+
return cir::ComplexAddOp::create(builder, op.loc, op.lhs, op.rhs);
605605

606606
if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
607607
mlir::Value real = builder.createComplexReal(op.loc, op.lhs);
@@ -623,7 +623,7 @@ mlir::Value ComplexExprEmitter::emitBinSub(const BinOpInfo &op) {
623623

624624
if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
625625
mlir::isa<cir::ComplexType>(op.rhs.getType()))
626-
return builder.create<cir::ComplexSubOp>(op.loc, op.lhs, op.rhs);
626+
return cir::ComplexSubOp::create(builder, op.loc, op.lhs, op.rhs);
627627

628628
if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
629629
mlir::Value real = builder.createComplexReal(op.loc, op.lhs);
@@ -664,7 +664,8 @@ mlir::Value ComplexExprEmitter::emitBinMul(const BinOpInfo &op) {
664664
mlir::isa<cir::ComplexType>(op.rhs.getType())) {
665665
cir::ComplexRangeKind rangeKind =
666666
getComplexRangeAttr(op.fpFeatures.getComplexRange());
667-
return builder.create<cir::ComplexMulOp>(op.loc, op.lhs, op.rhs, rangeKind);
667+
return cir::ComplexMulOp::create(builder, op.loc, op.lhs, op.rhs,
668+
rangeKind);
668669
}
669670

670671
if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
@@ -975,14 +976,14 @@ mlir::Value ComplexExprEmitter::VisitAbstractConditionalOperator(
975976
[&](mlir::OpBuilder &b, mlir::Location loc) {
976977
eval.beginEvaluation();
977978
mlir::Value trueValue = Visit(e->getTrueExpr());
978-
b.create<cir::YieldOp>(loc, trueValue);
979+
cir::YieldOp::create(b, loc, trueValue);
979980
eval.endEvaluation();
980981
},
981982
/*elseBuilder=*/
982983
[&](mlir::OpBuilder &b, mlir::Location loc) {
983984
eval.beginEvaluation();
984985
mlir::Value falseValue = Visit(e->getFalseExpr());
985-
b.create<cir::YieldOp>(loc, falseValue);
986+
cir::YieldOp::create(b, loc, falseValue);
986987
eval.endEvaluation();
987988
})
988989
.getResult();

0 commit comments

Comments
 (0)