clang: lib/CodeGen/Targets/WebAssembly.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10#include "TargetInfo.h"
11
12using namespace clang;
14
15
16
17
18
19
20
24
25public:
29
30private:
33
34
35
36
38 if (().classifyReturnType(FI))
41 Arg.info = classifyArgumentType(Arg.type);
42 }
43
46};
47
49public:
54 std::make_unique(CGT, false);
55 }
56
60 if (const auto *FD = dyn_cast_or_null(D)) {
61 if (const auto *Attr = FD->getAttr()) {
62 llvm::Function *Fn = castllvm::Function(GV);
63 llvm::AttrBuilder B(GV->getContext());
64 B.addAttribute("wasm-import-module", Attr->getImportModule());
65 Fn->addFnAttrs(B);
66 }
67 if (const auto *Attr = FD->getAttr()) {
68 llvm::Function *Fn = castllvm::Function(GV);
69 llvm::AttrBuilder B(GV->getContext());
70 B.addAttribute("wasm-import-name", Attr->getImportName());
71 Fn->addFnAttrs(B);
72 }
73 if (const auto *Attr = FD->getAttr()) {
74 llvm::Function *Fn = castllvm::Function(GV);
75 llvm::AttrBuilder B(GV->getContext());
76 B.addAttribute("wasm-export-name", Attr->getExportName());
77 Fn->addFnAttrs(B);
78 }
79 }
80
81 if (auto *FD = dyn_cast_or_null(D)) {
82 llvm::Function *Fn = castllvm::Function(GV);
83 if (!FD->doesThisDeclarationHaveABody() && !FD->hasPrototype())
84 Fn->addFnAttr("no-prototype");
85 }
86 }
87
88
90 return llvm::Type::getWasm_ExternrefTy(getABIInfo().getVMContext());
91 }
92
94 return llvm::Type::getWasm_FuncrefTy(getABIInfo().getVMContext());
95 }
96};
97
98
99ABIArgInfo WebAssemblyABIInfo::classifyArgumentType(QualType Ty) const {
101
103
104
107
110
111
112
115
116 if (Kind == WebAssemblyABIKind::ExperimentalMV) {
118 assert(RT);
119 bool HasBitField = false;
121 if (Field->isBitField()) {
122 HasBitField = true;
123 break;
124 }
125 }
126 if (!HasBitField)
128 }
129 }
130
131
132 return defaultInfo.classifyArgumentType(Ty);
133}
134
135ABIArgInfo WebAssemblyABIInfo::classifyReturnType(QualType RetTy) const {
137
138
140
143
144
145
148
149 if (Kind == WebAssemblyABIKind::ExperimentalMV)
151 }
152 }
153
154
155 return defaultInfo.classifyReturnType(RetTy);
156}
157
166 true, Slot);
167}
168
169std::unique_ptr
172 return std::make_unique(CGM.getTypes(), K);
173}
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)
ABIInfo - Target specific hooks for defining how a type should be passed or returned from functions.
CodeGen::CodeGenTypes & CGT
CodeGen::CGCXXABI & getCXXABI() const
ASTContext & getContext() const
CodeGen::ABIArgInfo getNaturalAlignIndirect(QualType Ty, 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...
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.
CodeGenTypes & getTypes()
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
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.
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
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...
Decl - This represents one declaration (or definition), e.g.
A (possibly-)qualified type.
field_range fields() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
The base class of the type hierarchy.
const T * getAs() const
Member-template getAs'.
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
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 "single element 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.
The JSON file list parser is used to communicate input to InstallAPI.