forked from OSchip/llvm-project
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
This commit is contained in:
parent
89073db6d2
commit
a39bab36c6
|
@ -720,10 +720,12 @@ ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy) const {
|
||||||
// This is a very simple ABI that relies a lot on DefaultABIInfo.
|
// This is a very simple ABI that relies a lot on DefaultABIInfo.
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
class WebAssemblyABIInfo final : public DefaultABIInfo {
|
class WebAssemblyABIInfo final : public SwiftABIInfo {
|
||||||
|
DefaultABIInfo defaultInfo;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT)
|
explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT)
|
||||||
: DefaultABIInfo(CGT) {}
|
: SwiftABIInfo(CGT), defaultInfo(CGT) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
ABIArgInfo classifyReturnType(QualType RetTy) const;
|
||||||
|
@ -741,6 +743,15 @@ private:
|
||||||
|
|
||||||
Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
|
Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
|
||||||
QualType Ty) const override;
|
QualType Ty) const override;
|
||||||
|
|
||||||
|
bool shouldPassIndirectlyForSwift(ArrayRef<llvm::Type*> scalars,
|
||||||
|
bool asReturnValue) const override {
|
||||||
|
return occupiesMoreThan(CGT, scalars, /*total*/ 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSwiftErrorInRegister() const override {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
|
class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
|
||||||
|
@ -778,7 +789,7 @@ ABIArgInfo WebAssemblyABIInfo::classifyArgumentType(QualType Ty) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise just do the default thing.
|
// Otherwise just do the default thing.
|
||||||
return DefaultABIInfo::classifyArgumentType(Ty);
|
return defaultInfo.classifyArgumentType(Ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
ABIArgInfo WebAssemblyABIInfo::classifyReturnType(QualType RetTy) const {
|
ABIArgInfo WebAssemblyABIInfo::classifyReturnType(QualType RetTy) const {
|
||||||
|
@ -798,7 +809,7 @@ ABIArgInfo WebAssemblyABIInfo::classifyReturnType(QualType RetTy) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise just do the default thing.
|
// Otherwise just do the default thing.
|
||||||
return DefaultABIInfo::classifyReturnType(RetTy);
|
return defaultInfo.classifyReturnType(RetTy);
|
||||||
}
|
}
|
||||||
|
|
||||||
Address WebAssemblyABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
|
Address WebAssemblyABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
|
||||||
|
@ -8307,7 +8318,7 @@ ABIArgInfo ARCABIInfo::getIndirectByRef(QualType Ty, bool HasFreeRegs) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ABIArgInfo ARCABIInfo::getIndirectByValue(QualType Ty) const {
|
ABIArgInfo ARCABIInfo::getIndirectByValue(QualType Ty) const {
|
||||||
// Compute the byval alignment.
|
// Compute the byval alignment.
|
||||||
const unsigned MinABIStackAlignInBytes = 4;
|
const unsigned MinABIStackAlignInBytes = 4;
|
||||||
unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
|
unsigned TypeAlign = getContext().getTypeAlign(Ty) / 8;
|
||||||
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4), /*ByVal=*/true,
|
return ABIArgInfo::getIndirect(CharUnits::fromQuantity(4), /*ByVal=*/true,
|
||||||
|
@ -8371,7 +8382,7 @@ ABIArgInfo ARCABIInfo::classifyReturnType(QualType RetTy) const {
|
||||||
if (RetTy->isAnyComplexType())
|
if (RetTy->isAnyComplexType())
|
||||||
return ABIArgInfo::getDirectInReg();
|
return ABIArgInfo::getDirectInReg();
|
||||||
|
|
||||||
// Arguments of size > 4 registers are indirect.
|
// Arguments of size > 4 registers are indirect.
|
||||||
auto RetSize = llvm::alignTo(getContext().getTypeSize(RetTy), 32) / 32;
|
auto RetSize = llvm::alignTo(getContext().getTypeSize(RetTy), 32) / 32;
|
||||||
if (RetSize > 4)
|
if (RetSize > 4)
|
||||||
return getIndirectByRef(RetTy, /*HasFreeRegs*/ true);
|
return getIndirectByRef(RetTy, /*HasFreeRegs*/ true);
|
||||||
|
|
Loading…
Reference in New Issue