<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Apr 4, 2016, at 12:10 PM, Sean Silva <<a href="mailto:chisophugis@gmail.com" class="">chisophugis@gmail.com</a>> wrote:</div><div class=""><div dir="ltr" class="">I'm seeing a warning:<div class=""><br class=""></div><div class=""><div class="">/Users/Sean/pg/llvm/tools/clang/lib/CodeGen/SwiftCallingConv.cpp:236:12: warning: unused variable 'eltTy' [-Wunused-variable]</div><div class=""> auto eltTy = split.first;</div><div class=""> ^</div><div class="">1 warning generated.</div></div></div></div></blockquote><div><br class=""></div>Ha, this is actually a bug. Fixing and adding a test case for this combination of paths.</div><div><br class=""></div><div>John.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class="">-- Sean Silva</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Apr 4, 2016 at 11:33 AM, John McCall via cfe-commits <span dir="ltr" class=""><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank" class="">cfe-commits@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rjmccall<br class="">
Date: Mon Apr 4 13:33:08 2016<br class="">
New Revision: 265324<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=265324&view=rev" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=265324&view=rev</a><br class="">
Log:<br class="">
IRGen-level lowering for the Swift calling convention.<br class="">
<br class="">
Added:<br class="">
cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h<br class="">
cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp<br class="">
cfe/trunk/test/CodeGen/arm-swiftcall.c<br class="">
cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp<br class="">
Modified:<br class="">
cfe/trunk/lib/CodeGen/ABIInfo.h<br class="">
cfe/trunk/lib/CodeGen/CGCall.cpp<br class="">
cfe/trunk/lib/CodeGen/CMakeLists.txt<br class="">
cfe/trunk/lib/CodeGen/CodeGenFunction.h<br class="">
cfe/trunk/lib/CodeGen/CodeGenModule.h<br class="">
cfe/trunk/lib/CodeGen/CodeGenTypes.h<br class="">
cfe/trunk/lib/CodeGen/TargetInfo.cpp<br class="">
cfe/trunk/lib/CodeGen/TargetInfo.h<br class="">
<br class="">
Added: cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h?rev=265324&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h?rev=265324&view=auto</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h (added)<br class="">
+++ cfe/trunk/include/clang/CodeGen/SwiftCallingConv.h Mon Apr 4 13:33:08 2016<br class="">
@@ -0,0 +1,168 @@<br class="">
+//==-- SwiftCallingConv.h - Swift ABI lowering -----------------------------==//<br class="">
+//<br class="">
+// The LLVM Compiler Infrastructure<br class="">
+//<br class="">
+// This file is distributed under the University of Illinois Open Source<br class="">
+// License. See LICENSE.TXT for details.<br class="">
+//<br class="">
+//===----------------------------------------------------------------------===//<br class="">
+//<br class="">
+// Defines constants and types related to Swift ABI lowering.<br class="">
+//<br class="">
+//===----------------------------------------------------------------------===//<br class="">
+<br class="">
+#ifndef LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H<br class="">
+#define LLVM_CLANG_CODEGEN_SWIFTCALLINGCONV_H<br class="">
+<br class="">
+#include "clang/AST/CanonicalType.h"<br class="">
+#include "clang/AST/CharUnits.h"<br class="">
+#include "clang/AST/Type.h"<br class="">
+#include "llvm/ADT/FoldingSet.h"<br class="">
+#include "llvm/Support/TrailingObjects.h"<br class="">
+#include <cassert><br class="">
+<br class="">
+namespace llvm {<br class="">
+ class IntegerType;<br class="">
+ class Type;<br class="">
+ class StructType;<br class="">
+ class VectorType;<br class="">
+}<br class="">
+<br class="">
+namespace clang {<br class="">
+class Decl;<br class="">
+class FieldDecl;<br class="">
+class ASTRecordLayout;<br class="">
+<br class="">
+namespace CodeGen {<br class="">
+class ABIArgInfo;<br class="">
+class CodeGenModule;<br class="">
+class CGFunctionInfo;<br class="">
+<br class="">
+namespace swiftcall {<br class="">
+<br class="">
+class SwiftAggLowering {<br class="">
+ CodeGenModule &CGM;<br class="">
+<br class="">
+ struct StorageEntry {<br class="">
+ CharUnits Begin;<br class="">
+ CharUnits End;<br class="">
+ llvm::Type *Type;<br class="">
+<br class="">
+ CharUnits getWidth() const {<br class="">
+ return End - Begin;<br class="">
+ }<br class="">
+ };<br class="">
+ SmallVector<StorageEntry, 4> Entries;<br class="">
+ bool Finished = false;<br class="">
+<br class="">
+public:<br class="">
+ SwiftAggLowering(CodeGenModule &CGM) : CGM(CGM) {}<br class="">
+<br class="">
+ void addOpaqueData(CharUnits begin, CharUnits end) {<br class="">
+ addEntry(nullptr, begin, end);<br class="">
+ }<br class="">
+<br class="">
+ void addTypedData(QualType type, CharUnits begin);<br class="">
+ void addTypedData(const RecordDecl *record, CharUnits begin);<br class="">
+ void addTypedData(const RecordDecl *record, CharUnits begin,<br class="">
+ const ASTRecordLayout &layout);<br class="">
+ void addTypedData(llvm::Type *type, CharUnits begin);<br class="">
+ void addTypedData(llvm::Type *type, CharUnits begin, CharUnits end);<br class="">
+<br class="">
+ void finish();<br class="">
+<br class="">
+ /// Does this lowering require passing any data?<br class="">
+ bool empty() const {<br class="">
+ assert(Finished && "didn't finish lowering before calling empty()");<br class="">
+ return Entries.empty();<br class="">
+ }<br class="">
+<br class="">
+ /// According to the target Swift ABI, should a value with this lowering<br class="">
+ /// be passed indirectly?<br class="">
+ ///<br class="">
+ /// Note that this decision is based purely on the data layout of the<br class="">
+ /// value and does not consider whether the type is address-only,<br class="">
+ /// must be passed indirectly to match a function abstraction pattern, or<br class="">
+ /// anything else that is expected to be handled by high-level lowering.<br class="">
+ ///<br class="">
+ /// \param asReturnValue - if true, answer whether it should be passed<br class="">
+ /// indirectly as a return value; if false, answer whether it should be<br class="">
+ /// passed indirectly as an argument<br class="">
+ bool shouldPassIndirectly(bool asReturnValue) const;<br class="">
+<br class="">
+ using EnumerationCallback =<br class="">
+ llvm::function_ref<void(CharUnits offset, llvm::Type *type)>;<br class="">
+<br class="">
+ /// Enumerate the expanded components of this type.<br class="">
+ ///<br class="">
+ /// The component types will always be legal vector, floating-point,<br class="">
+ /// integer, or pointer types.<br class="">
+ void enumerateComponents(EnumerationCallback callback) const;<br class="">
+<br class="">
+ /// Return the types for a coerce-and-expand operation.<br class="">
+ ///<br class="">
+ /// The first type matches the memory layout of the data that's been<br class="">
+ /// added to this structure, including explicit [N x i8] arrays for any<br class="">
+ /// internal padding.<br class="">
+ ///<br class="">
+ /// The second type removes any internal padding members and, if only<br class="">
+ /// one element remains, is simply that element type.<br class="">
+ std::pair<llvm::StructType*, llvm::Type*> getCoerceAndExpandTypes() const;<br class="">
+<br class="">
+private:<br class="">
+ void addBitFieldData(const FieldDecl *field, CharUnits begin,<br class="">
+ uint64_t bitOffset);<br class="">
+ void addLegalTypedData(llvm::Type *type, CharUnits begin, CharUnits end);<br class="">
+ void addEntry(llvm::Type *type, CharUnits begin, CharUnits end);<br class="">
+ void splitVectorEntry(unsigned index);<br class="">
+};<br class="">
+<br class="">
+/// Return the maximum voluntary integer size for the current target.<br class="">
+CharUnits getMaximumVoluntaryIntegerSize(CodeGenModule &CGM);<br class="">
+<br class="">
+/// Return the Swift CC's notion of the natural alignment of a type.<br class="">
+CharUnits getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type);<br class="">
+<br class="">
+/// Is the given integer type "legal" for Swift's perspective on the<br class="">
+/// current platform?<br class="">
+bool isLegalIntegerType(CodeGenModule &CGM, llvm::IntegerType *type);<br class="">
+<br class="">
+/// Is the given vector type "legal" for Swift's perspective on the<br class="">
+/// current platform?<br class="">
+bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,<br class="">
+ llvm::VectorType *vectorTy);<br class="">
+bool isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,<br class="">
+ llvm::Type *eltTy, unsigned numElts);<br class="">
+<br class="">
+/// Minimally split a legal vector type.<br class="">
+std::pair<llvm::Type*, unsigned><br class="">
+splitLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,<br class="">
+ llvm::VectorType *vectorTy);<br class="">
+<br class="">
+/// Turn a vector type in a sequence of legal component vector types.<br class="">
+///<br class="">
+/// The caller may assume that the sum of the data sizes of the resulting<br class="">
+/// types will equal the data size of the vector type.<br class="">
+void legalizeVectorType(CodeGenModule &CGM, CharUnits vectorSize,<br class="">
+ llvm::VectorType *vectorTy,<br class="">
+ llvm::SmallVectorImpl<llvm::Type*> &types);<br class="">
+<br class="">
+/// Should a C++ record type be passed and returned indirectly?<br class="">
+bool shouldPassCXXRecordIndirectly(CodeGenModule &CGM,<br class="">
+ const CXXRecordDecl *record);<br class="">
+<br class="">
+/// Classify the rules for how to return a particular type.<br class="">
+ABIArgInfo classifyReturnType(CodeGenModule &CGM, CanQualType type);<br class="">
+<br class="">
+/// Classify the rules for how to pass a particular type.<br class="">
+ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type);<br class="">
+<br class="">
+/// Compute the ABI information of a swiftcall function. This is a<br class="">
+/// private interface for Clang.<br class="">
+void computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI);<br class="">
+<br class="">
+} // end namespace swiftcall<br class="">
+} // end namespace CodeGen<br class="">
+} // end namespace clang<br class="">
+<br class="">
+#endif<br class="">
<br class="">
Modified: cfe/trunk/lib/CodeGen/ABIInfo.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ABIInfo.h?rev=265324&r1=265323&r2=265324&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ABIInfo.h?rev=265324&r1=265323&r2=265324&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/ABIInfo.h (original)<br class="">
+++ cfe/trunk/lib/CodeGen/ABIInfo.h Mon Apr 4 13:33:08 2016<br class="">
@@ -18,20 +18,25 @@ namespace llvm {<br class="">
class Value;<br class="">
class LLVMContext;<br class="">
class DataLayout;<br class="">
+ class Type;<br class="">
}<br class="">
<br class="">
namespace clang {<br class="">
class ASTContext;<br class="">
class TargetInfo;<br class="">
<br class="">
- namespace CodeGen {<br class="">
- class ABIArgInfo;<br class="">
- class Address;<br class="">
- class CGCXXABI;<br class="">
- class CGFunctionInfo;<br class="">
- class CodeGenFunction;<br class="">
- class CodeGenTypes;<br class="">
- }<br class="">
+namespace CodeGen {<br class="">
+ class ABIArgInfo;<br class="">
+ class Address;<br class="">
+ class CGCXXABI;<br class="">
+ class CGFunctionInfo;<br class="">
+ class CodeGenFunction;<br class="">
+ class CodeGenTypes;<br class="">
+ class SwiftABIInfo;<br class="">
+<br class="">
+namespace swiftcall {<br class="">
+ class SwiftAggLowering;<br class="">
+}<br class="">
<br class="">
// FIXME: All of this stuff should be part of the target interface<br class="">
// somehow. It is currently here because it is not clear how to factor<br class="">
@@ -55,6 +60,8 @@ namespace clang {<br class="">
<br class="">
virtual ~ABIInfo();<br class="">
<br class="">
+ virtual bool supportsSwift() const { return false; }<br class="">
+<br class="">
CodeGen::CGCXXABI &getCXXABI() const;<br class="">
ASTContext &getContext() const;<br class="">
llvm::LLVMContext &getVMContext() const;<br class="">
@@ -112,7 +119,35 @@ namespace clang {<br class="">
<br class="">
CodeGen::ABIArgInfo<br class="">
getNaturalAlignIndirectInReg(QualType Ty, bool Realign = false) const;<br class="">
+<br class="">
+<br class="">
+ };<br class="">
+<br class="">
+ /// A refining implementation of ABIInfo for targets that support swiftcall.<br class="">
+ ///<br class="">
+ /// If we find ourselves wanting multiple such refinements, they'll probably<br class="">
+ /// be independent refinements, and we should probably find another way<br class="">
+ /// to do it than simple inheritance.<br class="">
+ class SwiftABIInfo : public ABIInfo {<br class="">
+ public:<br class="">
+ SwiftABIInfo(CodeGen::CodeGenTypes &cgt) : ABIInfo(cgt) {}<br class="">
+<br class="">
+ bool supportsSwift() const final override { return true; }<br class="">
+<br class="">
+ virtual bool shouldPassIndirectlyForSwift(CharUnits totalSize,<br class="">
+ ArrayRef<llvm::Type*> types,<br class="">
+ bool asReturnValue) const = 0;<br class="">
+<br class="">
+ virtual bool isLegalVectorTypeForSwift(CharUnits totalSize,<br class="">
+ llvm::Type *eltTy,<br class="">
+ unsigned elts) const;<br class="">
+<br class="">
+ static bool classof(const ABIInfo *info) {<br class="">
+ return info->supportsSwift();<br class="">
+ }<br class="">
};<br class="">
+<br class="">
+} // end namespace CodeGen<br class="">
} // end namespace clang<br class="">
<br class="">
#endif<br class="">
<br class="">
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=265324&r1=265323&r2=265324&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=265324&r1=265323&r2=265324&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)<br class="">
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Apr 4 13:33:08 2016<br class="">
@@ -26,6 +26,7 @@<br class="">
#include "clang/Basic/TargetBuiltins.h"<br class="">
#include "clang/Basic/TargetInfo.h"<br class="">
#include "clang/CodeGen/CGFunctionInfo.h"<br class="">
+#include "clang/CodeGen/SwiftCallingConv.h"<br class="">
#include "clang/Frontend/CodeGenOptions.h"<br class="">
#include "llvm/ADT/StringExtras.h"<br class="">
#include "llvm/IR/Attributes.h"<br class="">
@@ -59,6 +60,7 @@ static unsigned ClangCallConvToLLVMCallC<br class="">
case CC_SpirKernel: return llvm::CallingConv::SPIR_KERNEL;<br class="">
case CC_PreserveMost: return llvm::CallingConv::PreserveMost;<br class="">
case CC_PreserveAll: return llvm::CallingConv::PreserveAll;<br class="">
+ case CC_Swift: return llvm::CallingConv::Swift;<br class="">
}<br class="">
}<br class="">
<br class="">
@@ -109,7 +111,7 @@ static void appendParameterTypes(const C<br class="">
auto protoParamInfos = FPT->getExtParameterInfos();<br class="">
paramInfos.reserve(prefix.size() + protoParamInfos.size());<br class="">
paramInfos.resize(prefix.size());<br class="">
- paramInfos.append(paramInfos.begin(), paramInfos.end());<br class="">
+ paramInfos.append(protoParamInfos.begin(), protoParamInfos.end());<br class="">
}<br class="">
<br class="">
// Fast path: unknown target.<br class="">
@@ -590,7 +592,6 @@ CodeGenTypes::arrangeBuiltinFunctionDecl<br class="">
argTypes, FunctionType::ExtInfo(), {}, RequiredArgs::All);<br class="">
}<br class="">
<br class="">
-<br class="">
/// Arrange a call to a C++ method, passing the given arguments.<br class="">
const CGFunctionInfo &<br class="">
CodeGenTypes::arrangeCXXMethodCall(const CallArgList &args,<br class="">
@@ -679,7 +680,11 @@ CodeGenTypes::arrangeLLVMFunctionInfo(Ca<br class="">
assert(inserted && "Recursively being processed?");<br class="">
<br class="">
// Compute ABI information.<br class="">
- getABIInfo().computeInfo(*FI);<br class="">
+ if (info.getCC() != CC_Swift) {<br class="">
+ getABIInfo().computeInfo(*FI);<br class="">
+ } else {<br class="">
+ swiftcall::computeABIInfo(CGM, *FI);<br class="">
+ }<br class="">
<br class="">
// Loop over all of the computed argument and return value info. If any of<br class="">
// them are direct or extend without a specified coerce type, specify the<br class="">
@@ -918,7 +923,7 @@ static void forConstantArrayExpansion(Co<br class="">
}<br class="">
<br class="">
void CodeGenFunction::ExpandTypeFromArgs(<br class="">
- QualType Ty, LValue LV, SmallVectorImpl<llvm::Argument *>::iterator &AI) {<br class="">
+ QualType Ty, LValue LV, SmallVectorImpl<llvm::Value *>::iterator &AI) {<br class="">
assert(LV.isSimple() &&<br class="">
"Unexpected non-simple lvalue during struct expansion.");<br class="">
<br class="">
@@ -1813,10 +1818,13 @@ void CodeGenModule::ConstructAttributeLi<br class="">
getLLVMContext(), llvm::AttributeSet::ReturnIndex, RetAttrs));<br class="">
}<br class="">
<br class="">
+ bool hasUsedSRet = false;<br class="">
+<br class="">
// Attach attributes to sret.<br class="">
if (IRFunctionArgs.hasSRetArg()) {<br class="">
llvm::AttrBuilder SRETAttrs;<br class="">
SRETAttrs.addAttribute(llvm::Attribute::StructRet);<br class="">
+ hasUsedSRet = true;<br class="">
if (RetAI.getInReg())<br class="">
SRETAttrs.addAttribute(llvm::Attribute::InReg);<br class="">
PAL.push_back(llvm::AttributeSet::get(<br class="">
@@ -1920,6 +1928,41 @@ void CodeGenModule::ConstructAttributeLi<br class="">
Attrs.addAttribute(llvm::Attribute::NonNull);<br class="">
}<br class="">
<br class="">
+ switch (FI.getExtParameterInfo(ArgNo).getABI()) {<br class="">
+ case ParameterABI::Ordinary:<br class="">
+ break;<br class="">
+<br class="">
+ case ParameterABI::SwiftIndirectResult: {<br class="">
+ // Add 'sret' if we haven't already used it for something, but<br class="">
+ // only if the result is void.<br class="">
+ if (!hasUsedSRet && RetTy->isVoidType()) {<br class="">
+ Attrs.addAttribute(llvm::Attribute::StructRet);<br class="">
+ hasUsedSRet = true;<br class="">
+ }<br class="">
+<br class="">
+ // Add 'noalias' in either case.<br class="">
+ Attrs.addAttribute(llvm::Attribute::NoAlias);<br class="">
+<br class="">
+ // Add 'dereferenceable' and 'alignment'.<br class="">
+ auto PTy = ParamType->getPointeeType();<br class="">
+ if (!PTy->isIncompleteType() && PTy->isConstantSizeType()) {<br class="">
+ auto info = getContext().getTypeInfoInChars(PTy);<br class="">
+ Attrs.addDereferenceableAttr(info.first.getQuantity());<br class="">
+ Attrs.addAttribute(llvm::Attribute::getWithAlignment(getLLVMContext(),<br class="">
+ info.second.getQuantity()));<br class="">
+ }<br class="">
+ break;<br class="">
+ }<br class="">
+<br class="">
+ case ParameterABI::SwiftErrorResult:<br class="">
+ Attrs.addAttribute(llvm::Attribute::SwiftError);<br class="">
+ break;<br class="">
+<br class="">
+ case ParameterABI::SwiftContext:<br class="">
+ Attrs.addAttribute(llvm::Attribute::SwiftSelf);<br class="">
+ break;<br class="">
+ }<br class="">
+<br class="">
if (Attrs.hasAttributes()) {<br class="">
unsigned FirstIRArg, NumIRArgs;<br class="">
std::tie(FirstIRArg, NumIRArgs) = IRFunctionArgs.getIRArgs(ArgNo);<br class="">
@@ -1985,6 +2028,18 @@ static const NonNullAttr *getNonNullAttr<br class="">
return nullptr;<br class="">
}<br class="">
<br class="">
+namespace {<br class="">
+ struct CopyBackSwiftError final : EHScopeStack::Cleanup {<br class="">
+ Address Temp;<br class="">
+ Address Arg;<br class="">
+ CopyBackSwiftError(Address temp, Address arg) : Temp(temp), Arg(arg) {}<br class="">
+ void Emit(CodeGenFunction &CGF, Flags flags) override {<br class="">
+ llvm::Value *errorValue = CGF.Builder.CreateLoad(Temp);<br class="">
+ CGF.Builder.CreateStore(errorValue, Arg);<br class="">
+ }<br class="">
+ };<br class="">
+}<br class="">
+<br class="">
void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,<br class="">
llvm::Function *Fn,<br class="">
const FunctionArgList &Args) {<br class="">
@@ -2010,7 +2065,7 @@ void CodeGenFunction::EmitFunctionProlog<br class="">
<br class="">
ClangToLLVMArgMapping IRFunctionArgs(CGM.getContext(), FI);<br class="">
// Flattened function arguments.<br class="">
- SmallVector<llvm::Argument *, 16> FnArgs;<br class="">
+ SmallVector<llvm::Value *, 16> FnArgs;<br class="">
FnArgs.reserve(IRFunctionArgs.totalIRArgs());<br class="">
for (auto &Arg : Fn->args()) {<br class="">
FnArgs.push_back(&Arg);<br class="">
@@ -2031,7 +2086,7 @@ void CodeGenFunction::EmitFunctionProlog<br class="">
<br class="">
// Name the struct return parameter.<br class="">
if (IRFunctionArgs.hasSRetArg()) {<br class="">
- auto AI = FnArgs[IRFunctionArgs.getSRetArgNo()];<br class="">
+ auto AI = cast<llvm::Argument>(FnArgs[IRFunctionArgs.getSRetArgNo()]);<br class="">
AI->setName("agg.result");<br class="">
AI->addAttr(llvm::AttributeSet::get(getLLVMContext(), AI->getArgNo() + 1,<br class="">
llvm::Attribute::NoAlias));<br class="">
@@ -2119,8 +2174,8 @@ void CodeGenFunction::EmitFunctionProlog<br class="">
ArgI.getCoerceToType() == ConvertType(Ty) &&<br class="">
ArgI.getDirectOffset() == 0) {<br class="">
assert(NumIRArgs == 1);<br class="">
- auto AI = FnArgs[FirstIRArg];<br class="">
- llvm::Value *V = AI;<br class="">
+ llvm::Value *V = FnArgs[FirstIRArg];<br class="">
+ auto AI = cast<llvm::Argument>(V);<br class="">
<br class="">
if (const ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(Arg)) {<br class="">
if (getNonNullAttr(CurCodeDecl, PVD, PVD->getType(),<br class="">
@@ -2189,6 +2244,25 @@ void CodeGenFunction::EmitFunctionProlog<br class="">
AI->getArgNo() + 1,<br class="">
llvm::Attribute::NoAlias));<br class="">
<br class="">
+ // LLVM expects swifterror parameters to be used in very restricted<br class="">
+ // ways. Copy the value into a less-restricted temporary.<br class="">
+ if (FI.getExtParameterInfo(ArgNo).getABI()<br class="">
+ == ParameterABI::SwiftErrorResult) {<br class="">
+ QualType pointeeTy = Ty->getPointeeType();<br class="">
+ assert(pointeeTy->isPointerType());<br class="">
+ Address temp =<br class="">
+ CreateMemTemp(pointeeTy, getPointerAlign(), "swifterror.temp");<br class="">
+ Address arg = Address(V, getContext().getTypeAlignInChars(pointeeTy));<br class="">
+ llvm::Value *incomingErrorValue = Builder.CreateLoad(arg);<br class="">
+ Builder.CreateStore(incomingErrorValue, temp);<br class="">
+ V = temp.getPointer();<br class="">
+<br class="">
+ // Push a cleanup to copy the value back at the end of the function.<br class="">
+ // The convention does not guarantee that the value will be written<br class="">
+ // back if the function exits with an unwind exception.<br class="">
+ EHStack.pushCleanup<CopyBackSwiftError>(NormalCleanup, temp, arg);<br class="">
+ }<br class="">
+<br class="">
// Ensure the argument is the correct type.<br class="">
if (V->getType() != ArgI.getCoerceToType())<br class="">
V = Builder.CreateBitCast(V, ArgI.getCoerceToType());<br class="">
@@ -3481,6 +3555,9 @@ RValue CodeGenFunction::EmitCall(const C<br class="">
}<br class="">
}<br class="">
<br class="">
+ Address swiftErrorTemp = Address::invalid();<br class="">
+ Address swiftErrorArg = Address::invalid();<br class="">
+<br class="">
assert(CallInfo.arg_size() == CallArgs.size() &&<br class="">
"Mismatch between function signature & arguments.");<br class="">
unsigned ArgNo = 0;<br class="">
@@ -3587,6 +3664,25 @@ RValue CodeGenFunction::EmitCall(const C<br class="">
else<br class="">
V = Builder.CreateLoad(RV.getAggregateAddress());<br class="">
<br class="">
+ // Implement swifterror by copying into a new swifterror argument.<br class="">
+ // We'll write back in the normal path out of the call.<br class="">
+ if (CallInfo.getExtParameterInfo(ArgNo).getABI()<br class="">
+ == ParameterABI::SwiftErrorResult) {<br class="">
+ assert(!swiftErrorTemp.isValid() && "multiple swifterror args");<br class="">
+<br class="">
+ QualType pointeeTy = I->Ty->getPointeeType();<br class="">
+ swiftErrorArg =<br class="">
+ Address(V, getContext().getTypeAlignInChars(pointeeTy));<br class="">
+<br class="">
+ swiftErrorTemp =<br class="">
+ CreateMemTemp(pointeeTy, getPointerAlign(), "swifterror.temp");<br class="">
+ V = swiftErrorTemp.getPointer();<br class="">
+ cast<llvm::AllocaInst>(V)->setSwiftError(true);<br class="">
+<br class="">
+ llvm::Value *errorValue = Builder.CreateLoad(swiftErrorArg);<br class="">
+ Builder.CreateStore(errorValue, swiftErrorTemp);<br class="">
+ }<br class="">
+<br class="">
// We might have to widen integers, but we should never truncate.<br class="">
if (ArgInfo.getCoerceToType() != V->getType() &&<br class="">
V->getType()->isIntegerTy())<br class="">
@@ -3597,6 +3693,7 @@ RValue CodeGenFunction::EmitCall(const C<br class="">
if (FirstIRArg < IRFuncTy->getNumParams() &&<br class="">
V->getType() != IRFuncTy->getParamType(FirstIRArg))<br class="">
V = Builder.CreateBitCast(V, IRFuncTy->getParamType(FirstIRArg));<br class="">
+<br class="">
IRCallArgs[FirstIRArg] = V;<br class="">
break;<br class="">
}<br class="">
@@ -3656,13 +3753,31 @@ RValue CodeGenFunction::EmitCall(const C<br class="">
}<br class="">
<br class="">
case ABIArgInfo::CoerceAndExpand: {<br class="">
- assert(RV.isAggregate() &&<br class="">
- "CoerceAndExpand does not support non-aggregate types yet");<br class="">
-<br class="">
auto coercionType = ArgInfo.getCoerceAndExpandType();<br class="">
auto layout = CGM.getDataLayout().getStructLayout(coercionType);<br class="">
<br class="">
- Address addr = RV.getAggregateAddress();<br class="">
+ llvm::Value *tempSize = nullptr;<br class="">
+ Address addr = Address::invalid();<br class="">
+ if (RV.isAggregate()) {<br class="">
+ addr = RV.getAggregateAddress();<br class="">
+ } else {<br class="">
+ assert(RV.isScalar()); // complex should always just be direct<br class="">
+<br class="">
+ llvm::Type *scalarType = RV.getScalarVal()->getType();<br class="">
+ auto scalarSize = CGM.getDataLayout().getTypeAllocSize(scalarType);<br class="">
+ auto scalarAlign = CGM.getDataLayout().getPrefTypeAlignment(scalarType);<br class="">
+<br class="">
+ tempSize = llvm::ConstantInt::get(CGM.Int64Ty, scalarSize);<br class="">
+<br class="">
+ // Materialize to a temporary.<br class="">
+ addr = CreateTempAlloca(RV.getScalarVal()->getType(),<br class="">
+ CharUnits::fromQuantity(std::max(layout->getAlignment(),<br class="">
+ scalarAlign)));<br class="">
+ EmitLifetimeStart(scalarSize, addr.getPointer());<br class="">
+<br class="">
+ Builder.CreateStore(RV.getScalarVal(), addr);<br class="">
+ }<br class="">
+<br class="">
addr = Builder.CreateElementBitCast(addr, coercionType);<br class="">
<br class="">
unsigned IRArgPos = FirstIRArg;<br class="">
@@ -3675,6 +3790,10 @@ RValue CodeGenFunction::EmitCall(const C<br class="">
}<br class="">
assert(IRArgPos == FirstIRArg + NumIRArgs);<br class="">
<br class="">
+ if (tempSize) {<br class="">
+ EmitLifetimeEnd(tempSize, addr.getPointer());<br class="">
+ }<br class="">
+<br class="">
break;<br class="">
}<br class="">
<br class="">
@@ -3853,6 +3972,12 @@ RValue CodeGenFunction::EmitCall(const C<br class="">
if (!CI->getType()->isVoidTy())<br class="">
CI->setName("call");<br class="">
<br class="">
+ // Perform the swifterror writeback.<br class="">
+ if (swiftErrorTemp.isValid()) {<br class="">
+ llvm::Value *errorResult = Builder.CreateLoad(swiftErrorTemp);<br class="">
+ Builder.CreateStore(errorResult, swiftErrorArg);<br class="">
+ }<br class="">
+<br class="">
// Emit any writebacks immediately. Arguably this should happen<br class="">
// after any return-value munging.<br class="">
if (CallArgs.hasWritebacks())<br class="">
@@ -3870,15 +3995,6 @@ RValue CodeGenFunction::EmitCall(const C<br class="">
<br class="">
RValue Ret = [&] {<br class="">
switch (RetAI.getKind()) {<br class="">
- case ABIArgInfo::InAlloca:<br class="">
- case ABIArgInfo::Indirect: {<br class="">
- RValue ret = convertTempToRValue(SRetPtr, RetTy, SourceLocation());<br class="">
- if (UnusedReturnSize)<br class="">
- EmitLifetimeEnd(llvm::ConstantInt::get(Int64Ty, UnusedReturnSize),<br class="">
- SRetPtr.getPointer());<br class="">
- return ret;<br class="">
- }<br class="">
-<br class="">
case ABIArgInfo::CoerceAndExpand: {<br class="">
auto coercionType = RetAI.getCoerceAndExpandType();<br class="">
auto layout = CGM.getDataLayout().getStructLayout(coercionType);<br class="">
@@ -3886,15 +4002,31 @@ RValue CodeGenFunction::EmitCall(const C<br class="">
Address addr = SRetPtr;<br class="">
addr = Builder.CreateElementBitCast(addr, coercionType);<br class="">
<br class="">
+ assert(CI->getType() == RetAI.getUnpaddedCoerceAndExpandType());<br class="">
+ bool requiresExtract = isa<llvm::StructType>(CI->getType());<br class="">
+<br class="">
unsigned unpaddedIndex = 0;<br class="">
for (unsigned i = 0, e = coercionType->getNumElements(); i != e; ++i) {<br class="">
llvm::Type *eltType = coercionType->getElementType(i);<br class="">
if (ABIArgInfo::isPaddingForCoerceAndExpand(eltType)) continue;<br class="">
Address eltAddr = Builder.CreateStructGEP(addr, i, layout);<br class="">
- llvm::Value *elt = Builder.CreateExtractValue(CI, unpaddedIndex++);<br class="">
+ llvm::Value *elt = CI;<br class="">
+ if (requiresExtract)<br class="">
+ elt = Builder.CreateExtractValue(elt, unpaddedIndex++);<br class="">
+ else<br class="">
+ assert(unpaddedIndex == 0);<br class="">
Builder.CreateStore(elt, eltAddr);<br class="">
}<br class="">
- break;<br class="">
+ // FALLTHROUGH<br class="">
+ }<br class="">
+<br class="">
+ case ABIArgInfo::InAlloca:<br class="">
+ case ABIArgInfo::Indirect: {<br class="">
+ RValue ret = convertTempToRValue(SRetPtr, RetTy, SourceLocation());<br class="">
+ if (UnusedReturnSize)<br class="">
+ EmitLifetimeEnd(llvm::ConstantInt::get(Int64Ty, UnusedReturnSize),<br class="">
+ SRetPtr.getPointer());<br class="">
+ return ret;<br class="">
}<br class="">
<br class="">
case ABIArgInfo::Ignore:<br class="">
<br class="">
Modified: cfe/trunk/lib/CodeGen/CMakeLists.txt<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=265324&r1=265323&r2=265324&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=265324&r1=265323&r2=265324&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/CMakeLists.txt (original)<br class="">
+++ cfe/trunk/lib/CodeGen/CMakeLists.txt Mon Apr 4 13:33:08 2016<br class="">
@@ -76,6 +76,7 @@ add_clang_library(clangCodeGen<br class="">
ModuleBuilder.cpp<br class="">
ObjectFilePCHContainerOperations.cpp<br class="">
SanitizerMetadata.cpp<br class="">
+ SwiftCallingConv.cpp<br class="">
TargetInfo.cpp<br class="">
<br class="">
DEPENDS<br class="">
<br class="">
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=265324&r1=265323&r2=265324&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=265324&r1=265323&r2=265324&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)<br class="">
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Mon Apr 4 13:33:08 2016<br class="">
@@ -68,7 +68,6 @@ class ObjCMethodDecl;<br class="">
class ObjCImplementationDecl;<br class="">
class ObjCPropertyImplDecl;<br class="">
class TargetInfo;<br class="">
-class TargetCodeGenInfo;<br class="">
class VarDecl;<br class="">
class ObjCForCollectionStmt;<br class="">
class ObjCAtTryStmt;<br class="">
@@ -86,6 +85,7 @@ class BlockByrefHelpers;<br class="">
class BlockByrefInfo;<br class="">
class BlockFlags;<br class="">
class BlockFieldFlags;<br class="">
+class TargetCodeGenInfo;<br class="">
<br class="">
/// The kind of evaluation to perform on values of a particular<br class="">
/// type. Basically, is the code in CGExprScalar, CGExprComplex, or<br class="">
@@ -3110,7 +3110,7 @@ private:<br class="">
///<br class="">
/// \param AI - The first function argument of the expansion.<br class="">
void ExpandTypeFromArgs(QualType Ty, LValue Dst,<br class="">
- SmallVectorImpl<llvm::Argument *>::iterator &AI);<br class="">
+ SmallVectorImpl<llvm::Value *>::iterator &AI);<br class="">
<br class="">
/// ExpandTypeToArgs - Expand an RValue \arg RV, with the LLVM type for \arg<br class="">
/// Ty, into individual arguments on the provided vector \arg IRCallArgs,<br class="">
<br class="">
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=265324&r1=265323&r2=265324&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=265324&r1=265323&r2=265324&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)<br class="">
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Apr 4 13:33:08 2016<br class="">
@@ -49,7 +49,6 @@ class IndexedInstrProfReader;<br class="">
}<br class="">
<br class="">
namespace clang {<br class="">
-class TargetCodeGenInfo;<br class="">
class ASTContext;<br class="">
class AtomicType;<br class="">
class FunctionDecl;<br class="">
@@ -93,6 +92,7 @@ class CGCUDARuntime;<br class="">
class BlockFieldFlags;<br class="">
class FunctionArgList;<br class="">
class CoverageMappingModuleGen;<br class="">
+class TargetCodeGenInfo;<br class="">
<br class="">
struct OrderGlobalInits {<br class="">
unsigned int priority;<br class="">
<br class="">
Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.h?rev=265324&r1=265323&r2=265324&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.h?rev=265324&r1=265323&r2=265324&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/CodeGenTypes.h (original)<br class="">
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.h Mon Apr 4 13:33:08 2016<br class="">
@@ -31,7 +31,6 @@ class StructType;<br class="">
}<br class="">
<br class="">
namespace clang {<br class="">
-class ABIInfo;<br class="">
class ASTContext;<br class="">
template <typename> class CanQual;<br class="">
class CXXConstructorDecl;<br class="">
@@ -51,6 +50,7 @@ class Type;<br class="">
typedef CanQual<Type> CanQualType;<br class="">
<br class="">
namespace CodeGen {<br class="">
+class ABIInfo;<br class="">
class CGCXXABI;<br class="">
class CGRecordLayout;<br class="">
class CodeGenModule;<br class="">
<br class="">
Added: cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp?rev=265324&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp?rev=265324&view=auto</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp (added)<br class="">
+++ cfe/trunk/lib/CodeGen/SwiftCallingConv.cpp Mon Apr 4 13:33:08 2016<br class="">
@@ -0,0 +1,830 @@<br class="">
+//===--- SwiftCallingConv.cpp - Lowering for the Swift calling convention -===//<br class="">
+//<br class="">
+// The LLVM Compiler Infrastructure<br class="">
+//<br class="">
+// This file is distributed under the University of Illinois Open Source<br class="">
+// License. See LICENSE.TXT for details.<br class="">
+//<br class="">
+//===----------------------------------------------------------------------===//<br class="">
+//<br class="">
+// Implementation of the abstract lowering for the Swift calling convention.<br class="">
+//<br class="">
+//===----------------------------------------------------------------------===//<br class="">
+<br class="">
+#include "clang/CodeGen/SwiftCallingConv.h"<br class="">
+#include "clang/Basic/TargetInfo.h"<br class="">
+#include "CodeGenModule.h"<br class="">
+#include "TargetInfo.h"<br class="">
+<br class="">
+using namespace clang;<br class="">
+using namespace CodeGen;<br class="">
+using namespace swiftcall;<br class="">
+<br class="">
+static const SwiftABIInfo &getSwiftABIInfo(CodeGenModule &CGM) {<br class="">
+ return cast<SwiftABIInfo>(CGM.getTargetCodeGenInfo().getABIInfo());<br class="">
+}<br class="">
+<br class="">
+static bool isPowerOf2(unsigned n) {<br class="">
+ return n == (n & -n);<br class="">
+}<br class="">
+<br class="">
+/// Given two types with the same size, try to find a common type.<br class="">
+static llvm::Type *getCommonType(llvm::Type *first, llvm::Type *second) {<br class="">
+ assert(first != second);<br class="">
+<br class="">
+ // Allow pointers to merge with integers, but prefer the integer type.<br class="">
+ if (first->isIntegerTy()) {<br class="">
+ if (second->isPointerTy()) return first;<br class="">
+ } else if (first->isPointerTy()) {<br class="">
+ if (second->isIntegerTy()) return second;<br class="">
+ if (second->isPointerTy()) return first;<br class="">
+<br class="">
+ // Allow two vectors to be merged (given that they have the same size).<br class="">
+ // This assumes that we never have two different vector register sets.<br class="">
+ } else if (auto firstVecTy = dyn_cast<llvm::VectorType>(first)) {<br class="">
+ if (auto secondVecTy = dyn_cast<llvm::VectorType>(second)) {<br class="">
+ if (auto commonTy = getCommonType(firstVecTy->getElementType(),<br class="">
+ secondVecTy->getElementType())) {<br class="">
+ return (commonTy == firstVecTy->getElementType() ? first : second);<br class="">
+ }<br class="">
+ }<br class="">
+ }<br class="">
+<br class="">
+ return nullptr;<br class="">
+}<br class="">
+<br class="">
+static CharUnits getTypeStoreSize(CodeGenModule &CGM, llvm::Type *type) {<br class="">
+ return CharUnits::fromQuantity(CGM.getDataLayout().getTypeStoreSize(type));<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::addTypedData(QualType type, CharUnits begin) {<br class="">
+ // Deal with various aggregate types as special cases:<br class="">
+<br class="">
+ // Record types.<br class="">
+ if (auto recType = type->getAs<RecordType>()) {<br class="">
+ addTypedData(recType->getDecl(), begin);<br class="">
+<br class="">
+ // Array types.<br class="">
+ } else if (type->isArrayType()) {<br class="">
+ // Incomplete array types (flexible array members?) don't provide<br class="">
+ // data to lay out, and the other cases shouldn't be possible.<br class="">
+ auto arrayType = CGM.getContext().getAsConstantArrayType(type);<br class="">
+ if (!arrayType) return;<br class="">
+<br class="">
+ QualType eltType = arrayType->getElementType();<br class="">
+ auto eltSize = CGM.getContext().getTypeSizeInChars(eltType);<br class="">
+ for (uint64_t i = 0, e = arrayType->getSize().getZExtValue(); i != e; ++i) {<br class="">
+ addTypedData(eltType, begin + i * eltSize);<br class="">
+ }<br class="">
+<br class="">
+ // Complex types.<br class="">
+ } else if (auto complexType = type->getAs<ComplexType>()) {<br class="">
+ auto eltType = complexType->getElementType();<br class="">
+ auto eltSize = CGM.getContext().getTypeSizeInChars(eltType);<br class="">
+ auto eltLLVMType = CGM.getTypes().ConvertType(eltType);<br class="">
+ addTypedData(eltLLVMType, begin, begin + eltSize);<br class="">
+ addTypedData(eltLLVMType, begin + eltSize, begin + 2 * eltSize);<br class="">
+<br class="">
+ // Member pointer types.<br class="">
+ } else if (type->getAs<MemberPointerType>()) {<br class="">
+ // Just add it all as opaque.<br class="">
+ addOpaqueData(begin, begin + CGM.getContext().getTypeSizeInChars(type));<br class="">
+<br class="">
+ // Everything else is scalar and should not convert as an LLVM aggregate.<br class="">
+ } else {<br class="">
+ // We intentionally convert as !ForMem because we want to preserve<br class="">
+ // that a type was an i1.<br class="">
+ auto llvmType = CGM.getTypes().ConvertType(type);<br class="">
+ addTypedData(llvmType, begin);<br class="">
+ }<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::addTypedData(const RecordDecl *record, CharUnits begin) {<br class="">
+ addTypedData(record, begin, CGM.getContext().getASTRecordLayout(record));<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::addTypedData(const RecordDecl *record, CharUnits begin,<br class="">
+ const ASTRecordLayout &layout) {<br class="">
+ // Unions are a special case.<br class="">
+ if (record->isUnion()) {<br class="">
+ for (auto field : record->fields()) {<br class="">
+ if (field->isBitField()) {<br class="">
+ addBitFieldData(field, begin, 0);<br class="">
+ } else {<br class="">
+ addTypedData(field->getType(), begin);<br class="">
+ }<br class="">
+ }<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // Note that correctness does not rely on us adding things in<br class="">
+ // their actual order of layout; it's just somewhat more efficient<br class="">
+ // for the builder.<br class="">
+<br class="">
+ // With that in mind, add "early" C++ data.<br class="">
+ auto cxxRecord = dyn_cast<CXXRecordDecl>(record);<br class="">
+ if (cxxRecord) {<br class="">
+ // - a v-table pointer, if the class adds its own<br class="">
+ if (layout.hasOwnVFPtr()) {<br class="">
+ addTypedData(CGM.Int8PtrTy, begin);<br class="">
+ }<br class="">
+<br class="">
+ // - non-virtual bases<br class="">
+ for (auto &baseSpecifier : cxxRecord->bases()) {<br class="">
+ if (baseSpecifier.isVirtual()) continue;<br class="">
+<br class="">
+ auto baseRecord = baseSpecifier.getType()->getAsCXXRecordDecl();<br class="">
+ addTypedData(baseRecord, begin + layout.getBaseClassOffset(baseRecord));<br class="">
+ }<br class="">
+<br class="">
+ // - a vbptr if the class adds its own<br class="">
+ if (layout.hasOwnVBPtr()) {<br class="">
+ addTypedData(CGM.Int8PtrTy, begin + layout.getVBPtrOffset());<br class="">
+ }<br class="">
+ }<br class="">
+<br class="">
+ // Add fields.<br class="">
+ for (auto field : record->fields()) {<br class="">
+ auto fieldOffsetInBits = layout.getFieldOffset(field->getFieldIndex());<br class="">
+ if (field->isBitField()) {<br class="">
+ addBitFieldData(field, begin, fieldOffsetInBits);<br class="">
+ } else {<br class="">
+ addTypedData(field->getType(),<br class="">
+ begin + CGM.getContext().toCharUnitsFromBits(fieldOffsetInBits));<br class="">
+ }<br class="">
+ }<br class="">
+<br class="">
+ // Add "late" C++ data:<br class="">
+ if (cxxRecord) {<br class="">
+ // - virtual bases<br class="">
+ for (auto &vbaseSpecifier : cxxRecord->vbases()) {<br class="">
+ auto baseRecord = vbaseSpecifier.getType()->getAsCXXRecordDecl();<br class="">
+ addTypedData(baseRecord, begin + layout.getVBaseClassOffset(baseRecord));<br class="">
+ }<br class="">
+ }<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::addBitFieldData(const FieldDecl *bitfield,<br class="">
+ CharUnits recordBegin,<br class="">
+ uint64_t bitfieldBitBegin) {<br class="">
+ assert(bitfield->isBitField());<br class="">
+ auto &ctx = CGM.getContext();<br class="">
+ auto width = bitfield->getBitWidthValue(ctx);<br class="">
+<br class="">
+ // We can ignore zero-width bit-fields.<br class="">
+ if (width == 0) return;<br class="">
+<br class="">
+ // toCharUnitsFromBits rounds down.<br class="">
+ CharUnits bitfieldByteBegin = ctx.toCharUnitsFromBits(bitfieldBitBegin);<br class="">
+<br class="">
+ // Find the offset of the last byte that is partially occupied by the<br class="">
+ // bit-field; since we otherwise expect exclusive ends, the end is the<br class="">
+ // next byte.<br class="">
+ uint64_t bitfieldBitLast = bitfieldBitBegin + width - 1;<br class="">
+ CharUnits bitfieldByteEnd =<br class="">
+ ctx.toCharUnitsFromBits(bitfieldBitLast) + CharUnits::One();<br class="">
+ addOpaqueData(recordBegin + bitfieldByteBegin,<br class="">
+ recordBegin + bitfieldByteEnd);<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::addTypedData(llvm::Type *type, CharUnits begin) {<br class="">
+ assert(type && "didn't provide type for typed data");<br class="">
+ addTypedData(type, begin, begin + getTypeStoreSize(CGM, type));<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::addTypedData(llvm::Type *type,<br class="">
+ CharUnits begin, CharUnits end) {<br class="">
+ assert(type && "didn't provide type for typed data");<br class="">
+ assert(getTypeStoreSize(CGM, type) == end - begin);<br class="">
+<br class="">
+ // Legalize vector types.<br class="">
+ if (auto vecTy = dyn_cast<llvm::VectorType>(type)) {<br class="">
+ SmallVector<llvm::Type*, 4> componentTys;<br class="">
+ legalizeVectorType(CGM, end - begin, vecTy, componentTys);<br class="">
+ assert(componentTys.size() >= 1);<br class="">
+<br class="">
+ // Walk the initial components.<br class="">
+ for (size_t i = 0, e = componentTys.size(); i != e - 1; ++i) {<br class="">
+ llvm::Type *componentTy = componentTys[i];<br class="">
+ auto componentSize = getTypeStoreSize(CGM, componentTy);<br class="">
+ assert(componentSize < end - begin);<br class="">
+ addLegalTypedData(componentTy, begin, begin + componentSize);<br class="">
+ begin += componentSize;<br class="">
+ }<br class="">
+<br class="">
+ return addLegalTypedData(componentTys.back(), begin, end);<br class="">
+ }<br class="">
+<br class="">
+ // Legalize integer types.<br class="">
+ if (auto intTy = dyn_cast<llvm::IntegerType>(type)) {<br class="">
+ if (!isLegalIntegerType(CGM, intTy))<br class="">
+ return addOpaqueData(begin, end);<br class="">
+ }<br class="">
+<br class="">
+ // All other types should be legal.<br class="">
+ return addLegalTypedData(type, begin, end);<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::addLegalTypedData(llvm::Type *type,<br class="">
+ CharUnits begin, CharUnits end) {<br class="">
+ // Require the type to be naturally aligned.<br class="">
+ if (!begin.isZero() && !begin.isMultipleOf(getNaturalAlignment(CGM, type))) {<br class="">
+<br class="">
+ // Try splitting vector types.<br class="">
+ if (auto vecTy = dyn_cast<llvm::VectorType>(type)) {<br class="">
+ auto split = splitLegalVectorType(CGM, end - begin, vecTy);<br class="">
+ auto eltTy = split.first;<br class="">
+ auto numElts = split.second;<br class="">
+<br class="">
+ auto eltSize = (end - begin) / numElts;<br class="">
+ assert(eltSize == getTypeStoreSize(CGM, eltTy));<br class="">
+ for (size_t i = 0, e = numElts; i != e; ++i) {<br class="">
+ addLegalTypedData(type, begin, begin + eltSize);<br class="">
+ begin += eltSize;<br class="">
+ }<br class="">
+ assert(begin == end);<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ return addOpaqueData(begin, end);<br class="">
+ }<br class="">
+<br class="">
+ addEntry(type, begin, end);<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::addEntry(llvm::Type *type,<br class="">
+ CharUnits begin, CharUnits end) {<br class="">
+ assert(!type ||<br class="">
+ (!isa<llvm::StructType>(type) && !isa<llvm::ArrayType>(type)) &&<br class="">
+ "cannot add aggregate-typed data");<br class="">
+ assert(!type || begin.isMultipleOf(getNaturalAlignment(CGM, type)));<br class="">
+<br class="">
+ // Fast path: we can just add entries to the end.<br class="">
+ if (Entries.empty() || Entries.back().End <= begin) {<br class="">
+ Entries.push_back({begin, end, type});<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // Find the first existing entry that ends after the start of the new data.<br class="">
+ // TODO: do a binary search if Entries is big enough for it to matter.<br class="">
+ size_t index = Entries.size() - 1;<br class="">
+ while (index != 0) {<br class="">
+ if (Entries[index - 1].End <= begin) break;<br class="">
+ --index;<br class="">
+ }<br class="">
+<br class="">
+ // The entry ends after the start of the new data.<br class="">
+ // If the entry starts after the end of the new data, there's no conflict.<br class="">
+ if (Entries[index].Begin >= end) {<br class="">
+ // This insertion is potentially O(n), but the way we generally build<br class="">
+ // these layouts makes that unlikely to matter: we'd need a union of<br class="">
+ // several very large types.<br class="">
+ Entries.insert(Entries.begin() + index, {begin, end, type});<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // Otherwise, the ranges overlap. The new range might also overlap<br class="">
+ // with later ranges.<br class="">
+restartAfterSplit:<br class="">
+<br class="">
+ // Simplest case: an exact overlap.<br class="">
+ if (Entries[index].Begin == begin && Entries[index].End == end) {<br class="">
+ // If the types match exactly, great.<br class="">
+ if (Entries[index].Type == type) return;<br class="">
+<br class="">
+ // If either type is opaque, make the entry opaque and return.<br class="">
+ if (Entries[index].Type == nullptr) {<br class="">
+ return;<br class="">
+ } else if (type == nullptr) {<br class="">
+ Entries[index].Type = nullptr;<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // If they disagree in an ABI-agnostic way, just resolve the conflict<br class="">
+ // arbitrarily.<br class="">
+ if (auto entryType = getCommonType(Entries[index].Type, type)) {<br class="">
+ Entries[index].Type = entryType;<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // Otherwise, make the entry opaque.<br class="">
+ Entries[index].Type = nullptr;<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // Okay, we have an overlapping conflict of some sort.<br class="">
+<br class="">
+ // If we have a vector type, split it.<br class="">
+ if (auto vecTy = dyn_cast_or_null<llvm::VectorType>(type)) {<br class="">
+ auto eltTy = vecTy->getElementType();<br class="">
+ CharUnits eltSize = (end - begin) / vecTy->getNumElements();<br class="">
+ assert(eltSize == getTypeStoreSize(CGM, eltTy));<br class="">
+ for (unsigned i = 0, e = vecTy->getNumElements(); i != e; ++i) {<br class="">
+ addEntry(eltTy, begin, begin + eltSize);<br class="">
+ begin += eltSize;<br class="">
+ }<br class="">
+ assert(begin == end);<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // If the entry is a vector type, split it and try again.<br class="">
+ if (Entries[index].Type && Entries[index].Type->isVectorTy()) {<br class="">
+ splitVectorEntry(index);<br class="">
+ goto restartAfterSplit;<br class="">
+ }<br class="">
+<br class="">
+ // Okay, we have no choice but to make the existing entry opaque.<br class="">
+<br class="">
+ Entries[index].Type = nullptr;<br class="">
+<br class="">
+ // Stretch the start of the entry to the beginning of the range.<br class="">
+ if (begin < Entries[index].Begin) {<br class="">
+ Entries[index].Begin = begin;<br class="">
+ assert(index == 0 || begin >= Entries[index - 1].End);<br class="">
+ }<br class="">
+<br class="">
+ // Stretch the end of the entry to the end of the range; but if we run<br class="">
+ // into the start of the next entry, just leave the range there and repeat.<br class="">
+ while (end > Entries[index].End) {<br class="">
+ assert(Entries[index].Type == nullptr);<br class="">
+<br class="">
+ // If the range doesn't overlap the next entry, we're done.<br class="">
+ if (index == Entries.size() - 1 || end <= Entries[index + 1].Begin) {<br class="">
+ Entries[index].End = end;<br class="">
+ break;<br class="">
+ }<br class="">
+<br class="">
+ // Otherwise, stretch to the start of the next entry.<br class="">
+ Entries[index].End = Entries[index + 1].Begin;<br class="">
+<br class="">
+ // Continue with the next entry.<br class="">
+ index++;<br class="">
+<br class="">
+ // This entry needs to be made opaque if it is not already.<br class="">
+ if (Entries[index].Type == nullptr)<br class="">
+ continue;<br class="">
+<br class="">
+ // Split vector entries unless we completely subsume them.<br class="">
+ if (Entries[index].Type->isVectorTy() &&<br class="">
+ end < Entries[index].End) {<br class="">
+ splitVectorEntry(index);<br class="">
+ }<br class="">
+<br class="">
+ // Make the entry opaque.<br class="">
+ Entries[index].Type = nullptr;<br class="">
+ }<br class="">
+}<br class="">
+<br class="">
+/// Replace the entry of vector type at offset 'index' with a sequence<br class="">
+/// of its component vectors.<br class="">
+void SwiftAggLowering::splitVectorEntry(unsigned index) {<br class="">
+ auto vecTy = cast<llvm::VectorType>(Entries[index].Type);<br class="">
+ auto split = splitLegalVectorType(CGM, Entries[index].getWidth(), vecTy);<br class="">
+<br class="">
+ auto eltTy = split.first;<br class="">
+ CharUnits eltSize = getTypeStoreSize(CGM, eltTy);<br class="">
+ auto numElts = split.second;<br class="">
+ Entries.insert(&Entries[index + 1], numElts - 1, StorageEntry());<br class="">
+<br class="">
+ CharUnits begin = Entries[index].Begin;<br class="">
+ for (unsigned i = 0; i != numElts; ++i) {<br class="">
+ Entries[index].Type = eltTy;<br class="">
+ Entries[index].Begin = begin;<br class="">
+ Entries[index].End = begin + eltSize;<br class="">
+ begin += eltSize;<br class="">
+ }<br class="">
+}<br class="">
+<br class="">
+/// Given a power-of-two unit size, return the offset of the aligned unit<br class="">
+/// of that size which contains the given offset.<br class="">
+///<br class="">
+/// In other words, round down to the nearest multiple of the unit size.<br class="">
+static CharUnits getOffsetAtStartOfUnit(CharUnits offset, CharUnits unitSize) {<br class="">
+ assert(isPowerOf2(unitSize.getQuantity()));<br class="">
+ auto unitMask = ~(unitSize.getQuantity() - 1);<br class="">
+ return CharUnits::fromQuantity(offset.getQuantity() & unitMask);<br class="">
+}<br class="">
+<br class="">
+static bool areBytesInSameUnit(CharUnits first, CharUnits second,<br class="">
+ CharUnits chunkSize) {<br class="">
+ return getOffsetAtStartOfUnit(first, chunkSize)<br class="">
+ == getOffsetAtStartOfUnit(second, chunkSize);<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::finish() {<br class="">
+ if (Entries.empty()) {<br class="">
+ Finished = true;<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // We logically split the layout down into a series of chunks of this size,<br class="">
+ // which is generally the size of a pointer.<br class="">
+ const CharUnits chunkSize = getMaximumVoluntaryIntegerSize(CGM);<br class="">
+<br class="">
+ // First pass: if two entries share a chunk, make them both opaque<br class="">
+ // and stretch one to meet the next.<br class="">
+ bool hasOpaqueEntries = (Entries[0].Type == nullptr);<br class="">
+ for (size_t i = 1, e = Entries.size(); i != e; ++i) {<br class="">
+ if (areBytesInSameUnit(Entries[i - 1].End - CharUnits::One(),<br class="">
+ Entries[i].Begin, chunkSize)) {<br class="">
+ Entries[i - 1].Type = nullptr;<br class="">
+ Entries[i].Type = nullptr;<br class="">
+ Entries[i - 1].End = Entries[i].Begin;<br class="">
+ hasOpaqueEntries = true;<br class="">
+<br class="">
+ } else if (Entries[i].Type == nullptr) {<br class="">
+ hasOpaqueEntries = true;<br class="">
+ }<br class="">
+ }<br class="">
+<br class="">
+ // The rest of the algorithm leaves non-opaque entries alone, so if we<br class="">
+ // have no opaque entries, we're done.<br class="">
+ if (!hasOpaqueEntries) {<br class="">
+ Finished = true;<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // Okay, move the entries to a temporary and rebuild Entries.<br class="">
+ auto orig = std::move(Entries);<br class="">
+ assert(Entries.empty());<br class="">
+<br class="">
+ for (size_t i = 0, e = orig.size(); i != e; ++i) {<br class="">
+ // Just copy over non-opaque entries.<br class="">
+ if (orig[i].Type != nullptr) {<br class="">
+ Entries.push_back(orig[i]);<br class="">
+ continue;<br class="">
+ }<br class="">
+<br class="">
+ // Scan forward to determine the full extent of the next opaque range.<br class="">
+ // We know from the first pass that only contiguous ranges will overlap<br class="">
+ // the same aligned chunk.<br class="">
+ auto begin = orig[i].Begin;<br class="">
+ auto end = orig[i].End;<br class="">
+ while (i + 1 != e &&<br class="">
+ orig[i + 1].Type == nullptr &&<br class="">
+ end == orig[i + 1].Begin) {<br class="">
+ end = orig[i + 1].End;<br class="">
+ i++;<br class="">
+ }<br class="">
+<br class="">
+ // Add an entry per intersected chunk.<br class="">
+ do {<br class="">
+ // Find the smallest aligned storage unit in the maximal aligned<br class="">
+ // storage unit containing 'begin' that contains all the bytes in<br class="">
+ // the intersection between the range and this chunk.<br class="">
+ CharUnits localBegin = begin;<br class="">
+ CharUnits chunkBegin = getOffsetAtStartOfUnit(localBegin, chunkSize);<br class="">
+ CharUnits chunkEnd = chunkBegin + chunkSize;<br class="">
+ CharUnits localEnd = std::min(end, chunkEnd);<br class="">
+<br class="">
+ // Just do a simple loop over ever-increasing unit sizes.<br class="">
+ CharUnits unitSize = CharUnits::One();<br class="">
+ CharUnits unitBegin, unitEnd;<br class="">
+ for (; ; unitSize *= 2) {<br class="">
+ assert(unitSize <= chunkSize);<br class="">
+ unitBegin = getOffsetAtStartOfUnit(localBegin, unitSize);<br class="">
+ unitEnd = unitBegin + unitSize;<br class="">
+ if (unitEnd >= localEnd) break;<br class="">
+ }<br class="">
+<br class="">
+ // Add an entry for this unit.<br class="">
+ auto entryTy =<br class="">
+ llvm::IntegerType::get(CGM.getLLVMContext(),<br class="">
+ CGM.getContext().toBits(unitSize));<br class="">
+ Entries.push_back({unitBegin, unitEnd, entryTy});<br class="">
+<br class="">
+ // The next chunk starts where this chunk left off.<br class="">
+ begin = localEnd;<br class="">
+ } while (begin != end);<br class="">
+ }<br class="">
+<br class="">
+ // Okay, finally finished.<br class="">
+ Finished = true;<br class="">
+}<br class="">
+<br class="">
+void SwiftAggLowering::enumerateComponents(EnumerationCallback callback) const {<br class="">
+ assert(Finished && "haven't yet finished lowering");<br class="">
+<br class="">
+ for (auto &entry : Entries) {<br class="">
+ callback(entry.Begin, entry.Type);<br class="">
+ }<br class="">
+}<br class="">
+<br class="">
+std::pair<llvm::StructType*, llvm::Type*><br class="">
+SwiftAggLowering::getCoerceAndExpandTypes() const {<br class="">
+ assert(Finished && "haven't yet finished lowering");<br class="">
+<br class="">
+ auto &ctx = CGM.getLLVMContext();<br class="">
+<br class="">
+ if (Entries.empty()) {<br class="">
+ auto type = llvm::StructType::get(ctx);<br class="">
+ return { type, type };<br class="">
+ }<br class="">
+<br class="">
+ SmallVector<llvm::Type*, 8> elts;<br class="">
+ CharUnits lastEnd = CharUnits::Zero();<br class="">
+ bool hasPadding = false;<br class="">
+ bool packed = false;<br class="">
+ for (auto &entry : Entries) {<br class="">
+ if (entry.Begin != lastEnd) {<br class="">
+ auto paddingSize = entry.Begin - lastEnd;<br class="">
+ assert(!paddingSize.isNegative());<br class="">
+<br class="">
+ auto padding = llvm::ArrayType::get(llvm::Type::getInt8Ty(ctx),<br class="">
+ paddingSize.getQuantity());<br class="">
+ elts.push_back(padding);<br class="">
+ hasPadding = true;<br class="">
+ }<br class="">
+<br class="">
+ if (!packed && !entry.Begin.isMultipleOf(<br class="">
+ CharUnits::fromQuantity(<br class="">
+ CGM.getDataLayout().getABITypeAlignment(entry.Type))))<br class="">
+ packed = true;<br class="">
+<br class="">
+ elts.push_back(entry.Type);<br class="">
+ lastEnd = entry.End;<br class="">
+ }<br class="">
+<br class="">
+ // We don't need to adjust 'packed' to deal with possible tail padding<br class="">
+ // because we never do that kind of access through the coercion type.<br class="">
+ auto coercionType = llvm::StructType::get(ctx, elts, packed);<br class="">
+<br class="">
+ llvm::Type *unpaddedType = coercionType;<br class="">
+ if (hasPadding) {<br class="">
+ elts.clear();<br class="">
+ for (auto &entry : Entries) {<br class="">
+ elts.push_back(entry.Type);<br class="">
+ }<br class="">
+ if (elts.size() == 1) {<br class="">
+ unpaddedType = elts[0];<br class="">
+ } else {<br class="">
+ unpaddedType = llvm::StructType::get(ctx, elts, /*packed*/ false);<br class="">
+ }<br class="">
+ } else if (Entries.size() == 1) {<br class="">
+ unpaddedType = Entries[0].Type;<br class="">
+ }<br class="">
+<br class="">
+ return { coercionType, unpaddedType };<br class="">
+}<br class="">
+<br class="">
+bool SwiftAggLowering::shouldPassIndirectly(bool asReturnValue) const {<br class="">
+ assert(Finished && "haven't yet finished lowering");<br class="">
+<br class="">
+ // Empty types don't need to be passed indirectly.<br class="">
+ if (Entries.empty()) return false;<br class="">
+<br class="">
+ CharUnits totalSize = Entries.back().End;<br class="">
+<br class="">
+ // Avoid copying the array of types when there's just a single element.<br class="">
+ if (Entries.size() == 1) {<br class="">
+ return getSwiftABIInfo(CGM).shouldPassIndirectlyForSwift(totalSize,<br class="">
+ Entries.back().Type,<br class="">
+ asReturnValue);<br class="">
+ }<br class="">
+<br class="">
+ SmallVector<llvm::Type*, 8> componentTys;<br class="">
+ componentTys.reserve(Entries.size());<br class="">
+ for (auto &entry : Entries) {<br class="">
+ componentTys.push_back(entry.Type);<br class="">
+ }<br class="">
+ return getSwiftABIInfo(CGM).shouldPassIndirectlyForSwift(totalSize,<br class="">
+ componentTys,<br class="">
+ asReturnValue);<br class="">
+}<br class="">
+<br class="">
+CharUnits swiftcall::getMaximumVoluntaryIntegerSize(CodeGenModule &CGM) {<br class="">
+ // Currently always the size of an ordinary pointer.<br class="">
+ return CGM.getContext().toCharUnitsFromBits(<br class="">
+ CGM.getContext().getTargetInfo().getPointerWidth(0));<br class="">
+}<br class="">
+<br class="">
+CharUnits swiftcall::getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type) {<br class="">
+ // For Swift's purposes, this is always just the store size of the type<br class="">
+ // rounded up to a power of 2.<br class="">
+ auto size = (unsigned long long) getTypeStoreSize(CGM, type).getQuantity();<br class="">
+ if (!isPowerOf2(size)) {<br class="">
+ size = 1U << (llvm::findLastSet(size, llvm::ZB_Undefined) + 1);<br class="">
+ }<br class="">
+ assert(size >= CGM.getDataLayout().getABITypeAlignment(type));<br class="">
+ return CharUnits::fromQuantity(size);<br class="">
+}<br class="">
+<br class="">
+bool swiftcall::isLegalIntegerType(CodeGenModule &CGM,<br class="">
+ llvm::IntegerType *intTy) {<br class="">
+ auto size = intTy->getBitWidth();<br class="">
+ switch (size) {<br class="">
+ case 1:<br class="">
+ case 8:<br class="">
+ case 16:<br class="">
+ case 32:<br class="">
+ case 64:<br class="">
+ // Just assume that the above are always legal.<br class="">
+ return true;<br class="">
+<br class="">
+ case 128:<br class="">
+ return CGM.getContext().getTargetInfo().hasInt128Type();<br class="">
+<br class="">
+ default:<br class="">
+ return false;<br class="">
+ }<br class="">
+}<br class="">
+<br class="">
+bool swiftcall::isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,<br class="">
+ llvm::VectorType *vectorTy) {<br class="">
+ return isLegalVectorType(CGM, vectorSize, vectorTy->getElementType(),<br class="">
+ vectorTy->getNumElements());<br class="">
+}<br class="">
+<br class="">
+bool swiftcall::isLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,<br class="">
+ llvm::Type *eltTy, unsigned numElts) {<br class="">
+ assert(numElts > 1 && "illegal vector length");<br class="">
+ return getSwiftABIInfo(CGM)<br class="">
+ .isLegalVectorTypeForSwift(vectorSize, eltTy, numElts);<br class="">
+}<br class="">
+<br class="">
+std::pair<llvm::Type*, unsigned><br class="">
+swiftcall::splitLegalVectorType(CodeGenModule &CGM, CharUnits vectorSize,<br class="">
+ llvm::VectorType *vectorTy) {<br class="">
+ auto numElts = vectorTy->getNumElements();<br class="">
+ auto eltTy = vectorTy->getElementType();<br class="">
+<br class="">
+ // Try to split the vector type in half.<br class="">
+ if (numElts >= 4 && isPowerOf2(numElts)) {<br class="">
+ if (isLegalVectorType(CGM, vectorSize / 2, eltTy, numElts / 2))<br class="">
+ return {llvm::VectorType::get(eltTy, numElts / 2), 2};<br class="">
+ }<br class="">
+<br class="">
+ return {eltTy, numElts};<br class="">
+}<br class="">
+<br class="">
+void swiftcall::legalizeVectorType(CodeGenModule &CGM, CharUnits origVectorSize,<br class="">
+ llvm::VectorType *origVectorTy,<br class="">
+ llvm::SmallVectorImpl<llvm::Type*> &components) {<br class="">
+ // If it's already a legal vector type, use it.<br class="">
+ if (isLegalVectorType(CGM, origVectorSize, origVectorTy)) {<br class="">
+ components.push_back(origVectorTy);<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // Try to split the vector into legal subvectors.<br class="">
+ auto numElts = origVectorTy->getNumElements();<br class="">
+ auto eltTy = origVectorTy->getElementType();<br class="">
+ assert(numElts != 1);<br class="">
+<br class="">
+ // The largest size that we're still considering making subvectors of.<br class="">
+ // Always a power of 2.<br class="">
+ unsigned logCandidateNumElts = llvm::findLastSet(numElts, llvm::ZB_Undefined);<br class="">
+ unsigned candidateNumElts = 1U << logCandidateNumElts;<br class="">
+ assert(candidateNumElts <= numElts && candidateNumElts * 2 > numElts);<br class="">
+<br class="">
+ // Minor optimization: don't check the legality of this exact size twice.<br class="">
+ if (candidateNumElts == numElts) {<br class="">
+ logCandidateNumElts--;<br class="">
+ candidateNumElts >>= 1;<br class="">
+ }<br class="">
+<br class="">
+ CharUnits eltSize = (origVectorSize / numElts);<br class="">
+ CharUnits candidateSize = eltSize * candidateNumElts;<br class="">
+<br class="">
+ // The sensibility of this algorithm relies on the fact that we never<br class="">
+ // have a legal non-power-of-2 vector size without having the power of 2<br class="">
+ // also be legal.<br class="">
+ while (logCandidateNumElts > 0) {<br class="">
+ assert(candidateNumElts == 1U << logCandidateNumElts);<br class="">
+ assert(candidateNumElts <= numElts);<br class="">
+ assert(candidateSize == eltSize * candidateNumElts);<br class="">
+<br class="">
+ // Skip illegal vector sizes.<br class="">
+ if (!isLegalVectorType(CGM, candidateSize, eltTy, candidateNumElts)) {<br class="">
+ logCandidateNumElts--;<br class="">
+ candidateNumElts /= 2;<br class="">
+ candidateSize /= 2;<br class="">
+ continue;<br class="">
+ }<br class="">
+<br class="">
+ // Add the right number of vectors of this size.<br class="">
+ auto numVecs = numElts >> logCandidateNumElts;<br class="">
+ components.append(numVecs, llvm::VectorType::get(eltTy, candidateNumElts));<br class="">
+ numElts -= (numVecs << logCandidateNumElts);<br class="">
+<br class="">
+ if (numElts == 0) return;<br class="">
+<br class="">
+ // It's possible that the number of elements remaining will be legal.<br class="">
+ // This can happen with e.g. <7 x float> when <3 x float> is legal.<br class="">
+ // This only needs to be separately checked if it's not a power of 2.<br class="">
+ if (numElts > 2 && !isPowerOf2(numElts) &&<br class="">
+ isLegalVectorType(CGM, eltSize * numElts, eltTy, numElts)) {<br class="">
+ components.push_back(llvm::VectorType::get(eltTy, numElts));<br class="">
+ return;<br class="">
+ }<br class="">
+<br class="">
+ // Bring vecSize down to something no larger than numElts.<br class="">
+ do {<br class="">
+ logCandidateNumElts--;<br class="">
+ candidateNumElts /= 2;<br class="">
+ candidateSize /= 2;<br class="">
+ } while (candidateNumElts > numElts);<br class="">
+ }<br class="">
+<br class="">
+ // Otherwise, just append a bunch of individual elements.<br class="">
+ components.append(numElts, eltTy);<br class="">
+}<br class="">
+<br class="">
+bool swiftcall::shouldPassCXXRecordIndirectly(CodeGenModule &CGM,<br class="">
+ const CXXRecordDecl *record) {<br class="">
+ // Following a recommendation from Richard Smith, pass a C++ type<br class="">
+ // indirectly only if the destructor is non-trivial or *all* of the<br class="">
+ // copy/move constructors are deleted or non-trivial.<br class="">
+<br class="">
+ if (record->hasNonTrivialDestructor())<br class="">
+ return true;<br class="">
+<br class="">
+ // It would be nice if this were summarized on the CXXRecordDecl.<br class="">
+ for (auto ctor : record->ctors()) {<br class="">
+ if (ctor->isCopyOrMoveConstructor() && !ctor->isDeleted() &&<br class="">
+ ctor->isTrivial()) {<br class="">
+ return false;<br class="">
+ }<br class="">
+ }<br class="">
+<br class="">
+ return true;<br class="">
+}<br class="">
+<br class="">
+static ABIArgInfo classifyExpandedType(SwiftAggLowering &lowering,<br class="">
+ bool forReturn,<br class="">
+ CharUnits alignmentForIndirect) {<br class="">
+ if (lowering.empty()) {<br class="">
+ return ABIArgInfo::getIgnore();<br class="">
+ } else if (lowering.shouldPassIndirectly(forReturn)) {<br class="">
+ return ABIArgInfo::getIndirect(alignmentForIndirect, /*byval*/ false);<br class="">
+ } else {<br class="">
+ auto types = lowering.getCoerceAndExpandTypes();<br class="">
+ return ABIArgInfo::getCoerceAndExpand(types.first, types.second);<br class="">
+ }<br class="">
+}<br class="">
+<br class="">
+static ABIArgInfo classifyType(CodeGenModule &CGM, CanQualType type,<br class="">
+ bool forReturn) {<br class="">
+ if (auto recordType = dyn_cast<RecordType>(type)) {<br class="">
+ auto record = recordType->getDecl();<br class="">
+ auto &layout = CGM.getContext().getASTRecordLayout(record);<br class="">
+<br class="">
+ if (auto cxxRecord = dyn_cast<CXXRecordDecl>(record)) {<br class="">
+ if (shouldPassCXXRecordIndirectly(CGM, cxxRecord))<br class="">
+ return ABIArgInfo::getIndirect(layout.getAlignment(), /*byval*/ false);<br class="">
+ }<br class="">
+<br class="">
+ SwiftAggLowering lowering(CGM);<br class="">
+ lowering.addTypedData(recordType->getDecl(), CharUnits::Zero(), layout);<br class="">
+ lowering.finish();<br class="">
+<br class="">
+ return classifyExpandedType(lowering, forReturn, layout.getAlignment());<br class="">
+ }<br class="">
+<br class="">
+ // Just assume that all of our target ABIs can support returning at least<br class="">
+ // two integer or floating-point values.<br class="">
+ if (isa<ComplexType>(type)) {<br class="">
+ return (forReturn ? ABIArgInfo::getDirect() : ABIArgInfo::getExpand());<br class="">
+ }<br class="">
+<br class="">
+ // Vector types may need to be legalized.<br class="">
+ if (isa<VectorType>(type)) {<br class="">
+ SwiftAggLowering lowering(CGM);<br class="">
+ lowering.addTypedData(type, CharUnits::Zero());<br class="">
+ lowering.finish();<br class="">
+<br class="">
+ CharUnits alignment = CGM.getContext().getTypeAlignInChars(type);<br class="">
+ return classifyExpandedType(lowering, forReturn, alignment);<br class="">
+ }<br class="">
+<br class="">
+ // Member pointer types need to be expanded, but it's a simple form of<br class="">
+ // expansion that 'Direct' can handle. Note that CanBeFlattened should be<br class="">
+ // true for this to work.<br class="">
+<br class="">
+ // 'void' needs to be ignored.<br class="">
+ if (type->isVoidType()) {<br class="">
+ return ABIArgInfo::getIgnore();<br class="">
+ }<br class="">
+<br class="">
+ // Everything else can be passed directly.<br class="">
+ return ABIArgInfo::getDirect();<br class="">
+}<br class="">
+<br class="">
+ABIArgInfo swiftcall::classifyReturnType(CodeGenModule &CGM, CanQualType type) {<br class="">
+ return classifyType(CGM, type, /*forReturn*/ true);<br class="">
+}<br class="">
+<br class="">
+ABIArgInfo swiftcall::classifyArgumentType(CodeGenModule &CGM,<br class="">
+ CanQualType type) {<br class="">
+ return classifyType(CGM, type, /*forReturn*/ false);<br class="">
+}<br class="">
+<br class="">
+void swiftcall::computeABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI) {<br class="">
+ auto &retInfo = FI.getReturnInfo();<br class="">
+ retInfo = classifyReturnType(CGM, FI.getReturnType());<br class="">
+<br class="">
+ for (unsigned i = 0, e = FI.arg_size(); i != e; ++i) {<br class="">
+ auto &argInfo = FI.arg_begin()[i];<br class="">
+ <a href="http://arginfo.info" class="">argInfo.info</a> = classifyArgumentType(CGM, argInfo.type);<br class="">
+ }<br class="">
+}<br class="">
\ No newline at end of file<br class="">
<br class="">
Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=265324&r1=265323&r2=265324&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=265324&r1=265323&r2=265324&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)<br class="">
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Mon Apr 4 13:33:08 2016<br class="">
@@ -19,6 +19,7 @@<br class="">
#include "CodeGenFunction.h"<br class="">
#include "clang/AST/RecordLayout.h"<br class="">
#include "clang/CodeGen/CGFunctionInfo.h"<br class="">
+#include "clang/CodeGen/SwiftCallingConv.h"<br class="">
#include "clang/Frontend/CodeGenOptions.h"<br class="">
#include "llvm/ADT/StringExtras.h"<br class="">
#include "llvm/ADT/Triple.h"<br class="">
@@ -68,6 +69,46 @@ Address ABIInfo::EmitMSVAArg(CodeGenFunc<br class="">
<br class="">
ABIInfo::~ABIInfo() {}<br class="">
<br class="">
+/// Does the given lowering require more than the given number of<br class="">
+/// registers when expanded?<br class="">
+///<br class="">
+/// This is intended to be the basis of a reasonable basic implementation<br class="">
+/// of should{Pass,Return}IndirectlyForSwift.<br class="">
+///<br class="">
+/// For most targets, a limit of four total registers is reasonable; this<br class="">
+/// limits the amount of code required in order to move around the value<br class="">
+/// in case it wasn't produced immediately prior to the call by the caller<br class="">
+/// (or wasn't produced in exactly the right registers) or isn't used<br class="">
+/// immediately within the callee. But some targets may need to further<br class="">
+/// limit the register count due to an inability to support that many<br class="">
+/// return registers.<br class="">
+static bool occupiesMoreThan(CodeGenTypes &cgt,<br class="">
+ ArrayRef<llvm::Type*> scalarTypes,<br class="">
+ unsigned maxAllRegisters) {<br class="">
+ unsigned intCount = 0, fpCount = 0;<br class="">
+ for (llvm::Type *type : scalarTypes) {<br class="">
+ if (type->isPointerTy()) {<br class="">
+ intCount++;<br class="">
+ } else if (auto intTy = dyn_cast<llvm::IntegerType>(type)) {<br class="">
+ auto ptrWidth = cgt.getTarget().getPointerWidth(0);<br class="">
+ intCount += (intTy->getBitWidth() + ptrWidth - 1) / ptrWidth;<br class="">
+ } else {<br class="">
+ assert(type->isVectorTy() || type->isFloatingPointTy());<br class="">
+ fpCount++;<br class="">
+ }<br class="">
+ }<br class="">
+<br class="">
+ return (intCount + fpCount > maxAllRegisters);<br class="">
+}<br class="">
+<br class="">
+bool SwiftABIInfo::isLegalVectorTypeForSwift(CharUnits vectorSize,<br class="">
+ llvm::Type *eltTy,<br class="">
+ unsigned numElts) const {<br class="">
+ // The default implementation of this assumes that the target guarantees<br class="">
+ // 128-bit SIMD support but nothing more.<br class="">
+ return (vectorSize.getQuantity() > 8 && vectorSize.getQuantity() <= 16);<br class="">
+}<br class="">
+<br class="">
static CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT,<br class="">
CGCXXABI &CXXABI) {<br class="">
const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());<br class="">
@@ -866,7 +907,7 @@ struct CCState {<br class="">
};<br class="">
<br class="">
/// X86_32ABIInfo - The X86-32 ABI information.<br class="">
-class X86_32ABIInfo : public ABIInfo {<br class="">
+class X86_32ABIInfo : public SwiftABIInfo {<br class="">
enum Class {<br class="">
Integer,<br class="">
Float<br class="">
@@ -935,12 +976,22 @@ public:<br class="">
X86_32ABIInfo(CodeGen::CodeGenTypes &CGT, bool DarwinVectorABI,<br class="">
bool RetSmallStructInRegABI, bool Win32StructABI,<br class="">
unsigned NumRegisterParameters, bool SoftFloatABI)<br class="">
- : ABIInfo(CGT), IsDarwinVectorABI(DarwinVectorABI),<br class="">
+ : SwiftABIInfo(CGT), IsDarwinVectorABI(DarwinVectorABI),<br class="">
IsRetSmallStructInRegABI(RetSmallStructInRegABI),<br class="">
IsWin32StructABI(Win32StructABI),<br class="">
IsSoftFloatABI(SoftFloatABI),<br class="">
IsMCUABI(CGT.getTarget().getTriple().isOSIAMCU()),<br class="">
DefaultNumRegisterParameters(NumRegisterParameters) {}<br class="">
+<br class="">
+ bool shouldPassIndirectlyForSwift(CharUnits totalSize,<br class="">
+ ArrayRef<llvm::Type*> scalars,<br class="">
+ bool asReturnValue) const override {<br class="">
+ // LLVM's x86-32 lowering currently only assigns up to three<br class="">
+ // integer registers and three fp registers. Oddly, it'll use up to<br class="">
+ // four vector registers for vectors, but those can overlap with the<br class="">
+ // scalar registers.<br class="">
+ return occupiesMoreThan(CGT, scalars, /*total*/ 3);<br class="">
+ }<br class="">
};<br class="">
<br class="">
class X86_32TargetCodeGenInfo : public TargetCodeGenInfo {<br class="">
@@ -1758,7 +1809,7 @@ static unsigned getNativeVectorSizeForAV<br class="">
}<br class="">
<br class="">
/// X86_64ABIInfo - The X86_64 ABI information.<br class="">
-class X86_64ABIInfo : public ABIInfo {<br class="">
+class X86_64ABIInfo : public SwiftABIInfo {<br class="">
enum Class {<br class="">
Integer = 0,<br class="">
SSE,<br class="">
@@ -1880,7 +1931,7 @@ class X86_64ABIInfo : public ABIInfo {<br class="">
<br class="">
public:<br class="">
X86_64ABIInfo(CodeGen::CodeGenTypes &CGT, X86AVXABILevel AVXLevel) :<br class="">
- ABIInfo(CGT), AVXLevel(AVXLevel),<br class="">
+ SwiftABIInfo(CGT), AVXLevel(AVXLevel),<br class="">
Has64BitPointers(CGT.getDataLayout().getPointerSize(0) == 8) {<br class="">
}<br class="">
<br class="">
@@ -1907,6 +1958,12 @@ public:<br class="">
bool has64BitPointers() const {<br class="">
return Has64BitPointers;<br class="">
}<br class="">
+<br class="">
+ bool shouldPassIndirectlyForSwift(CharUnits totalSize,<br class="">
+ ArrayRef<llvm::Type*> scalars,<br class="">
+ bool asReturnValue) const override {<br class="">
+ return occupiesMoreThan(CGT, scalars, /*total*/ 4);<br class="">
+ }<br class="">
};<br class="">
<br class="">
/// WinX86_64ABIInfo - The Windows X86_64 ABI information.<br class="">
@@ -4338,7 +4395,7 @@ PPC64TargetCodeGenInfo::initDwarfEHRegSi<br class="">
<br class="">
namespace {<br class="">
<br class="">
-class AArch64ABIInfo : public ABIInfo {<br class="">
+class AArch64ABIInfo : public SwiftABIInfo {<br class="">
public:<br class="">
enum ABIKind {<br class="">
AAPCS = 0,<br class="">
@@ -4349,7 +4406,8 @@ private:<br class="">
ABIKind Kind;<br class="">
<br class="">
public:<br class="">
- AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind) : ABIInfo(CGT), Kind(Kind) {}<br class="">
+ AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind)<br class="">
+ : SwiftABIInfo(CGT), Kind(Kind) {}<br class="">
<br class="">
private:<br class="">
ABIKind getABIKind() const { return Kind; }<br class="">
@@ -4382,6 +4440,12 @@ private:<br class="">
return isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)<br class="">
: EmitAAPCSVAArg(VAListAddr, Ty, CGF);<br class="">
}<br class="">
+<br class="">
+ bool shouldPassIndirectlyForSwift(CharUnits totalSize,<br class="">
+ ArrayRef<llvm::Type*> scalars,<br class="">
+ bool asReturnValue) const override {<br class="">
+ return occupiesMoreThan(CGT, scalars, /*total*/ 4);<br class="">
+ }<br class="">
};<br class="">
<br class="">
class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {<br class="">
@@ -4856,7 +4920,7 @@ Address AArch64ABIInfo::EmitDarwinVAArg(<br class="">
<br class="">
namespace {<br class="">
<br class="">
-class ARMABIInfo : public ABIInfo {<br class="">
+class ARMABIInfo : public SwiftABIInfo {<br class="">
public:<br class="">
enum ABIKind {<br class="">
APCS = 0,<br class="">
@@ -4869,7 +4933,8 @@ private:<br class="">
ABIKind Kind;<br class="">
<br class="">
public:<br class="">
- ARMABIInfo(CodeGenTypes &CGT, ABIKind _Kind) : ABIInfo(CGT), Kind(_Kind) {<br class="">
+ ARMABIInfo(CodeGenTypes &CGT, ABIKind _Kind)<br class="">
+ : SwiftABIInfo(CGT), Kind(_Kind) {<br class="">
setCCs();<br class="">
}<br class="">
<br class="">
@@ -4915,6 +4980,12 @@ private:<br class="">
llvm::CallingConv::ID getLLVMDefaultCC() const;<br class="">
llvm::CallingConv::ID getABIDefaultCC() const;<br class="">
void setCCs();<br class="">
+<br class="">
+ bool shouldPassIndirectlyForSwift(CharUnits totalSize,<br class="">
+ ArrayRef<llvm::Type*> scalars,<br class="">
+ bool asReturnValue) const override {<br class="">
+ return occupiesMoreThan(CGT, scalars, /*total*/ 4);<br class="">
+ }<br class="">
};<br class="">
<br class="">
class ARMTargetCodeGenInfo : public TargetCodeGenInfo {<br class="">
<br class="">
Modified: cfe/trunk/lib/CodeGen/TargetInfo.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.h?rev=265324&r1=265323&r2=265324&view=diff" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.h?rev=265324&r1=265323&r2=265324&view=diff</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/lib/CodeGen/TargetInfo.h (original)<br class="">
+++ cfe/trunk/lib/CodeGen/TargetInfo.h Mon Apr 4 13:33:08 2016<br class="">
@@ -29,15 +29,14 @@ class Value;<br class="">
}<br class="">
<br class="">
namespace clang {<br class="">
-class ABIInfo;<br class="">
class Decl;<br class="">
<br class="">
namespace CodeGen {<br class="">
+class ABIInfo;<br class="">
class CallArgList;<br class="">
class CodeGenModule;<br class="">
class CodeGenFunction;<br class="">
class CGFunctionInfo;<br class="">
-}<br class="">
<br class="">
/// TargetCodeGenInfo - This class organizes various target-specific<br class="">
/// codegeneration issues, like target-specific attributes, builtins and so<br class="">
@@ -219,6 +218,8 @@ public:<br class="">
llvm::StringRef Value,<br class="">
llvm::SmallString<32> &Opt) const {}<br class="">
};<br class="">
+<br class="">
+} // namespace CodeGen<br class="">
} // namespace clang<br class="">
<br class="">
#endif // LLVM_CLANG_LIB_CODEGEN_TARGETINFO_H<br class="">
<br class="">
Added: cfe/trunk/test/CodeGen/arm-swiftcall.c<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-swiftcall.c?rev=265324&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/arm-swiftcall.c?rev=265324&view=auto</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/test/CodeGen/arm-swiftcall.c (added)<br class="">
+++ cfe/trunk/test/CodeGen/arm-swiftcall.c Mon Apr 4 13:33:08 2016<br class="">
@@ -0,0 +1,496 @@<br class="">
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s<br class="">
+<br class="">
+// This isn't really testing anything ARM-specific; it's just a convenient<br class="">
+// 32-bit platform.<br class="">
+<br class="">
+#define SWIFTCALL __attribute__((swiftcall))<br class="">
+#define OUT __attribute__((swift_indirect_result))<br class="">
+#define ERROR __attribute__((swift_error_result))<br class="">
+#define CONTEXT __attribute__((swift_context))<br class="">
+<br class="">
+/*****************************************************************************/<br class="">
+/****************************** PARAMETER ABIS *******************************/<br class="">
+/*****************************************************************************/<br class="">
+<br class="">
+SWIFTCALL void indirect_result_1(OUT int *arg0, OUT float *arg1) {}<br class="">
+// CHECK-LABEL: define {{.*}} void @indirect_result_1(i32* noalias sret align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})<br class="">
+<br class="">
+// TODO: maybe this shouldn't suppress sret.<br class="">
+SWIFTCALL int indirect_result_2(OUT int *arg0, OUT float *arg1) { __builtin_unreachable(); }<br class="">
+// CHECK-LABEL: define {{.*}} i32 @indirect_result_2(i32* noalias align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})<br class="">
+<br class="">
+typedef struct { char array[1024]; } struct_reallybig;<br class="">
+SWIFTCALL struct_reallybig indirect_result_3(OUT int *arg0, OUT float *arg1) { __builtin_unreachable(); }<br class="">
+// CHECK-LABEL: define {{.*}} void @indirect_result_3({{.*}}* noalias sret {{.*}}, i32* noalias align 4 dereferenceable(4){{.*}}, float* noalias align 4 dereferenceable(4){{.*}})<br class="">
+<br class="">
+SWIFTCALL void context_1(CONTEXT void *self) {}<br class="">
+// CHECK-LABEL: define {{.*}} void @context_1(i8* swiftself<br class="">
+<br class="">
+SWIFTCALL void context_2(void *arg0, CONTEXT void *self) {}<br class="">
+// CHECK-LABEL: define {{.*}} void @context_2(i8*{{.*}}, i8* swiftself<br class="">
+<br class="">
+SWIFTCALL void context_error_1(CONTEXT int *self, ERROR float **error) {}<br class="">
+// CHECK-LABEL: define {{.*}} void @context_error_1(i32* swiftself{{.*}}, float** swifterror)<br class="">
+// CHECK: [[TEMP:%.*]] = alloca float*, align 4<br class="">
+// CHECK: [[T0:%.*]] = load float*, float** [[ERRORARG:%.*]], align 4<br class="">
+// CHECK: store float* [[T0]], float** [[TEMP]], align 4<br class="">
+// CHECK: [[T0:%.*]] = load float*, float** [[TEMP]], align 4<br class="">
+// CHECK: store float* [[T0]], float** [[ERRORARG]], align 4<br class="">
+void test_context_error_1() {<br class="">
+ int x;<br class="">
+ float *error;<br class="">
+ context_error_1(&x, &error);<br class="">
+}<br class="">
+// CHECK-LABEL: define void @test_context_error_1()<br class="">
+// CHECK: [[X:%.*]] = alloca i32, align 4<br class="">
+// CHECK: [[ERROR:%.*]] = alloca float*, align 4<br class="">
+// CHECK: [[TEMP:%.*]] = alloca swifterror float*, align 4<br class="">
+// CHECK: [[T0:%.*]] = load float*, float** [[ERROR]], align 4<br class="">
+// CHECK: store float* [[T0]], float** [[TEMP]], align 4<br class="">
+// CHECK: call [[SWIFTCC:cc16]] void @context_error_1(i32* swiftself [[X]], float** swifterror [[TEMP]])<br class="">
+// CHECK: [[T0:%.*]] = load float*, float** [[TEMP]], align 4<br class="">
+// CHECK: store float* [[T0]], float** [[ERROR]], align 4<br class="">
+<br class="">
+SWIFTCALL void context_error_2(short s, CONTEXT int *self, ERROR float **error) {}<br class="">
+// CHECK-LABEL: define {{.*}} void @context_error_2(i16{{.*}}, i32* swiftself{{.*}}, float** swifterror)<br class="">
+<br class="">
+/*****************************************************************************/<br class="">
+/********************************** LOWERING *********************************/<br class="">
+/*****************************************************************************/<br class="">
+<br class="">
+typedef float float4 __attribute__((ext_vector_type(4)));<br class="">
+typedef float float8 __attribute__((ext_vector_type(8)));<br class="">
+typedef double double2 __attribute__((ext_vector_type(2)));<br class="">
+typedef double double4 __attribute__((ext_vector_type(4)));<br class="">
+typedef int int4 __attribute__((ext_vector_type(4)));<br class="">
+typedef int int5 __attribute__((ext_vector_type(5)));<br class="">
+typedef int int8 __attribute__((ext_vector_type(8)));<br class="">
+<br class="">
+#define TEST(TYPE) \<br class="">
+ SWIFTCALL TYPE return_##TYPE(void) { \<br class="">
+ TYPE result = {}; \<br class="">
+ return result; \<br class="">
+ } \<br class="">
+ SWIFTCALL void take_##TYPE(TYPE v) { \<br class="">
+ } \<br class="">
+ void test_##TYPE() { \<br class="">
+ take_##TYPE(return_##TYPE()); \<br class="">
+ }<br class="">
+<br class="">
+/*****************************************************************************/<br class="">
+/*********************************** STRUCTS *********************************/<br class="">
+/*****************************************************************************/<br class="">
+<br class="">
+typedef struct {<br class="">
+} struct_empty;<br class="">
+TEST(struct_empty);<br class="">
+// CHECK-LABEL: define {{.*}} @return_struct_empty()<br class="">
+// CHECK: ret void<br class="">
+// CHECK-LABEL: define {{.*}} @take_struct_empty()<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+typedef struct {<br class="">
+ int x;<br class="">
+ char c0;<br class="">
+ char c1;<br class="">
+ float f0;<br class="">
+ float f1;<br class="">
+} struct_1;<br class="">
+TEST(struct_1);<br class="">
+// CHECK-LABEL: define {{.*}} @return_struct_1()<br class="">
+// CHECK: [[RET:%.*]] = alloca [[REC:%.*]], align 4<br class="">
+// CHECK: [[VAR:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: @llvm.memset<br class="">
+// CHECK: @llvm.memcpy<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ i32, i16, \[2 x i8\], float, float }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i16, i16* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4<br class="">
+// CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ i32, i16, float, float }]] undef, i32 [[FIRST]], 0<br class="">
+// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i16 [[SECOND]], 1<br class="">
+// CHECK: [[T2:%.*]] = insertvalue [[UAGG]] [[T1]], float [[THIRD]], 2<br class="">
+// CHECK: [[T3:%.*]] = insertvalue [[UAGG]] [[T2]], float [[FOURTH]], 3<br class="">
+// CHECK: ret [[UAGG]] [[T3]]<br class="">
+// CHECK-LABEL: define {{.*}} @take_struct_1(i32, i16, float, float)<br class="">
+// CHECK: [[V:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: store i32 %0, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: store i16 %1, i16* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: store float %2, float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4<br class="">
+// CHECK: store float %3, float* [[T0]], align 4<br class="">
+// CHECK: ret void<br class="">
+// CHECK-LABEL: define void @test_struct_1()<br class="">
+// CHECK: [[TMP:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_struct_1()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1<br class="">
+// CHECK: store i16 [[T1]], i16* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 2<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 3<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i16, i16* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4<br class="">
+// CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: call [[SWIFTCC]] void @take_struct_1(i32 [[FIRST]], i16 [[SECOND]], float [[THIRD]], float [[FOURTH]])<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+typedef struct {<br class="">
+ int x;<br class="">
+ char c0;<br class="">
+ __attribute__((aligned(2))) char c1;<br class="">
+ float f0;<br class="">
+ float f1;<br class="">
+} struct_2;<br class="">
+TEST(struct_2);<br class="">
+// CHECK-LABEL: define {{.*}} @return_struct_2()<br class="">
+// CHECK: [[RET:%.*]] = alloca [[REC:%.*]], align 4<br class="">
+// CHECK: [[VAR:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: @llvm.memcpy<br class="">
+// CHECK: @llvm.memcpy<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ i32, i32, float, float }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ i32, i32, float, float }]] undef, i32 [[FIRST]], 0<br class="">
+// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i32 [[SECOND]], 1<br class="">
+// CHECK: [[T2:%.*]] = insertvalue [[UAGG]] [[T1]], float [[THIRD]], 2<br class="">
+// CHECK: [[T3:%.*]] = insertvalue [[UAGG]] [[T2]], float [[FOURTH]], 3<br class="">
+// CHECK: ret [[UAGG]] [[T3]]<br class="">
+// CHECK-LABEL: define {{.*}} @take_struct_2(i32, i32, float, float)<br class="">
+// CHECK: [[V:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: store i32 %0, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: store i32 %1, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: store float %2, float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: store float %3, float* [[T0]], align 4<br class="">
+// CHECK: ret void<br class="">
+// CHECK-LABEL: define void @test_struct_2()<br class="">
+// CHECK: [[TMP:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_struct_2()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 2<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 3<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: call [[SWIFTCC]] void @take_struct_2(i32 [[FIRST]], i32 [[SECOND]], float [[THIRD]], float [[FOURTH]])<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+// There's no way to put a field randomly in the middle of an otherwise<br class="">
+// empty storage unit in C, so that case has to be tested in C++, which<br class="">
+// can use empty structs to introduce arbitrary padding. (In C, they end up<br class="">
+// with size 0 and so don't affect layout.)<br class="">
+<br class="">
+// Misaligned data rule.<br class="">
+typedef struct {<br class="">
+ char c0;<br class="">
+ __attribute__((packed)) float f;<br class="">
+} struct_misaligned_1;<br class="">
+TEST(struct_misaligned_1)<br class="">
+// CHECK-LABEL: define {{.*}} @return_struct_misaligned_1()<br class="">
+// CHECK: [[RET:%.*]] = alloca [[REC:%.*]], align<br class="">
+// CHECK: [[VAR:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: @llvm.memset<br class="">
+// CHECK: @llvm.memcpy<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ i32, i8 }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i8, i8* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ i32, i8 }]] undef, i32 [[FIRST]], 0<br class="">
+// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i8 [[SECOND]], 1<br class="">
+// CHECK: ret [[UAGG]] [[T1]]<br class="">
+// CHECK-LABEL: define {{.*}} @take_struct_misaligned_1(i32, i8)<br class="">
+// CHECK: [[V:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: store i32 %0, i32* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: store i8 %1, i8* [[T0]], align<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+// Too many scalars.<br class="">
+typedef struct {<br class="">
+ int x[5];<br class="">
+} struct_big_1;<br class="">
+TEST(struct_big_1)<br class="">
+<br class="">
+// CHECK-LABEL: define {{.*}} void @return_struct_big_1({{.*}} noalias sret<br class="">
+<br class="">
+// Should not be byval.<br class="">
+// CHECK-LABEL: define {{.*}} void @take_struct_big_1({{.*}}*{{( %.*)?}})<br class="">
+<br class="">
+/*****************************************************************************/<br class="">
+/********************************* TYPE MERGING ******************************/<br class="">
+/*****************************************************************************/<br class="">
+<br class="">
+typedef union {<br class="">
+ float f;<br class="">
+ double d;<br class="">
+} union_het_fp;<br class="">
+TEST(union_het_fp)<br class="">
+// CHECK-LABEL: define {{.*}} @return_union_het_fp()<br class="">
+// CHECK: [[RET:%.*]] = alloca [[REC:%.*]], align 4<br class="">
+// CHECK: [[VAR:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: @llvm.memcpy<br class="">
+// CHECK: @llvm.memcpy<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ i32, i32 }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ i32, i32 }]] undef, i32 [[FIRST]], 0<br class="">
+// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i32 [[SECOND]], 1<br class="">
+// CHECK: ret [[UAGG]] [[T1]]<br class="">
+// CHECK-LABEL: define {{.*}} @take_union_het_fp(i32, i32)<br class="">
+// CHECK: [[V:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: store i32 %0, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: store i32 %1, i32* [[T0]], align 4<br class="">
+// CHECK: ret void<br class="">
+// CHECK-LABEL: define void @test_union_het_fp()<br class="">
+// CHECK: [[TMP:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_union_het_fp()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: call [[SWIFTCC]] void @take_union_het_fp(i32 [[FIRST]], i32 [[SECOND]])<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+<br class="">
+typedef union {<br class="">
+ float f1;<br class="">
+ float f2;<br class="">
+} union_hom_fp;<br class="">
+TEST(union_hom_fp)<br class="">
+// CHECK-LABEL: define void @test_union_hom_fp()<br class="">
+// CHECK: [[TMP:%.*]] = alloca [[REC:%.*]], align 4<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] float @return_union_hom_fp()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG:{ float }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: store float [[CALL]], float* [[T0]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: call [[SWIFTCC]] void @take_union_hom_fp(float [[FIRST]])<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+typedef union {<br class="">
+ float f1;<br class="">
+ float4 fv2;<br class="">
+} union_hom_fp_partial;<br class="">
+TEST(union_hom_fp_partial)<br class="">
+// CHECK-LABEL: define void @test_union_hom_fp_partial()<br class="">
+// CHECK: [[TMP:%.*]] = alloca [[REC:%.*]], align 16<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG:{ float, float, float, float }]] @return_union_hom_fp_partial()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG:{ float, float, float, float }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 2<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 3<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: call [[SWIFTCC]] void @take_union_hom_fp_partial(float [[FIRST]], float [[SECOND]], float [[THIRD]], float [[FOURTH]])<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+typedef union {<br class="">
+ struct { int x, y; } f1;<br class="">
+ float4 fv2;<br class="">
+} union_het_fpv_partial;<br class="">
+TEST(union_het_fpv_partial)<br class="">
+// CHECK-LABEL: define void @test_union_het_fpv_partial()<br class="">
+// CHECK: [[TMP:%.*]] = alloca [[REC:%.*]], align 16<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG:{ i32, i32, float, float }]] @return_union_het_fpv_partial()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG:{ i32, i32, float, float }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 2<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 3<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 3<br class="">
+// CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align<br class="">
+// CHECK: call [[SWIFTCC]] void @take_union_het_fpv_partial(i32 [[FIRST]], i32 [[SECOND]], float [[THIRD]], float [[FOURTH]])<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+/*****************************************************************************/<br class="">
+/****************************** VECTOR LEGALIZATION **************************/<br class="">
+/*****************************************************************************/<br class="">
+<br class="">
+TEST(int4)<br class="">
+// CHECK-LABEL: define {{.*}} <4 x i32> @return_int4()<br class="">
+// CHECK-LABEL: define {{.*}} @take_int4(<4 x i32><br class="">
+<br class="">
+TEST(int8)<br class="">
+// CHECK-LABEL: define {{.*}} @return_int8()<br class="">
+// CHECK: [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 32<br class="">
+// CHECK: [[VAR:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: store<br class="">
+// CHECK: load<br class="">
+// CHECK: store<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ <4 x i32>, <4 x i32> }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ <4 x i32>, <4 x i32> }]] undef, <4 x i32> [[FIRST]], 0<br class="">
+// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], <4 x i32> [[SECOND]], 1<br class="">
+// CHECK: ret [[UAGG]] [[T1]]<br class="">
+// CHECK-LABEL: define {{.*}} @take_int8(<4 x i32>, <4 x i32>)<br class="">
+// CHECK: [[V:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: store <4 x i32> %0, <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: store <4 x i32> %1, <4 x i32>* [[T0]], align<br class="">
+// CHECK: ret void<br class="">
+// CHECK-LABEL: define void @test_int8()<br class="">
+// CHECK: [[TMP1:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: [[TMP2:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_int8()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP1]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0<br class="">
+// CHECK: store <4 x i32> [[T1]], <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1<br class="">
+// CHECK: store <4 x i32> [[T1]], <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[V:%.*]] = load [[REC]], [[REC]]* [[TMP1]], align<br class="">
+// CHECK: store [[REC]] [[V]], [[REC]]* [[TMP2]], align<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP2]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align<br class="">
+// CHECK: call [[SWIFTCC]] void @take_int8(<4 x i32> [[FIRST]], <4 x i32> [[SECOND]])<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+TEST(int5)<br class="">
+// CHECK-LABEL: define {{.*}} @return_int5()<br class="">
+// CHECK: [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 32<br class="">
+// CHECK: [[VAR:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: store<br class="">
+// CHECK: load<br class="">
+// CHECK: store<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ <4 x i32>, i32 }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ <4 x i32>, i32 }]] undef, <4 x i32> [[FIRST]], 0<br class="">
+// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i32 [[SECOND]], 1<br class="">
+// CHECK: ret [[UAGG]] [[T1]]<br class="">
+// CHECK-LABEL: define {{.*}} @take_int5(<4 x i32>, i32)<br class="">
+// CHECK: [[V:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: store <4 x i32> %0, <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: store i32 %1, i32* [[T0]], align<br class="">
+// CHECK: ret void<br class="">
+// CHECK-LABEL: define void @test_int5()<br class="">
+// CHECK: [[TMP1:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: [[TMP2:%.*]] = alloca [[REC]], align<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC]] [[UAGG]] @return_int5()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP1]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0<br class="">
+// CHECK: store <4 x i32> [[T1]], <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align<br class="">
+// CHECK: [[V:%.*]] = load [[REC]], [[REC]]* [[TMP1]], align<br class="">
+// CHECK: store [[REC]] [[V]], [[REC]]* [[TMP2]], align<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP2]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load <4 x i32>, <4 x i32>* [[T0]], align<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 1<br class="">
+// CHECK: [[SECOND:%.*]] = load i32, i32* [[T0]], align<br class="">
+// CHECK: call [[SWIFTCC]] void @take_int5(<4 x i32> [[FIRST]], i32 [[SECOND]])<br class="">
+// CHECK: ret void<br class="">
<br class="">
Added: cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp?rev=265324&view=auto" rel="noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp?rev=265324&view=auto</a><br class="">
==============================================================================<br class="">
--- cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp (added)<br class="">
+++ cfe/trunk/test/CodeGenCXX/arm-swiftcall.cpp Mon Apr 4 13:33:08 2016<br class="">
@@ -0,0 +1,115 @@<br class="">
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s -Wno-return-type-c-linkage | FileCheck %s<br class="">
+<br class="">
+// This isn't really testing anything ARM-specific; it's just a convenient<br class="">
+// 32-bit platform.<br class="">
+<br class="">
+#define SWIFTCALL __attribute__((swiftcall))<br class="">
+#define OUT __attribute__((swift_indirect_result))<br class="">
+#define ERROR __attribute__((swift_error_result))<br class="">
+#define CONTEXT __attribute__((swift_context))<br class="">
+<br class="">
+/*****************************************************************************/<br class="">
+/********************************** LOWERING *********************************/<br class="">
+/*****************************************************************************/<br class="">
+<br class="">
+#define TEST(TYPE) \<br class="">
+ extern "C" SWIFTCALL TYPE return_##TYPE(void) { \<br class="">
+ TYPE result = {}; \<br class="">
+ return result; \<br class="">
+ } \<br class="">
+ extern "C" SWIFTCALL void take_##TYPE(TYPE v) { \<br class="">
+ } \<br class="">
+ extern "C" void test_##TYPE() { \<br class="">
+ take_##TYPE(return_##TYPE()); \<br class="">
+ }<br class="">
+<br class="">
+/*****************************************************************************/<br class="">
+/*********************************** STRUCTS *********************************/<br class="">
+/*****************************************************************************/<br class="">
+<br class="">
+typedef struct {<br class="">
+} struct_empty;<br class="">
+TEST(struct_empty);<br class="">
+// CHECK-LABEL: define {{.*}} @return_struct_empty()<br class="">
+// CHECK: ret void<br class="">
+// CHECK-LABEL: define {{.*}} @take_struct_empty()<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+// This is only properly testable in C++ because it relies on empty structs<br class="">
+// actually taking up space in a structure without requiring any extra data<br class="">
+// to be passed.<br class="">
+typedef struct {<br class="">
+ int x;<br class="">
+ struct_empty padding[2];<br class="">
+ char c1;<br class="">
+ float f0;<br class="">
+ float f1;<br class="">
+} struct_1;<br class="">
+TEST(struct_1);<br class="">
+// CHECK-LABEL: define {{.*}} @return_struct_1()<br class="">
+// CHECK: [[RET:%.*]] = alloca [[REC:%.*]], align 4<br class="">
+// CHECK: @llvm.memset<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[RET]] to [[AGG:{ i32, \[2 x i8\], i8, \[1 x i8\], float, float }]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[SECOND:%.*]] = load i8, i8* [[T0]], align 2<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4<br class="">
+// CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 5<br class="">
+// CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = insertvalue [[UAGG:{ i32, i8, float, float }]] undef, i32 [[FIRST]], 0<br class="">
+// CHECK: [[T1:%.*]] = insertvalue [[UAGG]] [[T0]], i8 [[SECOND]], 1<br class="">
+// CHECK: [[T2:%.*]] = insertvalue [[UAGG]] [[T1]], float [[THIRD]], 2<br class="">
+// CHECK: [[T3:%.*]] = insertvalue [[UAGG]] [[T2]], float [[FOURTH]], 3<br class="">
+// CHECK: ret [[UAGG]] [[T3]]<br class="">
+// CHECK-LABEL: define {{.*}} @take_struct_1(i32, i8, float, float)<br class="">
+// CHECK: [[V:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[V]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: store i32 %0, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: store i8 %1, i8* [[T0]], align 2<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4<br class="">
+// CHECK: store float %2, float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 5<br class="">
+// CHECK: store float %3, float* [[T0]], align 4<br class="">
+// CHECK: ret void<br class="">
+// CHECK-LABEL: define void @test_struct_1()<br class="">
+// CHECK: [[TMP:%.*]] = alloca [[REC]], align 4<br class="">
+// CHECK: [[CALL:%.*]] = call [[SWIFTCC:cc16]] [[UAGG]] @return_struct_1()<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 0<br class="">
+// CHECK: store i32 [[T1]], i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 1<br class="">
+// CHECK: store i8 [[T1]], i8* [[T0]], align 2<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 2<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 5<br class="">
+// CHECK: [[T1:%.*]] = extractvalue [[UAGG]] [[CALL]], 3<br class="">
+// CHECK: store float [[T1]], float* [[T0]], align 4<br class="">
+// CHECK: [[CAST_TMP:%.*]] = bitcast [[REC]]* [[TMP]] to [[AGG]]*<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 0<br class="">
+// CHECK: [[FIRST:%.*]] = load i32, i32* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 2<br class="">
+// CHECK: [[SECOND:%.*]] = load i8, i8* [[T0]], align 2<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 4<br class="">
+// CHECK: [[THIRD:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: [[T0:%.*]] = getelementptr inbounds [[AGG]], [[AGG]]* [[CAST_TMP]], i32 0, i32 5<br class="">
+// CHECK: [[FOURTH:%.*]] = load float, float* [[T0]], align 4<br class="">
+// CHECK: call [[SWIFTCC]] void @take_struct_1(i32 [[FIRST]], i8 [[SECOND]], float [[THIRD]], float [[FOURTH]])<br class="">
+// CHECK: ret void<br class="">
+<br class="">
+struct struct_indirect_1 {<br class="">
+ int x;<br class="">
+ ~struct_indirect_1();<br class="">
+};<br class="">
+TEST(struct_indirect_1)<br class="">
+<br class="">
+// CHECK-LABEL: define {{.*}} void @return_struct_indirect_1({{.*}} noalias sret<br class="">
+<br class="">
+// Should not be byval.<br class="">
+// CHECK-LABEL: define {{.*}} void @take_struct_indirect_1({{.*}}*{{( %.*)?}})<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
cfe-commits mailing list<br class="">
<a href="mailto:cfe-commits@lists.llvm.org" class="">cfe-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>