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
21#include "llvm/IR/Module.h"
23using namespace llvm;
24
26
33
35 assert(WARegs.empty());
36 unsigned Reg = WebAssembly::UnusedReg;
37 WARegs.resize(MRI.getNumVirtRegs(), Reg);
38}
39
41 LLVMContext &Ctx, const DataLayout &DL,
42 Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
44 ComputeValueVTs(TLI, DL, Ty, VTs);
45
46 for (EVT VT : VTs) {
47 unsigned NumRegs = TLI.getNumRegisters(Ctx, VT);
48 MVT RegisterVT = TLI.getRegisterType(Ctx, VT);
49 for (unsigned I = 0; I != NumRegs; ++I)
50 ValueVTs.push_back(RegisterVT);
51 }
52}
53
55 Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
56 const DataLayout &DL(F.getDataLayout());
57 const WebAssemblyTargetLowering &TLI =
58 *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
59 computeLegalValueVTs(TLI, F.getContext(), DL, Ty, ValueVTs);
60}
61
63 const Function *TargetFunc,
64 const Function &ContextFunc,
65 const TargetMachine &TM,
68 computeLegalValueVTs(ContextFunc, TM, Ty->getReturnType(), Results);
69
70 const DataLayout &DL = ContextFunc.getParent()->getDataLayout();
71 MVT PtrVT = MVT::getIntegerVT(DL.getPointerSizeInBits());
73 Results.size(),
74 &TM.getSubtarget<WebAssemblySubtarget>(ContextFunc))) {
75 // WebAssembly can't lower returns of multiple values without demoting to
76 // sret unless multivalue is enabled (see
77 // WebAssemblyTargetLowering::CanLowerReturn). So replace multiple return
78 // values with a pointer parameter.
79 Results.clear();
80 Params.push_back(PtrVT);
81 }
82
83 for (auto *Param : Ty->params())
84 computeLegalValueVTs(ContextFunc, TM, Param, Params);
85 if (Ty->isVarArg())
86 Params.push_back(PtrVT);
87
88 // For swiftcc and swifttailcc, emit additional swiftself, swifterror, and
89 // (for swifttailcc) swiftasync parameters if there aren't. These additional
90 // parameters are also passed for caller. They are necessary to match callee
91 // and caller signature for indirect call.
92
93 if (TargetFunc && (TargetFunc->getCallingConv() == CallingConv::Swift ||
94 TargetFunc->getCallingConv() == CallingConv::SwiftTail)) {
95 MVT PtrVT = MVT::getIntegerVT(DL.getPointerSizeInBits());
96 bool HasSwiftErrorArg = false;
97 bool HasSwiftSelfArg = false;
98 bool HasSwiftAsyncArg = false;
99 for (const auto &Arg : TargetFunc->args()) {
100 HasSwiftErrorArg |= Arg.hasAttribute(Attribute::SwiftError);
101 HasSwiftSelfArg |= Arg.hasAttribute(Attribute::SwiftSelf);
102 HasSwiftAsyncArg |= Arg.hasAttribute(Attribute::SwiftAsync);
103 }
104 if (!HasSwiftSelfArg)
105 Params.push_back(PtrVT);
106 if (!HasSwiftErrorArg)
107 Params.push_back(PtrVT);
108 if (TargetFunc->getCallingConv() == CallingConv::SwiftTail &&
109 !HasSwiftAsyncArg)
110 Params.push_back(PtrVT);
111 }
112}
113
116 for (MVT Ty : In)
117 Out.push_back(WebAssembly::toValType(Ty));
118}
119
122 const SmallVectorImpl<MVT> &Params) {
123 auto Sig = Ctx.createWasmSignature();
124 valTypesFromMVTs(Results, Sig->Returns);
125 valTypesFromMVTs(Params, Sig->Params);
126 return Sig;
127}
128
131 : CFGStackified(MFI.isCFGStackified()) {
132 for (auto VT : MFI.getParams())
133 Params.push_back(EVT(VT).getEVTString());
134 for (auto VT : MFI.getResults())
135 Results.push_back(EVT(VT).getEVTString());
136}
137
141
144 CFGStackified = YamlMFI.CFGStackified;
145 for (auto VT : YamlMFI.Params)
147 for (auto VT : YamlMFI.Results)
149}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis Results
Module.h This file contains the declarations for the Module class.
#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
Class to represent function types.
iterator_range< arg_iterator > args()
Definition Function.h:877
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition Function.h:273
Module * getParent()
Get the module that this global value is contained inside of...
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.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition Module.h:325
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 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