LLVM  8.0.1
WebAssemblyMachineFunctionInfo.cpp
Go to the documentation of this file.
1 //=- WebAssemblyMachineFunctionInfo.cpp - WebAssembly Machine Function Info -=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// This file implements WebAssembly-specific per-machine-function
12 /// information.
13 ///
14 //===----------------------------------------------------------------------===//
15 
18 #include "WebAssemblySubtarget.h"
19 #include "llvm/CodeGen/Analysis.h"
20 using namespace llvm;
21 
23 
25  assert(WARegs.empty());
26  unsigned Reg = UnusedReg;
27  WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg);
28 }
29 
31  Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
32  const DataLayout &DL(F.getParent()->getDataLayout());
33  const WebAssemblyTargetLowering &TLI =
34  *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
36  ComputeValueVTs(TLI, DL, Ty, VTs);
37 
38  for (EVT VT : VTs) {
39  unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT);
40  MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT);
41  for (unsigned i = 0; i != NumRegs; ++i)
42  ValueVTs.push_back(RegisterVT);
43  }
44 }
45 
47  const TargetMachine &TM,
48  SmallVectorImpl<MVT> &Params,
49  SmallVectorImpl<MVT> &Results) {
50  ComputeLegalValueVTs(F, TM, Ty->getReturnType(), Results);
51 
53  if (Results.size() > 1) {
54  // WebAssembly currently can't lower returns of multiple values without
55  // demoting to sret (see WebAssemblyTargetLowering::CanLowerReturn). So
56  // replace multiple return values with a pointer parameter.
57  Results.clear();
58  Params.push_back(PtrVT);
59  }
60 
61  for (auto *Param : Ty->params())
62  ComputeLegalValueVTs(F, TM, Param, Params);
63  if (Ty->isVarArg())
64  Params.push_back(PtrVT);
65 }
66 
69  for (MVT Ty : In)
71 }
72 
73 std::unique_ptr<wasm::WasmSignature>
75  const SmallVectorImpl<MVT> &Params) {
76  auto Sig = make_unique<wasm::WasmSignature>();
77  ValTypesFromMVTs(Results, Sig->Returns);
78  ValTypesFromMVTs(Params, Sig->Params);
79  return Sig;
80 }
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:111
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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:363
F(f)
const DataLayout createDataLayout() const
Create a DataLayout.
const DataLayout & getDataLayout() const
Get the data layout for the module&#39;s target platform.
Definition: Module.cpp:371
void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty, SmallVectorImpl< MVT > &ValueVTs)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
Class to represent function types.
Definition: DerivedTypes.h:103
bool isVarArg() const
Definition: DerivedTypes.h:123
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
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:84
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:46
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:130
std::unique_ptr< wasm::WasmSignature > SignatureFromMVTs(const SmallVectorImpl< MVT > &Results, const SmallVectorImpl< MVT > &Params)
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:193
Extended Value Type.
Definition: ValueTypes.h:34
size_t size() const
Definition: SmallVector.h:53
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:847
Type * getReturnType() const
Definition: DerivedTypes.h:124
void ComputeSignatureVTs(const FunctionType *Ty, const Function &F, const TargetMachine &TM, SmallVectorImpl< MVT > &Params, SmallVectorImpl< MVT > &Results)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
void ValTypesFromMVTs(const ArrayRef< MVT > &In, SmallVectorImpl< wasm::ValType > &Out)
This file declares WebAssembly-specific per-machine-function information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:566
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:59
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.