LLVM 23.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 // Function properties.
64 bool CFGStackified = false;
65
66public:
68 const TargetSubtargetInfo *STI) {}
70
74 const override;
75
77 const yaml::WebAssemblyFunctionInfo &YamlMFI);
78
79 void addParam(MVT VT) { Params.push_back(VT); }
80 const std::vector<MVT> &getParams() const { return Params; }
81
82 void addResult(MVT VT) { Results.push_back(VT); }
83 const std::vector<MVT> &getResults() const { return Results; }
84
86 Params.clear();
87 Results.clear();
88 }
89
90 void setNumLocals(size_t NumLocals) { Locals.resize(NumLocals, MVT::i32); }
91 void setLocal(size_t i, MVT VT) { Locals[i] = VT; }
92 void addLocal(MVT VT) { Locals.push_back(VT); }
93 const std::vector<MVT> &getLocals() const { return Locals; }
94
95 unsigned getVarargBufferVreg() const {
96 assert(VarargVreg != -1U && "Vararg vreg hasn't been set");
97 return VarargVreg;
98 }
99 void setVarargBufferVreg(unsigned Reg) { VarargVreg = Reg; }
100
101 unsigned getBasePointerVreg() const {
102 assert(BasePtrVreg != -1U && "Base ptr vreg hasn't been set");
103 return BasePtrVreg;
104 }
105 void setFrameBaseVreg(unsigned Reg) { FrameBaseVreg = Reg; }
106 unsigned getFrameBaseVreg() const {
107 assert(FrameBaseVreg != -1U && "Frame base vreg hasn't been set");
108 return FrameBaseVreg;
109 }
110 void clearFrameBaseVreg() { FrameBaseVreg = -1U; }
111 // Return true if the frame base physreg has been replaced by a virtual reg.
112 bool isFrameBaseVirtual() const { return FrameBaseVreg != -1U; }
113 void setFrameBaseLocal(unsigned Local) { FrameBaseLocal = Local; }
114 unsigned getFrameBaseLocal() const {
115 assert(FrameBaseLocal != -1U && "Frame base local hasn't been set");
116 return FrameBaseLocal;
117 }
118 void setBasePointerVreg(unsigned Reg) { BasePtrVreg = Reg; }
119
121 assert(MRI.getUniqueVRegDef(VReg));
122 auto I = VReg.virtRegIndex();
123 if (I >= VRegStackified.size())
124 VRegStackified.resize(I + 1);
125 VRegStackified.set(I);
126 }
128 auto I = VReg.virtRegIndex();
129 if (I < VRegStackified.size())
130 VRegStackified.reset(I);
131 }
132 bool isVRegStackified(Register VReg) const {
133 auto I = VReg.virtRegIndex();
134 if (I >= VRegStackified.size())
135 return false;
136 return VRegStackified.test(I);
137 }
138
140 void setWAReg(Register VReg, unsigned WAReg) {
142 auto I = VReg.virtRegIndex();
143 assert(I < WARegs.size());
144 WARegs[I] = WAReg;
145 }
146 unsigned getWAReg(Register VReg) const {
147 auto I = VReg.virtRegIndex();
148 assert(I < WARegs.size());
149 return WARegs[I];
150 }
151
152 bool isCFGStackified() const { return CFGStackified; }
153 void setCFGStackified(bool Value = true) { CFGStackified = Value; }
154};
155
156void computeLegalValueVTs(const WebAssemblyTargetLowering &TLI,
157 LLVMContext &Ctx, const DataLayout &DL, Type *Ty,
158 SmallVectorImpl<MVT> &ValueVTs);
159
160void computeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty,
161 SmallVectorImpl<MVT> &ValueVTs);
162
163// Compute the signature for a given FunctionType (Ty). Note that it's not the
164// signature for ContextFunc (ContextFunc is just used to get varous context)
165void computeSignatureVTs(const FunctionType *Ty, const Function *TargetFunc,
166 const Function &ContextFunc, const TargetMachine &TM,
167 SmallVectorImpl<MVT> &Params,
168 SmallVectorImpl<MVT> &Results);
169
170void valTypesFromMVTs(ArrayRef<MVT> In, SmallVectorImpl<wasm::ValType> &Out);
171
172wasm::WasmSignature *signatureFromMVTs(MCContext &Ctx,
173 const SmallVectorImpl<MVT> &Results,
174 const SmallVectorImpl<MVT> &Params);
175
176namespace yaml {
177
179
181 std::vector<FlowStringValue> Params;
182 std::vector<FlowStringValue> Results;
183 bool CFGStackified = false;
184
188
189 void mappingImpl(yaml::IO &YamlIO) override;
190 ~WebAssemblyFunctionInfo() override = default;
191};
192
194 static void mapping(IO &YamlIO, WebAssemblyFunctionInfo &MFI) {
195 YamlIO.mapOptional("params", MFI.Params, std::vector<FlowStringValue>());
196 YamlIO.mapOptional("results", MFI.Results, std::vector<FlowStringValue>());
197 YamlIO.mapOptional("isCFGStackified", MFI.CFGStackified, false);
198 }
199};
200
201} // end namespace yaml
202
203} // end namespace llvm
204
205#endif
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
Basic Register Allocator
This file provides WebAssembly-specific target descriptions.
Machine Value Type.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
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)
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:383
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