@@ -199,9 +199,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
199
199
llvm_unreachable (" NYI" );
200
200
}
201
201
mlir::Value VisitCXXBoolLiteralExpr (const CXXBoolLiteralExpr *E) {
202
- mlir::Type Ty = CGF.convertType (E->getType ());
203
- return Builder.create <cir::ConstantOp>(
204
- CGF.getLoc (E->getExprLoc ()), Ty, Builder.getCIRBoolAttr (E->getValue ()));
202
+ return Builder.getBool (E->getValue (), CGF.getLoc (E->getExprLoc ()));
205
203
}
206
204
207
205
mlir::Value VisitCXXScalarValueInitExpr (const CXXScalarValueInitExpr *E) {
@@ -419,9 +417,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
419
417
// An interesting aspect of this is that increment is always true.
420
418
// Decrement does not have this property.
421
419
if (isInc && type->isBooleanType ()) {
422
- value = Builder.create <cir::ConstantOp>(CGF.getLoc (E->getExprLoc ()),
423
- CGF.convertType (type),
424
- Builder.getCIRBoolAttr (true ));
420
+ value = Builder.getTrue (CGF.getLoc (E->getExprLoc ()));
425
421
} else if (type->isIntegerType ()) {
426
422
QualType promotedType;
427
423
bool canPerformLossyDemotionCheck = false ;
@@ -2669,19 +2665,15 @@ mlir::Value ScalarExprEmitter::VisitBinLAnd(const clang::BinaryOperator *E) {
2669
2665
CIRGenFunction::LexicalScope lexScope{CGF, Loc,
2670
2666
B.getInsertionBlock ()};
2671
2667
CGF.currLexScope ->setAsTernary ();
2672
- auto res = B.create <cir::ConstantOp>(
2673
- Loc, Builder.getBoolTy (),
2674
- Builder.getAttr <cir::BoolAttr>(Builder.getBoolTy (), true ));
2668
+ auto res = B.create <cir::ConstantOp>(Loc, Builder.getTrueAttr ());
2675
2669
B.create <cir::YieldOp>(Loc, res.getRes ());
2676
2670
},
2677
2671
/* falseBuilder*/
2678
2672
[&](mlir::OpBuilder &b, mlir::Location Loc) {
2679
2673
CIRGenFunction::LexicalScope lexScope{CGF, Loc,
2680
2674
b.getInsertionBlock ()};
2681
2675
CGF.currLexScope ->setAsTernary ();
2682
- auto res = b.create <cir::ConstantOp>(
2683
- Loc, Builder.getBoolTy (),
2684
- Builder.getAttr <cir::BoolAttr>(Builder.getBoolTy (), false ));
2676
+ auto res = b.create <cir::ConstantOp>(Loc, Builder.getFalseAttr ());
2685
2677
b.create <cir::YieldOp>(Loc, res.getRes ());
2686
2678
});
2687
2679
B.create <cir::YieldOp>(Loc, res.getResult ());
@@ -2690,9 +2682,7 @@ mlir::Value ScalarExprEmitter::VisitBinLAnd(const clang::BinaryOperator *E) {
2690
2682
[&](mlir::OpBuilder &B, mlir::Location Loc) {
2691
2683
CIRGenFunction::LexicalScope lexScope{CGF, Loc, B.getInsertionBlock ()};
2692
2684
CGF.currLexScope ->setAsTernary ();
2693
- auto res = B.create <cir::ConstantOp>(
2694
- Loc, Builder.getBoolTy (),
2695
- Builder.getAttr <cir::BoolAttr>(Builder.getBoolTy (), false ));
2685
+ auto res = B.create <cir::ConstantOp>(Loc, Builder.getFalseAttr ());
2696
2686
B.create <cir::YieldOp>(Loc, res.getRes ());
2697
2687
});
2698
2688
return Builder.createZExtOrBitCast (ResOp.getLoc (), ResOp.getResult (), ResTy);
@@ -2738,9 +2728,7 @@ mlir::Value ScalarExprEmitter::VisitBinLOr(const clang::BinaryOperator *E) {
2738
2728
[&](mlir::OpBuilder &B, mlir::Location Loc) {
2739
2729
CIRGenFunction::LexicalScope lexScope{CGF, Loc, B.getInsertionBlock ()};
2740
2730
CGF.currLexScope ->setAsTernary ();
2741
- auto res = B.create <cir::ConstantOp>(
2742
- Loc, Builder.getBoolTy (),
2743
- Builder.getAttr <cir::BoolAttr>(Builder.getBoolTy (), true ));
2731
+ auto res = B.create <cir::ConstantOp>(Loc, Builder.getTrueAttr ());
2744
2732
B.create <cir::YieldOp>(Loc, res.getRes ());
2745
2733
},
2746
2734
/* falseBuilder*/
@@ -2763,9 +2751,7 @@ mlir::Value ScalarExprEmitter::VisitBinLOr(const clang::BinaryOperator *E) {
2763
2751
CIRGenFunction::LexicalScope lexScope{CGF, Loc,
2764
2752
B.getInsertionBlock ()};
2765
2753
CGF.currLexScope ->setAsTernary ();
2766
- auto res = B.create <cir::ConstantOp>(
2767
- Loc, Builder.getBoolTy (),
2768
- Builder.getAttr <cir::BoolAttr>(Builder.getBoolTy (), true ));
2754
+ auto res = B.create <cir::ConstantOp>(Loc, Builder.getTrueAttr ());
2769
2755
B.create <cir::YieldOp>(Loc, res.getRes ());
2770
2756
},
2771
2757
/* falseBuilder*/
@@ -2782,9 +2768,7 @@ mlir::Value ScalarExprEmitter::VisitBinLOr(const clang::BinaryOperator *E) {
2782
2768
CIRGenFunction::LexicalScope lexScope{CGF, Loc,
2783
2769
B.getInsertionBlock ()};
2784
2770
CGF.currLexScope ->setAsTernary ();
2785
- auto res = b.create <cir::ConstantOp>(
2786
- Loc, Builder.getBoolTy (),
2787
- Builder.getAttr <cir::BoolAttr>(Builder.getBoolTy (), false ));
2771
+ auto res = b.create <cir::ConstantOp>(Loc, Builder.getFalseAttr ());
2788
2772
b.create <cir::YieldOp>(Loc, res.getRes ());
2789
2773
});
2790
2774
B.create <cir::YieldOp>(Loc, res.getResult ());
0 commit comments