[clang] [CIR] Upstream VectorType support in helper function (PR #142222)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Fri May 30 16:47:39 PDT 2025
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/142222
>From bc6569aa45233cb3e08fa149cb45ca2f8c6d4ad1 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
Date: Sat, 31 May 2025 01:47:16 +0200
Subject: [PATCH] [CIR][NFC] Upstream VectorType support in helper function
---
.../CIR/Dialect/IR/CIRTypeConstraints.td | 37 +++++++++++++++++++
clang/include/clang/CIR/Dialect/IR/CIRTypes.h | 2 -
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 6 +--
clang/lib/CIR/Dialect/IR/CIRTypes.cpp | 9 -----
4 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
index ec461cab961c7..7b20ca4e2d1d4 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
@@ -31,6 +31,18 @@ class CIR_ConfinedType<Type type, list<Pred> preds, string summary = "">
: Type<And<[type.predicate, CIR_CastedSelfsToType<type.cppType, preds>]>,
summary, type.cppType>;
+// Generates a type summary.
+// - For a single type: returns its summary.
+// - For multiple types: returns `any of <comma-separated summaries>`.
+class CIR_TypeSummaries<list<Type> types> {
+ assert !not(!empty(types)), "expects non-empty list of types";
+
+ list<string> summaries = !foreach(type, types, type.summary);
+ string joined = !interleave(summaries, ", ");
+
+ string value = !if(!eq(!size(types), 1), joined, "any of " # joined);
+}
+
//===----------------------------------------------------------------------===//
// Bool Type predicates
//===----------------------------------------------------------------------===//
@@ -184,6 +196,8 @@ def CIR_PtrToVoidPtrType
// Vector Type predicates
//===----------------------------------------------------------------------===//
+def CIR_AnyVectorType : CIR_TypeBase<"::cir::VectorType", "vector type">;
+
// Vector of integral type
def IntegerVector : Type<
And<[
@@ -211,4 +225,27 @@ def CIR_AnyScalarType : AnyTypeOf<CIR_ScalarTypes, "cir scalar type"> {
let cppFunctionName = "isScalarType";
}
+//===----------------------------------------------------------------------===//
+// Element type constraint bases
+//===----------------------------------------------------------------------===//
+
+class CIR_ElementTypePred<Pred pred> : SubstLeaves<"$_self",
+ "::mlir::cast<::cir::VectorType>($_self).getElementType()", pred>;
+
+class CIR_VectorTypeOf<list<Type> types, string summary = "">
+ : CIR_ConfinedType<CIR_AnyVectorType,
+ [Or<!foreach(type, types, CIR_ElementTypePred<type.predicate>)>],
+ !if(!empty(summary),
+ "vector of " # CIR_TypeSummaries<types>.value,
+ summary)>;
+
+// Vector of type constraints
+def CIR_VectorOfFloatType : CIR_VectorTypeOf<[CIR_AnyFloatType]>;
+
+def CIR_AnyFloatOrVecOfFloatType
+ : AnyTypeOf<[CIR_AnyFloatType, CIR_VectorOfFloatType],
+ "floating point or vector of floating point type"> {
+ let cppFunctionName = "isFPOrVectorOfFPType";
+}
+
#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 3845fd2a4b67d..49933be724a04 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
+++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.h
@@ -26,8 +26,6 @@ struct RecordTypeStorage;
bool isValidFundamentalIntWidth(unsigned width);
-bool isFPOrFPVectorTy(mlir::Type);
-
} // namespace cir
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index 8448c164a5e58..b33bb71c99c90 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -1311,7 +1311,7 @@ mlir::Value ScalarExprEmitter::emitMul(const BinOpInfo &ops) {
!canElideOverflowCheck(cgf.getContext(), ops))
cgf.cgm.errorNYI("unsigned int overflow sanitizer");
- if (cir::isFPOrFPVectorTy(ops.lhs.getType())) {
+ if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
assert(!cir::MissingFeatures::cgFPOptionsRAII());
return builder.createFMul(loc, ops.lhs, ops.rhs);
}
@@ -1370,7 +1370,7 @@ mlir::Value ScalarExprEmitter::emitAdd(const BinOpInfo &ops) {
!canElideOverflowCheck(cgf.getContext(), ops))
cgf.cgm.errorNYI("unsigned int overflow sanitizer");
- if (cir::isFPOrFPVectorTy(ops.lhs.getType())) {
+ if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
assert(!cir::MissingFeatures::cgFPOptionsRAII());
return builder.createFAdd(loc, ops.lhs, ops.rhs);
}
@@ -1418,7 +1418,7 @@ mlir::Value ScalarExprEmitter::emitSub(const BinOpInfo &ops) {
!canElideOverflowCheck(cgf.getContext(), ops))
cgf.cgm.errorNYI("unsigned int overflow sanitizer");
- if (cir::isFPOrFPVectorTy(ops.lhs.getType())) {
+ if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
assert(!cir::MissingFeatures::cgFPOptionsRAII());
return builder.createFSub(loc, ops.lhs, ops.rhs);
}
diff --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index b402177a5ec18..21d957afefeb6 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -552,15 +552,6 @@ LongDoubleType::getABIAlignment(const mlir::DataLayout &dataLayout,
.getABIAlignment(dataLayout, params);
}
-//===----------------------------------------------------------------------===//
-// Floating-point and Float-point Vector type helpers
-//===----------------------------------------------------------------------===//
-
-bool cir::isFPOrFPVectorTy(mlir::Type t) {
- assert(!cir::MissingFeatures::vectorType());
- return isAnyFloatingPointType(t);
-}
-
//===----------------------------------------------------------------------===//
// FuncType Definitions
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list