-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[CIR] Upstream Unary Plus & Minus op for ComplexType #150281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,17 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { | |
| } | ||
|
|
||
| mlir::Value VisitUnaryDeref(const Expr *e); | ||
|
|
||
| mlir::Value VisitUnaryPlus(const UnaryOperator *e, | ||
| QualType promotionType = QualType()); | ||
|
|
||
| mlir::Value VisitPlus(const UnaryOperator *e, QualType promotionType); | ||
|
|
||
| mlir::Value VisitUnaryMinus(const UnaryOperator *e, | ||
| QualType promotionType = QualType()); | ||
|
|
||
| mlir::Value VisitMinus(const UnaryOperator *e, QualType promotionType); | ||
|
|
||
| mlir::Value VisitUnaryNot(const UnaryOperator *e); | ||
|
|
||
| struct BinOpInfo { | ||
|
|
@@ -174,6 +185,58 @@ mlir::Value ComplexExprEmitter::emitCast(CastKind ck, Expr *op, | |
| return {}; | ||
| } | ||
|
|
||
| mlir::Value ComplexExprEmitter::VisitUnaryPlus(const UnaryOperator *e, | ||
| QualType promotionType) { | ||
| QualType promotionTy = promotionType.isNull() | ||
| ? getPromotionType(e->getSubExpr()->getType()) | ||
| : promotionType; | ||
| mlir::Value result = VisitPlus(e, promotionTy); | ||
| if (!promotionTy.isNull()) { | ||
| cgf.cgm.errorNYI("ComplexExprEmitter::VisitUnaryPlus emitUnPromotedValue"); | ||
| return {}; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| mlir::Value ComplexExprEmitter::VisitPlus(const UnaryOperator *e, | ||
|
||
| QualType promotionType) { | ||
| mlir::Value op; | ||
| if (!promotionType.isNull()) | ||
| op = cgf.emitPromotedComplexExpr(e->getSubExpr(), promotionType); | ||
| else | ||
| op = Visit(e->getSubExpr()); | ||
|
|
||
| return builder.createUnaryOp(cgf.getLoc(e->getExprLoc()), | ||
| cir::UnaryOpKind::Plus, op); | ||
| } | ||
|
|
||
| mlir::Value ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *e, | ||
| QualType promotionType) { | ||
| QualType promotionTy = promotionType.isNull() | ||
| ? getPromotionType(e->getSubExpr()->getType()) | ||
| : promotionType; | ||
| mlir::Value result = VisitMinus(e, promotionTy); | ||
| if (!promotionTy.isNull()) { | ||
| cgf.cgm.errorNYI("ComplexExprEmitter::VisitUnaryMinus emitUnPromotedValue"); | ||
| return {}; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| mlir::Value ComplexExprEmitter::VisitMinus(const UnaryOperator *e, | ||
| QualType promotionType) { | ||
| mlir::Value op; | ||
| if (!promotionType.isNull()) | ||
| op = cgf.emitPromotedComplexExpr(e->getSubExpr(), promotionType); | ||
| else | ||
| op = Visit(e->getSubExpr()); | ||
|
|
||
| return builder.createUnaryOp(cgf.getLoc(e->getExprLoc()), | ||
| cir::UnaryOpKind::Minus, op); | ||
| } | ||
|
|
||
| mlir::Value ComplexExprEmitter::emitConstant( | ||
| const CIRGenFunction::ConstantEmission &constant, Expr *e) { | ||
| assert(constant && "not a constant"); | ||
|
|
@@ -389,9 +452,15 @@ mlir::Value ComplexExprEmitter::emitPromoted(const Expr *e, | |
| default: | ||
| break; | ||
| } | ||
| } else if (isa<UnaryOperator>(e)) { | ||
| cgf.cgm.errorNYI("emitPromoted UnaryOperator"); | ||
| return {}; | ||
| } else if (const auto *unaryOp = dyn_cast<UnaryOperator>(e)) { | ||
| switch (unaryOp->getOpcode()) { | ||
| case UO_Minus: | ||
| return VisitMinus(unaryOp, promotionTy); | ||
| case UO_Plus: | ||
| return VisitPlus(unaryOp, promotionTy); | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| mlir::Value result = Visit(const_cast<Expr *>(e)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think
VisitUnaryPlusandVisitUnaryMinusare ever called with apromotionTypeargument. I looked at the commit where these arguments were added in classic codegen (5def954) and it looks like it was possibly an artifact of some previous state. I'd suggest leaving them out for now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, i will do that