aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CIR/Lowering
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CIR/Lowering')
-rw-r--r--clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp483
-rw-r--r--clang/lib/CIR/Lowering/LoweringHelpers.cpp12
2 files changed, 257 insertions, 238 deletions
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index bb75f2d..a30ae02 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -90,12 +90,12 @@ static mlir::Value createIntCast(mlir::OpBuilder &bld, mlir::Value src,
mlir::Location loc = src.getLoc();
if (dstWidth > srcWidth && isSigned)
- return bld.create<mlir::LLVM::SExtOp>(loc, dstTy, src);
+ return mlir::LLVM::SExtOp::create(bld, loc, dstTy, src);
if (dstWidth > srcWidth)
- return bld.create<mlir::LLVM::ZExtOp>(loc, dstTy, src);
+ return mlir::LLVM::ZExtOp::create(bld, loc, dstTy, src);
if (dstWidth < srcWidth)
- return bld.create<mlir::LLVM::TruncOp>(loc, dstTy, src);
- return bld.create<mlir::LLVM::BitcastOp>(loc, dstTy, src);
+ return mlir::LLVM::TruncOp::create(bld, loc, dstTy, src);
+ return mlir::LLVM::BitcastOp::create(bld, loc, dstTy, src);
}
static mlir::LLVM::Visibility
@@ -204,12 +204,12 @@ static mlir::Value getLLVMIntCast(mlir::ConversionPatternRewriter &rewriter,
auto loc = llvmSrc.getLoc();
if (cirSrcWidth < cirDstIntWidth) {
if (isUnsigned)
- return rewriter.create<mlir::LLVM::ZExtOp>(loc, llvmDstIntTy, llvmSrc);
- return rewriter.create<mlir::LLVM::SExtOp>(loc, llvmDstIntTy, llvmSrc);
+ return mlir::LLVM::ZExtOp::create(rewriter, loc, llvmDstIntTy, llvmSrc);
+ return mlir::LLVM::SExtOp::create(rewriter, loc, llvmDstIntTy, llvmSrc);
}
// Otherwise truncate
- return rewriter.create<mlir::LLVM::TruncOp>(loc, llvmDstIntTy, llvmSrc);
+ return mlir::LLVM::TruncOp::create(rewriter, loc, llvmDstIntTy, llvmSrc);
}
class CIRAttrToValue {
@@ -315,15 +315,17 @@ static mlir::LLVM::CallIntrinsicOp replaceOpWithCallLLVMIntrinsicOp(
/// IntAttr visitor.
mlir::Value CIRAttrToValue::visitCirAttr(cir::IntAttr intAttr) {
mlir::Location loc = parentOp->getLoc();
- return rewriter.create<mlir::LLVM::ConstantOp>(
- loc, converter->convertType(intAttr.getType()), intAttr.getValue());
+ return mlir::LLVM::ConstantOp::create(
+ rewriter, loc, converter->convertType(intAttr.getType()),
+ intAttr.getValue());
}
/// FPAttr visitor.
mlir::Value CIRAttrToValue::visitCirAttr(cir::FPAttr fltAttr) {
mlir::Location loc = parentOp->getLoc();
- return rewriter.create<mlir::LLVM::ConstantOp>(
- loc, converter->convertType(fltAttr.getType()), fltAttr.getValue());
+ return mlir::LLVM::ConstantOp::create(
+ rewriter, loc, converter->convertType(fltAttr.getType()),
+ fltAttr.getValue());
}
/// ConstComplexAttr visitor.
@@ -350,8 +352,8 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstComplexAttr complexAttr) {
}
mlir::Location loc = parentOp->getLoc();
- return rewriter.create<mlir::LLVM::ConstantOp>(
- loc, converter->convertType(complexAttr.getType()),
+ return mlir::LLVM::ConstantOp::create(
+ rewriter, loc, converter->convertType(complexAttr.getType()),
rewriter.getArrayAttr(components));
}
@@ -359,15 +361,16 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstComplexAttr complexAttr) {
mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstPtrAttr ptrAttr) {
mlir::Location loc = parentOp->getLoc();
if (ptrAttr.isNullValue()) {
- return rewriter.create<mlir::LLVM::ZeroOp>(
- loc, converter->convertType(ptrAttr.getType()));
+ return mlir::LLVM::ZeroOp::create(
+ rewriter, loc, converter->convertType(ptrAttr.getType()));
}
mlir::DataLayout layout(parentOp->getParentOfType<mlir::ModuleOp>());
- mlir::Value ptrVal = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, rewriter.getIntegerType(layout.getTypeSizeInBits(ptrAttr.getType())),
+ mlir::Value ptrVal = mlir::LLVM::ConstantOp::create(
+ rewriter, loc,
+ rewriter.getIntegerType(layout.getTypeSizeInBits(ptrAttr.getType())),
ptrAttr.getValue().getInt());
- return rewriter.create<mlir::LLVM::IntToPtrOp>(
- loc, converter->convertType(ptrAttr.getType()), ptrVal);
+ return mlir::LLVM::IntToPtrOp::create(
+ rewriter, loc, converter->convertType(ptrAttr.getType()), ptrVal);
}
// ConstArrayAttr visitor
@@ -378,10 +381,10 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
if (attr.hasTrailingZeros()) {
mlir::Type arrayTy = attr.getType();
- result = rewriter.create<mlir::LLVM::ZeroOp>(
- loc, converter->convertType(arrayTy));
+ result = mlir::LLVM::ZeroOp::create(rewriter, loc,
+ converter->convertType(arrayTy));
} else {
- result = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmTy);
+ result = mlir::LLVM::UndefOp::create(rewriter, loc, llvmTy);
}
// Iteratively lower each constant element of the array.
@@ -390,7 +393,7 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
mlir::DataLayout dataLayout(parentOp->getParentOfType<mlir::ModuleOp>());
mlir::Value init = visit(elt);
result =
- rewriter.create<mlir::LLVM::InsertValueOp>(loc, result, init, idx);
+ mlir::LLVM::InsertValueOp::create(rewriter, loc, result, init, idx);
}
} else if (auto strAttr = mlir::dyn_cast<mlir::StringAttr>(attr.getElts())) {
// TODO(cir): this diverges from traditional lowering. Normally the string
@@ -399,10 +402,10 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
assert(arrayTy && "String attribute must have an array type");
mlir::Type eltTy = arrayTy.getElementType();
for (auto [idx, elt] : llvm::enumerate(strAttr)) {
- auto init = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, converter->convertType(eltTy), elt);
+ auto init = mlir::LLVM::ConstantOp::create(
+ rewriter, loc, converter->convertType(eltTy), elt);
result =
- rewriter.create<mlir::LLVM::InsertValueOp>(loc, result, init, idx);
+ mlir::LLVM::InsertValueOp::create(rewriter, loc, result, init, idx);
}
} else {
llvm_unreachable("unexpected ConstArrayAttr elements");
@@ -415,12 +418,13 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstRecordAttr constRecord) {
const mlir::Type llvmTy = converter->convertType(constRecord.getType());
const mlir::Location loc = parentOp->getLoc();
- mlir::Value result = rewriter.create<mlir::LLVM::UndefOp>(loc, llvmTy);
+ mlir::Value result = mlir::LLVM::UndefOp::create(rewriter, loc, llvmTy);
// Iteratively lower each constant element of the record.
for (auto [idx, elt] : llvm::enumerate(constRecord.getMembers())) {
mlir::Value init = visit(elt);
- result = rewriter.create<mlir::LLVM::InsertValueOp>(loc, result, init, idx);
+ result =
+ mlir::LLVM::InsertValueOp::create(rewriter, loc, result, init, idx);
}
return result;
@@ -447,8 +451,8 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstVectorAttr attr) {
mlirValues.push_back(mlirAttr);
}
- return rewriter.create<mlir::LLVM::ConstantOp>(
- loc, llvmTy,
+ return mlir::LLVM::ConstantOp::create(
+ rewriter, loc, llvmTy,
mlir::DenseElementsAttr::get(mlir::cast<mlir::ShapedType>(llvmTy),
mlirValues));
}
@@ -483,8 +487,9 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::GlobalViewAttr globalAttr) {
}
mlir::Location loc = parentOp->getLoc();
- mlir::Value addrOp = rewriter.create<mlir::LLVM::AddressOfOp>(
- loc, mlir::LLVM::LLVMPointerType::get(rewriter.getContext()), symName);
+ mlir::Value addrOp = mlir::LLVM::AddressOfOp::create(
+ rewriter, loc, mlir::LLVM::LLVMPointerType::get(rewriter.getContext()),
+ symName);
if (globalAttr.getIndices()) {
llvm::SmallVector<mlir::LLVM::GEPArg> indices;
@@ -499,8 +504,9 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::GlobalViewAttr globalAttr) {
}
mlir::Type resTy = addrOp.getType();
mlir::Type eltTy = converter->convertType(sourceType);
- addrOp = rewriter.create<mlir::LLVM::GEPOp>(
- loc, resTy, eltTy, addrOp, indices, mlir::LLVM::GEPNoWrapFlags::none);
+ addrOp =
+ mlir::LLVM::GEPOp::create(rewriter, loc, resTy, eltTy, addrOp, indices,
+ mlir::LLVM::GEPNoWrapFlags::none);
}
// The incubator has handling here for the attribute having integer type, but
@@ -517,8 +523,8 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::GlobalViewAttr globalAttr) {
return addrOp;
mlir::Type llvmDstTy = converter->convertType(globalAttr.getType());
- return rewriter.create<mlir::LLVM::BitcastOp>(parentOp->getLoc(), llvmDstTy,
- addrOp);
+ return mlir::LLVM::BitcastOp::create(rewriter, parentOp->getLoc(),
+ llvmDstTy, addrOp);
}
llvm_unreachable("Expecting pointer or integer type for GlobalViewAttr");
@@ -557,8 +563,8 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::VTableAttr vtableArr) {
/// ZeroAttr visitor.
mlir::Value CIRAttrToValue::visitCirAttr(cir::ZeroAttr attr) {
mlir::Location loc = parentOp->getLoc();
- return rewriter.create<mlir::LLVM::ZeroOp>(
- loc, converter->convertType(attr.getType()));
+ return mlir::LLVM::ZeroOp::create(rewriter, loc,
+ converter->convertType(attr.getType()));
}
// This class handles rewriting initializer attributes for types that do not
@@ -666,8 +672,8 @@ mlir::LogicalResult CIRToLLVMAssumeAlignedOpLowering::matchAndRewrite(
mlir::LogicalResult CIRToLLVMAssumeSepStorageOpLowering::matchAndRewrite(
cir::AssumeSepStorageOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
- auto cond = rewriter.create<mlir::LLVM::ConstantOp>(op.getLoc(),
- rewriter.getI1Type(), 1);
+ auto cond = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(),
+ rewriter.getI1Type(), 1);
rewriter.replaceOpWithNewOp<mlir::LLVM::AssumeOp>(
op, cond, mlir::LLVM::AssumeSeparateStorageTag{}, adaptor.getPtr1(),
adaptor.getPtr2());
@@ -914,28 +920,28 @@ mlir::LogicalResult CIRToLLVMAtomicFetchOpLowering::matchAndRewrite(
mlir::LogicalResult CIRToLLVMBitClrsbOpLowering::matchAndRewrite(
cir::BitClrsbOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
- auto zero = rewriter.create<mlir::LLVM::ConstantOp>(
- op.getLoc(), adaptor.getInput().getType(), 0);
- auto isNeg = rewriter.create<mlir::LLVM::ICmpOp>(
- op.getLoc(),
+ auto zero = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(),
+ adaptor.getInput().getType(), 0);
+ auto isNeg = mlir::LLVM::ICmpOp::create(
+ rewriter, op.getLoc(),
mlir::LLVM::ICmpPredicateAttr::get(rewriter.getContext(),
mlir::LLVM::ICmpPredicate::slt),
adaptor.getInput(), zero);
- auto negOne = rewriter.create<mlir::LLVM::ConstantOp>(
- op.getLoc(), adaptor.getInput().getType(), -1);
- auto flipped = rewriter.create<mlir::LLVM::XOrOp>(op.getLoc(),
- adaptor.getInput(), negOne);
+ auto negOne = mlir::LLVM::ConstantOp::create(
+ rewriter, op.getLoc(), adaptor.getInput().getType(), -1);
+ auto flipped = mlir::LLVM::XOrOp::create(rewriter, op.getLoc(),
+ adaptor.getInput(), negOne);
- auto select = rewriter.create<mlir::LLVM::SelectOp>(
- op.getLoc(), isNeg, flipped, adaptor.getInput());
+ auto select = mlir::LLVM::SelectOp::create(rewriter, op.getLoc(), isNeg,
+ flipped, adaptor.getInput());
auto resTy = getTypeConverter()->convertType(op.getType());
- auto clz = rewriter.create<mlir::LLVM::CountLeadingZerosOp>(
- op.getLoc(), resTy, select, /*is_zero_poison=*/false);
+ auto clz = mlir::LLVM::CountLeadingZerosOp::create(
+ rewriter, op.getLoc(), resTy, select, /*is_zero_poison=*/false);
- auto one = rewriter.create<mlir::LLVM::ConstantOp>(op.getLoc(), resTy, 1);
- auto res = rewriter.create<mlir::LLVM::SubOp>(op.getLoc(), clz, one);
+ auto one = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(), resTy, 1);
+ auto res = mlir::LLVM::SubOp::create(rewriter, op.getLoc(), clz, one);
rewriter.replaceOp(op, res);
return mlir::LogicalResult::success();
@@ -945,8 +951,8 @@ mlir::LogicalResult CIRToLLVMBitClzOpLowering::matchAndRewrite(
cir::BitClzOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
auto resTy = getTypeConverter()->convertType(op.getType());
- auto llvmOp = rewriter.create<mlir::LLVM::CountLeadingZerosOp>(
- op.getLoc(), resTy, adaptor.getInput(), op.getPoisonZero());
+ auto llvmOp = mlir::LLVM::CountLeadingZerosOp::create(
+ rewriter, op.getLoc(), resTy, adaptor.getInput(), op.getPoisonZero());
rewriter.replaceOp(op, llvmOp);
return mlir::LogicalResult::success();
}
@@ -955,8 +961,8 @@ mlir::LogicalResult CIRToLLVMBitCtzOpLowering::matchAndRewrite(
cir::BitCtzOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
auto resTy = getTypeConverter()->convertType(op.getType());
- auto llvmOp = rewriter.create<mlir::LLVM::CountTrailingZerosOp>(
- op.getLoc(), resTy, adaptor.getInput(), op.getPoisonZero());
+ auto llvmOp = mlir::LLVM::CountTrailingZerosOp::create(
+ rewriter, op.getLoc(), resTy, adaptor.getInput(), op.getPoisonZero());
rewriter.replaceOp(op, llvmOp);
return mlir::LogicalResult::success();
}
@@ -965,23 +971,24 @@ mlir::LogicalResult CIRToLLVMBitFfsOpLowering::matchAndRewrite(
cir::BitFfsOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
auto resTy = getTypeConverter()->convertType(op.getType());
- auto ctz = rewriter.create<mlir::LLVM::CountTrailingZerosOp>(
- op.getLoc(), resTy, adaptor.getInput(), /*is_zero_poison=*/true);
+ auto ctz = mlir::LLVM::CountTrailingZerosOp::create(rewriter, op.getLoc(),
+ resTy, adaptor.getInput(),
+ /*is_zero_poison=*/true);
- auto one = rewriter.create<mlir::LLVM::ConstantOp>(op.getLoc(), resTy, 1);
- auto ctzAddOne = rewriter.create<mlir::LLVM::AddOp>(op.getLoc(), ctz, one);
+ auto one = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(), resTy, 1);
+ auto ctzAddOne = mlir::LLVM::AddOp::create(rewriter, op.getLoc(), ctz, one);
- auto zeroInputTy = rewriter.create<mlir::LLVM::ConstantOp>(
- op.getLoc(), adaptor.getInput().getType(), 0);
- auto isZero = rewriter.create<mlir::LLVM::ICmpOp>(
- op.getLoc(),
+ auto zeroInputTy = mlir::LLVM::ConstantOp::create(
+ rewriter, op.getLoc(), adaptor.getInput().getType(), 0);
+ auto isZero = mlir::LLVM::ICmpOp::create(
+ rewriter, op.getLoc(),
mlir::LLVM::ICmpPredicateAttr::get(rewriter.getContext(),
mlir::LLVM::ICmpPredicate::eq),
adaptor.getInput(), zeroInputTy);
- auto zero = rewriter.create<mlir::LLVM::ConstantOp>(op.getLoc(), resTy, 0);
- auto res = rewriter.create<mlir::LLVM::SelectOp>(op.getLoc(), isZero, zero,
- ctzAddOne);
+ auto zero = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(), resTy, 0);
+ auto res = mlir::LLVM::SelectOp::create(rewriter, op.getLoc(), isZero, zero,
+ ctzAddOne);
rewriter.replaceOp(op, res);
return mlir::LogicalResult::success();
@@ -991,12 +998,12 @@ mlir::LogicalResult CIRToLLVMBitParityOpLowering::matchAndRewrite(
cir::BitParityOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
auto resTy = getTypeConverter()->convertType(op.getType());
- auto popcnt = rewriter.create<mlir::LLVM::CtPopOp>(op.getLoc(), resTy,
- adaptor.getInput());
+ auto popcnt = mlir::LLVM::CtPopOp::create(rewriter, op.getLoc(), resTy,
+ adaptor.getInput());
- auto one = rewriter.create<mlir::LLVM::ConstantOp>(op.getLoc(), resTy, 1);
+ auto one = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(), resTy, 1);
auto popcntMod2 =
- rewriter.create<mlir::LLVM::AndOp>(op.getLoc(), popcnt, one);
+ mlir::LLVM::AndOp::create(rewriter, op.getLoc(), popcnt, one);
rewriter.replaceOp(op, popcntMod2);
return mlir::LogicalResult::success();
@@ -1006,8 +1013,8 @@ mlir::LogicalResult CIRToLLVMBitPopcountOpLowering::matchAndRewrite(
cir::BitPopcountOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
auto resTy = getTypeConverter()->convertType(op.getType());
- auto llvmOp = rewriter.create<mlir::LLVM::CtPopOp>(op.getLoc(), resTy,
- adaptor.getInput());
+ auto llvmOp = mlir::LLVM::CtPopOp::create(rewriter, op.getLoc(), resTy,
+ adaptor.getInput());
rewriter.replaceOp(op, llvmOp);
return mlir::LogicalResult::success();
}
@@ -1067,8 +1074,8 @@ mlir::LogicalResult CIRToLLVMCastOpLowering::matchAndRewrite(
}
case cir::CastKind::int_to_bool: {
mlir::Value llvmSrcVal = adaptor.getSrc();
- mlir::Value zeroInt = rewriter.create<mlir::LLVM::ConstantOp>(
- castOp.getLoc(), llvmSrcVal.getType(), 0);
+ mlir::Value zeroInt = mlir::LLVM::ConstantOp::create(
+ rewriter, castOp.getLoc(), llvmSrcVal.getType(), 0);
rewriter.replaceOpWithNewOp<mlir::LLVM::ICmpOp>(
castOp, mlir::LLVM::ICmpPredicate::ne, llvmSrcVal, zeroInt);
break;
@@ -1132,8 +1139,8 @@ mlir::LogicalResult CIRToLLVMCastOpLowering::matchAndRewrite(
auto kind = mlir::LLVM::FCmpPredicate::une;
// Check if float is not equal to zero.
- auto zeroFloat = rewriter.create<mlir::LLVM::ConstantOp>(
- castOp.getLoc(), llvmSrcVal.getType(),
+ auto zeroFloat = mlir::LLVM::ConstantOp::create(
+ rewriter, castOp.getLoc(), llvmSrcVal.getType(),
mlir::FloatAttr::get(llvmSrcVal.getType(), 0.0));
// Extend comparison result to either bool (C++) or int (C).
@@ -1204,8 +1211,8 @@ mlir::LogicalResult CIRToLLVMCastOpLowering::matchAndRewrite(
}
case cir::CastKind::ptr_to_bool: {
mlir::Value llvmSrcVal = adaptor.getSrc();
- mlir::Value zeroPtr = rewriter.create<mlir::LLVM::ZeroOp>(
- castOp.getLoc(), llvmSrcVal.getType());
+ mlir::Value zeroPtr = mlir::LLVM::ZeroOp::create(rewriter, castOp.getLoc(),
+ llvmSrcVal.getType());
rewriter.replaceOpWithNewOp<mlir::LLVM::ICmpOp>(
castOp, mlir::LLVM::ICmpPredicate::ne, llvmSrcVal, zeroPtr);
break;
@@ -1275,10 +1282,10 @@ mlir::LogicalResult CIRToLLVMPtrStrideOpLowering::matchAndRewrite(
// Rewrite the sub in front of extensions/trunc
if (rewriteSub) {
- index = rewriter.create<mlir::LLVM::SubOp>(
- index.getLoc(), index.getType(),
- rewriter.create<mlir::LLVM::ConstantOp>(index.getLoc(),
- index.getType(), 0),
+ index = mlir::LLVM::SubOp::create(
+ rewriter, index.getLoc(), index.getType(),
+ mlir::LLVM::ConstantOp::create(rewriter, index.getLoc(),
+ index.getType(), 0),
index);
rewriter.eraseOp(sub);
}
@@ -1310,11 +1317,11 @@ mlir::LogicalResult CIRToLLVMBaseClassAddrOpLowering::matchAndRewrite(
baseClassOp, resultType, byteType, derivedAddr, offset);
} else {
auto loc = baseClassOp.getLoc();
- mlir::Value isNull = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::eq, derivedAddr,
- rewriter.create<mlir::LLVM::ZeroOp>(loc, derivedAddr.getType()));
- mlir::Value adjusted = rewriter.create<mlir::LLVM::GEPOp>(
- loc, resultType, byteType, derivedAddr, offset);
+ mlir::Value isNull = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::eq, derivedAddr,
+ mlir::LLVM::ZeroOp::create(rewriter, loc, derivedAddr.getType()));
+ mlir::Value adjusted = mlir::LLVM::GEPOp::create(
+ rewriter, loc, resultType, byteType, derivedAddr, offset);
rewriter.replaceOpWithNewOp<mlir::LLVM::SelectOp>(baseClassOp, isNull,
derivedAddr, adjusted);
}
@@ -1335,8 +1342,8 @@ mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite(
mlir::Value size =
op.isDynamic()
? adaptor.getDynAllocSize()
- : rewriter.create<mlir::LLVM::ConstantOp>(
- op.getLoc(),
+ : mlir::LLVM::ConstantOp::create(
+ rewriter, op.getLoc(),
typeConverter->convertType(rewriter.getIndexType()), 1);
mlir::Type elementTy =
convertTypeForMemory(*getTypeConverter(), dataLayout, op.getAllocaType());
@@ -1694,13 +1701,13 @@ mlir::LogicalResult CIRToLLVMPtrDiffOpLowering::matchAndRewrite(
auto dstTy = mlir::cast<cir::IntType>(op.getType());
mlir::Type llvmDstTy = getTypeConverter()->convertType(dstTy);
- auto lhs = rewriter.create<mlir::LLVM::PtrToIntOp>(op.getLoc(), llvmDstTy,
- adaptor.getLhs());
- auto rhs = rewriter.create<mlir::LLVM::PtrToIntOp>(op.getLoc(), llvmDstTy,
- adaptor.getRhs());
+ auto lhs = mlir::LLVM::PtrToIntOp::create(rewriter, op.getLoc(), llvmDstTy,
+ adaptor.getLhs());
+ auto rhs = mlir::LLVM::PtrToIntOp::create(rewriter, op.getLoc(), llvmDstTy,
+ adaptor.getRhs());
auto diff =
- rewriter.create<mlir::LLVM::SubOp>(op.getLoc(), llvmDstTy, lhs, rhs);
+ mlir::LLVM::SubOp::create(rewriter, op.getLoc(), llvmDstTy, lhs, rhs);
cir::PointerType ptrTy = op.getLhs().getType();
assert(!cir::MissingFeatures::llvmLoweringPtrDiffConsidersPointee());
@@ -1709,17 +1716,17 @@ mlir::LogicalResult CIRToLLVMPtrDiffOpLowering::matchAndRewrite(
// Avoid silly division by 1.
mlir::Value resultVal = diff.getResult();
if (typeSize != 1) {
- auto typeSizeVal = rewriter.create<mlir::LLVM::ConstantOp>(
- op.getLoc(), llvmDstTy, typeSize);
+ auto typeSizeVal = mlir::LLVM::ConstantOp::create(rewriter, op.getLoc(),
+ llvmDstTy, typeSize);
if (dstTy.isUnsigned()) {
auto uDiv =
- rewriter.create<mlir::LLVM::UDivOp>(op.getLoc(), diff, typeSizeVal);
+ mlir::LLVM::UDivOp::create(rewriter, op.getLoc(), diff, typeSizeVal);
uDiv.setIsExact(true);
resultVal = uDiv.getResult();
} else {
auto sDiv =
- rewriter.create<mlir::LLVM::SDivOp>(op.getLoc(), diff, typeSizeVal);
+ mlir::LLVM::SDivOp::create(rewriter, op.getLoc(), diff, typeSizeVal);
sDiv.setIsExact(true);
resultVal = sDiv.getResult();
}
@@ -1847,8 +1854,8 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite(
SmallVector<mlir::NamedAttribute, 4> attributes;
lowerFuncAttributes(op, /*filterArgAndResAttrs=*/false, attributes);
- mlir::LLVM::LLVMFuncOp fn = rewriter.create<mlir::LLVM::LLVMFuncOp>(
- loc, op.getName(), llvmFnTy, linkage, isDsoLocal, cconv,
+ mlir::LLVM::LLVMFuncOp fn = mlir::LLVM::LLVMFuncOp::create(
+ rewriter, loc, op.getName(), llvmFnTy, linkage, isDsoLocal, cconv,
mlir::SymbolRefAttr(), attributes);
assert(!cir::MissingFeatures::opFuncMultipleReturnVals());
@@ -1884,8 +1891,8 @@ mlir::LogicalResult CIRToLLVMGetGlobalOpLowering::matchAndRewrite(
}
mlir::Type type = getTypeConverter()->convertType(op.getType());
- mlir::Operation *newop =
- rewriter.create<mlir::LLVM::AddressOfOp>(op.getLoc(), type, op.getName());
+ mlir::Operation *newop = mlir::LLVM::AddressOfOp::create(
+ rewriter, op.getLoc(), type, op.getName());
assert(!cir::MissingFeatures::opGlobalThreadLocal());
@@ -1941,7 +1948,7 @@ CIRToLLVMGlobalOpLowering::matchAndRewriteRegionInitializedGlobal(
setupRegionInitializedLLVMGlobalOp(op, rewriter);
CIRAttrToValue valueConverter(op, rewriter, typeConverter);
mlir::Value value = valueConverter.visit(init);
- rewriter.create<mlir::LLVM::ReturnOp>(loc, value);
+ mlir::LLVM::ReturnOp::create(rewriter, loc, value);
return mlir::success();
}
@@ -2094,14 +2101,14 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
switch (op.getKind()) {
case cir::UnaryOpKind::Inc: {
assert(!isVector && "++ not allowed on vector types");
- auto one = rewriter.create<mlir::LLVM::ConstantOp>(loc, llvmType, 1);
+ auto one = mlir::LLVM::ConstantOp::create(rewriter, loc, llvmType, 1);
rewriter.replaceOpWithNewOp<mlir::LLVM::AddOp>(
op, llvmType, adaptor.getInput(), one, maybeNSW);
return mlir::success();
}
case cir::UnaryOpKind::Dec: {
assert(!isVector && "-- not allowed on vector types");
- auto one = rewriter.create<mlir::LLVM::ConstantOp>(loc, llvmType, 1);
+ auto one = mlir::LLVM::ConstantOp::create(rewriter, loc, llvmType, 1);
rewriter.replaceOpWithNewOp<mlir::LLVM::SubOp>(op, adaptor.getInput(),
one, maybeNSW);
return mlir::success();
@@ -2112,9 +2119,9 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
case cir::UnaryOpKind::Minus: {
mlir::Value zero;
if (isVector)
- zero = rewriter.create<mlir::LLVM::ZeroOp>(loc, llvmType);
+ zero = mlir::LLVM::ZeroOp::create(rewriter, loc, llvmType);
else
- zero = rewriter.create<mlir::LLVM::ConstantOp>(loc, llvmType, 0);
+ zero = mlir::LLVM::ConstantOp::create(rewriter, loc, llvmType, 0);
rewriter.replaceOpWithNewOp<mlir::LLVM::SubOp>(
op, zero, adaptor.getInput(), maybeNSW);
return mlir::success();
@@ -2128,9 +2135,9 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
std::vector<int32_t> values(numElements, -1);
mlir::DenseIntElementsAttr denseVec = rewriter.getI32VectorAttr(values);
minusOne =
- rewriter.create<mlir::LLVM::ConstantOp>(loc, llvmType, denseVec);
+ mlir::LLVM::ConstantOp::create(rewriter, loc, llvmType, denseVec);
} else {
- minusOne = rewriter.create<mlir::LLVM::ConstantOp>(loc, llvmType, -1);
+ minusOne = mlir::LLVM::ConstantOp::create(rewriter, loc, llvmType, -1);
}
rewriter.replaceOpWithNewOp<mlir::LLVM::XOrOp>(op, adaptor.getInput(),
minusOne);
@@ -2145,16 +2152,16 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
switch (op.getKind()) {
case cir::UnaryOpKind::Inc: {
assert(!isVector && "++ not allowed on vector types");
- mlir::LLVM::ConstantOp one = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, llvmType, rewriter.getFloatAttr(llvmType, 1.0));
+ mlir::LLVM::ConstantOp one = mlir::LLVM::ConstantOp::create(
+ rewriter, loc, llvmType, rewriter.getFloatAttr(llvmType, 1.0));
rewriter.replaceOpWithNewOp<mlir::LLVM::FAddOp>(op, llvmType, one,
adaptor.getInput());
return mlir::success();
}
case cir::UnaryOpKind::Dec: {
assert(!isVector && "-- not allowed on vector types");
- mlir::LLVM::ConstantOp minusOne = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, llvmType, rewriter.getFloatAttr(llvmType, -1.0));
+ mlir::LLVM::ConstantOp minusOne = mlir::LLVM::ConstantOp::create(
+ rewriter, loc, llvmType, rewriter.getFloatAttr(llvmType, -1.0));
rewriter.replaceOpWithNewOp<mlir::LLVM::FAddOp>(op, llvmType, minusOne,
adaptor.getInput());
return mlir::success();
@@ -2185,7 +2192,7 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
return op.emitError() << "Unsupported unary operation on boolean type";
case cir::UnaryOpKind::Not: {
assert(!isVector && "NYI: op! on vector mask");
- auto one = rewriter.create<mlir::LLVM::ConstantOp>(loc, llvmType, 1);
+ auto one = mlir::LLVM::ConstantOp::create(rewriter, loc, llvmType, 1);
rewriter.replaceOpWithNewOp<mlir::LLVM::XOrOp>(op, adaptor.getInput(),
one);
return mlir::success();
@@ -2404,6 +2411,15 @@ mlir::LogicalResult CIRToLLVMCmpOpLowering::matchAndRewrite(
return mlir::success();
}
+ if (auto vptrTy = mlir::dyn_cast<cir::VPtrType>(type)) {
+ // !cir.vptr is a special case, but it's just a pointer to LLVM.
+ auto kind = convertCmpKindToICmpPredicate(cmpOp.getKind(),
+ /* isSigned=*/false);
+ rewriter.replaceOpWithNewOp<mlir::LLVM::ICmpOp>(
+ cmpOp, kind, adaptor.getLhs(), adaptor.getRhs());
+ return mlir::success();
+ }
+
if (mlir::isa<cir::FPTypeInterface>(type)) {
mlir::LLVM::FCmpPredicate kind =
convertCmpKindToFCmpPredicate(cmpOp.getKind());
@@ -2421,47 +2437,47 @@ mlir::LogicalResult CIRToLLVMCmpOpLowering::matchAndRewrite(
mlir::Type complexElemTy =
getTypeConverter()->convertType(complexType.getElementType());
- auto lhsReal =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, lhs, 0);
- auto lhsImag =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, lhs, 1);
- auto rhsReal =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, rhs, 0);
- auto rhsImag =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, rhs, 1);
+ auto lhsReal = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, lhs, ArrayRef(int64_t{0}));
+ auto lhsImag = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, lhs, ArrayRef(int64_t{1}));
+ auto rhsReal = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, rhs, ArrayRef(int64_t{0}));
+ auto rhsImag = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, rhs, ArrayRef(int64_t{1}));
if (cmpOp.getKind() == cir::CmpOpKind::eq) {
if (complexElemTy.isInteger()) {
- auto realCmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::eq, lhsReal, rhsReal);
- auto imagCmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::eq, lhsImag, rhsImag);
+ auto realCmp = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::eq, lhsReal, rhsReal);
+ auto imagCmp = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::eq, lhsImag, rhsImag);
rewriter.replaceOpWithNewOp<mlir::LLVM::AndOp>(cmpOp, realCmp, imagCmp);
return mlir::success();
}
- auto realCmp = rewriter.create<mlir::LLVM::FCmpOp>(
- loc, mlir::LLVM::FCmpPredicate::oeq, lhsReal, rhsReal);
- auto imagCmp = rewriter.create<mlir::LLVM::FCmpOp>(
- loc, mlir::LLVM::FCmpPredicate::oeq, lhsImag, rhsImag);
+ auto realCmp = mlir::LLVM::FCmpOp::create(
+ rewriter, loc, mlir::LLVM::FCmpPredicate::oeq, lhsReal, rhsReal);
+ auto imagCmp = mlir::LLVM::FCmpOp::create(
+ rewriter, loc, mlir::LLVM::FCmpPredicate::oeq, lhsImag, rhsImag);
rewriter.replaceOpWithNewOp<mlir::LLVM::AndOp>(cmpOp, realCmp, imagCmp);
return mlir::success();
}
if (cmpOp.getKind() == cir::CmpOpKind::ne) {
if (complexElemTy.isInteger()) {
- auto realCmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::ne, lhsReal, rhsReal);
- auto imagCmp = rewriter.create<mlir::LLVM::ICmpOp>(
- loc, mlir::LLVM::ICmpPredicate::ne, lhsImag, rhsImag);
+ auto realCmp = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::ne, lhsReal, rhsReal);
+ auto imagCmp = mlir::LLVM::ICmpOp::create(
+ rewriter, loc, mlir::LLVM::ICmpPredicate::ne, lhsImag, rhsImag);
rewriter.replaceOpWithNewOp<mlir::LLVM::OrOp>(cmpOp, realCmp, imagCmp);
return mlir::success();
}
- auto realCmp = rewriter.create<mlir::LLVM::FCmpOp>(
- loc, mlir::LLVM::FCmpPredicate::une, lhsReal, rhsReal);
- auto imagCmp = rewriter.create<mlir::LLVM::FCmpOp>(
- loc, mlir::LLVM::FCmpPredicate::une, lhsImag, rhsImag);
+ auto realCmp = mlir::LLVM::FCmpOp::create(
+ rewriter, loc, mlir::LLVM::FCmpPredicate::une, lhsReal, rhsReal);
+ auto imagCmp = mlir::LLVM::FCmpOp::create(
+ rewriter, loc, mlir::LLVM::FCmpPredicate::une, lhsImag, rhsImag);
rewriter.replaceOpWithNewOp<mlir::LLVM::OrOp>(cmpOp, realCmp, imagCmp);
return mlir::success();
}
@@ -2725,7 +2741,7 @@ static void buildCtorDtorList(
index);
}
- builder.create<mlir::LLVM::ReturnOp>(loc, result);
+ mlir::LLVM::ReturnOp::create(builder, loc, result);
}
// The applyPartialConversion function traverses blocks in the dominance order,
@@ -2904,7 +2920,7 @@ void createLLVMFuncOpIfNotExist(mlir::ConversionPatternRewriter &rewriter,
if (!sourceSymbol) {
mlir::OpBuilder::InsertionGuard guard(rewriter);
rewriter.setInsertionPoint(enclosingFnOp);
- rewriter.create<mlir::LLVM::LLVMFuncOp>(srcOp->getLoc(), fnName, fnTy);
+ mlir::LLVM::LLVMFuncOp::create(rewriter, srcOp->getLoc(), fnName, fnTy);
}
}
@@ -2983,12 +2999,12 @@ mlir::LogicalResult CIRToLLVMTrapOpLowering::matchAndRewrite(
mlir::Location loc = op->getLoc();
rewriter.eraseOp(op);
- rewriter.create<mlir::LLVM::Trap>(loc);
+ mlir::LLVM::Trap::create(rewriter, loc);
// Note that the call to llvm.trap is not a terminator in LLVM dialect.
// So we must emit an additional llvm.unreachable to terminate the current
// block.
- rewriter.create<mlir::LLVM::UnreachableOp>(loc);
+ mlir::LLVM::UnreachableOp::create(rewriter, loc);
return mlir::success();
}
@@ -3114,15 +3130,15 @@ mlir::LogicalResult CIRToLLVMVecCreateOpLowering::matchAndRewrite(
const auto vecTy = mlir::cast<cir::VectorType>(op.getType());
const mlir::Type llvmTy = typeConverter->convertType(vecTy);
const mlir::Location loc = op.getLoc();
- mlir::Value result = rewriter.create<mlir::LLVM::PoisonOp>(loc, llvmTy);
+ mlir::Value result = mlir::LLVM::PoisonOp::create(rewriter, loc, llvmTy);
assert(vecTy.getSize() == op.getElements().size() &&
"cir.vec.create op count doesn't match vector type elements count");
for (uint64_t i = 0; i < vecTy.getSize(); ++i) {
const mlir::Value indexValue =
- rewriter.create<mlir::LLVM::ConstantOp>(loc, rewriter.getI64Type(), i);
- result = rewriter.create<mlir::LLVM::InsertElementOp>(
- loc, result, adaptor.getElements()[i], indexValue);
+ mlir::LLVM::ConstantOp::create(rewriter, loc, rewriter.getI64Type(), i);
+ result = mlir::LLVM::InsertElementOp::create(
+ rewriter, loc, result, adaptor.getElements()[i], indexValue);
}
rewriter.replaceOp(op, result);
@@ -3151,13 +3167,13 @@ mlir::LogicalResult CIRToLLVMVecCmpOpLowering::matchAndRewrite(
mlir::Type elementType = elementTypeIfVector(op.getLhs().getType());
mlir::Value bitResult;
if (auto intType = mlir::dyn_cast<cir::IntType>(elementType)) {
- bitResult = rewriter.create<mlir::LLVM::ICmpOp>(
- op.getLoc(),
+ bitResult = mlir::LLVM::ICmpOp::create(
+ rewriter, op.getLoc(),
convertCmpKindToICmpPredicate(op.getKind(), intType.isSigned()),
adaptor.getLhs(), adaptor.getRhs());
} else if (mlir::isa<cir::FPTypeInterface>(elementType)) {
- bitResult = rewriter.create<mlir::LLVM::FCmpOp>(
- op.getLoc(), convertCmpKindToFCmpPredicate(op.getKind()),
+ bitResult = mlir::LLVM::FCmpOp::create(
+ rewriter, op.getLoc(), convertCmpKindToFCmpPredicate(op.getKind()),
adaptor.getLhs(), adaptor.getRhs());
} else {
return op.emitError() << "unsupported type for VecCmpOp: " << elementType;
@@ -3181,7 +3197,7 @@ mlir::LogicalResult CIRToLLVMVecSplatOpLowering::matchAndRewrite(
cir::VectorType vecTy = op.getType();
mlir::Type llvmTy = typeConverter->convertType(vecTy);
mlir::Location loc = op.getLoc();
- mlir::Value poison = rewriter.create<mlir::LLVM::PoisonOp>(loc, llvmTy);
+ mlir::Value poison = mlir::LLVM::PoisonOp::create(rewriter, loc, llvmTy);
mlir::Value elementValue = adaptor.getValue();
if (elementValue.getDefiningOp<mlir::LLVM::PoisonOp>()) {
@@ -3210,9 +3226,9 @@ mlir::LogicalResult CIRToLLVMVecSplatOpLowering::matchAndRewrite(
}
mlir::Value indexValue =
- rewriter.create<mlir::LLVM::ConstantOp>(loc, rewriter.getI64Type(), 0);
- mlir::Value oneElement = rewriter.create<mlir::LLVM::InsertElementOp>(
- loc, poison, elementValue, indexValue);
+ mlir::LLVM::ConstantOp::create(rewriter, loc, rewriter.getI64Type(), 0);
+ mlir::Value oneElement = mlir::LLVM::InsertElementOp::create(
+ rewriter, loc, poison, elementValue, indexValue);
SmallVector<int32_t> zeroValues(vecTy.getSize(), 0);
rewriter.replaceOpWithNewOp<mlir::LLVM::ShuffleVectorOp>(op, oneElement,
poison, zeroValues);
@@ -3260,31 +3276,32 @@ mlir::LogicalResult CIRToLLVMVecShuffleDynamicOpLowering::matchAndRewrite(
mlir::cast<cir::VectorType>(op.getVec().getType()).getSize();
uint64_t maskBits = llvm::NextPowerOf2(numElements - 1) - 1;
- mlir::Value maskValue = rewriter.create<mlir::LLVM::ConstantOp>(
- loc, llvmIndexType, rewriter.getIntegerAttr(llvmIndexType, maskBits));
+ mlir::Value maskValue = mlir::LLVM::ConstantOp::create(
+ rewriter, loc, llvmIndexType,
+ rewriter.getIntegerAttr(llvmIndexType, maskBits));
mlir::Value maskVector =
- rewriter.create<mlir::LLVM::UndefOp>(loc, llvmIndexVecType);
+ mlir::LLVM::UndefOp::create(rewriter, loc, llvmIndexVecType);
for (uint64_t i = 0; i < numElements; ++i) {
mlir::Value idxValue =
- rewriter.create<mlir::LLVM::ConstantOp>(loc, rewriter.getI64Type(), i);
- maskVector = rewriter.create<mlir::LLVM::InsertElementOp>(
- loc, maskVector, maskValue, idxValue);
+ mlir::LLVM::ConstantOp::create(rewriter, loc, rewriter.getI64Type(), i);
+ maskVector = mlir::LLVM::InsertElementOp::create(rewriter, loc, maskVector,
+ maskValue, idxValue);
}
- mlir::Value maskedIndices = rewriter.create<mlir::LLVM::AndOp>(
- loc, llvmIndexVecType, adaptor.getIndices(), maskVector);
- mlir::Value result = rewriter.create<mlir::LLVM::UndefOp>(
- loc, getTypeConverter()->convertType(op.getVec().getType()));
+ mlir::Value maskedIndices = mlir::LLVM::AndOp::create(
+ rewriter, loc, llvmIndexVecType, adaptor.getIndices(), maskVector);
+ mlir::Value result = mlir::LLVM::UndefOp::create(
+ rewriter, loc, getTypeConverter()->convertType(op.getVec().getType()));
for (uint64_t i = 0; i < numElements; ++i) {
mlir::Value iValue =
- rewriter.create<mlir::LLVM::ConstantOp>(loc, rewriter.getI64Type(), i);
- mlir::Value indexValue = rewriter.create<mlir::LLVM::ExtractElementOp>(
- loc, maskedIndices, iValue);
+ mlir::LLVM::ConstantOp::create(rewriter, loc, rewriter.getI64Type(), i);
+ mlir::Value indexValue = mlir::LLVM::ExtractElementOp::create(
+ rewriter, loc, maskedIndices, iValue);
mlir::Value valueAtIndex =
- rewriter.create<mlir::LLVM::ExtractElementOp>(loc, input, indexValue);
- result = rewriter.create<mlir::LLVM::InsertElementOp>(loc, result,
- valueAtIndex, iValue);
+ mlir::LLVM::ExtractElementOp::create(rewriter, loc, input, indexValue);
+ result = mlir::LLVM::InsertElementOp::create(rewriter, loc, result,
+ valueAtIndex, iValue);
}
rewriter.replaceOp(op, result);
return mlir::success();
@@ -3294,10 +3311,10 @@ mlir::LogicalResult CIRToLLVMVecTernaryOpLowering::matchAndRewrite(
cir::VecTernaryOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
// Convert `cond` into a vector of i1, then use that in a `select` op.
- mlir::Value bitVec = rewriter.create<mlir::LLVM::ICmpOp>(
- op.getLoc(), mlir::LLVM::ICmpPredicate::ne, adaptor.getCond(),
- rewriter.create<mlir::LLVM::ZeroOp>(
- op.getCond().getLoc(),
+ mlir::Value bitVec = mlir::LLVM::ICmpOp::create(
+ rewriter, op.getLoc(), mlir::LLVM::ICmpPredicate::ne, adaptor.getCond(),
+ mlir::LLVM::ZeroOp::create(
+ rewriter, op.getCond().getLoc(),
typeConverter->convertType(op.getCond().getType())));
rewriter.replaceOpWithNewOp<mlir::LLVM::SelectOp>(
op, bitVec, adaptor.getLhs(), adaptor.getRhs());
@@ -3314,41 +3331,41 @@ mlir::LogicalResult CIRToLLVMComplexAddOpLowering::matchAndRewrite(
auto complexType = mlir::cast<cir::ComplexType>(op.getLhs().getType());
mlir::Type complexElemTy =
getTypeConverter()->convertType(complexType.getElementType());
- auto lhsReal =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, lhs, 0);
- auto lhsImag =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, lhs, 1);
- auto rhsReal =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, rhs, 0);
- auto rhsImag =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, rhs, 1);
+ auto lhsReal = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, lhs, ArrayRef(int64_t{0}));
+ auto lhsImag = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, lhs, ArrayRef(int64_t{1}));
+ auto rhsReal = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, rhs, ArrayRef(int64_t{0}));
+ auto rhsImag = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, rhs, ArrayRef(int64_t{1}));
mlir::Value newReal;
mlir::Value newImag;
if (complexElemTy.isInteger()) {
- newReal = rewriter.create<mlir::LLVM::AddOp>(loc, complexElemTy, lhsReal,
- rhsReal);
- newImag = rewriter.create<mlir::LLVM::AddOp>(loc, complexElemTy, lhsImag,
- rhsImag);
+ newReal = mlir::LLVM::AddOp::create(rewriter, loc, complexElemTy, lhsReal,
+ rhsReal);
+ newImag = mlir::LLVM::AddOp::create(rewriter, loc, complexElemTy, lhsImag,
+ rhsImag);
} else {
assert(!cir::MissingFeatures::fastMathFlags());
assert(!cir::MissingFeatures::fpConstraints());
- newReal = rewriter.create<mlir::LLVM::FAddOp>(loc, complexElemTy, lhsReal,
- rhsReal);
- newImag = rewriter.create<mlir::LLVM::FAddOp>(loc, complexElemTy, lhsImag,
- rhsImag);
+ newReal = mlir::LLVM::FAddOp::create(rewriter, loc, complexElemTy, lhsReal,
+ rhsReal);
+ newImag = mlir::LLVM::FAddOp::create(rewriter, loc, complexElemTy, lhsImag,
+ rhsImag);
}
mlir::Type complexLLVMTy =
getTypeConverter()->convertType(op.getResult().getType());
auto initialComplex =
- rewriter.create<mlir::LLVM::PoisonOp>(op->getLoc(), complexLLVMTy);
+ mlir::LLVM::PoisonOp::create(rewriter, op->getLoc(), complexLLVMTy);
- auto realComplex = rewriter.create<mlir::LLVM::InsertValueOp>(
- op->getLoc(), initialComplex, newReal, 0);
+ auto realComplex = mlir::LLVM::InsertValueOp::create(
+ rewriter, op->getLoc(), initialComplex, newReal, ArrayRef(int64_t{0}));
- rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(op, realComplex,
- newImag, 1);
+ rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
+ op, realComplex, newImag, ArrayRef(int64_t{1}));
return mlir::success();
}
@@ -3359,13 +3376,15 @@ mlir::LogicalResult CIRToLLVMComplexCreateOpLowering::matchAndRewrite(
mlir::Type complexLLVMTy =
getTypeConverter()->convertType(op.getResult().getType());
auto initialComplex =
- rewriter.create<mlir::LLVM::UndefOp>(op->getLoc(), complexLLVMTy);
+ mlir::LLVM::UndefOp::create(rewriter, op->getLoc(), complexLLVMTy);
- auto realComplex = rewriter.create<mlir::LLVM::InsertValueOp>(
- op->getLoc(), initialComplex, adaptor.getReal(), 0);
+ auto realComplex = mlir::LLVM::InsertValueOp::create(
+ rewriter, op->getLoc(), initialComplex, adaptor.getReal(),
+ ArrayRef(int64_t{0}));
- auto complex = rewriter.create<mlir::LLVM::InsertValueOp>(
- op->getLoc(), realComplex, adaptor.getImag(), 1);
+ auto complex = mlir::LLVM::InsertValueOp::create(
+ rewriter, op->getLoc(), realComplex, adaptor.getImag(),
+ ArrayRef(int64_t{1}));
rewriter.replaceOp(op, complex);
return mlir::success();
@@ -3395,41 +3414,41 @@ mlir::LogicalResult CIRToLLVMComplexSubOpLowering::matchAndRewrite(
auto complexType = mlir::cast<cir::ComplexType>(op.getLhs().getType());
mlir::Type complexElemTy =
getTypeConverter()->convertType(complexType.getElementType());
- auto lhsReal =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, lhs, 0);
- auto lhsImag =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, lhs, 1);
- auto rhsReal =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, rhs, 0);
- auto rhsImag =
- rewriter.create<mlir::LLVM::ExtractValueOp>(loc, complexElemTy, rhs, 1);
+ auto lhsReal = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, lhs, ArrayRef(int64_t{0}));
+ auto lhsImag = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, lhs, ArrayRef(int64_t{1}));
+ auto rhsReal = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, rhs, ArrayRef(int64_t{0}));
+ auto rhsImag = mlir::LLVM::ExtractValueOp::create(
+ rewriter, loc, complexElemTy, rhs, ArrayRef(int64_t{1}));
mlir::Value newReal;
mlir::Value newImag;
if (complexElemTy.isInteger()) {
- newReal = rewriter.create<mlir::LLVM::SubOp>(loc, complexElemTy, lhsReal,
- rhsReal);
- newImag = rewriter.create<mlir::LLVM::SubOp>(loc, complexElemTy, lhsImag,
- rhsImag);
+ newReal = mlir::LLVM::SubOp::create(rewriter, loc, complexElemTy, lhsReal,
+ rhsReal);
+ newImag = mlir::LLVM::SubOp::create(rewriter, loc, complexElemTy, lhsImag,
+ rhsImag);
} else {
assert(!cir::MissingFeatures::fastMathFlags());
assert(!cir::MissingFeatures::fpConstraints());
- newReal = rewriter.create<mlir::LLVM::FSubOp>(loc, complexElemTy, lhsReal,
- rhsReal);
- newImag = rewriter.create<mlir::LLVM::FSubOp>(loc, complexElemTy, lhsImag,
- rhsImag);
+ newReal = mlir::LLVM::FSubOp::create(rewriter, loc, complexElemTy, lhsReal,
+ rhsReal);
+ newImag = mlir::LLVM::FSubOp::create(rewriter, loc, complexElemTy, lhsImag,
+ rhsImag);
}
mlir::Type complexLLVMTy =
getTypeConverter()->convertType(op.getResult().getType());
auto initialComplex =
- rewriter.create<mlir::LLVM::PoisonOp>(op->getLoc(), complexLLVMTy);
+ mlir::LLVM::PoisonOp::create(rewriter, op->getLoc(), complexLLVMTy);
- auto realComplex = rewriter.create<mlir::LLVM::InsertValueOp>(
- op->getLoc(), initialComplex, newReal, 0);
+ auto realComplex = mlir::LLVM::InsertValueOp::create(
+ rewriter, op->getLoc(), initialComplex, newReal, ArrayRef(int64_t{0}));
- rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(op, realComplex,
- newImag, 1);
+ rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
+ op, realComplex, newImag, ArrayRef(int64_t{1}));
return mlir::success();
}
@@ -3496,8 +3515,8 @@ mlir::LogicalResult CIRToLLVMSetBitfieldOpLowering::matchAndRewrite(
if (storageSize != size) {
assert(storageSize > size && "Invalid bitfield size.");
- mlir::Value val = rewriter.create<mlir::LLVM::LoadOp>(
- op.getLoc(), intType, adaptor.getAddr(), op.getAlignment(),
+ mlir::Value val = mlir::LLVM::LoadOp::create(
+ rewriter, op.getLoc(), intType, adaptor.getAddr(), op.getAlignment(),
op.getIsVolatile());
srcVal =
@@ -3510,11 +3529,11 @@ mlir::LogicalResult CIRToLLVMSetBitfieldOpLowering::matchAndRewrite(
~llvm::APInt::getBitsSet(srcWidth, offset, offset + size));
// Or together the unchanged values and the source value.
- srcVal = rewriter.create<mlir::LLVM::OrOp>(op.getLoc(), val, srcVal);
+ srcVal = mlir::LLVM::OrOp::create(rewriter, op.getLoc(), val, srcVal);
}
- rewriter.create<mlir::LLVM::StoreOp>(op.getLoc(), srcVal, adaptor.getAddr(),
- op.getAlignment(), op.getIsVolatile());
+ mlir::LLVM::StoreOp::create(rewriter, op.getLoc(), srcVal, adaptor.getAddr(),
+ op.getAlignment(), op.getIsVolatile());
mlir::Type resultTy = getTypeConverter()->convertType(op.getType());
@@ -3587,10 +3606,10 @@ mlir::LogicalResult CIRToLLVMGetBitfieldOpLowering::matchAndRewrite(
mlir::IntegerType intType =
computeBitfieldIntType(storageType, context, storageSize);
- mlir::Value val = rewriter.create<mlir::LLVM::LoadOp>(
- op.getLoc(), intType, adaptor.getAddr(), op.getAlignment(),
+ mlir::Value val = mlir::LLVM::LoadOp::create(
+ rewriter, op.getLoc(), intType, adaptor.getAddr(), op.getAlignment(),
op.getIsVolatile());
- val = rewriter.create<mlir::LLVM::BitcastOp>(op.getLoc(), intType, val);
+ val = mlir::LLVM::BitcastOp::create(rewriter, op.getLoc(), intType, val);
if (info.getIsSigned()) {
assert(static_cast<unsigned>(offset + size) <= storageSize);
diff --git a/clang/lib/CIR/Lowering/LoweringHelpers.cpp b/clang/lib/CIR/Lowering/LoweringHelpers.cpp
index d5f1324..0786579 100644
--- a/clang/lib/CIR/Lowering/LoweringHelpers.cpp
+++ b/clang/lib/CIR/Lowering/LoweringHelpers.cpp
@@ -148,37 +148,37 @@ lowerConstArrayAttr(cir::ConstArrayAttr constArr,
mlir::Value getConstAPInt(mlir::OpBuilder &bld, mlir::Location loc,
mlir::Type typ, const llvm::APInt &val) {
- return bld.create<mlir::LLVM::ConstantOp>(loc, typ, val);
+ return mlir::LLVM::ConstantOp::create(bld, loc, typ, val);
}
mlir::Value getConst(mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ,
unsigned val) {
- return bld.create<mlir::LLVM::ConstantOp>(loc, typ, val);
+ return mlir::LLVM::ConstantOp::create(bld, loc, typ, val);
}
mlir::Value createShL(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs) {
if (!rhs)
return lhs;
mlir::Value rhsVal = getConst(bld, lhs.getLoc(), lhs.getType(), rhs);
- return bld.create<mlir::LLVM::ShlOp>(lhs.getLoc(), lhs, rhsVal);
+ return mlir::LLVM::ShlOp::create(bld, lhs.getLoc(), lhs, rhsVal);
}
mlir::Value createAShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs) {
if (!rhs)
return lhs;
mlir::Value rhsVal = getConst(bld, lhs.getLoc(), lhs.getType(), rhs);
- return bld.create<mlir::LLVM::AShrOp>(lhs.getLoc(), lhs, rhsVal);
+ return mlir::LLVM::AShrOp::create(bld, lhs.getLoc(), lhs, rhsVal);
}
mlir::Value createAnd(mlir::OpBuilder &bld, mlir::Value lhs,
const llvm::APInt &rhs) {
mlir::Value rhsVal = getConstAPInt(bld, lhs.getLoc(), lhs.getType(), rhs);
- return bld.create<mlir::LLVM::AndOp>(lhs.getLoc(), lhs, rhsVal);
+ return mlir::LLVM::AndOp::create(bld, lhs.getLoc(), lhs, rhsVal);
}
mlir::Value createLShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs) {
if (!rhs)
return lhs;
mlir::Value rhsVal = getConst(bld, lhs.getLoc(), lhs.getType(), rhs);
- return bld.create<mlir::LLVM::LShrOp>(lhs.getLoc(), lhs, rhsVal);
+ return mlir::LLVM::LShrOp::create(bld, lhs.getLoc(), lhs, rhsVal);
}