Skip to content

Commit dba8d2e

Browse files
committed
[NFC] Simplify making trivial scalar pair types.
1 parent 2e8d016 commit dba8d2e

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

lib/IRGen/GenIntegerLiteral.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,26 @@ namespace {
3636

3737
/// A TypeInfo implementation for Builtin.IntegerLiteral.
3838
class IntegerLiteralTypeInfo :
39-
public ScalarPairTypeInfo<IntegerLiteralTypeInfo, LoadableTypeInfo> {
39+
public TrivialScalarPairTypeInfo<IntegerLiteralTypeInfo, LoadableTypeInfo> {
4040

4141
public:
4242
IntegerLiteralTypeInfo(llvm::StructType *storageType,
4343
Size size, Alignment align, SpareBitVector &&spareBits)
44-
: ScalarPairTypeInfo(storageType, size, std::move(spareBits), align,
45-
IsPOD, IsFixedSize) {}
44+
: TrivialScalarPairTypeInfo(storageType, size, std::move(spareBits), align,
45+
IsPOD, IsFixedSize) {}
4646

4747
static Size getFirstElementSize(IRGenModule &IGM) {
4848
return IGM.getPointerSize();
4949
}
5050
static StringRef getFirstElementLabel() {
5151
return ".data";
5252
}
53-
static bool isFirstElementTrivial() {
54-
return true;
55-
}
5653

5754
TypeLayoutEntry *buildTypeLayoutEntry(IRGenModule &IGM,
5855
SILType T) const override {
5956
return IGM.typeLayoutCache.getOrCreateScalarEntry(*this, T);
6057
}
6158

62-
void emitRetainFirstElement(IRGenFunction &IGF, llvm::Value *fn,
63-
Optional<Atomicity> atomicity = None) const {}
64-
void emitReleaseFirstElement(IRGenFunction &IGF, llvm::Value *fn,
65-
Optional<Atomicity> atomicity = None) const {}
66-
void emitAssignFirstElement(IRGenFunction &IGF, llvm::Value *fn,
67-
Address fnAddr) const {
68-
IGF.Builder.CreateStore(fn, fnAddr);
69-
}
70-
7159
static Size getSecondElementOffset(IRGenModule &IGM) {
7260
return IGM.getPointerSize();
7361
}
@@ -77,17 +65,6 @@ class IntegerLiteralTypeInfo :
7765
static StringRef getSecondElementLabel() {
7866
return ".flags";
7967
}
80-
bool isSecondElementTrivial() const {
81-
return true;
82-
}
83-
void emitRetainSecondElement(IRGenFunction &IGF, llvm::Value *data,
84-
Optional<Atomicity> atomicity = None) const {}
85-
void emitReleaseSecondElement(IRGenFunction &IGF, llvm::Value *data,
86-
Optional<Atomicity> atomicity = None) const {}
87-
void emitAssignSecondElement(IRGenFunction &IGF, llvm::Value *context,
88-
Address dataAddr) const {
89-
IGF.Builder.CreateStore(context, dataAddr);
90-
}
9168

9269
// The data pointer isn't a heap object, but it is an aligned pointer.
9370
bool mayHaveExtraInhabitants(IRGenModule &IGM) const override {

lib/IRGen/ScalarPairTypeInfo.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,43 @@ class ScalarPairTypeInfo : public ScalarTypeInfo<Derived, Base> {
179179
}
180180
};
181181

182+
template <class Derived, class Base>
183+
class TrivialScalarPairTypeInfo : public ScalarPairTypeInfo<Derived, Base> {
184+
using super = ScalarPairTypeInfo<Derived, Base>;
185+
protected:
186+
template <class... T> TrivialScalarPairTypeInfo(T &&...args)
187+
: super(::std::forward<T>(args)...) {}
188+
189+
const Derived &asDerived() const {
190+
return static_cast<const Derived &>(*this);
191+
}
192+
193+
public:
194+
static bool isFirstElementTrivial() {
195+
return true;
196+
}
197+
void emitRetainFirstElement(IRGenFunction &IGF, llvm::Value *value,
198+
Optional<Atomicity> atomicity = None) const {}
199+
void emitReleaseFirstElement(IRGenFunction &IGF, llvm::Value *value,
200+
Optional<Atomicity> atomicity = None) const {}
201+
void emitAssignFirstElement(IRGenFunction &IGF, llvm::Value *value,
202+
Address valueAddr) const {
203+
IGF.Builder.CreateStore(value, valueAddr);
204+
}
205+
206+
static bool isSecondElementTrivial() {
207+
return true;
208+
}
209+
void emitRetainSecondElement(IRGenFunction &IGF, llvm::Value *value,
210+
Optional<Atomicity> atomicity = None) const {}
211+
void emitReleaseSecondElement(IRGenFunction &IGF, llvm::Value *value,
212+
Optional<Atomicity> atomicity = None) const {}
213+
void emitAssignSecondElement(IRGenFunction &IGF, llvm::Value *value,
214+
Address valueAddr) const {
215+
IGF.Builder.CreateStore(value, valueAddr);
216+
}
217+
};
218+
182219
}
183220
}
184221

0 commit comments

Comments
 (0)