Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
Line
Count
Source
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 "WebAssemblyISelLowering.h"
17
#include "WebAssemblySubtarget.h"
18
#include "llvm/CodeGen/Analysis.h"
19
using namespace llvm;
20
21
4.47k
WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() = default; // anchor.
22
23
4.45k
void WebAssemblyFunctionInfo::initWARegs() {
24
4.45k
  assert(WARegs.empty());
25
4.45k
  unsigned Reg = UnusedReg;
26
4.45k
  WARegs.resize(MF.getRegInfo().getNumVirtRegs(), Reg);
27
4.45k
}
28
29
void llvm::computeLegalValueVTs(const Function &F, const TargetMachine &TM,
30
22.1k
                                Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
31
22.1k
  const DataLayout &DL(F.getParent()->getDataLayout());
32
22.1k
  const WebAssemblyTargetLowering &TLI =
33
22.1k
      *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
34
22.1k
  SmallVector<EVT, 4> VTs;
35
22.1k
  ComputeValueVTs(TLI, DL, Ty, VTs);
36
22.1k
37
22.1k
  for (EVT VT : VTs) {
38
20.0k
    unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT);
39
20.0k
    MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT);
40
54.0k
    for (unsigned I = 0; I != NumRegs; 
++I34.0k
)
41
34.0k
      ValueVTs.push_back(RegisterVT);
42
20.0k
  }
43
22.1k
}
44
45
void llvm::computeSignatureVTs(const FunctionType *Ty, const Function &F,
46
                               const TargetMachine &TM,
47
                               SmallVectorImpl<MVT> &Params,
48
9.50k
                               SmallVectorImpl<MVT> &Results) {
49
9.50k
  computeLegalValueVTs(F, TM, Ty->getReturnType(), Results);
50
9.50k
51
9.50k
  MVT PtrVT = MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits());
52
9.50k
  if (Results.size() > 1) {
53
1.51k
    // WebAssembly currently can't lower returns of multiple values without
54
1.51k
    // demoting to sret (see WebAssemblyTargetLowering::CanLowerReturn). So
55
1.51k
    // replace multiple return values with a pointer parameter.
56
1.51k
    Results.clear();
57
1.51k
    Params.push_back(PtrVT);
58
1.51k
  }
59
9.50k
60
9.50k
  for (auto *Param : Ty->params())
61
12.6k
    computeLegalValueVTs(F, TM, Param, Params);
62
9.50k
  if (Ty->isVarArg())
63
53
    Params.push_back(PtrVT);
64
9.50k
}
65
66
void llvm::valTypesFromMVTs(const ArrayRef<MVT> &In,
67
14.9k
                            SmallVectorImpl<wasm::ValType> &Out) {
68
14.9k
  for (MVT Ty : In)
69
16.0k
    Out.push_back(WebAssembly::toValType(Ty));
70
14.9k
}
71
72
std::unique_ptr<wasm::WasmSignature>
73
llvm::signatureFromMVTs(const SmallVectorImpl<MVT> &Results,
74
5.23k
                        const SmallVectorImpl<MVT> &Params) {
75
5.23k
  auto Sig = make_unique<wasm::WasmSignature>();
76
5.23k
  valTypesFromMVTs(Results, Sig->Returns);
77
5.23k
  valTypesFromMVTs(Params, Sig->Params);
78
5.23k
  return Sig;
79
5.23k
}
80
81
yaml::WebAssemblyFunctionInfo::WebAssemblyFunctionInfo(
82
    const llvm::WebAssemblyFunctionInfo &MFI)
83
20
    : CFGStackified(MFI.isCFGStackified()) {}
84
85
20
void yaml::WebAssemblyFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
86
20
  MappingTraits<WebAssemblyFunctionInfo>::mapping(YamlIO, *this);
87
20
}
88
89
void WebAssemblyFunctionInfo::initializeBaseYamlFields(
90
21
    const yaml::WebAssemblyFunctionInfo &YamlMFI) {
91
21
  CFGStackified = YamlMFI.CFGStackified;
92
21
}