Skip to content

Commit a39bab3

Browse files
committedJan 3, 2019
Adopt SwiftABIInfo for WebAssembly.
Summary: - This adopts SwiftABIInfo as the base class for WebAssemblyABIInfo, which is in keeping with what is done for other targets for which Swift is supported. - This is a minimal patch to unblock exploration of WASM support for Swift (https://bugs.swift.org/browse/SR-9307) Reviewers: rjmccall, sunfish Reviewed By: rjmccall Subscribers: ahti, dschuff, sbc100, jgravelle-google, aheejin, cfe-commits Differential Revision: https://reviews.llvm.org/D56188 llvm-svn: 350372
1 parent 89073db commit a39bab3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed
 

Diff for: ‎clang/lib/CodeGen/TargetInfo.cpp

+17-6
Original file line numberDiff line numberDiff line change
@@ -720,10 +720,12 @@ ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy) const {
720720
// This is a very simple ABI that relies a lot on DefaultABIInfo.
721721
//===----------------------------------------------------------------------===//
722722

723-
class WebAssemblyABIInfo final : public DefaultABIInfo {
723+
class WebAssemblyABIInfo final : public SwiftABIInfo {
724+
DefaultABIInfo defaultInfo;
725+
724726
public:
725727
explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT)
726-
: DefaultABIInfo(CGT) {}
728+
: SwiftABIInfo(CGT), defaultInfo(CGT) {}
727729

728730
private:
729731
ABIArgInfo classifyReturnType(QualType RetTy) const;
@@ -741,6 +743,15 @@ class WebAssemblyABIInfo final : public DefaultABIInfo {
741743

742744
Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
743745
QualType Ty) const override;
746+
747+
bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> scalars,
748+
bool asReturnValue) const override {
749+
return occupiesMoreThan(CGT, scalars, /*total*/ 4);
750+
}
751+
752+
bool isSwiftErrorInRegister() const override {
753+
return false;
754+
}
744755
};
745756

746757
class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
@@ -778,7 +789,7 @@ ABIArgInfo WebAssemblyABIInfo::classifyArgumentType(QualType Ty) const {
778789
}
779790

780791
// Otherwise just do the default thing.
781-
return DefaultABIInfo::classifyArgumentType(Ty);
792+
return defaultInfo.classifyArgumentType(Ty);
782793
}
783794

784795
ABIArgInfo WebAssemblyABIInfo::classifyReturnType(QualType RetTy) const {
@@ -798,7 +809,7 @@ ABIArgInfo WebAssemblyABIInfo::classifyReturnType(QualType RetTy) const {
798809
}
799810

800811
// Otherwise just do the default thing.
801-
return DefaultABIInfo::classifyReturnType(RetTy);
812+
return defaultInfo.classifyReturnType(RetTy);
802813
}
803814

804815
Address WebAssemblyABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
@@ -8307,7 +8318,7 @@ ABIArgInfo ARCABIInfo::getIndirectByRef(QualType Ty, bool HasFreeRegs) const {
83078318
}
83088319

83098320
ABIArgInfo ARCABIInfo::getIndirectByValue(QualType Ty) const {
8310-
// Compute the byval alignment.
8321+
// Compute the byval alignment.
83118322
const unsigned MinABIStackAlignInBytes = 4;
83128323
unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
83138324
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4), /*ByVal=*/true,
@@ -8371,7 +8382,7 @@ ABIArgInfo ARCABIInfo::classifyReturnType(QualType RetTy) const {
83718382
if (RetTy->isAnyComplexType())
83728383
return ABIArgInfo::getDirectInReg();
83738384

8374-
// Arguments of size > 4 registers are indirect.
8385+
// Arguments of size > 4 registers are indirect.
83758386
auto RetSize = llvm::alignTo(getContext().getTypeSize(RetTy), 32) / 32;
83768387
if (RetSize > 4)
83778388
return getIndirectByRef(RetTy, /*HasFreeRegs*/ true);

0 commit comments

Comments
 (0)
Please sign in to comment.