-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[CIR] Upstream global initialization for ComplexType #141369
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
Changes from all commits
cd8321c
404e7d8
ec9fb3c
476374c
9d6d5a8
aa60e6f
1ef6589
850ee56
cb1d401
50ac739
187780a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines the CIR dialect attributes constraints. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD | ||
#define CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD | ||
|
||
include "mlir/IR/CommonAttrConstraints.td" | ||
|
||
class CIR_IsAttrPred<code attr> : CPred<"::mlir::isa<" # attr # ">($_self)">; | ||
|
||
class CIR_AttrConstraint<code attr, string summary = ""> | ||
: Attr<CIR_IsAttrPred<attr>, summary>; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// IntAttr constraints | ||
//===----------------------------------------------------------------------===// | ||
|
||
def CIR_AnyIntAttr : CIR_AttrConstraint<"::cir::IntAttr", "integer attribute">; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// FPAttr constraints | ||
//===----------------------------------------------------------------------===// | ||
|
||
def CIR_AnyFPAttr : CIR_AttrConstraint<"::cir::FPAttr", | ||
"floating-point attribute">; | ||
|
||
def CIR_AnyIntOrFloatAttr : AnyAttrOf<[CIR_AnyIntAttr, CIR_AnyFPAttr], | ||
"integer or floating point type"> { | ||
string cppType = "::mlir::TypedAttr"; | ||
} | ||
|
||
#endif // CLANG_CIR_DIALECT_IR_CIRATTRCONSTRAINTS_TD |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,56 @@ def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> { | |
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// ComplexType | ||
//===----------------------------------------------------------------------===// | ||
|
||
def CIR_ComplexType : CIR_Type<"Complex", "complex", | ||
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> { | ||
|
||
let summary = "CIR complex type"; | ||
let description = [{ | ||
CIR type that represents a C complex number. `cir.complex` models the C type | ||
`T _Complex`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment here mentioning how this relates to std::complex would be useful. Note that the representation of std::complex depends on the header file and I believe can even vary depending on which preprocessor symbols are defined (which maybe depends on the target). I don't want a comprehensive explanation of all possibilities here, just a general note explaining that this doesn't directly map to std::complex. I'm not sure what guarantees the C++ standard makes about the implementation of std::complex, but it would be very nice if we could in some way indicate when std::complex is being used. It looks like std::complex is generally unsupported in the incubator, so there's some work to be done to figure that out, I think. |
||
|
||
`cir.complex` type is not directly mapped to `std::complex`. | ||
|
||
The type models complex values, per C99 6.2.5p11. It supports the C99 | ||
complex float types as well as the GCC integer complex extensions. | ||
|
||
The parameter `elementType` gives the type of the real and imaginary part of | ||
the complex number. `elementType` must be either a CIR integer type or a CIR | ||
floating-point type. | ||
bcardosolopes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```mlir | ||
!cir.complex<!s32i> | ||
!cir.complex<!cir.float> | ||
``` | ||
}]; | ||
|
||
let parameters = (ins CIR_AnyIntOrFloatType:$elementType); | ||
|
||
let builders = [ | ||
TypeBuilderWithInferredContext<(ins "mlir::Type":$elementType), [{ | ||
return $_get(elementType.getContext(), elementType); | ||
}]>, | ||
]; | ||
|
||
let assemblyFormat = [{ | ||
`<` $elementType `>` | ||
}]; | ||
|
||
let extraClassDeclaration = [{ | ||
bool isFloatingPointComplex() const { | ||
return isAnyFloatingPointType(getElementType()); | ||
} | ||
|
||
bool isIntegerComplex() const { | ||
return mlir::isa<cir::IntType>(getElementType()); | ||
} | ||
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// PointerType | ||
//===----------------------------------------------------------------------===// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -577,12 +577,33 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value, | |
case APValue::Union: | ||
cgm.errorNYI("ConstExprEmitter::tryEmitPrivate struct or union"); | ||
return {}; | ||
case APValue::FixedPoint: | ||
case APValue::ComplexInt: | ||
case APValue::ComplexFloat: | ||
case APValue::ComplexFloat: { | ||
mlir::Type desiredType = cgm.convertType(destType); | ||
cir::ComplexType complexType = | ||
mlir::dyn_cast<cir::ComplexType>(desiredType); | ||
|
||
mlir::Type complexElemTy = complexType.getElementType(); | ||
if (isa<cir::IntType>(complexElemTy)) { | ||
llvm::APSInt real = value.getComplexIntReal(); | ||
llvm::APSInt imag = value.getComplexIntImag(); | ||
return builder.getAttr<cir::ConstComplexAttr>( | ||
complexType, builder.getAttr<cir::IntAttr>(complexElemTy, real), | ||
builder.getAttr<cir::IntAttr>(complexElemTy, imag)); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should you assert There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think |
||
assert(isa<cir::CIRFPTypeInterface>(complexElemTy) && | ||
"expected floating-point type"); | ||
llvm::APFloat real = value.getComplexFloatReal(); | ||
llvm::APFloat imag = value.getComplexFloatImag(); | ||
return builder.getAttr<cir::ConstComplexAttr>( | ||
complexType, builder.getAttr<cir::FPAttr>(complexElemTy, real), | ||
builder.getAttr<cir::FPAttr>(complexElemTy, imag)); | ||
} | ||
case APValue::FixedPoint: | ||
case APValue::AddrLabelDiff: | ||
cgm.errorNYI("ConstExprEmitter::tryEmitPrivate fixed point, complex int, " | ||
"complex float, addr label diff"); | ||
cgm.errorNYI( | ||
"ConstExprEmitter::tryEmitPrivate fixed point, addr label diff"); | ||
return {}; | ||
} | ||
llvm_unreachable("Unknown APValue kind"); | ||
|
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.
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.
I will check why, but
def CIR_AnyIntOrFloatAttr : AnyAttrOf<[CIR_AnyIntAttr, CIR_AnyFPAttr], "integer or floating point type", "::mlir::TypedAttr">;
still reportMissing
cppTypefield in Attribute/Type parameter: CIR_AnyIntOrFloatAttr
It should be the same before and after the suggestion because it the third param
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.
lgtm then, I can polish this when merged :)
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.
I updated the other suggestion, for this one, I will try to see why it's not working on the side
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.
If there is no other comment, I can merge now 🤔 @xlauko ?