Files
swift-mirror/stdlib/public/runtime/AutoDiffSupport.cpp
Dario Rexin a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00

79 lines
2.3 KiB
C++

//===--- AutoDiffSupport.cpp ----------------------------------*- C++ -*---===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2019 - 2020 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
//
//===----------------------------------------------------------------------===//
#include "AutoDiffSupport.h"
#include "swift/ABI/Metadata.h"
#include "swift/Runtime/HeapObject.h"
#include <new>
using namespace swift;
using namespace llvm;
SWIFT_CC(swift)
static void destroyLinearMapContext(SWIFT_CONTEXT HeapObject *obj) {
static_cast<AutoDiffLinearMapContext *>(obj)->~AutoDiffLinearMapContext();
free(obj);
}
/// Heap metadata for a linear map context.
static FullMetadata<HeapMetadata> linearMapContextHeapMetadata = {
{
{
/*type layout*/ nullptr,
},
{
&destroyLinearMapContext
},
{
/*value witness table*/ nullptr
}
},
{
MetadataKind::Opaque
}
};
AutoDiffLinearMapContext::AutoDiffLinearMapContext()
: HeapObject(&linearMapContextHeapMetadata) {
}
void *AutoDiffLinearMapContext::projectTopLevelSubcontext() const {
auto offset = alignTo(
sizeof(AutoDiffLinearMapContext), alignof(AutoDiffLinearMapContext));
return const_cast<uint8_t *>(
reinterpret_cast<const uint8_t *>(this) + offset);
}
void *AutoDiffLinearMapContext::allocate(size_t size) {
return allocator.Allocate(size, alignof(AutoDiffLinearMapContext));
}
AutoDiffLinearMapContext *swift::swift_autoDiffCreateLinearMapContext(
size_t topLevelLinearMapStructSize) {
auto allocationSize = alignTo(
sizeof(AutoDiffLinearMapContext), alignof(AutoDiffLinearMapContext))
+ topLevelLinearMapStructSize;
auto *buffer = (AutoDiffLinearMapContext *)malloc(allocationSize);
return ::new (buffer) AutoDiffLinearMapContext;
}
void *swift::swift_autoDiffProjectTopLevelSubcontext(
AutoDiffLinearMapContext *allocator) {
return allocator->projectTopLevelSubcontext();
}
void *swift::swift_autoDiffAllocateSubcontext(
AutoDiffLinearMapContext *allocator, size_t size) {
return allocator->allocate(size);
}