-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CIR] Upstream Cast kinds for ComplexType #149717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8a3e3e8
[CIR] Upstream Cast kinds for ComplexType
AmrDeveloper 13cc762
Address code review comments
AmrDeveloper 7c43c07
Address code review comments
AmrDeveloper 1c6ce40
Fix Complex to Complex cast
AmrDeveloper 7611b81
Update test to use regex
AmrDeveloper eb5d912
Address code review comment
AmrDeveloper 7bb89b6
Address code review comments
AmrDeveloper bf5393d
Address code review comments
AmrDeveloper ab1687c
Update llvm_unreachable message
AmrDeveloper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,19 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { | |
} | ||
|
||
mlir::Value emitLoadOfLValue(LValue lv, SourceLocation loc); | ||
|
||
/// Store the specified real/imag parts into the | ||
/// specified value pointer. | ||
void emitStoreOfComplex(mlir::Location loc, mlir::Value val, LValue lv, | ||
bool isInit); | ||
|
||
/// Emit a cast from complex value Val to DestType. | ||
mlir::Value emitComplexToComplexCast(mlir::Value Val, QualType SrcType, | ||
QualType DestType, SourceLocation Loc); | ||
/// Emit a cast from scalar value Val to DestType. | ||
mlir::Value emitScalarToComplexCast(mlir::Value Val, QualType SrcType, | ||
QualType DestType, SourceLocation Loc); | ||
|
||
mlir::Value | ||
VisitAbstractConditionalOperator(const AbstractConditionalOperator *e); | ||
mlir::Value VisitArraySubscriptExpr(Expr *e); | ||
|
@@ -164,14 +172,99 @@ LValue ComplexExprEmitter::emitBinAssignLValue(const BinaryOperator *e, | |
mlir::Value ComplexExprEmitter::emitCast(CastKind ck, Expr *op, | ||
QualType destTy) { | ||
switch (ck) { | ||
case CK_Dependent: | ||
llvm_unreachable("dependent cast kind in IR gen!"); | ||
|
||
case CK_NoOp: | ||
case CK_LValueToRValue: | ||
return Visit(op); | ||
default: | ||
break; | ||
|
||
case CK_AtomicToNonAtomic: | ||
case CK_NonAtomicToAtomic: | ||
case CK_UserDefinedConversion: | ||
llvm_unreachable("NYI"); | ||
|
||
|
||
case CK_LValueBitCast: | ||
llvm_unreachable("NYI"); | ||
|
||
case CK_LValueToRValueBitCast: | ||
llvm_unreachable("NYI"); | ||
|
||
case CK_BitCast: | ||
case CK_BaseToDerived: | ||
case CK_DerivedToBase: | ||
case CK_UncheckedDerivedToBase: | ||
case CK_Dynamic: | ||
case CK_ToUnion: | ||
case CK_ArrayToPointerDecay: | ||
case CK_FunctionToPointerDecay: | ||
case CK_NullToPointer: | ||
case CK_NullToMemberPointer: | ||
case CK_BaseToDerivedMemberPointer: | ||
case CK_DerivedToBaseMemberPointer: | ||
case CK_MemberPointerToBoolean: | ||
case CK_ReinterpretMemberPointer: | ||
case CK_ConstructorConversion: | ||
case CK_IntegralToPointer: | ||
case CK_PointerToIntegral: | ||
case CK_PointerToBoolean: | ||
case CK_ToVoid: | ||
case CK_VectorSplat: | ||
case CK_IntegralCast: | ||
case CK_BooleanToSignedIntegral: | ||
case CK_IntegralToBoolean: | ||
case CK_IntegralToFloating: | ||
case CK_FloatingToIntegral: | ||
case CK_FloatingToBoolean: | ||
case CK_FloatingCast: | ||
case CK_CPointerToObjCPointerCast: | ||
case CK_BlockPointerToObjCPointerCast: | ||
case CK_AnyPointerToBlockPointerCast: | ||
case CK_ObjCObjectLValueCast: | ||
case CK_FloatingComplexToReal: | ||
case CK_FloatingComplexToBoolean: | ||
case CK_IntegralComplexToReal: | ||
case CK_IntegralComplexToBoolean: | ||
case CK_ARCProduceObject: | ||
case CK_ARCConsumeObject: | ||
case CK_ARCReclaimReturnedObject: | ||
case CK_ARCExtendBlockObject: | ||
case CK_CopyAndAutoreleaseBlockObject: | ||
case CK_BuiltinFnToFnPtr: | ||
case CK_ZeroToOCLOpaqueType: | ||
case CK_AddressSpaceConversion: | ||
case CK_IntToOCLSampler: | ||
case CK_FloatingToFixedPoint: | ||
case CK_FixedPointToFloating: | ||
case CK_FixedPointCast: | ||
case CK_FixedPointToBoolean: | ||
case CK_FixedPointToIntegral: | ||
case CK_IntegralToFixedPoint: | ||
case CK_MatrixCast: | ||
case CK_HLSLVectorTruncation: | ||
case CK_HLSLArrayRValue: | ||
case CK_HLSLElementwiseCast: | ||
case CK_HLSLAggregateSplatCast: | ||
llvm_unreachable("invalid cast kind for complex value"); | ||
|
||
case CK_FloatingRealToComplex: | ||
case CK_IntegralRealToComplex: { | ||
assert(!cir::MissingFeatures::cgFPOptionsRAII()); | ||
return emitScalarToComplexCast(cgf.emitScalarExpr(op), op->getType(), | ||
destTy, op->getExprLoc()); | ||
} | ||
cgf.cgm.errorNYI("ComplexType Cast"); | ||
return {}; | ||
|
||
case CK_FloatingComplexCast: | ||
case CK_FloatingComplexToIntegralComplex: | ||
case CK_IntegralComplexCast: | ||
case CK_IntegralComplexToFloatingComplex: { | ||
assert(!cir::MissingFeatures::cgFPOptionsRAII()); | ||
return emitComplexToComplexCast(Visit(op), op->getType(), destTy, | ||
op->getExprLoc()); | ||
} | ||
} | ||
|
||
llvm_unreachable("unknown cast resulting in complex value"); | ||
} | ||
|
||
mlir::Value ComplexExprEmitter::emitConstant( | ||
|
@@ -207,6 +300,49 @@ void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val, | |
builder.createStore(loc, val, destAddr); | ||
} | ||
|
||
mlir::Value ComplexExprEmitter::emitComplexToComplexCast(mlir::Value val, | ||
QualType srcType, | ||
QualType destType, | ||
SourceLocation loc) { | ||
if (srcType == destType) | ||
return val; | ||
|
||
// Get the src/dest element type. | ||
QualType srcElemTy = srcType->castAs<ComplexType>()->getElementType(); | ||
QualType destElemTy = destType->castAs<ComplexType>()->getElementType(); | ||
|
||
cir::CastKind castOpKind; | ||
if (srcElemTy->isFloatingType() && destElemTy->isFloatingType()) | ||
castOpKind = cir::CastKind::float_complex; | ||
else if (srcElemTy->isFloatingType() && destElemTy->isIntegerType()) | ||
castOpKind = cir::CastKind::float_complex_to_int_complex; | ||
else if (srcElemTy->isIntegerType() && destElemTy->isFloatingType()) | ||
castOpKind = cir::CastKind::int_complex_to_float_complex; | ||
else if (srcElemTy->isIntegerType() && destElemTy->isIntegerType()) | ||
castOpKind = cir::CastKind::int_complex; | ||
else | ||
llvm_unreachable("unexpected src type or dest type"); | ||
xlauko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return builder.createCast(cgf.getLoc(loc), castOpKind, val, | ||
cgf.convertType(destType)); | ||
} | ||
|
||
mlir::Value ComplexExprEmitter::emitScalarToComplexCast(mlir::Value val, | ||
QualType srcType, | ||
QualType destType, | ||
SourceLocation loc) { | ||
cir::CastKind castOpKind; | ||
if (srcType->isFloatingType()) | ||
castOpKind = cir::CastKind::float_to_complex; | ||
else if (srcType->isIntegerType()) | ||
castOpKind = cir::CastKind::int_to_complex; | ||
else | ||
llvm_unreachable("unexpected src type"); | ||
xlauko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return builder.createCast(cgf.getLoc(loc), castOpKind, val, | ||
cgf.convertType(destType)); | ||
} | ||
|
||
mlir::Value ComplexExprEmitter::VisitAbstractConditionalOperator( | ||
const AbstractConditionalOperator *e) { | ||
mlir::Value condValue = Visit(e->getCond()); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we improve this message, so that it is clear why this should never come here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can change it to something like "dependent type must be resolved before the Codegen" 🤔 @xlauko
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe "dependent type must be resolved before the CIR codegen"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated :D, I will merge after CI is green if there are no other comments