10#include "TargetInfo.h"
42 Arg.info = classifyArgumentType(Arg.type);
45 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
46 AggValueSlot Slot)
const override;
55 std::make_unique<SwiftABIInfo>(CGT,
false);
61 if (
const auto *VD = dyn_cast_or_null<VarDecl>(D)) {
63 const auto *ModuleAttr = VD->getAttr<WebAssemblyImportModuleAttr>();
64 const auto *NameAttr = VD->getAttr<WebAssemblyImportNameAttr>();
65 if (ModuleAttr || NameAttr) {
67 bool IsExplicit = (ModuleAttr && !ModuleAttr->isInherited()) ||
68 (NameAttr && !NameAttr->isInherited());
70 auto AttrLoc = ModuleAttr ? ModuleAttr->getLocation()
71 : NameAttr->getLocation();
73 <<
"import attribute cannot be applied to a definition";
77 if (
Global->getAddressSpace() == 0) {
79 ModuleAttr ? ModuleAttr->getLocation() : NameAttr->getLocation();
81 <<
"import attribute cannot be applied to a non-wasm-variable "
86 Global->addAttribute(
"wasm-import-module",
87 ModuleAttr->getImportModule());
89 Global->addAttribute(
"wasm-import-name", NameAttr->getImportName());
91 if (
const auto *
Attr = VD->getAttr<WebAssemblyExportNameAttr>()) {
92 Global->addAttribute(
"wasm-export-name",
Attr->getExportName());
94 }
else if (
const auto *FD = dyn_cast_or_null<FunctionDecl>(D)) {
96 const auto *ModuleAttr = FD->getAttr<WebAssemblyImportModuleAttr>();
97 const auto *NameAttr = FD->getAttr<WebAssemblyImportNameAttr>();
98 if (ModuleAttr || NameAttr) {
99 if (FD->isThisDeclarationADefinition()) {
100 bool IsExplicit = (ModuleAttr && !ModuleAttr->isInherited()) ||
101 (NameAttr && !NameAttr->isInherited());
103 auto AttrLoc = ModuleAttr ? ModuleAttr->getLocation()
104 : NameAttr->getLocation();
106 <<
"import attribute cannot be applied to a definition";
108 NonConstFD->
dropAttr<WebAssemblyImportModuleAttr>();
109 NonConstFD->dropAttr<WebAssemblyImportNameAttr>();
114 Fn->addFnAttr(
"wasm-import-module", ModuleAttr->getImportModule());
116 Fn->addFnAttr(
"wasm-import-name", NameAttr->getImportName());
118 if (
const auto *
Attr = FD->getAttr<WebAssemblyExportNameAttr>()) {
119 Fn->addFnAttr(
"wasm-export-name",
Attr->getExportName());
122 if (!FD->doesThisDeclarationHaveABody() && !FD->hasPrototype())
123 Fn->addFnAttr(
"no-prototype");
129 return llvm::Type::getWasm_ExternrefTy(
getABIInfo().getVMContext());
133 return llvm::Type::getWasm_FuncrefTy(
getABIInfo().getVMContext());
156 if (Kind == WebAssemblyABIKind::ExperimentalMV) {
157 if (Ty->
getAs<ComplexType>())
161 bool HasBitField =
false;
162 for (
auto *Field : RD->fields()) {
163 if (
Field->isBitField()) {
175 return defaultInfo.classifyArgumentType(Ty);
192 if (Kind == WebAssemblyABIKind::ExperimentalMV)
198 return defaultInfo.classifyReturnType(RetTy);
212std::unique_ptr<TargetCodeGenInfo>
215 return std::make_unique<WebAssemblyTargetCodeGenInfo>(CGM.
getTypes(), K);
WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT, WebAssemblyABIKind Kind)
virtual llvm::Type * getWasmFuncrefReferenceType() const override
Return the WebAssembly funcref reference type.
virtual llvm::Type * getWasmExternrefReferenceType() const override
Return the WebAssembly externref reference type.
void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &CGM) const override
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
WebAssemblyTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT, WebAssemblyABIKind K)
Attr - This represents one attribute.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static ABIArgInfo getIgnore()
static ABIArgInfo getExpand()
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
const llvm::DataLayout & getDataLayout() const
CodeGen::ABIArgInfo getNaturalAlignIndirect(QualType Ty, unsigned AddrSpace, bool ByVal=true, bool Realign=false, llvm::Type *Padding=nullptr) const
A convenience method to return an indirect ABIArgInfo with an expected alignment equal to the ABI ali...
ABIInfo(CodeGen::CodeGenTypes &cgt)
CodeGen::CodeGenTypes & CGT
CodeGen::CGCXXABI & getCXXABI() const
ASTContext & getContext() const
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
CGFunctionInfo - Class to encapsulate the information about a function definition.
ABIArgInfo & getReturnInfo()
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
This class organizes the cross-function state that is used while generating LLVM code.
DiagnosticsEngine & getDiags() const
CodeGenTypes & getTypes()
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
DefaultABIInfo - The default implementation for ABI specific details.
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
std::unique_ptr< SwiftABIInfo > SwiftInfo
const T & getABIInfo() const
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
TargetCodeGenInfo(std::unique_ptr< ABIInfo > Info)
Decl - This represents one declaration (or definition), e.g.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Represents a function declaration or definition.
A (possibly-)qualified type.
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
const T * getAs() const
Member-template getAs<specific type>'.
@ DeclarationOnly
This declaration is only a declaration.
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
std::unique_ptr< TargetCodeGenInfo > createWebAssemblyTargetCodeGenInfo(CodeGenModule &CGM, WebAssemblyABIKind K)
RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType ValueTy, bool IsIndirect, TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign, bool AllowHigherAlign, AggValueSlot Slot, bool ForceRightAdjust=false)
Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...
bool isAggregateTypeForABI(QualType T)
const Type * isSingleElementStruct(QualType T, ASTContext &Context)
isSingleElementStruct - Determine if a structure is a "singleelement struct", i.e.
QualType useFirstFieldIfTransparentUnion(QualType Ty)
Pass transparent unions as if they were the type of the first element.
bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, bool AsIfNoUniqueAddr=false)
isEmptyRecord - Return true iff a structure contains only empty fields.
Top level wrappers for InstallAPI frontend operations.
@ Type
The name was classified as a type.
U cast(CodeGen::Address addr)