-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Refactor floating point type constraints #138112
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
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-clang Author: Henrich Lauko (xlauko) Changes
This mirrors inbubator changes from llvm/clangir#1594 Full diff: https://github.com/llvm/llvm-project/pull/138112.diff 4 Files Affected:
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
index 3b8cb20da8edb..274b9e509f0d6 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
@@ -110,4 +110,33 @@ def CIR_AnyFundamentalSIntType
let cppFunctionName = "isFundamentalSIntType";
}
+//===----------------------------------------------------------------------===//
+// Float Type predicates
+//===----------------------------------------------------------------------===//
+
+def CIR_AnySingleType : CIR_TypeBase<"::cir::SingleType", "single float type">;
+def CIR_AnyFP32Type : TypeAlias<CIR_AnySingleType>;
+
+def CIR_AnyDoubleType : CIR_TypeBase<"::cir::DoubleType", "double float type">;
+def CIR_AnyFP64Type : TypeAlias<CIR_AnyDoubleType>;
+
+def CIR_AnyFP16Type : CIR_TypeBase<"::cir::FP16Type", "f16 type">;
+def CIR_AnyBFloat16Type : CIR_TypeBase<"::cir::BF16Type", "bf16 type">;
+def CIR_AnyFP80Type : CIR_TypeBase<"::cir::FP80Type", "f80 type">;
+def CIR_AnyFP128Type : CIR_TypeBase<"::cir::FP128Type", "f128 type">;
+def CIR_AnyLongDoubleType : CIR_TypeBase<"::cir::LongDoubleType",
+ "long double type">;
+
+def CIR_AnyFloatType : AnyTypeOf<[
+ CIR_AnySingleType, CIR_AnyDoubleType, CIR_AnyFP16Type,
+ CIR_AnyBFloat16Type, CIR_AnyFP80Type, CIR_AnyFP128Type,
+ CIR_AnyLongDoubleType
+]> {
+ let cppFunctionName = "isAnyFloatingPointType";
+}
+
+def CIR_AnyIntOrFloat : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType]>;
+
+
+
#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
index 2e32765c1e941..3845fd2a4b67d 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -26,7 +26,6 @@ struct RecordTypeStorage;
bool isValidFundamentalIntWidth(unsigned width);
-bool isAnyFloatingPointType(mlir::Type t);
bool isFPOrFPVectorTy(mlir::Type);
} // namespace cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index d9f05c9aea63d..959e2cd822e76 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -80,12 +80,10 @@ def CIR_IntType : CIR_Type<"Int", "int",
// FloatType
//===----------------------------------------------------------------------===//
-class CIR_FloatType<string name, string mnemonic>
- : CIR_Type<name, mnemonic,
- [
- DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
- DeclareTypeInterfaceMethods<CIRFPTypeInterface>,
- ]> {}
+class CIR_FloatType<string name, string mnemonic> : CIR_Type<name, mnemonic, [
+ DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
+ DeclareTypeInterfaceMethods<CIRFPTypeInterface>
+]>;
def CIR_Single : CIR_FloatType<"Single", "float"> {
let summary = "CIR single-precision 32-bit float type";
@@ -155,21 +153,14 @@ def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
format are all in use.
}];
- let parameters = (ins "mlir::Type":$underlying);
+ let parameters = (ins AnyTypeOf<[CIR_Double, CIR_FP80, CIR_FP128],
+ "expects !cir.double, !cir.fp80 or !cir.fp128">:$underlying);
let assemblyFormat = [{
`<` $underlying `>`
}];
-
- let genVerifyDecl = 1;
}
-// Constraints
-
-def CIR_AnyFloat: AnyTypeOf<[CIR_Single, CIR_Double, CIR_FP80, CIR_FP128,
- CIR_LongDouble, CIR_FP16, CIR_BFloat16]>;
-def CIR_AnyIntOrFloat: AnyTypeOf<[CIR_AnyFloat, CIR_IntType]>;
-
//===----------------------------------------------------------------------===//
// PointerType
//===----------------------------------------------------------------------===//
@@ -518,7 +509,7 @@ def CIRRecordType : Type<
def CIR_AnyType : AnyTypeOf<[
CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_IntType,
- CIR_AnyFloat, CIR_PointerType, CIR_FuncType, CIR_RecordType
+ CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType
]>;
#endif // MLIR_CIR_DIALECT_CIR_TYPES
diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 7d960c21d7251..9a44f923ac143 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -550,26 +550,6 @@ LongDoubleType::getABIAlignment(const mlir::DataLayout &dataLayout,
.getABIAlignment(dataLayout, params);
}
-LogicalResult
-LongDoubleType::verify(function_ref<InFlightDiagnostic()> emitError,
- mlir::Type underlying) {
- if (!mlir::isa<DoubleType, FP80Type, FP128Type>(underlying)) {
- emitError() << "invalid underlying type for long double";
- return failure();
- }
-
- return success();
-}
-
-//===----------------------------------------------------------------------===//
-// Floating-point type helpers
-//===----------------------------------------------------------------------===//
-
-bool cir::isAnyFloatingPointType(mlir::Type t) {
- return isa<cir::SingleType, cir::DoubleType, cir::LongDoubleType,
- cir::FP80Type, cir::BF16Type, cir::FP16Type, cir::FP128Type>(t);
-}
-
//===----------------------------------------------------------------------===//
// Floating-point and Float-point Vector type helpers
//===----------------------------------------------------------------------===//
|
@llvm/pr-subscribers-clangir Author: Henrich Lauko (xlauko) Changes
This mirrors inbubator changes from llvm/clangir#1594 Full diff: https://github.com/llvm/llvm-project/pull/138112.diff 4 Files Affected:
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
index 3b8cb20da8edb..274b9e509f0d6 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
@@ -110,4 +110,33 @@ def CIR_AnyFundamentalSIntType
let cppFunctionName = "isFundamentalSIntType";
}
+//===----------------------------------------------------------------------===//
+// Float Type predicates
+//===----------------------------------------------------------------------===//
+
+def CIR_AnySingleType : CIR_TypeBase<"::cir::SingleType", "single float type">;
+def CIR_AnyFP32Type : TypeAlias<CIR_AnySingleType>;
+
+def CIR_AnyDoubleType : CIR_TypeBase<"::cir::DoubleType", "double float type">;
+def CIR_AnyFP64Type : TypeAlias<CIR_AnyDoubleType>;
+
+def CIR_AnyFP16Type : CIR_TypeBase<"::cir::FP16Type", "f16 type">;
+def CIR_AnyBFloat16Type : CIR_TypeBase<"::cir::BF16Type", "bf16 type">;
+def CIR_AnyFP80Type : CIR_TypeBase<"::cir::FP80Type", "f80 type">;
+def CIR_AnyFP128Type : CIR_TypeBase<"::cir::FP128Type", "f128 type">;
+def CIR_AnyLongDoubleType : CIR_TypeBase<"::cir::LongDoubleType",
+ "long double type">;
+
+def CIR_AnyFloatType : AnyTypeOf<[
+ CIR_AnySingleType, CIR_AnyDoubleType, CIR_AnyFP16Type,
+ CIR_AnyBFloat16Type, CIR_AnyFP80Type, CIR_AnyFP128Type,
+ CIR_AnyLongDoubleType
+]> {
+ let cppFunctionName = "isAnyFloatingPointType";
+}
+
+def CIR_AnyIntOrFloat : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType]>;
+
+
+
#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
index 2e32765c1e941..3845fd2a4b67d 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -26,7 +26,6 @@ struct RecordTypeStorage;
bool isValidFundamentalIntWidth(unsigned width);
-bool isAnyFloatingPointType(mlir::Type t);
bool isFPOrFPVectorTy(mlir::Type);
} // namespace cir
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
index d9f05c9aea63d..959e2cd822e76 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td
@@ -80,12 +80,10 @@ def CIR_IntType : CIR_Type<"Int", "int",
// FloatType
//===----------------------------------------------------------------------===//
-class CIR_FloatType<string name, string mnemonic>
- : CIR_Type<name, mnemonic,
- [
- DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
- DeclareTypeInterfaceMethods<CIRFPTypeInterface>,
- ]> {}
+class CIR_FloatType<string name, string mnemonic> : CIR_Type<name, mnemonic, [
+ DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
+ DeclareTypeInterfaceMethods<CIRFPTypeInterface>
+]>;
def CIR_Single : CIR_FloatType<"Single", "float"> {
let summary = "CIR single-precision 32-bit float type";
@@ -155,21 +153,14 @@ def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
format are all in use.
}];
- let parameters = (ins "mlir::Type":$underlying);
+ let parameters = (ins AnyTypeOf<[CIR_Double, CIR_FP80, CIR_FP128],
+ "expects !cir.double, !cir.fp80 or !cir.fp128">:$underlying);
let assemblyFormat = [{
`<` $underlying `>`
}];
-
- let genVerifyDecl = 1;
}
-// Constraints
-
-def CIR_AnyFloat: AnyTypeOf<[CIR_Single, CIR_Double, CIR_FP80, CIR_FP128,
- CIR_LongDouble, CIR_FP16, CIR_BFloat16]>;
-def CIR_AnyIntOrFloat: AnyTypeOf<[CIR_AnyFloat, CIR_IntType]>;
-
//===----------------------------------------------------------------------===//
// PointerType
//===----------------------------------------------------------------------===//
@@ -518,7 +509,7 @@ def CIRRecordType : Type<
def CIR_AnyType : AnyTypeOf<[
CIR_VoidType, CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_IntType,
- CIR_AnyFloat, CIR_PointerType, CIR_FuncType, CIR_RecordType
+ CIR_AnyFloatType, CIR_PointerType, CIR_FuncType, CIR_RecordType
]>;
#endif // MLIR_CIR_DIALECT_CIR_TYPES
diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 7d960c21d7251..9a44f923ac143 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -550,26 +550,6 @@ LongDoubleType::getABIAlignment(const mlir::DataLayout &dataLayout,
.getABIAlignment(dataLayout, params);
}
-LogicalResult
-LongDoubleType::verify(function_ref<InFlightDiagnostic()> emitError,
- mlir::Type underlying) {
- if (!mlir::isa<DoubleType, FP80Type, FP128Type>(underlying)) {
- emitError() << "invalid underlying type for long double";
- return failure();
- }
-
- return success();
-}
-
-//===----------------------------------------------------------------------===//
-// Floating-point type helpers
-//===----------------------------------------------------------------------===//
-
-bool cir::isAnyFloatingPointType(mlir::Type t) {
- return isa<cir::SingleType, cir::DoubleType, cir::LongDoubleType,
- cir::FP80Type, cir::BF16Type, cir::FP16Type, cir::FP128Type>(t);
-}
-
//===----------------------------------------------------------------------===//
// Floating-point and Float-point Vector type helpers
//===----------------------------------------------------------------------===//
|
17f61b8
to
3fb2fba
Compare
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.
Looks good, with one minor request.
// Float Type predicates | ||
//===----------------------------------------------------------------------===// | ||
|
||
def CIR_AnySingleType : CIR_TypeBase<"::cir::SingleType", "single float type">; |
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.
Is there a reason for the explicit global scope?
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 believe it used to make problems when core mlir dialects where included in out of tree projects/dialects.
Thats why entire mlir has explicit global scope, though I cannot remember the issue it was causing.
3fb2fba
to
88149b4
Compare
04686fc
to
4e5819c
Compare
- 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
88149b4
to
fbbee19
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/19356 Here is the relevant piece of the build log for the reference
|
- 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
- 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
- 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
- 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
CIR_AnyFloat
toCIR_AnyFloatType
.This mirrors inbubator changes from llvm/clangir#1594