Skip to content

Commit 32ce4c7

Browse files
committed
[CIR] Refactor floating point type constraints
1 parent ccc0b65 commit 32ce4c7

File tree

6 files changed

+44
-44
lines changed

6 files changed

+44
-44
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4724,7 +4724,7 @@ def FrameAddrOp : FuncAddrBuiltinOp<"frame_address"> {
47244724

47254725
class UnaryFPToIntBuiltinOp<string mnemonic, string llvmOpName>
47264726
: CIR_Op<mnemonic, [Pure]> {
4727-
let arguments = (ins CIR_AnyFloat:$src);
4727+
let arguments = (ins CIR_AnyFloatType:$src);
47284728
let results = (outs CIR_IntType:$result);
47294729

47304730
let summary = [{
@@ -4847,7 +4847,7 @@ def IsFPClassOp : CIR_Op<"is_fp_class"> {
48474847
| 9 | Positive infinity |
48484848
}];
48494849

4850-
let arguments = (ins CIR_AnyFloat:$src,
4850+
let arguments = (ins CIR_AnyFloatType:$src,
48514851
I32Attr:$flags);
48524852
let results = (outs CIR_BoolType:$result);
48534853
let assemblyFormat = [{
@@ -5708,7 +5708,7 @@ def SignBitOp : CIR_Op<"signbit", [Pure]> {
57085708
It returns whether the sign bit (i.e. the highest bit) of the input operand
57095709
is set.
57105710
}];
5711-
let arguments = (ins CIR_AnyFloat:$input);
5711+
let arguments = (ins CIR_AnyFloatType:$input);
57125712
let results = (outs CIR_BoolType:$res);
57135713
let assemblyFormat = [{
57145714
$input attr-dict `:` type($input) `->` qualified(type($res))

clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,31 @@ def CIR_AnyFundamentalSIntType
110110
let cppFunctionName = "isFundamentalSIntType";
111111
}
112112

113+
//===----------------------------------------------------------------------===//
114+
// Float Type predicates
115+
//===----------------------------------------------------------------------===//
116+
117+
def CIR_AnySingleType : CIR_TypeBase<"::cir::SingleType", "single float type">;
118+
def CIR_AnyFP32Type : TypeAlias<CIR_AnySingleType>;
119+
120+
def CIR_AnyDoubleType : CIR_TypeBase<"::cir::DoubleType", "double float type">;
121+
def CIR_AnyFP64Type : TypeAlias<CIR_AnyDoubleType>;
122+
123+
def CIR_AnyFP16Type : CIR_TypeBase<"::cir::FP16Type", "f16 type">;
124+
def CIR_AnyBFloat16Type : CIR_TypeBase<"::cir::BF16Type", "bf16 type">;
125+
def CIR_AnyFP80Type : CIR_TypeBase<"::cir::FP80Type", "f80 type">;
126+
def CIR_AnyFP128Type : CIR_TypeBase<"::cir::FP128Type", "f128 type">;
127+
def CIR_AnyLongDoubleType : CIR_TypeBase<"::cir::LongDoubleType",
128+
"long double type">;
129+
130+
def CIR_AnyFloatType : AnyTypeOf<[
131+
CIR_AnySingleType, CIR_AnyDoubleType, CIR_AnyFP16Type,
132+
CIR_AnyBFloat16Type, CIR_AnyFP80Type, CIR_AnyFP128Type,
133+
CIR_AnyLongDoubleType
134+
]> {
135+
let cppFunctionName = "isAnyFloatingPointType";
136+
}
137+
138+
def CIR_AnyIntOrFloat : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType]>;
139+
113140
#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD

clang/include/clang/CIR/Dialect/IR/CIRTypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct RecordTypeStorage;
2727

2828
bool isValidFundamentalIntWidth(unsigned width);
2929

30-
bool isAnyFloatingPointType(mlir::Type t);
3130
bool isScalarType(mlir::Type t);
3231
bool isFPOrFPVectorTy(mlir::Type);
3332
bool isIntOrIntVectorTy(mlir::Type);

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,10 @@ def CIR_IntType : CIR_Type<"Int", "int",
8080
// FloatType
8181
//===----------------------------------------------------------------------===//
8282

83-
class CIR_FloatType<string name, string mnemonic>
84-
: CIR_Type<name, mnemonic,
85-
[
86-
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
87-
DeclareTypeInterfaceMethods<CIRFPTypeInterface>,
88-
]> {}
83+
class CIR_FloatType<string name, string mnemonic> : CIR_Type<name, mnemonic, [
84+
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
85+
DeclareTypeInterfaceMethods<CIRFPTypeInterface>
86+
]>;
8987

9088
def CIR_Single : CIR_FloatType<"Single", "float"> {
9189
let summary = "CIR single-precision float type";
@@ -99,7 +97,7 @@ def CIR_Double : CIR_FloatType<"Double", "double"> {
9997
let summary = "CIR double-precision float type";
10098
let description = [{
10199
Floating-point type that represents the `double` type in C/C++. Its
102-
underlying floating-point format is the IEEE-754 binar64 format.
100+
underlying floating-point format is the IEEE-754 binary64 format.
103101
}];
104102
}
105103

@@ -138,25 +136,17 @@ def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
138136

139137
The underlying floating-point format of a long double value depends on the
140138
implementation. The `underlying` parameter specifies the CIR floating-point
141-
type that corresponds to this format. For now, it can only be either
142-
`!cir.double` or `!cir.fp80`.
139+
type that corresponds to this format.
143140
}];
144141

145-
let parameters = (ins "mlir::Type":$underlying);
142+
let parameters = (ins AnyTypeOf<[CIR_Double, CIR_FP80, CIR_FP128],
143+
"expects !cir.double, !cir.fp80 or !cir.fp128">:$underlying);
146144

147145
let assemblyFormat = [{
148146
`<` $underlying `>`
149147
}];
150-
151-
let genVerifyDecl = 1;
152148
}
153149

154-
// Constraints
155-
156-
def CIR_AnyFloat: AnyTypeOf<[CIR_Single, CIR_Double, CIR_FP80, CIR_FP128, CIR_LongDouble,
157-
CIR_FP16, CIR_BFloat16]>;
158-
def CIR_AnyIntOrFloat: AnyTypeOf<[CIR_AnyFloat, CIR_IntType]>;
159-
160150
//===----------------------------------------------------------------------===//
161151
// ComplexType
162152
//===----------------------------------------------------------------------===//
@@ -566,11 +556,12 @@ def FPVector : Type<
566556

567557
// Constraints
568558
def CIR_AnyIntOrVecOfInt: AnyTypeOf<[CIR_IntType, IntegerVector]>;
559+
569560
def CIR_AnySignedIntOrVecOfSignedInt: AnyTypeOf<[
570561
CIR_AnyFundamentalSIntType, SignedIntegerVector
571562
]>;
572563

573-
def CIR_AnyFloatOrVecOfFloat: AnyTypeOf<[CIR_AnyFloat, FPVector]>;
564+
def CIR_AnyFloatOrVecOfFloat: AnyTypeOf<[CIR_AnyFloatType, FPVector]>;
574565

575566
// Pointer to Arrays
576567
def ArrayPtr : Type<
@@ -667,7 +658,7 @@ def CIR_RecordType : CIR_Type<"Record", "record",
667658
CArg<"ASTRecordDeclInterface", "{}">:$ast
668659
), [{
669660
return $_get($_ctxt, members, name, /*complete=*/true, packed, padded,
670-
kind, ast);
661+
kind, ast);
671662
}]>,
672663

673664
// Create an identified and incomplete record type.
@@ -678,7 +669,7 @@ def CIR_RecordType : CIR_Type<"Record", "record",
678669
return $_get($_ctxt, /*members=*/llvm::ArrayRef<Type>{}, name,
679670
/*complete=*/false, /*packed=*/false,
680671
/*padded=*/false, kind,
681-
/*ast=*/ASTRecordDeclInterface{});
672+
/*ast=*/ASTRecordDeclInterface{});
682673
}]>,
683674

684675
// Create an anonymous record type (always complete).
@@ -755,8 +746,7 @@ def CIRRecordType : Type<
755746
def CIR_AnyType : AnyTypeOf<[
756747
CIR_IntType, CIR_PointerType, CIR_DataMemberType, CIR_MethodType,
757748
CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_FuncType, CIR_VoidType,
758-
CIR_RecordType, CIR_ExceptionType, CIR_AnyFloat, CIR_FP16, CIR_BFloat16,
759-
CIR_ComplexType
749+
CIR_RecordType, CIR_ExceptionType, CIR_AnyFloatType, CIR_ComplexType
760750
]>;
761751

762752
#endif // MLIR_CIR_DIALECT_CIR_TYPES

clang/lib/CIR/Dialect/IR/CIRTypes.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -741,26 +741,10 @@ LongDoubleType::getABIAlignment(const mlir::DataLayout &dataLayout,
741741
.getABIAlignment(dataLayout, params);
742742
}
743743

744-
LogicalResult
745-
LongDoubleType::verify(function_ref<InFlightDiagnostic()> emitError,
746-
mlir::Type underlying) {
747-
if (!mlir::isa<DoubleType, FP80Type, FP128Type>(underlying)) {
748-
emitError() << "invalid underlying type for long double";
749-
return failure();
750-
}
751-
752-
return success();
753-
}
754-
755744
//===----------------------------------------------------------------------===//
756745
// Floating-point type helpers
757746
//===----------------------------------------------------------------------===//
758747

759-
bool cir::isAnyFloatingPointType(mlir::Type t) {
760-
return isa<cir::SingleType, cir::DoubleType, cir::LongDoubleType,
761-
cir::FP80Type, cir::BF16Type, cir::FP16Type, cir::FP128Type>(t);
762-
}
763-
764748
bool cir::isScalarType(mlir::Type ty) {
765749
return isa<cir::IntType, cir::BoolType, cir::SingleType, cir::DoubleType,
766750
cir::LongDoubleType, cir::FP16Type, cir::FP128Type, cir::FP80Type,

clang/test/CIR/IR/invalid.cir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ cir.func @no_reference_global() {
11631163

11641164
// -----
11651165

1166-
// expected-error@+1 {{invalid underlying type for long double}}
1166+
// expected-error@+1 {{failed to verify 'underlying': expects !cir.double, !cir.fp80 or !cir.fp128}}
11671167
cir.func @bad_long_double(%arg0 : !cir.long_double<!cir.float>) -> () {
11681168
cir.return
11691169
}

0 commit comments

Comments
 (0)