Skip to content

Commit bb26b8c

Browse files
committed
Address code review comments
1 parent 2ad8eb5 commit bb26b8c

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
8585

8686
mlir::Value VisitUnaryPlus(const UnaryOperator *e);
8787

88-
mlir::Value VisitPlus(const UnaryOperator *e, QualType promotionType);
88+
mlir::Value VisitPlusMinus(const UnaryOperator *e, cir::UnaryOpKind kind,
89+
QualType promotionType);
8990

9091
mlir::Value VisitUnaryMinus(const UnaryOperator *e);
9192

92-
mlir::Value VisitMinus(const UnaryOperator *e, QualType promotionType);
93-
9493
mlir::Value VisitUnaryNot(const UnaryOperator *e);
9594

9695
struct BinOpInfo {
@@ -185,48 +184,39 @@ mlir::Value ComplexExprEmitter::emitCast(CastKind ck, Expr *op,
185184

186185
mlir::Value ComplexExprEmitter::VisitUnaryPlus(const UnaryOperator *e) {
187186
QualType promotionTy = getPromotionType(e->getSubExpr()->getType());
188-
mlir::Value result = VisitPlus(e, promotionTy);
187+
mlir::Value result = VisitPlusMinus(e, cir::UnaryOpKind::Plus, promotionTy);
189188
if (!promotionTy.isNull()) {
190189
cgf.cgm.errorNYI("ComplexExprEmitter::VisitUnaryPlus emitUnPromotedValue");
191190
return {};
192191
}
193192
return result;
194193
}
195194

196-
mlir::Value ComplexExprEmitter::VisitPlus(const UnaryOperator *e,
197-
QualType promotionType) {
195+
mlir::Value ComplexExprEmitter::VisitPlusMinus(const UnaryOperator *e,
196+
cir::UnaryOpKind kind,
197+
QualType promotionType) {
198+
assert(kind == cir::UnaryOpKind::Plus ||
199+
kind == cir::UnaryOpKind::Minus &&
200+
"Invalid UnaryOp kind for ComplexType Plus or Minus");
201+
198202
mlir::Value op;
199203
if (!promotionType.isNull())
200204
op = cgf.emitPromotedComplexExpr(e->getSubExpr(), promotionType);
201205
else
202206
op = Visit(e->getSubExpr());
203-
204-
return builder.createUnaryOp(cgf.getLoc(e->getExprLoc()),
205-
cir::UnaryOpKind::Plus, op);
207+
return builder.createUnaryOp(cgf.getLoc(e->getExprLoc()), kind, op);
206208
}
207209

208210
mlir::Value ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *e) {
209211
QualType promotionTy = getPromotionType(e->getSubExpr()->getType());
210-
mlir::Value result = VisitMinus(e, promotionTy);
212+
mlir::Value result = VisitPlusMinus(e, cir::UnaryOpKind::Minus, promotionTy);
211213
if (!promotionTy.isNull()) {
212214
cgf.cgm.errorNYI("ComplexExprEmitter::VisitUnaryMinus emitUnPromotedValue");
213215
return {};
214216
}
215217
return result;
216218
}
217219

218-
mlir::Value ComplexExprEmitter::VisitMinus(const UnaryOperator *e,
219-
QualType promotionType) {
220-
mlir::Value op;
221-
if (!promotionType.isNull())
222-
op = cgf.emitPromotedComplexExpr(e->getSubExpr(), promotionType);
223-
else
224-
op = Visit(e->getSubExpr());
225-
226-
return builder.createUnaryOp(cgf.getLoc(e->getExprLoc()),
227-
cir::UnaryOpKind::Minus, op);
228-
}
229-
230220
mlir::Value ComplexExprEmitter::emitConstant(
231221
const CIRGenFunction::ConstantEmission &constant, Expr *e) {
232222
assert(constant && "not a constant");
@@ -445,9 +435,11 @@ mlir::Value ComplexExprEmitter::emitPromoted(const Expr *e,
445435
} else if (const auto *unaryOp = dyn_cast<UnaryOperator>(e)) {
446436
switch (unaryOp->getOpcode()) {
447437
case UO_Minus:
448-
return VisitMinus(unaryOp, promotionTy);
449-
case UO_Plus:
450-
return VisitPlus(unaryOp, promotionTy);
438+
case UO_Plus: {
439+
auto kind = unaryOp->getOpcode() == UO_Plus ? cir::UnaryOpKind::Plus
440+
: cir::UnaryOpKind::Minus;
441+
return VisitPlusMinus(unaryOp, kind, promotionTy);
442+
}
451443
default:
452444
break;
453445
}

0 commit comments

Comments
 (0)