Skip to content

Commit bc6569a

Browse files
committed
[CIR][NFC] Upstream VectorType support in helper function
1 parent 459de73 commit bc6569a

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ class CIR_ConfinedType<Type type, list<Pred> preds, string summary = "">
3131
: Type<And<[type.predicate, CIR_CastedSelfsToType<type.cppType, preds>]>,
3232
summary, type.cppType>;
3333

34+
// Generates a type summary.
35+
// - For a single type: returns its summary.
36+
// - For multiple types: returns `any of <comma-separated summaries>`.
37+
class CIR_TypeSummaries<list<Type> types> {
38+
assert !not(!empty(types)), "expects non-empty list of types";
39+
40+
list<string> summaries = !foreach(type, types, type.summary);
41+
string joined = !interleave(summaries, ", ");
42+
43+
string value = !if(!eq(!size(types), 1), joined, "any of " # joined);
44+
}
45+
3446
//===----------------------------------------------------------------------===//
3547
// Bool Type predicates
3648
//===----------------------------------------------------------------------===//
@@ -184,6 +196,8 @@ def CIR_PtrToVoidPtrType
184196
// Vector Type predicates
185197
//===----------------------------------------------------------------------===//
186198

199+
def CIR_AnyVectorType : CIR_TypeBase<"::cir::VectorType", "vector type">;
200+
187201
// Vector of integral type
188202
def IntegerVector : Type<
189203
And<[
@@ -211,4 +225,27 @@ def CIR_AnyScalarType : AnyTypeOf<CIR_ScalarTypes, "cir scalar type"> {
211225
let cppFunctionName = "isScalarType";
212226
}
213227

228+
//===----------------------------------------------------------------------===//
229+
// Element type constraint bases
230+
//===----------------------------------------------------------------------===//
231+
232+
class CIR_ElementTypePred<Pred pred> : SubstLeaves<"$_self",
233+
"::mlir::cast<::cir::VectorType>($_self).getElementType()", pred>;
234+
235+
class CIR_VectorTypeOf<list<Type> types, string summary = "">
236+
: CIR_ConfinedType<CIR_AnyVectorType,
237+
[Or<!foreach(type, types, CIR_ElementTypePred<type.predicate>)>],
238+
!if(!empty(summary),
239+
"vector of " # CIR_TypeSummaries<types>.value,
240+
summary)>;
241+
242+
// Vector of type constraints
243+
def CIR_VectorOfFloatType : CIR_VectorTypeOf<[CIR_AnyFloatType]>;
244+
245+
def CIR_AnyFloatOrVecOfFloatType
246+
: AnyTypeOf<[CIR_AnyFloatType, CIR_VectorOfFloatType],
247+
"floating point or vector of floating point type"> {
248+
let cppFunctionName = "isFPOrVectorOfFPType";
249+
}
250+
214251
#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ struct RecordTypeStorage;
2626

2727
bool isValidFundamentalIntWidth(unsigned width);
2828

29-
bool isFPOrFPVectorTy(mlir::Type);
30-
3129
} // namespace cir
3230

3331
//===----------------------------------------------------------------------===//

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ mlir::Value ScalarExprEmitter::emitMul(const BinOpInfo &ops) {
13111311
!canElideOverflowCheck(cgf.getContext(), ops))
13121312
cgf.cgm.errorNYI("unsigned int overflow sanitizer");
13131313

1314-
if (cir::isFPOrFPVectorTy(ops.lhs.getType())) {
1314+
if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
13151315
assert(!cir::MissingFeatures::cgFPOptionsRAII());
13161316
return builder.createFMul(loc, ops.lhs, ops.rhs);
13171317
}
@@ -1370,7 +1370,7 @@ mlir::Value ScalarExprEmitter::emitAdd(const BinOpInfo &ops) {
13701370
!canElideOverflowCheck(cgf.getContext(), ops))
13711371
cgf.cgm.errorNYI("unsigned int overflow sanitizer");
13721372

1373-
if (cir::isFPOrFPVectorTy(ops.lhs.getType())) {
1373+
if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
13741374
assert(!cir::MissingFeatures::cgFPOptionsRAII());
13751375
return builder.createFAdd(loc, ops.lhs, ops.rhs);
13761376
}
@@ -1418,7 +1418,7 @@ mlir::Value ScalarExprEmitter::emitSub(const BinOpInfo &ops) {
14181418
!canElideOverflowCheck(cgf.getContext(), ops))
14191419
cgf.cgm.errorNYI("unsigned int overflow sanitizer");
14201420

1421-
if (cir::isFPOrFPVectorTy(ops.lhs.getType())) {
1421+
if (cir::isFPOrVectorOfFPType(ops.lhs.getType())) {
14221422
assert(!cir::MissingFeatures::cgFPOptionsRAII());
14231423
return builder.createFSub(loc, ops.lhs, ops.rhs);
14241424
}

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -552,15 +552,6 @@ LongDoubleType::getABIAlignment(const mlir::DataLayout &dataLayout,
552552
.getABIAlignment(dataLayout, params);
553553
}
554554

555-
//===----------------------------------------------------------------------===//
556-
// Floating-point and Float-point Vector type helpers
557-
//===----------------------------------------------------------------------===//
558-
559-
bool cir::isFPOrFPVectorTy(mlir::Type t) {
560-
assert(!cir::MissingFeatures::vectorType());
561-
return isAnyFloatingPointType(t);
562-
}
563-
564555
//===----------------------------------------------------------------------===//
565556
// FuncType Definitions
566557
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)