diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h index cb404205f019..e0a3904bc0c3 100644 --- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h +++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h @@ -46,7 +46,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value getConstAPSInt(mlir::Location loc, const llvm::APSInt &val) { auto ty = cir::IntType::get(getContext(), val.getBitWidth(), val.isSigned()); - return create(loc, cir::IntAttr::get(ty, val)); + return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(ty, val)); } mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits) { @@ -63,20 +63,20 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ, const llvm::APInt &val) { - return create(loc, cir::IntAttr::get(typ, val)); + return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(typ, val)); } cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr) { - return create(loc, attr); + return cir::ConstantOp::create(*this, loc, attr); } // Creates constant null value for integral type ty. cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc) { - return create(loc, getZeroInitAttr(ty)); + return cir::ConstantOp::create(*this, loc, getZeroInitAttr(ty)); } cir::ConstantOp getBool(bool state, mlir::Location loc) { - return create(loc, getCIRBoolAttr(state)); + return cir::ConstantOp::create(*this, loc, getCIRBoolAttr(state)); } cir::ConstantOp getFalse(mlir::Location loc) { return getBool(false, loc); } cir::ConstantOp getTrue(mlir::Location loc) { return getBool(true, loc); } @@ -164,7 +164,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { bool isVolatile = false, bool isNontemporal = false, uint64_t alignment = 0) { mlir::IntegerAttr alignmentAttr = getAlignmentAttr(alignment); - return create(loc, ptr, /*isDeref=*/false, isVolatile, + return cir::LoadOp::create(*this, loc, ptr, /*isDeref=*/false, isVolatile, isNontemporal, /*alignment=*/alignmentAttr, /*mem_order=*/ @@ -179,13 +179,13 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { } mlir::Value createNot(mlir::Value value) { - return create(value.getLoc(), value.getType(), + return cir::UnaryOp::create(*this, value.getLoc(), value.getType(), cir::UnaryOpKind::Not, value); } cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs) { - return create(loc, getBoolTy(), kind, lhs, rhs); + return cir::CmpOp::create(*this, loc, getBoolTy(), kind, lhs, rhs); } mlir::Value createIsNaN(mlir::Location loc, mlir::Value operand) { @@ -194,28 +194,29 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value createUnaryOp(mlir::Location loc, cir::UnaryOpKind kind, mlir::Value operand) { - return create(loc, kind, operand); + return cir::UnaryOp::create(*this, loc, kind, operand); } mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind, const llvm::APInt &rhs) { - return create(lhs.getLoc(), lhs.getType(), kind, lhs, + return cir::BinOp::create(*this, lhs.getLoc(), lhs.getType(), kind, lhs, getConstAPInt(lhs.getLoc(), lhs.getType(), rhs)); } mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind, mlir::Value rhs) { - return create(lhs.getLoc(), lhs.getType(), kind, lhs, rhs); + return cir::BinOp::create(*this, lhs.getLoc(), lhs.getType(), kind, lhs, + rhs); } mlir::Value createBinop(mlir::Location loc, mlir::Value lhs, cir::BinOpKind kind, mlir::Value rhs) { - return create(loc, lhs.getType(), kind, lhs, rhs); + return cir::BinOp::create(*this, loc, lhs.getType(), kind, lhs, rhs); } mlir::Value createShift(mlir::Value lhs, const llvm::APInt &rhs, bool isShiftLeft) { - return create(lhs.getLoc(), lhs.getType(), lhs, + return cir::ShiftOp::create(*this, lhs.getLoc(), lhs.getType(), lhs, getConstAPInt(lhs.getLoc(), lhs.getType(), rhs), isShiftLeft); } @@ -265,7 +266,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value createMul(mlir::Value lhs, mlir::Value rhs, bool hasNUW = false, bool hasNSW = false) { - auto op = create(lhs.getLoc(), lhs.getType(), + auto op = cir::BinOp::create(*this, lhs.getLoc(), lhs.getType(), cir::BinOpKind::Mul, lhs, rhs); if (hasNUW) op.setNoUnsignedWrap(true); @@ -289,8 +290,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value trueValue, mlir::Value falseValue) { assert(trueValue.getType() == falseValue.getType() && "trueValue and falseValue should have the same type"); - return create(loc, trueValue.getType(), condition, trueValue, - falseValue); + return cir::SelectOp::create(*this, loc, trueValue.getType(), condition, + trueValue, falseValue); } mlir::Value createLogicalAnd(mlir::Location loc, mlir::Value lhs, @@ -306,23 +307,27 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real, mlir::Value imag) { auto resultComplexTy = cir::ComplexType::get(real.getType()); - return create(loc, resultComplexTy, real, imag); + return cir::ComplexCreateOp::create(*this, loc, resultComplexTy, real, + imag); } mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand) { auto operandTy = mlir::cast(operand.getType()); - return create(loc, operandTy.getElementType(), operand); + return cir::ComplexRealOp::create(*this, loc, operandTy.getElementType(), + operand); } mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand) { auto operandTy = mlir::cast(operand.getType()); - return create(loc, operandTy.getElementType(), operand); + return cir::ComplexImagOp::create(*this, loc, operandTy.getElementType(), + operand); } mlir::Value createComplexBinOp(mlir::Location loc, mlir::Value lhs, cir::ComplexBinOpKind kind, mlir::Value rhs, cir::ComplexRangeKind range, bool promoted) { - return create(loc, kind, lhs, rhs, range, promoted); + return cir::ComplexBinOp::create(*this, loc, kind, lhs, rhs, range, + promoted); } mlir::Value createComplexAdd(mlir::Location loc, mlir::Value lhs, @@ -356,8 +361,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { if (mlir::cast(dst.getType()).getPointee() != val.getType()) dst = createPtrBitcast(dst, val.getType()); - return create(loc, val, dst, isVolatile, isNontemporal, align, - order, + return cir::StoreOp::create(*this, loc, val, dst, isVolatile, isNontemporal, + align, order, /*tbaa=*/cir::TBAAAttr{}); } @@ -365,7 +370,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Type type, llvm::StringRef name, mlir::IntegerAttr alignment, mlir::Value dynAllocSize) { - return create(loc, addrType, type, name, alignment, + return cir::AllocaOp::create(*this, loc, addrType, type, name, alignment, dynAllocSize); } @@ -380,7 +385,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, mlir::Type type, llvm::StringRef name, mlir::IntegerAttr alignment) { - return create(loc, addrType, type, name, alignment); + return cir::AllocaOp::create(*this, loc, addrType, type, name, alignment); } mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, @@ -392,8 +397,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value createGetGlobal(mlir::Location loc, cir::GlobalOp global, bool threadLocal = false) { - return create( - loc, getPointerTo(global.getSymType(), global.getAddrSpace()), + return cir::GetGlobalOp::create( + *this, loc, getPointerTo(global.getSymType(), global.getAddrSpace()), global.getName(), threadLocal); } @@ -404,23 +409,23 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { /// Create a copy with inferred length. cir::CopyOp createCopy(mlir::Value dst, mlir::Value src, bool isVolatile = false) { - return create(dst.getLoc(), dst, src, isVolatile, + return cir::CopyOp::create(*this, dst.getLoc(), dst, src, isVolatile, /*tbaa=*/cir::TBAAAttr{}); } cir::MemCpyOp createMemCpy(mlir::Location loc, mlir::Value dst, mlir::Value src, mlir::Value len) { - return create(loc, dst, src, len); + return cir::MemCpyOp::create(*this, loc, dst, src, len); } cir::SignBitOp createSignBit(mlir::Location loc, mlir::Value val) { auto resTy = cir::BoolType::get(getContext()); - return create(loc, resTy, val); + return cir::SignBitOp::create(*this, loc, resTy, val); } mlir::Value createSub(mlir::Value lhs, mlir::Value rhs, bool hasNUW = false, bool hasNSW = false, bool saturated = false) { - auto op = create(lhs.getLoc(), lhs.getType(), + auto op = cir::BinOp::create(*this, lhs.getLoc(), lhs.getType(), cir::BinOpKind::Sub, lhs, rhs); if (hasNUW) op.setNoUnsignedWrap(true); @@ -441,7 +446,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value createAdd(mlir::Value lhs, mlir::Value rhs, bool hasNUW = false, bool hasNSW = false, bool saturated = false) { - auto op = create(lhs.getLoc(), lhs.getType(), + auto op = cir::BinOp::create(*this, lhs.getLoc(), lhs.getType(), cir::BinOpKind::Add, lhs, rhs); if (hasNUW) op.setNoUnsignedWrap(true); @@ -468,7 +473,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { cir::IntType resultTy, cir::BinOpOverflowKind kind, mlir::Value lhs, mlir::Value rhs) { - auto op = create(loc, resultTy, kind, lhs, rhs); + auto op = + cir::BinOpOverflowOp::create(*this, loc, resultTy, kind, lhs, rhs); return {op.getResult(), op.getOverflow()}; } @@ -480,7 +486,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Value src, mlir::Type newTy) { if (newTy == src.getType()) return src; - return create(loc, newTy, kind, src); + return cir::CastOp::create(*this, loc, newTy, kind, src); } mlir::Value createCast(cir::CastKind kind, mlir::Value src, @@ -507,7 +513,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { assert(mlir::isa(recordBaseTy)); auto fldTy = mlir::cast(recordBaseTy).getMembers()[idx]; auto fldPtrTy = cir::PointerType::get(fldTy); - return create(loc, fldPtrTy, recordPtr, fldName, idx); + return cir::GetMemberOp::create(*this, loc, fldPtrTy, recordPtr, fldName, + idx); } mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy) { @@ -610,7 +617,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Location loc, llvm::function_ref condBuilder, llvm::function_ref bodyBuilder) { - return create(loc, condBuilder, bodyBuilder); + return cir::DoWhileOp::create(*this, loc, condBuilder, bodyBuilder); } /// Create a while operation. @@ -618,7 +625,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { mlir::Location loc, llvm::function_ref condBuilder, llvm::function_ref bodyBuilder) { - return create(loc, condBuilder, bodyBuilder); + return cir::WhileOp::create(*this, loc, condBuilder, bodyBuilder); } /// Create a for operation. @@ -627,7 +634,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { llvm::function_ref condBuilder, llvm::function_ref bodyBuilder, llvm::function_ref stepBuilder) { - return create(loc, condBuilder, bodyBuilder, stepBuilder); + return cir::ForOp::create(*this, loc, condBuilder, bodyBuilder, + stepBuilder); } mlir::TypedAttr getConstPtrAttr(mlir::Type t, int64_t v) { @@ -642,22 +650,22 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { // Creates constant nullptr for pointer type ty. cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc) { assert(!MissingFeatures::targetCodeGenInfoGetNullPointer()); - return create(loc, getConstPtrAttr(ty, 0)); + return cir::ConstantOp::create(*this, loc, getConstPtrAttr(ty, 0)); } /// Create a loop condition. cir::ConditionOp createCondition(mlir::Value condition) { - return create(condition.getLoc(), condition); + return cir::ConditionOp::create(*this, condition.getLoc(), condition); } /// Create a yield operation. cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value = {}) { - return create(loc, value); + return cir::YieldOp::create(*this, loc, value); } cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride) { - return create(loc, base.getType(), base, stride); + return cir::PtrStrideOp::create(*this, loc, base.getType(), base, stride); } cir::CallOp createCallOp(mlir::Location loc, @@ -668,8 +676,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { cir::SideEffect sideEffect = cir::SideEffect::All, cir::ExtraFuncAttributesAttr extraFnAttr = {}) { - cir::CallOp callOp = create(loc, callee, returnType, operands, - callingConv, sideEffect); + cir::CallOp callOp = cir::CallOp::create(*this, loc, callee, returnType, + operands, callingConv, sideEffect); if (extraFnAttr) { callOp->setAttr("extra_attrs", extraFnAttr); @@ -723,9 +731,9 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { cir::CallingConv callingConv = cir::CallingConv::C, cir::SideEffect sideEffect = cir::SideEffect::All, cir::ExtraFuncAttributesAttr extraFnAttr = {}) { - cir::CallOp tryCallOp = - create(loc, callee, returnType, operands, callingConv, - sideEffect, /*exception=*/getUnitAttr()); + cir::CallOp tryCallOp = cir::CallOp::create( + *this, loc, callee, returnType, operands, callingConv, sideEffect, + /*exception=*/getUnitAttr()); if (extraFnAttr) { tryCallOp->setAttr("extra_attrs", extraFnAttr); } else { @@ -783,8 +791,8 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { assert(!MissingFeatures::addressSpace()); auto calleeTy = getPointerTo(calleeFuncTy); - auto op = create(loc, calleeTy, adjustedThisTy, method, - objectPtr); + auto op = cir::GetMethodOp::create(*this, loc, calleeTy, adjustedThisTy, + method, objectPtr); return {op.getCallee(), op.getAdjustedThis()}; } }; diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h index c3bce5d11a57..a61ccd3ffba1 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h +++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h @@ -530,23 +530,23 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { // cir::ConstantOp getUInt8(uint8_t c, mlir::Location loc) { auto uInt8Ty = getUInt8Ty(); - return create(loc, cir::IntAttr::get(uInt8Ty, c)); + return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(uInt8Ty, c)); } cir::ConstantOp getSInt32(int32_t c, mlir::Location loc) { auto sInt32Ty = getSInt32Ty(); - return create(loc, cir::IntAttr::get(sInt32Ty, c)); + return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(sInt32Ty, c)); } cir::ConstantOp getUInt32(uint32_t C, mlir::Location loc) { auto uInt32Ty = getUInt32Ty(); - return create(loc, cir::IntAttr::get(uInt32Ty, C)); + return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(uInt32Ty, C)); } cir::ConstantOp getSInt64(uint64_t C, mlir::Location loc) { auto sInt64Ty = getSInt64Ty(); - return create(loc, cir::IntAttr::get(sInt64Ty, C)); + return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(sInt64Ty, C)); } cir::ConstantOp getUInt64(uint64_t C, mlir::Location loc) { auto uInt64Ty = getUInt64Ty(); - return create(loc, cir::IntAttr::get(uInt64Ty, C)); + return cir::ConstantOp::create(*this, loc, cir::IntAttr::get(uInt64Ty, C)); } cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal); @@ -559,22 +559,22 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { llvm::APFloat fpVal) { assert((mlir::isa(t)) && "expected cir::SingleType or cir::DoubleType"); - return create(loc, cir::FPAttr::get(t, fpVal)); + return cir::ConstantOp::create(*this, loc, cir::FPAttr::get(t, fpVal)); } cir::IsFPClassOp createIsFPClass(mlir::Location loc, mlir::Value src, unsigned flags) { - return create(loc, src, flags); + return cir::IsFPClassOp::create(*this, loc, src, flags); } /// Create constant nullptr for pointer-to-data-member type ty. cir::ConstantOp getNullDataMemberPtr(cir::DataMemberType ty, mlir::Location loc) { - return create(loc, getNullDataMemberAttr(ty)); + return cir::ConstantOp::create(*this, loc, getNullDataMemberAttr(ty)); } cir::ConstantOp getNullMethodPtr(cir::MethodType ty, mlir::Location loc) { - return create(loc, getNullMethodAttr(ty)); + return cir::ConstantOp::create(*this, loc, getNullMethodAttr(ty)); } cir::ConstantOp getZero(mlir::Location loc, mlir::Type ty) { @@ -582,7 +582,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { assert((mlir::isa(ty) || mlir::isa(ty) || mlir::isa(ty)) && "NYI for other types"); - return create(loc, cir::ZeroAttr::get(ty)); + return cir::ConstantOp::create(*this, loc, cir::ZeroAttr::get(ty)); } // @@ -592,35 +592,35 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { /// Create a break operation. cir::BreakOp createBreak(mlir::Location loc) { - return create(loc); + return cir::BreakOp::create(*this, loc); } /// Create a continue operation. cir::ContinueOp createContinue(mlir::Location loc) { - return create(loc); + return cir::ContinueOp::create(*this, loc); } cir::MemCpyOp createMemCpy(mlir::Location loc, mlir::Value dst, mlir::Value src, mlir::Value len) { - return create(loc, dst, src, len); + return cir::MemCpyOp::create(*this, loc, dst, src, len); } cir::MemMoveOp createMemMove(mlir::Location loc, mlir::Value dst, mlir::Value src, mlir::Value len) { - return create(loc, dst, src, len); + return cir::MemMoveOp::create(*this, loc, dst, src, len); } cir::MemSetOp createMemSet(mlir::Location loc, mlir::Value dst, mlir::Value val, mlir::Value len) { val = createIntCast(val, cir::IntType::get(getContext(), 32, true)); - return create(loc, dst, val, len); + return cir::MemSetOp::create(*this, loc, dst, val, len); } cir::MemSetInlineOp createMemSetInline(mlir::Location loc, mlir::Value dst, mlir::Value val, mlir::IntegerAttr len) { val = createIntCast(val, cir::IntType::get(getContext(), 32, true)); - return create(loc, dst, val, len); + return cir::MemSetInlineOp::create(*this, loc, dst, val, len); } mlir::Value createNeg(mlir::Value value) { @@ -629,7 +629,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { // Source is a unsigned integer: first cast it to signed. if (intTy.isUnsigned()) value = createIntCast(value, getSIntNTy(intTy.getWidth())); - return create(value.getLoc(), value.getType(), + return cir::UnaryOp::create(*this, value.getLoc(), value.getType(), cir::UnaryOpKind::Minus, value); } @@ -642,8 +642,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { if (getIsFPConstrained()) llvm_unreachable("constrainedfp NYI"); - return create(v.getLoc(), destType, cir::CastKind::floating, - v); + return cir::CastOp::create(*this, v.getLoc(), destType, + cir::CastKind::floating, v); } mlir::Value createFSub(mlir::Value lhs, mlir::Value rhs) { @@ -652,7 +652,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { llvm_unreachable("Constrained FP NYI"); assert(!cir::MissingFeatures::foldBinOpFMF()); - return create(lhs.getLoc(), cir::BinOpKind::Sub, lhs, rhs); + return cir::BinOp::create(*this, lhs.getLoc(), cir::BinOpKind::Sub, lhs, + rhs); } mlir::Value createFAdd(mlir::Value lhs, mlir::Value rhs) { @@ -661,7 +662,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { llvm_unreachable("Constrained FP NYI"); assert(!cir::MissingFeatures::foldBinOpFMF()); - return create(lhs.getLoc(), cir::BinOpKind::Add, lhs, rhs); + return cir::BinOp::create(*this, lhs.getLoc(), cir::BinOpKind::Add, lhs, + rhs); } mlir::Value createFMul(mlir::Value lhs, mlir::Value rhs) { assert(!cir::MissingFeatures::metaDataNode()); @@ -669,7 +671,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { llvm_unreachable("Constrained FP NYI"); assert(!cir::MissingFeatures::foldBinOpFMF()); - return create(lhs.getLoc(), cir::BinOpKind::Mul, lhs, rhs); + return cir::BinOp::create(*this, lhs.getLoc(), cir::BinOpKind::Mul, lhs, + rhs); } mlir::Value createFDiv(mlir::Value lhs, mlir::Value rhs) { assert(!cir::MissingFeatures::metaDataNode()); @@ -677,7 +680,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { llvm_unreachable("Constrained FP NYI"); assert(!cir::MissingFeatures::foldBinOpFMF()); - return create(lhs.getLoc(), cir::BinOpKind::Div, lhs, rhs); + return cir::BinOp::create(*this, lhs.getLoc(), cir::BinOpKind::Div, lhs, + rhs); } mlir::Value createDynCast(mlir::Location loc, mlir::Value src, @@ -685,7 +689,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { cir::DynamicCastInfoAttr info) { auto castKind = isRefCast ? cir::DynamicCastKind::Ref : cir::DynamicCastKind::Ptr; - return create(loc, destType, castKind, src, info, + return cir::DynamicCastOp::create(*this, loc, destType, castKind, src, info, /*relative_layout=*/false); } @@ -694,9 +698,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { // TODO(cir): consider address space here. assert(!cir::MissingFeatures::addressSpace()); auto destTy = getVoidPtrTy(); - return create(loc, destTy, cir::DynamicCastKind::Ptr, - src, cir::DynamicCastInfoAttr{}, - vtableUseRelativeLayout); + return cir::DynamicCastOp::create( + *this, loc, destTy, cir::DynamicCastKind::Ptr, src, + cir::DynamicCastInfoAttr{}, vtableUseRelativeLayout); } Address createBaseClassAddr(mlir::Location loc, Address addr, @@ -706,8 +710,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { return addr; auto ptrTy = getPointerTo(destType); - auto baseAddr = create( - loc, ptrTy, addr.getPointer(), mlir::APInt(64, offset), assumeNotNull); + auto baseAddr = + cir::BaseClassAddrOp::create(*this, loc, ptrTy, addr.getPointer(), + mlir::APInt(64, offset), assumeNotNull); return Address(baseAddr, destType, addr.getAlignment()); } @@ -718,20 +723,22 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { return addr; auto ptrTy = getPointerTo(destType); - auto derivedAddr = create( - loc, ptrTy, addr.getPointer(), mlir::APInt(64, offset), assumeNotNull); + auto derivedAddr = + cir::DerivedClassAddrOp::create(*this, loc, ptrTy, addr.getPointer(), + mlir::APInt(64, offset), assumeNotNull); return Address(derivedAddr, destType, addr.getAlignment()); } mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy, mlir::Value addr, uint64_t offset) { - return create(loc, retTy, mlir::FlatSymbolRefAttr{}, - addr, offset); + return cir::VTTAddrPointOp::create(*this, loc, retTy, + mlir::FlatSymbolRefAttr{}, addr, offset); } mlir::Value createVTTAddrPoint(mlir::Location loc, mlir::Type retTy, mlir::FlatSymbolRefAttr sym, uint64_t offset) { - return create(loc, retTy, sym, mlir::Value{}, offset); + return cir::VTTAddrPointOp::create(*this, loc, retTy, sym, mlir::Value{}, + offset); } // FIXME(cir): CIRGenBuilder class should have an attribute with a reference @@ -745,7 +752,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { cir::AddressSpace addrSpace = cir::AddressSpace::Default) { mlir::OpBuilder::InsertionGuard guard(*this); setInsertionPointToStart(module.getBody()); - return create(loc, name, type, isConst, linkage, addrSpace); + return cir::GlobalOp::create(*this, loc, name, type, isConst, linkage, + addrSpace); } /// Creates a versioned global variable. If the symbol is already taken, an ID @@ -771,7 +779,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { const CIRGenBitFieldInfo &info, bool isLvalueVolatile, bool useVolatile) { auto offset = useVolatile ? info.VolatileOffset : info.Offset; - return create(loc, resultType, addr.getPointer(), + return cir::GetBitfieldOp::create(*this, loc, resultType, addr.getPointer(), storageType, info.Name, info.Size, offset, info.IsSigned, isLvalueVolatile, addr.getAlignment().getAsAlign().value()); @@ -782,9 +790,9 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { mlir::Value src, const CIRGenBitFieldInfo &info, bool isLvalueVolatile, bool useVolatile) { auto offset = useVolatile ? info.VolatileOffset : info.Offset; - return create( - loc, resultType, dstAddr.getPointer(), storageType, src, info.Name, - info.Size, offset, info.IsSigned, isLvalueVolatile, + return cir::SetBitfieldOp::create( + *this, loc, resultType, dstAddr.getPointer(), storageType, src, + info.Name, info.Size, offset, info.IsSigned, isLvalueVolatile, dstAddr.getAlignment().getAsAlign().value()); } @@ -792,7 +800,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { mlir::Value createGetMember(mlir::Location loc, mlir::Type result, mlir::Value base, llvm::StringRef name, unsigned index) { - return create(loc, result, base, name, index); + return cir::GetMemberOp::create(*this, loc, result, base, name, index); } /// Create a cir.complex.real_ptr operation that derives a pointer to the real @@ -800,8 +808,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { mlir::Value createRealPtr(mlir::Location loc, mlir::Value value) { auto srcPtrTy = mlir::cast(value.getType()); auto srcComplexTy = mlir::cast(srcPtrTy.getPointee()); - return create( - loc, getPointerTo(srcComplexTy.getElementType()), value); + return cir::ComplexRealPtrOp::create( + *this, loc, getPointerTo(srcComplexTy.getElementType()), value); } Address createRealPtr(mlir::Location loc, Address addr) { @@ -814,8 +822,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { mlir::Value createImagPtr(mlir::Location loc, mlir::Value value) { auto srcPtrTy = mlir::cast(value.getType()); auto srcComplexTy = mlir::cast(srcPtrTy.getPointee()); - return create( - loc, getPointerTo(srcComplexTy.getElementType()), value); + return cir::ComplexImagPtrOp::create( + *this, loc, getPointerTo(srcComplexTy.getElementType()), value); } Address createImagPtr(mlir::Location loc, Address addr) { @@ -845,8 +853,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { uint64_t alignment = addr.getAlignment().getQuantity(); if (alignment) align = getI64IntegerAttr(alignment); - return create( - loc, addr.getElementType(), addr.getPointer(), /*isDeref=*/false, + return cir::LoadOp::create( + *this, loc, addr.getElementType(), addr.getPointer(), /*isDeref=*/false, /*is_volatile=*/isVolatile, /*is_nontemporal=*/isNontemporal, align, /*mem_order=*/cir::MemOrderAttr{}, /*tbaa=*/cir::TBAAAttr{}); } @@ -916,8 +924,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { mlir::Value ops[] = {ptr, this->getUInt32(int32_t(alignment.value()), loc), mask, passThru}; - return create(loc, getStringAttr("masked.load"), - ty, ops) + return cir::LLVMIntrinsicCallOp::create( + *this, loc, getStringAttr("masked.load"), ty, ops) .getResult(); } @@ -936,13 +944,13 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { assert(mlir::isa(dataTy) && "val should be a vector"); assert(mask && "mask should not be all-ones (null)"); - auto alignmentValue = create( - loc, cir::IntAttr::get(getUInt32Ty(), alignment.value())); + auto alignmentValue = cir::ConstantOp::create( + *this, loc, cir::IntAttr::get(getUInt32Ty(), alignment.value())); mlir::Value ops[] = {val, ptr, alignmentValue, mask}; - return create(loc, getStringAttr("masked.store"), - getVoidTy(), ops) + return cir::LLVMIntrinsicCallOp::create( + *this, loc, getStringAttr("masked.store"), getVoidTy(), ops) .getResult(); } @@ -952,8 +960,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { auto vecType = mlir::cast(vec1.getType()); auto resultTy = cir::VectorType::get(getContext(), vecType.getElementType(), maskAttrs.size()); - return CIRBaseBuilderTy::create( - loc, resultTy, vec1, vec2, getArrayAttr(maskAttrs)); + return cir::VecShuffleOp::create(*this, loc, resultTy, vec1, vec2, + getArrayAttr(maskAttrs)); } cir::VecShuffleOp createVecShuffle(mlir::Location loc, mlir::Value vec1, @@ -998,11 +1006,11 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { llvm::ArrayRef indexes); cir::StackSaveOp createStackSave(mlir::Location loc, mlir::Type ty) { - return create(loc, ty); + return cir::StackSaveOp::create(*this, loc, ty); } cir::StackRestoreOp createStackRestore(mlir::Location loc, mlir::Value v) { - return create(loc, v); + return cir::StackRestoreOp::create(*this, loc, v); } // TODO(cir): Change this to hoist alloca to the parent *scope* instead. @@ -1027,7 +1035,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { "the three comparison results must have the same bit width"); auto cmpResultTy = getSIntNTy(ltRes.getBitWidth()); auto infoAttr = getCmpThreeWayInfoStrongOrdering(ltRes, eqRes, gtRes); - return create(loc, cmpResultTy, lhs, rhs, infoAttr); + return cir::CmpThreeWayOp::create(*this, loc, cmpResultTy, lhs, rhs, + infoAttr); } cir::CmpThreeWayOp @@ -1042,7 +1051,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { auto cmpResultTy = getSIntNTy(ltRes.getBitWidth()); auto infoAttr = getCmpThreeWayInfoPartialOrdering(ltRes, eqRes, gtRes, unorderedRes); - return create(loc, cmpResultTy, lhs, rhs, infoAttr); + return cir::CmpThreeWayOp::create(*this, loc, cmpResultTy, lhs, rhs, + infoAttr); } cir::GetRuntimeMemberOp createGetIndirectMember(mlir::Location loc, @@ -1054,7 +1064,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { assert(!cir::MissingFeatures::addressSpace()); auto resultTy = getPointerTo(memberPtrTy.getMemberTy()); - return create(loc, resultTy, objectPtr, memberPtr); + return cir::GetRuntimeMemberOp::create(*this, loc, resultTy, objectPtr, + memberPtr); } /// Promote a value for use as an array index.