LCOV - code coverage report
Current view: top level - lib/Target/WebAssembly - WebAssemblyMachineFunctionInfo.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 31 31 100.0 %
Date: 2018-10-20 13:21:21 Functions: 5 6 83.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      16             : #include "WebAssemblyMachineFunctionInfo.h"
      17             : #include "WebAssemblyISelLowering.h"
      18             : #include "WebAssemblySubtarget.h"
      19             : #include "llvm/CodeGen/Analysis.h"
      20             : using namespace llvm;
      21             : 
      22        5976 : WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() {}
      23             : 
      24        2982 : void WebAssemblyFunctionInfo::initWARegs() {
      25             :   assert(WARegs.empty());
      26        2982 :   unsigned Reg = UnusedReg;
      27        5964 :   WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg);
      28        2982 : }
      29             : 
      30       14402 : void llvm::ComputeLegalValueVTs(const Function &F, const TargetMachine &TM,
      31             :                                 Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
      32       14402 :   const DataLayout &DL(F.getParent()->getDataLayout());
      33             :   const WebAssemblyTargetLowering &TLI =
      34             :       *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
      35             :   SmallVector<EVT, 4> VTs;
      36       14402 :   ComputeValueVTs(TLI, DL, Ty, VTs);
      37             : 
      38       27265 :   for (EVT VT : VTs) {
      39       12863 :     unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT);
      40       12863 :     MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT);
      41       34898 :     for (unsigned i = 0; i != NumRegs; ++i)
      42       22035 :       ValueVTs.push_back(RegisterVT);
      43             :   }
      44       14402 : }
      45             : 
      46        6349 : void llvm::ComputeSignatureVTs(const FunctionType *Ty, const Function &F,
      47             :                                const TargetMachine &TM,
      48             :                                SmallVectorImpl<MVT> &Params,
      49             :                                SmallVectorImpl<MVT> &Results) {
      50       12698 :   ComputeLegalValueVTs(F, TM, Ty->getReturnType(), Results);
      51             : 
      52        6349 :   MVT PtrVT = MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits());
      53        6349 :   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        1005 :     Params.push_back(PtrVT);
      59             :   }
      60             : 
      61       14402 :   for (auto *Param : Ty->params())
      62        8053 :     ComputeLegalValueVTs(F, TM, Param, Params);
      63        6349 :   if (Ty->isVarArg())
      64          37 :     Params.push_back(PtrVT);
      65        6349 : }
      66             : 
      67             : std::unique_ptr<wasm::WasmSignature>
      68        3482 : llvm::SignatureFromMVTs(const SmallVectorImpl<MVT> &Results,
      69             :                         const SmallVectorImpl<MVT> &Params) {
      70        3482 :   auto Sig = make_unique<wasm::WasmSignature>();
      71        5591 :   for (MVT Ty : Results)
      72        2109 :     Sig->Returns.push_back(WebAssembly::toValType(Ty));
      73       11095 :   for (MVT Ty : Params)
      74        7613 :     Sig->Params.push_back(WebAssembly::toValType(Ty));
      75        3482 :   return Sig;
      76             : }

Generated by: LCOV version 1.13