@@ -42,111 +42,16 @@ namespace detail {
42
42
class event_impl ;
43
43
using EventImplPtr = std::shared_ptr<event_impl>;
44
44
45
- // Periodically there is a need to extend handler and CG classes to hold more
46
- // data(members) than it has now. But any modification of the layout of those
47
- // classes is an ABI break. To have an ability to have more data the following
48
- // approach is implemented:
49
- //
50
- // Those classes have a member - MSharedPtrStorage which is an std::vector of
51
- // std::shared_ptr's and is supposed to hold reference counters of user
52
- // provided shared_ptr's.
53
- //
54
- // The first element of this vector is reused to store a vector of additional
55
- // members handler and CG need to have.
56
- //
57
- // These additional arguments are represented using "ExtendedMemberT" structure
58
- // which has a pointer to an arbitrary value and an integer which is used to
59
- // understand how the value the pointer points to should be interpreted.
60
- //
61
- // ======== ======== ========
62
- // | | | | ... | | std::vector<std::shared_ptr<void>>
63
- // ======== ======== ========
64
- // || || ||
65
- // || \/ \/
66
- // || user user
67
- // || data data
68
- // \/
69
- // ======== ======== ========
70
- // | Type | | Type | ... | Type | std::vector<ExtendedMemberT>
71
- // | | | | | |
72
- // | Ptr | | Ptr | ... | Ptr |
73
- // ======== ======== ========
74
- //
75
- // Prior to this change this vector was supposed to have user's values only, so
76
- // it is not legal to expect that the first argument is a special one.
77
- // Versioning is implemented to overcome this problem - if the first element of
78
- // the MSharedPtrStorage is a pointer to the special vector then CGType value
79
- // has version "1" encoded.
80
- //
81
- // The version of CG type is encoded in the highest byte of the value:
82
- //
83
- // 0x00000001 - CG type KERNEL version 0
84
- // 0x01000001 - CG type KERNEL version 1
85
- // ^
86
- // |
87
- // The byte specifies the version
88
- //
89
- // A user of this vector should not expect that a specific data is stored at a
90
- // specific position, but iterate over all looking for an ExtendedMemberT value
91
- // with the desired type.
92
- // This allows changing/extending the contents of this vector without changing
93
- // the version.
94
-
95
- // Used to represent a type of an extended member
96
- enum class ExtendedMembersType : unsigned int { PLACEHOLDER_TYPE };
97
-
98
- // Holds a pointer to an object of an arbitrary type and an ID value which
99
- // should be used to understand what type pointer points to.
100
- // Used as to extend handler class without introducing new class members which
101
- // would change handler layout.
102
- struct ExtendedMemberT {
103
- ExtendedMembersType MType;
104
- std::shared_ptr<void > MData;
105
- };
106
-
107
- static std::shared_ptr<std::vector<ExtendedMemberT>>
108
- convertToExtendedMembers (const std::shared_ptr<const void > &SPtr) {
109
- return std::const_pointer_cast<std::vector<ExtendedMemberT>>(
110
- std::static_pointer_cast<const std::vector<ExtendedMemberT>>(SPtr));
111
- }
112
-
113
45
class stream_impl ;
114
46
class queue_impl ;
115
47
class kernel_bundle_impl ;
116
48
117
- // The constant is used to left shift a CG type value to access it's version
118
- constexpr unsigned int ShiftBitsForVersion = 24 ;
119
-
120
- // Constructs versioned type
121
- constexpr unsigned int getVersionedCGType (unsigned int Type,
122
- unsigned char Version) {
123
- return Type | (static_cast <unsigned int >(Version) << ShiftBitsForVersion);
124
- }
125
-
126
- // Returns the type without version encoded
127
- constexpr unsigned char getUnversionedCGType (unsigned int Type) {
128
- unsigned int Mask = -1 ;
129
- Mask >>= (sizeof (Mask) * 8 - ShiftBitsForVersion);
130
- return Type & Mask;
131
- }
132
-
133
- // Returns the version encoded to the type
134
- constexpr unsigned char getCGTypeVersion (unsigned int Type) {
135
- return Type >> ShiftBitsForVersion;
136
- }
137
-
49
+ // If there's a need to add new members to CG classes without breaking ABI
50
+ // compatibility, we can bring back the extended members mechanism. See
51
+ // https://github.com/intel/llvm/pull/6759
138
52
// / Base class for all types of command groups.
139
53
class CG {
140
54
public:
141
- // Used to version CG and handler classes. Using unsigned char as the version
142
- // is encoded in the highest byte of CGType value. So it is not possible to
143
- // encode a value > 255 anyway which should be big enough room for version
144
- // bumping.
145
- enum class CG_VERSION : unsigned char {
146
- V0 = 0 ,
147
- V1 = 1 ,
148
- };
149
-
150
55
// / Type of the command group.
151
56
enum CGTYPE : unsigned int {
152
57
None = 0 ,
@@ -189,21 +94,7 @@ class CG {
189
94
190
95
CG (CG &&CommandGroup) = default;
191
96
192
- CGTYPE getType () { return static_cast <CGTYPE>(getUnversionedCGType (MType)); }
193
-
194
- CG_VERSION getVersion () {
195
- return static_cast <CG_VERSION>(getCGTypeVersion (MType));
196
- }
197
-
198
- std::shared_ptr<std::vector<ExtendedMemberT>> getExtendedMembers () {
199
- if (getCGTypeVersion (MType) == static_cast <unsigned int >(CG_VERSION::V0) ||
200
- MSharedPtrStorage.empty ())
201
- return nullptr ;
202
-
203
- // The first value in shared_ptr storage is supposed to store a vector of
204
- // extended members.
205
- return convertToExtendedMembers (MSharedPtrStorage[0 ]);
206
- }
97
+ CGTYPE getType () { return MType; }
207
98
208
99
virtual ~CG () = default ;
209
100
0 commit comments