From 17ba55db12d1e900897c0e7ddb50d7ff441947c8 Mon Sep 17 00:00:00 2001 From: John McCall Date: Sun, 7 Jan 2018 06:28:49 +0000 Subject: [PATCH] Simplify the internal API for checking whether swiftcall passes a type indirectly and expose that API externally. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321957 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/CodeGen/SwiftCallingConv.h | 6 ++++++ lib/CodeGen/ABIInfo.h | 3 +-- lib/CodeGen/SwiftCallingConv.cpp | 14 +++++++++----- lib/CodeGen/TargetInfo.cpp | 18 ++++++------------ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/clang/CodeGen/SwiftCallingConv.h b/include/clang/CodeGen/SwiftCallingConv.h index 23db43e673..8ea2b9d35d 100644 --- a/include/clang/CodeGen/SwiftCallingConv.h +++ b/include/clang/CodeGen/SwiftCallingConv.h @@ -116,6 +116,12 @@ private: void splitVectorEntry(unsigned index); }; +/// Should an aggregate which expands to the given type sequence +/// be passed/returned indirectly under swiftcall? +bool shouldPassIndirectly(CodeGenModule &CGM, + ArrayRef types, + bool asReturnValue); + /// Return the maximum voluntary integer size for the current target. CharUnits getMaximumVoluntaryIntegerSize(CodeGenModule &CGM); diff --git a/lib/CodeGen/ABIInfo.h b/lib/CodeGen/ABIInfo.h index 575506da84..4cfc3d059d 100644 --- a/lib/CodeGen/ABIInfo.h +++ b/lib/CodeGen/ABIInfo.h @@ -137,8 +137,7 @@ namespace swiftcall { bool supportsSwift() const final override { return true; } - virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize, - ArrayRef types, + virtual bool shouldPassIndirectlyForSwift(ArrayRef types, bool asReturnValue) const = 0; virtual bool isLegalVectorTypeForSwift(CharUnits totalSize, diff --git a/lib/CodeGen/SwiftCallingConv.cpp b/lib/CodeGen/SwiftCallingConv.cpp index fc8e36d2c5..2a12078e19 100644 --- a/lib/CodeGen/SwiftCallingConv.cpp +++ b/lib/CodeGen/SwiftCallingConv.cpp @@ -579,11 +579,9 @@ bool SwiftAggLowering::shouldPassIndirectly(bool asReturnValue) const { // Empty types don't need to be passed indirectly. if (Entries.empty()) return false; - CharUnits totalSize = Entries.back().End; - // Avoid copying the array of types when there's just a single element. if (Entries.size() == 1) { - return getSwiftABIInfo(CGM).shouldPassIndirectlyForSwift(totalSize, + return getSwiftABIInfo(CGM).shouldPassIndirectlyForSwift( Entries.back().Type, asReturnValue); } @@ -593,8 +591,14 @@ bool SwiftAggLowering::shouldPassIndirectly(bool asReturnValue) const { for (auto &entry : Entries) { componentTys.push_back(entry.Type); } - return getSwiftABIInfo(CGM).shouldPassIndirectlyForSwift(totalSize, - componentTys, + return getSwiftABIInfo(CGM).shouldPassIndirectlyForSwift(componentTys, + asReturnValue); +} + +bool swiftcall::shouldPassIndirectly(CodeGenModule &CGM, + ArrayRef componentTys, + bool asReturnValue) { + return getSwiftABIInfo(CGM).shouldPassIndirectlyForSwift(componentTys, asReturnValue); } diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 4b8006428f..e3f3ba1be4 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -1028,8 +1028,7 @@ public: IsMCUABI(CGT.getTarget().getTriple().isOSIAMCU()), DefaultNumRegisterParameters(NumRegisterParameters) {} - bool shouldPassIndirectlyForSwift(CharUnits totalSize, - ArrayRef scalars, + bool shouldPassIndirectlyForSwift(ArrayRef scalars, bool asReturnValue) const override { // LLVM's x86-32 lowering currently only assigns up to three // integer registers and three fp registers. Oddly, it'll use up to @@ -2168,8 +2167,7 @@ public: return Has64BitPointers; } - bool shouldPassIndirectlyForSwift(CharUnits totalSize, - ArrayRef scalars, + bool shouldPassIndirectlyForSwift(ArrayRef scalars, bool asReturnValue) const override { return occupiesMoreThan(CGT, scalars, /*total*/ 4); } @@ -2201,8 +2199,7 @@ public: return isX86VectorCallAggregateSmallEnough(NumMembers); } - bool shouldPassIndirectlyForSwift(CharUnits totalSize, - ArrayRef scalars, + bool shouldPassIndirectlyForSwift(ArrayRef scalars, bool asReturnValue) const override { return occupiesMoreThan(CGT, scalars, /*total*/ 4); } @@ -4922,8 +4919,7 @@ private: Address EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty) const override; - bool shouldPassIndirectlyForSwift(CharUnits totalSize, - ArrayRef scalars, + bool shouldPassIndirectlyForSwift(ArrayRef scalars, bool asReturnValue) const override { return occupiesMoreThan(CGT, scalars, /*total*/ 4); } @@ -5521,8 +5517,7 @@ private: llvm::CallingConv::ID getABIDefaultCC() const; void setCCs(); - bool shouldPassIndirectlyForSwift(CharUnits totalSize, - ArrayRef scalars, + bool shouldPassIndirectlyForSwift(ArrayRef scalars, bool asReturnValue) const override { return occupiesMoreThan(CGT, scalars, /*total*/ 4); } @@ -6313,8 +6308,7 @@ public: Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty) const override; - bool shouldPassIndirectlyForSwift(CharUnits totalSize, - ArrayRef scalars, + bool shouldPassIndirectlyForSwift(ArrayRef scalars, bool asReturnValue) const override { return occupiesMoreThan(CGT, scalars, /*total*/ 4); } -- 2.40.0