Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.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
15#include "WebAssemblyMachineFunctionInfo.h"
16#include "Utils/WebAssemblyTypeUtilities.h"
17#include "WebAssemblyISelLowering.h"
18#include "WebAssemblySubtarget.h"
19#include "WebAssemblyUtilities.h"
20#include "llvm/CodeGen/Analysis.h"
21#include "llvm/CodeGen/WasmEHFuncInfo.h"
22#include "llvm/Target/TargetMachine.h"
23using namespacellvm;
24
25WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() =default;// anchor.
26
27MachineFunctionInfo *WebAssemblyFunctionInfo::clone(
28BumpPtrAllocator &Allocator,MachineFunction &DestMF,
29constDenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
30 const{
31// TODO: Implement cloning for WasmEHFuncInfo. This will have invalid block
32// references.
33return DestMF.cloneInfo<WebAssemblyFunctionInfo>(*this);
34}
35
36voidWebAssemblyFunctionInfo::initWARegs(MachineRegisterInfo &MRI) {
37assert(WARegs.empty());
38unsigned Reg =WebAssembly::UnusedReg;
39 WARegs.resize(MRI.getNumVirtRegs(), Reg);
40}
41
42voidllvm::computeLegalValueVTs(constWebAssemblyTargetLowering &TLI,
43LLVMContext &Ctx,constDataLayout &DL,
44Type *Ty,SmallVectorImpl<MVT> &ValueVTs) {
45SmallVector<EVT, 4> VTs;
46ComputeValueVTs(TLI,DL, Ty, VTs);
47
48for (EVT VT : VTs) {
49unsigned NumRegs = TLI.getNumRegisters(Ctx, VT);
50MVT RegisterVT = TLI.getRegisterType(Ctx, VT);
51for (unsignedI = 0;I != NumRegs; ++I)
52 ValueVTs.push_back(RegisterVT);
53 }
54}
55
56voidllvm::computeLegalValueVTs(constFunction &F,constTargetMachine &TM,
57Type *Ty,SmallVectorImpl<MVT> &ValueVTs) {
58constDataLayout &DL(F.getDataLayout());
59constWebAssemblyTargetLowering &TLI =
60 *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
61computeLegalValueVTs(TLI,F.getContext(),DL, Ty, ValueVTs);
62}
63
64voidllvm::computeSignatureVTs(constFunctionType *Ty,
65constFunction *TargetFunc,
66constFunction &ContextFunc,
67constTargetMachine &TM,
68SmallVectorImpl<MVT> &Params,
69SmallVectorImpl<MVT> &Results) {
70computeLegalValueVTs(ContextFunc, TM, Ty->getReturnType(),Results);
71
72MVT PtrVT =MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits());
73if (!WebAssembly::canLowerReturn(
74Results.size(),
75 &TM.getSubtarget<WebAssemblySubtarget>(ContextFunc))) {
76// WebAssembly can't lower returns of multiple values without demoting to
77// sret unless multivalue is enabled (see
78// WebAssemblyTargetLowering::CanLowerReturn). So replace multiple return
79// values with a poitner parameter.
80Results.clear();
81 Params.push_back(PtrVT);
82 }
83
84for (auto *Param : Ty->params())
85computeLegalValueVTs(ContextFunc, TM, Param, Params);
86if (Ty->isVarArg())
87 Params.push_back(PtrVT);
88
89// For swiftcc, emit additional swiftself and swifterror parameters
90// if there aren't. These additional parameters are also passed for caller.
91// They are necessary to match callee and caller signature for indirect
92// call.
93
94if (TargetFunc && TargetFunc->getCallingConv() ==CallingConv::Swift) {
95MVT PtrVT =MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits());
96bool HasSwiftErrorArg =false;
97bool HasSwiftSelfArg =false;
98for (constauto &Arg : TargetFunc->args()) {
99 HasSwiftErrorArg |= Arg.hasAttribute(Attribute::SwiftError);
100 HasSwiftSelfArg |= Arg.hasAttribute(Attribute::SwiftSelf);
101 }
102if (!HasSwiftErrorArg)
103 Params.push_back(PtrVT);
104if (!HasSwiftSelfArg)
105 Params.push_back(PtrVT);
106 }
107}
108
109voidllvm::valTypesFromMVTs(ArrayRef<MVT> In,
110SmallVectorImpl<wasm::ValType> &Out) {
111for (MVT Ty : In)
112 Out.push_back(WebAssembly::toValType(Ty));
113}
114
115wasm::WasmSignature *
116llvm::signatureFromMVTs(MCContext &Ctx,constSmallVectorImpl<MVT> &Results,
117constSmallVectorImpl<MVT> &Params) {
118auto Sig = Ctx.createWasmSignature();
119valTypesFromMVTs(Results, Sig->Returns);
120valTypesFromMVTs(Params, Sig->Params);
121return Sig;
122}
123
124yaml::WebAssemblyFunctionInfo::WebAssemblyFunctionInfo(
125constllvm::MachineFunction &MF,constllvm::WebAssemblyFunctionInfo &MFI)
126 : CFGStackified(MFI.isCFGStackified()) {
127for (auto VT : MFI.getParams())
128Params.push_back(EVT(VT).getEVTString());
129for (auto VT : MFI.getResults())
130Results.push_back(EVT(VT).getEVTString());
131
132// MFI.getWasmEHFuncInfo() is non-null only for functions with the
133// personality function.
134
135if (auto *EHInfo = MF.getWasmEHFuncInfo()) {
136// SrcToUnwindDest can contain stale mappings in case BBs are removed in
137// optimizations, in case, for example, they are unreachable. We should not
138// include their info.
139SmallPtrSet<const MachineBasicBlock *, 16> MBBs;
140for (constauto &MBB : MF)
141 MBBs.insert(&MBB);
142for (auto KV : EHInfo->SrcToUnwindDest) {
143auto *SrcBB = cast<MachineBasicBlock *>(KV.first);
144auto *DestBB = cast<MachineBasicBlock *>(KV.second);
145if (MBBs.count(SrcBB) && MBBs.count(DestBB))
146SrcToUnwindDest[SrcBB->getNumber()] = DestBB->getNumber();
147 }
148 }
149}
150
151voidyaml::WebAssemblyFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
152MappingTraits<WebAssemblyFunctionInfo>::mapping(YamlIO, *this);
153}
154
155voidWebAssemblyFunctionInfo::initializeBaseYamlFields(
156MachineFunction &MF,constyaml::WebAssemblyFunctionInfo &YamlMFI) {
157CFGStackified = YamlMFI.CFGStackified;
158for (auto VT : YamlMFI.Params)
159 addParam(WebAssembly::parseMVT(VT.Value));
160for (auto VT : YamlMFI.Results)
161 addResult(WebAssembly::parseMVT(VT.Value));
162
163// FIXME: WasmEHInfo is defined in the MachineFunction, but serialized
164// here. Either WasmEHInfo should be moved out of MachineFunction, or the
165// serialization handling should be moved to MachineFunction.
166if (WasmEHFuncInfo *WasmEHInfo = MF.getWasmEHFuncInfo()) {
167for (auto KV : YamlMFI.SrcToUnwindDest)
168 WasmEHInfo->setUnwindDest(MF.getBlockNumbered(KV.first),
169 MF.getBlockNumbered(KV.second));
170 }
171}
MRI
unsigned const MachineRegisterInfo * MRI
Definition:AArch64AdvSIMDScalarPass.cpp:105
MBB
MachineBasicBlock & MBB
Definition:ARMSLSHardening.cpp:71
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition:ARMSLSHardening.cpp:73
Results
Function Alias Analysis Results
Definition:AliasAnalysis.cpp:731
YamlIO
IO & YamlIO
Definition:ELFYAML.cpp:1314
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
WasmEHFuncInfo.h
WebAssemblyISelLowering.h
This file defines the interfaces that WebAssembly uses to lower LLVM code into a selection DAG.
WebAssemblyMachineFunctionInfo.h
This file declares WebAssembly-specific per-machine-function information.
WebAssemblySubtarget.h
This file declares the WebAssembly-specific subclass of TargetSubtarget.
WebAssemblyTypeUtilities.h
This file contains the declaration of the WebAssembly-specific type parsing utility functions.
WebAssemblyUtilities.h
This file contains the declaration of the WebAssembly-specific utility functions.
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition:Allocator.h:66
llvm::DataLayout
A parsed version of the target data layout string in and methods for querying it.
Definition:DataLayout.h:63
llvm::DenseMap
Definition:DenseMap.h:727
llvm::FunctionType
Class to represent function types.
Definition:DerivedTypes.h:105
llvm::FunctionType::params
ArrayRef< Type * > params() const
Definition:DerivedTypes.h:132
llvm::FunctionType::isVarArg
bool isVarArg() const
Definition:DerivedTypes.h:125
llvm::FunctionType::getReturnType
Type * getReturnType() const
Definition:DerivedTypes.h:126
llvm::Function
Definition:Function.h:63
llvm::Function::args
iterator_range< arg_iterator > args()
Definition:Function.h:892
llvm::Function::getCallingConv
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
Definition:Function.h:277
llvm::Function::size
size_t size() const
Definition:Function.h:858
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition:LLVMContext.h:67
llvm::MCContext
Context object for machine code objects.
Definition:MCContext.h:83
llvm::MCContext::createWasmSignature
wasm::WasmSignature * createWasmSignature()
Allocates and returns a new WasmSignature instance (with empty parameter and return type lists).
Definition:MCContext.cpp:428
llvm::MVT
Machine Value Type.
Definition:MachineValueType.h:35
llvm::MVT::getIntegerVT
static MVT getIntegerVT(unsigned BitWidth)
Definition:MachineValueType.h:441
llvm::MachineFunction
Definition:MachineFunction.h:267
llvm::MachineFunction::getBlockNumbered
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
Definition:MachineFunction.h:866
llvm::MachineFunction::getWasmEHFuncInfo
const WasmEHFuncInfo * getWasmEHFuncInfo() const
getWasmEHFuncInfo - Return information about how the current function uses Wasm exception handling.
Definition:MachineFunction.h:771
llvm::MachineFunction::cloneInfo
Ty * cloneInfo(const Ty &Old)
Definition:MachineFunction.h:840
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition:MachineRegisterInfo.h:51
llvm::SmallPtrSetImpl::count
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Definition:SmallPtrSet.h:452
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition:SmallPtrSet.h:384
llvm::SmallPtrSet
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition:SmallPtrSet.h:519
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition:SmallVector.h:573
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::TargetLoweringBase::getNumRegisters
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.
Definition:TargetLowering.h:1763
llvm::TargetLoweringBase::getRegisterType
MVT getRegisterType(MVT VT) const
Return the type of registers that this ValueType will eventually require.
Definition:TargetLowering.h:1728
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition:TargetMachine.h:77
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::WebAssemblyFunctionInfo
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
Definition:WebAssemblyMachineFunctionInfo.h:34
llvm::WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo
~WebAssemblyFunctionInfo() override
llvm::WebAssemblyFunctionInfo::getResults
const std::vector< MVT > & getResults() const
Definition:WebAssemblyMachineFunctionInfo.h:85
llvm::WebAssemblyFunctionInfo::clone
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
Definition:WebAssemblyMachineFunctionInfo.cpp:27
llvm::WebAssemblyFunctionInfo::initWARegs
void initWARegs(MachineRegisterInfo &MRI)
Definition:WebAssemblyMachineFunctionInfo.cpp:36
llvm::WebAssemblyFunctionInfo::initializeBaseYamlFields
void initializeBaseYamlFields(MachineFunction &MF, const yaml::WebAssemblyFunctionInfo &YamlMFI)
Definition:WebAssemblyMachineFunctionInfo.cpp:155
llvm::WebAssemblyFunctionInfo::getParams
const std::vector< MVT > & getParams() const
Definition:WebAssemblyMachineFunctionInfo.h:82
llvm::WebAssemblySubtarget
Definition:WebAssemblySubtarget.h:35
llvm::WebAssemblyTargetLowering
Definition:WebAssemblyISelLowering.h:35
Analysis.h
TargetMachine.h
llvm::CallingConv::Swift
@ Swift
Calling convention for Swift.
Definition:CallingConv.h:69
llvm::WebAssembly::toValType
wasm::ValType toValType(MVT Type)
Definition:WebAssemblyTypeUtilities.cpp:40
llvm::WebAssembly::UnusedReg
static const unsigned UnusedReg
Definition:WebAssemblyMCTargetDesc.h:615
llvm::WebAssembly::canLowerReturn
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...
Definition:WebAssemblyUtilities.cpp:194
llvm::WebAssembly::parseMVT
MVT parseMVT(StringRef Type)
Definition:WebAssemblyTypeUtilities.cpp:23
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::computeSignatureVTs
void computeSignatureVTs(const FunctionType *Ty, const Function *TargetFunc, const Function &ContextFunc, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
Definition:WebAssemblyMachineFunctionInfo.cpp:64
llvm::ComputeValueVTs
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< EVT > *MemVTs, 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:79
llvm::valTypesFromMVTs
void valTypesFromMVTs(ArrayRef< MVT > In, SmallVectorImpl< wasm::ValType > &Out)
Definition:WebAssemblyMachineFunctionInfo.cpp:109
llvm::signatureFromMVTs
wasm::WasmSignature * signatureFromMVTs(MCContext &Ctx, const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
Definition:WebAssemblyMachineFunctionInfo.cpp:116
llvm::computeLegalValueVTs
void computeLegalValueVTs(const WebAssemblyTargetLowering &TLI, LLVMContext &Ctx, const DataLayout &DL, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)
Definition:WebAssemblyMachineFunctionInfo.cpp:42
llvm::EVT
Extended Value Type.
Definition:ValueTypes.h:35
llvm::MachineFunctionInfo
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Definition:MachineFunction.h:104
llvm::WasmEHFuncInfo
Definition:WasmEHFuncInfo.h:32
llvm::wasm::WasmSignature
Definition:Wasm.h:498
llvm::yaml::MappingTraits
Definition:ModuleSummaryIndex.h:54
llvm::yaml::WebAssemblyFunctionInfo
Definition:WebAssemblyMachineFunctionInfo.h:182
llvm::yaml::WebAssemblyFunctionInfo::WebAssemblyFunctionInfo
WebAssemblyFunctionInfo()=default
llvm::yaml::WebAssemblyFunctionInfo::CFGStackified
bool CFGStackified
Definition:WebAssemblyMachineFunctionInfo.h:185
llvm::yaml::WebAssemblyFunctionInfo::mappingImpl
void mappingImpl(yaml::IO &YamlIO) override
Definition:WebAssemblyMachineFunctionInfo.cpp:151
llvm::yaml::WebAssemblyFunctionInfo::Results
std::vector< FlowStringValue > Results
Definition:WebAssemblyMachineFunctionInfo.h:184
llvm::yaml::WebAssemblyFunctionInfo::Params
std::vector< FlowStringValue > Params
Definition:WebAssemblyMachineFunctionInfo.h:183
llvm::yaml::WebAssemblyFunctionInfo::SrcToUnwindDest
BBNumberMap SrcToUnwindDest
Definition:WebAssemblyMachineFunctionInfo.h:188

Generated on Fri Jul 18 2025 14:45:43 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp