Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/MCRegisterInfo.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MC/MCRegisterInfo.cpp - Target Register Description ----------------===//
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 implements MCRegisterInfo functions.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/MC/MCRegisterInfo.h"
14
#include "llvm/ADT/DenseMap.h"
15
#include "llvm/ADT/Twine.h"
16
#include "llvm/Support/ErrorHandling.h"
17
#include <algorithm>
18
#include <cassert>
19
#include <cstdint>
20
21
using namespace llvm;
22
23
unsigned MCRegisterInfo::getMatchingSuperReg(unsigned Reg, unsigned SubIdx,
24
734k
                                             const MCRegisterClass *RC) const {
25
1.00M
  for (MCSuperRegIterator Supers(Reg, this); Supers.isValid(); 
++Supers274k
)
26
1.00M
    if (RC->contains(*Supers) && 
Reg == getSubReg(*Supers, SubIdx)737k
)
27
729k
      return *Supers;
28
734k
  
return 05.11k
;
29
734k
}
30
31
2.67M
unsigned MCRegisterInfo::getSubReg(unsigned Reg, unsigned Idx) const {
32
2.67M
  assert(Idx && Idx < getNumSubRegIndices() &&
33
2.67M
         "This is not a subregister index");
34
2.67M
  // Get a pointer to the corresponding SubRegIndices list. This list has the
35
2.67M
  // name of each sub-register in the same order as MCSubRegIterator.
36
2.67M
  const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
37
3.69M
  for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); 
++Subs, ++SRI1.01M
)
38
3.23M
    if (*SRI == Idx)
39
2.22M
      return *Subs;
40
2.67M
  
return 0454k
;
41
2.67M
}
42
43
46.8k
unsigned MCRegisterInfo::getSubRegIndex(unsigned Reg, unsigned SubReg) const {
44
46.8k
  assert(SubReg && SubReg < getNumRegs() && "This is not a register");
45
46.8k
  // Get a pointer to the corresponding SubRegIndices list. This list has the
46
46.8k
  // name of each sub-register in the same order as MCSubRegIterator.
47
46.8k
  const uint16_t *SRI = SubRegIndices + get(Reg).SubRegIndices;
48
69.5k
  for (MCSubRegIterator Subs(Reg, this); Subs.isValid(); 
++Subs, ++SRI22.6k
)
49
52.9k
    if (*Subs == SubReg)
50
30.2k
      return *SRI;
51
46.8k
  
return 016.5k
;
52
46.8k
}
53
54
13.0k
unsigned MCRegisterInfo::getSubRegIdxSize(unsigned Idx) const {
55
13.0k
  assert(Idx && Idx < getNumSubRegIndices() &&
56
13.0k
         "This is not a subregister index");
57
13.0k
  return SubRegIdxRanges[Idx].Size;
58
13.0k
}
59
60
259
unsigned MCRegisterInfo::getSubRegIdxOffset(unsigned Idx) const {
61
259
  assert(Idx && Idx < getNumSubRegIndices() &&
62
259
         "This is not a subregister index");
63
259
  return SubRegIdxRanges[Idx].Offset;
64
259
}
65
66
604k
int MCRegisterInfo::getDwarfRegNum(unsigned RegNum, bool isEH) const {
67
604k
  const DwarfLLVMRegPair *M = isEH ? 
EHL2DwarfRegs595k
:
L2DwarfRegs9.03k
;
68
604k
  unsigned Size = isEH ? 
EHL2DwarfRegsSize595k
:
L2DwarfRegsSize9.03k
;
69
604k
70
604k
  if (!M)
71
23
    return -1;
72
604k
  DwarfLLVMRegPair Key = { RegNum, 0 };
73
604k
  const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
74
604k
  if (I == M+Size || 
I->FromReg != RegNum604k
)
75
987
    return -1;
76
603k
  return I->ToReg;
77
603k
}
78
79
357k
int MCRegisterInfo::getLLVMRegNum(unsigned RegNum, bool isEH) const {
80
357k
  const DwarfLLVMRegPair *M = isEH ? 
EHDwarf2LRegs355k
:
Dwarf2LRegs1.92k
;
81
357k
  unsigned Size = isEH ? 
EHDwarf2LRegsSize355k
:
Dwarf2LRegsSize1.92k
;
82
357k
83
357k
  if (!M)
84
0
    return -1;
85
357k
  DwarfLLVMRegPair Key = { RegNum, 0 };
86
357k
  const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
87
357k
  assert(I != M+Size && I->FromReg == RegNum && "Invalid RegNum");
88
357k
  return I->ToReg;
89
357k
}
90
91
23.0k
int MCRegisterInfo::getLLVMRegNumFromEH(unsigned RegNum) const {
92
23.0k
  const DwarfLLVMRegPair *M = EHDwarf2LRegs;
93
23.0k
  unsigned Size = EHDwarf2LRegsSize;
94
23.0k
95
23.0k
  if (!M)
96
0
    return -1;
97
23.0k
  DwarfLLVMRegPair Key = { RegNum, 0 };
98
23.0k
  const DwarfLLVMRegPair *I = std::lower_bound(M, M+Size, Key);
99
23.0k
  if (I == M+Size || 
I->FromReg != RegNum23.0k
)
100
2
    return -1;
101
22.9k
  return I->ToReg;
102
22.9k
}
103
104
287
int MCRegisterInfo::getDwarfRegNumFromDwarfEHRegNum(unsigned RegNum) const {
105
287
  // On ELF platforms, DWARF EH register numbers are the same as DWARF
106
287
  // other register numbers.  On Darwin x86, they differ and so need to be
107
287
  // mapped.  The .cfi_* directives accept integer literals as well as
108
287
  // register names and should generate exactly what the assembly code
109
287
  // asked for, so there might be DWARF/EH register numbers that don't have
110
287
  // a corresponding LLVM register number at all.  So if we can't map the
111
287
  // EH register number to an LLVM register number, assume it's just a
112
287
  // valid DWARF register number as is.
113
287
  int LRegNum = getLLVMRegNumFromEH(RegNum);
114
287
  if (LRegNum != -1)
115
287
    return getDwarfRegNum(LRegNum, false);
116
0
  return RegNum;
117
0
}
118
119
7
int MCRegisterInfo::getSEHRegNum(unsigned RegNum) const {
120
7
  const DenseMap<unsigned, int>::const_iterator I = L2SEHRegs.find(RegNum);
121
7
  if (I == L2SEHRegs.end()) 
return (int)RegNum0
;
122
7
  return I->second;
123
7
}
124
125
531
int MCRegisterInfo::getCodeViewRegNum(unsigned RegNum) const {
126
531
  if (L2CVRegs.empty())
127
0
    report_fatal_error("target does not implement codeview register mapping");
128
531
  const DenseMap<unsigned, int>::const_iterator I = L2CVRegs.find(RegNum);
129
531
  if (I == L2CVRegs.end())
130
0
    report_fatal_error("unknown codeview register " + (RegNum < getNumRegs()
131
0
                                                           ? getName(RegNum)
132
0
                                                           : Twine(RegNum)));
133
531
  return I->second;
134
531
}