From 06e7df12ca91bef4b1680a0a4d20bac50f1719e8 Mon Sep 17 00:00:00 2001 From: John McCall Date: Sat, 7 Apr 2018 20:16:47 +0000 Subject: [PATCH] Generalize the swiftcall API since being passed indirectly isn't C++-specific anymore. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329513 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/CodeGen/SwiftCallingConv.h | 14 ++++++++++---- lib/CodeGen/SwiftCallingConv.cpp | 10 ++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/clang/CodeGen/SwiftCallingConv.h b/include/clang/CodeGen/SwiftCallingConv.h index 8ea2b9d35d..a5ea900185 100644 --- a/include/clang/CodeGen/SwiftCallingConv.h +++ b/include/clang/CodeGen/SwiftCallingConv.h @@ -152,9 +152,15 @@ void legalizeVectorType(CodeGenModule &CGM, CharUnits vectorSize, llvm::VectorType *vectorTy, llvm::SmallVectorImpl &types); -/// Should a C++ record type be passed and returned indirectly? -bool shouldPassCXXRecordIndirectly(CodeGenModule &CGM, - const CXXRecordDecl *record); +/// Is the given record type required to be passed and returned indirectly +/// because of language restrictions? +/// +/// This considers *only* mandatory indirectness due to language restrictions, +/// such as C++'s non-trivially-copyable types and Objective-C's __weak +/// references. A record for which this returns true may still be passed +/// indirectly for other reasons, such as being too large to fit in a +/// reasonable number of registers. +bool mustPassRecordIndirectly(CodeGenModule &CGM, const RecordDecl *record); /// Classify the rules for how to return a particular type. ABIArgInfo classifyReturnType(CodeGenModule &CGM, CanQualType type); @@ -166,7 +172,7 @@ ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type); /// private interface for Clang. void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI); -/// Is swifterror lowered to a register by the target ABI. +/// Is swifterror lowered to a register by the target ABI? bool isSwiftErrorLoweredInRegister(CodeGenModule &CGM); } // end namespace swiftcall diff --git a/lib/CodeGen/SwiftCallingConv.cpp b/lib/CodeGen/SwiftCallingConv.cpp index 7dc2a1d089..3673a5597e 100644 --- a/lib/CodeGen/SwiftCallingConv.cpp +++ b/lib/CodeGen/SwiftCallingConv.cpp @@ -740,8 +740,8 @@ void swiftcall::legalizeVectorType(CodeGenModule &CGM, CharUnits origVectorSize, components.append(numElts, eltTy); } -bool swiftcall::shouldPassCXXRecordIndirectly(CodeGenModule &CGM, - const CXXRecordDecl *record) { +bool swiftcall::mustPassRecordIndirectly(CodeGenModule &CGM, + const RecordDecl *record) { // FIXME: should we not rely on the standard computation in Sema, just in // case we want to diverge from the platform ABI (e.g. on targets where // that uses the MSVC rule)? @@ -767,10 +767,8 @@ static ABIArgInfo classifyType(CodeGenModule &CGM, CanQualType type, auto record = recordType->getDecl(); auto &layout = CGM.getContext().getASTRecordLayout(record); - if (auto cxxRecord = dyn_cast(record)) { - if (shouldPassCXXRecordIndirectly(CGM, cxxRecord)) - return ABIArgInfo::getIndirect(layout.getAlignment(), /*byval*/ false); - } + if (mustPassRecordIndirectly(CGM, record)) + return ABIArgInfo::getIndirect(layout.getAlignment(), /*byval*/ false); SwiftAggLowering lowering(CGM); lowering.addTypedData(recordType->getDecl(), CharUnits::Zero(), layout); -- 2.40.0