@@ -54,8 +54,6 @@ class AttributeImpl : public FoldingSetNode {
54
54
AttributeImpl (const AttributeImpl &) = delete ;
55
55
AttributeImpl &operator =(const AttributeImpl &) = delete ;
56
56
57
- virtual ~AttributeImpl ();
58
-
59
57
bool isEnumAttribute () const { return KindID == EnumAttrEntry; }
60
58
bool isIntAttribute () const { return KindID == IntAttrEntry; }
61
59
bool isStringAttribute () const { return KindID == StringAttrEntry; }
@@ -104,6 +102,9 @@ class AttributeImpl : public FoldingSetNode {
104
102
}
105
103
};
106
104
105
+ static_assert (std::is_trivially_destructible<AttributeImpl>::value,
106
+ " AttributeImpl should be trivially destructible" );
107
+
107
108
// ===----------------------------------------------------------------------===//
108
109
// / \class
109
110
// / A set of classes that contain the value of the
@@ -112,8 +113,6 @@ class AttributeImpl : public FoldingSetNode {
112
113
// / attribute enties, which are for target-dependent attributes.
113
114
114
115
class EnumAttributeImpl : public AttributeImpl {
115
- virtual void anchor ();
116
-
117
116
Attribute::AttrKind Kind;
118
117
119
118
protected:
@@ -130,8 +129,6 @@ class EnumAttributeImpl : public AttributeImpl {
130
129
class IntAttributeImpl : public EnumAttributeImpl {
131
130
uint64_t Val;
132
131
133
- void anchor () override ;
134
-
135
132
public:
136
133
IntAttributeImpl (Attribute::AttrKind Kind, uint64_t Val)
137
134
: EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) {
@@ -142,24 +139,43 @@ class IntAttributeImpl : public EnumAttributeImpl {
142
139
uint64_t getValue () const { return Val; }
143
140
};
144
141
145
- class StringAttributeImpl : public AttributeImpl {
146
- virtual void anchor ();
142
+ class StringAttributeImpl final
143
+ : public AttributeImpl,
144
+ private TrailingObjects<StringAttributeImpl, char > {
145
+ friend TrailingObjects;
147
146
148
- std::string Kind;
149
- std::string Val;
147
+ unsigned KindSize;
148
+ unsigned ValSize;
149
+ size_t numTrailingObjects (OverloadToken<char >) const {
150
+ return KindSize + 1 + ValSize + 1 ;
151
+ }
150
152
151
153
public:
152
154
StringAttributeImpl (StringRef Kind, StringRef Val = StringRef())
153
- : AttributeImpl(StringAttrEntry), Kind(std::string(Kind)),
154
- Val (std::string(Val)) {}
155
+ : AttributeImpl(StringAttrEntry), KindSize(Kind.size()),
156
+ ValSize (Val.size()) {
157
+ char *TrailingString = getTrailingObjects<char >();
158
+ // Some users rely on zero-termination.
159
+ llvm::copy (Kind, TrailingString);
160
+ TrailingString[KindSize] = ' \0 ' ;
161
+ llvm::copy (Val, &TrailingString[KindSize + 1 ]);
162
+ TrailingString[KindSize + 1 + ValSize] = ' \0 ' ;
163
+ }
155
164
156
- StringRef getStringKind () const { return Kind; }
157
- StringRef getStringValue () const { return Val; }
165
+ StringRef getStringKind () const {
166
+ return StringRef (getTrailingObjects<char >(), KindSize);
167
+ }
168
+ StringRef getStringValue () const {
169
+ return StringRef (getTrailingObjects<char >() + KindSize + 1 , ValSize);
170
+ }
171
+
172
+ static size_t totalSizeToAlloc (StringRef Kind, StringRef Val) {
173
+ return TrailingObjects::totalSizeToAlloc<char >(Kind.size () + 1 +
174
+ Val.size () + 1 );
175
+ }
158
176
};
159
177
160
178
class TypeAttributeImpl : public EnumAttributeImpl {
161
- void anchor () override ;
162
-
163
179
Type *Ty;
164
180
165
181
public:
@@ -265,8 +281,6 @@ class AttributeListImpl final
265
281
AttributeListImpl (const AttributeListImpl &) = delete ;
266
282
AttributeListImpl &operator =(const AttributeListImpl &) = delete ;
267
283
268
- void operator delete (void *p) { ::operator delete (p); }
269
-
270
284
// / Get the context that created this AttributeListImpl.
271
285
LLVMContext &getContext () { return Context; }
272
286
@@ -287,6 +301,9 @@ class AttributeListImpl final
287
301
void dump () const ;
288
302
};
289
303
304
+ static_assert (std::is_trivially_destructible<AttributeListImpl>::value,
305
+ " AttributeListImpl should be trivially destructible" );
306
+
290
307
} // end namespace llvm
291
308
292
309
#endif // LLVM_LIB_IR_ATTRIBUTEIMPL_H
0 commit comments