forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenHeap.h
138 lines (115 loc) · 4.42 KB
/
GenHeap.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
//===--- GenHeap.h - Heap-object layout and management ----------*- 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 https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file defines some routines that are useful for emitting
// operations on heap objects and their metadata.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_GENHEAP_H
#define SWIFT_IRGEN_GENHEAP_H
#include "NecessaryBindings.h"
#include "StructLayout.h"
namespace llvm {
class Constant;
template <class T> class SmallVectorImpl;
}
namespace swift {
namespace irgen {
class Address;
class OwnedAddress;
/// A heap layout is the result of laying out a complete structure for
/// heap-allocation.
class HeapLayout : public StructLayout {
SmallVector<SILType, 8> ElementTypes;
NecessaryBindings Bindings;
mutable llvm::Constant *privateMetadata = nullptr;
public:
HeapLayout(IRGenModule &IGM, LayoutStrategy strategy,
ArrayRef<SILType> elementTypes,
ArrayRef<const TypeInfo *> elementTypeInfos,
llvm::StructType *typeToFill = 0,
NecessaryBindings &&bindings = {});
/// True if the heap object carries type bindings.
///
/// If true, the first element of the heap layout will be the type metadata
/// buffer.
bool hasBindings() const {
return !Bindings.empty();
}
const NecessaryBindings &getBindings() const {
return Bindings;
}
/// Get the types of the elements.
ArrayRef<SILType> getElementTypes() const {
return ElementTypes;
}
/// Build a size function for this layout.
llvm::Constant *createSizeFn(IRGenModule &IGM) const;
/// As a convenience, build a metadata object with internal linkage
/// consisting solely of the standard heap metadata.
llvm::Constant *getPrivateMetadata(IRGenModule &IGM,
llvm::Constant *captureDescriptor) const;
};
class HeapNonFixedOffsets : public NonFixedOffsetsImpl {
SmallVector<llvm::Value *, 1> Offsets;
llvm::Value *TotalSize;
llvm::Value *TotalAlignMask;
public:
HeapNonFixedOffsets(IRGenFunction &IGF, const HeapLayout &layout);
llvm::Value *getOffsetForIndex(IRGenFunction &IGF, unsigned index) override {
auto result = Offsets[index];
assert(result != nullptr
&& "fixed-layout field doesn't need NonFixedOffsets");
return result;
}
// The total size of the heap object.
llvm::Value *getSize() const {
return TotalSize;
}
// The total alignment of the heap object.
llvm::Value *getAlignMask() const {
return TotalAlignMask;
}
};
/// Emit a heap object deallocation.
void emitDeallocateHeapObject(IRGenFunction &IGF,
llvm::Value *object,
llvm::Value *size,
llvm::Value *alignMask);
/// Emit a class instance deallocation.
void emitDeallocateClassInstance(IRGenFunction &IGF,
llvm::Value *object,
llvm::Value *size,
llvm::Value *alignMask);
/// Emit a partial class instance deallocation from a failing constructor.
void emitDeallocatePartialClassInstance(IRGenFunction &IGF,
llvm::Value *object,
llvm::Value *metadata,
llvm::Value *size,
llvm::Value *alignMask);
/// Allocate a boxed value.
///
/// The interface type is required for emitting reflection metadata.
OwnedAddress
emitAllocateBox(IRGenFunction &IGF,
CanSILBoxType boxType,
CanSILBoxType boxInterfaceType,
const llvm::Twine &name);
/// Deallocate a box whose value is uninitialized.
void emitDeallocateBox(IRGenFunction &IGF, llvm::Value *box,
CanSILBoxType boxType);
/// Project the address of the value inside a box.
Address emitProjectBox(IRGenFunction &IGF, llvm::Value *box,
CanSILBoxType boxType);
} // end namespace irgen
} // end namespace swift
#endif