LLVM 24.0.0git
WebAssemblyMachineFunctionInfo.cpp
Go to the documentation of this file.
1//=- WebAssemblyMachineFunctionInfo.cpp - WebAssembly Machine Function Info -=//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements WebAssembly-specific per-machine-function
11/// information.
12///
13//===----------------------------------------------------------------------===//
14
22using namespace llvm;
23
25
32
34 assert(WARegs.empty());
35 unsigned Reg = WebAssembly::UnusedReg;
36 WARegs.resize(MRI.getNumVirtRegs(), Reg);
37}
38
40 LLVMContext &Ctx, const DataLayout &DL,
41 Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
43 ComputeValueVTs(TLI, DL, Ty, VTs);
44
45 for (EVT VT : VTs) {
46 unsigned NumRegs = TLI.getNumRegisters(Ctx, VT);
47 MVT RegisterVT = TLI.getRegisterType(Ctx, VT);
48 for (unsigned I = 0; I != NumRegs; ++I)
49 ValueVTs.push_back(RegisterVT);
50 }
51}
52
54 Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
55 const DataLayout &DL(F.getDataLayout());
56 const WebAssemblyTargetLowering &TLI =
57 *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
58 computeLegalValueVTs(TLI, F.getContext(), DL, Ty, ValueVTs);
59}
60
62 const Function *TargetFunc,
63 const Function &ContextFunc,
64 const TargetMachine &TM,
67 computeLegalValueVTs(ContextFunc, TM, Ty->getReturnType(), Results);
68
71 Results.size(),
72 &TM.getSubtarget<WebAssemblySubtarget>(ContextFunc))) {
73 // WebAssembly can't lower returns of multiple values without demoting to
74 // sret unless multivalue is enabled (see
75 // WebAssemblyTargetLowering::CanLowerReturn). So replace multiple return
76 // values with a poitner parameter.
77 Results.clear();
78 Params.push_back(PtrVT);
79 }
80
81 for (auto *Param : Ty->params())
82 computeLegalValueVTs(ContextFunc, TM, Param, Params);
83 if (Ty->isVarArg())
84 Params.push_back(PtrVT);
85
86 // For swiftcc and swifttailcc, emit additional swiftself, swifterror, and
87 // (for swifttailcc) swiftasync parameters if there aren't. These additional
88 // parameters are also passed for caller. They are necessary to match callee
89 // and caller signature for indirect call.
90
91 if (TargetFunc && (TargetFunc->getCallingConv() == CallingConv::Swift ||
92 TargetFunc->getCallingConv() == CallingConv::SwiftTail)) {
94 bool HasSwiftErrorArg = false;
95 bool HasSwiftSelfArg = false;
96 bool HasSwiftAsyncArg = false;
97 for (const auto &Arg : TargetFunc->args()) {
98 HasSwiftErrorArg |= Arg.hasAttribute(Attribute::SwiftError);
99 HasSwiftSelfArg |= Arg.hasAttribute(Attribute::SwiftSelf);
100 HasSwiftAsyncArg |= Arg.hasAttribute(Attribute::SwiftAsync);
101 }
102 if (!HasSwiftSelfArg)
103 Params.push_back(PtrVT);
104 if (!HasSwiftErrorArg)
105 Params.push_back(PtrVT);
106 if (TargetFunc->getCallingConv() == CallingConv::SwiftTail &&
107 !HasSwiftAsyncArg)
108 Params.push_back(PtrVT);
109 }
110}
111
117
120 const SmallVectorImpl<MVT> &Params) {
121 auto Sig = Ctx.createWasmSignature();
122 valTypesFromMVTs(Results, Sig->Returns);
123 valTypesFromMVTs(Params, Sig->Params);
124 return Sig;
125}
126
129 : CFGStackified(MFI.isCFGStackified()) {
130 for (auto VT : MFI.getParams())
131 Params.push_back(EVT(VT).getEVTString());
132 for (auto VT : MFI.getResults())
133 Results.push_back(EVT(VT).getEVTString());
134}
135
139
142 CFGStackified = YamlMFI.CFGStackified;
143 for (auto VT : YamlMFI.Params)
145 for (auto VT : YamlMFI.Results)
147}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file defines the interfaces that WebAssembly uses to lower LLVM code into a selection DAG.
This file declares WebAssembly-specific per-machine-function information.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file contains the declaration of the WebAssembly-specific type parsing utility functions.
This file contains the declaration of the WebAssembly-specific utility functions.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
unsigned getPointerSizeInBits(unsigned AS=0) const
The size in bits of the pointer representation in a given address space.
Definition DataLayout.h:501
Class to represent function types.
iterator_range< arg_iterator > args()
Definition Function.h:876
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition Function.h:272
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
Context object for machine code objects.
Definition MCContext.h:83
Machine Value Type.
static MVT getIntegerVT(unsigned BitWidth)
Ty * cloneInfo(const Ty &Old)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
MVT getRegisterType(LLVMContext &Context, EVT VT) const
Return the type of registers that this ValueType will eventually require.
virtual unsigned getNumRegisters(LLVMContext &Context, EVT VT, std::optional< MVT > RegisterVT=std::nullopt) const
Return the number of registers that this ValueType will eventually require.
Primary interface to the complete machine description for the target machine.
const DataLayout createDataLayout() const
Create a DataLayout.
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
WebAssemblyFunctionInfo(const Function &F, const TargetSubtargetInfo *STI)
const std::vector< MVT > & getResults() const
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
void initWARegs(MachineRegisterInfo &MRI)
void initializeBaseYamlFields(MachineFunction &MF, const yaml::WebAssemblyFunctionInfo &YamlMFI)
const std::vector< MVT > & getParams() const
@ Swift
Calling convention for Swift.
Definition CallingConv.h:69
@ SwiftTail
This follows the Swift calling convention in how arguments are passed but guarantees tail calls will ...
Definition CallingConv.h:87
wasm::ValType toValType(MVT Type)
static const unsigned UnusedReg
bool canLowerReturn(size_t ResultSize, const WebAssemblySubtarget *Subtarget)
Returns true if the function's return value(s) can be lowered directly, i.e., not indirectly via a po...
MVT parseMVT(StringRef Type)
This is an optimization pass for GlobalISel generic memory operations.
void computeSignatureVTs(const FunctionType *Ty, const Function *TargetFunc, const Function &ContextFunc, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
LLVM_ABI void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs=nullptr, SmallVectorImpl< TypeSize > *Offsets=nullptr, TypeSize StartingOffset=TypeSize::getZero())
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition Analysis.cpp:119
void valTypesFromMVTs(ArrayRef< MVT > In, SmallVectorImpl< wasm::ValType > &Out)
wasm::WasmSignature * signatureFromMVTs(MCContext &Ctx, const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
void computeLegalValueVTs(const WebAssemblyTargetLowering &TLI, LLVMContext &Ctx, const DataLayout &DL, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
Extended Value Type.
Definition ValueTypes.h:35
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63