|
| 1 | +//===--- ClassTypeInfo.h - The layout info for class types. -----*- C++ -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// |
| 13 | +// This file contains layout information for class types. |
| 14 | +// |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +#ifndef SWIFT_IRGEN_CLASSTYPEINFO_H |
| 18 | +#define SWIFT_IRGEN_CLASSTYPEINFO_H |
| 19 | + |
| 20 | +#include "ClassLayout.h" |
| 21 | +#include "HeapTypeInfo.h" |
| 22 | + |
| 23 | +namespace swift { |
| 24 | +namespace irgen { |
| 25 | + |
| 26 | +/// Layout information for class types. |
| 27 | +class ClassTypeInfo : public HeapTypeInfo<ClassTypeInfo> { |
| 28 | + ClassDecl *TheClass; |
| 29 | + |
| 30 | + // The resilient layout of the class, without making any assumptions |
| 31 | + // that violate resilience boundaries. This is used to allocate |
| 32 | + // and deallocate instances of the class, and to access fields. |
| 33 | + mutable Optional<ClassLayout> ResilientLayout; |
| 34 | + |
| 35 | + // A completely fragile layout, used for metadata emission. |
| 36 | + mutable Optional<ClassLayout> FragileLayout; |
| 37 | + |
| 38 | + /// Can we use swift reference-counting, or do we have to use |
| 39 | + /// objc_retain/release? |
| 40 | + const ReferenceCounting Refcount; |
| 41 | + |
| 42 | + ClassLayout generateLayout(IRGenModule &IGM, SILType classType, |
| 43 | + bool forBackwardDeployment) const; |
| 44 | + |
| 45 | +public: |
| 46 | + ClassTypeInfo(llvm::PointerType *irType, Size size, SpareBitVector spareBits, |
| 47 | + Alignment align, ClassDecl *theClass, |
| 48 | + ReferenceCounting refcount) |
| 49 | + : HeapTypeInfo(irType, size, std::move(spareBits), align), |
| 50 | + TheClass(theClass), Refcount(refcount) {} |
| 51 | + |
| 52 | + ReferenceCounting getReferenceCounting() const { return Refcount; } |
| 53 | + |
| 54 | + ClassDecl *getClass() const { return TheClass; } |
| 55 | + |
| 56 | + const ClassLayout &getClassLayout(IRGenModule &IGM, SILType type, |
| 57 | + bool forBackwardDeployment) const; |
| 58 | + |
| 59 | + StructLayout *createLayoutWithTailElems(IRGenModule &IGM, SILType classType, |
| 60 | + ArrayRef<SILType> tailTypes) const; |
| 61 | +}; |
| 62 | + |
| 63 | +} // namespace irgen |
| 64 | +} // namespace swift |
| 65 | + |
| 66 | +#endif |
0 commit comments