LLVM 24.0.0git
WebAssemblyMachineFunctionInfo.h
Go to the documentation of this file.
1// WebAssemblyMachineFunctionInfo.h-WebAssembly machine function info-*- C++ -*-
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 declares WebAssembly-specific per-machine-function
11/// information.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
16#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
17
22
23namespace llvm {
25
26namespace yaml {
28}
29
30/// This class is derived from MachineFunctionInfo and contains private
31/// WebAssembly-specific information for each MachineFunction.
33 std::vector<MVT> Params;
34 std::vector<MVT> Results;
35 std::vector<MVT> Locals;
36
37 /// A mapping from CodeGen vreg index to WebAssembly register number.
38 std::vector<unsigned> WARegs;
39
40 /// A mapping from CodeGen vreg index to a boolean value indicating whether
41 /// the given register is considered to be "stackified", meaning it has been
42 /// determined or made to meet the stack requirements:
43 /// - single use (per path)
44 /// - single def (per path)
45 /// - defined and used in LIFO order with other stack registers
46 BitVector VRegStackified;
47
48 // A virtual register holding the pointer to the vararg buffer for vararg
49 // functions. It is created and set in TLI::LowerFormalArguments and read by
50 // TLI::LowerVASTART
51 unsigned VarargVreg = -1U;
52
53 // A virtual register holding the base pointer for functions that have
54 // overaligned values on the user stack.
55 unsigned BasePtrVreg = -1U;
56 // A virtual register holding the frame base. This is either FP or SP
57 // after it has been replaced by a vreg
58 unsigned FrameBaseVreg = -1U;
59 // The local holding the frame base. This is either FP or SP
60 // after WebAssemblyExplicitLocals
61 unsigned FrameBaseLocal = -1U;
62
63 // The stack object that llvm.swift.async.context.addr points to.
64 std::optional<int> SwiftAsyncContextFrameIdx;
65
66 // Function properties.
67 bool CFGStackified = false;
68
69public:
71 const TargetSubtargetInfo *STI) {}
73
77 const override;
78
80 const yaml::WebAssemblyFunctionInfo &YamlMFI);
81
82 void addParam(MVT VT) { Params.push_back(VT); }
83 const std::vector<MVT> &getParams() const { return Params; }
84
85 void addResult(MVT VT) { Results.push_back(VT); }
86 const std::vector<MVT> &getResults() const { return Results; }
87
89 Params.clear();
90 Results.clear();
91 }
92
93 void setNumLocals(size_t NumLocals) { Locals.resize(NumLocals, MVT::i32); }
94 void setLocal(size_t i, MVT VT) { Locals[i] = VT; }
95 void addLocal(MVT VT) { Locals.push_back(VT); }
96 const std::vector<MVT> &getLocals() const { return Locals; }
97
98 unsigned getVarargBufferVreg() const {
99 assert(VarargVreg != -1U && "Vararg vreg hasn't been set");
100 return VarargVreg;
101 }
102 void setVarargBufferVreg(unsigned Reg) { VarargVreg = Reg; }
103
104 unsigned getBasePointerVreg() const {
105 assert(BasePtrVreg != -1U && "Base ptr vreg hasn't been set");
106 return BasePtrVreg;
107 }
108 void setFrameBaseVreg(unsigned Reg) { FrameBaseVreg = Reg; }
109 unsigned getFrameBaseVreg() const {
110 assert(FrameBaseVreg != -1U && "Frame base vreg hasn't been set");
111 return FrameBaseVreg;
112 }
113 void clearFrameBaseVreg() { FrameBaseVreg = -1U; }
114 // Return true if the frame base physreg has been replaced by a virtual reg.
115 bool isFrameBaseVirtual() const { return FrameBaseVreg != -1U; }
116 void setFrameBaseLocal(unsigned Local) { FrameBaseLocal = Local; }
117 unsigned getFrameBaseLocal() const {
118 assert(FrameBaseLocal != -1U && "Frame base local hasn't been set");
119 return FrameBaseLocal;
120 }
121 void setBasePointerVreg(unsigned Reg) { BasePtrVreg = Reg; }
122
123 std::optional<int> getSwiftAsyncContextFrameIdx() const {
124 return SwiftAsyncContextFrameIdx;
125 }
126 void setSwiftAsyncContextFrameIdx(int FI) { SwiftAsyncContextFrameIdx = FI; }
127
129 assert(MRI.getUniqueVRegDef(VReg));
130 auto I = VReg.virtRegIndex();
131 if (I >= VRegStackified.size())
132 VRegStackified.resize(I + 1);
133 VRegStackified.set(I);
134 }
136 auto I = VReg.virtRegIndex();
137 if (I < VRegStackified.size())
138 VRegStackified.reset(I);
139 }
140 bool isVRegStackified(Register VReg) const {
141 auto I = VReg.virtRegIndex();
142 if (I >= VRegStackified.size())
143 return false;
144 return VRegStackified.test(I);
145 }
146
148 void setWAReg(Register VReg, unsigned WAReg) {
150 auto I = VReg.virtRegIndex();
151 assert(I < WARegs.size());
152 WARegs[I] = WAReg;
153 }
154 unsigned getWAReg(Register VReg) const {
155 auto I = VReg.virtRegIndex();
156 assert(I < WARegs.size());
157 return WARegs[I];
158 }
159
160 bool isCFGStackified() const { return CFGStackified; }
161 void setCFGStackified(bool Value = true) { CFGStackified = Value; }
162};
163
164void computeLegalValueVTs(const WebAssemblyTargetLowering &TLI,
165 LLVMContext &Ctx, const DataLayout &DL, Type *Ty,
166 SmallVectorImpl<MVT> &ValueVTs);
167
168void computeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty,
169 SmallVectorImpl<MVT> &ValueVTs);
170
171// Compute the signature for a given FunctionType (Ty). Note that it's not the
172// signature for ContextFunc (ContextFunc is just used to get various context)
173void computeSignatureVTs(const FunctionType *Ty, const Function *TargetFunc,
174 const Function &ContextFunc, const TargetMachine &TM,
175 SmallVectorImpl<MVT> &Params,
176 SmallVectorImpl<MVT> &Results);
177
178void valTypesFromMVTs(ArrayRef<MVT> In, SmallVectorImpl<wasm::ValType> &Out);
179
180wasm::WasmSignature *signatureFromMVTs(MCContext &Ctx,
181 const SmallVectorImpl<MVT> &Results,
182 const SmallVectorImpl<MVT> &Params);
183
184namespace yaml {
185
187
189 std::vector<FlowStringValue> Params;
190 std::vector<FlowStringValue> Results;
191 bool CFGStackified = false;
192
196
197 void mappingImpl(yaml::IO &YamlIO) override;
198 ~WebAssemblyFunctionInfo() override = default;
199};
200
202 static void mapping(IO &YamlIO, WebAssemblyFunctionInfo &MFI) {
203 YamlIO.mapOptional("params", MFI.Params, std::vector<FlowStringValue>());
204 YamlIO.mapOptional("results", MFI.Results, std::vector<FlowStringValue>());
205 YamlIO.mapOptional("isCFGStackified", MFI.CFGStackified, false);
206 }
207};
208
209} // end namespace yaml
210
211} // end namespace llvm
212
213#endif
const TargetLowering & TLI
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
Register Reg
MachineRegisterInfo & MRI
Basic Register Allocator
This file provides WebAssembly-specific target descriptions.
Machine Value Type.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Wrapper class representing virtual and physical registers.
Definition Register.h:20
unsigned virtRegIndex() const
Convert a virtual register number to a 0-based index.
Definition Register.h:87
TargetSubtargetInfo - Generic base class for all target subtargets.
LLVM Value Representation.
Definition Value.h:75
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
void stackifyVReg(MachineRegisterInfo &MRI, Register VReg)
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)
std::optional< int > getSwiftAsyncContextFrameIdx() const
const std::vector< MVT > & getLocals() const
void setWAReg(Register VReg, unsigned WAReg)
void initializeBaseYamlFields(MachineFunction &MF, const yaml::WebAssemblyFunctionInfo &YamlMFI)
const std::vector< MVT > & getParams() const
void mapOptional(StringRef Key, T &Val)
Definition YAMLTraits.h:800
static const unsigned UnusedReg
DenseMap< int, int > BBNumberMap
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)
ArrayRef(const T &OneElt) -> ArrayRef< T >
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:391
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
static void mapping(IO &YamlIO, WebAssemblyFunctionInfo &MFI)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63
~WebAssemblyFunctionInfo() override=default