-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathGenExistential.h
153 lines (129 loc) · 6.9 KB
/
GenExistential.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//===--- GenExistential.h - IR generation for existentials ------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file provides the private interface to the existential emission code.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_GENEXISTENTIAL_H
#define SWIFT_IRGEN_GENEXISTENTIAL_H
#include "Address.h"
#include "swift/Basic/LLVM.h"
#include "swift/AST/Types.h"
namespace llvm {
class Value;
}
namespace swift {
class ProtocolConformanceRef;
class SILType;
namespace irgen {
class Address;
class Explosion;
class IRGenFunction;
/// Emit the metadata and witness table initialization for an allocated
/// opaque existential container.
Address emitOpaqueExistentialContainerInit(IRGenFunction &IGF,
Address dest,
SILType destType,
CanType formalSrcType,
SILType loweredSrcType,
ArrayRef<ProtocolConformanceRef> conformances);
/// Emit an existential metatype container from a metatype value
/// as an explosion.
void emitExistentialMetatypeContainer(IRGenFunction &IGF,
Explosion &out,
SILType outType,
llvm::Value *metatype,
SILType metatypeType,
ArrayRef<ProtocolConformanceRef> conformances);
/// Emit a class existential container from a class instance value
/// as an explosion.
void emitClassExistentialContainer(IRGenFunction &IGF,
Explosion &out,
SILType outType,
llvm::Value *instance,
CanType instanceFormalType,
SILType instanceLoweredType,
ArrayRef<ProtocolConformanceRef> conformances);
/// Allocate a boxed existential container with uninitialized space to hold a
/// value of a given type.
OwnedAddress emitBoxedExistentialContainerAllocation(IRGenFunction &IGF,
SILType destType,
CanType formalSrcType,
ArrayRef<ProtocolConformanceRef> conformances);
/// "Deinitialize" an existential container whose contained value is allocated
/// but uninitialized, by deallocating the buffer owned by the container if any.
void emitOpaqueExistentialContainerDeinit(IRGenFunction &IGF,
Address container,
SILType type);
/// Deallocate a boxed existential container with uninitialized space to hold
/// a value of a given type.
void emitBoxedExistentialContainerDeallocation(IRGenFunction &IGF,
Explosion &container,
SILType containerType,
CanType valueType);
/// Emit a projection from an existential container address to the address
/// of its concrete value buffer.
///
/// \param openedArchetype If non-null, the archetype that will capture the
/// metadata and witness tables produced by projecting the archetype.
Address emitOpaqueExistentialProjection(IRGenFunction &IGF,
Address base,
SILType baseTy,
CanArchetypeType openedArchetype);
/// Extract the instance pointer from a class existential value.
///
/// \param openedArchetype If non-null, the archetype that will capture the
/// metadata and witness tables produced by projecting the archetype.
llvm::Value *emitClassExistentialProjection(IRGenFunction &IGF,
Explosion &base,
SILType baseTy,
CanArchetypeType openedArchetype);
/// Extract the metatype pointer from an existential metatype value.
///
/// \param openedTy If non-null, a metatype of the archetype that
/// will capture the metadata and witness tables
llvm::Value *emitExistentialMetatypeProjection(IRGenFunction &IGF,
Explosion &base,
SILType baseTy,
CanType openedTy);
/// Project the address of the value inside a boxed existential container.
ContainedAddress emitBoxedExistentialProjection(IRGenFunction &IGF,
Explosion &base,
SILType baseTy,
CanType projectedType);
/// Project the address of the value inside a boxed existential container,
/// and open an archetype to its contained type.
Address emitOpenExistentialBox(IRGenFunction &IGF,
Explosion &base,
SILType baseTy,
CanArchetypeType openedArchetype);
/// Emit the existential metatype of an opaque existential value.
void emitMetatypeOfOpaqueExistential(IRGenFunction &IGF, Address addr,
SILType type, Explosion &out);
/// Emit the existential metatype of a class existential value.
void emitMetatypeOfClassExistential(IRGenFunction &IGF,
Explosion &value, SILType metatypeType,
SILType existentialType, Explosion &out);
/// Emit the existential metatype of a boxed existential value.
void emitMetatypeOfBoxedExistential(IRGenFunction &IGF, Explosion &value,
SILType type, Explosion &out);
/// Emit the existential metatype of a metatype.
void emitMetatypeOfMetatype(IRGenFunction &IGF, Explosion &value,
SILType existentialType, Explosion &out);
std::pair<Address, llvm::Value*>
emitIndirectExistentialProjectionWithMetadata(IRGenFunction &IGF,
Address base,
SILType baseTy,
CanType openedArchetype);
} // end namespace irgen
} // end namespace swift
#endif