@@ -334,11 +334,44 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
334
334
llvm_unreachable (" NYI" );
335
335
}
336
336
mlir::Value VisitUnaryPlus (const UnaryOperator *E) {
337
- llvm_unreachable (" NYI" );
337
+ // NOTE(cir): QualType function parameter still not used, so don´t replicate
338
+ // it here yet.
339
+ QualType promotionTy = getPromotionType (E->getSubExpr ()->getType ());
340
+ auto result = VisitPlus (E, promotionTy);
341
+ if (result && !promotionTy.isNull ())
342
+ assert (0 && " not implemented yet" );
343
+ return buildUnaryOp (E, mlir::cir::UnaryOpKind::Plus, result);
344
+ }
345
+
346
+ mlir::Value VisitPlus (const UnaryOperator *E, QualType PromotionType) {
347
+ // This differs from gcc, though, most likely due to a bug in gcc.
348
+ TestAndClearIgnoreResultAssign ();
349
+ if (!PromotionType.isNull ())
350
+ assert (0 && " scalar promotion not implemented yet" );
351
+ return Visit (E->getSubExpr ());
338
352
}
353
+
339
354
mlir::Value VisitUnaryMinus (const UnaryOperator *E) {
340
- llvm_unreachable (" NYI" );
355
+ // NOTE(cir): QualType function parameter still not used, so don´t replicate
356
+ // it here yet.
357
+ QualType promotionTy = getPromotionType (E->getSubExpr ()->getType ());
358
+ auto result = VisitMinus (E, promotionTy);
359
+ if (result && !promotionTy.isNull ())
360
+ assert (0 && " not implemented yet" );
361
+ return buildUnaryOp (E, mlir::cir::UnaryOpKind::Minus, result);
362
+ }
363
+
364
+ mlir::Value VisitMinus (const UnaryOperator *E, QualType PromotionType) {
365
+ TestAndClearIgnoreResultAssign ();
366
+ if (!PromotionType.isNull ())
367
+ assert (0 && " scalar promotion not implemented yet" );
368
+
369
+ // NOTE: LLVM codegen will lower this directly to either a FNeg
370
+ // or a Sub instruction. In CIR this will be handled later in LowerToLLVM.
371
+
372
+ return Visit (E->getSubExpr ());
341
373
}
374
+
342
375
mlir::Value VisitUnaryNot (const UnaryOperator *E) { llvm_unreachable (" NYI" ); }
343
376
mlir::Value VisitUnaryLNot (const UnaryOperator *E) {
344
377
llvm_unreachable (" NYI" );
@@ -592,6 +625,22 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
592
625
buildCompoundAssign (const CompoundAssignOperator *E,
593
626
mlir::Value (ScalarExprEmitter::*F)(const BinOpInfo &));
594
627
628
+ // TODO(cir): Candidate to be in a common AST helper between CIR and LLVM codegen.
629
+ QualType getPromotionType (QualType Ty) {
630
+ if (CGF.getContext ()
631
+ .getTargetInfo ()
632
+ .shouldEmitFloat16WithExcessPrecision ()) {
633
+ if (Ty->isAnyComplexType ()) {
634
+ QualType ElementType = Ty->castAs <ComplexType>()->getElementType ();
635
+ if (ElementType->isFloat16Type ())
636
+ return CGF.getContext ().getComplexType (CGF.getContext ().FloatTy );
637
+ }
638
+ if (Ty->isFloat16Type ())
639
+ return CGF.getContext ().FloatTy ;
640
+ }
641
+ return QualType ();
642
+ }
643
+
595
644
// Binary operators and binary compound assignment operators.
596
645
#define HANDLEBINOP (OP ) \
597
646
mlir::Value VisitBin##OP(const BinaryOperator *E) { \
0 commit comments