[clang] ed07b54 - [CIR][NFCI] Represent Complex RValues As Single Value (#144519)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 17 10:35:52 PDT 2025
Author: Morris Hafner
Date: 2025-06-17T18:35:49+01:00
New Revision: ed07b54b38c675235b4ce1bfd49e1fff372f6520
URL: https://github.com/llvm/llvm-project/commit/ed07b54b38c675235b4ce1bfd49e1fff372f6520
DIFF: https://github.com/llvm/llvm-project/commit/ed07b54b38c675235b4ce1bfd49e1fff372f6520.diff
LOG: [CIR][NFCI] Represent Complex RValues As Single Value (#144519)
This patch removes one mlir::Value in the RValue class that has been
used to represent complex values in classic CG. In CIR we plan on
representing complex as a single value. It also removes some now
unnecessary member functions related to complex handling.
Added:
Modified:
clang/lib/CIR/CodeGen/CIRGenCall.cpp
clang/lib/CIR/CodeGen/CIRGenExpr.cpp
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
clang/lib/CIR/CodeGen/CIRGenStmt.cpp
clang/lib/CIR/CodeGen/CIRGenValue.h
Removed:
################################################################################
diff --git a/clang/lib/CIR/CodeGen/CIRGenCall.cpp b/clang/lib/CIR/CodeGen/CIRGenCall.cpp
index 0d9064425fa95..af0e6ca822b8f 100644
--- a/clang/lib/CIR/CodeGen/CIRGenCall.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenCall.cpp
@@ -443,7 +443,7 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
mlir::Value v;
if (arg.isAggregate())
cgm.errorNYI(loc, "emitCall: aggregate call argument");
- v = arg.getKnownRValue().getScalarVal();
+ v = arg.getKnownRValue().getValue();
// We might have to widen integers, but we should never truncate.
if (argType != v.getType() && mlir::isa<cir::IntType>(v.getType()))
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 2e43f10be132c..4f2046ad26d72 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -219,7 +219,7 @@ void CIRGenFunction::emitStoreThroughLValue(RValue src, LValue dst,
const mlir::Value vector =
builder.createLoad(loc, dst.getVectorAddress());
const mlir::Value newVector = builder.create<cir::VecInsertOp>(
- loc, vector, src.getScalarVal(), dst.getVectorIdx());
+ loc, vector, src.getValue(), dst.getVectorIdx());
builder.createStore(loc, newVector, dst.getVectorAddress());
return;
}
@@ -232,7 +232,7 @@ void CIRGenFunction::emitStoreThroughLValue(RValue src, LValue dst,
assert(!cir::MissingFeatures::opLoadStoreObjC());
assert(src.isScalar() && "Can't emit an aggregate store with this method");
- emitStoreOfScalar(src.getScalarVal(), dst, isInit);
+ emitStoreOfScalar(src.getValue(), dst, isInit);
}
static LValue emitGlobalVarDeclLValue(CIRGenFunction &cgf, const Expr *e,
@@ -949,7 +949,7 @@ LValue CIRGenFunction::emitCallExprLValue(const CallExpr *e) {
"Can't have a scalar return unless the return type is a "
"reference type!");
- return makeNaturalAlignPointeeAddrLValue(rv.getScalarVal(), e->getType());
+ return makeNaturalAlignPointeeAddrLValue(rv.getValue(), e->getType());
}
LValue CIRGenFunction::emitBinaryOperatorLValue(const BinaryOperator *e) {
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 75b4d2a637e6e..8d0db5cd0a1e5 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -131,11 +131,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
mlir::Value emitLoadOfLValue(const Expr *e) {
LValue lv = cgf.emitLValue(e);
// FIXME: add some akin to EmitLValueAlignmentAssumption(E, V);
- return cgf.emitLoadOfLValue(lv, e->getExprLoc()).getScalarVal();
+ return cgf.emitLoadOfLValue(lv, e->getExprLoc()).getValue();
}
mlir::Value emitLoadOfLValue(LValue lv, SourceLocation loc) {
- return cgf.emitLoadOfLValue(lv, loc).getScalarVal();
+ return cgf.emitLoadOfLValue(lv, loc).getValue();
}
// l-values
@@ -400,10 +400,10 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
cgf.cgm.errorNYI(e->getSourceRange(), "Atomic inc/dec");
// TODO(cir): This is not correct, but it will produce reasonable code
// until atomic operations are implemented.
- value = cgf.emitLoadOfLValue(lv, e->getExprLoc()).getScalarVal();
+ value = cgf.emitLoadOfLValue(lv, e->getExprLoc()).getValue();
input = value;
} else {
- value = cgf.emitLoadOfLValue(lv, e->getExprLoc()).getScalarVal();
+ value = cgf.emitLoadOfLValue(lv, e->getExprLoc()).getValue();
input = value;
}
@@ -1805,7 +1805,7 @@ mlir::Value ScalarExprEmitter::VisitCallExpr(const CallExpr *e) {
if (e->getCallReturnType(cgf.getContext())->isReferenceType())
return emitLoadOfLValue(e);
- auto v = cgf.emitCallExpr(e).getScalarVal();
+ auto v = cgf.emitCallExpr(e).getValue();
assert(!cir::MissingFeatures::emitLValueAlignmentAssumption());
return v;
}
diff --git a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
index 019a44636ce3c..9193f6f1cd996 100644
--- a/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenStmt.cpp
@@ -391,8 +391,7 @@ mlir::LogicalResult CIRGenFunction::emitReturnStmt(const ReturnStmt &s) {
// If this function returns a reference, take the address of the
// expression rather than the value.
RValue result = emitReferenceBindingToExpr(rv);
- builder.CIRBaseBuilderTy::createStore(loc, result.getScalarVal(),
- *fnRetAlloca);
+ builder.CIRBaseBuilderTy::createStore(loc, result.getValue(), *fnRetAlloca);
} else {
mlir::Value value = nullptr;
switch (CIRGenFunction::getEvaluationKind(rv->getType())) {
diff --git a/clang/lib/CIR/CodeGen/CIRGenValue.h b/clang/lib/CIR/CodeGen/CIRGenValue.h
index c1e08ba1e9b67..84972fc7f9118 100644
--- a/clang/lib/CIR/CodeGen/CIRGenValue.h
+++ b/clang/lib/CIR/CodeGen/CIRGenValue.h
@@ -33,11 +33,7 @@ class RValue {
enum Flavor { Scalar, Complex, Aggregate };
union {
- // Stores first and second value.
- struct {
- mlir::Value first;
- mlir::Value second;
- } vals;
+ mlir::Value value;
// Stores aggregate address.
Address aggregateAddr;
@@ -47,7 +43,7 @@ class RValue {
unsigned flavor : 2;
public:
- RValue() : vals{nullptr, nullptr}, flavor(Scalar) {}
+ RValue() : value(nullptr), flavor(Scalar) {}
bool isScalar() const { return flavor == Scalar; }
bool isComplex() const { return flavor == Complex; }
@@ -56,14 +52,9 @@ class RValue {
bool isVolatileQualified() const { return isVolatile; }
/// Return the value of this scalar value.
- mlir::Value getScalarVal() const {
+ mlir::Value getValue() const {
assert(isScalar() && "Not a scalar!");
- return vals.first;
- }
-
- /// Return the real/imag components of this complex value.
- std::pair<mlir::Value, mlir::Value> getComplexVal() const {
- return std::make_pair(vals.first, vals.second);
+ return value;
}
/// Return the value of the address of the aggregate.
@@ -83,22 +74,20 @@ class RValue {
static RValue get(mlir::Value v) {
RValue er;
- er.vals.first = v;
+ er.value = v;
er.flavor = Scalar;
er.isVolatile = false;
return er;
}
- static RValue getComplex(mlir::Value v1, mlir::Value v2) {
+ static RValue getComplex(mlir::Value v) {
RValue er;
- er.vals = {v1, v2};
+ er.value = v;
er.flavor = Complex;
er.isVolatile = false;
return er;
}
- static RValue getComplex(const std::pair<mlir::Value, mlir::Value> &c) {
- return getComplex(c.first, c.second);
- }
+
// FIXME: Aggregate rvalues need to retain information about whether they are
// volatile or not. Remove default to find all places that probably get this
// wrong.
More information about the cfe-commits
mailing list