Skip to content

Commit 7d83ba5

Browse files
xlaukoGeorgeARM
authored andcommitted
[CIR] Refactor floating point type constraints (llvm#138112)
- This cleans up moves cir floating point type constraints to dedicated constraints file, and fixes long double verifier to use constraints directly. - Renames `CIR_AnyFloat` to `CIR_AnyFloatType`. This mirrors inbubator changes from llvm/clangir#1594
1 parent 592bcbc commit 7d83ba5

File tree

5 files changed

+44
-37
lines changed

5 files changed

+44
-37
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,35 @@ 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_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
139+
"integer or floating point type"
140+
> {
141+
let cppFunctionName = "isAnyIntegerOrFloatingPointType";
142+
}
143+
113144
#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
@@ -26,7 +26,6 @@ struct RecordTypeStorage;
2626

2727
bool isValidFundamentalIntWidth(unsigned width);
2828

29-
bool isAnyFloatingPointType(mlir::Type t);
3029
bool isFPOrFPVectorTy(mlir::Type);
3130

3231
} // namespace cir

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

Lines changed: 7 additions & 16 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 32-bit float type";
@@ -155,21 +153,14 @@ def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
155153
format are all in use.
156154
}];
157155

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

160159
let assemblyFormat = [{
161160
`<` $underlying `>`
162161
}];
163-
164-
let genVerifyDecl = 1;
165162
}
166163

167-
// Constraints
168-
169-
def CIR_AnyFloat: AnyTypeOf<[CIR_Single, CIR_Double, CIR_FP80, CIR_FP128,
170-
CIR_LongDouble, CIR_FP16, CIR_BFloat16]>;
171-
def CIR_AnyIntOrFloat: AnyTypeOf<[CIR_AnyFloat, CIR_IntType]>;
172-
173164
//===----------------------------------------------------------------------===//
174165
// PointerType
175166
//===----------------------------------------------------------------------===//
@@ -518,7 +509,7 @@ def CIRRecordType : Type<
518509

519510
def CIR_AnyType : AnyTypeOf<[
520511
CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_IntType,
521-
CIR_AnyFloat, CIR_PointerType, CIR_FuncType, CIR_RecordType
512+
CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType
522513
]>;
523514

524515
#endif // MLIR_CIR_DIALECT_CIR_TYPES

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -550,26 +550,6 @@ LongDoubleType::getABIAlignment(const mlir::DataLayout &dataLayout,
550550
.getABIAlignment(dataLayout, params);
551551
}
552552

553-
LogicalResult
554-
LongDoubleType::verify(function_ref<InFlightDiagnostic()> emitError,
555-
mlir::Type underlying) {
556-
if (!mlir::isa<DoubleType, FP80Type, FP128Type>(underlying)) {
557-
emitError() << "invalid underlying type for long double";
558-
return failure();
559-
}
560-
561-
return success();
562-
}
563-
564-
//===----------------------------------------------------------------------===//
565-
// Floating-point type helpers
566-
//===----------------------------------------------------------------------===//
567-
568-
bool cir::isAnyFloatingPointType(mlir::Type t) {
569-
return isa<cir::SingleType, cir::DoubleType, cir::LongDoubleType,
570-
cir::FP80Type, cir::BF16Type, cir::FP16Type, cir::FP128Type>(t);
571-
}
572-
573553
//===----------------------------------------------------------------------===//
574554
// Floating-point and Float-point Vector type helpers
575555
//===----------------------------------------------------------------------===//
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: cir-opt %s -verify-diagnostics -split-input-file
2+
3+
// expected-error@+1 {{failed to verify 'underlying': expects !cir.double, !cir.fp80 or !cir.fp128}}
4+
cir.func @bad_long_double(%arg0 : !cir.long_double<!cir.float>) -> () {
5+
cir.return
6+
}

0 commit comments

Comments
 (0)