[clang] [CIR] Add binary operators (PR #132420)
Morris Hafner via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 24 08:24:11 PDT 2025
================
@@ -558,8 +624,225 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
return res;
}
+
+ BinOpInfo emitBinOps(const BinaryOperator *e,
+ QualType promotionType = QualType()) {
+ BinOpInfo result;
+ result.lhs = cgf.emitPromotedScalarExpr(e->getLHS(), promotionType);
+ result.rhs = cgf.emitPromotedScalarExpr(e->getRHS(), promotionType);
+ if (!promotionType.isNull())
+ result.fullType = promotionType;
+ else
+ result.fullType = e->getType();
+ result.compType = result.fullType;
+ if (const auto *vecType = dyn_cast_or_null<VectorType>(result.fullType)) {
+ result.compType = vecType->getElementType();
+ }
+ result.opcode = e->getOpcode();
+ result.loc = e->getSourceRange();
+ // TODO(cir): Result.FPFeatures
+ assert(!cir::MissingFeatures::getFPFeaturesInEffect());
+ result.e = e;
+ return result;
+ }
+
+ mlir::Value emitMul(const BinOpInfo &ops);
+ mlir::Value emitDiv(const BinOpInfo &ops);
+ mlir::Value emitRem(const BinOpInfo &ops);
+ mlir::Value emitAdd(const BinOpInfo &ops);
+ mlir::Value emitSub(const BinOpInfo &ops);
+ mlir::Value emitShl(const BinOpInfo &ops);
+ mlir::Value emitShr(const BinOpInfo &ops);
+ mlir::Value emitAnd(const BinOpInfo &ops);
+ mlir::Value emitXor(const BinOpInfo &ops);
+ mlir::Value emitOr(const BinOpInfo &ops);
+
+ LValue emitCompoundAssignLValue(
+ const CompoundAssignOperator *e,
+ mlir::Value (ScalarExprEmitter::*f)(const BinOpInfo &),
+ mlir::Value &result);
+ mlir::Value
+ emitCompoundAssign(const CompoundAssignOperator *e,
+ mlir::Value (ScalarExprEmitter::*f)(const BinOpInfo &));
+
+ // TODO(cir): Candidate to be in a common AST helper between CIR and LLVM
+ // codegen.
+ QualType getPromotionType(QualType ty) {
----------------
mmha wrote:
I think we should leave this as a TODO in this patch. It's easier to have a mostly unimplemented `getPromotionType` and change the calls later on than to go back and figure out where it's supposed to be called.
There's a `getPromotionType` `CGExprScalar.cpp` and another one in `CGExprComplex.cpp`. So refactoring that should probably be done in a separate patch.
https://github.com/llvm/llvm-project/pull/132420
More information about the cfe-commits
mailing list