LLVM  9.0.0svn
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 //===----------------------------------------------------------------------===//
17 #include "WebAssemblySubtarget.h"
18 #include "llvm/CodeGen/Analysis.h"
19 using namespace llvm;
24  assert(WARegs.empty());
25  unsigned Reg = UnusedReg;
26  WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg);
27 }
30  Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
31  const DataLayout &DL(F.getParent()->getDataLayout());
32  const WebAssemblyTargetLowering &TLI =
33  *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
35  ComputeValueVTs(TLI, DL, Ty, VTs);
37  for (EVT VT : VTs) {
38  unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT);
39  MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT);
40  for (unsigned I = 0; I != NumRegs; ++I)
41  ValueVTs.push_back(RegisterVT);
42  }
43 }
46  const TargetMachine &TM,
47  SmallVectorImpl<MVT> &Params,
48  SmallVectorImpl<MVT> &Results) {
49  computeLegalValueVTs(F, TM, Ty->getReturnType(), Results);
52  if (Results.size() > 1) {
53  // WebAssembly currently can't lower returns of multiple values without
54  // demoting to sret (see WebAssemblyTargetLowering::CanLowerReturn). So
55  // replace multiple return values with a pointer parameter.
56  Results.clear();
57  Params.push_back(PtrVT);
58  }
60  for (auto *Param : Ty->params())
61  computeLegalValueVTs(F, TM, Param, Params);
62  if (Ty->isVarArg())
63  Params.push_back(PtrVT);
64 }
68  for (MVT Ty : In)
70 }
72 std::unique_ptr<wasm::WasmSignature>
74  const SmallVectorImpl<MVT> &Params) {
75  auto Sig = make_unique<wasm::WasmSignature>();
76  valTypesFromMVTs(Results, Sig->Returns);
77  valTypesFromMVTs(Params, Sig->Params);
78  return Sig;
79 }
static MVT getIntegerVT(unsigned BitWidth)
This file defines the interfaces that WebAssembly uses to lower LLVM code into a selection DAG...
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:110
This class represents lattice values for constants.
Definition: AllocatorList.h:23
unsigned Reg
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
Definition: DataLayout.h:362
const DataLayout createDataLayout() const
Create a DataLayout.
void computeSignatureVTs(const FunctionType *Ty, const Function &F, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
std::unique_ptr< wasm::WasmSignature > signatureFromMVTs(const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:369
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
Class to represent function types.
Definition: DerivedTypes.h:102
bool isVarArg() const
Definition: DerivedTypes.h:122
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
Definition: Analysis.cpp:83
wasm::ValType toValType(const MVT &Ty)
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:129
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Definition: Function.cpp:192
Extended Value Type.
Definition: ValueTypes.h:33
size_t size() const
Definition: SmallVector.h:52
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:839
Type * getReturnType() const
Definition: DerivedTypes.h:123
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
#define I(x, y, z)
Definition: MD5.cpp:58
This file declares WebAssembly-specific per-machine-function information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void valTypesFromMVTs(const ArrayRef< MVT > &In, SmallVectorImpl< wasm::ValType > &Out)
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:565
void computeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:58
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.