Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/BPF/BPFMCInstLower.cpp
Line
Count
Source (jump to first uncovered line)
1
//=-- BPFMCInstLower.cpp - Convert BPF 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 BPF MachineInstrs to their corresponding
10
// MCInst records.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "BPFMCInstLower.h"
15
#include "llvm/CodeGen/AsmPrinter.h"
16
#include "llvm/CodeGen/MachineBasicBlock.h"
17
#include "llvm/CodeGen/MachineInstr.h"
18
#include "llvm/MC/MCAsmInfo.h"
19
#include "llvm/MC/MCContext.h"
20
#include "llvm/MC/MCExpr.h"
21
#include "llvm/MC/MCInst.h"
22
#include "llvm/Support/ErrorHandling.h"
23
#include "llvm/Support/raw_ostream.h"
24
using namespace llvm;
25
26
MCSymbol *
27
132
BPFMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
28
132
  return Printer.getSymbol(MO.getGlobal());
29
132
}
30
31
MCSymbol *
32
1
BPFMCInstLower::GetExternalSymbolSymbol(const MachineOperand &MO) const {
33
1
  return Printer.GetExternalSymbolSymbol(MO.getSymbolName());
34
1
}
35
36
MCOperand BPFMCInstLower::LowerSymbolOperand(const MachineOperand &MO,
37
133
                                             MCSymbol *Sym) const {
38
133
39
133
  const MCExpr *Expr = MCSymbolRefExpr::create(Sym, Ctx);
40
133
41
133
  if (!MO.isJTI() && MO.getOffset())
42
133
    
llvm_unreachable0
("unknown symbol op");
43
133
44
133
  return MCOperand::createExpr(Expr);
45
133
}
46
47
2.09k
void BPFMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
48
2.09k
  OutMI.setOpcode(MI->getOpcode());
49
2.09k
50
7.87k
  for (unsigned i = 0, e = MI->getNumOperands(); i != e; 
++i5.77k
) {
51
5.77k
    const MachineOperand &MO = MI->getOperand(i);
52
5.77k
53
5.77k
    MCOperand MCOp;
54
5.77k
    switch (MO.getType()) {
55
5.77k
    default:
56
0
      MI->print(errs());
57
0
      llvm_unreachable("unknown operand type");
58
5.77k
    case MachineOperand::MO_Register:
59
4.42k
      // Ignore all implicit register operands.
60
4.42k
      if (MO.isImplicit())
61
1.21k
        continue;
62
3.21k
      MCOp = MCOperand::createReg(MO.getReg());
63
3.21k
      break;
64
3.21k
    case MachineOperand::MO_Immediate:
65
1.09k
      MCOp = MCOperand::createImm(MO.getImm());
66
1.09k
      break;
67
3.21k
    case MachineOperand::MO_MachineBasicBlock:
68
127
      MCOp = MCOperand::createExpr(
69
127
          MCSymbolRefExpr::create(MO.getMBB()->getSymbol(), Ctx));
70
127
      break;
71
3.21k
    case MachineOperand::MO_RegisterMask:
72
0
      continue;
73
3.21k
    case MachineOperand::MO_ExternalSymbol:
74
1
      MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
75
1
      break;
76
3.21k
    case MachineOperand::MO_GlobalAddress:
77
132
      MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
78
132
      break;
79
4.56k
    }
80
4.56k
81
4.56k
    OutMI.addOperand(MCOp);
82
4.56k
  }
83
2.09k
}