Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- WebAssemblyMCTargetDesc.cpp - WebAssembly Target Descriptions -----===//
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 provides WebAssembly-specific target descriptions.
11
///
12
//===----------------------------------------------------------------------===//
13
14
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
15
#include "MCTargetDesc/WebAssemblyInstPrinter.h"
16
#include "MCTargetDesc/WebAssemblyMCAsmInfo.h"
17
#include "MCTargetDesc/WebAssemblyTargetStreamer.h"
18
#include "TargetInfo/WebAssemblyTargetInfo.h"
19
#include "llvm/MC/MCInstrInfo.h"
20
#include "llvm/MC/MCRegisterInfo.h"
21
#include "llvm/MC/MCSubtargetInfo.h"
22
#include "llvm/Support/ErrorHandling.h"
23
#include "llvm/Support/TargetRegistry.h"
24
using namespace llvm;
25
26
#define DEBUG_TYPE "wasm-mc-target-desc"
27
28
#define GET_INSTRINFO_MC_DESC
29
#include "WebAssemblyGenInstrInfo.inc"
30
31
#define GET_SUBTARGETINFO_MC_DESC
32
#include "WebAssemblyGenSubtargetInfo.inc"
33
34
#define GET_REGINFO_MC_DESC
35
#include "WebAssemblyGenRegisterInfo.inc"
36
37
static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
38
507
                                  const Triple &TT) {
39
507
  return new WebAssemblyMCAsmInfo(TT);
40
507
}
41
42
509
static MCInstrInfo *createMCInstrInfo() {
43
509
  auto *X = new MCInstrInfo();
44
509
  InitWebAssemblyMCInstrInfo(X);
45
509
  return X;
46
509
}
47
48
510
static MCRegisterInfo *createMCRegisterInfo(const Triple & /*T*/) {
49
510
  auto *X = new MCRegisterInfo();
50
510
  InitWebAssemblyMCRegisterInfo(X, 0);
51
510
  return X;
52
510
}
53
54
static MCInstPrinter *createMCInstPrinter(const Triple & /*T*/,
55
                                          unsigned SyntaxVariant,
56
                                          const MCAsmInfo &MAI,
57
                                          const MCInstrInfo &MII,
58
236
                                          const MCRegisterInfo &MRI) {
59
236
  assert(SyntaxVariant == 0 && "WebAssembly only has one syntax variant");
60
236
  return new WebAssemblyInstPrinter(MAI, MII, MRI);
61
236
}
62
63
static MCCodeEmitter *createCodeEmitter(const MCInstrInfo &MCII,
64
                                        const MCRegisterInfo & /*MRI*/,
65
213
                                        MCContext &Ctx) {
66
213
  return createWebAssemblyMCCodeEmitter(MCII);
67
213
}
68
69
static MCAsmBackend *createAsmBackend(const Target & /*T*/,
70
                                      const MCSubtargetInfo &STI,
71
                                      const MCRegisterInfo & /*MRI*/,
72
443
                                      const MCTargetOptions & /*Options*/) {
73
443
  return createWebAssemblyAsmBackend(STI.getTargetTriple());
74
443
}
75
76
static MCSubtargetInfo *createMCSubtargetInfo(const Triple &TT, StringRef CPU,
77
505
                                              StringRef FS) {
78
505
  return createWebAssemblyMCSubtargetInfoImpl(TT, CPU, FS);
79
505
}
80
81
static MCTargetStreamer *
82
209
createObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
83
209
  return new WebAssemblyTargetWasmStreamer(S);
84
209
}
85
86
static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
87
                                                 formatted_raw_ostream &OS,
88
                                                 MCInstPrinter * /*InstPrint*/,
89
234
                                                 bool /*isVerboseAsm*/) {
90
234
  return new WebAssemblyTargetAsmStreamer(S, OS);
91
234
}
92
93
1
static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
94
1
  return new WebAssemblyTargetNullStreamer(S);
95
1
}
96
97
// Force static initialization.
98
96.4k
extern "C" void LLVMInitializeWebAssemblyTargetMC() {
99
96.4k
  for (Target *T :
100
192k
       {&getTheWebAssemblyTarget32(), &getTheWebAssemblyTarget64()}) {
101
192k
    // Register the MC asm info.
102
192k
    RegisterMCAsmInfoFn X(*T, createMCAsmInfo);
103
192k
104
192k
    // Register the MC instruction info.
105
192k
    TargetRegistry::RegisterMCInstrInfo(*T, createMCInstrInfo);
106
192k
107
192k
    // Register the MC register info.
108
192k
    TargetRegistry::RegisterMCRegInfo(*T, createMCRegisterInfo);
109
192k
110
192k
    // Register the MCInstPrinter.
111
192k
    TargetRegistry::RegisterMCInstPrinter(*T, createMCInstPrinter);
112
192k
113
192k
    // Register the MC code emitter.
114
192k
    TargetRegistry::RegisterMCCodeEmitter(*T, createCodeEmitter);
115
192k
116
192k
    // Register the ASM Backend.
117
192k
    TargetRegistry::RegisterMCAsmBackend(*T, createAsmBackend);
118
192k
119
192k
    // Register the MC subtarget info.
120
192k
    TargetRegistry::RegisterMCSubtargetInfo(*T, createMCSubtargetInfo);
121
192k
122
192k
    // Register the object target streamer.
123
192k
    TargetRegistry::RegisterObjectTargetStreamer(*T,
124
192k
                                                 createObjectTargetStreamer);
125
192k
    // Register the asm target streamer.
126
192k
    TargetRegistry::RegisterAsmTargetStreamer(*T, createAsmTargetStreamer);
127
192k
    // Register the null target streamer.
128
192k
    TargetRegistry::RegisterNullTargetStreamer(*T, createNullTargetStreamer);
129
192k
  }
130
96.4k
}
131
132
16.0k
wasm::ValType WebAssembly::toValType(const MVT &Ty) {
133
16.0k
  switch (Ty.SimpleTy) {
134
16.0k
  case MVT::i32:
135
9.23k
    return wasm::ValType::I32;
136
16.0k
  case MVT::i64:
137
1.39k
    return wasm::ValType::I64;
138
16.0k
  case MVT::f32:
139
999
    return wasm::ValType::F32;
140
16.0k
  case MVT::f64:
141
918
    return wasm::ValType::F64;
142
16.0k
  case MVT::v16i8:
143
3.50k
  case MVT::v8i16:
144
3.50k
  case MVT::v4i32:
145
3.50k
  case MVT::v2i64:
146
3.50k
  case MVT::v4f32:
147
3.50k
  case MVT::v2f64:
148
3.50k
    return wasm::ValType::V128;
149
3.50k
  case MVT::exnref:
150
7
    return wasm::ValType::EXNREF;
151
3.50k
  default:
152
0
    llvm_unreachable("unexpected type");
153
16.0k
  }
154
16.0k
}