@@ -88,13 +88,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
88
88
// ===--------------------------------------------------------------------===//
89
89
90
90
mlir::Value emitPromotedValue (mlir::Value result, QualType promotionType) {
91
- cgf.cgm .errorNYI (result.getLoc (), " floating cast for promoted value" );
92
- return {};
91
+ return builder.createFloatingCast (result, cgf.convertType (promotionType));
93
92
}
94
93
95
94
mlir::Value emitUnPromotedValue (mlir::Value result, QualType exprType) {
96
- cgf.cgm .errorNYI (result.getLoc (), " floating cast for unpromoted value" );
97
- return {};
95
+ return builder.createFloatingCast (result, cgf.convertType (exprType));
98
96
}
99
97
100
98
mlir::Value emitPromoted (const Expr *e, QualType promotionType);
@@ -446,37 +444,35 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
446
444
llvm_unreachable (" Unexpected signed overflow behavior kind" );
447
445
}
448
446
449
- mlir::Value VisitUnaryPlus (const UnaryOperator *e,
450
- QualType promotionType = QualType()) {
451
- if (!promotionType.isNull ())
452
- cgf.cgm .errorNYI (e->getSourceRange (), " VisitUnaryPlus: promotionType" );
453
- assert (!cir::MissingFeatures::opUnaryPromotionType ());
454
- mlir::Value result = emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Plus);
455
- return result;
447
+ mlir::Value VisitUnaryPlus (const UnaryOperator *e) {
448
+ return emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Plus);
456
449
}
457
450
458
- mlir::Value VisitUnaryMinus (const UnaryOperator *e,
459
- QualType promotionType = QualType()) {
460
- if (!promotionType.isNull ())
461
- cgf.cgm .errorNYI (e->getSourceRange (), " VisitUnaryMinus: promotionType" );
462
- assert (!cir::MissingFeatures::opUnaryPromotionType ());
463
- mlir::Value result = emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Minus);
464
- return result;
451
+ mlir::Value VisitUnaryMinus (const UnaryOperator *e) {
452
+ return emitUnaryPlusOrMinus (e, cir::UnaryOpKind::Minus);
465
453
}
466
454
467
455
mlir::Value emitUnaryPlusOrMinus (const UnaryOperator *e,
468
456
cir::UnaryOpKind kind) {
469
457
ignoreResultAssign = false ;
470
458
471
- assert (!cir::MissingFeatures::opUnaryPromotionType ());
472
- mlir::Value operand = Visit (e->getSubExpr ());
459
+ QualType promotionType = getPromotionType (e->getSubExpr ()->getType ());
460
+
461
+ mlir::Value operand;
462
+ if (!promotionType.isNull ())
463
+ operand = cgf.emitPromotedScalarExpr (e->getSubExpr (), promotionType);
464
+ else
465
+ operand = Visit (e->getSubExpr ());
473
466
474
467
bool nsw =
475
468
kind == cir::UnaryOpKind::Minus && e->getType ()->isSignedIntegerType ();
476
469
477
470
// NOTE: LLVM codegen will lower this directly to either a FNeg
478
471
// or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
479
- return emitUnaryOp (e, kind, operand, nsw);
472
+ mlir::Value result = emitUnaryOp (e, kind, operand, nsw);
473
+ if (result && !promotionType.isNull ())
474
+ return emitUnPromotedValue (result, e->getType ());
475
+ return result;
480
476
}
481
477
482
478
mlir::Value emitUnaryOp (const UnaryOperator *e, cir::UnaryOpKind kind,
0 commit comments