Coverage Report

Created: 2018-07-19 03:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/MCInst.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/MC/MCInst.h - MCInst class --------------------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file contains the declaration of the MCInst and MCOperand classes, which
11
// is the basic representation used to represent low-level machine code
12
// instructions.
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_MC_MCINST_H
17
#define LLVM_MC_MCINST_H
18
19
#include "llvm/ADT/SmallVector.h"
20
#include "llvm/ADT/StringRef.h"
21
#include "llvm/Support/SMLoc.h"
22
#include <cassert>
23
#include <cstddef>
24
#include <cstdint>
25
26
namespace llvm {
27
28
class MCExpr;
29
class MCInst;
30
class MCInstPrinter;
31
class raw_ostream;
32
33
/// Instances of this class represent operands of the MCInst class.
34
/// This is a simple discriminated union.
35
0
class MCOperand {
36
  enum MachineOperandType : unsigned char {
37
    kInvalid,     ///< Uninitialized.
38
    kRegister,    ///< Register operand.
39
    kImmediate,   ///< Immediate operand.
40
    kFPImmediate, ///< Floating-point immediate operand.
41
    kExpr,        ///< Relocatable immediate operand.
42
    kInst         ///< Sub-instruction operand.
43
  };
44
  MachineOperandType Kind = kInvalid;
45
46
0
  union {
47
    unsigned RegVal;
48
    int64_t ImmVal;
49
    double FPImmVal;
50
    const MCExpr *ExprVal;
51
    const MCInst *InstVal;
52
  };
53
54
public:
55
123M
  MCOperand() : FPImmVal(0.0) {}
56
57
608k
  bool isValid() const { return Kind != kInvalid; }
58
45.9M
  bool isReg() const { return Kind == kRegister; }
59
15.7M
  bool isImm() const { return Kind == kImmediate; }
60
24.2k
  bool isFPImm() const { return Kind == kFPImmediate; }
61
53.7M
  bool isExpr() const { return Kind == kExpr; }
62
0
  bool isInst() const { return Kind == kInst; }
63
64
  /// Returns the register number.
65
49.8M
  unsigned getReg() const {
66
49.8M
    assert(isReg() && "This is not a register operand!");
67
49.8M
    return RegVal;
68
49.8M
  }
69
70
  /// Set the register number.
71
2.16k
  void setReg(unsigned Reg) {
72
2.16k
    assert(isReg() && "This is not a register operand!");
73
2.16k
    RegVal = Reg;
74
2.16k
  }
75
76
19.0M
  int64_t getImm() const {
77
19.0M
    assert(isImm() && "This is not an immediate");
78
19.0M
    return ImmVal;
79
19.0M
  }
80
81
34.7k
  void setImm(int64_t Val) {
82
34.7k
    assert(isImm() && "This is not an immediate");
83
34.7k
    ImmVal = Val;
84
34.7k
  }
85
86
7
  double getFPImm() const {
87
7
    assert(isFPImm() && "This is not an FP immediate");
88
7
    return FPImmVal;
89
7
  }
90
91
0
  void setFPImm(double Val) {
92
0
    assert(isFPImm() && "This is not an FP immediate");
93
0
    FPImmVal = Val;
94
0
  }
95
96
9.52M
  const MCExpr *getExpr() const {
97
9.52M
    assert(isExpr() && "This is not an expression");
98
9.52M
    return ExprVal;
99
9.52M
  }
100
101
8
  void setExpr(const MCExpr *Val) {
102
8
    assert(isExpr() && "This is not an expression");
103
8
    ExprVal = Val;
104
8
  }
105
106
571k
  const MCInst *getInst() const {
107
571k
    assert(isInst() && "This is not a sub-instruction");
108
571k
    return InstVal;
109
571k
  }
110
111
1.60k
  void setInst(const MCInst *Val) {
112
1.60k
    assert(isInst() && "This is not a sub-instruction");
113
1.60k
    InstVal = Val;
114
1.60k
  }
115
116
38.9M
  static MCOperand createReg(unsigned Reg) {
117
38.9M
    MCOperand Op;
118
38.9M
    Op.Kind = kRegister;
119
38.9M
    Op.RegVal = Reg;
120
38.9M
    return Op;
121
38.9M
  }
122
123
18.5M
  static MCOperand createImm(int64_t Val) {
124
18.5M
    MCOperand Op;
125
18.5M
    Op.Kind = kImmediate;
126
18.5M
    Op.ImmVal = Val;
127
18.5M
    return Op;
128
18.5M
  }
129
130
3
  static MCOperand createFPImm(double Val) {
131
3
    MCOperand Op;
132
3
    Op.Kind = kFPImmediate;
133
3
    Op.FPImmVal = Val;
134
3
    return Op;
135
3
  }
136
137
4.65M
  static MCOperand createExpr(const MCExpr *Val) {
138
4.65M
    MCOperand Op;
139
4.65M
    Op.Kind = kExpr;
140
4.65M
    Op.ExprVal = Val;
141
4.65M
    return Op;
142
4.65M
  }
143
144
231k
  static MCOperand createInst(const MCInst *Val) {
145
231k
    MCOperand Op;
146
231k
    Op.Kind = kInst;
147
231k
    Op.InstVal = Val;
148
231k
    return Op;
149
231k
  }
150
151
  void print(raw_ostream &OS) const;
152
  void dump() const;
153
  bool isBareSymbolRef() const;
154
  bool evaluateAsConstantImm(int64_t &Imm) const;
155
};
156
157
template <> struct isPodLike<MCOperand> { static const bool value = true; };
158
159
/// Instances of this class represent a single low-level machine
160
/// instruction.
161
0
class MCInst {
162
  unsigned Opcode = 0;
163
  SMLoc Loc;
164
  SmallVector<MCOperand, 8> Operands;
165
  // These flags could be used to pass some info from one target subcomponent
166
  // to another, for example, from disassembler to asm printer. The values of
167
  // the flags have any sense on target level only (e.g. prefixes on x86).
168
  unsigned Flags = 0;
169
170
public:
171
455M
  MCInst() = default;
172
173
20.0M
  void setOpcode(unsigned Op) { Opcode = Op; }
174
85.6M
  unsigned getOpcode() const { return Opcode; }
175
176
514k
  void setFlags(unsigned F) { Flags = F; }
177
6.89M
  unsigned getFlags() const { return Flags; }
178
179
552k
  void setLoc(SMLoc loc) { Loc = loc; }
180
5.50M
  SMLoc getLoc() const { return Loc; }
181
182
133M
  const MCOperand &getOperand(unsigned i) const { return Operands[i]; }
183
971k
  MCOperand &getOperand(unsigned i) { return Operands[i]; }
184
24.0M
  unsigned getNumOperands() const { return Operands.size(); }
185
186
62.5M
  void addOperand(const MCOperand &Op) { Operands.push_back(Op); }
187
188
  using iterator = SmallVectorImpl<MCOperand>::iterator;
189
  using const_iterator = SmallVectorImpl<MCOperand>::const_iterator;
190
191
1.33M
  void clear() { Operands.clear(); }
192
1.68k
  void erase(iterator I) { Operands.erase(I); }
193
246k
  size_t size() const { return Operands.size(); }
194
61.9k
  iterator begin() { return Operands.begin(); }
195
230k
  const_iterator begin() const { return Operands.begin(); }
196
138k
  iterator end() { return Operands.end(); }
197
471k
  const_iterator end() const { return Operands.end(); }
198
199
33.8k
  iterator insert(iterator I, const MCOperand &Op) {
200
33.8k
    return Operands.insert(I, Op);
201
33.8k
  }
202
203
  void print(raw_ostream &OS) const;
204
  void dump() const;
205
206
  /// Dump the MCInst as prettily as possible using the additional MC
207
  /// structures, if given. Operators are separated by the \p Separator
208
  /// string.
209
  void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer = nullptr,
210
                   StringRef Separator = " ") const;
211
};
212
213
419
inline raw_ostream& operator<<(raw_ostream &OS, const MCOperand &MO) {
214
419
  MO.print(OS);
215
419
  return OS;
216
419
}
217
218
0
inline raw_ostream& operator<<(raw_ostream &OS, const MCInst &MI) {
219
0
  MI.print(OS);
220
0
  return OS;
221
0
}
222
223
} // end namespace llvm
224
225
#endif // LLVM_MC_MCINST_H