Skip to content

Commit 91569fa

Browse files
authored
[CIR][NFC] Use Op::create to create CIR operations in CIRGenBuilder (llvm#154540)
1 parent c811f52 commit 91569fa

File tree

2 files changed

+57
-51
lines changed

2 files changed

+57
-51
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
6363

6464
mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ,
6565
const llvm::APInt &val) {
66-
return create<cir::ConstantOp>(loc, cir::IntAttr::get(typ, val));
66+
return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(typ, val));
6767
}
6868

6969
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) {
70-
return create<cir::ConstantOp>(loc, attr);
70+
return cir::ConstantOp::create(*this, loc, attr);
7171
}
7272

7373
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty,
@@ -119,7 +119,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
119119
}
120120

121121
cir::ConstantOp getBool(bool state, mlir::Location loc) {
122-
return create<cir::ConstantOp>(loc, getCIRBoolAttr(state));
122+
return cir::ConstantOp::create(*this, loc, getCIRBoolAttr(state));
123123
}
124124
cir::ConstantOp getFalse(mlir::Location loc) { return getBool(false, loc); }
125125
cir::ConstantOp getTrue(mlir::Location loc) { return getBool(true, loc); }
@@ -144,17 +144,20 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
144144
mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real,
145145
mlir::Value imag) {
146146
auto resultComplexTy = cir::ComplexType::get(real.getType());
147-
return create<cir::ComplexCreateOp>(loc, resultComplexTy, real, imag);
147+
return cir::ComplexCreateOp::create(*this, loc, resultComplexTy, real,
148+
imag);
148149
}
149150

150151
mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand) {
151152
auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
152-
return create<cir::ComplexRealOp>(loc, operandTy.getElementType(), operand);
153+
return cir::ComplexRealOp::create(*this, loc, operandTy.getElementType(),
154+
operand);
153155
}
154156

155157
mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand) {
156158
auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
157-
return create<cir::ComplexImagOp>(loc, operandTy.getElementType(), operand);
159+
return cir::ComplexImagOp::create(*this, loc, operandTy.getElementType(),
160+
operand);
158161
}
159162

160163
cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr,
@@ -171,7 +174,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
171174
}
172175

173176
mlir::Value createNot(mlir::Value value) {
174-
return create<cir::UnaryOp>(value.getLoc(), value.getType(),
177+
return cir::UnaryOp::create(*this, value.getLoc(), value.getType(),
175178
cir::UnaryOpKind::Not, value);
176179
}
177180

@@ -180,15 +183,15 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
180183
mlir::Location loc,
181184
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
182185
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
183-
return create<cir::DoWhileOp>(loc, condBuilder, bodyBuilder);
186+
return cir::DoWhileOp::create(*this, loc, condBuilder, bodyBuilder);
184187
}
185188

186189
/// Create a while operation.
187190
cir::WhileOp createWhile(
188191
mlir::Location loc,
189192
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
190193
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
191-
return create<cir::WhileOp>(loc, condBuilder, bodyBuilder);
194+
return cir::WhileOp::create(*this, loc, condBuilder, bodyBuilder);
192195
}
193196

194197
/// Create a for operation.
@@ -197,22 +200,23 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
197200
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> condBuilder,
198201
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> bodyBuilder,
199202
llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)> stepBuilder) {
200-
return create<cir::ForOp>(loc, condBuilder, bodyBuilder, stepBuilder);
203+
return cir::ForOp::create(*this, loc, condBuilder, bodyBuilder,
204+
stepBuilder);
201205
}
202206

203207
/// Create a break operation.
204208
cir::BreakOp createBreak(mlir::Location loc) {
205-
return create<cir::BreakOp>(loc);
209+
return cir::BreakOp::create(*this, loc);
206210
}
207211

208212
/// Create a continue operation.
209213
cir::ContinueOp createContinue(mlir::Location loc) {
210-
return create<cir::ContinueOp>(loc);
214+
return cir::ContinueOp::create(*this, loc);
211215
}
212216

213217
mlir::Value createUnaryOp(mlir::Location loc, cir::UnaryOpKind kind,
214218
mlir::Value operand) {
215-
return create<cir::UnaryOp>(loc, kind, operand);
219+
return cir::UnaryOp::create(*this, loc, kind, operand);
216220
}
217221

218222
mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
@@ -222,7 +226,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
222226
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType,
223227
mlir::Type type, llvm::StringRef name,
224228
mlir::IntegerAttr alignment) {
225-
return create<cir::AllocaOp>(loc, addrType, type, name, alignment);
229+
return cir::AllocaOp::create(*this, loc, addrType, type, name, alignment);
226230
}
227231

228232
/// Get constant address of a global variable as an MLIR attribute.
@@ -235,8 +239,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
235239

236240
mlir::Value createGetGlobal(mlir::Location loc, cir::GlobalOp global) {
237241
assert(!cir::MissingFeatures::addressSpace());
238-
return create<cir::GetGlobalOp>(loc, getPointerTo(global.getSymType()),
239-
global.getSymName());
242+
return cir::GetGlobalOp::create(
243+
*this, loc, getPointerTo(global.getSymType()), global.getSymName());
240244
}
241245

242246
mlir::Value createGetGlobal(cir::GlobalOp global) {
@@ -263,7 +267,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
263267
cir::GetMemberOp createGetMember(mlir::Location loc, mlir::Type resultTy,
264268
mlir::Value base, llvm::StringRef name,
265269
unsigned index) {
266-
return create<cir::GetMemberOp>(loc, resultTy, base, name, index);
270+
return cir::GetMemberOp::create(*this, loc, resultTy, base, name, index);
267271
}
268272

269273
mlir::Value createDummyValue(mlir::Location loc, mlir::Type type,
@@ -276,7 +280,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
276280

277281
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base,
278282
mlir::Value stride) {
279-
return create<cir::PtrStrideOp>(loc, base.getType(), base, stride);
283+
return cir::PtrStrideOp::create(*this, loc, base.getType(), base, stride);
280284
}
281285

282286
//===--------------------------------------------------------------------===//
@@ -286,7 +290,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
286290
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
287291
mlir::Type returnType, mlir::ValueRange operands,
288292
llvm::ArrayRef<mlir::NamedAttribute> attrs = {}) {
289-
auto op = create<cir::CallOp>(loc, callee, returnType, operands);
293+
auto op = cir::CallOp::create(*this, loc, callee, returnType, operands);
290294
op->setAttrs(attrs);
291295
return op;
292296
}
@@ -317,7 +321,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
317321
mlir::Value src, mlir::Type newTy) {
318322
if (newTy == src.getType())
319323
return src;
320-
return create<cir::CastOp>(loc, newTy, kind, src);
324+
return cir::CastOp::create(*this, loc, newTy, kind, src);
321325
}
322326

323327
mlir::Value createCast(cir::CastKind kind, mlir::Value src,
@@ -367,7 +371,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
367371

368372
mlir::Value createBinop(mlir::Location loc, mlir::Value lhs,
369373
cir::BinOpKind kind, mlir::Value rhs) {
370-
return create<cir::BinOp>(loc, lhs.getType(), kind, lhs, rhs);
374+
return cir::BinOp::create(*this, loc, lhs.getType(), kind, lhs, rhs);
371375
}
372376

373377
mlir::Value createLowBitsSet(mlir::Location loc, unsigned size,
@@ -389,8 +393,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
389393
mlir::Value trueValue, mlir::Value falseValue) {
390394
assert(trueValue.getType() == falseValue.getType() &&
391395
"trueValue and falseValue should have the same type");
392-
return create<cir::SelectOp>(loc, trueValue.getType(), condition, trueValue,
393-
falseValue);
396+
return cir::SelectOp::create(*this, loc, trueValue.getType(), condition,
397+
trueValue, falseValue);
394398
}
395399

396400
mlir::Value createLogicalAnd(mlir::Location loc, mlir::Value lhs,
@@ -405,8 +409,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
405409

406410
mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
407411
OverflowBehavior ob = OverflowBehavior::None) {
408-
auto op =
409-
create<cir::BinOp>(loc, lhs.getType(), cir::BinOpKind::Mul, lhs, rhs);
412+
auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Mul,
413+
lhs, rhs);
410414
op.setNoUnsignedWrap(
411415
llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
412416
op.setNoSignedWrap(
@@ -424,8 +428,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
424428

425429
mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
426430
OverflowBehavior ob = OverflowBehavior::Saturated) {
427-
auto op =
428-
create<cir::BinOp>(loc, lhs.getType(), cir::BinOpKind::Sub, lhs, rhs);
431+
auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Sub,
432+
lhs, rhs);
429433
op.setNoUnsignedWrap(
430434
llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
431435
op.setNoSignedWrap(
@@ -446,8 +450,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
446450

447451
mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
448452
OverflowBehavior ob = OverflowBehavior::None) {
449-
auto op =
450-
create<cir::BinOp>(loc, lhs.getType(), cir::BinOpKind::Add, lhs, rhs);
453+
auto op = cir::BinOp::create(*this, loc, lhs.getType(), cir::BinOpKind::Add,
454+
lhs, rhs);
451455
op.setNoUnsignedWrap(
452456
llvm::to_underlying(ob & OverflowBehavior::NoUnsignedWrap));
453457
op.setNoSignedWrap(
@@ -468,7 +472,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
468472

469473
cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind,
470474
mlir::Value lhs, mlir::Value rhs) {
471-
return create<cir::CmpOp>(loc, getBoolTy(), kind, lhs, rhs);
475+
return cir::CmpOp::create(*this, loc, getBoolTy(), kind, lhs, rhs);
472476
}
473477

474478
mlir::Value createIsNaN(mlir::Location loc, mlir::Value operand) {
@@ -477,7 +481,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
477481

478482
mlir::Value createShift(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
479483
bool isShiftLeft) {
480-
return create<cir::ShiftOp>(loc, lhs.getType(), lhs, rhs, isShiftLeft);
484+
return cir::ShiftOp::create(*this, loc, lhs.getType(), lhs, rhs,
485+
isShiftLeft);
481486
}
482487

483488
mlir::Value createShift(mlir::Location loc, mlir::Value lhs,
@@ -555,12 +560,12 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
555560

556561
/// Create a loop condition.
557562
cir::ConditionOp createCondition(mlir::Value condition) {
558-
return create<cir::ConditionOp>(condition.getLoc(), condition);
563+
return cir::ConditionOp::create(*this, condition.getLoc(), condition);
559564
}
560565

561566
/// Create a yield operation.
562567
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value = {}) {
563-
return create<cir::YieldOp>(loc, value);
568+
return cir::YieldOp::create(*this, loc, value);
564569
}
565570
};
566571

clang/lib/CIR/CodeGen/CIRGenBuilder.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
291291
// Creates constant nullptr for pointer type ty.
292292
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) {
293293
assert(!cir::MissingFeatures::targetCodeGenInfoGetNullPointer());
294-
return create<cir::ConstantOp>(loc, getConstPtrAttr(ty, 0));
294+
return cir::ConstantOp::create(*this, loc, getConstPtrAttr(ty, 0));
295295
}
296296

297297
mlir::Value createNeg(mlir::Value value) {
@@ -300,7 +300,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
300300
// Source is a unsigned integer: first cast it to signed.
301301
if (intTy.isUnsigned())
302302
value = createIntCast(value, getSIntNTy(intTy.getWidth()));
303-
return create<cir::UnaryOp>(value.getLoc(), value.getType(),
303+
return cir::UnaryOp::create(*this, value.getLoc(), value.getType(),
304304
cir::UnaryOpKind::Minus, value);
305305
}
306306

@@ -312,38 +312,38 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
312312
mlir::Value createFloatingCast(mlir::Value v, mlir::Type destType) {
313313
assert(!cir::MissingFeatures::fpConstraints());
314314

315-
return create<cir::CastOp>(v.getLoc(), destType, cir::CastKind::floating,
316-
v);
315+
return cir::CastOp::create(*this, v.getLoc(), destType,
316+
cir::CastKind::floating, v);
317317
}
318318

319319
mlir::Value createFSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
320320
assert(!cir::MissingFeatures::metaDataNode());
321321
assert(!cir::MissingFeatures::fpConstraints());
322322
assert(!cir::MissingFeatures::fastMathFlags());
323323

324-
return create<cir::BinOp>(loc, cir::BinOpKind::Sub, lhs, rhs);
324+
return cir::BinOp::create(*this, loc, cir::BinOpKind::Sub, lhs, rhs);
325325
}
326326

327327
mlir::Value createFAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
328328
assert(!cir::MissingFeatures::metaDataNode());
329329
assert(!cir::MissingFeatures::fpConstraints());
330330
assert(!cir::MissingFeatures::fastMathFlags());
331331

332-
return create<cir::BinOp>(loc, cir::BinOpKind::Add, lhs, rhs);
332+
return cir::BinOp::create(*this, loc, cir::BinOpKind::Add, lhs, rhs);
333333
}
334334
mlir::Value createFMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
335335
assert(!cir::MissingFeatures::metaDataNode());
336336
assert(!cir::MissingFeatures::fpConstraints());
337337
assert(!cir::MissingFeatures::fastMathFlags());
338338

339-
return create<cir::BinOp>(loc, cir::BinOpKind::Mul, lhs, rhs);
339+
return cir::BinOp::create(*this, loc, cir::BinOpKind::Mul, lhs, rhs);
340340
}
341341
mlir::Value createFDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
342342
assert(!cir::MissingFeatures::metaDataNode());
343343
assert(!cir::MissingFeatures::fpConstraints());
344344
assert(!cir::MissingFeatures::fastMathFlags());
345345

346-
return create<cir::BinOp>(loc, cir::BinOpKind::Div, lhs, rhs);
346+
return cir::BinOp::create(*this, loc, cir::BinOpKind::Div, lhs, rhs);
347347
}
348348

349349
Address createBaseClassAddr(mlir::Location loc, Address addr,
@@ -353,8 +353,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
353353
return addr;
354354

355355
auto ptrTy = getPointerTo(destType);
356-
auto baseAddr = create<cir::BaseClassAddrOp>(
357-
loc, ptrTy, addr.getPointer(), mlir::APInt(64, offset), assumeNotNull);
356+
auto baseAddr =
357+
cir::BaseClassAddrOp::create(*this, loc, ptrTy, addr.getPointer(),
358+
mlir::APInt(64, offset), assumeNotNull);
358359
return Address(baseAddr, destType, addr.getAlignment());
359360
}
360361

@@ -393,8 +394,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
393394
mlir::Value createComplexRealPtr(mlir::Location loc, mlir::Value value) {
394395
auto srcPtrTy = mlir::cast<cir::PointerType>(value.getType());
395396
auto srcComplexTy = mlir::cast<cir::ComplexType>(srcPtrTy.getPointee());
396-
return create<cir::ComplexRealPtrOp>(
397-
loc, getPointerTo(srcComplexTy.getElementType()), value);
397+
return cir::ComplexRealPtrOp::create(
398+
*this, loc, getPointerTo(srcComplexTy.getElementType()), value);
398399
}
399400

400401
Address createComplexRealPtr(mlir::Location loc, Address addr) {
@@ -408,8 +409,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
408409
mlir::Value createComplexImagPtr(mlir::Location loc, mlir::Value value) {
409410
auto srcPtrTy = mlir::cast<cir::PointerType>(value.getType());
410411
auto srcComplexTy = mlir::cast<cir::ComplexType>(srcPtrTy.getPointee());
411-
return create<cir::ComplexImagPtrOp>(
412-
loc, getPointerTo(srcComplexTy.getElementType()), value);
412+
return cir::ComplexImagPtrOp::create(
413+
*this, loc, getPointerTo(srcComplexTy.getElementType()), value);
413414
}
414415

415416
Address createComplexImagPtr(mlir::Location loc, Address addr) {
@@ -467,9 +468,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
467468
useVolatile ? cir::IntType::get(storageType.getContext(),
468469
info.volatileStorageSize, info.isSigned)
469470
: storageType;
470-
return create<cir::SetBitfieldOp>(
471-
loc, resultType, dstAddr.getPointer(), storageType, src, info.name,
472-
info.size, offset, info.isSigned, isLvalueVolatile,
471+
return cir::SetBitfieldOp::create(
472+
*this, loc, resultType, dstAddr.getPointer(), storageType, src,
473+
info.name, info.size, offset, info.isSigned, isLvalueVolatile,
473474
dstAddr.getAlignment().getAsAlign().value());
474475
}
475476

@@ -485,7 +486,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
485486
useVolatile ? cir::IntType::get(storageType.getContext(),
486487
info.volatileStorageSize, info.isSigned)
487488
: storageType;
488-
return create<cir::GetBitfieldOp>(loc, resultType, addr.getPointer(),
489+
return cir::GetBitfieldOp::create(*this, loc, resultType, addr.getPointer(),
489490
storageType, info.name, info.size, offset,
490491
info.isSigned, isLvalueVolatile,
491492
addr.getAlignment().getAsAlign().value());

0 commit comments

Comments
 (0)