@@ -515,12 +515,56 @@ The front-end encodes the properties from the C++ attribute
515
515
* The third parameter is the name of the source file (as with any call to this
516
516
intrinsic).
517
517
* The fourth parameter is the line number (as with any call to this intrinsic).
518
- * The fifth parameter is a metadata tuple with information about all of the
519
- properties. The first element of the tuple is a string literal with the name
520
- of the first property. The second element is the value of the first
521
- property. The third element is a string literal with the name of the second
522
- property, etc. Since each property has exactly one value, this tuple has an
523
- even number of elements.
518
+ * The fifth parameter is a pointer to a constant global variable. The type of
519
+ this variable is an anonymous structure. The first field of the structure is
520
+ a pointer to a string literal representing the name of the first property. The
521
+ second field of the structure is a pointer to a string literal representing
522
+ the value of the first property. The third field of the structure is a pointer
523
+ to a string literal representing the name of the second property, etc.
524
+ Since each property has exactly one value, this tuple has an even number of
525
+ elements. Pointers to property value strings may be a null-pointer, signalling
526
+ a property without a value.
527
+
528
+ The resulting LLVM IR for the previous example would be:
529
+
530
+ ```
531
+ @.str = private unnamed_addr constant [16 x i8] c"sycl-properties\00",
532
+ section "llvm.metadata"
533
+ @.str.1 = private unnamed_addr constant [9 x i8] c"file.cpp\00",
534
+ section "llvm.metadata"
535
+ @.str.2 = private unnamed_addr constant [9 x i8] c"sycl-foo\00",
536
+ section "llvm.metadata"
537
+ @.str.3 = private unnamed_addr constant [9 x i8] c"sycl-bar\00",
538
+ section "llvm.metadata"
539
+ @.str.4 = private unnamed_addr constant [3 x i8] c"32\00",
540
+ section "llvm.metadata"
541
+
542
+ @.args = private unnamed_addr constant { [9 x i8]*, i8*, [9 x i8]*, [3 x i8]* }
543
+ {
544
+ [9 x i8]* @.str.2, ; Name of first property "sycl-foo"
545
+ i8* null, ; Null indicates this property has no value
546
+ [9 x i8]* @.str.3, ; Name of second property "sycl-bar"
547
+ [3 x i8]* @.str.4 ; Value of second property
548
+ },
549
+ section "llvm.metadata"
550
+
551
+ define void @foo(i32* %ptr) {
552
+ %aptr = alloca %class.annotated_ptr
553
+ %ptr = getelementptr inbounds %class.annotated_ptr, %class.annotated_ptr* %aptr,
554
+ i32 0, i32 0
555
+ %1 = bitcast i32** %ptr to i8*
556
+
557
+ %2 = call i8* @llvm.ptr.annotation.p0i8(i8* nonnull %0,
558
+ i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0),
559
+ i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0),
560
+ i32 3,
561
+ i8* bitcast ({ [9 x i8]*, i8*, [9 x i8]*, [3 x i8]* }* @.args to i8*))
562
+
563
+ %3 = bitcast i8* %2 to i32**
564
+ store i32* %ptr, i32** %3
565
+ ret void
566
+ }
567
+ ```
524
568
525
569
** NOTE** : Calls to the ` @llvm.ptr.annotation ` intrinsic function are known to
526
570
disable many clang optimizations. As a result, properties added to a
@@ -806,26 +850,57 @@ into one (or both) of the following:
806
850
In both cases, the decoration is a single ** UserSemantic** decoration where the
807
851
string literal is the same as the string literal in the LLVM annotation.
808
852
809
- When a SYCL structure member property needs to be represented in SPIR-V,
810
- however, we prefer to represent each property as an extended SPIR-V decoration
811
- rather than using a ** UserSemantic** decoration. There is no existing
812
- mechanism in the SPIR-V LLVM Translator to generate extended decorations like
813
- this, so we propose the following new mechanism.
853
+ An exception to this is for a selection of FPGA-related decorations. If these
854
+ are supported during translation from LLVM IR to SPIR-V the corresponding
855
+ decorations will be generated, and otherwise it will fall back to creating a
856
+ single ** UserSemantic** decoration. In general these decorations occur in the
857
+ annotation string as a series of ** {X}** and ** {X: Y }** where ** X** is a reserved
858
+ name and ** Y** is one or more words and numbers separated by ** ,** or ** :** ,
859
+ depending on the decoration.
860
+
861
+ As such we propose an extension to this functionality with the following
862
+ changes:
863
+
864
+ * To bring it in line with the format of the metadata decorations, the parsing
865
+ of these decorations should allow the use of SPIR-V decoration identifiers
866
+ rather than reserved names. With this there need not be any agreement between
867
+ the translator and LLVM IR producer, as the identifiers are specified by the
868
+ SPIR-V specification.
869
+ * For decorations parsed with decoration identifiers, only the ** ,** delimiter
870
+ is valid for separating decoration values.
871
+ * In addition to words and numbers, string literals enclosed by quotation marks
872
+ are allowed as decoration values. No escapes are planned for this, so all
873
+ symbols between starting quotation mark and ending quotation mark are
874
+ considered part of the string literal.
814
875
815
876
When a member variable property needs to be represented in SPIR-V, the
816
- ` sycl-post-link ` tool converts the ` @llvm.ptr.annotation ` intrinsic call into a
817
- call to the SPIR-V intrinsic ` __spirv_AddMemberDecoration ` which has a metadata
818
- function argument that specifies the decorations as illustrated below :
877
+ ` sycl-post-link ` tool converts the ` @llvm.ptr.annotation ` intrinsic call
878
+ produced by ` [[__sycl_detail__::add_ir_annotations_member()]] ` into another
879
+ ` @llvm.ptr.annotation ` intrinsic call using this format. For example :
819
880
820
881
```
821
- %annotated_ptr = call i8* __spirv_AddMemberDecoration(i8* %ptr, metadata !0)
882
+ ; Contains decorations:
883
+ ; * 7744 with no value.
884
+ ; * 7745 with 20 and "str 1" as the values.
885
+ @.str = private unnamed_addr constant [24 x i8] c"{7744}{7745:20,"str 1"}\00",
886
+ section "llvm.metadata"
887
+ @.str.1 = private unnamed_addr constant [9 x i8] c"file.cpp\00",
888
+ section "llvm.metadata"
822
889
823
- !0 = !{!1, !2} ; Each operand in this metadata represents one
824
- ; decoration.
825
- !1 = !{i32 7744} ; This is the integer value of the first decoration.
826
- !2 = !{i32 7745, i32 20} ; The first operand is the integer value of the
827
- ; second decoration. Additional operands are
828
- ; "extra operands" to the decoration. These
829
- ; operands may be either integer literals or string
830
- ; literals.
890
+ define void @foo(i32* %ptr) {
891
+ ...
892
+
893
+ ; %0 points to the annotated member field.
894
+ %2 = call i8* @llvm.ptr.annotation.p0i8(i8* nonnull %0,
895
+ i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0),
896
+ i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0),
897
+ i32 3,
898
+ i8* null)
899
+
900
+ ...
901
+ }
831
902
```
903
+
904
+ ** NOTE** : To allow backwards compatibility with the old format, reverse
905
+ translation of decorations will produce a decorations in the annotation string
906
+ following the old format if the decoration had a reserved name.
0 commit comments