Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/MSP430/MSP430MCInstLower.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- MSP430MCInstLower.cpp - Convert MSP430 MachineInstr to an MCInst --===//
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 contains code to lower MSP430 MachineInstrs to their corresponding
10
// MCInst records.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "MSP430MCInstLower.h"
15
#include "llvm/ADT/SmallString.h"
16
#include "llvm/CodeGen/AsmPrinter.h"
17
#include "llvm/CodeGen/MachineBasicBlock.h"
18
#include "llvm/CodeGen/MachineInstr.h"
19
#include "llvm/IR/DataLayout.h"
20
#include "llvm/IR/Mangler.h"
21
#include "llvm/MC/MCAsmInfo.h"
22
#include "llvm/MC/MCContext.h"
23
#include "llvm/MC/MCExpr.h"
24
#include "llvm/MC/MCInst.h"
25
#include "llvm/Support/ErrorHandling.h"
26
#include "llvm/Support/raw_ostream.h"
27
#include "llvm/Target/TargetMachine.h"
28
using namespace llvm;
29
30
MCSymbol *MSP430MCInstLower::
31
995
GetGlobalAddressSymbol(const MachineOperand &MO) const {
32
995
  switch (MO.getTargetFlags()) {
33
995
  
default: 0
llvm_unreachable0
("Unknown target flag on GV operand");
34
995
  case 0: break;
35
995
  }
36
995
37
995
  return Printer.getSymbol(MO.getGlobal());
38
995
}
39
40
MCSymbol *MSP430MCInstLower::
41
80
GetExternalSymbolSymbol(const MachineOperand &MO) const {
42
80
  switch (MO.getTargetFlags()) {
43
80
  
default: 0
llvm_unreachable0
("Unknown target flag on GV operand");
44
80
  case 0: break;
45
80
  }
46
80
47
80
  return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
48
80
}
49
50
MCSymbol *MSP430MCInstLower::
51
2
GetJumpTableSymbol(const MachineOperand &MO) const {
52
2
  const DataLayout &DL = Printer.getDataLayout();
53
2
  SmallString<256> Name;
54
2
  raw_svector_ostream(Name) << DL.getPrivateGlobalPrefix() << "JTI"
55
2
                            << Printer.getFunctionNumber() << '_'
56
2
                            << MO.getIndex();
57
2
58
2
  switch (MO.getTargetFlags()) {
59
2
  
default: 0
llvm_unreachable0
("Unknown target flag on GV operand");
60
2
  case 0: break;
61
2
  }
62
2
63
2
  // Create a symbol for the name.
64
2
  return Ctx.getOrCreateSymbol(Name);
65
2
}
66
67
MCSymbol *MSP430MCInstLower::
68
0
GetConstantPoolIndexSymbol(const MachineOperand &MO) const {
69
0
  const DataLayout &DL = Printer.getDataLayout();
70
0
  SmallString<256> Name;
71
0
  raw_svector_ostream(Name) << DL.getPrivateGlobalPrefix() << "CPI"
72
0
                            << Printer.getFunctionNumber() << '_'
73
0
                            << MO.getIndex();
74
0
75
0
  switch (MO.getTargetFlags()) {
76
0
  default: llvm_unreachable("Unknown target flag on GV operand");
77
0
  case 0: break;
78
0
  }
79
0
80
0
  // Create a symbol for the name.
81
0
  return Ctx.getOrCreateSymbol(Name);
82
0
}
83
84
MCSymbol *MSP430MCInstLower::
85
2
GetBlockAddressSymbol(const MachineOperand &MO) const {
86
2
  switch (MO.getTargetFlags()) {
87
2
  
default: 0
llvm_unreachable0
("Unknown target flag on GV operand");
88
2
  case 0: break;
89
2
  }
90
2
91
2
  return Printer.GetBlockAddressSymbol(MO.getBlockAddress());
92
2
}
93
94
MCOperand MSP430MCInstLower::
95
1.07k
LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const {
96
1.07k
  // FIXME: We would like an efficient form for this, so we don't have to do a
97
1.07k
  // lot of extra uniquing.
98
1.07k
  const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
99
1.07k
100
1.07k
  switch (MO.getTargetFlags()) {
101
1.07k
  
default: 0
llvm_unreachable0
("Unknown target flag on GV operand");
102
1.07k
  case 0: break;
103
1.07k
  }
104
1.07k
105
1.07k
  if (!MO.isJTI() && 
MO.getOffset()1.07k
)
106
211
    Expr = MCBinaryExpr::createAdd(Expr,
107
211
                                   MCConstantExpr::create(MO.getOffset(), Ctx),
108
211
                                   Ctx);
109
1.07k
  return MCOperand::createExpr(Expr);
110
1.07k
}
111
112
#define GET_REGINFO_ENUM
113
#include "MSP430GenRegisterInfo.inc"
114
115
2.74k
void MSP430MCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
116
2.74k
  OutMI.setOpcode(MI->getOpcode());
117
2.74k
118
11.3k
  for (unsigned i = 0, e = MI->getNumOperands(); i != e; 
++i8.63k
) {
119
8.63k
    const MachineOperand &MO = MI->getOperand(i);
120
8.63k
121
8.63k
    MCOperand MCOp;
122
8.63k
    switch (MO.getType()) {
123
8.63k
    default:
124
0
      MI->print(errs());
125
0
      llvm_unreachable("unknown operand type");
126
8.63k
    case MachineOperand::MO_Register:
127
5.90k
      // Ignore all implicit register operands.
128
5.90k
      if (MO.isImplicit()) 
continue2.39k
;
129
3.51k
      MCOp = MCOperand::createReg(MO.getReg());
130
3.51k
      break;
131
3.51k
    case MachineOperand::MO_Immediate:
132
1.58k
      MCOp = MCOperand::createImm(MO.getImm());
133
1.58k
      break;
134
3.51k
    case MachineOperand::MO_MachineBasicBlock:
135
68
      MCOp = MCOperand::createExpr(MCSymbolRefExpr::create(
136
68
                         MO.getMBB()->getSymbol(), Ctx));
137
68
      break;
138
3.51k
    case MachineOperand::MO_GlobalAddress:
139
995
      MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
140
995
      break;
141
3.51k
    case MachineOperand::MO_ExternalSymbol:
142
80
      MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
143
80
      break;
144
3.51k
    case MachineOperand::MO_JumpTableIndex:
145
2
      MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
146
2
      break;
147
3.51k
    case MachineOperand::MO_ConstantPoolIndex:
148
0
      MCOp = LowerSymbolOperand(MO, GetConstantPoolIndexSymbol(MO));
149
0
      break;
150
3.51k
    case MachineOperand::MO_BlockAddress:
151
2
      MCOp = LowerSymbolOperand(MO, GetBlockAddressSymbol(MO));
152
2
      break;
153
3.51k
    case MachineOperand::MO_RegisterMask:
154
0
      continue;
155
6.24k
    }
156
6.24k
157
6.24k
    OutMI.addOperand(MCOp);
158
6.24k
  }
159
2.74k
}