@@ -619,38 +619,26 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
619
619
QualType promotionTy = PromotionType.isNull ()
620
620
? getPromotionType (E->getSubExpr ()->getType ())
621
621
: PromotionType;
622
- auto result = VisitPlus (E , promotionTy);
622
+ auto result = emitUnaryPlusOrMinus (E, cir::UnaryOpKind::Plus , promotionTy);
623
623
if (result && !promotionTy.isNull ())
624
624
return emitUnPromotedValue (result, E->getType ());
625
625
return result;
626
626
}
627
627
628
- mlir::Value VisitPlus (const UnaryOperator *E,
629
- QualType PromotionType = QualType()) {
630
- // This differs from gcc, though, most likely due to a bug in gcc.
631
- TestAndClearIgnoreResultAssign ();
632
-
633
- mlir::Value operand;
634
- if (!PromotionType.isNull ())
635
- operand = CGF.emitPromotedScalarExpr (E->getSubExpr (), PromotionType);
636
- else
637
- operand = Visit (E->getSubExpr ());
638
-
639
- return emitUnaryOp (E, cir::UnaryOpKind::Plus, operand);
640
- }
641
-
642
628
mlir::Value VisitUnaryMinus (const UnaryOperator *E,
643
629
QualType PromotionType = QualType()) {
644
630
QualType promotionTy = PromotionType.isNull ()
645
631
? getPromotionType (E->getSubExpr ()->getType ())
646
632
: PromotionType;
647
- auto result = VisitMinus (E , promotionTy);
633
+ auto result = emitUnaryPlusOrMinus (E, cir::UnaryOpKind::Minus , promotionTy);
648
634
if (result && !promotionTy.isNull ())
649
635
return emitUnPromotedValue (result, E->getType ());
650
636
return result;
651
637
}
652
638
653
- mlir::Value VisitMinus (const UnaryOperator *E, QualType PromotionType) {
639
+ mlir::Value emitUnaryPlusOrMinus (const UnaryOperator *E,
640
+ cir::UnaryOpKind kind,
641
+ QualType PromotionType) {
654
642
TestAndClearIgnoreResultAssign ();
655
643
656
644
mlir::Value operand;
@@ -661,7 +649,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
661
649
662
650
// NOTE: LLVM codegen will lower this directly to either a FNeg
663
651
// or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
664
- return emitUnaryOp (E, cir::UnaryOpKind::Minus , operand);
652
+ return emitUnaryOp (E, kind , operand);
665
653
}
666
654
667
655
mlir::Value VisitUnaryNot (const UnaryOperator *E) {
@@ -2335,9 +2323,9 @@ mlir::Value ScalarExprEmitter::emitPromoted(const Expr *E,
2335
2323
case UO_Real:
2336
2324
llvm_unreachable (" NYI" );
2337
2325
case UO_Minus:
2338
- return VisitMinus (UO, PromotionType);
2326
+ return emitUnaryPlusOrMinus (UO, cir::UnaryOpKind::Minus , PromotionType);
2339
2327
case UO_Plus:
2340
- return VisitPlus (UO, PromotionType);
2328
+ return emitUnaryPlusOrMinus (UO, cir::UnaryOpKind::Plus , PromotionType);
2341
2329
default :
2342
2330
break ;
2343
2331
}
0 commit comments