Files
swift-mirror/lib/IRGen/ClassLayout.cpp
Slava Pestov 98b5eafcca IRGen: Split up doesClassMetadataRequireDynamicInitialization() into two predicates
- doesClassMetadataRequireRelocation() -- returns true if we must
  allocate new metadata at runtime and fill it in, because the class
  has multiple instantiations (generic case) or because the total size
  of the metadata is not known at compile time (resilient ancestry).

- doesClassMetadataRequireInitialization() -- weaker condition than
  the above. It's true if the metadata must be relocated, but it is
  also true if the metadata has otherwise fixed size but must be
  filled in dynamically. This occurs if the class has generic
  ancestry but is itself not generic, or if the class has
  resiliently-sized fields, or missing members.

For now, we don't actually care about the distinciton anywhere,
because we cannot do in-place initialization of class metadata yet.
2018-08-20 14:24:19 -07:00

59 lines
2.0 KiB
C++

//===--- ClassLayout.cpp - Layout of class instances ---------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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 implements algorithms for laying out class instances.
//
//===----------------------------------------------------------------------===//
#include "swift/AST/ASTContext.h"
#include "IRGenFunction.h"
#include "IRGenModule.h"
#include "ClassLayout.h"
#include "TypeInfo.h"
using namespace swift;
using namespace irgen;
ClassLayout::ClassLayout(const StructLayoutBuilder &builder,
bool isFixedSize,
bool metadataRequiresInitialization,
bool metadataRequiresRelocation,
llvm::Type *classTy,
ArrayRef<VarDecl *> allStoredProps,
ArrayRef<FieldAccess> allFieldAccesses,
ArrayRef<ElementLayout> allElements)
: MinimumAlign(builder.getAlignment()),
MinimumSize(builder.getSize()),
IsFixedLayout(builder.isFixedLayout()),
IsFixedSize(isFixedSize),
MetadataRequiresInitialization(metadataRequiresInitialization),
MetadataRequiresRelocation(metadataRequiresRelocation),
Ty(classTy),
AllStoredProperties(allStoredProps),
AllFieldAccesses(allFieldAccesses),
AllElements(allElements) { }
Size ClassLayout::getInstanceStart() const {
if (AllElements.empty())
return getSize();
auto element = AllElements[0];
if (element.getKind() == ElementLayout::Kind::Fixed ||
element.getKind() == ElementLayout::Kind::Empty) {
// FIXME: assumes layout is always sequential!
return element.getByteOffset();
}
return Size(0);
}