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