Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/MC/MCFragment.h
Line
Count
Source (jump to first uncovered line)
1
//===- MCFragment.h - Fragment type hierarchy -------------------*- C++ -*-===//
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
#ifndef LLVM_MC_MCFRAGMENT_H
10
#define LLVM_MC_MCFRAGMENT_H
11
12
#include "llvm/ADT/ArrayRef.h"
13
#include "llvm/ADT/SmallString.h"
14
#include "llvm/ADT/SmallVector.h"
15
#include "llvm/ADT/StringRef.h"
16
#include "llvm/ADT/ilist_node.h"
17
#include "llvm/MC/MCFixup.h"
18
#include "llvm/MC/MCInst.h"
19
#include "llvm/Support/Casting.h"
20
#include "llvm/Support/SMLoc.h"
21
#include <cstdint>
22
#include <utility>
23
24
namespace llvm {
25
26
class MCSection;
27
class MCSubtargetInfo;
28
class MCSymbol;
29
30
class MCFragment : public ilist_node_with_parent<MCFragment, MCSection> {
31
  friend class MCAsmLayout;
32
33
public:
34
  enum FragmentType : uint8_t {
35
    FT_Align,
36
    FT_Data,
37
    FT_CompactEncodedInst,
38
    FT_Fill,
39
    FT_Relaxable,
40
    FT_Org,
41
    FT_Dwarf,
42
    FT_DwarfFrame,
43
    FT_LEB,
44
    FT_Padding,
45
    FT_SymbolId,
46
    FT_CVInlineLines,
47
    FT_CVDefRange,
48
    FT_Dummy
49
  };
50
51
private:
52
  FragmentType Kind;
53
54
protected:
55
  bool HasInstructions;
56
57
private:
58
  /// LayoutOrder - The layout order of this fragment.
59
  unsigned LayoutOrder;
60
61
  /// The data for the section this fragment is in.
62
  MCSection *Parent;
63
64
  /// Atom - The atom this fragment is in, as represented by its defining
65
  /// symbol.
66
  const MCSymbol *Atom;
67
68
  /// \name Assembler Backend Data
69
  /// @{
70
  //
71
  // FIXME: This could all be kept private to the assembler implementation.
72
73
  /// Offset - The offset of this fragment in its section. This is ~0 until
74
  /// initialized.
75
  uint64_t Offset;
76
77
  /// @}
78
79
protected:
80
  MCFragment(FragmentType Kind, bool HasInstructions,
81
             MCSection *Parent = nullptr);
82
83
  ~MCFragment();
84
85
public:
86
  MCFragment() = delete;
87
  MCFragment(const MCFragment &) = delete;
88
  MCFragment &operator=(const MCFragment &) = delete;
89
90
  /// Destroys the current fragment.
91
  ///
92
  /// This must be used instead of delete as MCFragment is non-virtual.
93
  /// This method will dispatch to the appropriate subclass.
94
  void destroy();
95
96
115M
  FragmentType getKind() const { return Kind; }
97
98
85.8M
  MCSection *getParent() const { return Parent; }
99
7.20M
  void setParent(MCSection *Value) { Parent = Value; }
100
101
4.08M
  const MCSymbol *getAtom() const { return Atom; }
102
3.10M
  void setAtom(const MCSymbol *Value) { Atom = Value; }
103
104
55.0M
  unsigned getLayoutOrder() const { return LayoutOrder; }
105
5.51M
  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
106
107
  /// Does this fragment have instructions emitted into it? By default
108
  /// this is false, but specific fragment types may set it to true.
109
27.6M
  bool hasInstructions() const { return HasInstructions; }
110
111
  /// Return true if given frgment has FT_Dummy type.
112
3.12M
  bool isDummy() const { return Kind == FT_Dummy; }
113
114
  void dump() const;
115
};
116
117
class MCDummyFragment : public MCFragment {
118
public:
119
3.26M
  explicit MCDummyFragment(MCSection *Sec) : MCFragment(FT_Dummy, false, Sec) {}
120
121
0
  static bool classof(const MCFragment *F) { return F->getKind() == FT_Dummy; }
122
};
123
124
/// Interface implemented by fragments that contain encoded instructions and/or
125
/// data.
126
///
127
class MCEncodedFragment : public MCFragment {
128
  /// Should this fragment be aligned to the end of a bundle?
129
  bool AlignToBundleEnd = false;
130
131
  uint8_t BundlePadding = 0;
132
133
protected:
134
  MCEncodedFragment(MCFragment::FragmentType FType, bool HasInstructions,
135
                    MCSection *Sec)
136
6.10M
      : MCFragment(FType, HasInstructions, Sec) {}
137
138
  /// STI - The MCSubtargetInfo in effect when the instruction was encoded.
139
  /// must be non-null for instructions.
140
  const MCSubtargetInfo *STI = nullptr;
141
142
public:
143
16.5M
  static bool classof(const MCFragment *F) {
144
16.5M
    MCFragment::FragmentType Kind = F->getKind();
145
16.5M
    switch (Kind) {
146
16.5M
    default:
147
3.29M
      return false;
148
16.5M
    case MCFragment::FT_Relaxable:
149
13.2M
    case MCFragment::FT_CompactEncodedInst:
150
13.2M
    case MCFragment::FT_Data:
151
13.2M
    case MCFragment::FT_Dwarf:
152
13.2M
    case MCFragment::FT_DwarfFrame:
153
13.2M
      return true;
154
16.5M
    }
155
16.5M
  }
156
157
  /// Should this fragment be placed at the end of an aligned bundle?
158
1.31k
  bool alignToBundleEnd() const { return AlignToBundleEnd; }
159
2.24k
  void setAlignToBundleEnd(bool V) { AlignToBundleEnd = V; }
160
161
  /// Get the padding size that must be inserted before this fragment.
162
  /// Used for bundling. By default, no padding is inserted.
163
  /// Note that padding size is restricted to 8 bits. This is an optimization
164
  /// to reduce the amount of space used for each fragment. In practice, larger
165
  /// padding should never be required.
166
4.39M
  uint8_t getBundlePadding() const { return BundlePadding; }
167
168
  /// Set the padding size for this fragment. By default it's a no-op,
169
  /// and only some fragments have a meaningful implementation.
170
780
  void setBundlePadding(uint8_t N) { BundlePadding = N; }
171
172
  /// Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
173
  /// Guaranteed to be non-null if hasInstructions() == true
174
4.34M
  const MCSubtargetInfo *getSubtargetInfo() const { return STI; }
175
176
  /// Record that the fragment contains instructions with the MCSubtargetInfo in
177
  /// effect when the instruction was encoded.
178
16.5M
  void setHasInstructions(const MCSubtargetInfo &STI) {
179
16.5M
    HasInstructions = true;
180
16.5M
    this->STI = &STI;
181
16.5M
  }
182
};
183
184
/// Interface implemented by fragments that contain encoded instructions and/or
185
/// data.
186
///
187
template<unsigned ContentsSize>
188
class MCEncodedFragmentWithContents : public MCEncodedFragment {
189
  SmallVector<char, ContentsSize> Contents;
190
191
protected:
192
  MCEncodedFragmentWithContents(MCFragment::FragmentType FType,
193
                                bool HasInstructions,
194
                                MCSection *Sec)
195
6.10M
      : MCEncodedFragment(FType, HasInstructions, Sec) {}
llvm::MCEncodedFragmentWithContents<32u>::MCEncodedFragmentWithContents(llvm::MCFragment::FragmentType, bool, llvm::MCSection*)
Line
Count
Source
195
4.76M
      : MCEncodedFragment(FType, HasInstructions, Sec) {}
llvm::MCEncodedFragmentWithContents<4u>::MCEncodedFragmentWithContents(llvm::MCFragment::FragmentType, bool, llvm::MCSection*)
Line
Count
Source
195
141
      : MCEncodedFragment(FType, HasInstructions, Sec) {}
llvm::MCEncodedFragmentWithContents<8u>::MCEncodedFragmentWithContents(llvm::MCFragment::FragmentType, bool, llvm::MCSection*)
Line
Count
Source
195
1.33M
      : MCEncodedFragment(FType, HasInstructions, Sec) {}
196
197
public:
198
65.4M
  SmallVectorImpl<char> &getContents() { return Contents; }
llvm::MCEncodedFragmentWithContents<8u>::getContents()
Line
Count
Source
198
8.22M
  SmallVectorImpl<char> &getContents() { return Contents; }
llvm::MCEncodedFragmentWithContents<32u>::getContents()
Line
Count
Source
198
57.2M
  SmallVectorImpl<char> &getContents() { return Contents; }
llvm::MCEncodedFragmentWithContents<4u>::getContents()
Line
Count
Source
198
141
  SmallVectorImpl<char> &getContents() { return Contents; }
199
14.3M
  const SmallVectorImpl<char> &getContents() const { return Contents; }
llvm::MCEncodedFragmentWithContents<32u>::getContents() const
Line
Count
Source
199
9.98M
  const SmallVectorImpl<char> &getContents() const { return Contents; }
llvm::MCEncodedFragmentWithContents<8u>::getContents() const
Line
Count
Source
199
4.32M
  const SmallVectorImpl<char> &getContents() const { return Contents; }
llvm::MCEncodedFragmentWithContents<4u>::getContents() const
Line
Count
Source
199
543
  const SmallVectorImpl<char> &getContents() const { return Contents; }
200
};
201
202
/// Interface implemented by fragments that contain encoded instructions and/or
203
/// data and also have fixups registered.
204
///
205
template<unsigned ContentsSize, unsigned FixupsSize>
206
class MCEncodedFragmentWithFixups :
207
  public MCEncodedFragmentWithContents<ContentsSize> {
208
209
  /// Fixups - The list of fixups in this fragment.
210
  SmallVector<MCFixup, FixupsSize> Fixups;
211
212
protected:
213
  MCEncodedFragmentWithFixups(MCFragment::FragmentType FType,
214
                              bool HasInstructions,
215
                              MCSection *Sec)
216
      : MCEncodedFragmentWithContents<ContentsSize>(FType, HasInstructions,
217
6.10M
                                                    Sec) {}
llvm::MCEncodedFragmentWithFixups<32u, 4u>::MCEncodedFragmentWithFixups(llvm::MCFragment::FragmentType, bool, llvm::MCSection*)
Line
Count
Source
217
4.76M
                                                    Sec) {}
llvm::MCEncodedFragmentWithFixups<8u, 1u>::MCEncodedFragmentWithFixups(llvm::MCFragment::FragmentType, bool, llvm::MCSection*)
Line
Count
Source
217
1.33M
                                                    Sec) {}
218
219
public:
220
221
  using const_fixup_iterator = SmallVectorImpl<MCFixup>::const_iterator;
222
  using fixup_iterator = SmallVectorImpl<MCFixup>::iterator;
223
224
13.5M
  SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
llvm::MCEncodedFragmentWithFixups<32u, 4u>::getFixups()
Line
Count
Source
224
8.63M
  SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
llvm::MCEncodedFragmentWithFixups<8u, 1u>::getFixups()
Line
Count
Source
224
4.93M
  SmallVectorImpl<MCFixup> &getFixups() { return Fixups; }
225
621k
  const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
llvm::MCEncodedFragmentWithFixups<32u, 4u>::getFixups() const
Line
Count
Source
225
145
  const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
llvm::MCEncodedFragmentWithFixups<8u, 1u>::getFixups() const
Line
Count
Source
225
621k
  const SmallVectorImpl<MCFixup> &getFixups() const { return Fixups; }
226
227
  fixup_iterator fixup_begin() { return Fixups.begin(); }
228
9.90k
  const_fixup_iterator fixup_begin() const { return Fixups.begin(); }
229
230
  fixup_iterator fixup_end() { return Fixups.end(); }
231
9.90k
  const_fixup_iterator fixup_end() const { return Fixups.end(); }
232
233
  static bool classof(const MCFragment *F) {
234
    MCFragment::FragmentType Kind = F->getKind();
235
    return Kind == MCFragment::FT_Relaxable || Kind == MCFragment::FT_Data ||
236
           Kind == MCFragment::FT_CVDefRange || Kind == MCFragment::FT_Dwarf ||
237
           Kind == MCFragment::FT_DwarfFrame;
238
  }
239
};
240
241
/// Fragment for data and encoded instructions.
242
///
243
class MCDataFragment : public MCEncodedFragmentWithFixups<32, 4> {
244
public:
245
  MCDataFragment(MCSection *Sec = nullptr)
246
4.76M
      : MCEncodedFragmentWithFixups<32, 4>(FT_Data, false, Sec) {}
247
248
40.0M
  static bool classof(const MCFragment *F) {
249
40.0M
    return F->getKind() == MCFragment::FT_Data;
250
40.0M
  }
251
};
252
253
/// This is a compact (memory-size-wise) fragment for holding an encoded
254
/// instruction (non-relaxable) that has no fixups registered. When applicable,
255
/// it can be used instead of MCDataFragment and lead to lower memory
256
/// consumption.
257
///
258
class MCCompactEncodedInstFragment : public MCEncodedFragmentWithContents<4> {
259
public:
260
  MCCompactEncodedInstFragment(MCSection *Sec = nullptr)
261
141
      : MCEncodedFragmentWithContents(FT_CompactEncodedInst, true, Sec) {
262
141
  }
263
264
4.40M
  static bool classof(const MCFragment *F) {
265
4.40M
    return F->getKind() == MCFragment::FT_CompactEncodedInst;
266
4.40M
  }
267
};
268
269
/// A relaxable fragment holds on to its MCInst, since it may need to be
270
/// relaxed during the assembler layout and relaxation stage.
271
///
272
class MCRelaxableFragment : public MCEncodedFragmentWithFixups<8, 1> {
273
274
  /// Inst - The instruction this is a fragment for.
275
  MCInst Inst;
276
277
public:
278
  MCRelaxableFragment(const MCInst &Inst, const MCSubtargetInfo &STI,
279
                      MCSection *Sec = nullptr)
280
      : MCEncodedFragmentWithFixups(FT_Relaxable, true, Sec),
281
237k
        Inst(Inst) { this->STI = &STI; }
282
283
893k
  const MCInst &getInst() const { return Inst; }
284
67.6k
  void setInst(const MCInst &Value) { Inst = Value; }
285
286
1.82M
  static bool classof(const MCFragment *F) {
287
1.82M
    return F->getKind() == MCFragment::FT_Relaxable;
288
1.82M
  }
289
};
290
291
class MCAlignFragment : public MCFragment {
292
  /// Alignment - The alignment to ensure, in bytes.
293
  unsigned Alignment;
294
295
  /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
296
  /// of using the provided value. The exact interpretation of this flag is
297
  /// target dependent.
298
  bool EmitNops : 1;
299
300
  /// Value - Value to use for filling padding bytes.
301
  int64_t Value;
302
303
  /// ValueSize - The size of the integer (in bytes) of \p Value.
304
  unsigned ValueSize;
305
306
  /// MaxBytesToEmit - The maximum number of bytes to emit; if the alignment
307
  /// cannot be satisfied in this width then this fragment is ignored.
308
  unsigned MaxBytesToEmit;
309
310
public:
311
  MCAlignFragment(unsigned Alignment, int64_t Value, unsigned ValueSize,
312
                  unsigned MaxBytesToEmit, MCSection *Sec = nullptr)
313
      : MCFragment(FT_Align, false, Sec), Alignment(Alignment), EmitNops(false),
314
488k
        Value(Value), ValueSize(ValueSize), MaxBytesToEmit(MaxBytesToEmit) {}
315
316
  /// \name Accessors
317
  /// @{
318
319
1.02M
  unsigned getAlignment() const { return Alignment; }
320
321
1.55M
  int64_t getValue() const { return Value; }
322
323
2.51M
  unsigned getValueSize() const { return ValueSize; }
324
325
1.02M
  unsigned getMaxBytesToEmit() const { return MaxBytesToEmit; }
326
327
1.72M
  bool hasEmitNops() const { return EmitNops; }
328
300k
  void setEmitNops(bool Value) { EmitNops = Value; }
329
330
  /// @}
331
332
1.72M
  static bool classof(const MCFragment *F) {
333
1.72M
    return F->getKind() == MCFragment::FT_Align;
334
1.72M
  }
335
};
336
337
/// Fragment for adding required padding.
338
/// This fragment is always inserted before an instruction, and holds that
339
/// instruction as context information (as well as a mask of kinds) for
340
/// determining the padding size.
341
///
342
class MCPaddingFragment : public MCFragment {
343
  /// A mask containing all the kinds relevant to this fragment. i.e. the i'th
344
  /// bit will be set iff kind i is relevant to this fragment.
345
  uint64_t PaddingPoliciesMask;
346
  /// A boolean indicating if this fragment will actually hold padding. If its
347
  /// value is false, then this fragment serves only as a placeholder,
348
  /// containing data to assist other insertion point in their decision making.
349
  bool IsInsertionPoint;
350
351
  uint64_t Size;
352
353
  struct MCInstInfo {
354
    bool IsInitialized;
355
    MCInst Inst;
356
    /// A boolean indicating whether the instruction pointed by this fragment is
357
    /// a fixed size instruction or a relaxable instruction held by a
358
    /// MCRelaxableFragment.
359
    bool IsImmutableSizedInst;
360
    union {
361
      /// If the instruction is a fixed size instruction, hold its size.
362
      size_t InstSize;
363
      /// Otherwise, hold a pointer to the MCRelaxableFragment holding it.
364
      MCRelaxableFragment *InstFragment;
365
    };
366
  };
367
  MCInstInfo InstInfo;
368
369
public:
370
  static const uint64_t PFK_None = UINT64_C(0);
371
372
  enum MCPaddingFragmentKind {
373
    // values 0-7 are reserved for future target independet values.
374
375
    FirstTargetPerfNopFragmentKind = 8,
376
377
    /// Limit range of target MCPerfNopFragment kinds to fit in uint64_t
378
    MaxTargetPerfNopFragmentKind = 63
379
  };
380
381
  MCPaddingFragment(MCSection *Sec = nullptr)
382
      : MCFragment(FT_Padding, false, Sec), PaddingPoliciesMask(PFK_None),
383
        IsInsertionPoint(false), Size(UINT64_C(0)),
384
0
        InstInfo({false, MCInst(), false, {0}}) {}
385
386
0
  bool isInsertionPoint() const { return IsInsertionPoint; }
387
0
  void setAsInsertionPoint() { IsInsertionPoint = true; }
388
0
  uint64_t getPaddingPoliciesMask() const { return PaddingPoliciesMask; }
389
0
  void setPaddingPoliciesMask(uint64_t Value) { PaddingPoliciesMask = Value; }
390
0
  bool hasPaddingPolicy(uint64_t PolicyMask) const {
391
0
    assert(isPowerOf2_64(PolicyMask) &&
392
0
           "Policy mask must contain exactly one policy");
393
0
    return (getPaddingPoliciesMask() & PolicyMask) != PFK_None;
394
0
  }
395
0
  const MCInst &getInst() const {
396
0
    assert(isInstructionInitialized() && "Fragment has no instruction!");
397
0
    return InstInfo.Inst;
398
0
  }
399
0
  size_t getInstSize() const {
400
0
    assert(isInstructionInitialized() && "Fragment has no instruction!");
401
0
    if (InstInfo.IsImmutableSizedInst)
402
0
      return InstInfo.InstSize;
403
0
    assert(InstInfo.InstFragment != nullptr &&
404
0
           "Must have a valid InstFragment to retrieve InstSize from");
405
0
    return InstInfo.InstFragment->getContents().size();
406
0
  }
407
0
  void setInstAndInstSize(const MCInst &Inst, size_t InstSize) {
408
0
  InstInfo.IsInitialized = true;
409
0
    InstInfo.IsImmutableSizedInst = true;
410
0
    InstInfo.Inst = Inst;
411
0
    InstInfo.InstSize = InstSize;
412
0
  }
413
  void setInstAndInstFragment(const MCInst &Inst,
414
0
                              MCRelaxableFragment *InstFragment) {
415
0
    InstInfo.IsInitialized = true;
416
0
    InstInfo.IsImmutableSizedInst = false;
417
0
    InstInfo.Inst = Inst;
418
0
    InstInfo.InstFragment = InstFragment;
419
0
  }
420
0
  uint64_t getSize() const { return Size; }
421
0
  void setSize(uint64_t Value) { Size = Value; }
422
0
  bool isInstructionInitialized() const { return InstInfo.IsInitialized; }
423
424
0
  static bool classof(const MCFragment *F) {
425
0
    return F->getKind() == MCFragment::FT_Padding;
426
0
  }
427
};
428
429
class MCFillFragment : public MCFragment {
430
  /// Value to use for filling bytes.
431
  uint64_t Value;
432
  uint8_t ValueSize;
433
  /// The number of bytes to insert.
434
  const MCExpr &NumValues;
435
436
  /// Source location of the directive that this fragment was created for.
437
  SMLoc Loc;
438
439
public:
440
  MCFillFragment(uint64_t Value, uint8_t VSize, const MCExpr &NumValues,
441
                 SMLoc Loc, MCSection *Sec = nullptr)
442
      : MCFragment(FT_Fill, false, Sec), Value(Value), ValueSize(VSize),
443
609k
        NumValues(NumValues), Loc(Loc) {}
444
445
602k
  uint64_t getValue() const { return Value; }
446
1.86M
  uint8_t getValueSize() const { return ValueSize; }
447
1.26M
  const MCExpr &getNumValues() const { return NumValues; }
448
449
6
  SMLoc getLoc() const { return Loc; }
450
451
242
  static bool classof(const MCFragment *F) {
452
242
    return F->getKind() == MCFragment::FT_Fill;
453
242
  }
454
};
455
456
class MCOrgFragment : public MCFragment {
457
  /// The offset this fragment should start at.
458
  const MCExpr *Offset;
459
460
  /// Value to use for filling bytes.
461
  int8_t Value;
462
463
  /// Source location of the directive that this fragment was created for.
464
  SMLoc Loc;
465
466
public:
467
  MCOrgFragment(const MCExpr &Offset, int8_t Value, SMLoc Loc,
468
                MCSection *Sec = nullptr)
469
19
      : MCFragment(FT_Org, false, Sec), Offset(&Offset), Value(Value), Loc(Loc) {}
470
471
  /// \name Accessors
472
  /// @{
473
474
40
  const MCExpr &getOffset() const { return *Offset; }
475
476
2.46k
  uint8_t getValue() const { return Value; }
477
478
10
  SMLoc getLoc() const { return Loc; }
479
480
  /// @}
481
482
0
  static bool classof(const MCFragment *F) {
483
0
    return F->getKind() == MCFragment::FT_Org;
484
0
  }
485
};
486
487
class MCLEBFragment : public MCFragment {
488
  /// Value - The value this fragment should contain.
489
  const MCExpr *Value;
490
491
  /// IsSigned - True if this is a sleb128, false if uleb128.
492
  bool IsSigned;
493
494
  SmallString<8> Contents;
495
496
public:
497
  MCLEBFragment(const MCExpr &Value_, bool IsSigned_, MCSection *Sec = nullptr)
498
4.82k
      : MCFragment(FT_LEB, false, Sec), Value(&Value_), IsSigned(IsSigned_) {
499
4.82k
    Contents.push_back(0);
500
4.82k
  }
501
502
  /// \name Accessors
503
  /// @{
504
505
10.5k
  const MCExpr &getValue() const { return *Value; }
506
507
10.5k
  bool isSigned() const { return IsSigned; }
508
509
31.5k
  SmallString<8> &getContents() { return Contents; }
510
16.4k
  const SmallString<8> &getContents() const { return Contents; }
511
512
  /// @}
513
514
233
  static bool classof(const MCFragment *F) {
515
233
    return F->getKind() == MCFragment::FT_LEB;
516
233
  }
517
};
518
519
class MCDwarfLineAddrFragment : public MCEncodedFragmentWithFixups<8, 1> {
520
  /// LineDelta - the value of the difference between the two line numbers
521
  /// between two .loc dwarf directives.
522
  int64_t LineDelta;
523
524
  /// AddrDelta - The expression for the difference of the two symbols that
525
  /// make up the address delta between two .loc dwarf directives.
526
  const MCExpr *AddrDelta;
527
528
public:
529
  MCDwarfLineAddrFragment(int64_t LineDelta, const MCExpr &AddrDelta,
530
                          MCSection *Sec = nullptr)
531
      : MCEncodedFragmentWithFixups<8, 1>(FT_Dwarf, false, Sec),
532
965k
        LineDelta(LineDelta), AddrDelta(&AddrDelta) {}
533
534
  /// \name Accessors
535
  /// @{
536
537
2.89M
  int64_t getLineDelta() const { return LineDelta; }
538
539
2.89M
  const MCExpr &getAddrDelta() const { return *AddrDelta; }
540
541
  /// @}
542
543
1.58M
  static bool classof(const MCFragment *F) {
544
1.58M
    return F->getKind() == MCFragment::FT_Dwarf;
545
1.58M
  }
546
};
547
548
class MCDwarfCallFrameFragment : public MCEncodedFragmentWithFixups<8, 1> {
549
  /// AddrDelta - The expression for the difference of the two symbols that
550
  /// make up the address delta between two .cfi_* dwarf directives.
551
  const MCExpr *AddrDelta;
552
553
public:
554
  MCDwarfCallFrameFragment(const MCExpr &AddrDelta, MCSection *Sec = nullptr)
555
      : MCEncodedFragmentWithFixups<8, 1>(FT_DwarfFrame, false, Sec),
556
131k
        AddrDelta(&AddrDelta) {}
557
558
  /// \name Accessors
559
  /// @{
560
561
393k
  const MCExpr &getAddrDelta() const { return *AddrDelta; }
562
563
  /// @}
564
565
131k
  static bool classof(const MCFragment *F) {
566
131k
    return F->getKind() == MCFragment::FT_DwarfFrame;
567
131k
  }
568
};
569
570
/// Represents a symbol table index fragment.
571
class MCSymbolIdFragment : public MCFragment {
572
  const MCSymbol *Sym;
573
574
public:
575
  MCSymbolIdFragment(const MCSymbol *Sym, MCSection *Sec = nullptr)
576
16
      : MCFragment(FT_SymbolId, false, Sec), Sym(Sym) {}
577
578
  /// \name Accessors
579
  /// @{
580
581
0
  const MCSymbol *getSymbol() { return Sym; }
582
16
  const MCSymbol *getSymbol() const { return Sym; }
583
584
  /// @}
585
586
0
  static bool classof(const MCFragment *F) {
587
0
    return F->getKind() == MCFragment::FT_SymbolId;
588
0
  }
589
};
590
591
/// Fragment representing the binary annotations produced by the
592
/// .cv_inline_linetable directive.
593
class MCCVInlineLineTableFragment : public MCFragment {
594
  unsigned SiteFuncId;
595
  unsigned StartFileId;
596
  unsigned StartLineNum;
597
  const MCSymbol *FnStartSym;
598
  const MCSymbol *FnEndSym;
599
  SmallString<8> Contents;
600
601
  /// CodeViewContext has the real knowledge about this format, so let it access
602
  /// our members.
603
  friend class CodeViewContext;
604
605
public:
606
  MCCVInlineLineTableFragment(unsigned SiteFuncId, unsigned StartFileId,
607
                              unsigned StartLineNum, const MCSymbol *FnStartSym,
608
                              const MCSymbol *FnEndSym,
609
                              MCSection *Sec = nullptr)
610
      : MCFragment(FT_CVInlineLines, false, Sec), SiteFuncId(SiteFuncId),
611
        StartFileId(StartFileId), StartLineNum(StartLineNum),
612
33
        FnStartSym(FnStartSym), FnEndSym(FnEndSym) {}
613
614
  /// \name Accessors
615
  /// @{
616
617
198
  const MCSymbol *getFnStartSym() const { return FnStartSym; }
618
99
  const MCSymbol *getFnEndSym() const { return FnEndSym; }
619
620
297
  SmallString<8> &getContents() { return Contents; }
621
99
  const SmallString<8> &getContents() const { return Contents; }
622
623
  /// @}
624
625
0
  static bool classof(const MCFragment *F) {
626
0
    return F->getKind() == MCFragment::FT_CVInlineLines;
627
0
  }
628
};
629
630
/// Fragment representing the .cv_def_range directive.
631
class MCCVDefRangeFragment : public MCEncodedFragmentWithFixups<32, 4> {
632
  SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 2> Ranges;
633
  SmallString<32> FixedSizePortion;
634
635
  /// CodeViewContext has the real knowledge about this format, so let it access
636
  /// our members.
637
  friend class CodeViewContext;
638
639
public:
640
  MCCVDefRangeFragment(
641
      ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
642
      StringRef FixedSizePortion, MCSection *Sec = nullptr)
643
      : MCEncodedFragmentWithFixups<32, 4>(FT_CVDefRange, false, Sec),
644
        Ranges(Ranges.begin(), Ranges.end()),
645
358
        FixedSizePortion(FixedSizePortion) {}
646
647
  /// \name Accessors
648
  /// @{
649
3.22k
  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> getRanges() const {
650
3.22k
    return Ranges;
651
3.22k
  }
652
653
1.08k
  StringRef getFixedSizePortion() const { return FixedSizePortion; }
654
  /// @}
655
656
2.68M
  static bool classof(const MCFragment *F) {
657
2.68M
    return F->getKind() == MCFragment::FT_CVDefRange;
658
2.68M
  }
659
};
660
661
} // end namespace llvm
662
663
#endif // LLVM_MC_MCFRAGMENT_H