Skip to content

Commit adee41c

Browse files
authored
Merge branch 'llvm:main' into convertCIRTargetTriple
2 parents 7d83175 + 583e6b6 commit adee41c

39 files changed

+407
-261
lines changed

clang/include/clang/Basic/LangStandard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ enum class Language : uint8_t {
2626
/// Assembly: we accept this only so that we can preprocess it.
2727
Asm,
2828

29-
/// LLVM IR: we accept this so that we can run the optimizer on it,
30-
/// and compile it to assembly or object code.
29+
/// LLVM IR & CIR: we accept these so that we can run the optimizer on them,
30+
/// and compile them to assembly or object code (or LLVM for CIR).
3131
CIR,
3232
LLVM_IR,
3333

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

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,9 +1237,13 @@ def ShiftOp : CIR_Op<"shift", [Pure]> {
12371237
```
12381238
}];
12391239

1240-
let results = (outs CIR_AnyIntOrVecOfInt:$result);
1241-
let arguments = (ins CIR_AnyIntOrVecOfInt:$value, CIR_AnyIntOrVecOfInt:$amount,
1242-
UnitAttr:$isShiftleft);
1240+
let arguments = (ins
1241+
CIR_AnyIntOrVecOfIntType:$value,
1242+
CIR_AnyIntOrVecOfIntType:$amount,
1243+
UnitAttr:$isShiftleft
1244+
);
1245+
1246+
let results = (outs CIR_AnyIntOrVecOfIntType:$result);
12431247

12441248
let assemblyFormat = [{
12451249
`(`
@@ -3125,7 +3129,7 @@ def VecInsertOp : CIR_Op<"vec.insert", [Pure,
31253129

31263130
let arguments = (ins
31273131
CIR_VectorType:$vec,
3128-
AnyType:$value,
3132+
CIR_VectorElementType:$value,
31293133
CIR_AnyFundamentalIntType:$index
31303134
);
31313135

@@ -3158,13 +3162,14 @@ def VecExtractOp : CIR_Op<"vec.extract", [Pure,
31583162
CIR_AnyFundamentalIntType:$index
31593163
);
31603164

3161-
let results = (outs CIR_AnyType:$result);
3165+
let results = (outs CIR_VectorElementType:$result);
31623166

31633167
let assemblyFormat = [{
31643168
$vec `[` $index `:` type($index) `]` attr-dict `:` qualified(type($vec))
31653169
}];
31663170

31673171
let llvmOp = "ExtractElementOp";
3172+
let hasFolder = 1;
31683173
}
31693174

31703175
//===----------------------------------------------------------------------===//
@@ -3180,7 +3185,7 @@ def VecCreateOp : CIR_Op<"vec.create", [Pure]> {
31803185
in the vector type.
31813186
}];
31823187

3183-
let arguments = (ins Variadic<CIR_AnyType>:$elements);
3188+
let arguments = (ins Variadic<CIR_VectorElementType>:$elements);
31843189
let results = (outs CIR_VectorType:$result);
31853190

31863191
let assemblyFormat = [{
@@ -3210,7 +3215,7 @@ def VecSplatOp : CIR_Op<"vec.splat", [Pure,
32103215
All elements of the vector have the same value, that of the given scalar.
32113216
}];
32123217

3213-
let arguments = (ins CIR_AnyType:$value);
3218+
let arguments = (ins CIR_VectorElementType:$value);
32143219
let results = (outs CIR_VectorType:$result);
32153220

32163221
let assemblyFormat = [{
@@ -3263,8 +3268,13 @@ def VecTernaryOp : CIR_Op<"vec.ternary",
32633268
The result is a vector of the same type as the second and third arguments.
32643269
Each element of the result is `(bool)a[n] ? b[n] : c[n]`.
32653270
}];
3266-
let arguments = (ins IntegerVector:$cond, CIR_VectorType:$vec1,
3267-
CIR_VectorType:$vec2);
3271+
3272+
let arguments = (ins
3273+
CIR_VectorOfIntType:$cond,
3274+
CIR_VectorType:$vec1,
3275+
CIR_VectorType:$vec2
3276+
);
3277+
32683278
let results = (outs CIR_VectorType:$result);
32693279
let assemblyFormat = [{
32703280
`(` $cond `,` $vec1 `,` $vec2 `)` `:` qualified(type($cond)) `,`
@@ -3327,7 +3337,7 @@ def VecShuffleDynamicOp : CIR_Op<"vec.shuffle.dynamic",
33273337
result vector is constructed by taking the elements from the first input
33283338
vector from the indices indicated by the elements of the second vector.
33293339
}];
3330-
let arguments = (ins CIR_VectorType:$vec, IntegerVector:$indices);
3340+
let arguments = (ins CIR_VectorType:$vec, CIR_VectorOfIntType:$indices);
33313341
let results = (outs CIR_VectorType:$result);
33323342
let assemblyFormat = [{
33333343
$vec `:` qualified(type($vec)) `,` $indices `:` qualified(type($indices))
@@ -4711,8 +4721,8 @@ def LLrintOp : UnaryFPToIntBuiltinOp<"llrint", "LlrintOp">;
47114721

47124722
class UnaryFPToFPBuiltinOp<string mnemonic, string llvmOpName>
47134723
: CIR_Op<mnemonic, [Pure, SameOperandsAndResultType]> {
4714-
let arguments = (ins CIR_AnyFloatOrVecOfFloat:$src);
4715-
let results = (outs CIR_AnyFloatOrVecOfFloat:$result);
4724+
let arguments = (ins CIR_AnyFloatOrVecOfFloatType:$src);
4725+
let results = (outs CIR_AnyFloatOrVecOfFloatType:$result);
47164726
let summary = "libc builtin equivalent ignoring "
47174727
"floating point exceptions and errno";
47184728
let assemblyFormat = "$src `:` type($src) attr-dict";
@@ -4742,8 +4752,6 @@ def TanOp : UnaryFPToFPBuiltinOp<"tan", "TanOp">;
47424752
def TruncOp : UnaryFPToFPBuiltinOp<"trunc", "FTruncOp">;
47434753

47444754
def AbsOp : CIR_Op<"abs", [Pure, SameOperandsAndResultType]> {
4745-
let arguments = (ins CIR_AnySignedIntOrVecOfSignedInt:$src, UnitAttr:$poison);
4746-
let results = (outs CIR_AnySignedIntOrVecOfSignedInt:$result);
47474755
let summary = [{
47484756
libc builtin equivalent abs, labs, llabs
47494757

@@ -4759,6 +4767,14 @@ def AbsOp : CIR_Op<"abs", [Pure, SameOperandsAndResultType]> {
47594767
%2 = cir.abs %3 : !cir.vector<!s32i x 4>
47604768
```
47614769
}];
4770+
4771+
let arguments = (ins
4772+
CIR_AnySIntOrVecOfSIntType:$src,
4773+
UnitAttr:$poison
4774+
);
4775+
4776+
let results = (outs CIR_AnySIntOrVecOfSIntType:$result);
4777+
47624778
let assemblyFormat = "$src ( `poison` $poison^ )? `:` type($src) attr-dict";
47634779
}
47644780

@@ -4768,9 +4784,12 @@ class BinaryFPToFPBuiltinOp<string mnemonic, string llvmOpName>
47684784
libc builtin equivalent ignoring floating-point exceptions and errno.
47694785
}];
47704786

4771-
let arguments = (ins CIR_AnyFloatOrVecOfFloat:$lhs,
4772-
CIR_AnyFloatOrVecOfFloat:$rhs);
4773-
let results = (outs CIR_AnyFloatOrVecOfFloat:$result);
4787+
let arguments = (ins
4788+
CIR_AnyFloatOrVecOfFloatType:$lhs,
4789+
CIR_AnyFloatOrVecOfFloatType:$rhs
4790+
);
4791+
4792+
let results = (outs CIR_AnyFloatOrVecOfFloatType:$result);
47744793

47754794
let assemblyFormat = [{
47764795
$lhs `,` $rhs `:` qualified(type($lhs)) attr-dict

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class CIR_TypeSummaries<list<Type> types> {
4343
string value = !if(!eq(!size(types), 1), joined, "any of " # joined);
4444
}
4545

46+
//===----------------------------------------------------------------------===//
47+
// Bool Type predicates
48+
//===----------------------------------------------------------------------===//
49+
50+
def CIR_AnyBoolType : CIR_TypeBase<"::cir::BoolType", "boolean type">;
51+
4652
//===----------------------------------------------------------------------===//
4753
// IntType predicates
4854
//===----------------------------------------------------------------------===//
@@ -250,4 +256,78 @@ def CIR_PtrToExceptionInfoType
250256
BuildableType<"$_builder.getType<" # cppType # ">("
251257
"cir::ExceptionInfoType::get($_builder.getContext())))">;
252258

259+
//===----------------------------------------------------------------------===//
260+
// Data member type predicates
261+
//===----------------------------------------------------------------------===//
262+
263+
def CIR_AnyDataMemberType : CIR_TypeBase<"::cir::DataMemberType",
264+
"data member type">;
265+
266+
//===----------------------------------------------------------------------===//
267+
// Scalar Type predicates
268+
//===----------------------------------------------------------------------===//
269+
270+
defvar CIR_ScalarTypes = [
271+
CIR_AnyBoolType, CIR_AnyIntType, CIR_AnyFloatType, CIR_AnyPtrType,
272+
CIR_AnyDataMemberType
273+
];
274+
275+
def CIR_AnyScalarType : AnyTypeOf<CIR_ScalarTypes, "cir scalar type"> {
276+
let cppFunctionName = "isScalarType";
277+
}
278+
279+
//===----------------------------------------------------------------------===//
280+
// Vector Type predicates
281+
//===----------------------------------------------------------------------===//
282+
283+
def CIR_AnyVectorType : CIR_TypeBase<"::cir::VectorType", "vector type">;
284+
285+
def CIR_VectorElementType : AnyTypeOf<[CIR_AnyIntOrFloatType, CIR_AnyPtrType],
286+
"any cir integer, floating point or pointer type"
287+
> {
288+
let cppFunctionName = "isValidVectorTypeElementType";
289+
}
290+
291+
// Element type constraint bases
292+
class CIR_ElementTypePred<Pred pred> : SubstLeaves<"$_self",
293+
"::mlir::cast<::cir::VectorType>($_self).getElementType()", pred>;
294+
295+
class CIR_VectorTypeOf<list<Type> types, string summary = "">
296+
: CIR_ConfinedType<CIR_AnyVectorType,
297+
[Or<!foreach(type, types, CIR_ElementTypePred<type.predicate>)>],
298+
!if(!empty(summary),
299+
"vector of " # CIR_TypeSummaries<types>.value,
300+
summary)>;
301+
302+
// Vector of type constraints
303+
def CIR_VectorOfIntType : CIR_VectorTypeOf<[CIR_AnyIntType]>;
304+
def CIR_VectorOfUIntType : CIR_VectorTypeOf<[CIR_AnyUIntType]>;
305+
def CIR_VectorOfSIntType : CIR_VectorTypeOf<[CIR_AnySIntType]>;
306+
def CIR_VectorOfFloatType : CIR_VectorTypeOf<[CIR_AnyFloatType]>;
307+
308+
// Vector or Scalar type constraints
309+
def CIR_AnyIntOrVecOfIntType
310+
: AnyTypeOf<[CIR_AnyIntType, CIR_VectorOfIntType],
311+
"integer or vector of integer type"> {
312+
let cppFunctionName = "isIntOrVectorOfIntType";
313+
}
314+
315+
def CIR_AnySIntOrVecOfSIntType
316+
: AnyTypeOf<[CIR_AnySIntType, CIR_VectorOfSIntType],
317+
"signed integer or vector of signed integer type"> {
318+
let cppFunctionName = "isSIntOrVectorOfSIntType";
319+
}
320+
321+
def CIR_AnyUIntOrVecOfUIntType
322+
: AnyTypeOf<[CIR_AnyUIntType, CIR_VectorOfUIntType],
323+
"unsigned integer or vector of unsigned integer type"> {
324+
let cppFunctionName = "isUIntOrVectorOfUIntType";
325+
}
326+
327+
def CIR_AnyFloatOrVecOfFloatType
328+
: AnyTypeOf<[CIR_AnyFloatType, CIR_VectorOfFloatType],
329+
"floating point or vector of floating point type"> {
330+
let cppFunctionName = "isFPOrVectorOfFPType";
331+
}
332+
253333
#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ struct RecordTypeStorage;
2727

2828
bool isValidFundamentalIntWidth(unsigned width);
2929

30-
bool isScalarType(mlir::Type t);
31-
bool isFPOrFPVectorTy(mlir::Type);
32-
bool isIntOrIntVectorTy(mlir::Type);
3330
} // namespace cir
3431

3532
mlir::ParseResult parseAddrSpaceAttribute(mlir::AsmParser &p,

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

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,15 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr",
262262
}
263263

264264
//===----------------------------------------------------------------------===//
265-
// DataMemberType
265+
// CIR_DataMemberType
266266
//===----------------------------------------------------------------------===//
267267

268268
def CIR_DataMemberType : CIR_Type<"DataMember", "data_member",
269269
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
270270

271271
let summary = "CIR type that represents pointer-to-data-member type in C++";
272272
let description = [{
273-
`cir.member_ptr` models the pointer-to-data-member type in C++. Values of
273+
`cir.data_member` models the pointer-to-data-member type in C++. Values of
274274
this type are essentially offsets of the pointed-to member within one of
275275
its containing record.
276276
}];
@@ -345,11 +345,31 @@ def CIR_VectorType : CIR_Type<"Vector", "vector",
345345

346346
let summary = "CIR vector type";
347347
let description = [{
348-
`cir.vector' represents fixed-size vector types. The parameters are the
349-
element type and the number of elements.
348+
The `!cir.vector` type represents a fixed-size, one-dimensional vector.
349+
It takes two parameters: the element type and the number of elements.
350+
351+
Syntax:
352+
353+
```mlir
354+
vector-type ::= !cir.vector<element-type x size>
355+
element-type ::= float-type | integer-type | pointer-type
356+
```
357+
358+
The `element-type` must be a scalar CIR type. Zero-sized vectors are not
359+
allowed. The `size` must be a positive integer.
360+
361+
Examples:
362+
363+
```mlir
364+
!cir.vector<!cir.int<u, 8> x 4>
365+
!cir.vector<!cir.float x 2>
366+
```
350367
}];
351368

352-
let parameters = (ins "mlir::Type":$elementType, "uint64_t":$size);
369+
let parameters = (ins
370+
CIR_VectorElementType:$elementType,
371+
"uint64_t":$size
372+
);
353373

354374
let builders = [
355375
TypeBuilderWithInferredContext<(ins
@@ -503,50 +523,6 @@ def CIR_VoidType : CIR_Type<"Void", "void"> {
503523
}];
504524
}
505525

506-
// Constraints
507-
508-
// Vector of integral type
509-
def IntegerVector : Type<
510-
And<[
511-
CPred<"::mlir::isa<::cir::VectorType>($_self)">,
512-
CPred<"::mlir::isa<::cir::IntType>("
513-
"::mlir::cast<::cir::VectorType>($_self).getElementType())">,
514-
CPred<"::mlir::cast<::cir::IntType>("
515-
"::mlir::cast<::cir::VectorType>($_self).getElementType())"
516-
".isFundamental()">
517-
]>, "!cir.vector of !cir.int"> {
518-
}
519-
520-
// Vector of signed integral type
521-
def SignedIntegerVector : Type<
522-
And<[
523-
CPred<"::mlir::isa<::cir::VectorType>($_self)">,
524-
CPred<"::mlir::isa<::cir::IntType>("
525-
"::mlir::cast<::cir::VectorType>($_self).getElementType())">,
526-
CPred<"::mlir::cast<::cir::IntType>("
527-
"::mlir::cast<::cir::VectorType>($_self).getElementType())"
528-
".isSignedFundamental()">
529-
]>, "!cir.vector of !cir.int"> {
530-
}
531-
532-
// Vector of Float type
533-
def FPVector : Type<
534-
And<[
535-
CPred<"::mlir::isa<::cir::VectorType>($_self)">,
536-
CPred<"::mlir::isa<::cir::SingleType, ::cir::DoubleType>("
537-
"::mlir::cast<::cir::VectorType>($_self).getElementType())">,
538-
]>, "!cir.vector of !cir.fp"> {
539-
}
540-
541-
// Constraints
542-
def CIR_AnyIntOrVecOfInt: AnyTypeOf<[CIR_IntType, IntegerVector]>;
543-
544-
def CIR_AnySignedIntOrVecOfSignedInt: AnyTypeOf<[
545-
CIR_AnyFundamentalSIntType, SignedIntegerVector
546-
]>;
547-
548-
def CIR_AnyFloatOrVecOfFloat: AnyTypeOf<[CIR_AnyFloatType, FPVector]>;
549-
550526
//===----------------------------------------------------------------------===//
551527
// RecordType
552528
//

clang/include/clang/Driver/Types.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ TYPE("lto-ir", LTO_IR, INVALID, "s", phases
100100
TYPE("lto-bc", LTO_BC, INVALID, "o", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
101101

102102
TYPE("mlir", MLIR, INVALID, "mlir", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
103+
TYPE("cir", CIR, INVALID, "cir", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
103104

104105
// Misc.
105106
TYPE("ast", AST, INVALID, "ast", phases::Compile, phases::Backend, phases::Assemble, phases::Link)

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
14821482

14831483
case Builtin::BI__builtin_elementwise_abs: {
14841484
mlir::Type cirTy = convertType(E->getArg(0)->getType());
1485-
bool isIntTy = cir::isIntOrIntVectorTy(cirTy);
1485+
bool isIntTy = cir::isIntOrVectorOfIntType(cirTy);
14861486
if (!isIntTy) {
14871487
return emitUnaryFPBuiltin<cir::FAbsOp>(*this, *E);
14881488
}

clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,7 +4015,7 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
40154015
mlir::Location loc = getLoc(E->getExprLoc());
40164016
Ops[0] = builder.createBitcast(Ops[0], ty);
40174017
Ops[1] = builder.createBitcast(Ops[1], ty);
4018-
if (cir::isFPOrFPVectorTy(ty)) {
4018+
if (cir::isFPOrVectorOfFPType(ty)) {
40194019
return builder.create<cir::FMaximumOp>(loc, Ops[0], Ops[1]);
40204020
}
40214021
return builder.create<cir::BinOp>(loc, cir::BinOpKind::Max, Ops[0], Ops[1]);
@@ -4026,7 +4026,7 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
40264026
case NEON::BI__builtin_neon_vmin_v:
40274027
case NEON::BI__builtin_neon_vminq_v: {
40284028
llvm::StringRef name = usgn ? "aarch64.neon.umin" : "aarch64.neon.smin";
4029-
if (cir::isFPOrFPVectorTy(ty))
4029+
if (cir::isFPOrVectorOfFPType(ty))
40304030
name = "aarch64.neon.fmin";
40314031
return emitNeonCall(builder, {ty, ty}, Ops, name, ty,
40324032
getLoc(E->getExprLoc()));
@@ -4037,7 +4037,7 @@ CIRGenFunction::emitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
40374037
case NEON::BI__builtin_neon_vabd_v:
40384038
case NEON::BI__builtin_neon_vabdq_v: {
40394039
llvm::StringRef name = usgn ? "aarch64.neon.uabd" : "aarch64.neon.sabd";
4040-
if (cir::isFPOrFPVectorTy(ty))
4040+
if (cir::isFPOrVectorOfFPType(ty))
40414041
name = "aarch64.neon.fabd";
40424042
return emitNeonCall(builder, {ty, ty}, Ops, name, ty,
40434043
getLoc(E->getExprLoc()));

0 commit comments

Comments
 (0)