1919#include " swift/AST/Decl.h"
2020#include " swift/AST/DiagnosticEngine.h"
2121#include " swift/AST/DiagnosticsIRGen.h"
22+ #include " swift/AST/GenericEnvironment.h"
2223#include " swift/AST/GenericSignature.h"
2324#include " swift/AST/IRGenOptions.h"
2425#include " swift/AST/Module.h"
3940#include " clang/AST/GlobalDecl.h"
4041#include " llvm/ADT/SmallString.h"
4142#include " llvm/IR/GlobalAlias.h"
43+ #include " llvm/IR/InlineAsm.h"
4244#include " llvm/IR/Module.h"
4345#include " llvm/IR/TypeBuilder.h"
4446#include " llvm/IR/Value.h"
45- #include " llvm/IR/InlineAsm.h"
4647#include " llvm/Support/Compiler.h"
4748#include " llvm/Support/ConvertUTF.h"
4849#include " llvm/Support/Path.h"
@@ -3517,6 +3518,7 @@ llvm::Constant *IRGenModule::getOrCreateRetainFunction(const TypeInfo &objectTI,
35173518 return getOrCreateHelperFunction (
35183519 funcName, llvmType, argTys,
35193520 [&](IRGenFunction &IGF) {
3521+ IGF.setInOutlinedFunction ();
35203522 auto it = IGF.CurFn ->arg_begin ();
35213523 Address addr (&*it++, loadableTI->getFixedAlignment ());
35223524 Explosion loaded;
@@ -3540,6 +3542,7 @@ IRGenModule::getOrCreateReleaseFunction(const TypeInfo &objectTI, Type t,
35403542 return getOrCreateHelperFunction (
35413543 funcName, llvmType, argTys,
35423544 [&](IRGenFunction &IGF) {
3545+ IGF.setInOutlinedFunction ();
35433546 auto it = IGF.CurFn ->arg_begin ();
35443547 Address addr (&*it++, loadableTI->getFixedAlignment ());
35453548 Explosion loaded;
@@ -3549,3 +3552,87 @@ IRGenModule::getOrCreateReleaseFunction(const TypeInfo &objectTI, Type t,
35493552 },
35503553 true /* setIsNoInline*/ );
35513554}
3555+
3556+ void IRGenModule::generateCallToOutlinedCopyAddr (
3557+ IRGenFunction &IGF, const TypeInfo &objectTI, Address dest, Address src,
3558+ SILType T, const OutlinedCopyAddrFunction MethodToCall) {
3559+ llvm::Type *llvmType = dest->getType ();
3560+ auto *outlinedF = (this ->*MethodToCall)(objectTI, llvmType, T);
3561+ llvm::Value *args[] = {src.getAddress (), dest.getAddress ()};
3562+ llvm::CallInst *call = IGF.Builder .CreateCall (outlinedF, args);
3563+ call->setCallingConv (DefaultCC);
3564+ }
3565+
3566+ llvm::Constant *IRGenModule::getOrCreateOutlinedCopyAddrHelperFunction (
3567+ const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy,
3568+ std::string funcName,
3569+ llvm::function_ref<void (const TypeInfo &objectTI, IRGenFunction &IGF,
3570+ Address dest, Address src, SILType T)>
3571+ Generate) {
3572+ llvm::Type *argTys[] = {llvmType, llvmType};
3573+ return getOrCreateHelperFunction (
3574+ funcName, llvmType, argTys,
3575+ [&](IRGenFunction &IGF) {
3576+ IGF.setInOutlinedFunction ();
3577+ auto it = IGF.CurFn ->arg_begin ();
3578+ Address src (&*it++, objectTI.getBestKnownAlignment ());
3579+ Address dest (&*it++, objectTI.getBestKnownAlignment ());
3580+ Generate (objectTI, IGF, dest, src, addrTy);
3581+ IGF.Builder .CreateRet (dest.getAddress ());
3582+ },
3583+ true /* setIsNoInline*/ );
3584+ }
3585+
3586+ llvm::Constant *IRGenModule::getOrCreateOutlinedInitializeWithTakeFunction (
3587+ const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy) {
3588+ IRGenMangler mangler;
3589+ CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
3590+ std::string funcName =
3591+ mangler.mangleOutlinedInitializeWithTakeFunction (canType);
3592+ auto GenFunc = [this ](const TypeInfo &objectTI, IRGenFunction &IGF,
3593+ Address dest, Address src, SILType T) {
3594+ objectTI.initializeWithTake (IGF, dest, src, T);
3595+ };
3596+ return getOrCreateOutlinedCopyAddrHelperFunction (objectTI, llvmType, addrTy,
3597+ funcName, GenFunc);
3598+ }
3599+
3600+ llvm::Constant *IRGenModule::getOrCreateOutlinedInitializeWithCopyFunction (
3601+ const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy) {
3602+ IRGenMangler mangler;
3603+ CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
3604+ std::string funcName =
3605+ mangler.mangleOutlinedInitializeWithCopyFunction (canType);
3606+ auto GenFunc = [this ](const TypeInfo &objectTI, IRGenFunction &IGF,
3607+ Address dest, Address src, SILType T) {
3608+ objectTI.initializeWithCopy (IGF, dest, src, T);
3609+ };
3610+ return getOrCreateOutlinedCopyAddrHelperFunction (objectTI, llvmType, addrTy,
3611+ funcName, GenFunc);
3612+ }
3613+
3614+ llvm::Constant *IRGenModule::getOrCreateOutlinedAssignWithTakeFunction (
3615+ const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy) {
3616+ IRGenMangler mangler;
3617+ CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
3618+ std::string funcName = mangler.mangleOutlinedAssignWithTakeFunction (canType);
3619+ auto GenFunc = [this ](const TypeInfo &objectTI, IRGenFunction &IGF,
3620+ Address dest, Address src, SILType T) {
3621+ objectTI.assignWithTake (IGF, dest, src, T);
3622+ };
3623+ return getOrCreateOutlinedCopyAddrHelperFunction (objectTI, llvmType, addrTy,
3624+ funcName, GenFunc);
3625+ }
3626+
3627+ llvm::Constant *IRGenModule::getOrCreateOutlinedAssignWithCopyFunction (
3628+ const TypeInfo &objectTI, llvm::Type *llvmType, SILType addrTy) {
3629+ IRGenMangler mangler;
3630+ CanType canType = addrTy.getObjectType ().getSwiftRValueType ();
3631+ std::string funcName = mangler.mangleOutlinedAssignWithCopyFunction (canType);
3632+ auto GenFunc = [this ](const TypeInfo &objectTI, IRGenFunction &IGF,
3633+ Address dest, Address src, SILType T) {
3634+ objectTI.assignWithCopy (IGF, dest, src, T);
3635+ };
3636+ return getOrCreateOutlinedCopyAddrHelperFunction (objectTI, llvmType, addrTy,
3637+ funcName, GenFunc);
3638+ }
0 commit comments