Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {

mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand) {
auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
return create<cir::ComplexRealOp>(loc, operandTy.getElementTy(), operand);
return create<cir::ComplexRealOp>(loc, operandTy.getElementType(), operand);
}

mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand) {
auto operandTy = mlir::cast<cir::ComplexType>(operand.getType());
return create<cir::ComplexImagOp>(loc, operandTy.getElementTy(), operand);
return create<cir::ComplexImagOp>(loc, operandTy.getElementType(), operand);
}

mlir::Value createComplexBinOp(mlir::Location loc, mlir::Value lhs,
Expand Down
13 changes: 8 additions & 5 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,10 @@ def ComplexCreateOp : CIR_Op<"complex.create", [Pure, SameTypeOperands]> {
}];

let results = (outs CIR_ComplexType:$result);
let arguments = (ins CIR_AnyIntOrFloat:$real, CIR_AnyIntOrFloat:$imag);
let arguments = (ins
CIR_AnyIntOrFloatType:$real,
CIR_AnyIntOrFloatType:$imag
);

let assemblyFormat = [{
$real `,` $imag
Expand Down Expand Up @@ -1414,7 +1417,7 @@ def ComplexRealOp : CIR_Op<"complex.real", [Pure]> {
```
}];

let results = (outs CIR_AnyIntOrFloat:$result);
let results = (outs CIR_AnyIntOrFloatType:$result);
let arguments = (ins CIR_ComplexType:$operand);

let assemblyFormat = [{
Expand All @@ -1439,7 +1442,7 @@ def ComplexImagOp : CIR_Op<"complex.imag", [Pure]> {
```
}];

let results = (outs CIR_AnyIntOrFloat:$result);
let results = (outs CIR_AnyIntOrFloatType:$result);
let arguments = (ins CIR_ComplexType:$operand);

let assemblyFormat = [{
Expand Down Expand Up @@ -5564,9 +5567,9 @@ def AtomicFetch : CIR_Op<"atomic.fetch",
%res = cir.atomic.fetch(add, %ptr : !cir.ptr<!s32i>,
%val : !s32i, seq_cst) : !s32i
}];
let results = (outs CIR_AnyIntOrFloat:$result);
let results = (outs CIR_AnyIntOrFloatType:$result);
let arguments = (ins Arg<PrimitiveIntOrFPPtr, "", [MemRead, MemWrite]>:$ptr,
CIR_AnyIntOrFloat:$val,
CIR_AnyIntOrFloatType:$val,
AtomicFetchKind:$binop,
Arg<MemOrder, "memory order">:$mem_order,
UnitAttr:$is_volatile,
Expand Down
12 changes: 11 additions & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ def CIR_AnyFloatType : AnyTypeOf<[
let cppFunctionName = "isAnyFloatingPointType";
}

def CIR_AnyIntOrFloat : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType]>;
def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
"integer or floating point type"
> {
let cppFunctionName = "isAnyIntegerOrFloatingPointType";
}

//===----------------------------------------------------------------------===//
// Complex Type predicates
//===----------------------------------------------------------------------===//

def CIR_AnyComplexType : CIR_TypeBase<"::cir::ComplexType", "complex type">;

#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD
25 changes: 18 additions & 7 deletions clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -159,24 +159,35 @@ def CIR_ComplexType : CIR_Type<"Complex", "complex",
CIR type that represents a C complex number. `cir.complex` models the C type
`T _Complex`.

The parameter `elementTy` gives the type of the real and imaginary part of
the complex number. `elementTy` must be either a CIR integer type or a CIR
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.
}];

let parameters = (ins "mlir::Type":$elementTy);
let parameters = (ins CIR_AnyIntOrFloatType:$elementType);

let builders = [
TypeBuilderWithInferredContext<(ins "mlir::Type":$elementTy), [{
return $_get(elementTy.getContext(), elementTy);
TypeBuilderWithInferredContext<(ins "mlir::Type":$elementType), [{
return $_get(elementType.getContext(), elementType);
}]>,
];

let assemblyFormat = [{
`<` $elementTy `>`
`<` $elementType `>`
}];

let genVerifyDecl = 1;
let extraClassDeclaration = [{
bool isFloatingPointComplex() const {
return isAnyFloatingPointType(getElementType());
}

bool isIntegerComplex() const {
return mlir::isa<cir::IntType>(getElementType());
}
}];
}

//===----------------------------------------------------------------------===//
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
auto srcPtrTy = mlir::cast<cir::PointerType>(value.getType());
auto srcComplexTy = mlir::cast<cir::ComplexType>(srcPtrTy.getPointee());
return create<cir::ComplexRealPtrOp>(
loc, getPointerTo(srcComplexTy.getElementTy()), value);
loc, getPointerTo(srcComplexTy.getElementType()), value);
}

Address createRealPtr(mlir::Location loc, Address addr) {
Expand All @@ -830,7 +830,7 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
auto srcPtrTy = mlir::cast<cir::PointerType>(value.getType());
auto srcComplexTy = mlir::cast<cir::ComplexType>(srcPtrTy.getPointee());
return create<cir::ComplexImagPtrOp>(
loc, getPointerTo(srcComplexTy.getElementTy()), value);
loc, getPointerTo(srcComplexTy.getElementType()), value);
}

Address createImagPtr(mlir::Location loc, Address addr) {
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ mlir::Value
ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *IL) {
auto Loc = CGF.getLoc(IL->getExprLoc());
auto Ty = mlir::cast<cir::ComplexType>(CGF.convertType(IL->getType()));
auto ElementTy = Ty.getElementTy();
auto ElementTy = Ty.getElementType();

mlir::TypedAttr RealValueAttr;
mlir::TypedAttr ImagValueAttr;
Expand Down Expand Up @@ -875,17 +875,15 @@ mlir::Value CIRGenFunction::emitPromotedComplexExpr(const Expr *E,

mlir::Value CIRGenFunction::emitPromotedValue(mlir::Value result,
QualType PromotionType) {
assert(mlir::isa<cir::CIRFPTypeInterface>(
mlir::cast<cir::ComplexType>(result.getType()).getElementTy()) &&
assert(!mlir::cast<cir::ComplexType>(result.getType()).isIntegerComplex() &&
"integral complex will never be promoted");
return builder.createCast(cir::CastKind::float_complex, result,
convertType(PromotionType));
}

mlir::Value CIRGenFunction::emitUnPromotedValue(mlir::Value result,
QualType UnPromotionType) {
assert(mlir::isa<cir::CIRFPTypeInterface>(
mlir::cast<cir::ComplexType>(result.getType()).getElementTy()) &&
assert(!mlir::cast<cir::ComplexType>(result.getType()).isIntegerComplex() &&
"integral complex will never be promoted");
return builder.createCast(cir::CastKind::float_complex, result,
convertType(UnPromotionType));
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/CIR/Dialect/IR/CIRAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ LogicalResult FPAttr::verify(function_ref<InFlightDiagnostic()> emitError,
LogicalResult ComplexAttr::verify(function_ref<InFlightDiagnostic()> emitError,
cir::ComplexType type, mlir::TypedAttr real,
mlir::TypedAttr imag) {
auto elemTy = type.getElementTy();
if (real.getType() != elemTy) {
auto elemType = type.getElementType();
if (real.getType() != elemType) {
emitError() << "type of the real part does not match the complex type";
return failure();
}
if (imag.getType() != elemTy) {
if (imag.getType() != elemType) {
emitError() << "type of the imaginary part does not match the complex type";
return failure();
}
Expand Down
63 changes: 29 additions & 34 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ LogicalResult cir::CastOp::verify() {
auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
if (!resComplexTy)
return emitOpError() << "requires !cir.complex type for result";
if (srcType != resComplexTy.getElementTy())
if (srcType != resComplexTy.getElementType())
return emitOpError() << "requires source type match result element type";
return success();
}
Expand All @@ -665,7 +665,7 @@ LogicalResult cir::CastOp::verify() {
auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
if (!resComplexTy)
return emitOpError() << "requires !cir.complex type for result";
if (srcType != resComplexTy.getElementTy())
if (srcType != resComplexTy.getElementType())
return emitOpError() << "requires source type match result element type";
return success();
}
Expand All @@ -675,7 +675,7 @@ LogicalResult cir::CastOp::verify() {
return emitOpError() << "requires !cir.complex type for source";
if (!mlir::isa<cir::CIRFPTypeInterface>(resType))
return emitOpError() << "requires !cir.float type for result";
if (srcComplexTy.getElementTy() != resType)
if (srcComplexTy.getElementType() != resType)
return emitOpError() << "requires source element type match result type";
return success();
}
Expand All @@ -685,71 +685,66 @@ LogicalResult cir::CastOp::verify() {
return emitOpError() << "requires !cir.complex type for source";
if (!mlir::isa<cir::IntType>(resType))
return emitOpError() << "requires !cir.int type for result";
if (srcComplexTy.getElementTy() != resType)
if (srcComplexTy.getElementType() != resType)
return emitOpError() << "requires source element type match result type";
return success();
}
case cir::CastKind::float_complex_to_bool: {
auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
if (!srcComplexTy ||
!mlir::isa<cir::CIRFPTypeInterface>(srcComplexTy.getElementTy()))
if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
return emitOpError()
<< "requires !cir.complex<!cir.float> type for source";
<< "requires floating point !cir.complex type for source";
if (!mlir::isa<cir::BoolType>(resType))
return emitOpError() << "requires !cir.bool type for result";
return success();
}
case cir::CastKind::int_complex_to_bool: {
auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
if (!srcComplexTy || !mlir::isa<cir::IntType>(srcComplexTy.getElementTy()))
if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
return emitOpError()
<< "requires !cir.complex<!cir.float> type for source";
<< "requires floating point !cir.complex type for source";
if (!mlir::isa<cir::BoolType>(resType))
return emitOpError() << "requires !cir.bool type for result";
return success();
}
case cir::CastKind::float_complex: {
auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
if (!srcComplexTy ||
!mlir::isa<cir::CIRFPTypeInterface>(srcComplexTy.getElementTy()))
if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
return emitOpError()
<< "requires !cir.complex<!cir.float> type for source";
<< "requires floating point !cir.complex type for source";
auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
if (!resComplexTy ||
!mlir::isa<cir::CIRFPTypeInterface>(resComplexTy.getElementTy()))
if (!resComplexTy || !resComplexTy.isFloatingPointComplex())
return emitOpError()
<< "requires !cir.complex<!cir.float> type for result";
<< "requires floating point !cir.complex type for result";
return success();
}
case cir::CastKind::float_complex_to_int_complex: {
auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
if (!srcComplexTy ||
!mlir::isa<cir::CIRFPTypeInterface>(srcComplexTy.getElementTy()))
if (!srcComplexTy || !srcComplexTy.isFloatingPointComplex())
return emitOpError()
<< "requires !cir.complex<!cir.float> type for source";
<< "requires floating point !cir.complex type for source";
auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
if (!resComplexTy || !mlir::isa<cir::IntType>(resComplexTy.getElementTy()))
return emitOpError() << "requires !cir.complex<!cir.int> type for result";
if (!resComplexTy || !resComplexTy.isIntegerComplex())
return emitOpError() << "requires integer !cir.complex type for result";
return success();
}
case cir::CastKind::int_complex: {
auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
if (!srcComplexTy || !mlir::isa<cir::IntType>(srcComplexTy.getElementTy()))
return emitOpError() << "requires !cir.complex<!cir.int> type for source";
if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
return emitOpError() << "requires integer !cir.complex type for source";
auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
if (!resComplexTy || !mlir::isa<cir::IntType>(resComplexTy.getElementTy()))
return emitOpError() << "requires !cir.complex<!cir.int> type for result";
if (!resComplexTy || !resComplexTy.isIntegerComplex())
return emitOpError() << "requires integer !cir.complex type for result";
return success();
}
case cir::CastKind::int_complex_to_float_complex: {
auto srcComplexTy = mlir::dyn_cast<cir::ComplexType>(srcType);
if (!srcComplexTy || !mlir::isa<cir::IntType>(srcComplexTy.getElementTy()))
return emitOpError() << "requires !cir.complex<!cir.int> type for source";
if (!srcComplexTy || !srcComplexTy.isIntegerComplex())
return emitOpError() << "requires integer !cir.complex type for source";
auto resComplexTy = mlir::dyn_cast<cir::ComplexType>(resType);
if (!resComplexTy ||
!mlir::isa<cir::CIRFPTypeInterface>(resComplexTy.getElementTy()))
if (!resComplexTy || !resComplexTy.isFloatingPointComplex())
return emitOpError()
<< "requires !cir.complex<!cir.float> type for result";
<< "requires floating point !cir.complex type for result";
return success();
}
case cir::CastKind::member_ptr_to_bool: {
Expand Down Expand Up @@ -912,7 +907,7 @@ LogicalResult cir::DerivedMethodOp::verify() {
//===----------------------------------------------------------------------===//

LogicalResult cir::ComplexCreateOp::verify() {
if (getType().getElementTy() != getReal().getType()) {
if (getType().getElementType() != getReal().getType()) {
emitOpError()
<< "operand type of cir.complex.create does not match its result type";
return failure();
Expand Down Expand Up @@ -945,7 +940,7 @@ OpFoldResult cir::ComplexCreateOp::fold(FoldAdaptor adaptor) {
//===----------------------------------------------------------------------===//

LogicalResult cir::ComplexRealOp::verify() {
if (getType() != getOperand().getType().getElementTy()) {
if (getType() != getOperand().getType().getElementType()) {
emitOpError() << "cir.complex.real result type does not match operand type";
return failure();
}
Expand All @@ -960,7 +955,7 @@ OpFoldResult cir::ComplexRealOp::fold(FoldAdaptor adaptor) {
}

LogicalResult cir::ComplexImagOp::verify() {
if (getType() != getOperand().getType().getElementTy()) {
if (getType() != getOperand().getType().getElementType()) {
emitOpError() << "cir.complex.imag result type does not match operand type";
return failure();
}
Expand All @@ -984,7 +979,7 @@ LogicalResult cir::ComplexRealPtrOp::verify() {
auto operandPointeeTy =
mlir::cast<cir::ComplexType>(operandPtrTy.getPointee());

if (resultPointeeTy != operandPointeeTy.getElementTy()) {
if (resultPointeeTy != operandPointeeTy.getElementType()) {
emitOpError()
<< "cir.complex.real_ptr result type does not match operand type";
return failure();
Expand All @@ -999,7 +994,7 @@ LogicalResult cir::ComplexImagPtrOp::verify() {
auto operandPointeeTy =
mlir::cast<cir::ComplexType>(operandPtrTy.getPointee());

if (resultPointeeTy != operandPointeeTy.getElementTy()) {
if (resultPointeeTy != operandPointeeTy.getElementType()) {
emitOpError()
<< "cir.complex.imag_ptr result type does not match operand type";
return failure();
Expand Down
18 changes: 2 additions & 16 deletions clang/lib/CIR/Dialect/IR/CIRTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,18 +798,6 @@ bool cir::isIntOrIntVectorTy(mlir::Type t) {
// ComplexType Definitions
//===----------------------------------------------------------------------===//

mlir::LogicalResult cir::ComplexType::verify(
llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
mlir::Type elementTy) {
if (!mlir::isa<cir::IntType, cir::CIRFPTypeInterface>(elementTy)) {
emitError() << "element type of !cir.complex must be either a "
"floating-point type or an integer type";
return failure();
}

return success();
}

llvm::TypeSize
cir::ComplexType::getTypeSizeInBits(const mlir::DataLayout &dataLayout,
mlir::DataLayoutEntryListRef params) const {
Expand All @@ -818,8 +806,7 @@ cir::ComplexType::getTypeSizeInBits(const mlir::DataLayout &dataLayout,
// as an array type containing exactly two elements of the corresponding
// real type.

auto elementTy = getElementTy();
return dataLayout.getTypeSizeInBits(elementTy) * 2;
return dataLayout.getTypeSizeInBits(getElementType()) * 2;
}

uint64_t
Expand All @@ -830,8 +817,7 @@ cir::ComplexType::getABIAlignment(const mlir::DataLayout &dataLayout,
// as an array type containing exactly two elements of the corresponding
// real type.

auto elementTy = getElementTy();
return dataLayout.getTypeABIAlignment(elementTy);
return dataLayout.getTypeABIAlignment(getElementType());
}

//===----------------------------------------------------------------------===//
Expand Down
Loading
Loading