@@ -26,54 +26,38 @@ namespace swift {
26
26
namespace irgen {
27
27
28
28
// / A description of how to represent an enum payload as a value.
29
- // / A payload can either use a generic word-chunked representation, or attempt
30
- // / to follow the explosion schema of one of its payload types.
29
+ // / A payload can either use a generic word-chunked representation,
30
+ // / or attempt to follow the explosion schema of one of its payload
31
+ // / types.
32
+ // / TODO: the current code only ever uses the generic word-chunked
33
+ // / representation, it might be better if it used an appropriate
34
+ // / explosion schema instead.
31
35
class EnumPayloadSchema {
32
- using BitSizeTy = llvm::PointerEmbeddedInt<unsigned , 31 >;
33
-
34
- const llvm::PointerUnion<ExplosionSchema *, BitSizeTy> Value;
35
-
36
+ // A size in bits less than 0 indicates that the payload size is
37
+ // dynamic.
38
+ const int64_t BitSize;
36
39
public:
37
- EnumPayloadSchema () : Value((ExplosionSchema *)nullptr ) {}
38
-
39
- explicit operator bool () {
40
- return Value.getOpaqueValue () != nullptr ;
41
- }
40
+ // / Create a new schema with a dynamic size.
41
+ EnumPayloadSchema () : BitSize(-1 ) {}
42
42
43
+ // / Create a new schema with the given fixed size in bits.
43
44
explicit EnumPayloadSchema (unsigned bits)
44
- : Value(BitSizeTy(bits)) {}
45
-
46
- EnumPayloadSchema (ExplosionSchema &s)
47
- : Value(&s) {}
45
+ : BitSize(static_cast <int64_t >(bits)) {}
48
46
49
- static EnumPayloadSchema withBitSize (unsigned bits) {
50
- return EnumPayloadSchema (bits);
51
- }
52
-
53
- ExplosionSchema *getSchema () const {
54
- return Value.dyn_cast <ExplosionSchema*>();
47
+ // / Report whether the schema has a fixed size.
48
+ explicit operator bool () const {
49
+ return BitSize >= 0 ;
55
50
}
56
-
51
+
57
52
// / Invoke a functor for each element type in the schema.
58
53
template <typename TypeFn /* void(llvm::Type *schemaType) */ >
59
54
void forEachType (IRGenModule &IGM, TypeFn &&fn) const {
60
- // Follow an explosion schema if we have one.
61
- if (auto *explosion = Value.dyn_cast <ExplosionSchema *>()) {
62
- for (auto &element : *explosion) {
63
- auto type = element.getScalarType ();
64
- assert (IGM.DataLayout .getTypeSizeInBits (type)
65
- == IGM.DataLayout .getTypeAllocSizeInBits (type)
66
- && " enum payload schema elements should use full alloc size" );
67
- (void ) type;
68
- fn (element.getScalarType ());
69
- }
70
- return ;
71
- }
72
-
73
- // Otherwise, chunk into pointer-sized integer values by default.
74
- unsigned bitSize = Value.get <BitSizeTy>();
75
- unsigned pointerSize = IGM.getPointerSize ().getValueInBits ();
76
-
55
+ assert (BitSize >= 0 && " payload size must not be dynamic" );
56
+
57
+ // Chunk into pointer-sized integer values.
58
+ int64_t bitSize = BitSize;
59
+ int64_t pointerSize = IGM.getPointerSize ().getValueInBits ();
60
+
77
61
while (bitSize >= pointerSize) {
78
62
fn (IGM.SizeTy );
79
63
bitSize -= pointerSize;
0 commit comments