diff --git a/include/swift/AST/ExtInfo.h b/include/swift/AST/ExtInfo.h index bb38eb1a6dc..d690a0bfacf 100644 --- a/include/swift/AST/ExtInfo.h +++ b/include/swift/AST/ExtInfo.h @@ -549,7 +549,7 @@ public: : ASTExtInfoBuilder(Representation::Swift, false, false, Type(), DifferentiabilityKind::NonDifferentiable, nullptr, FunctionTypeIsolation::forNonIsolated(), - std::nullopt /* LifetimeDependenceInfo */, + {} /* LifetimeDependenceInfo */, false /*sendingResult*/) {} // Constructor for polymorphic type. @@ -557,7 +557,7 @@ public: : ASTExtInfoBuilder(rep, false, throws, thrownError, DifferentiabilityKind::NonDifferentiable, nullptr, FunctionTypeIsolation::forNonIsolated(), - std::nullopt /* LifetimeDependenceInfo */, + {} /* LifetimeDependenceInfo */, false /*sendingResult*/) {} // Constructor with no defaults. @@ -1047,7 +1047,7 @@ public: makeBits(SILFunctionTypeRepresentation::Thick, false, false, false, false, false, SILFunctionTypeIsolation::forUnknown(), DifferentiabilityKind::NonDifferentiable), - ClangTypeInfo(nullptr), /*LifetimeDependenceInfo*/ std::nullopt) {} + ClangTypeInfo(nullptr), /*LifetimeDependenceInfo*/ {}) {} SILExtInfoBuilder(Representation rep, bool isPseudogeneric, bool isNoEscape, bool isSendable, bool isAsync, bool isUnimplementable, diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index db2a1e57bf0..d86e7b87dd9 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -4018,7 +4018,7 @@ public: ArrayRef getLifetimeDependencies() const { if (!hasLifetimeDependencies()) - return std::nullopt; + return {}; return {getTrailingObjects(), getNumLifetimeDependencies()}; } @@ -4188,7 +4188,7 @@ public: ArrayRef getLifetimeDependencies() const { if (!hasLifetimeDependencies()) - return std::nullopt; + return {}; return {getTrailingObjects(), getNumLifetimeDependencies()}; } @@ -5680,7 +5680,7 @@ public: // relative to the original FunctionType. ArrayRef getLifetimeDependencies() const { if (!hasLifetimeDependencies()) - return std::nullopt; + return {}; return {getTrailingObjects(), NumLifetimeDependencies}; } diff --git a/include/swift/Basic/TaskQueue.h b/include/swift/Basic/TaskQueue.h index 758815601be..f40af641690 100644 --- a/include/swift/Basic/TaskQueue.h +++ b/include/swift/Basic/TaskQueue.h @@ -205,8 +205,8 @@ public: /// \param Context an optional context which will be associated with the task /// \param SeparateErrors Controls whether error output is reported separately virtual void addTask(const char *ExecPath, ArrayRef Args, - ArrayRef Env = std::nullopt, - void *Context = nullptr, bool SeparateErrors = false); + ArrayRef Env = {}, void *Context = nullptr, + bool SeparateErrors = false); /// Synchronously executes the tasks in the TaskQueue. /// @@ -240,8 +240,8 @@ class DummyTaskQueue : public TaskQueue { bool SeparateErrors; DummyTask(const char *ExecPath, ArrayRef Args, - ArrayRef Env = std::nullopt, - void *Context = nullptr, bool SeparateErrors = false) + ArrayRef Env = {}, void *Context = nullptr, + bool SeparateErrors = false) : ExecPath(ExecPath), Args(Args), Env(Env), Context(Context), SeparateErrors(SeparateErrors) {} }; @@ -254,8 +254,8 @@ public: virtual ~DummyTaskQueue(); void addTask(const char *ExecPath, ArrayRef Args, - ArrayRef Env = std::nullopt, - void *Context = nullptr, bool SeparateErrors = false) override; + ArrayRef Env = {}, void *Context = nullptr, + bool SeparateErrors = false) override; bool execute(TaskBeganCallback Began = TaskBeganCallback(), diff --git a/include/swift/Driver/Action.h b/include/swift/Driver/Action.h index 16795530100..4fd4350136f 100644 --- a/include/swift/Driver/Action.h +++ b/include/swift/Driver/Action.h @@ -134,7 +134,7 @@ private: public: CompileJobAction(file_types::ID OutputType) - : JobAction(Action::Kind::CompileJob, std::nullopt, OutputType) {} + : JobAction(Action::Kind::CompileJob, {}, OutputType) {} CompileJobAction(Action *Input, file_types::ID OutputType) : JobAction(Action::Kind::CompileJob, Input, OutputType) {} @@ -169,8 +169,7 @@ private: public: explicit InterpretJobAction() - : JobAction(Action::Kind::InterpretJob, std::nullopt, - file_types::TY_Nothing) {} + : JobAction(Action::Kind::InterpretJob, {}, file_types::TY_Nothing) {} static bool classof(const Action *A) { return A->getKind() == Action::Kind::InterpretJob; @@ -209,7 +208,7 @@ private: Mode RequestedMode; public: REPLJobAction(Mode mode) - : JobAction(Action::Kind::REPLJob, std::nullopt, file_types::TY_Nothing), + : JobAction(Action::Kind::REPLJob, {}, file_types::TY_Nothing), RequestedMode(mode) {} Mode getRequestedMode() const { return RequestedMode; } diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def index 474b6f55060..a4d9e06c97d 100644 --- a/include/swift/Runtime/RuntimeFunctions.def +++ b/include/swift/Runtime/RuntimeFunctions.def @@ -175,7 +175,7 @@ FUNCTION(SlowDealloc, Swift, swift_slowDealloc, C_CC, AlwaysAvailable, // void swift_willThrow(error *ptr); FUNCTION(WillThrow, Swift, swift_willThrow, SwiftCC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(Int8PtrTy, ErrorPtrTy->getPointerTo()), + ARGS(Int8PtrTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) @@ -759,10 +759,7 @@ FUNCTION(ArrayDestroy, Swift, swift_arrayDestroy, C_CC, AlwaysAvailable, FUNCTION(GetFunctionMetadata, Swift, swift_getFunctionTypeMetadata, C_CC, AlwaysAvailable, RETURNS(TypeMetadataPtrTy), - ARGS(SizeTy, - TypeMetadataPtrTy->getPointerTo(0), - Int32Ty->getPointerTo(0), - TypeMetadataPtrTy), + ARGS(SizeTy, PtrTy, PtrTy, TypeMetadataPtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), MEMEFFECTS(ReadOnly)) @@ -777,11 +774,7 @@ FUNCTION(GetFunctionMetadataDifferentiable, Swift, swift_getFunctionTypeMetadataDifferentiable, C_CC, AlwaysAvailable, RETURNS(TypeMetadataPtrTy), - ARGS(SizeTy, - SizeTy, - TypeMetadataPtrTy->getPointerTo(0), - Int32Ty->getPointerTo(0), - TypeMetadataPtrTy), + ARGS(SizeTy, SizeTy, PtrTy, PtrTy, TypeMetadataPtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), MEMEFFECTS(ReadOnly)) @@ -801,8 +794,8 @@ FUNCTION(GetFunctionMetadataExtended, RETURNS(TypeMetadataPtrTy), ARGS(SizeTy, SizeTy, - TypeMetadataPtrTy->getPointerTo(0), - Int32Ty->getPointerTo(0), + PtrTy, + PtrTy, TypeMetadataPtrTy, TypeMetadataPtrTy, Int32Ty, @@ -824,8 +817,8 @@ FUNCTION(GetFunctionMetadataGlobalActor, RETURNS(TypeMetadataPtrTy), ARGS(SizeTy, SizeTy, - TypeMetadataPtrTy->getPointerTo(0), - Int32Ty->getPointerTo(0), + PtrTy, + PtrTy, TypeMetadataPtrTy, TypeMetadataPtrTy), ATTRS(NoUnwind), @@ -845,8 +838,8 @@ FUNCTION(GetFunctionMetadataGlobalActorBackDeploy, RETURNS(TypeMetadataPtrTy), ARGS(SizeTy, SizeTy, - TypeMetadataPtrTy->getPointerTo(0), - Int32Ty->getPointerTo(0), + PtrTy, + PtrTy, TypeMetadataPtrTy, TypeMetadataPtrTy), ATTRS(NoUnwind), @@ -963,7 +956,7 @@ FUNCTION(GetCanonicalPrespecializedGenericMetadata, Swift, swift_getCanonicalPrespecializedGenericMetadata, SwiftCC, GetCanonicalPrespecializedGenericMetadataAvailability, RETURNS(TypeMetadataResponseTy), - ARGS(SizeTy, Int8PtrTy, TypeContextDescriptorPtrTy, OnceTy->getPointerTo()), + ARGS(SizeTy, Int8PtrTy, TypeContextDescriptorPtrTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), MEMEFFECTS(ReadOnly)) @@ -1108,22 +1101,14 @@ FUNCTION(GetWitnessTableRelative, Swift, swift_getWitnessTableRelative, C_CC, Al FUNCTION(GetAssociatedTypeWitness, Swift, swift_getAssociatedTypeWitness, SwiftCC, AlwaysAvailable, RETURNS(TypeMetadataResponseTy), - ARGS(SizeTy, - WitnessTablePtrTy, - TypeMetadataPtrTy, - ProtocolRequirementStructTy->getPointerTo(), - ProtocolRequirementStructTy->getPointerTo()), + ARGS(SizeTy, WitnessTablePtrTy, TypeMetadataPtrTy, PtrTy, PtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::MetaData), // ? MEMEFFECTS(ReadNone)) FUNCTION(GetAssociatedTypeWitnessRelative, Swift, swift_getAssociatedTypeWitnessRelative, SwiftCC, AlwaysAvailable, RETURNS(TypeMetadataResponseTy), - ARGS(SizeTy, - WitnessTablePtrTy, - TypeMetadataPtrTy, - ProtocolRequirementStructTy->getPointerTo(), - ProtocolRequirementStructTy->getPointerTo()), + ARGS(SizeTy, WitnessTablePtrTy, TypeMetadataPtrTy, PtrTy, PtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::MetaData), // ? MEMEFFECTS(ReadNone)) @@ -1141,8 +1126,8 @@ FUNCTION(GetAssociatedConformanceWitness, ARGS(WitnessTablePtrTy, TypeMetadataPtrTy, TypeMetadataPtrTy, - ProtocolRequirementStructTy->getPointerTo(), - ProtocolRequirementStructTy->getPointerTo()), + PtrTy, + PtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::MetaData), // ? MEMEFFECTS(ReadNone)) @@ -1152,8 +1137,8 @@ FUNCTION(GetAssociatedConformanceWitnessRelative, ARGS(WitnessTablePtrTy, TypeMetadataPtrTy, TypeMetadataPtrTy, - ProtocolRequirementStructTy->getPointerTo(), - ProtocolRequirementStructTy->getPointerTo()), + PtrTy, + PtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::MetaData), // ? MEMEFFECTS(ReadNone)) @@ -1248,8 +1233,7 @@ FUNCTION(GetObjCClassFromObject, Swift, swift_getObjCClassFromObject, // value_witness_table_t *proposed); FUNCTION(GetTupleMetadata, Swift, swift_getTupleTypeMetadata, SwiftCC, AlwaysAvailable, RETURNS(TypeMetadataResponseTy), - ARGS(SizeTy, SizeTy, TypeMetadataPtrTy->getPointerTo(0), - Int8PtrTy, WitnessTablePtrTy), + ARGS(SizeTy, SizeTy, PtrTy, Int8PtrTy, WitnessTablePtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::MetaData), MEMEFFECTS(ReadOnly)) @@ -1285,8 +1269,7 @@ FUNCTION(GetTupleMetadata3, Swift, swift_getTupleTypeMetadata3, SwiftCC, AlwaysA // const TypeLayout * const *elts); FUNCTION(GetTupleLayout, Swift, swift_getTupleTypeLayout, SwiftCC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(FullTypeLayoutTy->getPointerTo(0), Int32Ty->getPointerTo(0), - SizeTy, Int8PtrPtrTy->getPointerTo(0)), + ARGS(PtrTy, PtrTy, SizeTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) @@ -1296,7 +1279,7 @@ FUNCTION(GetTupleLayout, Swift, swift_getTupleTypeLayout, SwiftCC, AlwaysAvailab // const TypeLayout *elt1); FUNCTION(GetTupleLayout2, Swift, swift_getTupleTypeLayout2, SwiftCC, AlwaysAvailable, RETURNS(SizeTy), - ARGS(FullTypeLayoutTy->getPointerTo(0), Int8PtrPtrTy, Int8PtrPtrTy), + ARGS(PtrTy, Int8PtrPtrTy, Int8PtrPtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) @@ -1307,8 +1290,7 @@ FUNCTION(GetTupleLayout2, Swift, swift_getTupleTypeLayout2, SwiftCC, AlwaysAvail // const TypeLayout *elt2); FUNCTION(GetTupleLayout3, Swift, swift_getTupleTypeLayout3, SwiftCC, AlwaysAvailable, RETURNS(OffsetPairTy), - ARGS(FullTypeLayoutTy->getPointerTo(0), - Int8PtrPtrTy, Int8PtrPtrTy, Int8PtrPtrTy), + ARGS(PtrTy, Int8PtrPtrTy, Int8PtrPtrTy, Int8PtrPtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) @@ -1335,8 +1317,7 @@ FUNCTION(GetExistentialMetadata, Swift, swift_getExistentialTypeMetadata, C_CC, AlwaysAvailable, RETURNS(TypeMetadataPtrTy), - ARGS(Int1Ty, TypeMetadataPtrTy, SizeTy, - ProtocolDescriptorRefTy->getPointerTo()), + ARGS(Int1Ty, TypeMetadataPtrTy, SizeTy, PtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::MetaData), // ? MEMEFFECTS(ReadOnly)) @@ -1396,9 +1377,7 @@ FUNCTION(RelocateClassMetadata, FUNCTION(InitClassMetadata, Swift, swift_initClassMetadata, C_CC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, - Int8PtrPtrTy->getPointerTo(), - SizeTy->getPointerTo()), + ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, PtrTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -1411,9 +1390,7 @@ FUNCTION(InitClassMetadata, FUNCTION(UpdateClassMetadata, Swift, swift_updateClassMetadata, C_CC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, - Int8PtrPtrTy->getPointerTo(), - SizeTy->getPointerTo()), + ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, PtrTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -1426,9 +1403,7 @@ FUNCTION(UpdateClassMetadata, FUNCTION(InitClassMetadata2, Swift, swift_initClassMetadata2, SwiftCC, AlwaysAvailable, RETURNS(TypeMetadataDependencyTy), - ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, - Int8PtrPtrTy->getPointerTo(), - SizeTy->getPointerTo()), + ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, PtrTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -1441,9 +1416,7 @@ FUNCTION(InitClassMetadata2, FUNCTION(UpdateClassMetadata2, Swift, swift_updateClassMetadata2, SwiftCC, AlwaysAvailable, RETURNS(TypeMetadataDependencyTy), - ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, - Int8PtrPtrTy->getPointerTo(), - SizeTy->getPointerTo()), + ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, PtrTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -1456,7 +1429,7 @@ FUNCTION(UpdateClassMetadata2, FUNCTION(UpdatePureObjCClassMetadata, Swift, swift_updatePureObjCClassMetadata, SwiftCC, AlwaysAvailable, RETURNS(ObjCClassPtrTy), - ARGS(ObjCClassPtrTy, SizeTy, SizeTy, Int8PtrPtrTy->getPointerTo()), + ARGS(ObjCClassPtrTy, SizeTy, SizeTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -1467,9 +1440,7 @@ FUNCTION(UpdatePureObjCClassMetadata, FUNCTION(LookUpClassMethod, Swift, swift_lookUpClassMethod, C_CC, AlwaysAvailable, RETURNS(Int8PtrTy), - ARGS(TypeMetadataPtrTy, - MethodDescriptorStructTy->getPointerTo(), - TypeContextDescriptorPtrTy), + ARGS(TypeMetadataPtrTy, PtrTy, TypeContextDescriptorPtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) @@ -1482,9 +1453,7 @@ FUNCTION(LookUpClassMethod, FUNCTION(InitStructMetadata, Swift, swift_initStructMetadata, C_CC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, - Int8PtrPtrTy->getPointerTo(0), - Int32Ty->getPointerTo()), + ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, PtrTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -1498,10 +1467,7 @@ FUNCTION(InitStructMetadata, FUNCTION(InitStructMetadataWithLayoutString, Swift, swift_cvw_initStructMetadataWithLayoutString, C_CC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, - Int8PtrPtrTy->getPointerTo(0), - Int8PtrTy, - Int32Ty->getPointerTo()), + ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, PtrTy, Int8PtrTy, PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -1564,7 +1530,7 @@ FUNCTION(InitEnumMetadataMultiPayload, Swift, swift_initEnumMetadataMultiPayload, C_CC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, Int8PtrPtrTy->getPointerTo(0)), + ARGS(TypeMetadataPtrTy, SizeTy, SizeTy, PtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -1603,10 +1569,7 @@ FUNCTION(GetEnumTagSinglePayloadGeneric, Swift, swift_getEnumTagSinglePayloadGeneric, SwiftCC, AlwaysAvailable, RETURNS(Int32Ty), - ARGS(OpaquePtrTy, Int32Ty, TypeMetadataPtrTy, - llvm::FunctionType::get(Int32Ty, {OpaquePtrTy, Int32Ty, - TypeMetadataPtrTy}, - false)->getPointerTo()), + ARGS(OpaquePtrTy, Int32Ty, TypeMetadataPtrTy, PtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::NoEffect), MEMEFFECTS(ReadOnly)) @@ -1624,10 +1587,7 @@ FUNCTION(StoreEnumTagSinglePayloadGeneric, Swift, swift_storeEnumTagSinglePayloadGeneric, SwiftCC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(OpaquePtrTy, Int32Ty, Int32Ty, TypeMetadataPtrTy, - llvm::FunctionType::get(VoidTy, {OpaquePtrTy, Int32Ty, Int32Ty, - TypeMetadataPtrTy}, - false)->getPointerTo()), + ARGS(OpaquePtrTy, Int32Ty, Int32Ty, TypeMetadataPtrTy, PtrTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) @@ -1901,7 +1861,7 @@ FUNCTION(IsOptionalType, // void *context); FUNCTION(Once, Swift, swift_once, C_CC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(OnceTy->getPointerTo(), Int8PtrTy, Int8PtrTy), + ARGS(PtrTy, Int8PtrTy, Int8PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::Locking), UNKNOWN_MEMEFFECTS) @@ -1936,7 +1896,7 @@ FUNCTION(RegisterTypeMetadataRecords, // void swift_beginAccess(void *pointer, ValueBuffer *scratch, size_t flags); FUNCTION(BeginAccess, Swift, swift_beginAccess, C_CC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(Int8PtrTy, getFixedBufferTy()->getPointerTo(), SizeTy, Int8PtrTy), + ARGS(Int8PtrTy, PtrTy, SizeTy, Int8PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::ExclusivityChecking), UNKNOWN_MEMEFFECTS) @@ -1944,7 +1904,7 @@ FUNCTION(BeginAccess, Swift, swift_beginAccess, C_CC, AlwaysAvailable, // void swift_endAccess(ValueBuffer *scratch); FUNCTION(EndAccess, Swift, swift_endAccess, C_CC, AlwaysAvailable, RETURNS(VoidTy), - ARGS(getFixedBufferTy()->getPointerTo()), + ARGS(PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::ExclusivityChecking), UNKNOWN_MEMEFFECTS) @@ -1952,7 +1912,7 @@ FUNCTION(EndAccess, Swift, swift_endAccess, C_CC, AlwaysAvailable, FUNCTION(GetOrigOfReplaceable, Swift, swift_getOrigOfReplaceable, C_CC, DynamicReplacementAvailability, RETURNS(FunctionPtrTy), - ARGS(FunctionPtrTy->getPointerTo()), + ARGS(PtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) @@ -1960,7 +1920,7 @@ FUNCTION(GetOrigOfReplaceable, Swift, swift_getOrigOfReplaceable, C_CC, FUNCTION(GetReplacement, Swift, swift_getFunctionReplacement, C_CC, DynamicReplacementAvailability, RETURNS(FunctionPtrTy), - ARGS(FunctionPtrTy->getPointerTo(), FunctionPtrTy), + ARGS(PtrTy, FunctionPtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::NoEffect), UNKNOWN_MEMEFFECTS) @@ -2240,14 +2200,14 @@ FUNCTION(VerifyTypeLayoutAttribute, Swift, _swift_debug_verifyTypeLayoutAttribut // float swift_intToFloat32(const size_t *data, IntegerLiteralFlags flags); FUNCTION(IntToFloat32, Swift, swift_intToFloat32, SwiftCC, AlwaysAvailable, RETURNS(FloatTy), - ARGS(SizeTy->getPointerTo(), SizeTy), + ARGS(PtrTy, SizeTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::NoEffect), MEMEFFECTS(ReadOnly)) FUNCTION(IntToFloat64, Swift, swift_intToFloat64, SwiftCC, AlwaysAvailable, RETURNS(DoubleTy), - ARGS(SizeTy->getPointerTo(), SizeTy), + ARGS(PtrTy, SizeTy), ATTRS(NoUnwind, WillReturn), EFFECT(RuntimeEffect::NoEffect), MEMEFFECTS(ReadOnly)) @@ -2783,9 +2743,7 @@ FUNCTION(GenericInitializeBufferWithCopyOfBuffer, Swift, swift_cvw_initializeBufferWithCopyOfBuffer, C_CC, AlwaysAvailable, RETURNS(Int8PtrTy), - ARGS(getFixedBufferTy()->getPointerTo(), - getFixedBufferTy()->getPointerTo(), - TypeMetadataPtrTy), + ARGS(PtrTy, PtrTy, TypeMetadataPtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::RefCounting), UNKNOWN_MEMEFFECTS) @@ -2845,9 +2803,7 @@ FUNCTION(GenericInitializeBufferWithCopyOfBufferMultiPayloadEnumFN, Swift, swift_cvw_initializeBufferWithCopyOfBufferMultiPayloadEnumFN, C_CC, AlwaysAvailable, RETURNS(Int8PtrTy), - ARGS(getFixedBufferTy()->getPointerTo(), - getFixedBufferTy()->getPointerTo(), - TypeMetadataPtrTy), + ARGS(PtrTy, PtrTy, TypeMetadataPtrTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::RefCounting), UNKNOWN_MEMEFFECTS) @@ -2974,7 +2930,7 @@ FUNCTION(InitRawStructMetadata, Swift, swift_initRawStructMetadata, C_CC, InitRawStructMetadataAvailability, RETURNS(VoidTy), - ARGS(TypeMetadataPtrTy, SizeTy, Int8PtrPtrTy->getPointerTo(0), Int32Ty), + ARGS(TypeMetadataPtrTy, SizeTy, PtrTy, Int32Ty), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), UNKNOWN_MEMEFFECTS) @@ -2988,7 +2944,7 @@ FUNCTION(InitRawStructMetadata2, Swift, swift_initRawStructMetadata2, C_CC, InitRawStructMetadata2Availability, RETURNS(VoidTy), - ARGS(TypeMetadataPtrTy, SizeTy, Int8PtrPtrTy->getPointerTo(0), SizeTy, + ARGS(TypeMetadataPtrTy, SizeTy, PtrTy, SizeTy, SizeTy), ATTRS(NoUnwind), EFFECT(RuntimeEffect::MetaData), diff --git a/lib/AST/ASTDemangler.cpp b/lib/AST/ASTDemangler.cpp index d3bc9b57b53..ca01ddffb68 100644 --- a/lib/AST/ASTDemangler.cpp +++ b/lib/AST/ASTDemangler.cpp @@ -474,14 +474,13 @@ Type ASTBuilder::createFunctionType( representation); // TODO: Handle LifetimeDependenceInfo here. - auto einfo = - FunctionType::ExtInfoBuilder( - representation, noescape, flags.isThrowing(), thrownError, - resultDiffKind, clangFunctionType, isolation, - /*LifetimeDependenceInfo*/ std::nullopt, extFlags.hasSendingResult()) - .withAsync(flags.isAsync()) - .withSendable(flags.isSendable()) - .build(); + auto einfo = FunctionType::ExtInfoBuilder( + representation, noescape, flags.isThrowing(), thrownError, + resultDiffKind, clangFunctionType, isolation, + /*LifetimeDependenceInfo*/ {}, extFlags.hasSendingResult()) + .withAsync(flags.isAsync()) + .withSendable(flags.isSendable()) + .build(); return FunctionType::get(funcParams, output, einfo); } @@ -714,7 +713,7 @@ Type ASTBuilder::createImplFunctionType( SILFunctionType::ExtInfoBuilder( representation, flags.isPseudogeneric(), !flags.isEscaping(), flags.isSendable(), flags.isAsync(), unimplementable, isolation, - diffKind, clangFnType, /*LifetimeDependenceInfo*/ std::nullopt) + diffKind, clangFnType, /*LifetimeDependenceInfo*/ {}) .build(); return SILFunctionType::get(genericSig, einfo, funcCoroutineKind, diff --git a/lib/AST/ASTMangler.cpp b/lib/AST/ASTMangler.cpp index 0fb823b4c14..bc074548d97 100644 --- a/lib/AST/ASTMangler.cpp +++ b/lib/AST/ASTMangler.cpp @@ -3018,7 +3018,7 @@ void ASTMangler::appendContextualInverses(const GenericTypeDecl *contextDecl, // that we're extending. // There are no generic parameters in this extension itself. - parts.params = std::nullopt; + parts.params = {}; // The depth of parameters for this extension is +1 of the extended signature. parts.initialParamDepth = sig.getNextDepth(); @@ -3616,7 +3616,7 @@ bool ASTMangler::GenericSignatureParts::hasRequirements() const { } void ASTMangler::GenericSignatureParts::clear() { - params = std::nullopt; + params = {}; requirements.clear(); inverses.clear(); initialParamDepth = 0; diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 64dd30b2992..5ef8c115ead 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -7383,8 +7383,7 @@ ArrayRef ProtocolDecl::getProtocolDependencies() const { return evaluateOrDefault( getASTContext().evaluator, - ProtocolDependenciesRequest{const_cast(this)}, - std::nullopt); + ProtocolDependenciesRequest{const_cast(this)}, {}); } RequirementSignature ProtocolDecl::getRequirementSignature() const { diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index e78eddc1307..c7d711d9ad7 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -1171,7 +1171,8 @@ namespace { auto *enumDecl = Impl.createDeclWithClangNode( decl, AccessLevel::Public, Impl.importSourceLoc(decl->getBeginLoc()), importedName.getBaseIdentifier(Impl.SwiftContext), - Impl.importSourceLoc(decl->getLocation()), std::nullopt, nullptr, dc); + Impl.importSourceLoc(decl->getLocation()), ArrayRef(), + nullptr, dc); // TODO: we only have this for the sid effect of calling // "FirstDeclAndLazyMembers.setInt(true)". // This should never actually try to use Impl as the member loader, @@ -1595,7 +1596,8 @@ namespace { auto access = importer::convertClangAccess(decl->getAccess()); auto Loc = Impl.importSourceLoc(decl->getLocation()); auto structDecl = Impl.createDeclWithClangNode( - decl, access, Loc, name, Loc, std::nullopt, nullptr, dc); + decl, access, Loc, name, Loc, ArrayRef(), nullptr, + dc); auto options = getDefaultMakeStructRawValuedOptions(); options |= MakeStructRawValuedFlags::MakeUnlabeledValueInit; @@ -1649,7 +1651,7 @@ namespace { "NSError enums shouldn't be defined as non-public C++ members"); // Create the wrapper struct. errorWrapper = - new (C) StructDecl(loc, name, loc, std::nullopt, nullptr, dc); + new (C) StructDecl(loc, name, loc, /*Inherited*/ {}, nullptr, dc); SourceLoc end = Impl.importSourceLoc(decl->getEndLoc()); errorWrapper->setBraces(SourceRange(loc, end)); errorWrapper->setAccess(AccessLevel::Public); @@ -1719,8 +1721,8 @@ namespace { // Create the enumeration. auto enumDecl = Impl.createDeclWithClangNode( decl, importer::convertClangAccess(decl->getAccess()), loc, - enumName, Impl.importSourceLoc(decl->getLocation()), std::nullopt, - nullptr, enumDC); + enumName, Impl.importSourceLoc(decl->getLocation()), + ArrayRef(), nullptr, enumDC); enumDecl->setHasFixedRawValues(); // Annotate as 'frozen' if appropriate. @@ -2223,7 +2225,7 @@ namespace { else result = Impl.createDeclWithClangNode( decl, importer::convertClangAccess(decl->getAccess()), loc, name, - loc, std::nullopt, nullptr, dc); + loc, ArrayRef(), nullptr, dc); Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result; if (recordHasMoveOnlySemantics(decl)) { @@ -4789,7 +4791,7 @@ namespace { auto structDecl = Impl.createDeclWithClangNode( decl, importer::convertClangAccess(decl->getAccess()), loc, name, loc, - std::nullopt, genericParamList, dc); + ArrayRef(), genericParamList, dc); auto attr = AvailableAttr::createUniversallyUnavailable( Impl.SwiftContext, "Un-specialized class templates are not currently " @@ -5801,7 +5803,8 @@ namespace { /*allowForwardDeclaration=*/true), Impl.importSourceLoc(decl->getBeginLoc()), Impl.importSourceLoc(decl->getLocation()), name, - ArrayRef(), std::nullopt, + ArrayRef(), + ArrayRef(), /*TrailingWhere=*/nullptr); Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result; @@ -5841,7 +5844,7 @@ namespace { decl, AccessLevel::Public, dc, Impl.importSourceLoc(decl->getBeginLoc()), Impl.importSourceLoc(decl->getLocation()), name, - ArrayRef(), std::nullopt, + ArrayRef(), ArrayRef(), /*TrailingWhere=*/nullptr); addObjCAttribute(result, Impl.importIdentifier(decl->getIdentifier())); @@ -5884,7 +5887,7 @@ namespace { auto result = Impl.createDeclWithClangNode( decl, AccessLevel::Public, SourceLoc(), name, SourceLoc(), - std::nullopt, nullptr, dc, + ArrayRef(), nullptr, dc, /*isActor*/ false); if (cacheResult) Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result; @@ -5998,7 +6001,8 @@ namespace { // Create the class declaration and record it. auto result = Impl.createDeclWithClangNode( decl, access, Impl.importSourceLoc(decl->getBeginLoc()), name, - Impl.importSourceLoc(decl->getLocation()), std::nullopt, nullptr, dc, + Impl.importSourceLoc(decl->getLocation()), ArrayRef(), + nullptr, dc, /*isActor*/ false); // Import generic arguments, if any. @@ -6472,7 +6476,7 @@ SwiftDeclConverter::importCFClassType(const clang::TypedefNameDecl *decl, auto theClass = Impl.createDeclWithClangNode( decl, AccessLevel::Public, SourceLoc(), className, SourceLoc(), - std::nullopt, nullptr, dc, /*isActor*/ false); + ArrayRef(), nullptr, dc, /*isActor*/ false); theClass->setSuperclass(superclass); theClass->setAddedImplicitInitializers(); // suppress all initializers theClass->setHasMissingVTableEntries(false); @@ -6638,7 +6642,7 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl, auto structDecl = Impl.createDeclWithClangNode( decl, importer::convertClangAccess(decl->getAccess()), Loc, name, Loc, - std::nullopt, nullptr, dc); + ArrayRef(), nullptr, dc); // Import the type of the underlying storage ImportDiagnosticAdder addImportDiag(Impl, decl, decl->getLocation()); @@ -6946,7 +6950,7 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name, // Create a struct with the underlying type as a field. auto structDecl = Impl.createDeclWithClangNode( decl, importer::convertClangAccess(decl->getAccess()), Loc, name, Loc, - std::nullopt, nullptr, dc); + ArrayRef(), nullptr, dc); Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = structDecl; // Compute the underlying type. diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 732596b7f10..cd762cd9169 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -282,8 +282,8 @@ namespace driver { "not implemented for compilations with multiple jobs"); if (Comp.getShowJobLifecycle()) llvm::outs() << "Added to TaskQueue: " << LogJob(Cmd) << "\n"; - TQ->addTask(Cmd->getExecutable(), Cmd->getArgumentsForTaskExecution(), - std::nullopt, (void *)Cmd); + TQ->addTask(Cmd->getExecutable(), Cmd->getArgumentsForTaskExecution(), {}, + (void *)Cmd); } /// When a task finishes, check other Jobs that may be blocked. diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index 755df3cc72e..1ca6696397c 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -186,7 +186,7 @@ static bool findXcodeClangPath(llvm::SmallVectorImpl &path) { // included with an open-source toolchain. const char *args[] = {"-toolchain", "default", "-f", "clang", nullptr}; sys::TaskQueue queue; - queue.addTask(xcrunPath->c_str(), args, /*Env=*/std::nullopt, + queue.addTask(xcrunPath->c_str(), args, /*Env=*/{}, /*Context=*/nullptr, /*SeparateErrors=*/true); queue.execute(nullptr, diff --git a/lib/Frontend/CASOutputBackends.cpp b/lib/Frontend/CASOutputBackends.cpp index 904f885fbbf..968ced016ba 100644 --- a/lib/Frontend/CASOutputBackends.cpp +++ b/lib/Frontend/CASOutputBackends.cpp @@ -78,11 +78,11 @@ public: (void)Shortened; std::optional PathRef; if (Error E = - CAS.storeFromString(std::nullopt, Path).moveInto(PathRef)) + CAS.storeFromString(/*Refs*/ {}, Path).moveInto(PathRef)) return E; std::optional BytesRef; if (Error E = - CAS.storeFromString(std::nullopt, Bytes).moveInto(BytesRef)) + CAS.storeFromString(/*Refs*/ {}, Bytes).moveInto(BytesRef)) return E; auto Ref = CAS.store({*PathRef, *BytesRef}, {}); if (!Ref) @@ -256,7 +256,7 @@ Error SwiftCASOutputBackend::Implementation::storeImpl( StringRef Path, StringRef Bytes, unsigned InputIndex, file_types::ID OutputKind) { std::optional BytesRef; - if (Error E = CAS.storeFromString(std::nullopt, Bytes).moveInto(BytesRef)) + if (Error E = CAS.storeFromString(/*Refs*/ {}, Bytes).moveInto(BytesRef)) return E; LLVM_DEBUG(llvm::dbgs() << "DEBUG: producing CAS output of type \'" diff --git a/lib/Frontend/CompileJobCacheKey.cpp b/lib/Frontend/CompileJobCacheKey.cpp index a6e8e0e3f67..7a844cf4a88 100644 --- a/lib/Frontend/CompileJobCacheKey.cpp +++ b/lib/Frontend/CompileJobCacheKey.cpp @@ -72,14 +72,14 @@ llvm::Expected swift::createCompileJobBaseCacheKey( } llvm::cas::HierarchicalTreeBuilder Builder; - auto CMD = CAS.storeFromString(std::nullopt, CommandLine); + auto CMD = CAS.storeFromString(/*Refs*/ {}, CommandLine); if (!CMD) return CMD.takeError(); Builder.push(*CMD, llvm::cas::TreeEntry::Regular, "command-line"); // FIXME: The version is maybe insufficient... auto Version = - CAS.storeFromString(std::nullopt, version::getSwiftFullVersion()); + CAS.storeFromString(/*Refs*/ {}, version::getSwiftFullVersion()); if (!Version) return Version.takeError(); Builder.push(*Version, llvm::cas::TreeEntry::Regular, "version"); diff --git a/lib/IRGen/GenBuiltin.cpp b/lib/IRGen/GenBuiltin.cpp index 9604ba97c53..287c07ace9b 100644 --- a/lib/IRGen/GenBuiltin.cpp +++ b/lib/IRGen/GenBuiltin.cpp @@ -133,6 +133,8 @@ getMaximallyAbstractedLoweredTypeAndTypeInfo(IRGenModule &IGM, Type unloweredTyp void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, BuiltinInst *Inst, ArrayRef argTypes, Explosion &args, Explosion &out) { + auto &IGM = IGF.IGM; + Identifier FnId = Inst->getName(); SILType resultType = Inst->getType(); SubstitutionMap substitutions = Inst->getSubstitutions(); @@ -732,8 +734,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, newval = IGF.Builder.CreatePtrToInt(newval, IGF.IGM.IntPtrTy); } - pointer = IGF.Builder.CreateBitCast(pointer, - llvm::PointerType::getUnqual(cmp->getType())); + pointer = IGF.Builder.CreateBitCast(pointer, IGM.PtrTy); llvm::Value *value = IGF.Builder.CreateAtomicCmpXchg( pointer, cmp, newval, llvm::MaybeAlign(), successOrdering, failureOrdering, @@ -801,8 +802,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, if (origTy->isPointerTy()) val = IGF.Builder.CreatePtrToInt(val, IGF.IGM.IntPtrTy); - pointer = IGF.Builder.CreateBitCast(pointer, - llvm::PointerType::getUnqual(val->getType())); + pointer = IGF.Builder.CreateBitCast(pointer, IGM.PtrTy); llvm::Value *value = IGF.Builder.CreateAtomicRMW( SubOpcode, pointer, val, llvm::MaybeAlign(), ordering, isSingleThread ? llvm::SyncScope::SingleThread @@ -853,7 +853,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, valueTy->getPrimitiveSizeInBits()); } - pointer = IGF.Builder.CreateBitCast(pointer, valueTy->getPointerTo()); + pointer = IGF.Builder.CreateBitCast(pointer, IGM.PtrTy); if (Builtin.ID == BuiltinValueKind::AtomicLoad) { auto load = IGF.Builder.CreateLoad(pointer, valueTy, @@ -1065,8 +1065,8 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, || Builtin.ID == BuiltinValueKind::OnceWithContext) { // The input type is statically (Builtin.RawPointer, @convention(thin) () -> ()). llvm::Value *PredPtr = args.claimNext(); - // Cast the predicate to a OnceTy pointer. - PredPtr = IGF.Builder.CreateBitCast(PredPtr, IGF.IGM.OnceTy->getPointerTo()); + // Cast the predicate to a pointer. + PredPtr = IGF.Builder.CreateBitCast(PredPtr, IGM.PtrTy); llvm::Value *FnCode = args.claimNext(); // Get the context if any. llvm::Value *Context; @@ -1157,9 +1157,8 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, IsTriviallyDestroyable) return; - llvm::Value *firstElem = - IGF.Builder.CreatePtrToInt(IGF.Builder.CreateBitCast( - ptr, elemTI.getStorageType()->getPointerTo()), IGF.IGM.IntPtrTy); + llvm::Value *firstElem = IGF.Builder.CreatePtrToInt( + IGF.Builder.CreateBitCast(ptr, IGM.PtrTy), IGF.IGM.IntPtrTy); auto *origBB = IGF.Builder.GetInsertBlock(); auto *headerBB = IGF.createBasicBlock("loop_header"); @@ -1177,8 +1176,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, llvm::Value *offset = IGF.Builder.CreateMul(phi, elemTI.getStaticStride(IGF.IGM)); llvm::Value *added = IGF.Builder.CreateAdd(firstElem, offset); - llvm::Value *addr = IGF.Builder.CreateIntToPtr( - added, elemTI.getStorageType()->getPointerTo()); + llvm::Value *addr = IGF.Builder.CreateIntToPtr(added, IGM.PtrTy); bool isOutlined = false; elemTI.destroy(IGF, elemTI.getAddressForPointer(addr), elemTy, @@ -1193,8 +1191,7 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, return; } - ptr = IGF.Builder.CreateBitCast(ptr, - valueTy.second.getStorageType()->getPointerTo()); + ptr = IGF.Builder.CreateBitCast(ptr, IGM.PtrTy); Address array = valueTy.second.getAddressForPointer(ptr); // If the count is statically known to be a constant 1, then just call the @@ -1246,13 +1243,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, } llvm::Value *firstSrcElem = IGF.Builder.CreatePtrToInt( - IGF.Builder.CreateBitCast(src, - elemTI.getStorageType()->getPointerTo()), - IGF.IGM.IntPtrTy); + IGF.Builder.CreateBitCast(src, IGM.PtrTy), IGF.IGM.IntPtrTy); llvm::Value *firstDestElem = IGF.Builder.CreatePtrToInt( - IGF.Builder.CreateBitCast(dest, - elemTI.getStorageType()->getPointerTo()), - IGF.IGM.IntPtrTy); + IGF.Builder.CreateBitCast(dest, IGM.PtrTy), IGF.IGM.IntPtrTy); auto *origBB = IGF.Builder.GetInsertBlock(); auto *headerBB = IGF.createBasicBlock("loop_header"); @@ -1284,11 +1277,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, IGF.Builder.CreateMul(idx, elemTI.getStaticStride(IGF.IGM)); llvm::Value *srcAdded = IGF.Builder.CreateAdd(firstSrcElem, offset); - auto *srcElem = IGF.Builder.CreateIntToPtr( - srcAdded, elemTI.getStorageType()->getPointerTo()); + auto *srcElem = IGF.Builder.CreateIntToPtr(srcAdded, IGM.PtrTy); llvm::Value *dstAdded = IGF.Builder.CreateAdd(firstDestElem, offset); - auto *destElem = IGF.Builder.CreateIntToPtr( - dstAdded, elemTI.getStorageType()->getPointerTo()); + auto *destElem = IGF.Builder.CreateIntToPtr(dstAdded, IGM.PtrTy); Address destAddr = elemTI.getAddressForPointer(destElem); Address srcAddr = elemTI.getAddressForPointer(srcElem); @@ -1326,11 +1317,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin, auto valueTy = getLoweredTypeAndTypeInfo(IGF.IGM, substitutions.getReplacementTypes()[0]); - - dest = IGF.Builder.CreateBitCast(dest, - valueTy.second.getStorageType()->getPointerTo()); - src = IGF.Builder.CreateBitCast(src, - valueTy.second.getStorageType()->getPointerTo()); + + dest = IGF.Builder.CreateBitCast(dest, IGM.PtrTy); + src = IGF.Builder.CreateBitCast(src, IGM.PtrTy); Address destArray = valueTy.second.getAddressForPointer(dest); Address srcArray = valueTy.second.getAddressForPointer(src); diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp index e16a714a2e8..afddc583fe2 100644 --- a/lib/IRGen/GenCall.cpp +++ b/lib/IRGen/GenCall.cpp @@ -639,9 +639,7 @@ namespace { } /// Add a pointer to the given type as the next parameter. - void addPointerParameter(llvm::Type *storageType) { - ParamIRTypes.push_back(storageType->getPointerTo()); - } + void addOpaquePointerParameter() { ParamIRTypes.push_back(IGM.PtrTy); } void addCoroutineContextParameter(); void addCoroutineAllocatorParameter(); @@ -674,7 +672,7 @@ llvm::Type *SignatureExpansion::addIndirectResult(SILType resultType, auto storageTy = resultTI.getStorageType(); addIndirectResultAttributes(IGM, Attrs, ParamIRTypes.size(), claimSRet(), storageTy, resultTI, useInReg); - addPointerParameter(storageTy); + addOpaquePointerParameter(); return IGM.VoidTy; } @@ -749,7 +747,7 @@ void SignatureExpansion::expandIndirectResults() { } addIndirectResultAttributes(IGM, Attrs, ParamIRTypes.size(), useSRet, storageTy, typeInfo); - addPointerParameter(storageTy); + addOpaquePointerParameter(); } } @@ -787,9 +785,9 @@ namespace { /// Is the yielded value formally indirect? bool isFormalIndirect() const { return YieldTy.isAddress(); } - llvm::PointerType *getIndirectPointerType() const { + llvm::PointerType *getIndirectPointerType(IRGenModule &IGM) const { assert(isIndirect()); - return YieldTI.getStorageType()->getPointerTo(); + return IGM.PtrTy; } const NativeConventionSchema &getDirectSchema() const { @@ -849,7 +847,7 @@ void SignatureExpansion::expandCoroutineResult(bool forContinuation) { // If the individual value must be yielded indirectly, add a pointer. if (schema.isIndirect()) { - components.push_back(schema.getIndirectPointerType()); + components.push_back(schema.getIndirectPointerType(IGM)); continue; } @@ -891,7 +889,7 @@ void SignatureExpansion::expandCoroutineResult(bool forContinuation) { // trusting LLVM's? CoroInfo.indirectResultsType = llvm::StructType::get(IGM.getLLVMContext(), overflowTypes); - components.back() = CoroInfo.indirectResultsType->getPointerTo(); + components.back() = IGM.PtrTy; } ResultIRType = components.size() == 1 @@ -1724,7 +1722,7 @@ void SignatureExpansion::expandExternalSignatureTypes() { Alignment(AI.getIndirectAlign().getQuantity()), paramTI.getStorageType()); } - addPointerParameter(paramTI.getStorageType()); + addOpaquePointerParameter(); break; } case clang::CodeGen::ABIArgInfo::Expand: @@ -1799,8 +1797,7 @@ const TypeInfo &SignatureExpansion::expand(unsigned paramIdx) { case ParameterConvention::Indirect_In_CXX: addIndirectValueParameterAttributes(IGM, Attrs, ti, ParamIRTypes.size(), isAddressableParam(paramIdx)); - addPointerParameter(IGM.getStorageType(getSILFuncConventions().getSILType( - param, IGM.getMaximalTypeExpansionContext()))); + addOpaquePointerParameter(); return ti; case ParameterConvention::Indirect_Inout: @@ -1809,15 +1806,14 @@ const TypeInfo &SignatureExpansion::expand(unsigned paramIdx) { IGM, paramSILType, Attrs, ti, ParamIRTypes.size(), conv == ParameterConvention::Indirect_InoutAliasable, isAddressableParam(paramIdx)); - addPointerParameter(IGM.getStorageType(getSILFuncConventions().getSILType( - param, IGM.getMaximalTypeExpansionContext()))); + addOpaquePointerParameter(); return ti; case ParameterConvention::Pack_Guaranteed: case ParameterConvention::Pack_Owned: case ParameterConvention::Pack_Inout: addPackParameterAttributes(IGM, paramSILType, Attrs, ParamIRTypes.size()); - addPointerParameter(ti.getStorageType()); + addOpaquePointerParameter(); return ti; case ParameterConvention::Direct_Owned: @@ -1834,7 +1830,7 @@ const TypeInfo &SignatureExpansion::expand(unsigned paramIdx) { addIndirectValueParameterAttributes(IGM, Attrs, ti, ParamIRTypes.size(), /*addressable*/ false); - ParamIRTypes.push_back(ti.getStorageType()->getPointerTo()); + addOpaquePointerParameter(); return ti; } if (nativeSchema.empty()) { @@ -1989,8 +1985,8 @@ void SignatureExpansion::expandParameters( auto fnConv = getSILFuncConventions(); for (auto indirectResultType : fnConv.getIndirectSILResultTypes( IGM.getMaximalTypeExpansionContext())) { - auto storageTy = IGM.getStorageType(indirectResultType); - addPointerParameter(storageTy); + (void)indirectResultType; + addOpaquePointerParameter(); } break; } @@ -2079,8 +2075,7 @@ void SignatureExpansion::expandParameters( if (FnType->hasErrorResult()) { if (claimError()) IGM.addSwiftErrorAttributes(Attrs, ParamIRTypes.size()); - llvm::Type *errorType = getErrorRegisterType(); - ParamIRTypes.push_back(errorType->getPointerTo()); + addOpaquePointerParameter(); if (recordedABIDetails) recordedABIDetails->hasErrorResult = true; if (getSILFuncConventions().isTypedError()) { @@ -2098,7 +2093,7 @@ void SignatureExpansion::expandParameters( getSILFuncConventions().hasIndirectSILErrorResults() || native.requiresIndirect() || nativeError.shouldReturnTypedErrorIndirectly()) { - ParamIRTypes.push_back(IGM.getStorageType(errorType)->getPointerTo()); + addOpaquePointerParameter(); } } } @@ -2241,8 +2236,7 @@ void SignatureExpansion::addIndirectThrowingResult() { getSILFuncConventions().hasIndirectSILErrorResults() || native.requiresIndirect() || nativeError.shouldReturnTypedErrorIndirectly()) { - auto errorStorageTy = errorTI.getStorageType(); - ParamIRTypes.push_back(errorStorageTy->getPointerTo()); + addOpaquePointerParameter(); } } @@ -2566,8 +2560,7 @@ llvm::Value *emitIndirectAsyncFunctionPointer(IRGenFunction &IGF, llvm::Value *UntaggedPointer = IGF.Builder.CreateAnd(PtrToInt, NegativeOne); llvm::Value *IntToPtr = - IGF.Builder.CreateIntToPtr(UntaggedPointer, - AsyncFunctionPointerPtrTy->getPointerTo()); + IGF.Builder.CreateIntToPtr(UntaggedPointer, IGF.IGM.PtrTy); llvm::Value *Load = IGF.Builder.CreateLoad( IntToPtr, AsyncFunctionPointerPtrTy, PointerAlignment); @@ -2596,8 +2589,8 @@ llvm::Value *emitIndirectCoroFunctionPointer(IRGenFunction &IGF, IGF.Builder.CreateBitCast(pointer, CoroFunctionPointerPtrTy); llvm::Value *UntaggedPointer = IGF.Builder.CreateAnd(PtrToInt, NegativeOne); - llvm::Value *IntToPtr = IGF.Builder.CreateIntToPtr( - UntaggedPointer, CoroFunctionPointerPtrTy->getPointerTo()); + llvm::Value *IntToPtr = + IGF.Builder.CreateIntToPtr(UntaggedPointer, IGF.IGM.PtrTy); llvm::Value *Load = IGF.Builder.CreateLoad(IntToPtr, CoroFunctionPointerPtrTy, PointerAlignment); @@ -3236,9 +3229,8 @@ public: getCallee().getFunctionPointer().getKind()); return FunctionPointer::createForAsyncCall( - IGF.Builder.CreateBitCast(calleeFunction, - awaitEntrySig.getType()->getPointerTo()), - codeAuthInfo, awaitSig, awaitEntrySig.getType()); + IGF.Builder.CreateBitCast(calleeFunction, IGF.IGM.PtrTy), codeAuthInfo, + awaitSig, awaitEntrySig.getType()); } SILType getParameterType(unsigned index) override { @@ -3913,8 +3905,9 @@ void CallEmission::emitYieldsToExplosion(Explosion &out) { // If the schema says it's indirect, then we expect a pointer. if (schema.isIndirect()) { - auto pointer = IGF.Builder.CreateBitCast(rawYieldComponents.claimNext(), - schema.getIndirectPointerType()); + auto pointer = + IGF.Builder.CreateBitCast(rawYieldComponents.claimNext(), + schema.getIndirectPointerType(IGF.IGM)); // If it's formally indirect, then we should just add that pointer // to the output. @@ -5190,8 +5183,7 @@ static llvm::Constant *getCoroAllocFn(IRGenModule &IGM) { {llvm::ConstantInt::get(IGF.IGM.Int32Ty, 0), llvm::ConstantInt::get(IGF.IGM.Int32Ty, 1)}); auto *callee = IGF.Builder.CreateLoad( - Address(calleePtr, IGF.IGM.CoroAllocateFnTy->getPointerTo(), - IGF.IGM.getPointerAlignment()), + Address(calleePtr, IGF.IGM.PtrTy, IGF.IGM.getPointerAlignment()), "allocate_fn"); auto fnPtr = FunctionPointer::createUnsigned( FunctionPointer::Kind::Function, callee, @@ -5268,8 +5260,7 @@ static llvm::Constant *getCoroDeallocFn(IRGenModule &IGM) { {llvm::ConstantInt::get(IGF.IGM.Int32Ty, 0), llvm::ConstantInt::get(IGF.IGM.Int32Ty, 2)}); auto *callee = IGF.Builder.CreateLoad( - Address(calleePtr, IGF.IGM.CoroDeallocateFnTy->getPointerTo(), - IGF.IGM.getPointerAlignment()), + Address(calleePtr, IGF.IGM.PtrTy, IGF.IGM.getPointerAlignment()), "deallocate_fn"); auto fnPtr = FunctionPointer::createUnsigned( FunctionPointer::Kind::Function, callee, @@ -6412,8 +6403,7 @@ Explosion IRGenFunction::coerceValueTo(SILType fromTy, Explosion &from, auto temporary = toTI.allocateStack(*this, toTy, "coerce.temp"); auto addr = - Address(Builder.CreateBitCast(temporary.getAddressPointer(), - fromTI.getStorageType()->getPointerTo()), + Address(Builder.CreateBitCast(temporary.getAddressPointer(), IGM.PtrTy), fromTI.getStorageType(), temporary.getAlignment()); fromTI.initialize(*this, from, addr, false); @@ -6549,7 +6539,7 @@ Signature irgen::emitCastOfFunctionPointer(IRGenFunction &IGF, : IGF.IGM.getSignature(fnType); // Emit the cast. - fnPtr = IGF.Builder.CreateBitCast(fnPtr, sig.getType()->getPointerTo()); + fnPtr = IGF.Builder.CreateBitCast(fnPtr, IGF.IGM.PtrTy); // Return the information. return sig; @@ -7038,7 +7028,7 @@ IRGenFunction::getFunctionPointerForResumeIntrinsic(llvm::Value *resume) { Signature(fnTy, attrs, IGM.SwiftAsyncCC); auto fnPtr = FunctionPointer::createUnsigned( FunctionPointer::Kind::Function, - Builder.CreateBitOrPointerCast(resume, fnTy->getPointerTo()), signature); + Builder.CreateBitOrPointerCast(resume, IGM.PtrTy), signature); return fnPtr; } diff --git a/lib/IRGen/GenCast.cpp b/lib/IRGen/GenCast.cpp index b8f462af53d..2f6eb20f576 100644 --- a/lib/IRGen/GenCast.cpp +++ b/lib/IRGen/GenCast.cpp @@ -1009,7 +1009,7 @@ void irgen::emitScalarCheckedCast(IRGenFunction &IGF, IGF.IGM.getPointerAlignment(), "castSrc"); IGF.Builder.CreateStore(metatypeVal, src); - llvm::PointerType *destPtrType = IGF.IGM.getStoragePointerType(targetLoweredType); + llvm::PointerType *destPtrType = IGF.IGM.PtrTy; Address dest = IGF.createAlloca(destPtrType, IGF.IGM.getPointerAlignment(), "castDest"); diff --git a/lib/IRGen/GenClass.cpp b/lib/IRGen/GenClass.cpp index beca2b1cc59..c3e26fe4009 100644 --- a/lib/IRGen/GenClass.cpp +++ b/lib/IRGen/GenClass.cpp @@ -546,12 +546,11 @@ ClassTypeInfo::getClassLayout(IRGenModule &IGM, SILType classType, /// as a size_t), and cast to a pointer to the given type. llvm::Value *IRGenFunction::emitByteOffsetGEP(llvm::Value *base, llvm::Value *offset, - llvm::Type *objectType, const llvm::Twine &name) { assert(offset->getType() == IGM.SizeTy || offset->getType() == IGM.Int32Ty); auto addr = Builder.CreateBitCast(base, IGM.Int8PtrTy); addr = Builder.CreateInBoundsGEP(IGM.Int8Ty, addr, offset); - return Builder.CreateBitCast(addr, objectType->getPointerTo(), name); + return Builder.CreateBitCast(addr, IGM.PtrTy, name); } /// Cast the base to i8*, apply the given inbounds offset (in bytes, @@ -560,7 +559,7 @@ Address IRGenFunction::emitByteOffsetGEP(llvm::Value *base, llvm::Value *offset, const TypeInfo &type, const llvm::Twine &name) { - auto addr = emitByteOffsetGEP(base, offset, type.getStorageType(), name); + auto addr = emitByteOffsetGEP(base, offset, name); return type.getAddressForPointer(addr); } @@ -864,7 +863,6 @@ llvm::Value *irgen::emitClassAllocation(IRGenFunction &IGF, SILType selfType, auto &classLayout = classTI.getClassLayout(IGF.IGM, selfType, /*forBackwardDeployment=*/false); - llvm::Type *destType = classLayout.getType()->getPointerTo(); llvm::Value *val = nullptr; if (llvm::Value *Promoted = stackPromote(IGF, classLayout, StackAllocSize, TailArrays)) { @@ -900,7 +898,7 @@ llvm::Value *irgen::emitClassAllocation(IRGenFunction &IGF, SILType selfType, val = IGF.emitAllocObjectCall(metadata, size, alignMask, "reference.new"); StackAllocSize = -1; } - return IGF.Builder.CreateBitCast(val, destType); + return IGF.Builder.CreateBitCast(val, IGF.IGM.PtrTy); } llvm::Value *irgen::emitClassAllocationDynamic(IRGenFunction &IGF, @@ -919,6 +917,7 @@ llvm::Value *irgen::emitClassAllocationDynamic(IRGenFunction &IGF, auto &classTI = IGF.getTypeInfo(selfType).as(); auto &classLayout = classTI.getClassLayout(IGF.IGM, selfType, /*forBackwardDeployment=*/false); + auto *destType = IGF.IGM.PtrTy; // If we are allowed to allocate on the stack we are allowed to use // `selfType`'s size assumptions. @@ -929,7 +928,6 @@ llvm::Value *irgen::emitClassAllocationDynamic(IRGenFunction &IGF, IGF.IGM.RefCountedPtrTy); val = IGF.emitInitStackObjectCall(metadata, val, "reference.new"); - llvm::Type *destType = classLayout.getType()->getPointerTo(); return IGF.Builder.CreateBitCast(val, destType); } @@ -945,7 +943,6 @@ llvm::Value *irgen::emitClassAllocationDynamic(IRGenFunction &IGF, llvm::Value *val = IGF.emitAllocObjectCall(metadata, size, alignMask, "reference.new"); StackAllocSize = -1; - llvm::Type *destType = classLayout.getType()->getPointerTo(); return IGF.Builder.CreateBitCast(val, destType); } @@ -2089,7 +2086,7 @@ namespace { if (offsetPtr) fields.add(offsetPtr); else - fields.addNullPointer(IGM.IntPtrTy->getPointerTo()); + fields.addNullPointer(IGM.PtrTy); // TODO: clang puts this in __TEXT,__objc_methname,cstring_literals fields.add(IGM.getAddrOfGlobalString(name)); @@ -2634,8 +2631,7 @@ llvm::Constant *IRGenModule::emitObjCResilientClassStub( auto *objcStub = llvm::ConstantExpr::getBitCast(fullObjCStub, Int8PtrTy); objcStub = llvm::ConstantExpr::getInBoundsGetElementPtr( Int8Ty, objcStub, getSize(getPointerSize())); - objcStub = llvm::ConstantExpr::getPointerCast(objcStub, - ObjCResilientClassStubTy->getPointerTo()); + objcStub = llvm::ConstantExpr::getPointerCast(objcStub, PtrTy); if (isPublic) { entity = LinkEntity::forObjCResilientClassStub( @@ -2800,7 +2796,6 @@ llvm::Constant *irgen::emitObjCProtocolData(IRGenModule &IGM, const TypeInfo * TypeConverter::convertClassType(CanType type, ClassDecl *D) { llvm::StructType *ST = IGM.createNominalType(type); - llvm::PointerType *irType = ST->getPointerTo(); ReferenceCounting refcount = type->getReferenceCounting(); SpareBitVector spareBits; @@ -2813,8 +2808,9 @@ TypeConverter::convertClassType(CanType type, ClassDecl *D) { else spareBits = IGM.getHeapObjectSpareBits(); - return new ClassTypeInfo(irType, IGM.getPointerSize(), std::move(spareBits), - IGM.getPointerAlignment(), D, refcount, ST); + return new ClassTypeInfo(IGM.PtrTy, IGM.getPointerSize(), + std::move(spareBits), IGM.getPointerAlignment(), D, + refcount, ST); } /// Lazily declare a fake-looking class to represent an ObjC runtime base class. @@ -3081,8 +3077,7 @@ static llvm::Value *emitVTableSlotLoad(IRGenFunction &IGF, Address slot, llvm::Value *checkedLoad = IGF.Builder.CreateIntrinsicCall( llvm::Intrinsic::type_checked_load, args); auto fnPtr = IGF.Builder.CreateExtractValue(checkedLoad, 0); - return IGF.Builder.CreateBitCast(fnPtr, - signature.getType()->getPointerTo()); + return IGF.Builder.CreateBitCast(fnPtr, IGF.IGM.PtrTy); } // Not doing LLVM IR VFE, can just be a direct load. @@ -3104,8 +3099,7 @@ FunctionPointer irgen::emitVirtualMethodValue(IRGenFunction &IGF, case ClassMetadataLayout::MethodInfo::Kind::Offset: { auto offset = methodInfo.getOffset(); - auto slot = IGF.emitAddressAtOffset(metadata, offset, - signature.getType()->getPointerTo(), + auto slot = IGF.emitAddressAtOffset(metadata, offset, IGF.IGM.PtrTy, IGF.IGM.getPointerAlignment()); auto fnPtr = emitVTableSlotLoad(IGF, slot, method, signature); auto &schema = methodType->isAsync() @@ -3120,7 +3114,7 @@ FunctionPointer irgen::emitVirtualMethodValue(IRGenFunction &IGF, } case ClassMetadataLayout::MethodInfo::Kind::DirectImpl: { auto fnPtr = llvm::ConstantExpr::getBitCast(methodInfo.getDirectImpl(), - signature.getType()->getPointerTo()); + IGF.IGM.PtrTy); llvm::Constant *secondaryValue = nullptr; auto *accessor = dyn_cast(method.getDecl()); if (cast(method.getDecl())->hasAsync()) { diff --git a/lib/IRGen/GenCoro.cpp b/lib/IRGen/GenCoro.cpp index b8e9c88e15d..f9ab20348e5 100644 --- a/lib/IRGen/GenCoro.cpp +++ b/lib/IRGen/GenCoro.cpp @@ -76,8 +76,7 @@ class GetDeallocThroughFn { auto runtimeFnValue = cast(IGM.getTaskDeallocThroughFn()); runtimeFnValue->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); auto *symbolExists = IGF.Builder.CreateICmpNE( - runtimeFnValue, - llvm::ConstantPointerNull::get(IGF.IGM.Int8Ty->getPointerTo()), + runtimeFnValue, llvm::ConstantPointerNull::get(IGF.IGM.PtrTy), "runtime_has_dealloc_through"); auto *noSymbolBlock = IGF.createBasicBlock("no_runtime_symbol"); @@ -184,8 +183,7 @@ class GetDeallocThroughFn { ApplyIRLinkage(IRLinkage::ExternalWeakImport) .to(cast(escalationSymbol)); auto *symbolExists = IGF.Builder.CreateICmpNE( - escalationSymbol, - llvm::ConstantPointerNull::get(IGF.IGM.Int8Ty->getPointerTo()), + escalationSymbol, llvm::ConstantPointerNull::get(IGF.IGM.PtrTy), "escalation_is_defined"); IGF.Builder.CreateCondBr(symbolExists, hasEscalationSymbolBlock, @@ -367,7 +365,7 @@ class GetDeallocThroughFn { } llvm_unreachable("covered switch"); } - llvm::Type *getType(IRGenModule &IGM, llvm::Type *allocationTy) { + llvm::Type *getType(IRGenModule &IGM) { switch (kind) { case RefCountedStruct: return IGM.RefCountedStructTy; @@ -384,7 +382,7 @@ class GetDeallocThroughFn { case IntPtr: return IGM.IntPtrTy; case AllocationPtr: - return allocationTy->getPointerTo(); + return IGM.PtrTy; } llvm_unreachable("covered switch"); } @@ -445,26 +443,23 @@ class GetDeallocThroughFn { } llvm_unreachable("covered switch"); }; - void getFields(IRGenModule &IGM, llvm::Type *allocationTy, + void getFields(IRGenModule &IGM, SmallVectorImpl &fieldTys) { struct Visitor : PrivateLayout::FieldVisitor { SmallVectorImpl &fieldTys; IRGenModule &IGM; - llvm::Type *allocationTy; - Visitor(SmallVectorImpl &fieldTys, IRGenModule &IGM, - llvm::Type *allocationTy) - : fieldTys(fieldTys), IGM(IGM), allocationTy(allocationTy) {} + Visitor(SmallVectorImpl &fieldTys, IRGenModule &IGM) + : fieldTys(fieldTys), IGM(IGM) {} void visitField(PrivateLayout::Field field) { - fieldTys.push_back(field.getType(IGM, allocationTy)); + fieldTys.push_back(field.getType(IGM)); }; void visitArray(PrivateLayout::Field field, unsigned count) { - fieldTys.push_back( - llvm::ArrayType::get(field.getType(IGM, allocationTy), count)); + fieldTys.push_back(llvm::ArrayType::get(field.getType(IGM), count)); } }; - Visitor visitor(fieldTys, IGM, allocationTy); + Visitor visitor(fieldTys, IGM); visitor.visit(*this); } unsigned getAllocatorIndex() { @@ -512,7 +507,7 @@ class GetDeallocThroughFn { assert(layout.isPointer8Bytes() == isPointer8Bytes); SmallVector fieldTys; - layout.getFields(IGM, getAllocationTy(), fieldTys); + layout.getFields(IGM, fieldTys); auto name = layout.getName(); return llvm::StructType::create(IGM.getLLVMContext(), fieldTys, name, diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index e0569dbaa23..3548e654335 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -344,8 +344,7 @@ public: llvm::Value *ref = IGM.getAddrOfObjCProtocolRef(proto, NotForDefinition).getAddress(); - ref = IGF.Builder.CreateBitCast(ref, - IGM.ProtocolDescriptorPtrTy->getPointerTo()); + ref = IGF.Builder.CreateBitCast(ref, IGM.PtrTy); Builder.CreateStore(result, ref, IGM.getPointerAlignment()); } @@ -2693,8 +2692,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var, // If we're not emitting this to define it, make sure we cast it to the // right type. if (!forDefinition) { - auto ptrTy = ti.getStorageType()->getPointerTo(); - addr = llvm::ConstantExpr::getBitCast(addr, ptrTy); + addr = llvm::ConstantExpr::getBitCast(addr, PtrTy); } auto alignment = @@ -2828,8 +2826,7 @@ Address IRGenModule::getAddrOfSILGlobalVariable(SILGlobalVariable *var, } addr = llvm::ConstantExpr::getBitCast( - addr, - castStorageToType ? castStorageToType : storageType->getPointerTo()); + addr, castStorageToType ? castStorageToType : PtrTy); if (castStorageToType) storageType = cast(ti).getClassLayoutType(); @@ -3026,8 +3023,7 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) { linkEntry->getValueType(), linkEntry, indices); auto *ReplAddr = - llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(fnPtrAddr, - FunctionPtrTy->getPointerTo()); + llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(fnPtrAddr, PtrTy); auto *FnAddr = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast( funPtr, FunctionPtrTy); @@ -3068,7 +3064,7 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) { PrologueLocation AutoRestore(IGM.DebugInfo.get(), Builder); auto authEntity = PointerAuthEntity(f); auto authInfo = PointerAuthInfo::emit(IGF, schema, fnPtrAddr, authEntity); - auto *fnType = signature.getType()->getPointerTo(); + auto *fnType = PtrTy; auto *realReplFn = Builder.CreateBitCast(ReplFn, fnType); auto asyncFnPtr = FunctionPointer::createSigned(silFunctionType, realReplFn, authInfo, signature); @@ -3191,7 +3187,7 @@ void IRGenModule::createReplaceableProlog(IRGenFunction &IGF, SILFunction *f) { SmallVector forwardedArgs; for (auto &arg : IGF.CurFn->args()) forwardedArgs.push_back(&arg); - auto *fnType = signature.getType()->getPointerTo(); + auto *fnType = PtrTy; auto *realReplFn = IGF.Builder.CreateBitCast(ReplFn, fnType); auto authEntity = PointerAuthEntity(f); @@ -3373,7 +3369,7 @@ void IRGenModule::emitDynamicReplacementOriginalFunctionThunk(SILFunction *f) { auto *fnPtrAddr = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast( llvm::ConstantExpr::getInBoundsGetElementPtr(linkEntry->getValueType(), linkEntry, indices), - FunctionPtrTy->getPointerTo()); + PtrTy); auto *OrigFn = IGF.Builder.CreateCall( getGetOrigOfReplaceableFunctionPointer(), {fnPtrAddr}); @@ -3793,12 +3789,13 @@ llvm::Constant *IRGenModule::getOrCreateGOTEquivalent(llvm::Constant *global, return gotEquivalent; } -static llvm::Constant *getElementBitCast(llvm::GlobalValue *ptr, +static llvm::Constant *getElementBitCast(IRGenModule &IGM, + llvm::GlobalValue *ptr, llvm::Type *newEltType) { if (ptr->getValueType() == newEltType) { return ptr; } else { - auto newPtrType = newEltType->getPointerTo( + auto newPtrType = IGM.getOpaquePointerType( cast(ptr->getType())->getAddressSpace()); return llvm::ConstantExpr::getBitCast(ptr, newPtrType); } @@ -3911,7 +3908,7 @@ IRGenModule::getAddrOfLLVMVariable(LinkEntity entity, // Otherwise, we have a previous declaration or definition which // we need to ensure has the right type. } else { - return getElementBitCast(existing, defaultType); + return getElementBitCast(*this, existing, defaultType); } } @@ -3920,7 +3917,7 @@ IRGenModule::getAddrOfLLVMVariable(LinkEntity entity, // Clang may have defined the variable already. if (auto existing = Module.getNamedGlobal(link.getName())) { - auto var = getElementBitCast(existing, defaultType); + auto var = getElementBitCast(*this, existing, defaultType); GlobalVars[entity] = var; return var; } diff --git a/lib/IRGen/GenDistributed.cpp b/lib/IRGen/GenDistributed.cpp index 7bfd08282f5..db84ef920ef 100644 --- a/lib/IRGen/GenDistributed.cpp +++ b/lib/IRGen/GenDistributed.cpp @@ -52,11 +52,6 @@ using namespace irgen; llvm::Value *irgen::emitDistributedActorInitializeRemote( IRGenFunction &IGF, SILType selfType, llvm::Value *actorMetatype, Explosion &out) { - auto &classTI = IGF.getTypeInfo(selfType).as(); - auto &classLayout = classTI.getClassLayout(IGF.IGM, selfType, - /*forBackwardDeployment=*/false); - llvm::Type *destType = classLayout.getType()->getPointerTo(); - auto fn = IGF.IGM.getDistributedActorInitializeRemoteFunctionPointer(); actorMetatype = IGF.Builder.CreateBitCast(actorMetatype, IGF.IGM.TypeMetadataPtrTy); @@ -65,7 +60,7 @@ llvm::Value *irgen::emitDistributedActorInitializeRemote( call->setCallingConv(IGF.IGM.SwiftCC); call->setDoesNotThrow(); - auto result = IGF.Builder.CreateBitCast(call, destType); + auto result = IGF.Builder.CreateBitCast(call, IGF.IGM.PtrTy); out.add(result); @@ -665,8 +660,7 @@ void DistributedAccessor::emitLoadOfWitnessTables(llvm::Value *witnessTables, IGF.Builder.emitBlock(contBB); - witnessTables = IGF.Builder.CreateBitCast(witnessTables, - IGM.Int8PtrPtrTy->getPointerTo()); + witnessTables = IGF.Builder.CreateBitCast(witnessTables, IGM.PtrTy); for (unsigned i = 0, n = expectedWitnessTables; i != n; ++i) { auto offset = Size(i * IGM.getPointerSize()); @@ -758,8 +752,7 @@ void DistributedAccessor::emit() { emitAsyncFunctionPointer(IGM, IGF.CurFn, entity, AsyncLayout.getSize()); } - auto *typedResultBuffer = IGF.Builder.CreateBitCast( - resultBuffer, IGM.getStoragePointerType(directResultTy)); + auto *typedResultBuffer = IGF.Builder.CreateBitCast(resultBuffer, IGM.PtrTy); if (targetConv.getNumIndirectSILResults()) { // Since tuples are not allowed as valid result types (because they cannot @@ -866,9 +859,8 @@ FunctionPointer AccessorTarget::getPointerToTarget(llvm::Value *actorSelf) { auto fpKind = classifyFunctionPointerKind(thunk); auto signature = IGM.getSignature(Type, fpKind); - auto *fnPtr = - llvm::ConstantExpr::getBitCast(IGM.getAddrOfAsyncFunctionPointer(thunk), - signature.getType()->getPointerTo()); + auto *fnPtr = llvm::ConstantExpr::getBitCast( + IGM.getAddrOfAsyncFunctionPointer(thunk), IGM.PtrTy); return FunctionPointer::forDirect( FunctionPointer::Kind(Type), fnPtr, @@ -983,11 +975,9 @@ ArgumentDecoderInfo DistributedAccessor::findArgumentDecoder( IGM.getSILModule(), methodTy, expansionContext); auto &classTI = IGM.getTypeInfo(selfTy).as(); - auto &classLayout = classTI.getClassLayout(IGM, selfTy, - /*forBackwardDeployment=*/false); - llvm::Value *typedDecoderPtr = IGF.Builder.CreateBitCast( - decoder, classLayout.getType()->getPointerTo()->getPointerTo()); + llvm::Value *typedDecoderPtr = + IGF.Builder.CreateBitCast(decoder, IGM.PtrTy); Explosion instance; diff --git a/lib/IRGen/GenEnum.cpp b/lib/IRGen/GenEnum.cpp index 34a2800cdab..b26f433dce8 100644 --- a/lib/IRGen/GenEnum.cpp +++ b/lib/IRGen/GenEnum.cpp @@ -330,7 +330,7 @@ EnumImplStrategy::emitOutlinedGetEnumTag(IRGenFunction &IGF, SILType T, manglingBits.second); const TypeInfo &ti = IGF.getTypeInfo(T); - auto ptrTy = ti.getStorageType()->getPointerTo(); + auto *ptrTy = IGF.IGM.PtrTy; llvm::SmallVector paramTys; paramTys.push_back(ptrTy); @@ -736,8 +736,8 @@ namespace { // Pre swift-5.1 runtimes were missing the initialization of the // the extraInhabitantCount field. Do it here instead. - auto payloadRef = IGF.Builder.CreateBitOrPointerCast( - payloadLayout, IGF.IGM.TypeLayoutTy->getPointerTo()); + auto payloadRef = + IGF.Builder.CreateBitOrPointerCast(payloadLayout, IGM.PtrTy); auto payloadExtraInhabitantCount = IGF.Builder.CreateLoad(IGF.Builder.CreateStructGEP( Address(payloadRef, IGF.IGM.TypeLayoutTy, Alignment(1)), 3, @@ -774,8 +774,8 @@ namespace { // Pre swift-5.1 runtimes were missing the initialization of the // the extraInhabitantCount field. Do it here instead. auto payloadLayout = emitTypeLayoutRef(IGF, payloadTy, collector); - auto payloadRef = IGF.Builder.CreateBitOrPointerCast( - payloadLayout, IGF.IGM.TypeLayoutTy->getPointerTo()); + auto payloadRef = + IGF.Builder.CreateBitOrPointerCast(payloadLayout, IGM.PtrTy); auto payloadExtraInhabitantCount = IGF.Builder.CreateLoad(IGF.Builder.CreateStructGEP( Address(payloadRef, IGF.IGM.TypeLayoutTy, Alignment(1)), 3, @@ -2071,8 +2071,7 @@ namespace { auto PayloadT = getPayloadType(IGF.IGM, T); auto &fixedTI = getFixedPayloadTypeInfo(); - auto addr = IGF.Builder.CreateBitCast( - enumAddr.getAddress(), fixedTI.getStorageType()->getPointerTo()); + auto addr = IGF.Builder.CreateBitCast(enumAddr.getAddress(), IGM.PtrTy); return fixedTI.getEnumTagSinglePayload(IGF, numEmptyCases, fixedTI.getAddressForPointer(addr), PayloadT, /*isOutlined*/ false); @@ -7555,9 +7554,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedDestructiveProjectDataForLoad( manglingBits.second, caseIdx); - auto ptrTy = ti.getStorageType()->getPointerTo(); llvm::SmallVector paramTys; - paramTys.push_back(ptrTy); + paramTys.push_back(PtrTy); return getOrCreateHelperFunction(funcName, PtrTy, paramTys, [&](IRGenFunction &IGF) { @@ -7630,9 +7628,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedEnumTagStoreFunction( manglingBits.second, caseIdx); - auto ptrTy = ti.getStorageType()->getPointerTo(); llvm::SmallVector paramTys; - paramTys.push_back(ptrTy); + paramTys.push_back(PtrTy); return getOrCreateHelperFunction(funcName, VoidTy, paramTys, [&](IRGenFunction &IGF) { diff --git a/lib/IRGen/GenExistential.cpp b/lib/IRGen/GenExistential.cpp index b1333fd611d..f364c0e4d5c 100644 --- a/lib/IRGen/GenExistential.cpp +++ b/lib/IRGen/GenExistential.cpp @@ -939,7 +939,7 @@ public: // Use copy-on-write existentials? auto fn = getAssignBoxedOpaqueExistentialBufferFunction( IGF.IGM, getLayout()); - auto *type = IGF.IGM.getExistentialPtrTy(getLayout().getNumTables()); + auto *type = IGF.IGM.PtrTy; auto *destAddr = IGF.Builder.CreateBitCast(dest.getAddress(), type); auto *srcAddr = IGF.Builder.CreateBitCast(src.getAddress(), type); auto call = IGF.Builder.CreateCallWithoutDbgLoc(fn->getFunctionType(), fn, @@ -1006,9 +1006,7 @@ public: // Use copy-on-write existentials? auto fn = getDestroyBoxedOpaqueExistentialBufferFunction( IGF.IGM, getLayout()); - auto *addr = IGF.Builder.CreateBitCast( - buffer.getAddress(), - IGF.IGM.getExistentialPtrTy(getLayout().getNumTables())); + auto *addr = IGF.Builder.CreateBitCast(buffer.getAddress(), IGF.IGM.PtrTy); auto call = IGF.Builder.CreateCallWithoutDbgLoc(fn->getFunctionType(), fn, {addr}); call->setCallingConv(IGF.IGM.DefaultCC); @@ -1538,10 +1536,6 @@ llvm::Type *TypeConverter::getExistentialType(unsigned numWitnessTables) { return type; } -llvm::PointerType *IRGenModule::getExistentialPtrTy(unsigned numTables) { - return Types.getExistentialType(numTables)->getPointerTo(); -} - llvm::Type *IRGenModule::getExistentialType(unsigned numTables) { return Types.getExistentialType(numTables); } @@ -1834,8 +1828,7 @@ ContainedAddress irgen::emitBoxedExistentialProjection(IRGenFunction &IGF, auto &projectedTI = IGF.getTypeInfoForLowered(projectedType); auto projectedPtrAddr = IGF.Builder.CreateStructGEP(out, 0, Size(0)); llvm::Value *projectedPtr = IGF.Builder.CreateLoad(projectedPtrAddr); - projectedPtr = IGF.Builder.CreateBitCast(projectedPtr, - projectedTI.getStorageType()->getPointerTo()); + projectedPtr = IGF.Builder.CreateBitCast(projectedPtr, IGF.IGM.PtrTy); auto projected = projectedTI.getAddressForPointer(projectedPtr); return ContainedAddress(out, projected); } @@ -1898,8 +1891,7 @@ OwnedAddress irgen::emitBoxedExistentialContainerAllocation(IRGenFunction &IGF, ExistentialArchetypeType::get(destType.getASTType()); auto &srcTI = IGF.getTypeInfoForUnlowered(AbstractionPattern(archetype), formalSrcType); - addr = IGF.Builder.CreateBitCast(addr, - srcTI.getStorageType()->getPointerTo()); + addr = IGF.Builder.CreateBitCast(addr, IGF.IGM.PtrTy); return OwnedAddress(srcTI.getAddressForPointer(addr), box); } @@ -2047,9 +2039,7 @@ void irgen::emitMetatypeOfOpaqueExistential(IRGenFunction &IGF, Address buffer, // Project the buffer and apply the 'typeof' value witness. llvm::Value *object; - auto *addr = IGF.Builder.CreateBitCast( - buffer.getAddress(), - IGF.IGM.getExistentialPtrTy(existLayout.getNumTables())); + auto *addr = IGF.Builder.CreateBitCast(buffer.getAddress(), IGF.IGM.PtrTy); auto *projectFunc = getProjectBoxedOpaqueExistentialFunction( IGF, OpenedExistentialAccess::Immutable, existLayout); auto *addrOfValue = IGF.Builder.CreateCallWithoutDbgLoc( @@ -2243,7 +2233,7 @@ static Address castToOpaquePtr(IRGenFunction &IGF, Address addr) { static llvm::Function *getAllocateBoxedOpaqueExistentialBufferFunction( IRGenModule &IGM, OpaqueExistentialLayout existLayout) { - llvm::Type *argTys[] = {IGM.getExistentialPtrTy(existLayout.getNumTables())}; + llvm::Type *argTys[] = {IGM.PtrTy}; // __swift_allocate_boxed_opaque_existential__N is the well-known function for // allocating buffers in existential containers of types with N witness @@ -2286,11 +2276,10 @@ static llvm::Function *getAllocateBoxedOpaqueExistentialBufferFunction( addressInBox = IGF.Builder.CreateBitCast(address, IGF.IGM.OpaquePtrTy); IGF.Builder.CreateStore( - box, - Address(IGF.Builder.CreateBitCast(existentialBuffer.getAddress(), - box->getType()->getPointerTo()), - IGF.IGM.RefCountedPtrTy, - existLayout.getAlignment(IGF.IGM))); + box, Address(IGF.Builder.CreateBitCast( + existentialBuffer.getAddress(), IGM.PtrTy), + IGF.IGM.RefCountedPtrTy, + existLayout.getAlignment(IGF.IGM))); IGF.Builder.CreateRet(addressInBox); } }, @@ -2310,7 +2299,6 @@ Address irgen::emitAllocateBoxedOpaqueExistentialBuffer( existLayout.projectExistentialBuffer(IGF, existentialContainer); auto &valueTI = IGF.getTypeInfo(valueType); - auto *valuePointerType = valueTI.getStorageType()->getPointerTo(); // Check if the value is fixed size. if (auto *fixedTI = dyn_cast(&valueTI)) { @@ -2318,7 +2306,7 @@ Address irgen::emitAllocateBoxedOpaqueExistentialBuffer( // sufficient. if (fixedTI->getFixedPacking(IGF.IGM) == FixedPacking::OffsetZero) { return valueTI.getAddressForPointer(IGF.Builder.CreateBitCast( - existentialBuffer.getAddress(), valuePointerType)); + existentialBuffer.getAddress(), IGF.IGM.PtrTy)); } // Otherwise, allocate a box with enough storage. Address addr = emitAllocateExistentialBoxInBuffer( @@ -2330,20 +2318,19 @@ Address irgen::emitAllocateBoxedOpaqueExistentialBuffer( auto *allocateFun = getAllocateBoxedOpaqueExistentialBufferFunction( IGF.IGM, existLayout); auto *existentialAddr = IGF.Builder.CreateBitCast( - existentialContainer.getAddress(), - IGF.IGM.getExistentialPtrTy(existLayout.getNumTables())); + existentialContainer.getAddress(), IGF.IGM.PtrTy); auto *call = IGF.Builder.CreateCallWithoutDbgLoc( allocateFun->getFunctionType(), allocateFun, {existentialAddr}); call->setCallingConv(IGF.IGM.DefaultCC); call->setDoesNotThrow(); - auto addressOfValue = IGF.Builder.CreateBitCast(call, valuePointerType); + auto addressOfValue = IGF.Builder.CreateBitCast(call, IGF.IGM.PtrTy); return valueTI.getAddressForPointer(addressOfValue); } static llvm::Function *getDeallocateBoxedOpaqueExistentialBufferFunction( IRGenModule &IGM, OpaqueExistentialLayout existLayout) { - llvm::Type *argTys[] = {IGM.getExistentialPtrTy(existLayout.getNumTables())}; + llvm::Type *argTys[] = {IGM.PtrTy}; // __swift_deallocate_boxed_opaque_existential_N is the well-known function // for deallocating buffers in existential containers of types with N witness @@ -2384,8 +2371,7 @@ static llvm::Function *getDeallocateBoxedOpaqueExistentialBufferFunction( auto existentialBuffer = existLayout.projectExistentialBuffer(IGF, existentialContainer); auto *boxReferenceAddr = - Builder.CreateBitCast(existentialBuffer.getAddress(), - IGM.RefCountedPtrTy->getPointerTo()); + Builder.CreateBitCast(existentialBuffer.getAddress(), IGM.PtrTy); // Load the reference. auto *boxReference = Builder.CreateLoad(Address(boxReferenceAddr, IGM.RefCountedPtrTy, @@ -2427,8 +2413,7 @@ void irgen::emitDeallocateBoxedOpaqueExistentialBuffer( auto *deallocateFun = getDeallocateBoxedOpaqueExistentialBufferFunction( IGF.IGM, existLayout); auto *bufferAddr = IGF.Builder.CreateBitCast( - existentialContainer.getAddress(), - IGF.IGM.getExistentialPtrTy(existLayout.getNumTables())); + existentialContainer.getAddress(), IGF.IGM.PtrTy); auto *call = IGF.Builder.CreateCallWithoutDbgLoc( deallocateFun->getFunctionType(), deallocateFun, {bufferAddr}); call->setCallingConv(IGF.IGM.DefaultCC); @@ -2447,8 +2432,7 @@ void irgen::emitDestroyBoxedOpaqueExistentialBuffer( auto *deallocateFun = getDestroyBoxedOpaqueExistentialBufferFunction(IGF.IGM, existLayout); auto *bufferAddr = IGF.Builder.CreateBitCast( - existentialContainer.getAddress(), - IGF.IGM.getExistentialPtrTy(existLayout.getNumTables())); + existentialContainer.getAddress(), IGF.IGM.PtrTy); auto *call = IGF.Builder.CreateCallWithoutDbgLoc( deallocateFun->getFunctionType(), deallocateFun, {bufferAddr}); call->setCallingConv(IGF.IGM.DefaultCC); @@ -2462,7 +2446,7 @@ getProjectBoxedOpaqueExistentialFunction(IRGenFunction &IGF, OpaqueExistentialLayout existLayout) { auto &IGM = IGF.IGM; - auto *existentialBufferTy = IGM.getExistentialPtrTy(existLayout.getNumTables()); + auto *existentialBufferTy = IGF.IGM.PtrTy; llvm::Type *argTys[] = {existentialBufferTy, IGM.TypeMetadataPtrTy}; // __swift_project_boxed_opaque_existential_N is the well-known function for @@ -2506,8 +2490,7 @@ getProjectBoxedOpaqueExistentialFunction(IRGenFunction &IGF, if (accessKind == OpenedExistentialAccess::Immutable) { // Project to the existential buffer address. auto *boxReferenceAddr = - Builder.CreateBitCast(existentialBuffer.getAddress(), - IGM.RefCountedPtrTy->getPointerTo()); + Builder.CreateBitCast(existentialBuffer.getAddress(), IGM.PtrTy); // Load the reference. auto *boxReference = Builder.CreateLoad(Address(boxReferenceAddr, IGM.RefCountedPtrTy, @@ -2522,8 +2505,7 @@ getProjectBoxedOpaqueExistentialFunction(IRGenFunction &IGF, auto *Add = Builder.CreateAdd(heapHeaderSize, alignmentMask); auto *Not = Builder.CreateNot(alignmentMask); auto *startOffset = Builder.CreateAnd(Add, Not); - auto *addressInBox = - IGF.emitByteOffsetGEP(boxReference, startOffset, IGM.OpaqueTy); + auto *addressInBox = IGF.emitByteOffsetGEP(boxReference, startOffset); IGF.Builder.CreateRet(addressInBox); return; } @@ -2592,9 +2574,8 @@ Address irgen::emitOpaqueBoxedExistentialProjection( auto *projectFunc = getProjectBoxedOpaqueExistentialFunction(IGF, accessKind, layout); - auto *bufferAddr = IGF.Builder.CreateBitCast( - base.getAddress(), - IGF.IGM.getExistentialPtrTy(layout.getNumTables())); + auto *bufferAddr = + IGF.Builder.CreateBitCast(base.getAddress(), IGF.IGM.PtrTy); auto *addrOfValue = IGF.Builder.CreateCallWithoutDbgLoc( projectFunc->getFunctionType(), projectFunc, {bufferAddr, metadata}); addrOfValue->setCallingConv(IGF.IGM.DefaultCC); @@ -2610,23 +2591,22 @@ static void initBufferWithCopyOfReference(IRGenFunction &IGF, auto &IGM = IGF.IGM; auto &Builder = IGF.Builder; - auto *destReferenceAddr = Builder.CreateBitCast( - destBuffer.getAddress(), IGM.RefCountedPtrTy->getPointerTo()); - auto *srcReferenceAddr = Builder.CreateBitCast( - srcBuffer.getAddress(), IGM.RefCountedPtrTy->getPointerTo()); + auto *destReferenceAddr = + Builder.CreateBitCast(destBuffer.getAddress(), IGM.PtrTy); + auto *srcReferenceAddr = + Builder.CreateBitCast(srcBuffer.getAddress(), IGM.PtrTy); auto *srcReference = Builder.CreateLoad( - Address(srcReferenceAddr, IGM.RefCountedPtrTy, srcBuffer.getAlignment())); + Address(srcReferenceAddr, IGM.PtrTy, srcBuffer.getAlignment())); IGF.emitNativeStrongRetain(srcReference, IGF.getDefaultAtomicity()); - IGF.Builder.CreateStore(srcReference, - Address(destReferenceAddr, IGM.RefCountedPtrTy, - existLayout.getAlignment(IGF.IGM))); + IGF.Builder.CreateStore( + srcReference, + Address(destReferenceAddr, IGM.PtrTy, existLayout.getAlignment(IGF.IGM))); } static llvm::Function *getAssignBoxedOpaqueExistentialBufferFunction( IRGenModule &IGM, OpaqueExistentialLayout existLayout) { - llvm::Type *argTys[] = {IGM.getExistentialPtrTy(existLayout.getNumTables()), - IGM.getExistentialPtrTy(existLayout.getNumTables())}; + llvm::Type *argTys[] = {IGM.PtrTy, IGM.PtrTy}; // __swift_assign_box_in_existentials_N is the well-known function for // assigning buffers in existential containers of types with N witness @@ -2695,10 +2675,10 @@ static llvm::Function *getAssignBoxedOpaqueExistentialBufferFunction( Builder.emitBlock(matchOutlineBB); { ConditionalDominanceScope outlineCondition(IGF); - auto *destReferenceAddr = Builder.CreateBitCast( - destBuffer.getAddress(), IGM.RefCountedPtrTy->getPointerTo()); - auto *srcReferenceAddr = Builder.CreateBitCast( - srcBuffer.getAddress(), IGM.RefCountedPtrTy->getPointerTo()); + auto *destReferenceAddr = + Builder.CreateBitCast(destBuffer.getAddress(), IGM.PtrTy); + auto *srcReferenceAddr = + Builder.CreateBitCast(srcBuffer.getAddress(), IGM.PtrTy); // Load the reference. auto *destReference = Builder.CreateLoad( Address(destReferenceAddr, IGM.RefCountedPtrTy, @@ -2798,8 +2778,8 @@ static llvm::Function *getAssignBoxedOpaqueExistentialBufferFunction( { ConditionalDominanceScope destOutlineCondition(IGF); // tmpRef = dest[0] - auto *destReferenceAddr = Builder.CreateBitCast( - destBuffer.getAddress(), IGM.RefCountedPtrTy->getPointerTo()); + auto *destReferenceAddr = + Builder.CreateBitCast(destBuffer.getAddress(), IGM.PtrTy); auto *destReference = Builder.CreateLoad( Address(destReferenceAddr, IGM.RefCountedPtrTy, srcBuffer.getAlignment())); @@ -2850,7 +2830,7 @@ static llvm::Function *getAssignBoxedOpaqueExistentialBufferFunction( static llvm::Function *getDestroyBoxedOpaqueExistentialBufferFunction( IRGenModule &IGM, OpaqueExistentialLayout existLayout) { - llvm::Type *argTys[] = {IGM.getExistentialPtrTy(existLayout.getNumTables())}; + llvm::Type *argTys[] = {IGM.PtrTy}; llvm::SmallString<40> fnName; llvm::raw_svector_ostream(fnName) @@ -2892,8 +2872,8 @@ static llvm::Function *getDestroyBoxedOpaqueExistentialBufferFunction( ConditionalDominanceScope domScope(IGF); // swift_release(buffer[0]) - auto *referenceAddr = Builder.CreateBitCast( - buffer.getAddress(), IGM.RefCountedPtrTy->getPointerTo()); + auto *referenceAddr = + Builder.CreateBitCast(buffer.getAddress(), IGM.PtrTy); auto *reference = Builder.CreateLoad(Address( referenceAddr, IGM.RefCountedPtrTy, buffer.getAlignment())); IGF.emitNativeStrongRelease(reference, IGF.getDefaultAtomicity()); diff --git a/lib/IRGen/GenFunc.cpp b/lib/IRGen/GenFunc.cpp index aa724db88b2..60c72c45c3a 100644 --- a/lib/IRGen/GenFunc.cpp +++ b/lib/IRGen/GenFunc.cpp @@ -803,9 +803,7 @@ static void emitApplyArgument(IRGenFunction &IGF, // If a substitution is in play, just bitcast the address. if (isSubstituted) { - auto origType = IGF.IGM.getStoragePointerType( - silConv.getSILType(origParam, origFnTy, context)); - addr = IGF.Builder.CreateBitCast(addr, origType); + addr = IGF.Builder.CreateBitCast(addr, IGF.IGM.PtrTy); } out.add(addr); @@ -1026,9 +1024,7 @@ public: if (nativeResultSchema.requiresIndirect()) { assert(origNativeSchema.requiresIndirect()); auto resultAddr = origParams.claimNext(); - resultAddr = subIGF.Builder.CreateBitCast( - resultAddr, IGM.getStoragePointerType(origConv.getSILResultType( - IGM.getMaximalTypeExpansionContext()))); + resultAddr = subIGF.Builder.CreateBitCast(resultAddr, IGM.PtrTy); args.add(resultAddr); useSRet = false; } else if (origNativeSchema.requiresIndirect()) { @@ -1050,8 +1046,7 @@ public: for (auto resultType : origConv.getIndirectSILResultTypes( IGM.getMaximalTypeExpansionContext())) { auto addr = origParams.claimNext(); - addr = subIGF.Builder.CreateBitCast( - addr, IGM.getStoragePointerType(resultType)); + addr = subIGF.Builder.CreateBitCast(addr, IGM.PtrTy); auto useOpaque = useSRet && !isa(IGM.getTypeInfo(resultType)); if (useOpaque) @@ -1077,9 +1072,8 @@ public: bool isIndirectParam = origConv.isSILIndirect(origParamInfo); if (!isIndirectParam && nativeSchemaOrigParam.requiresIndirect()) { auto addr = origParams.claimNext(); - if (addr->getType() != ti.getStorageType()->getPointerTo()) - addr = subIGF.Builder.CreateBitCast(addr, - ti.getStorageType()->getPointerTo()); + if (addr->getType() != IGM.PtrTy) + addr = subIGF.Builder.CreateBitCast(addr, IGM.PtrTy); args.add(addr); continue; } @@ -2165,7 +2159,7 @@ static llvm::Value *emitPartialApplicationForwarder( } // Derive the callee function pointer. - auto fnTy = origSig.getType()->getPointerTo(); + auto *fnTy = IGM.PtrTy; FunctionPointer fnPtr = [&]() -> FunctionPointer { // If we found a function pointer statically, great. if (staticFnPtr) { @@ -2674,8 +2668,8 @@ static llvm::Function *emitBlockCopyHelper(IRGenModule &IGM, // Create the helper. llvm::Type *args[] = { - blockTL.getStorageType()->getPointerTo(), - blockTL.getStorageType()->getPointerTo(), + IGM.PtrTy, + IGM.PtrTy, }; auto copyTy = llvm::FunctionType::get(IGM.VoidTy, args, /*vararg*/ false); // TODO: Give these predictable mangled names and shared linkage. @@ -2713,9 +2707,8 @@ static llvm::Function *emitBlockDisposeHelper(IRGenModule &IGM, // TODO // Create the helper. - auto destroyTy = llvm::FunctionType::get(IGM.VoidTy, - blockTL.getStorageType()->getPointerTo(), - /*vararg*/ false); + auto destroyTy = llvm::FunctionType::get(IGM.VoidTy, IGM.PtrTy, + /*vararg*/ false); // TODO: Give these predictable mangled names and shared linkage. auto func = llvm::Function::Create(destroyTy, llvm::GlobalValue::InternalLinkage, diff --git a/lib/IRGen/GenHeap.cpp b/lib/IRGen/GenHeap.cpp index 67dc0386ec9..ef4b4d4947c 100644 --- a/lib/IRGen/GenHeap.cpp +++ b/lib/IRGen/GenHeap.cpp @@ -877,7 +877,7 @@ static void emitUnaryRefCountCall(IRGenFunction &IGF, ? IGF.IGM.VoidTy : value->getType(); fnType = llvm::FunctionType::get(resultTy, value->getType(), false); - fn = llvm::ConstantExpr::getBitCast(fn, fnType->getPointerTo()); + fn = llvm::ConstantExpr::getBitCast(fn, IGF.IGM.PtrTy); } // Emit the call. @@ -909,7 +909,7 @@ static void emitCopyLikeCall(IRGenFunction &IGF, auto resultTy = fnType->getReturnType() == IGF.IGM.VoidTy ? IGF.IGM.VoidTy : dest->getType(); fnType = llvm::FunctionType::get(resultTy, paramTypes, false); - fn = llvm::ConstantExpr::getBitCast(fn, fnType->getPointerTo()); + fn = llvm::ConstantExpr::getBitCast(fn, IGF.IGM.PtrTy); } // Emit the call. @@ -941,7 +941,7 @@ static llvm::Value *emitLoadWeakLikeCall(IRGenFunction &IGF, if (resultType != fnType->getReturnType()) { llvm::Type *paramTypes[] = { addr->getType() }; fnType = llvm::FunctionType::get(resultType, paramTypes, false); - fn = llvm::ConstantExpr::getBitCast(fn, fnType->getPointerTo()); + fn = llvm::ConstantExpr::getBitCast(fn, IGF.IGM.PtrTy); } // Emit the call. @@ -974,7 +974,7 @@ static void emitStoreWeakLikeCall(IRGenFunction &IGF, auto resultTy = fnType->getReturnType() == IGF.IGM.VoidTy ? IGF.IGM.VoidTy : addr->getType(); fnType = llvm::FunctionType::get(resultTy, paramTypes, false); - fn = llvm::ConstantExpr::getBitCast(fn, fnType->getPointerTo()); + fn = llvm::ConstantExpr::getBitCast(fn, IGF.IGM.PtrTy); } // Emit the call. @@ -1528,8 +1528,7 @@ public: auto metadata = IGF.emitTypeMetadataRefForLayout(boxedType); llvm::Value *box, *address; IGF.emitAllocBoxCall(metadata, box, address); - address = IGF.Builder.CreateBitCast(address, - ti.getStorageType()->getPointerTo()); + address = IGF.Builder.CreateBitCast(address, IGF.IGM.PtrTy); return {ti.getAddressForPointer(address), box}; } @@ -1546,8 +1545,7 @@ public: auto &ti = IGF.getTypeInfo(boxedType); auto metadata = IGF.emitTypeMetadataRefForLayout(boxedType); llvm::Value *address = IGF.emitProjectBoxCall(box, metadata); - address = IGF.Builder.CreateBitCast(address, - ti.getStorageType()->getPointerTo()); + address = IGF.Builder.CreateBitCast(address, IGF.IGM.PtrTy); return ti.getAddressForPointer(address); } }; @@ -1839,13 +1837,11 @@ Address irgen::emitAllocateExistentialBoxInBuffer( OwnedAddress owned = boxTI.allocate(IGF, env, boxType, name); Explosion box; box.add(owned.getOwner()); - boxTI.initialize(IGF, box, - Address(IGF.Builder.CreateBitCast( - destBuffer.getAddress(), - owned.getOwner()->getType()->getPointerTo()), - owned.getOwner()->getType(), - destBuffer.getAlignment()), - isOutlined); + boxTI.initialize( + IGF, box, + Address(IGF.Builder.CreateBitCast(destBuffer.getAddress(), IGF.IGM.PtrTy), + owned.getOwner()->getType(), destBuffer.getAlignment()), + isOutlined); return owned.getAddress(); } @@ -1958,8 +1954,7 @@ llvm::Value *IRGenFunction::getDynamicSelfMetadata() { llvm::Value *irgen::emitLoadOfObjCHeapMetadataRef(IRGenFunction &IGF, llvm::Value *object) { if (IGF.IGM.TargetInfo.hasISAMasking()) { - object = IGF.Builder.CreateBitCast(object, - IGF.IGM.IntPtrTy->getPointerTo()); + object = IGF.Builder.CreateBitCast(object, IGF.IGM.PtrTy); llvm::Value *metadata = IGF.Builder.CreateLoad( Address(object, IGF.IGM.IntPtrTy, IGF.IGM.getPointerAlignment())); llvm::Value *mask = IGF.Builder.CreateLoad(IGF.IGM.getAddrOfObjCISAMask()); @@ -1969,8 +1964,7 @@ llvm::Value *irgen::emitLoadOfObjCHeapMetadataRef(IRGenFunction &IGF, } else if (IGF.IGM.TargetInfo.hasOpaqueISAs()) { return emitHeapMetadataRefForUnknownHeapObject(IGF, object); } else { - object = IGF.Builder.CreateBitCast(object, - IGF.IGM.TypeMetadataPtrTy->getPointerTo()); + object = IGF.Builder.CreateBitCast(object, IGF.IGM.PtrTy); llvm::Value *metadata = IGF.Builder.CreateLoad(Address( object, IGF.IGM.TypeMetadataPtrTy, IGF.IGM.getPointerAlignment())); return metadata; diff --git a/lib/IRGen/GenIntegerLiteral.cpp b/lib/IRGen/GenIntegerLiteral.cpp index a39663e3a59..6adc92ea847 100644 --- a/lib/IRGen/GenIntegerLiteral.cpp +++ b/lib/IRGen/GenIntegerLiteral.cpp @@ -111,11 +111,9 @@ public: llvm::StructType *IRGenModule::getIntegerLiteralTy() { if (!IntegerLiteralTy) { - IntegerLiteralTy = - llvm::StructType::create(getLLVMContext(), { - SizeTy->getPointerTo(), - SizeTy - }, "swift.int_literal"); + IntegerLiteralTy = llvm::StructType::create( + getLLVMContext(), {PtrTy, SizeTy}, + "swift.int_literal"); } return IntegerLiteralTy; } diff --git a/lib/IRGen/GenKeyPath.cpp b/lib/IRGen/GenKeyPath.cpp index be52b437900..c100fb45613 100644 --- a/lib/IRGen/GenKeyPath.cpp +++ b/lib/IRGen/GenKeyPath.cpp @@ -311,8 +311,8 @@ getWitnessTableForComputedComponent(IRGenModule &IGM, } auto elt = IGF.Builder.CreateInBoundsGEP(IGM.Int8Ty, componentArgsBuf, offset); - auto eltAddr = ti.getAddressForPointer( - IGF.Builder.CreateBitCast(elt, ti.getStorageType()->getPointerTo())); + auto eltAddr = + ti.getAddressForPointer(IGF.Builder.CreateBitCast(elt, IGM.PtrTy)); ti.destroy(IGF, eltAddr, ty, true /*witness table: need it to be fast*/); auto size = ti.getSize(IGF, ty); @@ -365,11 +365,9 @@ getWitnessTableForComputedComponent(IRGenModule &IGM, auto destElt = IGF.Builder.CreateInBoundsGEP(IGM.Int8Ty, destArgsBuf, offset); auto sourceEltAddr = ti.getAddressForPointer( - IGF.Builder.CreateBitCast(sourceElt, - ti.getStorageType()->getPointerTo())); + IGF.Builder.CreateBitCast(sourceElt, IGM.PtrTy)); auto destEltAddr = ti.getAddressForPointer( - IGF.Builder.CreateBitCast(destElt, - ti.getStorageType()->getPointerTo())); + IGF.Builder.CreateBitCast(destElt, IGM.PtrTy)); ti.initializeWithCopy(IGF, destEltAddr, sourceEltAddr, ty, false); auto size = ti.getSize(IGF, ty); @@ -495,8 +493,8 @@ getInitializerForComputedComponent(IRGenModule &IGM, } auto ptr = IGF.Builder.CreateInBoundsGEP(IGM.Int8Ty, src, offset); - auto addr = ti.getAddressForPointer(IGF.Builder.CreateBitCast( - ptr, ti.getStorageType()->getPointerTo())); + auto addr = + ti.getAddressForPointer(IGF.Builder.CreateBitCast(ptr, IGM.PtrTy)); srcAddresses.push_back(addr); auto size = ti.getSize(IGF, ty); @@ -524,9 +522,9 @@ getInitializerForComputedComponent(IRGenModule &IGM, } auto ptr = IGF.Builder.CreateInBoundsGEP(IGM.Int8Ty, dest, offset); - auto destAddr = ti.getAddressForPointer(IGF.Builder.CreateBitCast( - ptr, ti.getStorageType()->getPointerTo())); - + auto destAddr = + ti.getAddressForPointer(IGF.Builder.CreateBitCast(ptr, IGM.PtrTy)); + // The last component using an operand can move the value out of the // buffer. if (&component == operands[index.Operand].LastUser) { @@ -1360,8 +1358,8 @@ std::pair irgen::emitKeyPathArgument( auto &ti = IGF.getTypeInfo(operandTy); auto ptr = IGF.Builder.CreateInBoundsGEP(IGM.Int8Ty, argsBuf.getAddress(), operandOffsets[i]); - auto addr = ti.getAddressForPointer( - IGF.Builder.CreateBitCast(ptr, ti.getStorageType()->getPointerTo())); + auto addr = + ti.getAddressForPointer(IGF.Builder.CreateBitCast(ptr, IGM.PtrTy)); if (operandTy.isAddress()) { ti.initializeWithTake(IGF, addr, ti.getAddressForPointer(indiceValues.claimNext()), operandTy, false, /*zeroizeIfSensitive=*/ true); diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp index eb17c932b6c..4279633c000 100644 --- a/lib/IRGen/GenMeta.cpp +++ b/lib/IRGen/GenMeta.cpp @@ -3376,9 +3376,9 @@ static void emitInitializeRawLayoutOldOld(IRGenFunction &IGF, SILType likeType, // This is the list of field type layouts that we're going to pass to the init // function. This will only ever hold 1 field which is the temporary one we're // going to build up from our like type's layout. - auto fieldLayouts = IGF.createAlloca( - llvm::ArrayType::get(IGM.TypeLayoutTy->getPointerTo(), 1), - IGM.getPointerAlignment(), "fieldLayouts"); + auto fieldLayouts = + IGF.createAlloca(llvm::ArrayType::get(IGM.PtrTy, 1), + IGM.getPointerAlignment(), "fieldLayouts"); IGF.Builder.CreateLifetimeStart(fieldLayouts, IGM.getPointerSize()); // We're going to pretend that this is our field offset vector for the init to diff --git a/lib/IRGen/GenObjC.cpp b/lib/IRGen/GenObjC.cpp index 0dd45be3826..044ec406fc9 100644 --- a/lib/IRGen/GenObjC.cpp +++ b/lib/IRGen/GenObjC.cpp @@ -830,8 +830,7 @@ Callee irgen::getObjCMethodCallee(IRGenFunction &IGF, } }(); - messenger = llvm::ConstantExpr::getBitCast(messenger, - sig.getType()->getPointerTo()); + messenger = llvm::ConstantExpr::getBitCast(messenger, IGF.IGM.PtrTy); // super.constructor references an instance method (even though the // decl is really a 'static' member). Similarly, destructors refer @@ -877,7 +876,7 @@ llvm::Value *irgen::emitObjCAllocObjectCall(IRGenFunction &IGF, if (self->getType() != IGF.IGM.ObjCClassPtrTy) { fnType = llvm::FunctionType::get(self->getType(), self->getType(), false); - fn = llvm::ConstantExpr::getBitCast(fn, fnType->getPointerTo()); + fn = llvm::ConstantExpr::getBitCast(fn, IGF.IGM.PtrTy); } auto call = IGF.Builder.CreateCall(fnType, fn, self); @@ -1701,7 +1700,7 @@ llvm::Value *IRGenFunction::emitBlockCopyCall(llvm::Value *value) { if (value->getType() != IGM.ObjCBlockPtrTy) { fnType = llvm::FunctionType::get(value->getType(), value->getType(), false); - fn = llvm::ConstantExpr::getBitCast(fn, fnType->getPointerTo()); + fn = llvm::ConstantExpr::getBitCast(fn, IGM.PtrTy); } auto call = Builder.CreateCall(fnType, fn, value); @@ -1714,7 +1713,7 @@ void IRGenFunction::emitBlockRelease(llvm::Value *value) { auto fnType = IGM.getBlockReleaseFnType(); if (value->getType() != IGM.ObjCBlockPtrTy) { fnType = llvm::FunctionType::get(IGM.VoidTy, value->getType(), false); - fn = llvm::ConstantExpr::getBitCast(fn, fnType->getPointerTo()); + fn = llvm::ConstantExpr::getBitCast(fn, IGM.PtrTy); } auto call = Builder.CreateCall(fnType, fn, value); call->setDoesNotThrow(); diff --git a/lib/IRGen/GenOpaque.cpp b/lib/IRGen/GenOpaque.cpp index 5bb471da73b..73ec377e7db 100644 --- a/lib/IRGen/GenOpaque.cpp +++ b/lib/IRGen/GenOpaque.cpp @@ -72,7 +72,7 @@ static llvm::Type *createWitnessType(IRGenModule &IGM, ValueWitness index) { // T *(*initializeBufferWithCopyOfBuffer)(B *dest, B *src, M *self); case ValueWitness::InitializeBufferWithCopyOfBuffer: { - llvm::Type *bufPtrTy = IGM.getFixedBufferTy()->getPointerTo(0); + auto *bufPtrTy = IGM.PtrTy; llvm::Type *args[] = { bufPtrTy, bufPtrTy, IGM.TypeMetadataPtrTy }; return llvm::FunctionType::get(IGM.OpaquePtrTy, args, /*isVarArg*/ false); } @@ -293,21 +293,20 @@ getOrCreateValueWitnessTableTy(IRGenModule &IGM, llvm::StructType *&cache, return structTy; } +llvm::PointerType * +IRGenModule::getOpaquePointerType(unsigned AddressSpace) const { + return llvm::PointerType::get(getLLVMContext(), AddressSpace); +} + llvm::StructType *IRGenModule::getValueWitnessTableTy() { return getOrCreateValueWitnessTableTy(*this, ValueWitnessTableTy, "swift.vwtable", false); } -llvm::PointerType *IRGenModule::getValueWitnessTablePtrTy() { - return getValueWitnessTableTy()->getPointerTo(); -} llvm::StructType *IRGenModule::getEnumValueWitnessTableTy() { return getOrCreateValueWitnessTableTy(*this, EnumValueWitnessTableTy, "swift.enum_vwtable", true); } -llvm::PointerType *IRGenModule::getEnumValueWitnessTablePtrTy() { - return getEnumValueWitnessTableTy()->getPointerTo(); -} Address irgen::slotForLoadOfOpaqueWitness(IRGenFunction &IGF, llvm::Value *table, @@ -455,8 +454,7 @@ static FunctionPointer emitLoadOfValueWitnessFunction(IRGenFunction &IGF, auto label = getValueWitnessLabel(index); auto signature = IGF.IGM.getValueWitnessSignature(index); - auto type = signature.getType()->getPointerTo(); - witness = IGF.Builder.CreateBitCast(witness, type, label); + witness = IGF.Builder.CreateBitCast(witness, IGF.IGM.PtrTy, label); auto authInfo = PointerAuthInfo::emit(IGF, IGF.getOptions().PointerAuth.ValueWitnesses, @@ -1168,10 +1166,9 @@ static llvm::Constant *getAllocateValueBufferFunction(IRGenModule &IGM) { auto valueAddr = IGF.emitAllocRawCall(size, alignMask, "outline.ValueBuffer"); IGF.Builder.CreateStore( - valueAddr, Address(IGF.Builder.CreateBitCast( - buffer.getAddress(), - valueAddr->getType()->getPointerTo()), - IGM.Int8PtrTy, Alignment(1))); + valueAddr, + Address(IGF.Builder.CreateBitCast(buffer.getAddress(), IGM.PtrTy), + IGM.Int8PtrTy, Alignment(1))); addressOutline = IGF.Builder.CreateBitCast(valueAddr, IGM.OpaquePtrTy); IGF.Builder.CreateBr(doneBB); @@ -1190,7 +1187,7 @@ Address irgen::emitAllocateValueInBuffer(IRGenFunction &IGF, SILType type, Address buffer) { // Handle FixedSize types. auto &IGM = IGF.IGM; - auto storagePtrTy = IGM.getStoragePointerType(type); + auto *storagePtrTy = IGM.PtrTy; auto storageTy = IGM.getStorageType(type); auto &Builder = IGF.Builder; if (auto *fixedTI = dyn_cast(&IGF.getTypeInfo(type))) { @@ -1261,8 +1258,7 @@ static llvm::Constant *getProjectValueInBufferFunction(IRGenModule &IGM) { Builder.emitBlock(outlineBB); { addressOutline = Builder.CreateLoad( - Address(Builder.CreateBitCast(buffer.getAddress(), - IGM.OpaquePtrTy->getPointerTo()), + Address(Builder.CreateBitCast(buffer.getAddress(), IGM.PtrTy), IGM.OpaquePtrTy, Alignment(1))); Builder.CreateBr(doneBB); } @@ -1281,7 +1277,7 @@ Address irgen::emitProjectValueInBuffer(IRGenFunction &IGF, SILType type, Address buffer) { // Handle FixedSize types. auto &IGM = IGF.IGM; - auto storagePtrTy = IGM.getStoragePointerType(type); + auto *storagePtrTy = IGM.PtrTy; auto storageTy = IGM.getStorageType(type); auto &Builder = IGF.Builder; if (auto *fixedTI = dyn_cast(&IGF.getTypeInfo(type))) { @@ -1296,8 +1292,7 @@ Address irgen::emitProjectValueInBuffer(IRGenFunction &IGF, SILType type, // Outline representation. assert(packing == FixedPacking::Allocate && "Expect non dynamic packing"); auto valueAddr = Builder.CreateLoad( - Address(Builder.CreateBitCast(buffer.getAddress(), - storagePtrTy->getPointerTo()), + Address(Builder.CreateBitCast(buffer.getAddress(), IGM.PtrTy), storagePtrTy, buffer.getAlignment())); return Address(Builder.CreateBitCast(valueAddr, storagePtrTy), storageTy, buffer.getAlignment()); @@ -1388,8 +1383,7 @@ irgen::getOrCreateGetExtraInhabitantTagFunction(IRGenModule &IGM, MetadataState::Complete); // Form a well-typed address from the opaque pointer. - ptr = IGF.Builder.CreateBitCast(ptr, - objectTI.getStorageType()->getPointerTo()); + ptr = IGF.Builder.CreateBitCast(ptr, IGM.PtrTy); Address addr = objectTI.getAddressForPointer(ptr); auto tag = emitter(IGF, addr, xiCount); @@ -1473,8 +1467,7 @@ irgen::getOrCreateStoreExtraInhabitantTagFunction(IRGenModule &IGM, MetadataState::Complete); // Form a well-typed address from the opaque pointer. - ptr = IGF.Builder.CreateBitCast(ptr, - objectTI.getStorageType()->getPointerTo()); + ptr = IGF.Builder.CreateBitCast(ptr, IGM.PtrTy); Address addr = objectTI.getAddressForPointer(ptr); emitter(IGF, addr, tag, xiCount); diff --git a/lib/IRGen/GenPack.cpp b/lib/IRGen/GenPack.cpp index eb193c4e10e..82d0de41cfb 100644 --- a/lib/IRGen/GenPack.cpp +++ b/lib/IRGen/GenPack.cpp @@ -519,8 +519,7 @@ irgen::emitTypeMetadataPackRef(IRGenFunction &IGF, CanPackType packType, std::tie(pack, shape) = emitTypeMetadataPack(IGF, packType, request); auto *metadata = pack.getAddress().getAddress(); - metadata = IGF.Builder.CreatePointerCast( - metadata, IGF.IGM.TypeMetadataPtrTy->getPointerTo()); + metadata = IGF.Builder.CreatePointerCast(metadata, IGF.IGM.PtrTy); if (!IGF.canStackPromotePackMetadata()) { metadata = IGF.Builder.CreateCall( @@ -754,8 +753,7 @@ llvm::Value *irgen::emitWitnessTablePackRef(IRGenFunction &IGF, std::tie(pack, shape) = emitWitnessTablePack(IGF, packType, conformance); auto *result = pack.getAddress().getAddress(); - result = IGF.Builder.CreatePointerCast( - result, IGF.IGM.WitnessTablePtrTy->getPointerTo()); + result = IGF.Builder.CreatePointerCast(result, IGF.IGM.PtrTy); if (!IGF.canStackPromotePackMetadata()) { result = IGF.Builder.CreateCall( @@ -1156,8 +1154,7 @@ Address irgen::emitStorageAddressOfPackElement(IRGenFunction &IGF, Address pack, assert(elementType.isAddress() && "direct packs not currently supported"); auto elementSize = getPackElementSize(IGF.IGM, packType); auto elementAddress = IGF.Builder.CreateArrayGEP(pack, index, elementSize); - return IGF.Builder.CreateElementBitCast(elementAddress, - IGF.IGM.getStoragePointerType(elementType)); + return IGF.Builder.CreateElementBitCast(elementAddress, IGF.IGM.PtrTy); } Size irgen::getPackElementSize(IRGenModule &IGM, CanSILPackType ty) { diff --git a/lib/IRGen/GenProto.cpp b/lib/IRGen/GenProto.cpp index b198789ffeb..635f792db3a 100644 --- a/lib/IRGen/GenProto.cpp +++ b/lib/IRGen/GenProto.cpp @@ -4413,7 +4413,7 @@ static FunctionPointer emitRelativeProtocolWitnessTableAccess(IRGenFunction &IGF helperFn->getFunctionType(), helperFn, {wtable}); call->setCallingConv(IGF.IGM.DefaultCC); call->setDoesNotThrow(); - auto fn = IGF.Builder.CreateBitCast(call, signature.getType()->getPointerTo()); + auto fn = IGF.Builder.CreateBitCast(call, IGM.PtrTy); return FunctionPointer::createUnsigned(fnType, fn, signature, true); } @@ -4443,8 +4443,7 @@ FunctionPointer irgen::emitWitnessMethodValue(IRGenFunction &IGF, auto fnType = IGF.IGM.getSILTypes().getConstantFunctionType( IGF.IGM.getMaximalTypeExpansionContext(), member); Signature signature = IGF.IGM.getSignature(fnType); - witnessFnPtr = IGF.Builder.CreateBitCast(witnessFnPtr, - signature.getType()->getPointerTo()); + witnessFnPtr = IGF.Builder.CreateBitCast(witnessFnPtr, IGF.IGM.PtrTy); auto &schema = fnType->isAsync() ? IGF.getOptions().PointerAuth.AsyncProtocolWitnesses diff --git a/lib/IRGen/GenStruct.cpp b/lib/IRGen/GenStruct.cpp index 53b4fac82b3..1b7f71dd99d 100644 --- a/lib/IRGen/GenStruct.cpp +++ b/lib/IRGen/GenStruct.cpp @@ -342,8 +342,7 @@ namespace { IGF.IGM.Int8Ty, metadataBytes, IGF.IGM.getSize(scanner.FieldOffset - scanner.AddressPoint)); fieldOffsetPtr = - IGF.Builder.CreateBitCast(fieldOffsetPtr, - IGF.IGM.Int32Ty->getPointerTo()); + IGF.Builder.CreateBitCast(fieldOffsetPtr, IGF.IGM.PtrTy); llvm::Value *fieldOffset = IGF.Builder.CreateLoad( Address(fieldOffsetPtr, IGF.IGM.Int32Ty, Alignment(4))); fieldOffset = IGF.Builder.CreateZExtOrBitCast(fieldOffset, diff --git a/lib/IRGen/GenThunk.cpp b/lib/IRGen/GenThunk.cpp index d22bf843fb6..f0bfd4fa0b2 100644 --- a/lib/IRGen/GenThunk.cpp +++ b/lib/IRGen/GenThunk.cpp @@ -387,8 +387,7 @@ void IRGenThunk::emit() { // unreachable auto *continuation = result.claimNext(); auto sig = Signature::forCoroutineContinuation(IGF.IGM, origTy); - continuation = - IGF.Builder.CreateBitCast(continuation, sig.getType()->getPointerTo()); + continuation = IGF.Builder.CreateBitCast(continuation, IGF.IGM.PtrTy); auto schemaAndEntity = getCoroutineResumeFunctionPointerAuth(IGF.IGM, origTy); auto pointerAuth = PointerAuthInfo::emit( @@ -604,8 +603,7 @@ IRGenModule::getAddrOfAsyncFunctionPointer(LinkEntity entity) { llvm::ConstantExpr::getAdd(PointerPointerConstant, Marker); IndirectAsyncFunctionPointers[entity] = Address; - return llvm::ConstantExpr::getIntToPtr(Address, - AsyncFunctionPointerTy->getPointerTo()); + return llvm::ConstantExpr::getIntToPtr(Address, PtrTy); } llvm::Constant * @@ -668,8 +666,7 @@ llvm::Constant *IRGenModule::getAddrOfCoroFunctionPointer(LinkEntity entity) { llvm::ConstantExpr::getAdd(PointerPointerConstant, Marker); IndirectCoroFunctionPointers[entity] = Address; - return llvm::ConstantExpr::getIntToPtr(Address, - CoroFunctionPointerTy->getPointerTo()); + return llvm::ConstantExpr::getIntToPtr(Address, PtrTy); } llvm::Constant * @@ -737,10 +734,7 @@ IRGenModule::getAddrOfMethodLookupFunction(ClassDecl *classDecl, return entry; } - llvm::Type *params[] = { - TypeMetadataPtrTy, - MethodDescriptorStructTy->getPointerTo() - }; + llvm::Type *params[] = {TypeMetadataPtrTy, PtrTy}; auto fnType = llvm::FunctionType::get(Int8PtrTy, params, false); Signature signature(fnType, llvm::AttributeList(), SwiftCC); LinkInfo link = LinkInfo::get(*this, entity, forDefinition); diff --git a/lib/IRGen/GenTuple.cpp b/lib/IRGen/GenTuple.cpp index 92d5368387b..6233c36a6c6 100644 --- a/lib/IRGen/GenTuple.cpp +++ b/lib/IRGen/GenTuple.cpp @@ -646,8 +646,7 @@ Address irgen::projectTupleElementAddressByDynamicIndex(IRGenFunction &IGF, result = tupleOffset; } - auto *gep = - IGF.emitByteOffsetGEP(tuple.getAddress(), result, IGF.IGM.OpaqueTy); + auto *gep = IGF.emitByteOffsetGEP(tuple.getAddress(), result); auto elementAddress = Address(gep, IGF.IGM.OpaqueTy, IGF.IGM.getPointerAlignment()); return IGF.Builder.CreateElementBitCast(elementAddress, diff --git a/lib/IRGen/GenType.cpp b/lib/IRGen/GenType.cpp index 3bac23f56a1..e958260e7e8 100644 --- a/lib/IRGen/GenType.cpp +++ b/lib/IRGen/GenType.cpp @@ -120,7 +120,8 @@ Address TypeInfo::getAddressForPointer(llvm::Value *ptr) const { } Address TypeInfo::getUndefAddress() const { - return Address(llvm::UndefValue::get(getStorageType()->getPointerTo(0)), + return Address(llvm::UndefValue::get(llvm::PointerType::getUnqual( + getStorageType()->getContext())), getStorageType(), getBestKnownAlignment()); } @@ -701,16 +702,14 @@ llvm::Value *irgen::getFixedTypeEnumTagSinglePayload( // The size of the chunk does not have to be a power of 2. auto *caseIndexType = llvm::IntegerType::get(Ctx, fixedSize.getValueInBits()); - auto *caseIndexAddr = - Builder.CreateBitCast(valueAddr, caseIndexType->getPointerTo()); + auto *caseIndexAddr = Builder.CreateBitCast(valueAddr, IGM.PtrTy); caseIndexFromValue = Builder.CreateZExtOrTrunc( Builder.CreateLoad( Address(caseIndexAddr, caseIndexType, Alignment(1))), IGM.Int32Ty); } else { auto *caseIndexType = llvm::IntegerType::get(Ctx, 32); - auto *caseIndexAddr = - Builder.CreateBitCast(valueAddr, caseIndexType->getPointerTo()); + auto *caseIndexAddr = Builder.CreateBitCast(valueAddr, IGM.PtrTy); caseIndexFromValue = Builder.CreateZExtOrTrunc( Builder.CreateLoad( Address(caseIndexAddr, caseIndexType, Alignment(1))), @@ -1907,19 +1906,6 @@ bool IRGenModule::isTypeABIAccessible(SILType type) const { type, TypeExpansionContext::maximalResilienceExpansionOnly()); } -/// Get a pointer to the storage type for the given type. Note that, -/// unlike fetching the type info and asking it for the storage type, -/// this operation will succeed for forward-declarations. -llvm::PointerType *IRGenModule::getStoragePointerType(SILType T) { - return getStoragePointerTypeForLowered(T.getASTType()); -} -llvm::PointerType *IRGenModule::getStoragePointerTypeForUnlowered(Type T) { - return getStorageTypeForUnlowered(T)->getPointerTo(); -} -llvm::PointerType *IRGenModule::getStoragePointerTypeForLowered(CanType T) { - return getStorageTypeForLowered(T)->getPointerTo(); -} - llvm::Type *IRGenModule::getStorageTypeForUnlowered(Type subst) { return getStorageType(getLoweredType(subst)); } @@ -2378,9 +2364,8 @@ const TypeInfo *TypeConverter::convertType(CanType ty) { /// Convert an inout type. This is always just a bare pointer. const TypeInfo *TypeConverter::convertInOutType(InOutType *T) { - auto referenceType = - IGM.getStoragePointerTypeForUnlowered(CanType(T->getObjectType())); - + auto *referenceType = IGM.PtrTy; + // Just use the reference type as a primitive pointer. return createPrimitive(referenceType, IGM.getPointerSize(), IGM.getPointerAlignment()); diff --git a/lib/IRGen/GenValueWitness.cpp b/lib/IRGen/GenValueWitness.cpp index 89372fbe09d..8c763ca3a87 100644 --- a/lib/IRGen/GenValueWitness.cpp +++ b/lib/IRGen/GenValueWitness.cpp @@ -237,17 +237,14 @@ static ResultTy emitForDynamicPacking(IRGenFunction &IGF, static Address emitDefaultProjectBuffer(IRGenFunction &IGF, Address buffer, SILType T, const TypeInfo &type, FixedPacking packing) { - llvm::PointerType *resultTy = type.getStorageType()->getPointerTo(); switch (packing) { case FixedPacking::Allocate: { // Use copy-on-write existentials? auto &IGM = IGF.IGM; auto &Builder = IGF.Builder; - Address boxAddress( - Builder.CreateBitCast(buffer.getAddress(), - IGM.RefCountedPtrTy->getPointerTo()), - IGM.RefCountedPtrTy, buffer.getAlignment()); + Address boxAddress(Builder.CreateBitCast(buffer.getAddress(), IGM.PtrTy), + IGM.RefCountedPtrTy, buffer.getAlignment()); auto *boxStart = IGF.Builder.CreateLoad(boxAddress); auto *alignmentMask = type.getAlignmentMask(IGF, T); auto *heapHeaderSize = llvm::ConstantInt::get( @@ -255,10 +252,9 @@ static Address emitDefaultProjectBuffer(IRGenFunction &IGF, Address buffer, auto *startOffset = Builder.CreateAnd(Builder.CreateAdd(heapHeaderSize, alignmentMask), Builder.CreateNot(alignmentMask)); - auto *addressInBox = - IGF.emitByteOffsetGEP(boxStart, startOffset, IGM.OpaqueTy); + auto *addressInBox = IGF.emitByteOffsetGEP(boxStart, startOffset); - addressInBox = Builder.CreateBitCast(addressInBox, resultTy); + addressInBox = Builder.CreateBitCast(addressInBox, IGF.IGM.PtrTy); return type.getAddressForPointer(addressInBox); } @@ -286,12 +282,11 @@ static Address emitDefaultAllocateBuffer(IRGenFunction &IGF, Address buffer, auto *metadata = IGF.emitTypeMetadataRefForLayout(T); IGF.emitAllocBoxCall(metadata, box, address); IGF.Builder.CreateStore( - box, Address(IGF.Builder.CreateBitCast(buffer.getAddress(), - box->getType()->getPointerTo()), - IGF.IGM.RefCountedPtrTy, buffer.getAlignment())); + box, + Address(IGF.Builder.CreateBitCast(buffer.getAddress(), IGF.IGM.PtrTy), + IGF.IGM.RefCountedPtrTy, buffer.getAlignment())); - llvm::PointerType *resultTy = type.getStorageType()->getPointerTo(); - address = IGF.Builder.CreateBitCast(address, resultTy); + address = IGF.Builder.CreateBitCast(address, IGF.IGM.PtrTy); return type.getAddressForPointer(address); } @@ -325,10 +320,10 @@ static Address emitDefaultInitializeBufferWithCopyOfBuffer( return destObject; } else { assert(packing == FixedPacking::Allocate); - auto *destReferenceAddr = IGF.Builder.CreateBitCast( - destBuffer.getAddress(), IGF.IGM.RefCountedPtrTy->getPointerTo()); - auto *srcReferenceAddr = IGF.Builder.CreateBitCast( - srcBuffer.getAddress(), IGF.IGM.RefCountedPtrTy->getPointerTo()); + auto *destReferenceAddr = + IGF.Builder.CreateBitCast(destBuffer.getAddress(), IGF.IGM.PtrTy); + auto *srcReferenceAddr = + IGF.Builder.CreateBitCast(srcBuffer.getAddress(), IGF.IGM.PtrTy); auto *srcReference = IGF.Builder.CreateLoad(Address( srcReferenceAddr, IGF.IGM.RefCountedPtrTy, srcBuffer.getAlignment())); IGF.emitNativeStrongRetain(srcReference, IGF.getDefaultAtomicity()); @@ -375,8 +370,7 @@ static Address getArgAs(IRGenFunction &IGF, const TypeInfo &type, StringRef name) { llvm::Value *arg = getArg(it, name); - llvm::Value *result = - IGF.Builder.CreateBitCast(arg, type.getStorageType()->getPointerTo()); + llvm::Value *result = IGF.Builder.CreateBitCast(arg, IGF.IGM.PtrTy); return type.getAddressForPointer(result); } @@ -570,8 +564,7 @@ static void buildValueWitnessFunction(IRGenModule &IGM, llvm::Value *value = getArg(argv, "value"); getArgAsLocalSelfTypeMetadata(IGF, argv, abstractType); - auto enumTy = type.getStorageType()->getPointerTo(); - value = IGF.Builder.CreateBitCast(value, enumTy); + value = IGF.Builder.CreateBitCast(value, IGM.PtrTy); auto enumAddr = type.getAddressForPointer(value); llvm::Value *result; @@ -612,8 +605,7 @@ static void buildValueWitnessFunction(IRGenModule &IGM, llvm::Value *value = getArg(argv, "value"); - auto enumTy = type.getStorageType()->getPointerTo(); - value = IGF.Builder.CreateBitCast(value, enumTy); + value = IGF.Builder.CreateBitCast(value, IGM.PtrTy); llvm::Value *tag = getArg(argv, "tag"); @@ -636,8 +628,7 @@ static void buildValueWitnessFunction(IRGenModule &IGM, case ValueWitness::GetEnumTagSinglePayload: { llvm::Value *value = getArg(argv, "value"); - auto enumTy = type.getStorageType()->getPointerTo(); - value = IGF.Builder.CreateBitCast(value, enumTy); + value = IGF.Builder.CreateBitCast(value, IGM.PtrTy); llvm::Value *numEmptyCases = getArg(argv, "numEmptyCases"); @@ -661,8 +652,7 @@ static void buildValueWitnessFunction(IRGenModule &IGM, case ValueWitness::StoreEnumTagSinglePayload: { llvm::Value *value = getArg(argv, "value"); - auto enumTy = type.getStorageType()->getPointerTo(); - value = IGF.Builder.CreateBitCast(value, enumTy); + value = IGF.Builder.CreateBitCast(value, IGM.PtrTy); llvm::Value *whichCase = getArg(argv, "whichCase"); llvm::Value *numEmptyCases = getArg(argv, "numEmptyCases"); @@ -719,7 +709,7 @@ static llvm::Constant *getNoncopyableTrapFunction(IRGenModule &IGM) { /// the second, retains it, loads a pointer from the first, stores the /// new pointer in the first, and releases the old pointer. static llvm::Constant *getAssignWithCopyStrongFunction(IRGenModule &IGM) { - llvm::Type *ptrPtrTy = IGM.RefCountedPtrTy->getPointerTo(); + auto *ptrPtrTy = IGM.PtrTy; llvm::Type *argTys[] = { ptrPtrTy, ptrPtrTy, IGM.WitnessTablePtrTy }; return IGM.getOrCreateHelperFunction("__swift_assignWithCopy_strong", ptrPtrTy, argTys, @@ -743,7 +733,7 @@ static llvm::Constant *getAssignWithCopyStrongFunction(IRGenModule &IGM) { /// the second, retains it, loads a pointer from the first, stores the /// new pointer in the first, and releases the old pointer. static llvm::Constant *getAssignWithTakeStrongFunction(IRGenModule &IGM) { - llvm::Type *ptrPtrTy = IGM.RefCountedPtrTy->getPointerTo(); + auto *ptrPtrTy = IGM.PtrTy; llvm::Type *argTys[] = { ptrPtrTy, ptrPtrTy, IGM.WitnessTablePtrTy }; return IGM.getOrCreateHelperFunction("__swift_assignWithTake_strong", ptrPtrTy, argTys, @@ -765,7 +755,7 @@ static llvm::Constant *getAssignWithTakeStrongFunction(IRGenModule &IGM) { /// retaining initWithCopy on the first two: it loads a pointer from /// the second, retains it, and stores that in the first. static llvm::Constant *getInitWithCopyStrongFunction(IRGenModule &IGM) { - llvm::Type *ptrPtrTy = IGM.RefCountedPtrTy->getPointerTo(); + auto *ptrPtrTy = IGM.PtrTy; llvm::Type *argTys[] = { ptrPtrTy, ptrPtrTy, IGM.WitnessTablePtrTy }; return IGM.getOrCreateHelperFunction("__swift_initWithCopy_strong", ptrPtrTy, argTys, @@ -1769,7 +1759,7 @@ Address TypeInfo::roundUpToTypeAlignment(IRGenFunction &IGF, Address base, Addr = IGF.Builder.CreateNUWAdd(Addr, TyAlignMask); llvm::Value *InvertedMask = IGF.Builder.CreateNot(TyAlignMask); Addr = IGF.Builder.CreateAnd(Addr, InvertedMask); - Addr = IGF.Builder.CreateIntToPtr(Addr, getStorageType()->getPointerTo()); + Addr = IGF.Builder.CreateIntToPtr(Addr, IGF.IGM.PtrTy); return Address(Addr, getStorageType(), Align); } diff --git a/lib/IRGen/IRBuilder.h b/lib/IRGen/IRBuilder.h index 8885a761deb..1f63c168460 100644 --- a/lib/IRGen/IRBuilder.h +++ b/lib/IRGen/IRBuilder.h @@ -257,10 +257,11 @@ public: // Otherwise, cast to a pointer to the correct type. auto origPtrType = address.getType(); - return Address( - CreateBitCast(address.getAddress(), - type->getPointerTo(origPtrType->getAddressSpace())), - type, address.getAlignment()); + + return Address(CreateBitCast(address.getAddress(), + llvm::PointerType::get( + Context, origPtrType->getAddressSpace())), + type, address.getAlignment()); } /// Insert the given basic block after the IP block and move the diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index 569602f836d..659d9366410 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -1076,8 +1076,7 @@ static void embedBitcode(llvm::Module *M, const IRGenOptions &Opts) // Save llvm.compiler.used and remove it. SmallVector UsedArray; SmallVector UsedGlobals; - auto *UsedElementType = - llvm::Type::getInt8Ty(M->getContext())->getPointerTo(0); + auto *UsedElementType = llvm::PointerType::getUnqual(M->getContext()); llvm::GlobalVariable *Used = collectUsedGlobalVariables(*M, UsedGlobals, true); for (auto *GV : UsedGlobals) { diff --git a/lib/IRGen/IRGenFunction.cpp b/lib/IRGen/IRGenFunction.cpp index 3b02f89d4d0..e4ec6b07fe4 100644 --- a/lib/IRGen/IRGenFunction.cpp +++ b/lib/IRGen/IRGenFunction.cpp @@ -404,7 +404,7 @@ llvm::Value *IRGenFunction::emitLoadOfCompactFunctionPointer( void IRGenFunction::emitFakeExplosion(const TypeInfo &type, Explosion &explosion) { if (!isa(type)) { - explosion.add(llvm::UndefValue::get(type.getStorageType()->getPointerTo())); + explosion.add(llvm::UndefValue::get(IGM.PtrTy)); return; } @@ -412,7 +412,7 @@ void IRGenFunction::emitFakeExplosion(const TypeInfo &type, for (auto &element : schema) { llvm::Type *elementType; if (element.isAggregate()) { - elementType = element.getAggregateType()->getPointerTo(); + elementType = IGM.PtrTy; } else { elementType = element.getScalarType(); } @@ -465,8 +465,7 @@ Address IRGenFunction::emitAddressAtOffset(llvm::Value *base, Offset offset, Size objectSize(IGM.DataLayout.getTypeAllocSize(objectTy)); if (byteOffset.isMultipleOf(objectSize)) { // Cast to T*. - auto objectPtrTy = objectTy->getPointerTo(); - base = Builder.CreateBitCast(base, objectPtrTy); + base = Builder.CreateBitCast(base, IGM.PtrTy); // GEP to the slot, computing the index as a signed number. auto scaledIndex = @@ -480,7 +479,7 @@ Address IRGenFunction::emitAddressAtOffset(llvm::Value *base, Offset offset, // GEP to the slot. auto offsetValue = offset.getAsValue(*this); - auto slotPtr = emitByteOffsetGEP(base, offsetValue, objectTy); + auto slotPtr = emitByteOffsetGEP(base, offsetValue); return Address(slotPtr, objectTy, objectAlignment); } @@ -878,8 +877,7 @@ void IRGenFunction::emitAwaitAsyncContinuation( auto &resumeTI = cast(getTypeInfo(resumeTy)); auto resultStorageTy = resumeTI.getStorageType(); auto resultAddr = - Address(Builder.CreateBitOrPointerCast(resultAddrVal, - resultStorageTy->getPointerTo()), + Address(Builder.CreateBitOrPointerCast(resultAddrVal, IGM.PtrTy), resultStorageTy, resumeTI.getFixedAlignment()); resumeTI.loadAsTake(*this, resultAddr, outDirectResult); } @@ -900,8 +898,8 @@ void IRGenFunction::emitResumeAsyncContinuationReturning( // pointer type. Address context = emitLoadOfContinuationContext(*this, continuation); auto destPtrAddr = emitAddrOfContinuationNormalResultPointer(*this, context); - auto destPtr = Builder.CreateBitCast(Builder.CreateLoad(destPtrAddr), - valueTI.getStorageType()->getPointerTo()); + auto destPtr = + Builder.CreateBitCast(Builder.CreateLoad(destPtrAddr), IGM.PtrTy); Address destAddr = valueTI.getAddressForPointer(destPtr); valueTI.initializeWithTake(*this, destAddr, srcAddr, valueTy, diff --git a/lib/IRGen/IRGenFunction.h b/lib/IRGen/IRGenFunction.h index ed7e70cbfee..832d6504985 100644 --- a/lib/IRGen/IRGenFunction.h +++ b/lib/IRGen/IRGenFunction.h @@ -324,7 +324,6 @@ public: void emitMemCpy(Address dest, Address src, llvm::Value *size); llvm::Value *emitByteOffsetGEP(llvm::Value *base, llvm::Value *offset, - llvm::Type *objectType, const llvm::Twine &name = ""); Address emitByteOffsetGEP(llvm::Value *base, llvm::Value *offset, const TypeInfo &type, diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 4985b1ce203..6f567ce303c 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -265,10 +265,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen, Int8Ty = llvm::Type::getInt8Ty(getLLVMContext()); Int16Ty = llvm::Type::getInt16Ty(getLLVMContext()); Int32Ty = llvm::Type::getInt32Ty(getLLVMContext()); - Int32PtrTy = Int32Ty->getPointerTo(); Int64Ty = llvm::Type::getInt64Ty(getLLVMContext()); - Int8PtrTy = PtrTy; - Int8PtrPtrTy = Int8PtrTy->getPointerTo(0); SizeTy = DataLayout.getIntPtrType(getLLVMContext(), /*addrspace*/ 0); // For the relative address type, we want to use the int32 bit type @@ -281,8 +278,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, RelativeAddressTy = Int32Ty; } - RelativeAddressPtrTy = RelativeAddressTy->getPointerTo(); - FloatTy = llvm::Type::getFloatTy(getLLVMContext()); DoubleTy = llvm::Type::getDoubleTy(getLLVMContext()); @@ -295,15 +290,13 @@ IRGenModule::IRGenModule(IRGenerator &irgen, ObjCBoolTy = Int8Ty; RefCountedStructTy = - llvm::StructType::create(getLLVMContext(), "swift.refcounted"); - RefCountedPtrTy = RefCountedStructTy->getPointerTo(/*addrspace*/ 0); + llvm::StructType::create(getLLVMContext(), "swift.refcounted"); RefCountedNull = llvm::ConstantPointerNull::get(RefCountedPtrTy); // For now, references storage types are just pointers. #define CHECKED_REF_STORAGE(Name, name, ...) \ Name##ReferenceStructTy = \ - createStructType(*this, "swift." #name, {RefCountedPtrTy}); \ - Name##ReferencePtrTy = Name##ReferenceStructTy->getPointerTo(0); + createStructType(*this, "swift." #name, {RefCountedPtrTy}); #include "swift/AST/ReferenceStorage.def" // A type metadata record is the structure pointed to by the canonical @@ -313,8 +306,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, TypeMetadataStructTy = createStructType(*this, "swift.type", { MetadataKindTy // MetadataKind Kind; }); - TypeMetadataPtrTy = TypeMetadataStructTy->getPointerTo(DefaultAS); - TypeMetadataPtrPtrTy = TypeMetadataPtrTy->getPointerTo(DefaultAS); TypeMetadataResponseTy = createStructType(*this, "swift.metadata_response", { TypeMetadataPtrTy, @@ -357,8 +348,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, RelativeAddressTy, // superclass RelativeAddressTy // associated type names }); - - ProtocolDescriptorPtrTy = ProtocolDescriptorStructTy->getPointerTo(); ProtocolRequirementStructTy = createStructType(*this, "swift.protocol_requirement", { @@ -379,7 +368,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen, Int8PtrTy, // const char *Labels; llvm::ArrayType::get(tupleElementTy, 0) // Element Elements[]; }); - TupleTypeMetadataPtrTy = TupleTypeMetadataTy->getPointerTo(); + // A full type metadata record is basically just an adjustment to the // address point of a type metadata. Resilience may cause // additional data to be laid out prior to this address point. @@ -390,7 +379,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, WitnessTablePtrTy, TypeMetadataStructTy }); - FullTypeMetadataPtrTy = FullTypeMetadataStructTy->getPointerTo(DefaultAS); FullForeignTypeMetadataStructTy = createStructType(*this, "swift.full_foreign_type", { WitnessTablePtrTy, @@ -398,7 +386,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, }); DeallocatingDtorTy = llvm::FunctionType::get(VoidTy, RefCountedPtrTy, false); - llvm::Type *dtorPtrTy = DeallocatingDtorTy->getPointerTo(); FullExistentialTypeMetadataStructTy = createStructType(*this, "swift.full_existential_type", { WitnessTablePtrTy, @@ -413,23 +400,21 @@ IRGenModule::IRGenModule(IRGenerator &irgen, FullHeapMetadataStructTy = createStructType(*this, "swift.full_heapmetadata", { Int8PtrTy, - dtorPtrTy, + PtrTy, WitnessTablePtrTy, TypeMetadataStructTy }); - FullHeapMetadataPtrTy = FullHeapMetadataStructTy->getPointerTo(DefaultAS); // A full box metadata is non-type heap metadata for a heap allocation of a // single value. The box tracks the offset to the value inside the box. FullBoxMetadataStructTy = createStructType(*this, "swift.full_boxmetadata", { - dtorPtrTy, + PtrTy, WitnessTablePtrTy, TypeMetadataStructTy, Int32Ty, CaptureDescriptorPtrTy, }); - FullBoxMetadataPtrTy = FullBoxMetadataStructTy->getPointerTo(DefaultAS); // This must match struct HeapObject in the runtime. llvm::Type *refCountedElts[] = {TypeMetadataPtrTy, IntPtrTy}; @@ -445,7 +430,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen, }); OpaqueTy = llvm::StructType::create(getLLVMContext(), "swift.opaque"); - OpaquePtrTy = OpaqueTy->getPointerTo(DefaultAS); + NoEscapeFunctionPairTy = createStructType(*this, "swift.noescape.function", { FunctionPtrTy, OpaquePtrTy, @@ -455,7 +440,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, createStructType(*this, "swift.protocolref", { RelativeAddressTy }); - ProtocolRecordPtrTy = ProtocolRecordTy->getPointerTo(); ProtocolConformanceDescriptorTy = createStructType(*this, "swift.protocol_conformance_descriptor", { @@ -464,13 +448,9 @@ IRGenModule::IRGenModule(IRGenerator &irgen, RelativeAddressTy, Int32Ty }); - ProtocolConformanceDescriptorPtrTy - = ProtocolConformanceDescriptorTy->getPointerTo(DefaultAS); TypeContextDescriptorTy = llvm::StructType::create(getLLVMContext(), "swift.type_descriptor"); - TypeContextDescriptorPtrTy - = TypeContextDescriptorTy->getPointerTo(DefaultAS); ClassContextDescriptorTy = llvm::StructType::get(getLLVMContext(), { @@ -514,25 +494,16 @@ IRGenModule::IRGenModule(IRGenerator &irgen, = createStructType(*this, "swift.type_metadata_record", { RelativeAddressTy }); - TypeMetadataRecordPtrTy - = TypeMetadataRecordTy->getPointerTo(DefaultAS); FieldDescriptorTy = llvm::StructType::create(getLLVMContext(), "swift.field_descriptor"); - FieldDescriptorPtrTy = FieldDescriptorTy->getPointerTo(DefaultAS); - FieldDescriptorPtrPtrTy = FieldDescriptorPtrTy->getPointerTo(DefaultAS); FixedBufferTy = nullptr; for (unsigned i = 0; i != MaxNumValueWitnesses; ++i) ValueWitnessTys[i] = nullptr; - ObjCPtrTy = llvm::StructType::create(getLLVMContext(), "objc_object") - ->getPointerTo(DefaultAS); - BridgeObjectPtrTy = llvm::StructType::create(getLLVMContext(), "swift.bridge") - ->getPointerTo(DefaultAS); - ObjCClassStructTy = llvm::StructType::create(getLLVMContext(), "objc_class"); - ObjCClassPtrTy = ObjCClassStructTy->getPointerTo(DefaultAS); + llvm::Type *objcClassElts[] = { ObjCClassPtrTy, ObjCClassPtrTy, @@ -543,15 +514,13 @@ IRGenModule::IRGenModule(IRGenerator &irgen, ObjCClassStructTy->setBody(objcClassElts); ObjCSuperStructTy = llvm::StructType::create(getLLVMContext(), "objc_super"); - ObjCSuperPtrTy = ObjCSuperStructTy->getPointerTo(DefaultAS); llvm::Type *objcSuperElts[] = { ObjCPtrTy, ObjCClassPtrTy }; ObjCSuperStructTy->setBody(objcSuperElts); - + ObjCBlockStructTy = llvm::StructType::create(getLLVMContext(), "objc_block"); - ObjCBlockPtrTy = ObjCBlockStructTy->getPointerTo(DefaultAS); llvm::Type *objcBlockElts[] = { ObjCClassPtrTy, // isa Int32Ty, // flags @@ -571,19 +540,15 @@ IRGenModule::IRGenModule(IRGenerator &irgen, ObjCFullResilientClassStubTy = createStructType(*this, "objc_full_class_stub", { SizeTy, // zero padding to appease the linker SizeTy, // isa pointer -- always 1 - ObjCUpdateCallbackTy->getPointerTo() // the update callback + PtrTy // the update callback }); // What we actually export. ObjCResilientClassStubTy = createStructType(*this, "objc_class_stub", { SizeTy, // isa pointer -- always 1 - ObjCUpdateCallbackTy->getPointerTo() // the update callback + PtrTy // the update callback }); - auto ErrorStructTy = llvm::StructType::create(getLLVMContext(), "swift.error"); - // ErrorStruct is currently opaque to the compiler. - ErrorPtrTy = ErrorStructTy->getPointerTo(DefaultAS); - llvm::Type *openedErrorTriple[] = { OpaquePtrTy, TypeMetadataPtrTy, @@ -592,13 +557,9 @@ IRGenModule::IRGenModule(IRGenerator &irgen, OpenedErrorTripleTy = llvm::StructType::get(getLLVMContext(), openedErrorTriple, /*packed*/ false); - OpenedErrorTriplePtrTy = OpenedErrorTripleTy->getPointerTo(DefaultAS); - WitnessTablePtrPtrTy = WitnessTablePtrTy->getPointerTo(DefaultAS); - // todo OpaqueTypeDescriptorTy = TypeContextDescriptorTy; - OpaqueTypeDescriptorPtrTy = OpaqueTypeDescriptorTy->getPointerTo(); InvariantMetadataID = getLLVMContext().getMDKindID("invariant.load"); InvariantNode = llvm::MDNode::get(getLLVMContext(), {}); @@ -675,12 +636,9 @@ IRGenModule::IRGenModule(IRGenerator &irgen, DynamicReplacementsTy = llvm::StructType::get(getLLVMContext(), {Int8PtrPtrTy, Int8PtrTy}); - DynamicReplacementsPtrTy = DynamicReplacementsTy->getPointerTo(DefaultAS); DynamicReplacementLinkEntryTy = llvm::StructType::create(getLLVMContext(), "swift.dyn_repl_link_entry"); - DynamicReplacementLinkEntryPtrTy = - DynamicReplacementLinkEntryTy->getPointerTo(DefaultAS); llvm::Type *linkEntryFields[] = { Int8PtrTy, // function pointer. DynamicReplacementLinkEntryPtrTy // next. @@ -698,7 +656,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, AsyncFunctionPointerTy = createStructType(*this, "swift.async_func_pointer", {RelativeAddressTy, Int32Ty}, true); SwiftContextTy = llvm::StructType::create(getLLVMContext(), "swift.context"); - SwiftContextPtrTy = SwiftContextTy->getPointerTo(DefaultAS); // This must match the definition of class AsyncTask in swift/ABI/Task.h. SwiftTaskTy = createStructType(*this, "swift.task", { @@ -711,17 +668,12 @@ IRGenModule::IRGenModule(IRGenerator &irgen, SwiftContextPtrTy, // Task.ResumeContext }); - AsyncFunctionPointerPtrTy = AsyncFunctionPointerTy->getPointerTo(DefaultAS); - SwiftTaskPtrTy = SwiftTaskTy->getPointerTo(DefaultAS); - SwiftAsyncLetPtrTy = Int8PtrTy; // we pass it opaquely (AsyncLet*) SwiftTaskOptionRecordTy = llvm::StructType::create(getLLVMContext(), "swift.task_option"); - SwiftTaskOptionRecordPtrTy = SwiftTaskOptionRecordTy->getPointerTo(DefaultAS); SwiftTaskOptionRecordTy->setBody({ SizeTy, // Flags SwiftTaskOptionRecordPtrTy, // Parent }); - SwiftTaskGroupPtrTy = Int8PtrTy; // we pass it opaquely (TaskGroup*) SwiftTaskGroupTaskOptionRecordTy = createStructType( *this, "swift.task_group_task_option", { SwiftTaskOptionRecordTy, // Base option record @@ -770,13 +722,11 @@ IRGenModule::IRGenModule(IRGenerator &irgen, Int8PtrTy, Int8PtrTy, // Reserved FunctionPtrTy, // RunJob/ResumeTask }); - SwiftJobPtrTy = SwiftJobTy->getPointerTo(DefaultAS); // using TaskContinuationFunction = // SWIFT_CC(swift) void (SWIFT_ASYNC_CONTEXT AsyncContext *); TaskContinuationFunctionTy = llvm::FunctionType::get( VoidTy, {SwiftContextPtrTy}, /*isVarArg*/ false); - TaskContinuationFunctionPtrTy = TaskContinuationFunctionTy->getPointerTo(); SwiftContextTy->setBody({ SwiftContextPtrTy, // Parent @@ -809,8 +759,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, SwiftExecutorTy // resume to executor }); } - ContinuationAsyncContextPtrTy = - ContinuationAsyncContextTy->getPointerTo(DefaultAS); ClassMetadataBaseOffsetTy = llvm::StructType::get( getLLVMContext(), { @@ -824,8 +772,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen, CoroFunctionPointerTy = createStructType(*this, "swift.coro_func_pointer", {RelativeAddressTy, Int32Ty}, true); - CoroFunctionPointerPtrTy = CoroFunctionPointerTy->getPointerTo(); - CoroAllocationTy = PtrTy; CoroAllocateFnTy = llvm::FunctionType::get(CoroAllocationTy, SizeTy, /*isVarArg*/ false); CoroDeallocateFnTy = @@ -835,10 +781,9 @@ IRGenModule::IRGenModule(IRGenerator &irgen, CoroAllocatorTy = createStructType(*this, "swift.coro_allocator", { Int32Ty, // CoroAllocator.Flags - CoroAllocateFnTy->getPointerTo(), - CoroDeallocateFnTy->getPointerTo(), + PtrTy, + PtrTy, }); - CoroAllocatorPtrTy = CoroAllocatorTy->getPointerTo(); } IRGenModule::~IRGenModule() { diff --git a/lib/IRGen/IRGenModule.h b/lib/IRGen/IRGenModule.h index 21ac4927179..8c00c5be2e3 100644 --- a/lib/IRGen/IRGenModule.h +++ b/lib/IRGen/IRGenModule.h @@ -704,14 +704,11 @@ public: bool ShouldUseSwiftError; llvm::Type *VoidTy; /// void (usually {}) - llvm::PointerType *PtrTy; /// ptr llvm::IntegerType *Int1Ty; /// i1 llvm::IntegerType *Int8Ty; /// i8 llvm::IntegerType *Int16Ty; /// i16 llvm::IntegerType *Int32Ty; /// i32 - llvm::PointerType *Int32PtrTy; /// i32 * llvm::IntegerType *RelativeAddressTy; - llvm::PointerType *RelativeAddressPtrTy; llvm::IntegerType *Int64Ty; /// i64 union { llvm::IntegerType *SizeTy; /// usually i32 or i64 @@ -722,31 +719,74 @@ public: llvm::IntegerType *ProtocolDescriptorRefTy; }; llvm::IntegerType *ObjCBoolTy; /// i8 or i1 + union { - llvm::PointerType *Int8PtrTy; /// i8* - llvm::PointerType *WitnessTableTy; - llvm::PointerType *ObjCSELTy; - llvm::PointerType *FunctionPtrTy; + llvm::PointerType *PtrTy; /// ptr + + llvm::PointerType *BridgeObjectPtrTy; /// %swift.bridge* llvm::PointerType *CaptureDescriptorPtrTy; - }; - union { + llvm::PointerType *ContinuationAsyncContextPtrTy; + llvm::PointerType *CoroAllocationTy; + llvm::PointerType *CoroAllocatorPtrTy; + llvm::PointerType *CoroFunctionPointerPtrTy; + llvm::PointerType *DynamicReplacementLinkEntryPtrTy; /// %link_entry* + llvm::PointerType *DynamicReplacementsPtrTy; /// { i8**, i8* }* + llvm::PointerType *ErrorPtrTy; /// %swift.error* + llvm::PointerType *FieldDescriptorPtrTy; + llvm::PointerType *FieldDescriptorPtrPtrTy; + llvm::PointerType *FullBoxMetadataPtrTy; /// %swift.full_boxmetadata* + llvm::PointerType *FullHeapMetadataPtrTy; /// %swift.full_heapmetadata* + llvm::PointerType *FullTypeMetadataPtrTy; /// %swift.full_type* + llvm::PointerType *FunctionPtrTy; + llvm::PointerType *Int8PtrTy; /// i8* llvm::PointerType *Int8PtrPtrTy; /// i8** + llvm::PointerType *Int32PtrTy; /// i32 * + llvm::PointerType *ObjCBlockPtrTy; /// %objc_block* + llvm::PointerType *ObjCClassPtrTy; /// %objc_class* + llvm::PointerType *ObjCPtrTy; /// %objc_object* + llvm::PointerType *ObjCSELTy; + llvm::PointerType *ObjCSuperPtrTy; /// %objc_super* + llvm::PointerType *OpaquePtrTy; /// %swift.opaque* + llvm::PointerType *OpaqueTypeDescriptorPtrTy; + llvm::PointerType + *OpenedErrorTriplePtrTy; /// { %swift.opaque*, %swift.type*, i8** }* + llvm::PointerType *ProtocolConformanceDescriptorPtrTy; + llvm::PointerType *ProtocolDescriptorPtrTy; /// %swift.protocol* + llvm::PointerType *ProtocolRecordPtrTy; + llvm::PointerType *RelativeAddressPtrTy; + llvm::PointerType *RefCountedPtrTy; /// %swift.refcounted* +#define CHECKED_REF_STORAGE(Name, ...) \ + llvm::PointerType *Name##ReferencePtrTy; /// %swift. #name _reference* +#include "swift/AST/ReferenceStorage.def" + llvm::PointerType *SwiftAsyncLetPtrTy; + llvm::PointerType *SwiftContextPtrTy; + llvm::PointerType *SwiftJobPtrTy; + llvm::PointerType *SwiftTaskGroupPtrTy; + llvm::PointerType *SwiftTaskOptionRecordPtrTy; + llvm::PointerType *SwiftTaskPtrTy; + llvm::PointerType *AsyncFunctionPointerPtrTy; + llvm::PointerType *TaskContinuationFunctionPtrTy; + llvm::PointerType *TupleTypeMetadataPtrTy; /// %swift.tuple_type* + llvm::PointerType *TypeContextDescriptorPtrTy; + llvm::PointerType *TypeMetadataPtrTy; /// %swift.type* + llvm::PointerType *TypeMetadataPtrPtrTy; /// %swift.type** + llvm::PointerType *TypeMetadataRecordPtrTy; + llvm::PointerType *UnknownRefCountedPtrTy; llvm::PointerType *WitnessTablePtrTy; + llvm::PointerType *WitnessTablePtrPtrTy; /// i8*** + llvm::PointerType *WitnessTableTy; }; + llvm::StructType *RefCountedStructTy;/// %swift.refcounted = type { ... } Size RefCountedStructSize; /// sizeof(%swift.refcounted) - llvm::PointerType *RefCountedPtrTy; /// %swift.refcounted* #define CHECKED_REF_STORAGE(Name, ...) \ - llvm::StructType *Name##ReferenceStructTy; \ - llvm::PointerType *Name##ReferencePtrTy; /// %swift. #name _reference* + llvm::StructType *Name##ReferenceStructTy; /// %swift. #name _reference #include "swift/AST/ReferenceStorage.def" llvm::Constant *RefCountedNull; /// %swift.refcounted* null llvm::StructType *FunctionPairTy; /// { i8*, %swift.refcounted* } llvm::StructType *NoEscapeFunctionPairTy; /// { i8*, %swift.opaque* } llvm::FunctionType *DeallocatingDtorTy; /// void (%swift.refcounted*) llvm::StructType *TypeMetadataStructTy; /// %swift.type = type { ... } - llvm::PointerType *TypeMetadataPtrTy;/// %swift.type* - llvm::PointerType *TypeMetadataPtrPtrTy; /// %swift.type** union { llvm::StructType *TypeMetadataResponseTy; /// { %swift.type*, iSize } llvm::StructType *TypeMetadataDependencyTy; /// { %swift.type*, iSize } @@ -755,63 +795,36 @@ public: llvm::StructType *FullTypeLayoutTy; /// %swift.full_type_layout = { ... } llvm::StructType *TypeLayoutTy; /// %swift.type_layout = { ... } llvm::StructType *TupleTypeMetadataTy; /// %swift.tuple_type - llvm::PointerType *TupleTypeMetadataPtrTy; /// %swift.tuple_type* llvm::StructType *FullHeapMetadataStructTy; /// %swift.full_heapmetadata = type { ... } - llvm::PointerType *FullHeapMetadataPtrTy;/// %swift.full_heapmetadata* llvm::StructType *FullBoxMetadataStructTy; /// %swift.full_boxmetadata = type { ... } - llvm::PointerType *FullBoxMetadataPtrTy;/// %swift.full_boxmetadata* llvm::StructType *FullTypeMetadataStructTy; /// %swift.full_type = type { ... } llvm::StructType *FullExistentialTypeMetadataStructTy; /// %swift.full_existential_type = type { ... } - llvm::PointerType *FullTypeMetadataPtrTy;/// %swift.full_type* llvm::StructType *FullForeignTypeMetadataStructTy; /// %swift.full_foreign_type = type { ... } llvm::StructType *ProtocolDescriptorStructTy; /// %swift.protocol = type { ... } - llvm::PointerType *ProtocolDescriptorPtrTy; /// %swift.protocol* llvm::StructType *ProtocolRequirementStructTy; /// %swift.protocol_requirement - union { - llvm::PointerType *ObjCPtrTy; /// %objc_object* - llvm::PointerType *UnknownRefCountedPtrTy; - }; - llvm::PointerType *BridgeObjectPtrTy;/// %swift.bridge* llvm::StructType *OpaqueTy; /// %swift.opaque - llvm::PointerType *OpaquePtrTy; /// %swift.opaque* llvm::StructType *ObjCClassStructTy; /// %objc_class - llvm::PointerType *ObjCClassPtrTy; /// %objc_class* llvm::StructType *ObjCSuperStructTy; /// %objc_super - llvm::PointerType *ObjCSuperPtrTy; /// %objc_super* llvm::StructType *ObjCBlockStructTy; /// %objc_block - llvm::PointerType *ObjCBlockPtrTy; /// %objc_block* llvm::FunctionType *ObjCUpdateCallbackTy; llvm::StructType *ObjCFullResilientClassStubTy; /// %objc_full_class_stub llvm::StructType *ObjCResilientClassStubTy; /// %objc_class_stub llvm::StructType *ProtocolRecordTy; - llvm::PointerType *ProtocolRecordPtrTy; llvm::StructType *ProtocolConformanceDescriptorTy; - llvm::PointerType *ProtocolConformanceDescriptorPtrTy; llvm::StructType *TypeContextDescriptorTy; - llvm::PointerType *TypeContextDescriptorPtrTy; llvm::StructType *ClassContextDescriptorTy; llvm::StructType *MethodDescriptorStructTy; /// %swift.method_descriptor llvm::StructType *MethodOverrideDescriptorStructTy; /// %swift.method_override_descriptor llvm::StructType *MethodDefaultOverrideDescriptorStructTy; /// %swift.method_default_override_descriptor llvm::StructType *TypeMetadataRecordTy; - llvm::PointerType *TypeMetadataRecordPtrTy; llvm::StructType *FieldDescriptorTy; - llvm::PointerType *FieldDescriptorPtrTy; - llvm::PointerType *FieldDescriptorPtrPtrTy; - llvm::PointerType *ErrorPtrTy; /// %swift.error* llvm::StructType *OpenedErrorTripleTy; /// { %swift.opaque*, %swift.type*, i8** } - llvm::PointerType *OpenedErrorTriplePtrTy; /// { %swift.opaque*, %swift.type*, i8** }* - llvm::PointerType *WitnessTablePtrPtrTy; /// i8*** llvm::StructType *OpaqueTypeDescriptorTy; - llvm::PointerType *OpaqueTypeDescriptorPtrTy; llvm::Type *FloatTy; llvm::Type *DoubleTy; llvm::StructType *DynamicReplacementsTy; // { i8**, i8* } - llvm::PointerType *DynamicReplacementsPtrTy; llvm::StructType *DynamicReplacementLinkEntryTy; // %link_entry = { i8*, %link_entry*} - llvm::PointerType - *DynamicReplacementLinkEntryPtrTy; // %link_entry* llvm::StructType *DynamicReplacementKeyTy; // { i32, i32} llvm::StructType *AccessibleFunctionRecordTy; // { i32*, i32*, i32*, i32} @@ -822,12 +835,6 @@ public: llvm::StructType *SwiftTaskTy; llvm::StructType *SwiftJobTy; llvm::StructType *SwiftExecutorTy; - llvm::PointerType *AsyncFunctionPointerPtrTy; - llvm::PointerType *SwiftContextPtrTy; - llvm::PointerType *SwiftTaskPtrTy; - llvm::PointerType *SwiftAsyncLetPtrTy; - llvm::PointerType *SwiftTaskOptionRecordPtrTy; - llvm::PointerType *SwiftTaskGroupPtrTy; llvm::StructType *SwiftTaskOptionRecordTy; llvm::StructType *SwiftInitialSerialExecutorTaskOptionRecordTy; llvm::StructType *SwiftTaskGroupTaskOptionRecordTy; @@ -835,26 +842,20 @@ public: llvm::StructType *SwiftInitialTaskExecutorOwnedPreferenceTaskOptionRecordTy; llvm::StructType *SwiftInitialTaskNameTaskOptionRecordTy; llvm::StructType *SwiftResultTypeInfoTaskOptionRecordTy; - llvm::PointerType *SwiftJobPtrTy; llvm::IntegerType *ExecutorFirstTy; llvm::IntegerType *ExecutorSecondTy; llvm::FunctionType *TaskContinuationFunctionTy; - llvm::PointerType *TaskContinuationFunctionPtrTy; llvm::StructType *AsyncTaskAndContextTy; llvm::StructType *ContinuationAsyncContextTy; - llvm::PointerType *ContinuationAsyncContextPtrTy; llvm::StructType *ClassMetadataBaseOffsetTy; llvm::StructType *DifferentiabilityWitnessTy; // { i8*, i8* } // clang-format on llvm::StructType *CoroFunctionPointerTy; // { i32, i32 } - llvm::PointerType *CoroFunctionPointerPtrTy; - llvm::PointerType *CoroAllocationTy; llvm::FunctionType *CoroAllocateFnTy; llvm::FunctionType *CoroDeallocateFnTy; llvm::IntegerType *CoroAllocatorFlagsTy; llvm::StructType *CoroAllocatorTy; - llvm::PointerType *CoroAllocatorPtrTy; llvm::GlobalVariable *TheTrivialPropertyDescriptor = nullptr; @@ -930,6 +931,8 @@ public: llvm::Type *getReferenceType(ReferenceCounting style); + llvm::PointerType *getOpaquePointerType(unsigned AddressSpace) const; + static bool isLoadableReferenceAddressOnly(ReferenceCounting style) { switch (style) { case ReferenceCounting::Native: @@ -969,7 +972,6 @@ public: ReferenceCounting style) const; llvm::Type *getFixedBufferTy(); - llvm::PointerType *getExistentialPtrTy(unsigned numTables); llvm::Type *getExistentialType(unsigned numTables); llvm::Type *getValueWitnessTy(ValueWitness index); Signature getValueWitnessSignature(ValueWitness index); @@ -978,8 +980,6 @@ public: llvm::StructType *getValueWitnessTableTy(); llvm::StructType *getEnumValueWitnessTableTy(); - llvm::PointerType *getValueWitnessTablePtrTy(); - llvm::PointerType *getEnumValueWitnessTablePtrTy(); llvm::IntegerType *getTypeMetadataRequestParamTy(); llvm::StructType *getTypeMetadataResponseTy(); @@ -1101,9 +1101,6 @@ public: llvm::Type *getStorageTypeForUnlowered(Type T); llvm::Type *getStorageTypeForLowered(CanType T); llvm::Type *getStorageType(SILType T); - llvm::PointerType *getStoragePointerTypeForUnlowered(Type T); - llvm::PointerType *getStoragePointerTypeForLowered(CanType T); - llvm::PointerType *getStoragePointerType(SILType T); llvm::StructType *createNominalType(CanType type); llvm::StructType *createNominalType(ProtocolCompositionType *T); clang::CanQual getClangType(CanType type); diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 34bdb94ff7a..c9678b127d8 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -571,8 +571,8 @@ public: auto &ti = getTypeInfo(t); switch (t.getCategory()) { case SILValueCategory::Address: { - Address undefAddr = ti.getAddressForPointer( - llvm::UndefValue::get(ti.getStorageType()->getPointerTo())); + Address undefAddr = + ti.getAddressForPointer(llvm::UndefValue::get(IGM.PtrTy)); LoweredUndefs.insert({t, LoweredValue(undefAddr)}); break; } @@ -1598,9 +1598,8 @@ Explosion NativeCCEntryPointArgumentEmission::explosionForObject( Address paramAddr = loadableParamTI.getAddressForPointer(paramExplosion.claimNext()); if (loadableParamTI.getStorageType() != loadableArgTI.getStorageType()) - paramAddr = loadableArgTI.getAddressForPointer(IGF.Builder.CreateBitCast( - paramAddr.getAddress(), - loadableArgTI.getStorageType()->getPointerTo())); + paramAddr = loadableArgTI.getAddressForPointer( + IGF.Builder.CreateBitCast(paramAddr.getAddress(), IGF.IGM.PtrTy)); loadableArgTI.loadAsTake(IGF, paramAddr, paramValues); } else { if (!nativeSchema.empty()) { @@ -1963,8 +1962,7 @@ static void emitPHINodesForType(IRGenSILFunction &IGF, SILType type, const TypeInfo &ti, unsigned predecessors, ValueVector &phis) { if (type.isAddress()) { - phis.push_back(IGF.Builder.CreatePHI(ti.getStorageType()->getPointerTo(), - predecessors)); + phis.push_back(IGF.Builder.CreatePHI(IGF.IGM.PtrTy, predecessors)); } else { // PHIs are always emitted with maximal explosion. ExplosionSchema schema = ti.getSchema(); @@ -1973,9 +1971,7 @@ static void emitPHINodesForType(IRGenSILFunction &IGF, SILType type, phis.push_back( IGF.Builder.CreatePHI(elt.getScalarType(), predecessors)); else - phis.push_back( - IGF.Builder.CreatePHI(elt.getAggregateType()->getPointerTo(), - predecessors)); + phis.push_back(IGF.Builder.CreatePHI(IGF.IGM.PtrTy, predecessors)); } } } @@ -2046,8 +2042,7 @@ static ArrayRef emitEntryPointIndirectReturn( auto ptr = emission.getIndirectResultForFormallyDirectResult(); if (paramTI.getStorageType() != retTI.getStorageType()) { assert(directResultType.getASTType()->hasOpaqueArchetype()); - ptr = IGF.Builder.CreateBitCast(ptr, - retTI.getStorageType()->getPointerTo()); + ptr = IGF.Builder.CreateBitCast(ptr, IGF.IGM.PtrTy); } IGF.IndirectReturn = retTI.getAddressForPointer(ptr); } @@ -2073,8 +2068,7 @@ static ArrayRef emitEntryPointIndirectReturn( if (paramTI.getStorageType() != retTI.getStorageType() || !isFixedSize) { assert(!isFixedSize || inContextResultType.getASTType()->hasOpaqueArchetype()); - ptr = IGF.Builder.CreateBitCast(ptr, - retTI.getStorageType()->getPointerTo()); + ptr = IGF.Builder.CreateBitCast(ptr, IGF.IGM.PtrTy); } auto addr = retTI.getAddressForPointer(ptr); IGF.setLoweredAddress(ret, addr); @@ -2114,8 +2108,7 @@ static void bindParameter(IRGenSILFunction &IGF, Explosion paramExplosion = explosionForArgument(index, 1); auto ptr = paramExplosion.claimNext(); if (paramTI.getStorageType() != argTI.getStorageType()) { - ptr = - IGF.Builder.CreateBitCast(ptr, argTI.getStorageType()->getPointerTo()); + ptr = IGF.Builder.CreateBitCast(ptr, IGF.IGM.PtrTy); } Address paramAddr = argTI.getAddressForPointer(ptr); IGF.setLoweredAddress(param, paramAddr); @@ -2303,10 +2296,8 @@ static void emitEntryPointArgumentsNativeCC(IRGenSILFunction &IGF, [&](unsigned startIndex, unsigned size) { assert(size == 1); Explosion indicesTemp; - auto castedIndices = IGF.Builder.CreateBitCast( - componentArgsBuf, IGF.getTypeInfo(indicesArg->getType()) - .getStorageType() - ->getPointerTo()); + auto castedIndices = + IGF.Builder.CreateBitCast(componentArgsBuf, IGF.IGM.PtrTy); indicesTemp.add(castedIndices); return indicesTemp; }); @@ -2418,8 +2409,7 @@ static void emitEntryPointArgumentsCOrObjC(IRGenSILFunction &IGF, // Bitcast indirect argument pointers to the right storage type. if (arg->getType().isAddress()) { llvm::Value *ptr = params.claimNext(); - ptr = IGF.Builder.CreateBitCast(ptr, - argTI.getStorageType()->getPointerTo()); + ptr = IGF.Builder.CreateBitCast(ptr, IGF.IGM.PtrTy); IGF.setLoweredAddress(arg, Address(ptr, argTI.getStorageType(), argTI.getBestKnownAlignment())); continue; @@ -3028,8 +3018,7 @@ void IRGenSILFunction::visitDifferentiabilityWitnessFunctionInst( auto fnType = cast(i->getType().getASTType()); Signature signature = IGM.getSignature(fnType); - diffWitness = - Builder.CreateBitCast(diffWitness, signature.getType()->getPointerTo()); + diffWitness = Builder.CreateBitCast(diffWitness, IGM.PtrTy); setLoweredFunctionPointer( i, FunctionPointer::createUnsigned(fnType, diffWitness, signature, true)); @@ -3239,8 +3228,7 @@ void IRGenSILFunction::visitGlobalAddrInst(GlobalAddrInst *i) { SILType loweredTyInContext = var->getLoweredTypeInContext(getExpansionContext()); auto &tiInContext = getTypeInfo(loweredTyInContext); - auto ptr = Builder.CreateBitOrPointerCast( - addr.getAddress(), tiInContext.getStorageType()->getPointerTo()); + auto ptr = Builder.CreateBitOrPointerCast(addr.getAddress(), IGM.PtrTy); addr = Address(ptr, tiInContext.getStorageType(), tiInContext.getBestKnownAlignment()); return addr; @@ -3289,9 +3277,8 @@ void IRGenSILFunction::visitGlobalValueInst(GlobalValueInst *i) { } void IRGenSILFunction::visitBaseAddrForOffsetInst(BaseAddrForOffsetInst *i) { - auto storagePtrTy = IGM.getStoragePointerType(i->getType()); auto storageTy = IGM.getStorageType(i->getType()); - llvm::Value *addr = llvm::ConstantPointerNull::get(storagePtrTy); + llvm::Value *addr = llvm::ConstantPointerNull::get(IGM.PtrTy); setLoweredAddress(i, Address(addr, storageTy, Alignment())); } @@ -4782,8 +4769,7 @@ void IRGenSILFunction::visitEndApply(BeginApplyInst *i, EndApplyInst *ei) { // Cast the continuation pointer to the right function pointer type. auto continuation = coroutine.Continuation; - continuation = Builder.CreateBitCast(continuation, - sig.getType()->getPointerTo()); + continuation = Builder.CreateBitCast(continuation, IGM.PtrTy); auto schemaAndEntity = getCoroutineResumeFunctionPointerAuth(IGM, i->getOrigCalleeType()); @@ -5353,8 +5339,7 @@ void IRGenSILFunction::visitDynamicMethodBranchInst(DynamicMethodBranchInst *i){ }; auto respondsToSelectorTy = llvm::FunctionType::get(IGM.Int1Ty, argTys, /*isVarArg*/ false); - messenger = llvm::ConstantExpr::getBitCast( - messenger, respondsToSelectorTy->getPointerTo()); + messenger = llvm::ConstantExpr::getBitCast(messenger, IGM.PtrTy); llvm::CallInst *call = Builder.CreateCall( respondsToSelectorTy, messenger, {object, respondsToSelector, loadSel}); call->setDoesNotThrow(); @@ -7160,9 +7145,8 @@ void IRGenSILFunction::visitPointerToAddressInst(swift::PointerToAddressInst *i) llvm::Value *ptrValue = from.claimNext(); auto &ti = getTypeInfo(i->getType()); - - llvm::Type *destType = ti.getStorageType()->getPointerTo(); - ptrValue = Builder.CreateBitCast(ptrValue, destType); + + ptrValue = Builder.CreateBitCast(ptrValue, IGM.PtrTy); if (i->alignment()) setLoweredAddress(i, Address(ptrValue, ti.getStorageType(), @@ -7784,8 +7768,8 @@ void IRGenSILFunction::visitKeyPathInst(swift::KeyPathInst *I) { auto &ti = getTypeInfo(operand->getType()); auto ptr = Builder.CreateInBoundsGEP(IGM.Int8Ty, argsBuf.getAddress(), operandOffsets[i]); - auto addr = ti.getAddressForPointer( - Builder.CreateBitCast(ptr, ti.getStorageType()->getPointerTo())); + auto addr = + ti.getAddressForPointer(Builder.CreateBitCast(ptr, IGM.PtrTy)); if (operand->getType().isAddress()) { ti.initializeWithTake(*this, addr, getLoweredAddress(operand), operand->getType(), false, @@ -8381,7 +8365,7 @@ void IRGenSILFunction::visitSuperMethodInst(swift::SuperMethodInst *i) { // The function returns an i8*; cast it to the correct type. auto sig = IGM.getSignature(methodType); - fnPtr = Builder.CreateBitCast(fnPtr, sig.getType()->getPointerTo()); + fnPtr = Builder.CreateBitCast(fnPtr, IGM.PtrTy); auto &schema = methodType->isAsync() ? getOptions().PointerAuth.AsyncSwiftClassMethodPointers diff --git a/lib/IRGen/Linking.cpp b/lib/IRGen/Linking.cpp index 0a2559f4258..0d8199cf1aa 100644 --- a/lib/IRGen/Linking.cpp +++ b/lib/IRGen/Linking.cpp @@ -1147,7 +1147,7 @@ llvm::Type *LinkEntity::getDefaultDeclarationType(IRGenModule &IGM) const { case Kind::ProtocolWitnessTableLazyCacheVariable: return IGM.WitnessTablePtrTy; case Kind::SILFunction: - return IGM.FunctionPtrTy->getPointerTo(); + return IGM.PtrTy; case Kind::MethodDescriptor: case Kind::MethodDescriptorInitializer: case Kind::MethodDescriptorAllocator: diff --git a/lib/IRGen/MetadataRequest.cpp b/lib/IRGen/MetadataRequest.cpp index f9d440e6f09..bfd08bc1959 100644 --- a/lib/IRGen/MetadataRequest.cpp +++ b/lib/IRGen/MetadataRequest.cpp @@ -1499,13 +1499,11 @@ emitFunctionTypeMetadataParams(IRGenFunction &IGF, flagsArr.addInt32(paramFlags.getIntValue()); } } else { - auto parametersPtr = - llvm::ConstantPointerNull::get( - IGF.IGM.TypeMetadataPtrTy->getPointerTo()); + auto parametersPtr = llvm::ConstantPointerNull::get(IGF.IGM.PtrTy); arguments.push_back(parametersPtr); } - auto *Int32Ptr = IGF.IGM.Int32Ty->getPointerTo(); + auto *Int32Ptr = IGF.IGM.PtrTy; if (flags.hasParameterFlags()) { auto *flagsVar = flagsArr.finishAndCreateGlobal( "parameter-flags", IGF.IGM.getPointerAlignment(), @@ -1542,8 +1540,7 @@ emitDynamicFunctionTypeMetadataParams(IRGenFunction &IGF, arguments.push_back(info.paramFlags.getAddress().getAddress()); } else { - arguments.push_back(llvm::ConstantPointerNull::get( - IGF.IGM.Int32Ty->getPointerTo())); + arguments.push_back(llvm::ConstantPointerNull::get(IGF.IGM.PtrTy)); } return info; @@ -2329,9 +2326,7 @@ void irgen::emitCacheAccessFunction(IRGenModule &IGM, llvm::Function *accessor, // For in-place initialization, drill to the first element of the cache. case CacheStrategy::SingletonInitialization: - cacheVariable = - llvm::ConstantExpr::getBitCast(cacheVariable, - IGM.TypeMetadataPtrTy->getPointerTo()); + cacheVariable = llvm::ConstantExpr::getBitCast(cacheVariable, IGM.PtrTy); break; case CacheStrategy::Lazy: @@ -2630,7 +2625,7 @@ MetadataResponse irgen::emitGenericTypeMetadataAccessFunction( IGM.Int8PtrTy, // arg 1 IGM.Int8PtrTy, // arg 2 IGM.TypeContextDescriptorPtrTy, // type context descriptor - IGM.OnceTy->getPointerTo() // token pointer + IGM.PtrTy // token pointer }, generateThunkFn, /*noinline*/ true)); @@ -3199,8 +3194,7 @@ emitMetadataAccessByMangledName(IRGenFunction &IGF, CanType type, // Therefore, we can perform a completely naked load here. // FIXME: Technically should be "consume", but that introduces barriers // in the current LLVM ARM backend. - auto cacheWordAddr = subIGF.Builder.CreateBitCast(cache, - IGM.Int64Ty->getPointerTo()); + auto cacheWordAddr = subIGF.Builder.CreateBitCast(cache, IGM.PtrTy); auto load = subIGF.Builder.CreateLoad( Address(cacheWordAddr, IGM.Int64Ty, Alignment(8))); // Make this barrier explicit when building for TSan to avoid false positives. @@ -3888,8 +3882,7 @@ namespace { } // Ignore the offsets. - auto offsetsPtr = - llvm::ConstantPointerNull::get(IGF.IGM.Int32Ty->getPointerTo()); + auto offsetsPtr = llvm::ConstantPointerNull::get(IGF.IGM.PtrTy); // Flags. auto flags = TupleTypeFlags().withNumElements(type->getNumElements()); diff --git a/lib/IRGen/NonFixedTypeInfo.h b/lib/IRGen/NonFixedTypeInfo.h index 3bc8f0ed8cb..50a00e5ccdf 100644 --- a/lib/IRGen/NonFixedTypeInfo.h +++ b/lib/IRGen/NonFixedTypeInfo.h @@ -54,8 +54,7 @@ private: /// Bit-cast the given pointer to the right type and assume it as an /// address of this type. Address getAsBitCastAddress(IRGenFunction &IGF, llvm::Value *addr) const { - addr = IGF.Builder.CreateBitCast(addr, - this->getStorageType()->getPointerTo()); + addr = IGF.Builder.CreateBitCast(addr, IGF.IGM.PtrTy); return this->getAddressForPointer(addr); } diff --git a/lib/IRGen/Outlining.cpp b/lib/IRGen/Outlining.cpp index 658dfab2cfb..e1380ec8224 100644 --- a/lib/IRGen/Outlining.cpp +++ b/lib/IRGen/Outlining.cpp @@ -487,11 +487,10 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction( StringRef funcName, CopyAddrHelperGenerator generator) { assert(collector.hasFinished()); - auto ptrTy = ti.getStorageType()->getPointerTo(); llvm::SmallVector paramTys; - paramTys.push_back(ptrTy); - paramTys.push_back(ptrTy); + paramTys.push_back(PtrTy); + paramTys.push_back(PtrTy); collector.addPolymorphicParameterTypes(paramTys); IRLinkage *linkage = nullptr; @@ -510,7 +509,8 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction( linkage = &privateLinkage; } - return getOrCreateHelperFunction(funcName, ptrTy, paramTys, + return getOrCreateHelperFunction( + funcName, PtrTy, paramTys, [&](IRGenFunction &IGF) { auto params = IGF.collectParameters(); Address src = ti.getAddressForPointer(params.claimNext()); @@ -582,12 +582,12 @@ llvm::Constant *IRGenModule::getOrCreateOutlinedDestroyFunction( linkage = &privateLinkage; } - auto ptrTy = ti.getStorageType()->getPointerTo(); llvm::SmallVector paramTys; - paramTys.push_back(ptrTy); + paramTys.push_back(PtrTy); collector.addPolymorphicParameterTypes(paramTys); - return getOrCreateHelperFunction(funcName, ptrTy, paramTys, + return getOrCreateHelperFunction( + funcName, PtrTy, paramTys, [&](IRGenFunction &IGF) { Explosion params = IGF.collectParameters(); Address addr = ti.getAddressForPointer(params.claimNext()); diff --git a/lib/IRGen/ScalarTypeInfo.h b/lib/IRGen/ScalarTypeInfo.h index 204c8646228..9d108cae108 100644 --- a/lib/IRGen/ScalarTypeInfo.h +++ b/lib/IRGen/ScalarTypeInfo.h @@ -128,8 +128,7 @@ public: auto nextByteSizedIntTy = llvm::IntegerType::get(IGM.getLLVMContext(), nextByteSize); auto newAddr = - Address(Builder.CreatePointerCast(addr.getAddress(), - nextByteSizedIntTy->getPointerTo()), + Address(Builder.CreatePointerCast(addr.getAddress(), IGF.IGM.PtrTy), nextByteSizedIntTy, addr.getAlignment()); auto newValue = Builder.CreateZExt(src.claimNext(), nextByteSizedIntTy); Builder.CreateStore(newValue, newAddr); diff --git a/lib/IRGen/StructLayout.cpp b/lib/IRGen/StructLayout.cpp index 368ff61dbf9..f6eea342200 100644 --- a/lib/IRGen/StructLayout.cpp +++ b/lib/IRGen/StructLayout.cpp @@ -291,8 +291,7 @@ llvm::Constant *StructLayout::emitAlignMask(IRGenModule &IGM) const { Address StructLayout::emitCastTo(IRGenFunction &IGF, llvm::Value *ptr, const llvm::Twine &name) const { - llvm::Value *addr = - IGF.Builder.CreateBitCast(ptr, getType()->getPointerTo(), name); + llvm::Value *addr = IGF.Builder.CreateBitCast(ptr, IGF.IGM.PtrTy, name); return Address(addr, getType(), getAlignment()); } diff --git a/lib/IRGen/TypeLayout.cpp b/lib/IRGen/TypeLayout.cpp index 60c879bb384..b88fa9939f1 100644 --- a/lib/IRGen/TypeLayout.cpp +++ b/lib/IRGen/TypeLayout.cpp @@ -514,8 +514,7 @@ llvm::Function *createFixedEnumLoadTag(IRGenModule &IGM, [&](IRGenFunction &IGF) { auto enumPtr = IGF.collectParameters().claimNext(); auto *typeInfo = *entry.fixedTypeInfo; - auto enumType = typeInfo->getStorageType()->getPointerTo(); - auto castEnumPtr = IGF.Builder.CreateBitCast(enumPtr, enumType); + auto castEnumPtr = IGF.Builder.CreateBitCast(enumPtr, IGM.PtrTy); auto enumAddr = typeInfo->getAddressForPointer(castEnumPtr); auto &strategy = getEnumImplStrategy(IGM, entry.ty); @@ -1113,8 +1112,7 @@ static llvm::Value *projectOutlineBuffer(IRGenFunction &IGF, Address buffer, llvm::Value *alignmentMask) { auto &IGM = IGF.IGM; auto &Builder = IGF.Builder; - Address boxAddress(Builder.CreateBitCast(buffer.getAddress(), - IGM.RefCountedPtrTy->getPointerTo()), + Address boxAddress(Builder.CreateBitCast(buffer.getAddress(), IGM.PtrTy), IGM.RefCountedPtrTy, buffer.getAlignment()); auto *boxStart = Builder.CreateLoad(boxAddress); auto *heapHeaderSize = @@ -1122,8 +1120,7 @@ static llvm::Value *projectOutlineBuffer(IRGenFunction &IGF, Address buffer, auto *startOffset = Builder.CreateAnd(Builder.CreateAdd(heapHeaderSize, alignmentMask), Builder.CreateNot(alignmentMask)); - auto *addressInBox = - IGF.emitByteOffsetGEP(boxStart, startOffset, IGM.OpaqueTy); + auto *addressInBox = IGF.emitByteOffsetGEP(boxStart, startOffset); addressInBox = Builder.CreateBitCast(addressInBox, IGM.OpaquePtrTy); return addressInBox; @@ -1168,10 +1165,9 @@ llvm::Value *TypeLayoutEntry::initBufferWithCopyOfBuffer(IRGenFunction &IGF, Builder.emitBlock(allocateBB); { // The buffer stores a reference to a copy-on-write managed heap buffer. - auto *destReferenceAddr = Builder.CreateBitCast( - dest.getAddress(), IGM.RefCountedPtrTy->getPointerTo()); - auto *srcReferenceAddr = Builder.CreateBitCast( - src.getAddress(), IGM.RefCountedPtrTy->getPointerTo()); + auto *destReferenceAddr = + Builder.CreateBitCast(dest.getAddress(), IGM.PtrTy); + auto *srcReferenceAddr = Builder.CreateBitCast(src.getAddress(), IGM.PtrTy); auto *srcReference = Builder.CreateLoad( Address(srcReferenceAddr, IGM.RefCountedPtrTy, src.getAlignment())); IGF.emitNativeStrongRetain(srcReference, IGF.getDefaultAtomicity()); @@ -1326,6 +1322,8 @@ bool ScalarTypeLayoutEntry::refCountString(IRGenModule &IGM, } void ScalarTypeLayoutEntry::destroy(IRGenFunction &IGF, Address addr) const { + auto &IGM = IGF.IGM; + switch (scalarKind) { case ScalarKind::TriviallyDestroyable: return; @@ -1334,8 +1332,7 @@ void ScalarTypeLayoutEntry::destroy(IRGenFunction &IGF, Address addr) const { case ScalarKind::NativeStrongReference: { auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); - auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), - addressType->getPointerTo()); + auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), IGM.PtrTy); addr = Address(castAddr, addressType, alignment); llvm::Value *val = IGF.Builder.CreateLoad(addr, "toDestroy"); IGF.emitNativeStrongRelease(val, IGF.getDefaultAtomicity()); @@ -1344,8 +1341,7 @@ void ScalarTypeLayoutEntry::destroy(IRGenFunction &IGF, Address addr) const { case ScalarKind::ErrorReference: { auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); - auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), - addressType->getPointerTo()); + auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), IGM.PtrTy); addr = Address(castAddr, addressType, alignment); llvm::Value *val = IGF.Builder.CreateLoad(addr, "toDestroy"); IGF.emitErrorStrongRelease(val); @@ -1366,8 +1362,7 @@ void ScalarTypeLayoutEntry::destroy(IRGenFunction &IGF, Address addr) const { case ScalarKind::UnknownReference: { auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); - auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), - addressType->getPointerTo()); + auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), IGM.PtrTy); addr = Address(castAddr, addressType, alignment); llvm::Value *val = IGF.Builder.CreateLoad(addr, "toDestroy"); IGF.emitUnknownStrongRelease(val, IGF.getDefaultAtomicity()); @@ -1383,10 +1378,8 @@ void ScalarTypeLayoutEntry::destroy(IRGenFunction &IGF, Address addr) const { } case ScalarKind::BridgeReference: { auto alignment = typeInfo.getFixedAlignment(); - auto addressType = typeInfo.getStorageType()->getPointerTo(); - auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), - addressType->getPointerTo()); - addr = Address(castAddr, addressType, alignment); + auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), IGM.PtrTy); + addr = Address(castAddr, IGM.PtrTy, alignment); llvm::Value *val = IGF.Builder.CreateLoad(addr, "toDestroy"); IGF.emitBridgeStrongRelease(val, IGF.getDefaultAtomicity()); return; @@ -1394,8 +1387,8 @@ void ScalarTypeLayoutEntry::destroy(IRGenFunction &IGF, Address addr) const { case ScalarKind::ObjCReference: { auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); - auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), - addressType->getPointerTo()); + auto *castAddr = + IGF.Builder.CreateBitCast(addr.getAddress(), IGF.IGM.PtrTy); addr = Address(castAddr, addressType, alignment); llvm::Value *val = IGF.Builder.CreateLoad(addr, "toDestroy"); IGF.emitObjCStrongRelease(val); @@ -1413,8 +1406,7 @@ void ScalarTypeLayoutEntry::destroy(IRGenFunction &IGF, Address addr) const { // function pointer, but we need to release the opaque pointer. auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); - auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), - addressType->getPointerTo()); + auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), IGM.PtrTy); addr = Address(castAddr, addressType, alignment); auto secondElement = IGF.Builder.CreateStructGEP( addr, 1, IGF.IGM.getPointerSize(), @@ -1437,7 +1429,7 @@ void ScalarTypeLayoutEntry::assignWithCopy(IRGenFunction &IGF, Address dest, Address src) const { auto alignment = typeInfo.getFixedAlignment(); auto storageTy = typeInfo.getStorageType(); - auto addressType = typeInfo.getStorageType()->getPointerTo(); + auto *addressType = IGF.IGM.PtrTy; auto &Builder = IGF.Builder; dest = Address(Builder.CreateBitCast(dest.getAddress(), addressType), storageTy, alignment); @@ -1450,7 +1442,7 @@ void ScalarTypeLayoutEntry::assignWithTake(IRGenFunction &IGF, Address dest, Address src) const { auto alignment = typeInfo.getFixedAlignment(); auto storageTy = typeInfo.getStorageType(); - auto addressType = typeInfo.getStorageType()->getPointerTo(); + auto *addressType = IGF.IGM.PtrTy; auto &Builder = IGF.Builder; dest = Address(Builder.CreateBitCast(dest.getAddress(), addressType), storageTy, alignment); @@ -1463,7 +1455,7 @@ void ScalarTypeLayoutEntry::initWithCopy(IRGenFunction &IGF, Address dest, Address src) const { auto alignment = typeInfo.getFixedAlignment(); auto storageTy = typeInfo.getStorageType(); - auto addressType = typeInfo.getStorageType()->getPointerTo(); + auto *addressType = IGF.IGM.PtrTy; auto &Builder = IGF.Builder; dest = Address(Builder.CreateBitCast(dest.getAddress(), addressType), storageTy, alignment); @@ -1475,7 +1467,7 @@ void ScalarTypeLayoutEntry::initWithCopy(IRGenFunction &IGF, Address dest, void ScalarTypeLayoutEntry::initWithTake(IRGenFunction &IGF, Address dest, Address src) const { auto alignment = typeInfo.getFixedAlignment(); - auto addressType = typeInfo.getStorageType()->getPointerTo(); + auto *addressType = IGF.IGM.PtrTy; auto storageTy = typeInfo.getStorageType(); auto &Builder = IGF.Builder; dest = Address(Builder.CreateBitCast(dest.getAddress(), addressType), @@ -1489,7 +1481,7 @@ void ScalarTypeLayoutEntry::initWithTake(IRGenFunction &IGF, Address dest, llvm::Value *ScalarTypeLayoutEntry::getEnumTagSinglePayload( IRGenFunction &IGF, llvm::Value *numEmptyCases, Address value) const { auto alignment = typeInfo.getFixedAlignment(); - auto addressType = typeInfo.getStorageType()->getPointerTo(); + auto *addressType = IGF.IGM.PtrTy; auto storageTy = typeInfo.getStorageType(); auto &Builder = IGF.Builder; value = Address(Builder.CreateBitCast(value.getAddress(), addressType), @@ -1505,7 +1497,7 @@ void ScalarTypeLayoutEntry::storeEnumTagSinglePayload(IRGenFunction &IGF, Address addr) const { auto alignment = typeInfo.getFixedAlignment(); auto storageTy = typeInfo.getStorageType(); - auto addressType = typeInfo.getStorageType()->getPointerTo(); + auto *addressType = IGF.IGM.PtrTy; auto &Builder = IGF.Builder; addr = Address(Builder.CreateBitCast(addr.getAddress(), addressType), storageTy, alignment); @@ -1819,8 +1811,7 @@ void AlignedGroupEntry::destroy(IRGenFunction &IGF, Address addr) const { offset = Size(aligned); auto projected = IGF.emitByteOffsetGEP( addr.getAddress(), - llvm::ConstantInt::get(IGF.IGM.Int32Ty, offset.getValue()), - IGF.IGM.OpaquePtrTy); + llvm::ConstantInt::get(IGF.IGM.Int32Ty, offset.getValue())); entry->destroy(IGF, Address(projected, IGF.IGM.OpaquePtrTy, *entry->fixedAlignment(IGF.IGM))); offset += *entry->fixedSize(IGF.IGM); @@ -1862,12 +1853,10 @@ void AlignedGroupEntry::withEachEntry( offset = Size(aligned); auto projectedSrc = IGF.emitByteOffsetGEP( src.getAddress(), - llvm::ConstantInt::get(IGF.IGM.Int32Ty, offset.getValue()), - IGF.IGM.OpaquePtrTy); + llvm::ConstantInt::get(IGF.IGM.Int32Ty, offset.getValue())); auto projectedDest = IGF.emitByteOffsetGEP( dest.getAddress(), - llvm::ConstantInt::get(IGF.IGM.Int32Ty, offset.getValue()), - IGF.IGM.OpaquePtrTy); + llvm::ConstantInt::get(IGF.IGM.Int32Ty, offset.getValue())); entryFun(entry, Address(projectedDest, IGF.IGM.OpaquePtrTy, *entry->fixedAlignment(IGF.IGM)), @@ -1955,8 +1944,7 @@ llvm::Value *AlignedGroupEntry::withExtraInhabitantProvidingEntry( if (xiCount == maxXICount) { auto projected = IGF.emitByteOffsetGEP( addr.getAddress(), - llvm::ConstantInt::get(IGF.IGM.Int32Ty, offset.getValue()), - IGF.IGM.OpaquePtrTy); + llvm::ConstantInt::get(IGF.IGM.Int32Ty, offset.getValue())); return entryFun(entry, Address(projected, IGF.IGM.OpaquePtrTy, *entry->fixedAlignment(IGF.IGM)), @@ -3747,8 +3735,7 @@ void TypeInfoBasedTypeLayoutEntry::destroy(IRGenFunction &IGF, Address addr) const { auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); - auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), - addressType->getPointerTo()); + auto *castAddr = IGF.Builder.CreateBitCast(addr.getAddress(), IGF.IGM.PtrTy); addr = Address(castAddr, addressType, alignment); typeInfo.destroy(IGF, addr, representative, true); } @@ -3759,14 +3746,10 @@ void TypeInfoBasedTypeLayoutEntry::assignWithCopy(IRGenFunction &IGF, auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); auto &Builder = IGF.Builder; - dest = - Address(Builder.CreateBitCast(dest.getAddress(), - addressType->getPointerTo()), - addressType, alignment); - src = - Address(Builder.CreateBitCast(src.getAddress(), - addressType->getPointerTo()), - addressType, alignment); + dest = Address(Builder.CreateBitCast(dest.getAddress(), IGF.IGM.PtrTy), + addressType, alignment); + src = Address(Builder.CreateBitCast(src.getAddress(), IGF.IGM.PtrTy), + addressType, alignment); typeInfo.assignWithCopy(IGF, dest, src, representative, true); } @@ -3776,14 +3759,10 @@ void TypeInfoBasedTypeLayoutEntry::assignWithTake(IRGenFunction &IGF, auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); auto &Builder = IGF.Builder; - dest = - Address(Builder.CreateBitCast(dest.getAddress(), - addressType->getPointerTo()), - addressType, alignment); - src = - Address(Builder.CreateBitCast(src.getAddress(), - addressType->getPointerTo()), - addressType, alignment); + dest = Address(Builder.CreateBitCast(dest.getAddress(), IGF.IGM.PtrTy), + addressType, alignment); + src = Address(Builder.CreateBitCast(src.getAddress(), IGF.IGM.PtrTy), + addressType, alignment); typeInfo.assignWithTake(IGF, dest, src, representative, true); } @@ -3793,14 +3772,10 @@ void TypeInfoBasedTypeLayoutEntry::initWithCopy(IRGenFunction &IGF, auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); auto &Builder = IGF.Builder; - dest = - Address(Builder.CreateBitCast(dest.getAddress(), - addressType->getPointerTo()), - addressType, alignment); - src = - Address(Builder.CreateBitCast(src.getAddress(), - addressType->getPointerTo()), - addressType, alignment); + dest = Address(Builder.CreateBitCast(dest.getAddress(), IGF.IGM.PtrTy), + addressType, alignment); + src = Address(Builder.CreateBitCast(src.getAddress(), IGF.IGM.PtrTy), + addressType, alignment); typeInfo.initializeWithCopy(IGF, dest, src, representative, true); } @@ -3810,14 +3785,10 @@ void TypeInfoBasedTypeLayoutEntry::initWithTake(IRGenFunction &IGF, auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); auto &Builder = IGF.Builder; - dest = - Address(Builder.CreateBitCast(dest.getAddress(), - addressType->getPointerTo()), - addressType, alignment); - src = - Address(Builder.CreateBitCast(src.getAddress(), - addressType->getPointerTo()), - addressType, alignment); + dest = Address(Builder.CreateBitCast(dest.getAddress(), IGF.IGM.PtrTy), + addressType, alignment); + src = Address(Builder.CreateBitCast(src.getAddress(), IGF.IGM.PtrTy), + addressType, alignment); typeInfo.initializeWithTake(IGF, dest, src, representative, true, /*zeroizeIfSensitive=*/ true); } @@ -3827,8 +3798,7 @@ llvm::Value *TypeInfoBasedTypeLayoutEntry::getEnumTagSinglePayload( auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); auto &Builder = IGF.Builder; - value = Address(Builder.CreateBitCast(value.getAddress(), - addressType->getPointerTo()), + value = Address(Builder.CreateBitCast(value.getAddress(), IGF.IGM.PtrTy), addressType, alignment); return typeInfo.getEnumTagSinglePayload(IGF, numEmptyCases, value, representative, true); @@ -3840,8 +3810,7 @@ void TypeInfoBasedTypeLayoutEntry::storeEnumTagSinglePayload( auto alignment = typeInfo.getFixedAlignment(); auto addressType = typeInfo.getStorageType(); auto &Builder = IGF.Builder; - addr = Address(Builder.CreateBitCast(addr.getAddress(), - addressType->getPointerTo()), + addr = Address(Builder.CreateBitCast(addr.getAddress(), IGF.IGM.PtrTy), addressType, alignment); typeInfo.storeEnumTagSinglePayload(IGF, tag, numEmptyCases, addr, representative, true); diff --git a/lib/LLVMPasses/ARCEntryPointBuilder.h b/lib/LLVMPasses/ARCEntryPointBuilder.h index 6811d8c405b..9e92f3f2349 100644 --- a/lib/LLVMPasses/ARCEntryPointBuilder.h +++ b/lib/LLVMPasses/ARCEntryPointBuilder.h @@ -66,8 +66,7 @@ class ARCEntryPointBuilder { NullablePtr BridgeReleaseN; // The type cache. - NullablePtr ObjectPtrTy; - NullablePtr BridgeObjectPtrTy; + llvm::PointerType *PtrTy; llvm::CallingConv::ID DefaultCC; @@ -91,8 +90,9 @@ class ARCEntryPointBuilder { public: ARCEntryPointBuilder(Function &F) - : B(&*F.begin()), Retain(), ObjectPtrTy(), - DefaultCC(SWIFT_DEFAULT_LLVM_CC) { } + : B(&*F.begin()), Retain(), + PtrTy(llvm::PointerType::getUnqual(B.getContext())), + DefaultCC(SWIFT_DEFAULT_LLVM_CC) {} ~ARCEntryPointBuilder() = default; ARCEntryPointBuilder(ARCEntryPointBuilder &&) = delete; @@ -119,7 +119,7 @@ public: CallInst *createRetain(Value *V, CallInst *OrigI) { // Cast just to make sure that we have the right type. - V = B.CreatePointerCast(V, getObjectPtrTy()); + V = B.CreatePointerCast(V, PtrTy); // Create the call. CallInst *CI = CreateCall(getRetain(OrigI), V); @@ -128,7 +128,7 @@ public: CallInst *createRelease(Value *V, CallInst *OrigI) { // Cast just to make sure that we have the right type. - V = B.CreatePointerCast(V, getObjectPtrTy()); + V = B.CreatePointerCast(V, PtrTy); // Create the call. CallInst *CI = CreateCall(getRelease(OrigI), V); @@ -138,29 +138,29 @@ public: CallInst *createCheckUnowned(Value *V, CallInst *OrigI) { // Cast just to make sure that we have the right type. - V = B.CreatePointerCast(V, getObjectPtrTy()); - + V = B.CreatePointerCast(V, PtrTy); + CallInst *CI = CreateCall(getCheckUnowned(OrigI), V); return CI; } CallInst *createRetainN(Value *V, uint32_t n, CallInst *OrigI) { // Cast just to make sure that we have the right object type. - V = B.CreatePointerCast(V, getObjectPtrTy()); + V = B.CreatePointerCast(V, PtrTy); CallInst *CI = CreateCall(getRetainN(OrigI), {V, getIntConstant(n)}); return CI; } CallInst *createReleaseN(Value *V, uint32_t n, CallInst *OrigI) { // Cast just to make sure we have the right object type. - V = B.CreatePointerCast(V, getObjectPtrTy()); + V = B.CreatePointerCast(V, PtrTy); CallInst *CI = CreateCall(getReleaseN(OrigI), {V, getIntConstant(n)}); return CI; } CallInst *createUnknownObjectRetainN(Value *V, uint32_t n, CallInst *OrigI) { // Cast just to make sure that we have the right object type. - V = B.CreatePointerCast(V, getObjectPtrTy()); + V = B.CreatePointerCast(V, PtrTy); CallInst *CI = CreateCall(getUnknownObjectRetainN(OrigI), {V, getIntConstant(n)}); return CI; @@ -168,7 +168,7 @@ public: CallInst *createUnknownObjectReleaseN(Value *V, uint32_t n, CallInst *OrigI) { // Cast just to make sure we have the right object type. - V = B.CreatePointerCast(V, getObjectPtrTy()); + V = B.CreatePointerCast(V, PtrTy); CallInst *CI = CreateCall(getUnknownObjectReleaseN(OrigI), {V, getIntConstant(n)}); return CI; @@ -176,14 +176,14 @@ public: CallInst *createBridgeRetainN(Value *V, uint32_t n, CallInst *OrigI) { // Cast just to make sure we have the right object type. - V = B.CreatePointerCast(V, getBridgeObjectPtrTy()); + V = B.CreatePointerCast(V, PtrTy); CallInst *CI = CreateCall(getBridgeRetainN(OrigI), {V, getIntConstant(n)}); return CI; } CallInst *createBridgeReleaseN(Value *V, uint32_t n, CallInst *OrigI) { // Cast just to make sure we have the right object type. - V = B.CreatePointerCast(V, getBridgeObjectPtrTy()); + V = B.CreatePointerCast(V, PtrTy); CallInst *CI = CreateCall(getBridgeReleaseN(OrigI), {V, getIntConstant(n)}); return CI; } @@ -217,14 +217,13 @@ private: Constant *getRetain(CallInst *OrigI) { if (Retain) return Retain.get(); - auto *ObjectPtrTy = getObjectPtrTy(); llvm::Constant *cache = nullptr; - Retain = getRuntimeFn( - getModule(), cache, "Swift", - isNonAtomic(OrigI) ? "swift_nonatomic_retain" : "swift_retain", - DefaultCC, RuntimeAvailability::AlwaysAvailable, {ObjectPtrTy}, - {ObjectPtrTy}, {NoUnwind, FirstParamReturned}, {}); + Retain = getRuntimeFn(getModule(), cache, "Swift", + isNonAtomic(OrigI) ? "swift_nonatomic_retain" + : "swift_retain", + DefaultCC, RuntimeAvailability::AlwaysAvailable, + {PtrTy}, {PtrTy}, {NoUnwind, FirstParamReturned}, {}); return Retain.get(); } @@ -233,7 +232,7 @@ private: Constant *getRelease(CallInst *OrigI) { if (Release) return Release.get(); - auto *ObjectPtrTy = getObjectPtrTy(); + auto *VoidTy = Type::getVoidTy(getModule().getContext()); llvm::Constant *cache = nullptr; @@ -241,7 +240,7 @@ private: isNonAtomic(OrigI) ? "swift_nonatomic_release" : "swift_release", DefaultCC, RuntimeAvailability::AlwaysAvailable, - {VoidTy}, {ObjectPtrTy}, {NoUnwind}, {}); + {VoidTy}, {PtrTy}, {NoUnwind}, {}); return Release.get(); } @@ -249,8 +248,8 @@ private: Constant *getCheckUnowned(CallInst *OrigI) { if (CheckUnowned) return CheckUnowned.get(); - - auto *ObjectPtrTy = getObjectPtrTy(); + + auto *ObjectPtrTy = PtrTy; auto &M = getModule(); auto AttrList = AttributeList::get(M.getContext(), 1, Attribute::NoCapture); AttrList = AttrList.addFnAttribute(M.getContext(), Attribute::NoUnwind); @@ -269,15 +268,15 @@ private: Constant *getRetainN(CallInst *OrigI) { if (RetainN) return RetainN.get(); - auto *ObjectPtrTy = getObjectPtrTy(); + auto *Int32Ty = Type::getInt32Ty(getModule().getContext()); llvm::Constant *cache = nullptr; RetainN = getRuntimeFn( getModule(), cache, "Swift", isNonAtomic(OrigI) ? "swift_nonatomic_retain_n" : "swift_retain_n", - DefaultCC, RuntimeAvailability::AlwaysAvailable, {ObjectPtrTy}, - {ObjectPtrTy, Int32Ty}, {NoUnwind, FirstParamReturned}, {}); + DefaultCC, RuntimeAvailability::AlwaysAvailable, {PtrTy}, + {PtrTy, Int32Ty}, {NoUnwind, FirstParamReturned}, {}); return RetainN.get(); } @@ -286,7 +285,7 @@ private: Constant *getReleaseN(CallInst *OrigI) { if (ReleaseN) return ReleaseN.get(); - auto *ObjectPtrTy = getObjectPtrTy(); + auto *Int32Ty = Type::getInt32Ty(getModule().getContext()); auto *VoidTy = Type::getVoidTy(getModule().getContext()); @@ -295,7 +294,7 @@ private: isNonAtomic(OrigI) ? "swift_nonatomic_release_n" : "swift_release_n", DefaultCC, RuntimeAvailability::AlwaysAvailable, - {VoidTy}, {ObjectPtrTy, Int32Ty}, {NoUnwind}, {}); + {VoidTy}, {PtrTy, Int32Ty}, {NoUnwind}, {}); return ReleaseN.get(); } @@ -305,7 +304,7 @@ private: Constant *getUnknownObjectRetainN(CallInst *OrigI) { if (UnknownObjectRetainN) return UnknownObjectRetainN.get(); - auto *ObjectPtrTy = getObjectPtrTy(); + auto *Int32Ty = Type::getInt32Ty(getModule().getContext()); llvm::Constant *cache = nullptr; @@ -313,8 +312,8 @@ private: getModule(), cache, "Swift", isNonAtomic(OrigI) ? "swift_nonatomic_unknownObjectRetain_n" : "swift_unknownObjectRetain_n", - DefaultCC, RuntimeAvailability::AlwaysAvailable, {ObjectPtrTy}, - {ObjectPtrTy, Int32Ty}, {NoUnwind, FirstParamReturned}, {}); + DefaultCC, RuntimeAvailability::AlwaysAvailable, {PtrTy}, + {PtrTy, Int32Ty}, {NoUnwind, FirstParamReturned}, {}); return UnknownObjectRetainN.get(); } @@ -323,7 +322,7 @@ private: Constant *getUnknownObjectReleaseN(CallInst *OrigI) { if (UnknownObjectReleaseN) return UnknownObjectReleaseN.get(); - auto *ObjectPtrTy = getObjectPtrTy(); + auto *Int32Ty = Type::getInt32Ty(getModule().getContext()); auto *VoidTy = Type::getVoidTy(getModule().getContext()); @@ -333,7 +332,7 @@ private: isNonAtomic(OrigI) ? "swift_nonatomic_unknownObjectRelease_n" : "swift_unknownObjectRelease_n", DefaultCC, RuntimeAvailability::AlwaysAvailable, {VoidTy}, - {ObjectPtrTy, Int32Ty}, {NoUnwind}, {}); + {PtrTy, Int32Ty}, {NoUnwind}, {}); return UnknownObjectReleaseN.get(); } @@ -342,16 +341,16 @@ private: Constant *getBridgeRetainN(CallInst *OrigI) { if (BridgeRetainN) return BridgeRetainN.get(); - auto *BridgeObjectPtrTy = getBridgeObjectPtrTy(); + auto *Int32Ty = Type::getInt32Ty(getModule().getContext()); llvm::Constant *cache = nullptr; - BridgeRetainN = getRuntimeFn( - getModule(), cache, "Swift", - isNonAtomic(OrigI) ? "swift_nonatomic_bridgeObjectRetain_n" - : "swift_bridgeObjectRetain_n", - DefaultCC, RuntimeAvailability::AlwaysAvailable, {BridgeObjectPtrTy}, - {BridgeObjectPtrTy, Int32Ty}, {NoUnwind}, {}); + BridgeRetainN = + getRuntimeFn(getModule(), cache, "Swift", + isNonAtomic(OrigI) ? "swift_nonatomic_bridgeObjectRetain_n" + : "swift_bridgeObjectRetain_n", + DefaultCC, RuntimeAvailability::AlwaysAvailable, {PtrTy}, + {PtrTy, Int32Ty}, {NoUnwind}, {}); return BridgeRetainN.get(); } @@ -360,7 +359,6 @@ private: if (BridgeReleaseN) return BridgeReleaseN.get(); - auto *BridgeObjectPtrTy = getBridgeObjectPtrTy(); auto *Int32Ty = Type::getInt32Ty(getModule().getContext()); auto *VoidTy = Type::getVoidTy(getModule().getContext()); @@ -370,35 +368,10 @@ private: isNonAtomic(OrigI) ? "swift_nonatomic_bridgeObjectRelease_n" : "swift_bridgeObjectRelease_n", DefaultCC, RuntimeAvailability::AlwaysAvailable, {VoidTy}, - {BridgeObjectPtrTy, Int32Ty}, {NoUnwind}, {}); + {PtrTy, Int32Ty}, {NoUnwind}, {}); return BridgeReleaseN.get(); } - Type *getNamedOpaquePtrTy(StringRef name) { - auto &M = getModule(); - if (auto *ty = llvm::StructType::getTypeByName(M.getContext(), name)) { - return ty->getPointerTo(); - } - - // Otherwise, create an anonymous struct type. - auto *ty = llvm::StructType::create(M.getContext(), name); - return ty->getPointerTo(); - } - - Type *getObjectPtrTy() { - if (ObjectPtrTy) - return ObjectPtrTy.get(); - ObjectPtrTy = getNamedOpaquePtrTy("swift.refcounted"); - return ObjectPtrTy.get(); - } - - Type *getBridgeObjectPtrTy() { - if (BridgeObjectPtrTy) - return BridgeObjectPtrTy.get(); - BridgeObjectPtrTy = getNamedOpaquePtrTy("swift.bridge"); - return BridgeObjectPtrTy.get(); - } - Constant *getIntConstant(uint32_t constant) { auto &M = getModule(); auto *Int32Ty = Type::getInt32Ty(M.getContext()); diff --git a/lib/LLVMPasses/LLVMMergeFunctions.cpp b/lib/LLVMPasses/LLVMMergeFunctions.cpp index 3f53edfa891..cc4d99e523a 100644 --- a/lib/LLVMPasses/LLVMMergeFunctions.cpp +++ b/lib/LLVMPasses/LLVMMergeFunctions.cpp @@ -1322,8 +1322,9 @@ bool SwiftMergeFunctions::replaceDirectCallers(Function *Old, Function *New, auto *FType = FunctionType::get(Old->getFunctionType()->getReturnType(), OldParamTypes, false); - auto *FPtrType = PointerType::get(FType, - cast(New->getType())->getAddressSpace()); + auto *FPtrType = + PointerType::get(module->getContext(), + cast(New->getType())->getAddressSpace()); Value *Callee = ConstantExpr::getBitCast(New, FPtrType); CallInst *NewCI = Builder.CreateCall(FType, Callee, NewArgs); diff --git a/lib/Sema/TypeCheckSwitchStmt.cpp b/lib/Sema/TypeCheckSwitchStmt.cpp index 2dcc2b59297..a03fb5c1c78 100644 --- a/lib/Sema/TypeCheckSwitchStmt.cpp +++ b/lib/Sema/TypeCheckSwitchStmt.cpp @@ -1503,8 +1503,9 @@ namespace { // If there's no sub-pattern then there's no further recursive // structure here. Yield the constructor space. // FIXME: Compound names. - return Space::forConstructor( - item->getType(), VP->getName().getBaseIdentifier(), std::nullopt); + return Space::forConstructor(item->getType(), + VP->getName().getBaseIdentifier(), + ArrayRef()); } SmallVector conArgSpace; diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index b4d00c7eea7..6fe560f1845 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -4336,7 +4336,7 @@ NeverNullType TypeResolver::resolveASTFunctionType( FunctionType::ExtInfoBuilder extInfoBuilder( FunctionTypeRepresentation::Swift, noescape, repr->isThrowing(), thrownTy, diffKind, /*clangFunctionType*/ nullptr, isolation, - /*LifetimeDependenceInfo*/ std::nullopt, hasSendingResult); + /*LifetimeDependenceInfo*/ {}, hasSendingResult); const clang::Type *clangFnType = parsedClangFunctionType; if (shouldStoreClangType(representation) && !clangFnType) @@ -4557,7 +4557,7 @@ NeverNullType TypeResolver::resolveSILFunctionType(FunctionTypeRepr *repr, auto extInfoBuilder = SILFunctionType::ExtInfoBuilder( representation, pseudogeneric, noescape, sendable, async, unimplementable, isolation, diffKind, clangFnType, - /*LifetimeDependenceInfo*/ std::nullopt); + /*LifetimeDependenceInfo*/ {}); // Resolve parameter and result types using the function's generic // environment. diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 904329b7ccd..6e264e176ee 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -3749,7 +3749,8 @@ public: return declOrOffset; auto theStruct = MF.createDecl(SourceLoc(), name, SourceLoc(), - std::nullopt, genericParams, DC); + ArrayRef(), + genericParams, DC); declOrOffset = theStruct; // Read the generic environment. @@ -3898,8 +3899,9 @@ public: } ctx.evaluator.cacheOutput(LifetimeDependenceInfoRequest{ctor}, - lifetimeDependencies.empty()? std::nullopt : - ctx.AllocateCopy(lifetimeDependencies)); + lifetimeDependencies.empty() + ? ArrayRef() + : ctx.AllocateCopy(lifetimeDependencies)); if (auto errorConvention = MF.maybeReadForeignErrorConvention()) ctor->setForeignErrorConvention(*errorConvention); @@ -4502,7 +4504,8 @@ public: } ctx.evaluator.cacheOutput(LifetimeDependenceInfoRequest{fn}, - lifetimeDependencies.empty() ? std::nullopt + lifetimeDependencies.empty() + ? ArrayRef() : ctx.AllocateCopy(lifetimeDependencies)); if (auto errorConvention = MF.maybeReadForeignErrorConvention()) @@ -4833,7 +4836,7 @@ public: auto proto = MF.createDecl( DC, SourceLoc(), SourceLoc(), name, - ArrayRef(), std::nullopt, + ArrayRef(), ArrayRef(), /*TrailingWhere=*/nullptr); declOrOffset = proto; @@ -5059,9 +5062,9 @@ public: if (declOrOffset.isComplete()) return declOrOffset; - auto theClass = - MF.createDecl(SourceLoc(), name, SourceLoc(), std::nullopt, - genericParams, DC, isExplicitActorDecl); + auto theClass = MF.createDecl( + SourceLoc(), name, SourceLoc(), ArrayRef(), + genericParams, DC, isExplicitActorDecl); declOrOffset = theClass; theClass->setGenericSignature(MF.getGenericSignature(genericSigID)); @@ -5142,8 +5145,9 @@ public: if (declOrOffset.isComplete()) return declOrOffset; - auto theEnum = MF.createDecl(SourceLoc(), name, SourceLoc(), - std::nullopt, genericParams, DC); + auto theEnum = + MF.createDecl(SourceLoc(), name, SourceLoc(), + ArrayRef(), genericParams, DC); declOrOffset = theEnum; @@ -5266,8 +5270,9 @@ public: } ctx.evaluator.cacheOutput(LifetimeDependenceInfoRequest{elem}, - lifetimeDependencies.empty()? std::nullopt : - ctx.AllocateCopy(lifetimeDependencies)); + lifetimeDependencies.empty() + ? ArrayRef() + : ctx.AllocateCopy(lifetimeDependencies)); return elem; } @@ -7397,7 +7402,7 @@ detail::function_deserializer::deserialize(ModuleFile &MF, auto info = FunctionType::ExtInfoBuilder( *representation, noescape, throws, thrownError, *diffKind, clangFunctionType, isolation, - /*LifetimeDependenceInfo */ std::nullopt, hasSendingResult) + /*LifetimeDependenceInfo */ {}, hasSendingResult) .withSendable(sendable) .withAsync(async) .build(); @@ -7965,7 +7970,7 @@ Expected DESERIALIZE_TYPE(SIL_FUNCTION_TYPE)( auto extInfo = SILFunctionType::ExtInfoBuilder( *representation, pseudogeneric, noescape, sendable, async, unimplementable, isolation, *diffKind, clangFunctionType, - /*LifetimeDependenceInfo*/ std::nullopt) + /*LifetimeDependenceInfo*/ {}) .build(); // Process the coroutine kind. diff --git a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp index ac233ae3c66..c5d2c5f3b26 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp @@ -1102,7 +1102,7 @@ static bool getModuleInterfaceInfo(ASTContext &Ctx, StringRef ModuleName, llvm::raw_svector_ostream OS(Text); AnnotatingPrinter Printer(OS); - printModuleInterface(M, std::nullopt, TraversalOptions, Printer, Options, + printModuleInterface(M, /*GroupNames*/ {}, TraversalOptions, Printer, Options, true); Info.Text = std::string(OS.str()); diff --git a/tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp b/tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp index 88f2c7b4100..c46f297a4b4 100644 --- a/tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp +++ b/tools/SourceKit/lib/SwiftLang/SwiftEditorInterfaceGen.cpp @@ -886,7 +886,7 @@ void SwiftLangSupport::editorOpenHeaderInterface(EditorConsumer &Consumer, CompilerInvocation Invocation; std::string Error; - ArrayRef SwiftArgs = UsingSwiftArgs ? Args : std::nullopt; + auto SwiftArgs = UsingSwiftArgs ? Args : ArrayRef(); if (getASTManager()->initCompilerInvocationNoInputs( Invocation, SwiftArgs, FrontendOptions::ActionType::Typecheck, CI.getDiags(), Error)) {