Skip to content

Commit ed07b54

Browse files
authored
[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.
1 parent 9e0186d commit ed07b54

File tree

5 files changed

+18
-30
lines changed

5 files changed

+18
-30
lines changed

clang/lib/CIR/CodeGen/CIRGenCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo,
443443
mlir::Value v;
444444
if (arg.isAggregate())
445445
cgm.errorNYI(loc, "emitCall: aggregate call argument");
446-
v = arg.getKnownRValue().getScalarVal();
446+
v = arg.getKnownRValue().getValue();
447447

448448
// We might have to widen integers, but we should never truncate.
449449
if (argType != v.getType() && mlir::isa<cir::IntType>(v.getType()))

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void CIRGenFunction::emitStoreThroughLValue(RValue src, LValue dst,
219219
const mlir::Value vector =
220220
builder.createLoad(loc, dst.getVectorAddress());
221221
const mlir::Value newVector = builder.create<cir::VecInsertOp>(
222-
loc, vector, src.getScalarVal(), dst.getVectorIdx());
222+
loc, vector, src.getValue(), dst.getVectorIdx());
223223
builder.createStore(loc, newVector, dst.getVectorAddress());
224224
return;
225225
}
@@ -232,7 +232,7 @@ void CIRGenFunction::emitStoreThroughLValue(RValue src, LValue dst,
232232
assert(!cir::MissingFeatures::opLoadStoreObjC());
233233

234234
assert(src.isScalar() && "Can't emit an aggregate store with this method");
235-
emitStoreOfScalar(src.getScalarVal(), dst, isInit);
235+
emitStoreOfScalar(src.getValue(), dst, isInit);
236236
}
237237

238238
static LValue emitGlobalVarDeclLValue(CIRGenFunction &cgf, const Expr *e,
@@ -949,7 +949,7 @@ LValue CIRGenFunction::emitCallExprLValue(const CallExpr *e) {
949949
"Can't have a scalar return unless the return type is a "
950950
"reference type!");
951951

952-
return makeNaturalAlignPointeeAddrLValue(rv.getScalarVal(), e->getType());
952+
return makeNaturalAlignPointeeAddrLValue(rv.getValue(), e->getType());
953953
}
954954

955955
LValue CIRGenFunction::emitBinaryOperatorLValue(const BinaryOperator *e) {

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
131131
mlir::Value emitLoadOfLValue(const Expr *e) {
132132
LValue lv = cgf.emitLValue(e);
133133
// FIXME: add some akin to EmitLValueAlignmentAssumption(E, V);
134-
return cgf.emitLoadOfLValue(lv, e->getExprLoc()).getScalarVal();
134+
return cgf.emitLoadOfLValue(lv, e->getExprLoc()).getValue();
135135
}
136136

137137
mlir::Value emitLoadOfLValue(LValue lv, SourceLocation loc) {
138-
return cgf.emitLoadOfLValue(lv, loc).getScalarVal();
138+
return cgf.emitLoadOfLValue(lv, loc).getValue();
139139
}
140140

141141
// l-values
@@ -400,10 +400,10 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
400400
cgf.cgm.errorNYI(e->getSourceRange(), "Atomic inc/dec");
401401
// TODO(cir): This is not correct, but it will produce reasonable code
402402
// until atomic operations are implemented.
403-
value = cgf.emitLoadOfLValue(lv, e->getExprLoc()).getScalarVal();
403+
value = cgf.emitLoadOfLValue(lv, e->getExprLoc()).getValue();
404404
input = value;
405405
} else {
406-
value = cgf.emitLoadOfLValue(lv, e->getExprLoc()).getScalarVal();
406+
value = cgf.emitLoadOfLValue(lv, e->getExprLoc()).getValue();
407407
input = value;
408408
}
409409

@@ -1805,7 +1805,7 @@ mlir::Value ScalarExprEmitter::VisitCallExpr(const CallExpr *e) {
18051805
if (e->getCallReturnType(cgf.getContext())->isReferenceType())
18061806
return emitLoadOfLValue(e);
18071807

1808-
auto v = cgf.emitCallExpr(e).getScalarVal();
1808+
auto v = cgf.emitCallExpr(e).getValue();
18091809
assert(!cir::MissingFeatures::emitLValueAlignmentAssumption());
18101810
return v;
18111811
}

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,7 @@ mlir::LogicalResult CIRGenFunction::emitReturnStmt(const ReturnStmt &s) {
391391
// If this function returns a reference, take the address of the
392392
// expression rather than the value.
393393
RValue result = emitReferenceBindingToExpr(rv);
394-
builder.CIRBaseBuilderTy::createStore(loc, result.getScalarVal(),
395-
*fnRetAlloca);
394+
builder.CIRBaseBuilderTy::createStore(loc, result.getValue(), *fnRetAlloca);
396395
} else {
397396
mlir::Value value = nullptr;
398397
switch (CIRGenFunction::getEvaluationKind(rv->getType())) {

clang/lib/CIR/CodeGen/CIRGenValue.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ class RValue {
3333
enum Flavor { Scalar, Complex, Aggregate };
3434

3535
union {
36-
// Stores first and second value.
37-
struct {
38-
mlir::Value first;
39-
mlir::Value second;
40-
} vals;
36+
mlir::Value value;
4137

4238
// Stores aggregate address.
4339
Address aggregateAddr;
@@ -47,7 +43,7 @@ class RValue {
4743
unsigned flavor : 2;
4844

4945
public:
50-
RValue() : vals{nullptr, nullptr}, flavor(Scalar) {}
46+
RValue() : value(nullptr), flavor(Scalar) {}
5147

5248
bool isScalar() const { return flavor == Scalar; }
5349
bool isComplex() const { return flavor == Complex; }
@@ -56,14 +52,9 @@ class RValue {
5652
bool isVolatileQualified() const { return isVolatile; }
5753

5854
/// Return the value of this scalar value.
59-
mlir::Value getScalarVal() const {
55+
mlir::Value getValue() const {
6056
assert(isScalar() && "Not a scalar!");
61-
return vals.first;
62-
}
63-
64-
/// Return the real/imag components of this complex value.
65-
std::pair<mlir::Value, mlir::Value> getComplexVal() const {
66-
return std::make_pair(vals.first, vals.second);
57+
return value;
6758
}
6859

6960
/// Return the value of the address of the aggregate.
@@ -83,22 +74,20 @@ class RValue {
8374

8475
static RValue get(mlir::Value v) {
8576
RValue er;
86-
er.vals.first = v;
77+
er.value = v;
8778
er.flavor = Scalar;
8879
er.isVolatile = false;
8980
return er;
9081
}
9182

92-
static RValue getComplex(mlir::Value v1, mlir::Value v2) {
83+
static RValue getComplex(mlir::Value v) {
9384
RValue er;
94-
er.vals = {v1, v2};
85+
er.value = v;
9586
er.flavor = Complex;
9687
er.isVolatile = false;
9788
return er;
9889
}
99-
static RValue getComplex(const std::pair<mlir::Value, mlir::Value> &c) {
100-
return getComplex(c.first, c.second);
101-
}
90+
10291
// FIXME: Aggregate rvalues need to retain information about whether they are
10392
// volatile or not. Remove default to find all places that probably get this
10493
// wrong.

0 commit comments

Comments
 (0)