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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
//===--- ResilientTypeInfo.h - Resilient-layout types -----------*- C++ -*-===//
//
// 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 defines a class used for implementing non-class-bound
// archetypes, and resilient structs and enums. Values of these types are
// opaque and must be manipulated through value witness function calls.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_IRGEN_RESILIENTTYPEINFO_H
#define SWIFT_IRGEN_RESILIENTTYPEINFO_H
#include "NonFixedTypeInfo.h"
#include "Outlining.h"
namespace swift {
namespace irgen {
/// An abstract CRTP class designed for types whose values are manipulated
/// indirectly through value witness functions.
///
/// We build upon WitnessSizedTypeInfo, adding the additional structure
/// that the opaque value has the same size as the underlying type with
/// no additional metadata, distinguishing this case from other uses of
/// WitnessSizedTypeInfo, which are existentials (these add conformance
/// tables) and fragile enums with generic payloads (these add tag bits).
///
/// This allows us to make use of array value witness functions, and
/// more importantly, to forward extra inhabitant information from the
/// concrete type. This ensures that enums have the correct layout
/// when accessed at different abstraction levels or from different
/// resilience scopes.
///
template <class Impl>
class ResilientTypeInfo : public WitnessSizedTypeInfo<Impl> {
protected:
ResilientTypeInfo(llvm::Type *type,
IsCopyable_t copyable,
IsABIAccessible_t abiAccessible)
: WitnessSizedTypeInfo<Impl>(type, Alignment(1),
IsNotTriviallyDestroyable, IsNotBitwiseTakable,
copyable,
abiAccessible) {}
public:
void assignWithCopy(IRGenFunction &IGF, Address dest, Address src, SILType T,
bool isOutlined) const override {
emitAssignWithCopyCall(IGF, T, dest, src);
}
void assignArrayWithCopyNoAlias(IRGenFunction &IGF, Address dest, Address src,
llvm::Value *count,
SILType T) const override {
emitAssignArrayWithCopyNoAliasCall(IGF, T, dest, src, count);
}
void assignArrayWithCopyFrontToBack(IRGenFunction &IGF, Address dest,
Address src, llvm::Value *count,
SILType T) const override {
emitAssignArrayWithCopyFrontToBackCall(IGF, T, dest, src, count);
}
void assignArrayWithCopyBackToFront(IRGenFunction &IGF, Address dest,
Address src, llvm::Value *count,
SILType T) const override {
emitAssignArrayWithCopyBackToFrontCall(IGF, T, dest, src, count);
}
void assignWithTake(IRGenFunction &IGF, Address dest, Address src, SILType T,
bool isOutlined) const override {
emitAssignWithTakeCall(IGF, T, dest, src);
}
void assignArrayWithTake(IRGenFunction &IGF, Address dest, Address src,
llvm::Value *count, SILType T) const override {
emitAssignArrayWithTakeCall(IGF, T, dest, src, count);
}
Address initializeBufferWithCopyOfBuffer(IRGenFunction &IGF,
Address dest, Address src,
SILType T) const override {
auto addr = emitInitializeBufferWithCopyOfBufferCall(IGF, T, dest, src);
return this->getAddressForPointer(addr);
}
void initializeWithCopy(IRGenFunction &IGF, Address dest, Address src,
SILType T, bool isOutlined) const override {
emitInitializeWithCopyCall(IGF, T, dest, src);
}
void initializeArrayWithCopy(IRGenFunction &IGF,
Address dest, Address src, llvm::Value *count,
SILType T) const override {
emitInitializeArrayWithCopyCall(IGF, T, dest, src, count);
}
void initializeWithTake(IRGenFunction &IGF, Address dest, Address src,
SILType T, bool isOutlined) const override {
emitInitializeWithTakeCall(IGF, T, dest, src);
}
void initializeArrayWithTakeNoAlias(IRGenFunction &IGF, Address dest,
Address src, llvm::Value *count,
SILType T) const override {
emitInitializeArrayWithTakeNoAliasCall(IGF, T, dest, src, count);
}
void initializeArrayWithTakeFrontToBack(IRGenFunction &IGF,
Address dest, Address src,
llvm::Value *count,
SILType T) const override {
emitInitializeArrayWithTakeFrontToBackCall(IGF, T, dest, src, count);
}
void initializeArrayWithTakeBackToFront(IRGenFunction &IGF,
Address dest, Address src,
llvm::Value *count,
SILType T) const override {
emitInitializeArrayWithTakeBackToFrontCall(IGF, T, dest, src, count);
}
void destroy(IRGenFunction &IGF, Address addr, SILType T,
bool isOutlined) const override {
emitDestroyCall(IGF, T, addr);
}
void destroyArray(IRGenFunction &IGF, Address addr, llvm::Value *count,
SILType T) const override {
emitDestroyArrayCall(IGF, T, addr, count);
}
bool mayHaveExtraInhabitants(IRGenModule &IGM) const override {
return true;
}
llvm::Value *getEnumTagSinglePayload(IRGenFunction &IGF,
llvm::Value *numEmptyCases,
Address enumAddr,
SILType T,
bool isOutlined) const override {
return emitGetEnumTagSinglePayloadCall(IGF, T, numEmptyCases, enumAddr);
}
void storeEnumTagSinglePayload(IRGenFunction &IGF, llvm::Value *whichCase,
llvm::Value *numEmptyCases, Address enumAddr,
SILType T, bool isOutlined) const override {
emitStoreEnumTagSinglePayloadCall(IGF, T, whichCase, numEmptyCases, enumAddr);
}
void collectMetadataForOutlining(OutliningMetadataCollector &collector,
SILType T) const override {
collector.collectTypeMetadata(T);
}
};
}
}
#endif
|