Skip to content

Commit 35f7139

Browse files
committed
Revert partial changes in the previous commit
1 parent 09b8f2d commit 35f7139

12 files changed

+68
-92
lines changed

clang/lib/CIR/CodeGen/CIRGenCXX.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ static void buildDeclInit(CIRGenFunction &CGF, const VarDecl *D,
200200
case TEK_Scalar:
201201
CGF.buildScalarInit(Init, CGF.getLoc(D->getLocation()), lv, false);
202202
return;
203+
case TEK_Complex:
204+
llvm_unreachable("complext evaluation NYI");
203205
}
204206
}
205207

clang/lib/CIR/CodeGen/CIRGenClass.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,9 @@ void CIRGenFunction::buildInitializerForField(FieldDecl *Field, LValue LHS,
804804
llvm_unreachable("NYI");
805805
}
806806
break;
807+
case TEK_Complex:
808+
llvm_unreachable("NYI");
809+
break;
807810
case TEK_Aggregate: {
808811
AggValueSlot Slot = AggValueSlot::forLValue(
809812
LHS, AggValueSlot::IsDestructed, AggValueSlot::DoesNotNeedGCBarriers,

clang/lib/CIR/CodeGen/CIRGenDecl.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,12 @@ void CIRGenFunction::buildExprAsInit(const Expr *init, const ValueDecl *D,
700700
return;
701701
}
702702
switch (CIRGenFunction::getEvaluationKind(type)) {
703-
case TEK_Scalar: {
703+
case TEK_Scalar:
704704
buildScalarInit(init, getLoc(D->getSourceRange()), lvalue);
705705
return;
706+
case TEK_Complex: {
707+
assert(0 && "not implemented");
708+
return;
706709
}
707710
case TEK_Aggregate:
708711
assert(!type->isAtomicType() && "NYI");

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,8 @@ LValue CIRGenFunction::buildBinaryOperatorLValue(const BinaryOperator *E) {
974974
return LV;
975975
}
976976

977+
case TEK_Complex:
978+
assert(0 && "not implemented");
977979
case TEK_Aggregate:
978980
assert(0 && "not implemented");
979981
}
@@ -1063,6 +1065,8 @@ RValue CIRGenFunction::buildAnyExpr(const Expr *E, AggValueSlot aggSlot,
10631065
switch (CIRGenFunction::getEvaluationKind(E->getType())) {
10641066
case TEK_Scalar:
10651067
return RValue::get(buildScalarExpr(E));
1068+
case TEK_Complex:
1069+
assert(0 && "not implemented");
10661070
case TEK_Aggregate: {
10671071
if (!ignoreResult && aggSlot.isIgnored())
10681072
aggSlot = CreateAggTemp(E->getType(), getLoc(E->getSourceRange()),
@@ -1850,6 +1854,10 @@ void CIRGenFunction::buildAnyExprToMem(const Expr *E, Address Location,
18501854
Qualifiers Quals, bool IsInit) {
18511855
// FIXME: This function should take an LValue as an argument.
18521856
switch (getEvaluationKind(E->getType())) {
1857+
case TEK_Complex:
1858+
assert(0 && "NYI");
1859+
return;
1860+
18531861
case TEK_Aggregate: {
18541862
buildAggExpr(E, AggValueSlot::forAddr(Location, Quals,
18551863
AggValueSlot::IsDestructed_t(IsInit),
@@ -2298,6 +2306,8 @@ RValue CIRGenFunction::convertTempToRValue(Address addr, clang::QualType type,
22982306
clang::SourceLocation loc) {
22992307
LValue lvalue = makeAddrLValue(addr, type, AlignmentSource::Decl);
23002308
switch (getEvaluationKind(type)) {
2309+
case TEK_Complex:
2310+
llvm_unreachable("NYI");
23012311
case TEK_Aggregate:
23022312
llvm_unreachable("NYI");
23032313
case TEK_Scalar:

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,9 @@ void AggExprEmitter::buildInitializationToLValue(Expr *E, LValue LV) {
782782
}
783783

784784
switch (CGF.getEvaluationKind(type)) {
785+
case TEK_Complex:
786+
llvm_unreachable("NYI");
787+
return;
785788
case TEK_Aggregate:
786789
CGF.buildAggExpr(
787790
E, AggValueSlot::forLValue(LV, AggValueSlot::IsDestructed,

clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ static void StoreAnyExprIntoOneUnit(CIRGenFunction &CGF, const Expr *Init,
592592
CGF.buildScalarInit(Init, CGF.getLoc(Init->getSourceRange()),
593593
CGF.makeAddrLValue(NewPtr, AllocType), false);
594594
return;
595+
case TEK_Complex:
596+
llvm_unreachable("NYI");
597+
return;
595598
case TEK_Aggregate: {
596599
AggValueSlot Slot = AggValueSlot::forAddr(
597600
NewPtr, AllocType.getQualifiers(), AggValueSlot::IsDestructed,

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

+14-85
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,6 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
171171
CGF.getLoc(E->getExprLoc()), Ty,
172172
Builder.getAttr<mlir::cir::FPAttr>(Ty, E->getValue()));
173173
}
174-
mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *E) {
175-
auto Loc = CGF.getLoc(E->getExprLoc());
176-
auto Ty = CGF.getCIRType(E->getType()).cast<mlir::cir::ComplexType>();
177-
auto ElementTy = Ty.getElementTy();
178-
179-
mlir::TypedAttr Real = Builder.getZeroInitAttr(ElementTy);
180-
mlir::TypedAttr Imag;
181-
if (ElementTy.isa<mlir::cir::IntType>()) {
182-
auto RealValue = cast<IntegerLiteral>(E->getSubExpr())->getValue();
183-
Imag = mlir::cir::IntAttr::get(ElementTy, RealValue);
184-
} else if (ElementTy.isa<mlir::cir::CIRFPTypeInterface>()) {
185-
auto RealValue = cast<FloatingLiteral>(E->getSubExpr())->getValue();
186-
Imag = mlir::cir::FPAttr::get(ElementTy, RealValue);
187-
} else
188-
llvm_unreachable("unexpected complex element type");
189-
190-
auto Attr = mlir::cir::ComplexAttr::get(Ty, Real, Imag);
191-
return Builder.getConstant(Loc, Attr);
192-
}
193174
mlir::Value VisitCharacterLiteral(const CharacterLiteral *E) {
194175
mlir::Type Ty = CGF.getCIRType(E->getType());
195176
auto loc = CGF.getLoc(E->getExprLoc());
@@ -746,45 +727,9 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
746727
Result.Loc = E->getSourceRange();
747728
// TODO: Result.FPFeatures
748729
Result.E = E;
749-
750-
buildComplexPromotion(Result);
751-
752730
return Result;
753731
}
754732

755-
// If any of the two operands of a binary operation is of complex type,
756-
// ensure both operands are promoted to complex type.
757-
void buildComplexPromotion(BinOpInfo &Info) {
758-
auto LHSTy = Info.LHS.getType().dyn_cast<mlir::cir::ComplexType>();
759-
auto RHSTy = Info.RHS.getType().dyn_cast<mlir::cir::ComplexType>();
760-
if (!LHSTy && !RHSTy)
761-
return;
762-
763-
if (LHSTy && RHSTy)
764-
return;
765-
766-
// We need to promote *Scalar to ComplexTy.
767-
mlir::Value *Scalar;
768-
mlir::cir::ComplexType ComplexTy;
769-
if (LHSTy) {
770-
Scalar = &Info.RHS;
771-
ComplexTy = LHSTy;
772-
} else {
773-
Scalar = &Info.LHS;
774-
ComplexTy = RHSTy;
775-
}
776-
777-
mlir::cir::CastKind Kind;
778-
if (Scalar->getType().isa<mlir::cir::IntType>())
779-
Kind = mlir::cir::CastKind::int_to_complex;
780-
else if (Scalar->getType().isa<mlir::cir::CIRFPTypeInterface>())
781-
Kind = mlir::cir::CastKind::float_to_complex;
782-
else
783-
llvm_unreachable("unexpected complex promotion candidate");
784-
785-
*Scalar = Builder.createCast(Kind, *Scalar, ComplexTy);
786-
}
787-
788733
mlir::Value buildMul(const BinOpInfo &Ops);
789734
mlir::Value buildDiv(const BinOpInfo &Ops);
790735
mlir::Value buildRem(const BinOpInfo &Ops);
@@ -808,9 +753,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
808753
// codegen.
809754
QualType getPromotionType(QualType Ty) {
810755
if (auto *CT = Ty->getAs<ComplexType>()) {
811-
QualType ElementType = CT->getElementType();
812-
if (ElementType.UseExcessPrecision(CGF.getContext()))
813-
llvm_unreachable("NYI");
756+
llvm_unreachable("NYI");
814757
}
815758
if (Ty.UseExcessPrecision(CGF.getContext()))
816759
llvm_unreachable("NYI");
@@ -820,8 +763,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
820763
// Binary operators and binary compound assignment operators.
821764
#define HANDLEBINOP(OP) \
822765
mlir::Value VisitBin##OP(const BinaryOperator *E) { \
823-
auto binOpInfo = buildBinOps(E); \
824-
return build##OP(binOpInfo); \
766+
return build##OP(buildBinOps(E)); \
825767
} \
826768
mlir::Value VisitBin##OP##Assign(const CompoundAssignOperator *E) { \
827769
return buildCompoundAssign(E, &ScalarExprEmitter::build##OP); \
@@ -1549,25 +1491,14 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
15491491
llvm_unreachable("NYI");
15501492
case CK_CopyAndAutoreleaseBlockObject:
15511493
llvm_unreachable("NYI");
1552-
case CK_IntegralRealToComplex: {
1553-
auto DestComplexTy = ConvertType(DestTy).cast<mlir::cir::ComplexType>();
1554-
auto Src = Visit(const_cast<Expr *>(E));
1555-
return Builder.createCast(mlir::cir::CastKind::int_to_complex, Src,
1556-
DestComplexTy);
1557-
}
1558-
case CK_FloatingRealToComplex: {
1559-
auto DestComplexTy = ConvertType(DestTy).cast<mlir::cir::ComplexType>();
1560-
auto Src = Visit(const_cast<Expr *>(E));
1561-
return Builder.createCast(mlir::cir::CastKind::float_to_complex, Src,
1562-
DestComplexTy);
1563-
}
1494+
case CK_FloatingRealToComplex:
1495+
llvm_unreachable("NYI");
15641496
case CK_FloatingComplexCast:
1497+
llvm_unreachable("NYI");
15651498
case CK_IntegralComplexToFloatingComplex:
1566-
case CK_FloatingComplexToIntegralComplex: {
1567-
auto DestComplexTy = ConvertType(DestTy).cast<mlir::cir::ComplexType>();
1568-
auto Src = Visit(const_cast<Expr *>(E));
1569-
return Builder.createCast(mlir::cir::CastKind::complex, Src, DestComplexTy);
1570-
}
1499+
llvm_unreachable("NYI");
1500+
case CK_FloatingComplexToIntegralComplex:
1501+
llvm_unreachable("NYI");
15711502
case CK_ConstructorConversion:
15721503
llvm_unreachable("NYI");
15731504
case CK_ToUnion:
@@ -1659,15 +1590,13 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
16591590
case CK_MemberPointerToBoolean:
16601591
llvm_unreachable("NYI");
16611592
case CK_FloatingComplexToReal:
1662-
case CK_IntegralComplexToReal: {
1663-
auto Src = Visit(const_cast<Expr *>(E));
1664-
return Builder.createComplexReal(CGF.getLoc(CE->getSourceRange()), Src);
1665-
}
1593+
llvm_unreachable("NYI");
1594+
case CK_IntegralComplexToReal:
1595+
llvm_unreachable("NYI");
16661596
case CK_FloatingComplexToBoolean:
1667-
case CK_IntegralComplexToBoolean: {
1668-
auto Src = Visit(const_cast<Expr *>(E));
1669-
return Builder.createComplexIsZero(CGF.getLoc(CE->getSourceRange()), Src);
1670-
}
1597+
llvm_unreachable("NYI");
1598+
case CK_IntegralComplexToBoolean:
1599+
llvm_unreachable("NYI");
16711600
case CK_ZeroToOCLOpaqueType:
16721601
llvm_unreachable("NYI");
16731602
case CK_IntToOCLSampler:

clang/lib/CIR/CodeGen/CIRGenFunction.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ TypeEvaluationKind CIRGenFunction::getEvaluationKind(QualType type) {
8484
case Type::ObjCObjectPointer:
8585
case Type::Pipe:
8686
case Type::BitInt:
87-
case Type::Complex: // In CIR we treat complex types as scalars
8887
return TEK_Scalar;
8988

89+
// Complexes.
90+
case Type::Complex:
91+
return TEK_Complex;
92+
9093
// Arrays, records, and Objective-C objects.
9194
case Type::ConstantArray:
9295
case Type::IncompleteArray:

clang/lib/CIR/CodeGen/CIRGenFunction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace cir {
5050

5151
// FIXME: for now we are reusing this from lib/Clang/CIRGenFunction.h, which
5252
// isn't available in the include dir. Same for getEvaluationKind below.
53-
enum TypeEvaluationKind { TEK_Scalar, TEK_Aggregate };
53+
enum TypeEvaluationKind { TEK_Scalar, TEK_Complex, TEK_Aggregate };
5454
struct CGCoroData;
5555

5656
class CIRGenFunction : public CIRGenTypeCache {

clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,9 @@ static void InitCatchParam(CIRGenFunction &CGF, const VarDecl &CatchParam,
717717
LValue srcLV = CGF.MakeNaturalAlignAddrLValue(catchParam, CatchType);
718718
LValue destLV = CGF.makeAddrLValue(ParamAddr, CatchType);
719719
switch (TEK) {
720+
case TEK_Complex:
721+
llvm_unreachable("NYI");
722+
return;
720723
case TEK_Scalar: {
721724
auto exnLoad = CGF.buildLoadOfScalar(srcLV, catchParam.getLoc());
722725
CGF.buildStoreOfScalar(exnLoad, destLV, /*init*/ true);

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,9 @@ mlir::LogicalResult CIRGenFunction::buildReturnStmt(const ReturnStmt &S) {
500500
V = buildScalarExpr(RV);
501501
builder.create<mlir::cir::StoreOp>(loc, V, *FnRetAlloca);
502502
break;
503+
case TEK_Complex:
504+
llvm_unreachable("NYI");
505+
break;
503506
case TEK_Aggregate:
504507
buildAggExpr(
505508
RV, AggValueSlot::forAddr(

clang/lib/CIR/CodeGen/CIRGenValue.h

+18-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ namespace cir {
3030

3131
/// This trivial value class is used to represent the result of an
3232
/// expression that is evaluated. It can be one of three things: either a
33-
/// simple MLIR SSA value, or the address of an aggregate value in memory.
34-
///
35-
/// Note that in CIR, we treat expressions of complex type as scalars.
33+
/// simple MLIR SSA value, a pair of SSA values for complex numbers, or the
34+
/// address of an aggregate value in memory.
3635
class RValue {
37-
enum Flavor { Scalar, Aggregate };
36+
enum Flavor { Scalar, Complex, Aggregate };
3837

3938
// The shift to make to an aggregate's alignment to make it look
4039
// like a pointer.
@@ -49,6 +48,7 @@ class RValue {
4948

5049
public:
5150
bool isScalar() const { return V1.getInt() == Scalar; }
51+
bool isComplex() const { return V1.getInt() == Complex; }
5252
bool isAggregate() const { return V1.getInt() == Aggregate; }
5353
bool isIgnored() const { return isScalar() && !getScalarVal(); }
5454

@@ -60,6 +60,12 @@ class RValue {
6060
return V1.getPointer();
6161
}
6262

63+
/// Return the real/imag components of this complex value.
64+
std::pair<mlir::Value, mlir::Value> getComplexVal() const {
65+
assert(0 && "not implemented");
66+
return {};
67+
}
68+
6369
/// Return the mlir::Value of the address of the aggregate.
6470
Address getAggregateAddress() const {
6571
assert(isAggregate() && "Not an aggregate!");
@@ -86,6 +92,14 @@ class RValue {
8692
ER.V2.setInt(false);
8793
return ER;
8894
}
95+
static RValue getComplex(mlir::Value V1, mlir::Value V2) {
96+
assert(0 && "not implemented");
97+
return RValue{};
98+
}
99+
static RValue getComplex(const std::pair<mlir::Value, mlir::Value> &C) {
100+
assert(0 && "not implemented");
101+
return RValue{};
102+
}
89103
// FIXME: Aggregate rvalues need to retain information about whether they are
90104
// volatile or not. Remove default to find all places that probably get this
91105
// wrong.

0 commit comments

Comments
 (0)