Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Lanai/MCTargetDesc/LanaiMCTargetDesc.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- LanaiMCTargetDesc.cpp - Lanai 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
// This file provides Lanai specific target descriptions.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "LanaiMCTargetDesc.h"
14
#include "LanaiInstPrinter.h"
15
#include "LanaiMCAsmInfo.h"
16
#include "TargetInfo/LanaiTargetInfo.h"
17
#include "llvm/ADT/StringRef.h"
18
#include "llvm/ADT/Triple.h"
19
#include "llvm/MC/MCInst.h"
20
#include "llvm/MC/MCInstrAnalysis.h"
21
#include "llvm/MC/MCInstrInfo.h"
22
#include "llvm/MC/MCRegisterInfo.h"
23
#include "llvm/MC/MCStreamer.h"
24
#include "llvm/MC/MCSubtargetInfo.h"
25
#include "llvm/Support/ErrorHandling.h"
26
#include "llvm/Support/TargetRegistry.h"
27
#include <cstdint>
28
#include <string>
29
30
#define GET_INSTRINFO_MC_DESC
31
#include "LanaiGenInstrInfo.inc"
32
33
#define GET_SUBTARGETINFO_MC_DESC
34
#include "LanaiGenSubtargetInfo.inc"
35
36
#define GET_REGINFO_MC_DESC
37
#include "LanaiGenRegisterInfo.inc"
38
39
using namespace llvm;
40
41
35
static MCInstrInfo *createLanaiMCInstrInfo() {
42
35
  MCInstrInfo *X = new MCInstrInfo();
43
35
  InitLanaiMCInstrInfo(X);
44
35
  return X;
45
35
}
46
47
34
static MCRegisterInfo *createLanaiMCRegisterInfo(const Triple & /*TT*/) {
48
34
  MCRegisterInfo *X = new MCRegisterInfo();
49
34
  InitLanaiMCRegisterInfo(X, Lanai::RCA, 0, 0, Lanai::PC);
50
34
  return X;
51
34
}
52
53
static MCSubtargetInfo *
54
32
createLanaiMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
55
32
  std::string CPUName = CPU;
56
32
  if (CPUName.empty())
57
32
    CPUName = "generic";
58
32
59
32
  return createLanaiMCSubtargetInfoImpl(TT, CPUName, FS);
60
32
}
61
62
static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context,
63
                                    std::unique_ptr<MCAsmBackend> &&MAB,
64
                                    std::unique_ptr<MCObjectWriter> &&OW,
65
                                    std::unique_ptr<MCCodeEmitter> &&Emitter,
66
1
                                    bool RelaxAll) {
67
1
  if (!T.isOSBinFormatELF())
68
1
    
llvm_unreachable0
("OS not supported");
69
1
70
1
  return createELFStreamer(Context, std::move(MAB), std::move(OW),
71
1
                           std::move(Emitter), RelaxAll);
72
1
}
73
74
static MCInstPrinter *createLanaiMCInstPrinter(const Triple & /*T*/,
75
                                               unsigned SyntaxVariant,
76
                                               const MCAsmInfo &MAI,
77
                                               const MCInstrInfo &MII,
78
26
                                               const MCRegisterInfo &MRI) {
79
26
  if (SyntaxVariant == 0)
80
26
    return new LanaiInstPrinter(MAI, MII, MRI);
81
0
  return nullptr;
82
0
}
83
84
static MCRelocationInfo *createLanaiElfRelocation(const Triple &TheTriple,
85
0
                                                  MCContext &Ctx) {
86
0
  return createMCRelocationInfo(TheTriple, Ctx);
87
0
}
88
89
namespace {
90
91
class LanaiMCInstrAnalysis : public MCInstrAnalysis {
92
public:
93
  explicit LanaiMCInstrAnalysis(const MCInstrInfo *Info)
94
0
      : MCInstrAnalysis(Info) {}
95
96
  bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
97
0
                      uint64_t &Target) const override {
98
0
    if (Inst.getNumOperands() == 0)
99
0
      return false;
100
0
101
0
    if (Info->get(Inst.getOpcode()).OpInfo[0].OperandType ==
102
0
        MCOI::OPERAND_PCREL) {
103
0
      int64_t Imm = Inst.getOperand(0).getImm();
104
0
      Target = Addr + Size + Imm;
105
0
      return true;
106
0
    } else {
107
0
      int64_t Imm = Inst.getOperand(0).getImm();
108
0
109
0
      // Skip case where immediate is 0 as that occurs in file that isn't linked
110
0
      // and the branch target inferred would be wrong.
111
0
      if (Imm == 0)
112
0
        return false;
113
0
114
0
      Target = Imm;
115
0
      return true;
116
0
    }
117
0
  }
118
};
119
120
} // end anonymous namespace
121
122
0
static MCInstrAnalysis *createLanaiInstrAnalysis(const MCInstrInfo *Info) {
123
0
  return new LanaiMCInstrAnalysis(Info);
124
0
}
125
126
96.4k
extern "C" void LLVMInitializeLanaiTargetMC() {
127
96.4k
  // Register the MC asm info.
128
96.4k
  RegisterMCAsmInfo<LanaiMCAsmInfo> X(getTheLanaiTarget());
129
96.4k
130
96.4k
  // Register the MC instruction info.
131
96.4k
  TargetRegistry::RegisterMCInstrInfo(getTheLanaiTarget(),
132
96.4k
                                      createLanaiMCInstrInfo);
133
96.4k
134
96.4k
  // Register the MC register info.
135
96.4k
  TargetRegistry::RegisterMCRegInfo(getTheLanaiTarget(),
136
96.4k
                                    createLanaiMCRegisterInfo);
137
96.4k
138
96.4k
  // Register the MC subtarget info.
139
96.4k
  TargetRegistry::RegisterMCSubtargetInfo(getTheLanaiTarget(),
140
96.4k
                                          createLanaiMCSubtargetInfo);
141
96.4k
142
96.4k
  // Register the MC code emitter
143
96.4k
  TargetRegistry::RegisterMCCodeEmitter(getTheLanaiTarget(),
144
96.4k
                                        createLanaiMCCodeEmitter);
145
96.4k
146
96.4k
  // Register the ASM Backend
147
96.4k
  TargetRegistry::RegisterMCAsmBackend(getTheLanaiTarget(),
148
96.4k
                                       createLanaiAsmBackend);
149
96.4k
150
96.4k
  // Register the MCInstPrinter.
151
96.4k
  TargetRegistry::RegisterMCInstPrinter(getTheLanaiTarget(),
152
96.4k
                                        createLanaiMCInstPrinter);
153
96.4k
154
96.4k
  // Register the ELF streamer.
155
96.4k
  TargetRegistry::RegisterELFStreamer(getTheLanaiTarget(), createMCStreamer);
156
96.4k
157
96.4k
  // Register the MC relocation info.
158
96.4k
  TargetRegistry::RegisterMCRelocationInfo(getTheLanaiTarget(),
159
96.4k
                                           createLanaiElfRelocation);
160
96.4k
161
96.4k
  // Register the MC instruction analyzer.
162
96.4k
  TargetRegistry::RegisterMCInstrAnalysis(getTheLanaiTarget(),
163
96.4k
                                          createLanaiInstrAnalysis);
164
96.4k
}