@@ -180,10 +180,18 @@ class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
180
180
let VecWidth = 0;
181
181
}
182
182
183
+ // Builtin function attributes.
184
+ def Attr {
185
+ list<bit> None = [0, 0, 0];
186
+ list<bit> Pure = [1, 0, 0];
187
+ list<bit> Const = [0, 1, 0];
188
+ list<bit> Convergent = [0, 0, 1];
189
+ }
190
+
183
191
//===----------------------------------------------------------------------===//
184
192
// OpenCL C class for builtin functions
185
193
//===----------------------------------------------------------------------===//
186
- class Builtin<string _Name, list<Type> _Signature> {
194
+ class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None > {
187
195
// Name of the builtin function
188
196
string Name = _Name;
189
197
// List of types used by the function. The first one is the return type and
@@ -192,6 +200,12 @@ class Builtin<string _Name, list<Type> _Signature> {
192
200
list<Type> Signature = _Signature;
193
201
// OpenCL Extension to which the function belongs (cl_khr_subgroups, ...)
194
202
string Extension = "";
203
+ // Function attribute __attribute__((pure))
204
+ bit IsPure = _Attributes[0];
205
+ // Function attribute __attribute__((const))
206
+ bit IsConst = _Attributes[1];
207
+ // Function attribute __attribute__((convergent))
208
+ bit IsConv = _Attributes[2];
195
209
// Version of OpenCL from which the function is available (e.g.: CL10).
196
210
// MinVersion is inclusive.
197
211
Version MinVersion = CL10;
@@ -307,11 +321,12 @@ foreach RType = [Float, Double, Half, Char, UChar, Short,
307
321
UShort, Int, UInt, Long, ULong] in {
308
322
foreach sat = ["", "_sat"] in {
309
323
foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
310
- def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType]>;
324
+ def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
325
+ Attr.Const>;
311
326
foreach v = [2, 3, 4, 8, 16] in {
312
327
def : Builtin<"convert_" # RType.Name # v # sat # rnd,
313
- [VectorType<RType, v>,
314
- VectorType<IType, v>] >;
328
+ [VectorType<RType, v>, VectorType<IType, v>],
329
+ Attr.Const >;
315
330
}
316
331
}
317
332
}
@@ -321,11 +336,11 @@ foreach RType = [Float, Double, Half, Char, UChar, Short,
321
336
//--------------------------------------------------------------------
322
337
// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
323
338
// --- Table 7 ---
324
- def : Builtin<"get_work_dim", [UInt]>;
339
+ def : Builtin<"get_work_dim", [UInt], Attr.Const >;
325
340
foreach name = ["get_global_size", "get_global_id", "get_local_size",
326
341
"get_local_id", "get_num_groups", "get_group_id",
327
342
"get_global_offset"] in {
328
- def : Builtin<name, [Size, UInt]>;
343
+ def : Builtin<name, [Size, UInt], Attr.Const >;
329
344
}
330
345
331
346
let MinVersion = CL20 in {
@@ -491,24 +506,24 @@ foreach Type = [Int, UInt] in {
491
506
foreach name = ["acos", "acosh", "acospi",
492
507
"asin", "asinh", "asinpi",
493
508
"atan", "atanh", "atanpi"] in {
494
- def : Builtin<name, [FGenTypeN, FGenTypeN]>;
509
+ def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const >;
495
510
}
496
511
497
512
foreach name = ["atan2", "atan2pi"] in {
498
- def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
513
+ def : Builtin<name, [FGenTypeN, FGenTypeN,FGenTypeN], Attr.Const >;
499
514
}
500
515
501
516
foreach name = ["fmax", "fmin"] in {
502
517
def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
503
- def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float]>;
504
- def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double]>;
505
- def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half]>;
518
+ def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const >;
519
+ def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const >;
520
+ def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const >;
506
521
}
507
522
508
523
// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
509
524
foreach name = ["max", "min"] in {
510
- def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN]>;
511
- def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1]>;
525
+ def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const >;
526
+ def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const >;
512
527
}
513
528
514
529
//--------------------------------------------------------------------
@@ -517,49 +532,49 @@ foreach name = ["max", "min"] in {
517
532
// --- Table 22: Image Read Functions with Samplers ---
518
533
foreach imgTy = [Image1d] in {
519
534
foreach coordTy = [Int, Float] in {
520
- def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
521
- def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
522
- def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
535
+ def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure >;
536
+ def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure >;
537
+ def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure >;
523
538
}
524
539
}
525
540
foreach imgTy = [Image2d, Image1dArray] in {
526
541
foreach coordTy = [Int, Float] in {
527
- def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
528
- def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
529
- def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
542
+ def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure >;
543
+ def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure >;
544
+ def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure >;
530
545
}
531
546
}
532
547
foreach imgTy = [Image3d, Image2dArray] in {
533
548
foreach coordTy = [Int, Float] in {
534
- def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
535
- def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
536
- def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
549
+ def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure >;
550
+ def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure >;
551
+ def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure >;
537
552
}
538
553
}
539
554
foreach coordTy = [Int, Float] in {
540
- def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>]>;
541
- def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>]>;
555
+ def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure >;
556
+ def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure >;
542
557
}
543
558
544
559
// --- Table 23: Sampler-less Read Functions ---
545
560
foreach aQual = ["RO", "RW"] in {
546
561
foreach imgTy = [Image2d, Image1dArray] in {
547
- def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
548
- def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
549
- def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
562
+ def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure >;
563
+ def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure >;
564
+ def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure >;
550
565
}
551
566
foreach imgTy = [Image3d, Image2dArray] in {
552
- def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
553
- def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
554
- def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
567
+ def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure >;
568
+ def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure >;
569
+ def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure >;
555
570
}
556
571
foreach imgTy = [Image1d, Image1dBuffer] in {
557
- def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int]>;
558
- def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int]>;
559
- def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int]>;
572
+ def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure >;
573
+ def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure >;
574
+ def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure >;
560
575
}
561
- def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>]>;
562
- def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>]>;
576
+ def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure >;
577
+ def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure >;
563
578
}
564
579
565
580
// --- Table 24: Image Write Functions ---
@@ -624,13 +639,13 @@ foreach aQual = ["RO"] in {
624
639
foreach name = ["read_imageh"] in {
625
640
foreach coordTy = [Int, Float] in {
626
641
foreach imgTy = [Image2d, Image1dArray] in {
627
- def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>]>;
642
+ def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure >;
628
643
}
629
644
foreach imgTy = [Image3d, Image2dArray] in {
630
- def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>]>;
645
+ def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure >;
631
646
}
632
647
foreach imgTy = [Image1d] in {
633
- def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy]>;
648
+ def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure >;
634
649
}
635
650
}
636
651
}
@@ -640,13 +655,13 @@ foreach aQual = ["RO"] in {
640
655
foreach aQual = ["RO", "RW"] in {
641
656
foreach name = ["read_imageh"] in {
642
657
foreach imgTy = [Image2d, Image1dArray] in {
643
- def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
658
+ def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure >;
644
659
}
645
660
foreach imgTy = [Image3d, Image2dArray] in {
646
- def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
661
+ def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure >;
647
662
}
648
663
foreach imgTy = [Image1d, Image1dBuffer] in {
649
- def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int]>;
664
+ def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure >;
650
665
}
651
666
}
652
667
}
0 commit comments