Skip to content

Commit 706dc1b

Browse files
andykaylormikolaj-pirog
authored andcommitted
[CIR][NFC] Migrate more calls to free create functions (llvm#164719)
This migrates some code that was calling the now-deprecated form of the MLIR builder create function.
1 parent 20d7d91 commit 706dc1b

File tree

7 files changed

+77
-79
lines changed

7 files changed

+77
-79
lines changed

clang/lib/CIR/CodeGen/CIRGenBuilder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ mlir::Value CIRGenBuilderTy::maybeBuildArrayDecay(mlir::Location loc,
2222

2323
if (arrayTy) {
2424
const cir::PointerType flatPtrTy = getPointerTo(arrayTy.getElementType());
25-
return create<cir::CastOp>(loc, flatPtrTy, cir::CastKind::array_to_ptrdecay,
26-
arrayPtr);
25+
return cir::CastOp::create(*this, loc, flatPtrTy,
26+
cir::CastKind::array_to_ptrdecay, arrayPtr);
2727
}
2828

2929
assert(arrayPtrTy.getPointee() == eltTy &&
@@ -40,7 +40,7 @@ mlir::Value CIRGenBuilderTy::getArrayElement(mlir::Location arrayLocBegin,
4040
if (shouldDecay)
4141
basePtr = maybeBuildArrayDecay(arrayLocBegin, arrayPtr, eltTy);
4242
const mlir::Type flatPtrTy = basePtr.getType();
43-
return create<cir::PtrStrideOp>(arrayLocEnd, flatPtrTy, basePtr, idx);
43+
return cir::PtrStrideOp::create(*this, arrayLocEnd, flatPtrTy, basePtr, idx);
4444
}
4545

4646
cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
@@ -60,14 +60,14 @@ cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc,
6060
cir::ConstantOp CIRGenBuilderTy::getConstInt(mlir::Location loc, mlir::Type t,
6161
uint64_t c) {
6262
assert(mlir::isa<cir::IntType>(t) && "expected cir::IntType");
63-
return create<cir::ConstantOp>(loc, cir::IntAttr::get(t, c));
63+
return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(t, c));
6464
}
6565

6666
cir::ConstantOp
6767
clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
6868
llvm::APFloat fpVal) {
6969
assert(mlir::isa<cir::FPTypeInterface>(t) && "expected floating point type");
70-
return create<cir::ConstantOp>(loc, cir::FPAttr::get(t, fpVal));
70+
return cir::ConstantOp::create(*this, loc, cir::FPAttr::get(t, fpVal));
7171
}
7272

7373
void CIRGenBuilderTy::computeGlobalViewIndicesFromFlatOffset(

clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ cir::GlobalLinkageKind CIRGenCXXABI::getCXXDestructorLinkage(
7070
mlir::Value CIRGenCXXABI::loadIncomingCXXThis(CIRGenFunction &cgf) {
7171
ImplicitParamDecl *vd = getThisDecl(cgf);
7272
Address addr = cgf.getAddrOfLocalVar(vd);
73-
return cgf.getBuilder().create<cir::LoadOp>(
74-
cgf.getLoc(vd->getLocation()), addr.getElementType(), addr.getPointer());
73+
return cir::LoadOp::create(cgf.getBuilder(), cgf.getLoc(vd->getLocation()),
74+
addr.getElementType(), addr.getPointer());
7575
}
7676

7777
void CIRGenCXXABI::setCXXABIThisValue(CIRGenFunction &cgf,

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ static LValue emitFunctionDeclLValue(CIRGenFunction &cgf, const Expr *e,
671671

672672
mlir::Type fnTy = funcOp.getFunctionType();
673673
mlir::Type ptrTy = cir::PointerType::get(fnTy);
674-
mlir::Value addr = cgf.getBuilder().create<cir::GetGlobalOp>(
675-
loc, ptrTy, funcOp.getSymName());
674+
mlir::Value addr = cir::GetGlobalOp::create(cgf.getBuilder(), loc, ptrTy,
675+
funcOp.getSymName());
676676

677677
if (funcOp.getFunctionType() != cgf.convertType(fd->getType())) {
678678
fnTy = cgf.convertType(fd->getType());
@@ -2020,18 +2020,17 @@ mlir::Value CIRGenFunction::emitOpOnBoolExpr(mlir::Location loc,
20202020
mlir::Value condV = emitOpOnBoolExpr(loc, condOp->getCond());
20212021

20222022
mlir::Value ternaryOpRes =
2023-
builder
2024-
.create<cir::TernaryOp>(
2025-
loc, condV, /*thenBuilder=*/
2026-
[this, trueExpr](mlir::OpBuilder &b, mlir::Location loc) {
2027-
mlir::Value lhs = emitScalarExpr(trueExpr);
2028-
cir::YieldOp::create(b, loc, lhs);
2029-
},
2030-
/*elseBuilder=*/
2031-
[this, falseExpr](mlir::OpBuilder &b, mlir::Location loc) {
2032-
mlir::Value rhs = emitScalarExpr(falseExpr);
2033-
cir::YieldOp::create(b, loc, rhs);
2034-
})
2023+
cir::TernaryOp::create(
2024+
builder, loc, condV, /*thenBuilder=*/
2025+
[this, trueExpr](mlir::OpBuilder &b, mlir::Location loc) {
2026+
mlir::Value lhs = emitScalarExpr(trueExpr);
2027+
cir::YieldOp::create(b, loc, lhs);
2028+
},
2029+
/*elseBuilder=*/
2030+
[this, falseExpr](mlir::OpBuilder &b, mlir::Location loc) {
2031+
mlir::Value rhs = emitScalarExpr(falseExpr);
2032+
cir::YieldOp::create(b, loc, rhs);
2033+
})
20352034
.getResult();
20362035

20372036
return emitScalarConversion(ternaryOpRes, condOp->getType(),

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -969,23 +969,22 @@ mlir::Value ComplexExprEmitter::VisitAbstractConditionalOperator(
969969
Expr *cond = e->getCond()->IgnoreParens();
970970
mlir::Value condValue = cgf.evaluateExprAsBool(cond);
971971

972-
return builder
973-
.create<cir::TernaryOp>(
974-
loc, condValue,
975-
/*thenBuilder=*/
976-
[&](mlir::OpBuilder &b, mlir::Location loc) {
977-
eval.beginEvaluation();
978-
mlir::Value trueValue = Visit(e->getTrueExpr());
979-
cir::YieldOp::create(b, loc, trueValue);
980-
eval.endEvaluation();
981-
},
982-
/*elseBuilder=*/
983-
[&](mlir::OpBuilder &b, mlir::Location loc) {
984-
eval.beginEvaluation();
985-
mlir::Value falseValue = Visit(e->getFalseExpr());
986-
cir::YieldOp::create(b, loc, falseValue);
987-
eval.endEvaluation();
988-
})
972+
return cir::TernaryOp::create(
973+
builder, loc, condValue,
974+
/*thenBuilder=*/
975+
[&](mlir::OpBuilder &b, mlir::Location loc) {
976+
eval.beginEvaluation();
977+
mlir::Value trueValue = Visit(e->getTrueExpr());
978+
cir::YieldOp::create(b, loc, trueValue);
979+
eval.endEvaluation();
980+
},
981+
/*elseBuilder=*/
982+
[&](mlir::OpBuilder &b, mlir::Location loc) {
983+
eval.beginEvaluation();
984+
mlir::Value falseValue = Visit(e->getFalseExpr());
985+
cir::YieldOp::create(b, loc, falseValue);
986+
eval.endEvaluation();
987+
})
989988
.getResult();
990989
}
991990

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,8 +1568,9 @@ static mlir::Value emitPointerArithmetic(CIRGenFunction &cgf,
15681568
}
15691569

15701570
assert(!cir::MissingFeatures::sanitizers());
1571-
return cgf.getBuilder().create<cir::PtrStrideOp>(
1572-
cgf.getLoc(op.e->getExprLoc()), pointer.getType(), pointer, index);
1571+
return cir::PtrStrideOp::create(cgf.getBuilder(),
1572+
cgf.getLoc(op.e->getExprLoc()),
1573+
pointer.getType(), pointer, index);
15731574
}
15741575

15751576
mlir::Value ScalarExprEmitter::emitMul(const BinOpInfo &ops) {
@@ -2075,8 +2076,9 @@ mlir::Value ScalarExprEmitter::VisitInitListExpr(InitListExpr *e) {
20752076
vectorType.getSize() - numInitElements, zeroValue);
20762077
}
20772078

2078-
return cgf.getBuilder().create<cir::VecCreateOp>(
2079-
cgf.getLoc(e->getSourceRange()), vectorType, elements);
2079+
return cir::VecCreateOp::create(cgf.getBuilder(),
2080+
cgf.getLoc(e->getSourceRange()), vectorType,
2081+
elements);
20802082
}
20812083

20822084
// C++11 value-initialization for the scalar.
@@ -2364,17 +2366,16 @@ mlir::Value ScalarExprEmitter::VisitAbstractConditionalOperator(
23642366
}
23652367
};
23662368

2367-
mlir::Value result = builder
2368-
.create<cir::TernaryOp>(
2369-
loc, condV,
2370-
/*trueBuilder=*/
2371-
[&](mlir::OpBuilder &b, mlir::Location loc) {
2372-
emitBranch(b, loc, lhsExpr);
2373-
},
2374-
/*falseBuilder=*/
2375-
[&](mlir::OpBuilder &b, mlir::Location loc) {
2376-
emitBranch(b, loc, rhsExpr);
2377-
})
2369+
mlir::Value result = cir::TernaryOp::create(
2370+
builder, loc, condV,
2371+
/*trueBuilder=*/
2372+
[&](mlir::OpBuilder &b, mlir::Location loc) {
2373+
emitBranch(b, loc, lhsExpr);
2374+
},
2375+
/*falseBuilder=*/
2376+
[&](mlir::OpBuilder &b, mlir::Location loc) {
2377+
emitBranch(b, loc, rhsExpr);
2378+
})
23782379
.getResult();
23792380

23802381
if (!insertPoints.empty()) {

clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -612,18 +612,17 @@ static mlir::Value lowerComplexMul(LoweringPreparePass &pass,
612612
mlir::Value resultRealAndImagAreNaN =
613613
builder.createLogicalAnd(loc, resultRealIsNaN, resultImagIsNaN);
614614

615-
return builder
616-
.create<cir::TernaryOp>(
617-
loc, resultRealAndImagAreNaN,
618-
[&](mlir::OpBuilder &, mlir::Location) {
619-
mlir::Value libCallResult = buildComplexBinOpLibCall(
620-
pass, builder, &getComplexMulLibCallName, loc, complexTy,
621-
lhsReal, lhsImag, rhsReal, rhsImag);
622-
builder.createYield(loc, libCallResult);
623-
},
624-
[&](mlir::OpBuilder &, mlir::Location) {
625-
builder.createYield(loc, algebraicResult);
626-
})
615+
return cir::TernaryOp::create(
616+
builder, loc, resultRealAndImagAreNaN,
617+
[&](mlir::OpBuilder &, mlir::Location) {
618+
mlir::Value libCallResult = buildComplexBinOpLibCall(
619+
pass, builder, &getComplexMulLibCallName, loc, complexTy,
620+
lhsReal, lhsImag, rhsReal, rhsImag);
621+
builder.createYield(loc, libCallResult);
622+
},
623+
[&](mlir::OpBuilder &, mlir::Location) {
624+
builder.createYield(loc, algebraicResult);
625+
})
627626
.getResult();
628627
}
629628

clang/lib/CIR/Dialect/Transforms/LoweringPrepareItaniumCXXABI.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,19 @@ LoweringPrepareItaniumCXXABI::lowerDynamicCast(cir::CIRBaseBuilderTy &builder,
155155
return buildDynamicCastAfterNullCheck(builder, op);
156156

157157
mlir::Value srcValueIsNotNull = builder.createPtrToBoolCast(srcValue);
158-
return builder
159-
.create<cir::TernaryOp>(
160-
loc, srcValueIsNotNull,
161-
[&](mlir::OpBuilder &, mlir::Location) {
162-
mlir::Value castedValue =
163-
op.isCastToVoid()
164-
? buildDynamicCastToVoidAfterNullCheck(builder, astCtx, op)
165-
: buildDynamicCastAfterNullCheck(builder, op);
166-
builder.createYield(loc, castedValue);
167-
},
168-
[&](mlir::OpBuilder &, mlir::Location) {
169-
builder.createYield(
170-
loc, builder.getNullPtr(op.getType(), loc).getResult());
171-
})
158+
return cir::TernaryOp::create(
159+
builder, loc, srcValueIsNotNull,
160+
[&](mlir::OpBuilder &, mlir::Location) {
161+
mlir::Value castedValue =
162+
op.isCastToVoid()
163+
? buildDynamicCastToVoidAfterNullCheck(builder, astCtx,
164+
op)
165+
: buildDynamicCastAfterNullCheck(builder, op);
166+
builder.createYield(loc, castedValue);
167+
},
168+
[&](mlir::OpBuilder &, mlir::Location) {
169+
builder.createYield(
170+
loc, builder.getNullPtr(op.getType(), loc).getResult());
171+
})
172172
.getResult();
173173
}

0 commit comments

Comments
 (0)