Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/Sparc/SparcMCInstLower.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- SparcMCInstLower.cpp - Convert Sparc MachineInstr to 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 Sparc MachineInstrs to their corresponding
10
// MCInst records.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "MCTargetDesc/SparcMCExpr.h"
15
#include "Sparc.h"
16
#include "llvm/CodeGen/AsmPrinter.h"
17
#include "llvm/CodeGen/MachineFunction.h"
18
#include "llvm/CodeGen/MachineInstr.h"
19
#include "llvm/CodeGen/MachineOperand.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
26
using namespace llvm;
27
28
29
static MCOperand LowerSymbolOperand(const MachineInstr *MI,
30
                                    const MachineOperand &MO,
31
984
                                    AsmPrinter &AP) {
32
984
33
984
  SparcMCExpr::VariantKind Kind =
34
984
    (SparcMCExpr::VariantKind)MO.getTargetFlags();
35
984
  const MCSymbol *Symbol = nullptr;
36
984
37
984
  switch(MO.getType()) {
38
984
  
default: 0
llvm_unreachable0
("Unknown type in LowerSymbolOperand");
39
984
  case MachineOperand::MO_MachineBasicBlock:
40
172
    Symbol = MO.getMBB()->getSymbol();
41
172
    break;
42
984
43
984
  case MachineOperand::MO_GlobalAddress:
44
451
    Symbol = AP.getSymbol(MO.getGlobal());
45
451
    break;
46
984
47
984
  case MachineOperand::MO_BlockAddress:
48
30
    Symbol = AP.GetBlockAddressSymbol(MO.getBlockAddress());
49
30
    break;
50
984
51
984
  case MachineOperand::MO_ExternalSymbol:
52
173
    Symbol = AP.GetExternalSymbolSymbol(MO.getSymbolName());
53
173
    break;
54
984
55
984
  case MachineOperand::MO_ConstantPoolIndex:
56
158
    Symbol = AP.GetCPISymbol(MO.getIndex());
57
158
    break;
58
984
  }
59
984
60
984
  const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Symbol,
61
984
                                                         AP.OutContext);
62
984
  const SparcMCExpr *expr = SparcMCExpr::create(Kind, MCSym,
63
984
                                                AP.OutContext);
64
984
  return MCOperand::createExpr(expr);
65
984
}
66
67
static MCOperand LowerOperand(const MachineInstr *MI,
68
                              const MachineOperand &MO,
69
53.0k
                              AsmPrinter &AP) {
70
53.0k
  switch(MO.getType()) {
71
53.0k
  
default: 0
llvm_unreachable0
("unknown operand type");
break0
;
72
53.0k
  case MachineOperand::MO_Register:
73
39.1k
    if (MO.isImplicit())
74
6.74k
      break;
75
32.3k
    return MCOperand::createReg(MO.getReg());
76
32.3k
77
32.3k
  case MachineOperand::MO_Immediate:
78
12.6k
    return MCOperand::createImm(MO.getImm());
79
32.3k
80
32.3k
  case MachineOperand::MO_MachineBasicBlock:
81
984
  case MachineOperand::MO_GlobalAddress:
82
984
  case MachineOperand::MO_BlockAddress:
83
984
  case MachineOperand::MO_ExternalSymbol:
84
984
  case MachineOperand::MO_ConstantPoolIndex:
85
984
    return LowerSymbolOperand(MI, MO, AP);
86
984
87
984
  
case MachineOperand::MO_RegisterMask: break365
;
88
7.11k
89
7.11k
  }
90
7.11k
  return MCOperand();
91
7.11k
}
92
93
void llvm::LowerSparcMachineInstrToMCInst(const MachineInstr *MI,
94
                                          MCInst &OutMI,
95
                                          AsmPrinter &AP)
96
16.6k
{
97
16.6k
98
16.6k
  OutMI.setOpcode(MI->getOpcode());
99
16.6k
100
69.7k
  for (unsigned i = 0, e = MI->getNumOperands(); i != e; 
++i53.0k
) {
101
53.0k
    const MachineOperand &MO = MI->getOperand(i);
102
53.0k
    MCOperand MCOp = LowerOperand(MI, MO, AP);
103
53.0k
104
53.0k
    if (MCOp.isValid())
105
45.9k
      OutMI.addOperand(MCOp);
106
53.0k
  }
107
16.6k
}