@@ -914,6 +914,24 @@ mlir::LogicalResult CIRToLLVMDerivedClassAddrOpLowering::matchAndRewrite(
914
914
return mlir::success ();
915
915
}
916
916
917
+ mlir::LogicalResult CIRToLLVMBaseDataMemberOpLowering::matchAndRewrite (
918
+ cir::BaseDataMemberOp op, OpAdaptor adaptor,
919
+ mlir::ConversionPatternRewriter &rewriter) const {
920
+ mlir::Value loweredResult =
921
+ lowerMod->getCXXABI ().lowerBaseDataMember (op, adaptor.getSrc (), rewriter);
922
+ rewriter.replaceOp (op, loweredResult);
923
+ return mlir::success ();
924
+ }
925
+
926
+ mlir::LogicalResult CIRToLLVMDerivedDataMemberOpLowering::matchAndRewrite (
927
+ cir::DerivedDataMemberOp op, OpAdaptor adaptor,
928
+ mlir::ConversionPatternRewriter &rewriter) const {
929
+ mlir::Value loweredResult = lowerMod->getCXXABI ().lowerDerivedDataMember (
930
+ op, adaptor.getSrc (), rewriter);
931
+ rewriter.replaceOp (op, loweredResult);
932
+ return mlir::success ();
933
+ }
934
+
917
935
static mlir::Value
918
936
getValueForVTableSymbol (mlir::Operation *op,
919
937
mlir::ConversionPatternRewriter &rewriter,
@@ -1518,7 +1536,13 @@ mlir::LogicalResult CIRToLLVMConstantOpLowering::matchAndRewrite(
1518
1536
mlir::ConversionPatternRewriter &rewriter) const {
1519
1537
mlir::Attribute attr = op.getValue ();
1520
1538
1521
- if (mlir::isa<cir::BoolType>(op.getType ())) {
1539
+ if (mlir::isa<mlir::IntegerType>(op.getType ())) {
1540
+ // Verified cir.const operations cannot actually be of these types, but the
1541
+ // lowering pass may generate temporary cir.const operations with these
1542
+ // types. This is OK since MLIR allows unverified operations to be alive
1543
+ // during a pass as long as they don't live past the end of the pass.
1544
+ attr = op.getValue ();
1545
+ } else if (mlir::isa<cir::BoolType>(op.getType ())) {
1522
1546
int value = (op.getValue () ==
1523
1547
cir::BoolAttr::get (getContext (),
1524
1548
cir::BoolType::get (getContext ()), true ));
@@ -2412,11 +2436,12 @@ CIRToLLVMBinOpLowering::getIntOverflowFlag(cir::BinOp op) const {
2412
2436
mlir::LogicalResult CIRToLLVMBinOpLowering::matchAndRewrite (
2413
2437
cir::BinOp op, OpAdaptor adaptor,
2414
2438
mlir::ConversionPatternRewriter &rewriter) const {
2415
- assert ((op .getLhs ().getType () == op .getRhs ().getType ()) &&
2439
+ assert ((adaptor .getLhs ().getType () == adaptor .getRhs ().getType ()) &&
2416
2440
" inconsistent operands' types not supported yet" );
2441
+
2417
2442
mlir::Type type = op.getRhs ().getType ();
2418
- assert ((mlir::isa<cir::IntType, cir::CIRFPTypeInterface, cir::VectorType>(
2419
- type)) &&
2443
+ assert ((mlir::isa<cir::IntType, cir::CIRFPTypeInterface, cir::VectorType,
2444
+ mlir::IntegerType>( type)) &&
2420
2445
" operand type not supported yet" );
2421
2446
2422
2447
auto llvmTy = getTypeConverter ()->convertType (op.getType ());
@@ -2427,38 +2452,44 @@ mlir::LogicalResult CIRToLLVMBinOpLowering::matchAndRewrite(
2427
2452
2428
2453
switch (op.getKind ()) {
2429
2454
case cir::BinOpKind::Add:
2430
- if (mlir::isa<cir::IntType>(type))
2455
+ if (mlir::isa<cir::IntType, mlir::IntegerType >(type))
2431
2456
rewriter.replaceOpWithNewOp <mlir::LLVM::AddOp>(op, llvmTy, lhs, rhs,
2432
2457
getIntOverflowFlag (op));
2433
2458
else
2434
2459
rewriter.replaceOpWithNewOp <mlir::LLVM::FAddOp>(op, llvmTy, lhs, rhs);
2435
2460
break ;
2436
2461
case cir::BinOpKind::Sub:
2437
- if (mlir::isa<cir::IntType>(type))
2462
+ if (mlir::isa<cir::IntType, mlir::IntegerType >(type))
2438
2463
rewriter.replaceOpWithNewOp <mlir::LLVM::SubOp>(op, llvmTy, lhs, rhs,
2439
2464
getIntOverflowFlag (op));
2440
2465
else
2441
2466
rewriter.replaceOpWithNewOp <mlir::LLVM::FSubOp>(op, llvmTy, lhs, rhs);
2442
2467
break ;
2443
2468
case cir::BinOpKind::Mul:
2444
- if (mlir::isa<cir::IntType>(type))
2469
+ if (mlir::isa<cir::IntType, mlir::IntegerType >(type))
2445
2470
rewriter.replaceOpWithNewOp <mlir::LLVM::MulOp>(op, llvmTy, lhs, rhs,
2446
2471
getIntOverflowFlag (op));
2447
2472
else
2448
2473
rewriter.replaceOpWithNewOp <mlir::LLVM::FMulOp>(op, llvmTy, lhs, rhs);
2449
2474
break ;
2450
2475
case cir::BinOpKind::Div:
2451
- if (auto ty = mlir::dyn_cast<cir::IntType>(type)) {
2452
- if (ty.isUnsigned ())
2476
+ if (mlir::isa<cir::IntType, mlir::IntegerType>(type)) {
2477
+ auto isUnsigned = mlir::isa<cir::IntType>(type)
2478
+ ? mlir::cast<cir::IntType>(type).isUnsigned ()
2479
+ : mlir::cast<mlir::IntegerType>(type).isUnsigned ();
2480
+ if (isUnsigned)
2453
2481
rewriter.replaceOpWithNewOp <mlir::LLVM::UDivOp>(op, llvmTy, lhs, rhs);
2454
2482
else
2455
2483
rewriter.replaceOpWithNewOp <mlir::LLVM::SDivOp>(op, llvmTy, lhs, rhs);
2456
2484
} else
2457
2485
rewriter.replaceOpWithNewOp <mlir::LLVM::FDivOp>(op, llvmTy, lhs, rhs);
2458
2486
break ;
2459
2487
case cir::BinOpKind::Rem:
2460
- if (auto ty = mlir::dyn_cast<cir::IntType>(type)) {
2461
- if (ty.isUnsigned ())
2488
+ if (mlir::isa<cir::IntType, mlir::IntegerType>(type)) {
2489
+ auto isUnsigned = mlir::isa<cir::IntType>(type)
2490
+ ? mlir::cast<cir::IntType>(type).isUnsigned ()
2491
+ : mlir::cast<mlir::IntegerType>(type).isUnsigned ();
2492
+ if (isUnsigned)
2462
2493
rewriter.replaceOpWithNewOp <mlir::LLVM::URemOp>(op, llvmTy, lhs, rhs);
2463
2494
else
2464
2495
rewriter.replaceOpWithNewOp <mlir::LLVM::SRemOp>(op, llvmTy, lhs, rhs);
@@ -2642,9 +2673,12 @@ mlir::LogicalResult CIRToLLVMCmpOpLowering::matchAndRewrite(
2642
2673
mlir::Value llResult;
2643
2674
2644
2675
// Lower to LLVM comparison op.
2645
- if (auto intTy = mlir::dyn_cast<cir::IntType>(type)) {
2646
- auto kind =
2647
- convertCmpKindToICmpPredicate (cmpOp.getKind (), intTy.isSigned ());
2676
+ // if (auto intTy = mlir::dyn_cast<cir::IntType>(type)) {
2677
+ if (mlir::isa<cir::IntType, mlir::IntegerType>(type)) {
2678
+ auto isSigned = mlir::isa<cir::IntType>(type)
2679
+ ? mlir::cast<cir::IntType>(type).isSigned ()
2680
+ : mlir::cast<mlir::IntegerType>(type).isSigned ();
2681
+ auto kind = convertCmpKindToICmpPredicate (cmpOp.getKind (), isSigned);
2648
2682
llResult = rewriter.create <mlir::LLVM::ICmpOp>(
2649
2683
cmpOp.getLoc (), kind, adaptor.getLhs (), adaptor.getRhs ());
2650
2684
} else if (auto ptrTy = mlir::dyn_cast<cir::PointerType>(type)) {
@@ -3847,9 +3881,15 @@ void populateCIRToLLVMConversionPatterns(
3847
3881
patterns.add <CIRToLLVMAllocaOpLowering>(converter, dataLayout,
3848
3882
stringGlobalsMap, argStringGlobalsMap,
3849
3883
argsVarMap, patterns.getContext ());
3850
- patterns.add <CIRToLLVMConstantOpLowering, CIRToLLVMGlobalOpLowering,
3851
- CIRToLLVMGetRuntimeMemberOpLowering>(
3852
- converter, patterns.getContext (), lowerModule);
3884
+ patterns.add <
3885
+ // clang-format off
3886
+ CIRToLLVMBaseDataMemberOpLowering,
3887
+ CIRToLLVMConstantOpLowering,
3888
+ CIRToLLVMDerivedDataMemberOpLowering,
3889
+ CIRToLLVMGetRuntimeMemberOpLowering,
3890
+ CIRToLLVMGlobalOpLowering
3891
+ // clang-format on
3892
+ >(converter, patterns.getContext (), lowerModule);
3853
3893
patterns.add <
3854
3894
// clang-format off
3855
3895
CIRToLLVMAbsOpLowering,
0 commit comments