@@ -527,14 +527,35 @@ class CIRScopeOpLowering
527
527
}
528
528
};
529
529
530
+ struct CIRBrCondOpLowering
531
+ : public mlir::OpConversionPattern<mlir::cir::BrCondOp> {
532
+ using mlir::OpConversionPattern<mlir::cir::BrCondOp>::OpConversionPattern;
533
+
534
+ mlir::LogicalResult
535
+ matchAndRewrite (mlir::cir::BrCondOp brOp, OpAdaptor adaptor,
536
+ mlir::ConversionPatternRewriter &rewriter) const override {
537
+
538
+ auto condition = adaptor.getCond ();
539
+ auto i1Condition = rewriter.create <mlir::arith::TruncIOp>(
540
+ brOp.getLoc (), rewriter.getI1Type (), condition);
541
+ rewriter.replaceOpWithNewOp <mlir::cf::CondBranchOp>(
542
+ brOp, i1Condition.getResult (), brOp.getDestTrue (),
543
+ adaptor.getDestOperandsTrue (), brOp.getDestFalse (),
544
+ adaptor.getDestOperandsFalse ());
545
+
546
+ return mlir::success ();
547
+ }
548
+ };
549
+
530
550
void populateCIRToMLIRConversionPatterns (mlir::RewritePatternSet &patterns,
531
551
mlir::TypeConverter &converter) {
532
552
patterns.add <CIRReturnLowering, CIRBrOpLowering>(patterns.getContext ());
533
553
534
554
patterns.add <CIRCmpOpLowering, CIRCallLowering, CIRUnaryOpLowering,
535
555
CIRBinOpLowering, CIRLoadLowering, CIRConstantLowering,
536
556
CIRStoreLowering, CIRAllocaLowering, CIRFuncLowering,
537
- CIRScopeOpLowering>(converter, patterns.getContext ());
557
+ CIRScopeOpLowering, CIRBrCondOpLowering>(converter,
558
+ patterns.getContext ());
538
559
}
539
560
540
561
static mlir::TypeConverter prepareTypeConverter () {
0 commit comments