Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/Bitcode/BitstreamWriter.h
Line
Count
Source (jump to first uncovered line)
1
//===- BitstreamWriter.h - Low-level bitstream writer interface -*- 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 header defines the BitstreamWriter class.  This class can be used to
11
// write an arbitrary bitstream, regardless of its contents.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_BITCODE_BITSTREAMWRITER_H
16
#define LLVM_BITCODE_BITSTREAMWRITER_H
17
18
#include "llvm/ADT/ArrayRef.h"
19
#include "llvm/ADT/Optional.h"
20
#include "llvm/ADT/SmallVector.h"
21
#include "llvm/ADT/StringRef.h"
22
#include "llvm/Bitcode/BitCodes.h"
23
#include "llvm/Support/Endian.h"
24
#include <vector>
25
26
namespace llvm {
27
28
class BitstreamWriter {
29
  SmallVectorImpl<char> &Out;
30
31
  /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use.
32
  unsigned CurBit;
33
34
  /// CurValue - The current value.  Only bits < CurBit are valid.
35
  uint32_t CurValue;
36
37
  /// CurCodeSize - This is the declared size of code values used for the
38
  /// current block, in bits.
39
  unsigned CurCodeSize;
40
41
  /// BlockInfoCurBID - When emitting a BLOCKINFO_BLOCK, this is the currently
42
  /// selected BLOCK ID.
43
  unsigned BlockInfoCurBID;
44
45
  /// CurAbbrevs - Abbrevs installed at in this block.
46
  std::vector<std::shared_ptr<BitCodeAbbrev>> CurAbbrevs;
47
48
  struct Block {
49
    unsigned PrevCodeSize;
50
    size_t StartSizeWord;
51
    std::vector<std::shared_ptr<BitCodeAbbrev>> PrevAbbrevs;
52
73.7k
    Block(unsigned PCS, size_t SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {}
53
  };
54
55
  /// BlockScope - This tracks the current blocks that we have entered.
56
  std::vector<Block> BlockScope;
57
58
  /// BlockInfo - This contains information emitted to BLOCKINFO_BLOCK blocks.
59
  /// These describe abbreviations that all blocks of the specified ID inherit.
60
  struct BlockInfo {
61
    unsigned BlockID;
62
    std::vector<std::shared_ptr<BitCodeAbbrev>> Abbrevs;
63
  };
64
  std::vector<BlockInfo> BlockInfoRecords;
65
66
145M
  void WriteByte(unsigned char Value) {
67
145M
    Out.push_back(Value);
68
145M
  }
69
70
18.5M
  void WriteWord(unsigned Value) {
71
18.5M
    Value = support::endian::byte_swap<uint32_t, support::little>(Value);
72
18.5M
    Out.append(reinterpret_cast<const char *>(&Value),
73
18.5M
               reinterpret_cast<const char *>(&Value + 1));
74
18.5M
  }
75
76
3.36M
  size_t GetBufferOffset() const { return Out.size(); }
77
78
147k
  size_t GetWordIndex() const {
79
147k
    size_t Offset = GetBufferOffset();
80
147k
    assert((Offset & 3) == 0 && "Not 32-bit aligned");
81
147k
    return Offset / 4;
82
147k
  }
83
84
public:
85
  explicit BitstreamWriter(SmallVectorImpl<char> &O)
86
7.26k
    : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
87
88
7.25k
  ~BitstreamWriter() {
89
7.25k
    assert(CurBit == 0 && "Unflushed data remaining");
90
7.25k
    assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance");
91
7.25k
  }
92
93
  /// \brief Retrieve the current position in the stream, in bits.
94
3.05M
  uint64_t GetCurrentBitNo() const { return GetBufferOffset() * 8 + CurBit; }
95
96
  /// \brief Retrieve the number of bits currently used to encode an abbrev ID.
97
0
  unsigned GetAbbrevIDWidth() const { return CurCodeSize; }
98
99
  //===--------------------------------------------------------------------===//
100
  // Basic Primitives for emitting bits to the stream.
101
  //===--------------------------------------------------------------------===//
102
103
  /// Backpatch a 32-bit word in the output at the given bit offset
104
  /// with the specified value.
105
77.1k
  void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
106
77.1k
    using namespace llvm::support;
107
77.1k
    unsigned ByteNo = BitNo / 8;
108
77.1k
    assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
109
77.1k
               &Out[ByteNo], BitNo & 7)) &&
110
77.1k
           "Expected to be patching over 0-value placeholders");
111
77.1k
    endian::writeAtBitAlignment<uint32_t, little, unaligned>(
112
77.1k
        &Out[ByteNo], NewWord, BitNo & 7);
113
77.1k
  }
114
115
81
  void BackpatchWord64(uint64_t BitNo, uint64_t Val) {
116
81
    BackpatchWord(BitNo, (uint32_t)Val);
117
81
    BackpatchWord(BitNo + 32, (uint32_t)(Val >> 32));
118
81
  }
119
120
101M
  void Emit(uint32_t Val, unsigned NumBits) {
121
101M
    assert(NumBits && NumBits <= 32 && "Invalid value size!");
122
101M
    assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!");
123
101M
    CurValue |= Val << CurBit;
124
101M
    if (
CurBit + NumBits < 32101M
) {
125
83.3M
      CurBit += NumBits;
126
83.3M
      return;
127
83.3M
    }
128
101M
129
101M
    // Add the current word.
130
18.2M
    WriteWord(CurValue);
131
18.2M
132
18.2M
    if (CurBit)
133
18.2M
      CurValue = Val >> (32-CurBit);
134
18.2M
    else
135
72.1k
      CurValue = 0;
136
101M
    CurBit = (CurBit+NumBits) & 31;
137
101M
  }
138
139
258k
  void FlushToWord() {
140
258k
    if (
CurBit258k
) {
141
251k
      WriteWord(CurValue);
142
251k
      CurBit = 0;
143
251k
      CurValue = 0;
144
251k
    }
145
258k
  }
146
147
51.5M
  void EmitVBR(uint32_t Val, unsigned NumBits) {
148
51.5M
    assert(NumBits <= 32 && "Too many bits to emit!");
149
51.5M
    uint32_t Threshold = 1U << (NumBits-1);
150
51.5M
151
51.5M
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
152
91.5M
    while (
Val >= Threshold91.5M
) {
153
39.9M
      Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
154
39.9M
      Val >>= NumBits-1;
155
39.9M
    }
156
51.5M
157
51.5M
    Emit(Val, NumBits);
158
51.5M
  }
159
160
44.6M
  void EmitVBR64(uint64_t Val, unsigned NumBits) {
161
44.6M
    assert(NumBits <= 32 && "Too many bits to emit!");
162
44.6M
    if ((uint32_t)Val == Val)
163
44.6M
      return EmitVBR((uint32_t)Val, NumBits);
164
44.6M
165
1.26k
    uint32_t Threshold = 1U << (NumBits-1);
166
1.26k
167
1.26k
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
168
16.6k
    while (
Val >= Threshold16.6k
) {
169
15.4k
      Emit(((uint32_t)Val & ((1 << (NumBits-1))-1)) |
170
15.4k
           (1 << (NumBits-1)), NumBits);
171
15.4k
      Val >>= NumBits-1;
172
15.4k
    }
173
44.6M
174
44.6M
    Emit((uint32_t)Val, NumBits);
175
44.6M
  }
176
177
  /// EmitCode - Emit the specified code.
178
4.44M
  void EmitCode(unsigned Val) {
179
4.44M
    Emit(Val, CurCodeSize);
180
4.44M
  }
181
182
  //===--------------------------------------------------------------------===//
183
  // Block Manipulation
184
  //===--------------------------------------------------------------------===//
185
186
  /// getBlockInfo - If there is block info for the specified ID, return it,
187
  /// otherwise return null.
188
125k
  BlockInfo *getBlockInfo(unsigned BlockID) {
189
125k
    // Common case, the most recent entry matches BlockID.
190
125k
    if (
!BlockInfoRecords.empty() && 125k
BlockInfoRecords.back().BlockID == BlockID88.2k
)
191
48.6k
      return &BlockInfoRecords.back();
192
125k
193
76.9k
    for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
194
155k
         
i != e155k
;
++i78.8k
)
195
90.3k
      
if (90.3k
BlockInfoRecords[i].BlockID == BlockID90.3k
)
196
11.5k
        return &BlockInfoRecords[i];
197
65.4k
    return nullptr;
198
125k
  }
199
200
73.7k
  void EnterSubblock(unsigned BlockID, unsigned CodeLen) {
201
73.7k
    // Block header:
202
73.7k
    //    [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
203
73.7k
    EmitCode(bitc::ENTER_SUBBLOCK);
204
73.7k
    EmitVBR(BlockID, bitc::BlockIDWidth);
205
73.7k
    EmitVBR(CodeLen, bitc::CodeLenWidth);
206
73.7k
    FlushToWord();
207
73.7k
208
73.7k
    size_t BlockSizeWordIndex = GetWordIndex();
209
73.7k
    unsigned OldCodeSize = CurCodeSize;
210
73.7k
211
73.7k
    // Emit a placeholder, which will be replaced when the block is popped.
212
73.7k
    Emit(0, bitc::BlockSizeWidth);
213
73.7k
214
73.7k
    CurCodeSize = CodeLen;
215
73.7k
216
73.7k
    // Push the outer block's abbrev set onto the stack, start out with an
217
73.7k
    // empty abbrev set.
218
73.7k
    BlockScope.emplace_back(OldCodeSize, BlockSizeWordIndex);
219
73.7k
    BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
220
73.7k
221
73.7k
    // If there is a blockinfo for this BlockID, add all the predefined abbrevs
222
73.7k
    // to the abbrev list.
223
73.7k
    if (BlockInfo *
Info73.7k
= getBlockInfo(BlockID)) {
224
18.0k
      CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
225
18.0k
                        Info->Abbrevs.end());
226
18.0k
    }
227
73.7k
  }
228
229
73.7k
  void ExitBlock() {
230
73.7k
    assert(!BlockScope.empty() && "Block scope imbalance!");
231
73.7k
    const Block &B = BlockScope.back();
232
73.7k
233
73.7k
    // Block tail:
234
73.7k
    //    [END_BLOCK, <align4bytes>]
235
73.7k
    EmitCode(bitc::END_BLOCK);
236
73.7k
    FlushToWord();
237
73.7k
238
73.7k
    // Compute the size of the block, in words, not counting the size field.
239
73.7k
    size_t SizeInWords = GetWordIndex() - B.StartSizeWord - 1;
240
73.7k
    uint64_t BitNo = uint64_t(B.StartSizeWord) * 32;
241
73.7k
242
73.7k
    // Update the block size field in the header of this sub-block.
243
73.7k
    BackpatchWord(BitNo, SizeInWords);
244
73.7k
245
73.7k
    // Restore the inner block's code size and abbrev table.
246
73.7k
    CurCodeSize = B.PrevCodeSize;
247
73.7k
    CurAbbrevs = std::move(B.PrevAbbrevs);
248
73.7k
    BlockScope.pop_back();
249
73.7k
  }
250
251
  //===--------------------------------------------------------------------===//
252
  // Record Emission
253
  //===--------------------------------------------------------------------===//
254
255
private:
256
  /// EmitAbbreviatedLiteral - Emit a literal value according to its abbrev
257
  /// record.  This is a no-op, since the abbrev specifies the literal to use.
258
  template<typename uintty>
259
4.09M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
4.09M
    assert(Op.isLiteral() && "Not a literal");
261
4.09M
    // If the abbrev specifies the literal value to use, don't emit
262
4.09M
    // anything.
263
4.09M
    assert(V == Op.getLiteralValue() &&
264
4.09M
           "Invalid abbrev for record!");
265
4.09M
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned long long>(llvm::BitCodeAbbrevOp const&, unsigned long long)
Line
Count
Source
259
3.55M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
3.55M
    assert(Op.isLiteral() && "Not a literal");
261
3.55M
    // If the abbrev specifies the literal value to use, don't emit
262
3.55M
    // anything.
263
3.55M
    assert(V == Op.getLiteralValue() &&
264
3.55M
           "Invalid abbrev for record!");
265
3.55M
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
259
548k
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
548k
    assert(Op.isLiteral() && "Not a literal");
261
548k
    // If the abbrev specifies the literal value to use, don't emit
262
548k
    // anything.
263
548k
    assert(V == Op.getLiteralValue() &&
264
548k
           "Invalid abbrev for record!");
265
548k
  }
266
267
  /// EmitAbbreviatedField - Emit a single scalar field value with the specified
268
  /// encoding.
269
  template<typename uintty>
270
6.81M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
6.81M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
6.81M
273
6.81M
    // Encode the value as we are commanded.
274
6.81M
    switch (Op.getEncoding()) {
275
0
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
3.12M
    case BitCodeAbbrevOp::Fixed:
277
3.12M
      if (Op.getEncodingData())
278
3.12M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
3.12M
      break;
280
3.39M
    case BitCodeAbbrevOp::VBR:
281
3.39M
      if (Op.getEncodingData())
282
3.39M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.39M
      break;
284
297k
    case BitCodeAbbrevOp::Char6:
285
297k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
297k
      break;
287
6.81M
    }
288
6.81M
  }
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned long long>(llvm::BitCodeAbbrevOp const&, unsigned long long)
Line
Count
Source
270
6.43M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
6.43M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
6.43M
273
6.43M
    // Encode the value as we are commanded.
274
6.43M
    switch (Op.getEncoding()) {
275
0
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
2.85M
    case BitCodeAbbrevOp::Fixed:
277
2.85M
      if (Op.getEncodingData())
278
2.85M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
2.85M
      break;
280
3.34M
    case BitCodeAbbrevOp::VBR:
281
3.34M
      if (Op.getEncodingData())
282
3.34M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.34M
      break;
284
234k
    case BitCodeAbbrevOp::Char6:
285
234k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
234k
      break;
287
6.43M
    }
288
6.43M
  }
Unexecuted instantiation: void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned char>(llvm::BitCodeAbbrevOp const&, unsigned char)
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
270
388k
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
388k
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
388k
273
388k
    // Encode the value as we are commanded.
274
388k
    switch (Op.getEncoding()) {
275
0
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
277k
    case BitCodeAbbrevOp::Fixed:
277
277k
      if (Op.getEncodingData())
278
277k
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
277k
      break;
280
47.8k
    case BitCodeAbbrevOp::VBR:
281
47.8k
      if (Op.getEncodingData())
282
47.8k
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
47.8k
      break;
284
62.5k
    case BitCodeAbbrevOp::Char6:
285
62.5k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
62.5k
      break;
287
388k
    }
288
388k
  }
289
290
  /// EmitRecordWithAbbrevImpl - This is the core implementation of the record
291
  /// emission code.  If BlobData is non-null, then it specifies an array of
292
  /// data that should be emitted as part of the Blob or Array operand that is
293
  /// known to exist at the end of the record. If Code is specified, then
294
  /// it is the record code to emit before the Vals, which must not contain
295
  /// the code.
296
  template <typename uintty>
297
  void EmitRecordWithAbbrevImpl(unsigned Abbrev, ArrayRef<uintty> Vals,
298
928k
                                StringRef Blob, Optional<unsigned> Code) {
299
928k
    const char *BlobData = Blob.data();
300
928k
    unsigned BlobLen = (unsigned) Blob.size();
301
928k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
928k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
928k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
928k
305
928k
    EmitCode(Abbrev);
306
928k
307
928k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
928k
    if (
Code928k
) {
309
545k
      assert(e && "Expected non-empty abbreviation");
310
545k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
545k
312
545k
      if (Op.isLiteral())
313
545k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
25
      else {
315
25
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
25
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
25
               "Expected literal or scalar");
318
25
        EmitAbbreviatedField(Op, Code.getValue());
319
25
      }
320
545k
    }
321
928k
322
928k
    unsigned RecordIdx = 0;
323
10.7M
    for (; 
i != e10.7M
;
++i9.80M
) {
324
9.80M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
9.80M
      if (
Op.isLiteral()9.80M
) {
326
3.55M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.55M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.55M
        ++RecordIdx;
329
9.80M
      } else 
if (6.25M
Op.getEncoding() == BitCodeAbbrevOp::Array6.25M
) {
330
182k
        // Array case.
331
182k
        assert(i + 2 == e && "array op not second to last?");
332
182k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
182k
334
182k
        // If this record has blob data, emit it, otherwise we must have record
335
182k
        // entries to encode this way.
336
182k
        if (
BlobData182k
) {
337
0
          assert(RecordIdx == Vals.size() &&
338
0
                 "Blob data and record entries specified for array!");
339
0
          // Emit a vbr6 to indicate the number of elements present.
340
0
          EmitVBR(static_cast<uint32_t>(BlobLen), 6);
341
0
342
0
          // Emit each field.
343
0
          for (unsigned i = 0; 
i != BlobLen0
;
++i0
)
344
0
            EmitAbbreviatedField(EltEnc, (unsigned char)BlobData[i]);
345
0
346
0
          // Know that blob data is consumed for assertion below.
347
0
          BlobData = nullptr;
348
182k
        } else {
349
182k
          // Emit a vbr6 to indicate the number of elements present.
350
182k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
182k
352
182k
          // Emit each field.
353
1.04M
          for (unsigned e = Vals.size(); 
RecordIdx != e1.04M
;
++RecordIdx858k
)
354
858k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
182k
        }
356
6.25M
      } else 
if (6.06M
Op.getEncoding() == BitCodeAbbrevOp::Blob6.06M
) {
357
107k
        // If this record has blob data, emit it, otherwise we must have record
358
107k
        // entries to encode this way.
359
107k
360
107k
        if (
BlobData107k
) {
361
106k
          assert(RecordIdx == Vals.size() &&
362
106k
                 "Blob data and record entries specified for blob operand!");
363
106k
364
106k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
106k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
106k
          emitBlob(Blob);
367
106k
          BlobData = nullptr;
368
107k
        } else {
369
1.23k
          emitBlob(Vals.slice(RecordIdx));
370
1.23k
        }
371
6.06M
      } else {  // Single scalar field.
372
5.96M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
5.96M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
5.96M
        ++RecordIdx;
375
5.96M
      }
376
9.80M
    }
377
928k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
928k
    assert(BlobData == nullptr &&
379
928k
           "Blob data specified for record that doesn't use it!");
380
928k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned long long>(unsigned int, llvm::ArrayRef<unsigned long long>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
298
892k
                                StringRef Blob, Optional<unsigned> Code) {
299
892k
    const char *BlobData = Blob.data();
300
892k
    unsigned BlobLen = (unsigned) Blob.size();
301
892k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
892k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
892k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
892k
305
892k
    EmitCode(Abbrev);
306
892k
307
892k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
892k
    if (
Code892k
) {
309
509k
      assert(e && "Expected non-empty abbreviation");
310
509k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
509k
312
509k
      if (Op.isLiteral())
313
509k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
28
      else {
315
28
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
28
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
28
               "Expected literal or scalar");
318
28
        EmitAbbreviatedField(Op, Code.getValue());
319
28
      }
320
509k
    }
321
892k
322
892k
    unsigned RecordIdx = 0;
323
10.6M
    for (; 
i != e10.6M
;
++i9.71M
) {
324
9.71M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
9.71M
      if (
Op.isLiteral()9.71M
) {
326
3.55M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.55M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.55M
        ++RecordIdx;
329
9.71M
      } else 
if (6.16M
Op.getEncoding() == BitCodeAbbrevOp::Array6.16M
) {
330
171k
        // Array case.
331
171k
        assert(i + 2 == e && "array op not second to last?");
332
171k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
171k
334
171k
        // If this record has blob data, emit it, otherwise we must have record
335
171k
        // entries to encode this way.
336
171k
        if (
BlobData171k
) {
337
0
          assert(RecordIdx == Vals.size() &&
338
0
                 "Blob data and record entries specified for array!");
339
0
          // Emit a vbr6 to indicate the number of elements present.
340
0
          EmitVBR(static_cast<uint32_t>(BlobLen), 6);
341
0
342
0
          // Emit each field.
343
0
          for (unsigned i = 0; 
i != BlobLen0
;
++i0
)
344
0
            EmitAbbreviatedField(EltEnc, (unsigned char)BlobData[i]);
345
0
346
0
          // Know that blob data is consumed for assertion below.
347
0
          BlobData = nullptr;
348
171k
        } else {
349
171k
          // Emit a vbr6 to indicate the number of elements present.
350
171k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
171k
352
171k
          // Emit each field.
353
719k
          for (unsigned e = Vals.size(); 
RecordIdx != e719k
;
++RecordIdx547k
)
354
547k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
171k
        }
356
6.16M
      } else 
if (5.99M
Op.getEncoding() == BitCodeAbbrevOp::Blob5.99M
) {
357
107k
        // If this record has blob data, emit it, otherwise we must have record
358
107k
        // entries to encode this way.
359
107k
360
107k
        if (
BlobData107k
) {
361
106k
          assert(RecordIdx == Vals.size() &&
362
106k
                 "Blob data and record entries specified for blob operand!");
363
106k
364
106k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
106k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
106k
          emitBlob(Blob);
367
106k
          BlobData = nullptr;
368
107k
        } else {
369
1.23k
          emitBlob(Vals.slice(RecordIdx));
370
1.23k
        }
371
5.99M
      } else {  // Single scalar field.
372
5.88M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
5.88M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
5.88M
        ++RecordIdx;
375
5.88M
      }
376
9.71M
    }
377
892k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
892k
    assert(BlobData == nullptr &&
379
892k
           "Blob data specified for record that doesn't use it!");
380
892k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned int>(unsigned int, llvm::ArrayRef<unsigned int>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
298
36.1k
                                StringRef Blob, Optional<unsigned> Code) {
299
36.1k
    const char *BlobData = Blob.data();
300
36.1k
    unsigned BlobLen = (unsigned) Blob.size();
301
36.1k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
36.1k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
36.1k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
36.1k
305
36.1k
    EmitCode(Abbrev);
306
36.1k
307
36.1k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
36.1k
    if (
Code36.1k
) {
309
36.1k
      assert(e && "Expected non-empty abbreviation");
310
36.1k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
36.1k
312
36.1k
      if (Op.isLiteral())
313
36.1k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
18.4E
      else {
315
18.4E
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
18.4E
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
18.4E
               "Expected literal or scalar");
318
18.4E
        EmitAbbreviatedField(Op, Code.getValue());
319
18.4E
      }
320
36.1k
    }
321
36.1k
322
36.1k
    unsigned RecordIdx = 0;
323
127k
    for (; 
i != e127k
;
++i91.4k
) {
324
91.4k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
91.4k
      if (
Op.isLiteral()91.4k
) {
326
3.31k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.31k
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.31k
        ++RecordIdx;
329
91.4k
      } else 
if (88.1k
Op.getEncoding() == BitCodeAbbrevOp::Array88.1k
) {
330
10.9k
        // Array case.
331
10.9k
        assert(i + 2 == e && "array op not second to last?");
332
10.9k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
10.9k
334
10.9k
        // If this record has blob data, emit it, otherwise we must have record
335
10.9k
        // entries to encode this way.
336
10.9k
        if (
BlobData10.9k
) {
337
0
          assert(RecordIdx == Vals.size() &&
338
0
                 "Blob data and record entries specified for array!");
339
0
          // Emit a vbr6 to indicate the number of elements present.
340
0
          EmitVBR(static_cast<uint32_t>(BlobLen), 6);
341
0
342
0
          // Emit each field.
343
0
          for (unsigned i = 0; 
i != BlobLen0
;
++i0
)
344
0
            EmitAbbreviatedField(EltEnc, (unsigned char)BlobData[i]);
345
0
346
0
          // Know that blob data is consumed for assertion below.
347
0
          BlobData = nullptr;
348
10.9k
        } else {
349
10.9k
          // Emit a vbr6 to indicate the number of elements present.
350
10.9k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
10.9k
352
10.9k
          // Emit each field.
353
322k
          for (unsigned e = Vals.size(); 
RecordIdx != e322k
;
++RecordIdx311k
)
354
311k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
10.9k
        }
356
88.1k
      } else 
if (77.1k
Op.getEncoding() == BitCodeAbbrevOp::Blob77.1k
) {
357
45
        // If this record has blob data, emit it, otherwise we must have record
358
45
        // entries to encode this way.
359
45
360
45
        if (
BlobData45
) {
361
45
          assert(RecordIdx == Vals.size() &&
362
45
                 "Blob data and record entries specified for blob operand!");
363
45
364
45
          assert(Blob.data() == BlobData && "BlobData got moved");
365
45
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
45
          emitBlob(Blob);
367
45
          BlobData = nullptr;
368
45
        } else {
369
0
          emitBlob(Vals.slice(RecordIdx));
370
0
        }
371
77.1k
      } else {  // Single scalar field.
372
77.0k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
77.0k
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
77.0k
        ++RecordIdx;
375
77.0k
      }
376
91.4k
    }
377
36.1k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
36.1k
    assert(BlobData == nullptr &&
379
36.1k
           "Blob data specified for record that doesn't use it!");
380
36.1k
  }
381
382
public:
383
  /// Emit a blob, including flushing before and tail-padding.
384
  template <class UIntTy>
385
107k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
107k
    // Emit a vbr6 to indicate the number of elements present.
387
107k
    if (ShouldEmitSize)
388
107k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
107k
390
107k
    // Flush to a 32-bit alignment boundary.
391
107k
    FlushToWord();
392
107k
393
107k
    // Emit literal bytes.
394
145M
    for (const auto &B : Bytes) {
395
145M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
145M
      WriteByte((unsigned char)B);
397
145M
    }
398
107k
399
107k
    // Align end to 32-bits.
400
156k
    while (GetBufferOffset() & 3)
401
48.8k
      WriteByte(0);
402
107k
  }
void llvm::BitstreamWriter::emitBlob<unsigned char>(llvm::ArrayRef<unsigned char>, bool)
Line
Count
Source
385
106k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
106k
    // Emit a vbr6 to indicate the number of elements present.
387
106k
    if (ShouldEmitSize)
388
106k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
106k
390
106k
    // Flush to a 32-bit alignment boundary.
391
106k
    FlushToWord();
392
106k
393
106k
    // Emit literal bytes.
394
145M
    for (const auto &B : Bytes) {
395
145M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
145M
      WriteByte((unsigned char)B);
397
145M
    }
398
106k
399
106k
    // Align end to 32-bits.
400
155k
    while (GetBufferOffset() & 3)
401
48.8k
      WriteByte(0);
402
106k
  }
void llvm::BitstreamWriter::emitBlob<unsigned long long>(llvm::ArrayRef<unsigned long long>, bool)
Line
Count
Source
385
1.23k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
1.23k
    // Emit a vbr6 to indicate the number of elements present.
387
1.23k
    if (ShouldEmitSize)
388
1.23k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
1.23k
390
1.23k
    // Flush to a 32-bit alignment boundary.
391
1.23k
    FlushToWord();
392
1.23k
393
1.23k
    // Emit literal bytes.
394
0
    for (const auto &B : Bytes) {
395
0
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
0
      WriteByte((unsigned char)B);
397
0
    }
398
1.23k
399
1.23k
    // Align end to 32-bits.
400
1.23k
    while (GetBufferOffset() & 3)
401
0
      WriteByte(0);
402
1.23k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::emitBlob<unsigned int>(llvm::ArrayRef<unsigned int>, bool)
403
106k
  void emitBlob(StringRef Bytes, bool ShouldEmitSize = true) {
404
106k
    emitBlob(makeArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
405
106k
             ShouldEmitSize);
406
106k
  }
407
408
  /// EmitRecord - Emit the specified record to the stream, using an abbrev if
409
  /// we have one to compress the output.
410
  template <typename Container>
411
3.71M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.71M
    if (
!Abbrev3.71M
) {
413
3.16M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.16M
      // form.
415
3.16M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.16M
      EmitCode(bitc::UNABBREV_RECORD);
417
3.16M
      EmitVBR(Code, 6);
418
3.16M
      EmitVBR(Count, 6);
419
43.2M
      for (unsigned i = 0, e = Count; 
i != e43.2M
;
++i40.0M
)
420
40.0M
        EmitVBR64(Vals[i], 6);
421
3.16M
      return;
422
3.16M
    }
423
3.71M
424
545k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
545k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned int> >(unsigned int, llvm::SmallVectorImpl<unsigned int> const&, unsigned int)
Line
Count
Source
411
51.4k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
51.4k
    if (
!Abbrev51.4k
) {
413
29.7k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
29.7k
      // form.
415
29.7k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
29.7k
      EmitCode(bitc::UNABBREV_RECORD);
417
29.7k
      EmitVBR(Code, 6);
418
29.7k
      EmitVBR(Count, 6);
419
147k
      for (unsigned i = 0, e = Count; 
i != e147k
;
++i117k
)
420
117k
        EmitVBR64(Vals[i], 6);
421
29.7k
      return;
422
29.7k
    }
423
51.4k
424
21.6k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
21.6k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned long long, 128u> >(unsigned int, llvm::SmallVector<unsigned long long, 128u> const&, unsigned int)
Line
Count
Source
411
500
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
500
    if (
!Abbrev500
) {
413
500
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
500
      // form.
415
500
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
500
      EmitCode(bitc::UNABBREV_RECORD);
417
500
      EmitVBR(Code, 6);
418
500
      EmitVBR(Count, 6);
419
2.91k
      for (unsigned i = 0, e = Count; 
i != e2.91k
;
++i2.41k
)
420
2.41k
        EmitVBR64(Vals[i], 6);
421
500
      return;
422
500
    }
423
500
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned long long, 4u> >(unsigned int, llvm::SmallVector<unsigned long long, 4u> const&, unsigned int)
Line
Count
Source
411
77
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
77
    if (
!Abbrev77
) {
413
77
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
77
      // form.
415
77
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
77
      EmitCode(bitc::UNABBREV_RECORD);
417
77
      EmitVBR(Code, 6);
418
77
      EmitVBR(Count, 6);
419
342
      for (unsigned i = 0, e = Count; 
i != e342
;
++i265
)
420
265
        EmitVBR64(Vals[i], 6);
421
77
      return;
422
77
    }
423
77
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<std::__1::vector<unsigned long long, std::__1::allocator<unsigned long long> > >(unsigned int, std::__1::vector<unsigned long long, std::__1::allocator<unsigned long long> > const&, unsigned int)
Line
Count
Source
411
81
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
81
    if (
!Abbrev81
) {
413
0
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
0
      // form.
415
0
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
0
      EmitCode(bitc::UNABBREV_RECORD);
417
0
      EmitVBR(Code, 6);
418
0
      EmitVBR(Count, 6);
419
0
      for (unsigned i = 0, e = Count; 
i != e0
;
++i0
)
420
0
        EmitVBR64(Vals[i], 6);
421
0
      return;
422
0
    }
423
81
424
81
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
81
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, unsigned int)
Line
Count
Source
411
4.17k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
4.17k
    if (
!Abbrev4.17k
) {
413
4.17k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
4.17k
      // form.
415
4.17k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
4.17k
      EmitCode(bitc::UNABBREV_RECORD);
417
4.17k
      EmitVBR(Code, 6);
418
4.17k
      EmitVBR(Count, 6);
419
8.81k
      for (unsigned i = 0, e = Count; 
i != e8.81k
;
++i4.63k
)
420
4.63k
        EmitVBR64(Vals[i], 6);
421
4.17k
      return;
422
4.17k
    }
423
4.17k
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 1u> >(unsigned int, llvm::SmallVector<unsigned int, 1u> const&, unsigned int)
Line
Count
Source
411
3.22k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.22k
    if (
!Abbrev3.22k
) {
413
0
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
0
      // form.
415
0
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
0
      EmitCode(bitc::UNABBREV_RECORD);
417
0
      EmitVBR(Code, 6);
418
0
      EmitVBR(Count, 6);
419
0
      for (unsigned i = 0, e = Count; 
i != e0
;
++i0
)
420
0
        EmitVBR64(Vals[i], 6);
421
0
      return;
422
0
    }
423
3.22k
424
3.22k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
3.22k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 64u> >(unsigned int, llvm::SmallVector<unsigned int, 64u> const&, unsigned int)
Line
Count
Source
411
34.4k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
34.4k
    if (
!Abbrev34.4k
) {
413
23.2k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
23.2k
      // form.
415
23.2k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
23.2k
      EmitCode(bitc::UNABBREV_RECORD);
417
23.2k
      EmitVBR(Code, 6);
418
23.2k
      EmitVBR(Count, 6);
419
326k
      for (unsigned i = 0, e = Count; 
i != e326k
;
++i303k
)
420
303k
        EmitVBR64(Vals[i], 6);
421
23.2k
      return;
422
23.2k
    }
423
34.4k
424
11.2k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
11.2k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned long long, 2u> >(unsigned int, llvm::SmallVector<unsigned long long, 2u> const&, unsigned int)
Line
Count
Source
411
1.69k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.69k
    if (
!Abbrev1.69k
) {
413
1.69k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.69k
      // form.
415
1.69k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.69k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.69k
      EmitVBR(Code, 6);
418
1.69k
      EmitVBR(Count, 6);
419
200k
      for (unsigned i = 0, e = Count; 
i != e200k
;
++i198k
)
420
198k
        EmitVBR64(Vals[i], 6);
421
1.69k
      return;
422
1.69k
    }
423
1.69k
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned int> >(unsigned int, llvm::ArrayRef<unsigned int> const&, unsigned int)
Line
Count
Source
411
75.2k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
75.2k
    if (
!Abbrev75.2k
) {
413
75.2k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
75.2k
      // form.
415
75.2k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
75.2k
      EmitCode(bitc::UNABBREV_RECORD);
417
75.2k
      EmitVBR(Code, 6);
418
75.2k
      EmitVBR(Count, 6);
419
75.3k
      for (unsigned i = 0, e = Count; 
i != e75.3k
;
++i35
)
420
35
        EmitVBR64(Vals[i], 6);
421
75.2k
      return;
422
75.2k
    }
423
75.2k
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [4]>(unsigned int, unsigned long long const (&) [4], unsigned int)
Line
Count
Source
411
2.13k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
2.13k
    if (
!Abbrev2.13k
) {
413
2.13k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
2.13k
      // form.
415
2.13k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
2.13k
      EmitCode(bitc::UNABBREV_RECORD);
417
2.13k
      EmitVBR(Code, 6);
418
2.13k
      EmitVBR(Count, 6);
419
10.6k
      for (unsigned i = 0, e = Count; 
i != e10.6k
;
++i8.54k
)
420
8.54k
        EmitVBR64(Vals[i], 6);
421
2.13k
      return;
422
2.13k
    }
423
2.13k
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned long long, 16u> >(unsigned int, llvm::SmallVector<unsigned long long, 16u> const&, unsigned int)
Line
Count
Source
411
655
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
655
    if (
!Abbrev655
) {
413
655
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
655
      // form.
415
655
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
655
      EmitCode(bitc::UNABBREV_RECORD);
417
655
      EmitVBR(Code, 6);
418
655
      EmitVBR(Count, 6);
419
2.63k
      for (unsigned i = 0, e = Count; 
i != e2.63k
;
++i1.97k
)
420
1.97k
        EmitVBR64(Vals[i], 6);
421
655
      return;
422
655
    }
423
655
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], unsigned int)
Line
Count
Source
411
7.79k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
7.79k
    if (
!Abbrev7.79k
) {
413
1.26k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.26k
      // form.
415
1.26k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.26k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.26k
      EmitVBR(Code, 6);
418
1.26k
      EmitVBR(Count, 6);
419
3.80k
      for (unsigned i = 0, e = Count; 
i != e3.80k
;
++i2.53k
)
420
2.53k
        EmitVBR64(Vals[i], 6);
421
1.26k
      return;
422
1.26k
    }
423
7.79k
424
6.53k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
6.53k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], unsigned int)
Line
Count
Source
411
2.14k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
2.14k
    if (
!Abbrev2.14k
) {
413
2.14k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
2.14k
      // form.
415
2.14k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
2.14k
      EmitCode(bitc::UNABBREV_RECORD);
417
2.14k
      EmitVBR(Code, 6);
418
2.14k
      EmitVBR(Count, 6);
419
4.28k
      for (unsigned i = 0, e = Count; 
i != e4.28k
;
++i2.14k
)
420
2.14k
        EmitVBR64(Vals[i], 6);
421
2.14k
      return;
422
2.14k
    }
423
2.14k
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<unsigned int [5]>(unsigned int, unsigned int const (&) [5], unsigned int)
Line
Count
Source
411
72
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
72
    if (
!Abbrev72
) {
413
72
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
72
      // form.
415
72
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
72
      EmitCode(bitc::UNABBREV_RECORD);
417
72
      EmitVBR(Code, 6);
418
72
      EmitVBR(Count, 6);
419
432
      for (unsigned i = 0, e = Count; 
i != e432
;
++i360
)
420
360
        EmitVBR64(Vals[i], 6);
421
72
      return;
422
72
    }
423
72
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, unsigned int)
Line
Count
Source
411
1.79M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.79M
    if (
!Abbrev1.79M
) {
413
1.36M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.36M
      // form.
415
1.36M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.36M
      EmitCode(bitc::UNABBREV_RECORD);
417
1.36M
      EmitVBR(Code, 6);
418
1.36M
      EmitVBR(Count, 6);
419
30.8M
      for (unsigned i = 0, e = Count; 
i != e30.8M
;
++i29.5M
)
420
29.5M
        EmitVBR64(Vals[i], 6);
421
1.36M
      return;
422
1.36M
    }
423
1.79M
424
432k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
432k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 2u> >(unsigned int, llvm::SmallVector<unsigned int, 2u> const&, unsigned int)
Line
Count
Source
411
9.73k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
9.73k
    if (
!Abbrev9.73k
) {
413
9.73k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
9.73k
      // form.
415
9.73k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
9.73k
      EmitCode(bitc::UNABBREV_RECORD);
417
9.73k
      EmitVBR(Code, 6);
418
9.73k
      EmitVBR(Count, 6);
419
19.4k
      for (unsigned i = 0, e = Count; 
i != e19.4k
;
++i9.73k
)
420
9.73k
        EmitVBR64(Vals[i], 6);
421
9.73k
      return;
422
9.73k
    }
423
9.73k
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned long long, 64u> >(unsigned int, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int)
Line
Count
Source
411
1.72M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.72M
    if (
!Abbrev1.72M
) {
413
1.64M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.64M
      // form.
415
1.64M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.64M
      EmitCode(bitc::UNABBREV_RECORD);
417
1.64M
      EmitVBR(Code, 6);
418
1.64M
      EmitVBR(Count, 6);
419
11.5M
      for (unsigned i = 0, e = Count; 
i != e11.5M
;
++i9.89M
)
420
9.89M
        EmitVBR64(Vals[i], 6);
421
1.64M
      return;
422
1.64M
    }
423
1.72M
424
70.4k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
70.4k
  }
426
427
  /// EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
428
  /// Unlike EmitRecord, the code for the record should be included in Vals as
429
  /// the first entry.
430
  template <typename Container>
431
275k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
275k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
275k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::EmitRecordWithAbbrev<unsigned long long [9]>(unsigned int, unsigned long long const (&) [9])
void llvm::BitstreamWriter::EmitRecordWithAbbrev<llvm::SmallVector<unsigned long long, 64u> >(unsigned int, llvm::SmallVector<unsigned long long, 64u> const&)
Line
Count
Source
431
272k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
272k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
272k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrev<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2])
Line
Count
Source
431
3.25k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
3.25k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
3.25k
  }
434
435
  /// EmitRecordWithBlob - Emit the specified record to the stream, using an
436
  /// abbrev that includes a blob at the end.  The blob data to emit is
437
  /// specified by the pointer and length specified at the end.  In contrast to
438
  /// EmitRecord, this routine expects that the first entry in Vals is the code
439
  /// of the record.
440
  template <typename Container>
441
  void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
442
104k
                          StringRef Blob) {
443
104k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
104k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
11.6k
                          StringRef Blob) {
443
11.6k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
11.6k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [12]>(unsigned int, unsigned long long const (&) [12], llvm::StringRef)
Line
Count
Source
442
2.89k
                          StringRef Blob) {
443
2.89k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
2.89k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [4]>(unsigned int, unsigned long long const (&) [4], llvm::StringRef)
Line
Count
Source
442
2.13k
                          StringRef Blob) {
443
2.13k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
2.13k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], llvm::StringRef)
Line
Count
Source
442
56.5k
                          StringRef Blob) {
443
56.5k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
56.5k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [8]>(unsigned int, unsigned long long const (&) [8], llvm::StringRef)
Line
Count
Source
442
2.13k
                          StringRef Blob) {
443
2.13k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
2.13k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], llvm::StringRef)
Line
Count
Source
442
10.4k
                          StringRef Blob) {
443
10.4k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
10.4k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::SmallVector<unsigned long long, 64u> >(unsigned int, llvm::SmallVector<unsigned long long, 64u> const&, llvm::StringRef)
Line
Count
Source
442
3.91k
                          StringRef Blob) {
443
3.91k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.91k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [10]>(unsigned int, unsigned long long const (&) [10], llvm::StringRef)
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [5]>(unsigned int, unsigned long long const (&) [5], llvm::StringRef)
Line
Count
Source
442
44
                          StringRef Blob) {
443
44
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
44
  }
Unexecuted instantiation: void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [9]>(unsigned int, unsigned long long const (&) [9], llvm::StringRef)
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [3]>(unsigned int, unsigned long long const (&) [3], llvm::StringRef)
Line
Count
Source
442
13.2k
                          StringRef Blob) {
443
13.2k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
13.2k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
1.10k
                          StringRef Blob) {
443
1.10k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
1.10k
  }
445
  template <typename Container>
446
  void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
447
3.51k
                          const char *BlobData, unsigned BlobLen) {
448
3.51k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
3.51k
                                    StringRef(BlobData, BlobLen), None);
450
3.51k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], char const*, unsigned int)
Line
Count
Source
447
2.13k
                          const char *BlobData, unsigned BlobLen) {
448
2.13k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
2.13k
                                    StringRef(BlobData, BlobLen), None);
450
2.13k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], char const*, unsigned int)
Line
Count
Source
447
1.38k
                          const char *BlobData, unsigned BlobLen) {
448
1.38k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
1.38k
                                    StringRef(BlobData, BlobLen), None);
450
1.38k
  }
451
452
  /// EmitRecordWithArray - Just like EmitRecordWithBlob, works with records
453
  /// that end with an array.
454
  template <typename Container>
455
  void EmitRecordWithArray(unsigned Abbrev, const Container &Vals,
456
                           StringRef Array) {
457
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Array, None);
458
  }
459
  template <typename Container>
460
  void EmitRecordWithArray(unsigned Abbrev, const Container &Vals,
461
                           const char *ArrayData, unsigned ArrayLen) {
462
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
463
                                    StringRef(ArrayData, ArrayLen), None);
464
  }
465
466
  //===--------------------------------------------------------------------===//
467
  // Abbrev Emission
468
  //===--------------------------------------------------------------------===//
469
470
private:
471
  // Emit the abbreviation as a DEFINE_ABBREV record.
472
206k
  void EncodeAbbrev(const BitCodeAbbrev &Abbv) {
473
206k
    EmitCode(bitc::DEFINE_ABBREV);
474
206k
    EmitVBR(Abbv.getNumOperandInfos(), 5);
475
206k
    for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos());
476
1.50M
         
i != e1.50M
;
++i1.29M
) {
477
1.29M
      const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i);
478
1.29M
      Emit(Op.isLiteral(), 1);
479
1.29M
      if (
Op.isLiteral()1.29M
) {
480
470k
        EmitVBR64(Op.getLiteralValue(), 8);
481
1.29M
      } else {
482
828k
        Emit(Op.getEncoding(), 3);
483
828k
        if (Op.hasEncodingData())
484
681k
          EmitVBR64(Op.getEncodingData(), 5);
485
828k
      }
486
1.29M
    }
487
206k
  }
488
public:
489
490
  /// EmitAbbrev - This emits an abbreviation to the stream.  Note that this
491
  /// method takes ownership of the specified abbrev.
492
154k
  unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) {
493
154k
    // Emit the abbreviation as a record.
494
154k
    EncodeAbbrev(*Abbv);
495
154k
    CurAbbrevs.push_back(std::move(Abbv));
496
154k
    return static_cast<unsigned>(CurAbbrevs.size())-1 +
497
154k
      bitc::FIRST_APPLICATION_ABBREV;
498
154k
  }
499
500
  //===--------------------------------------------------------------------===//
501
  // BlockInfo Block Emission
502
  //===--------------------------------------------------------------------===//
503
504
  /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
505
5.94k
  void EnterBlockInfoBlock() {
506
5.94k
    EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2);
507
5.94k
    BlockInfoCurBID = ~0U;
508
5.94k
    BlockInfoRecords.clear();
509
5.94k
  }
510
private:
511
  /// SwitchToBlockID - If we aren't already talking about the specified block
512
  /// ID, emit a BLOCKINFO_CODE_SETBID record.
513
51.8k
  void SwitchToBlockID(unsigned BlockID) {
514
51.8k
    if (
BlockInfoCurBID == BlockID51.8k
)
return42.0k
;
515
9.73k
    SmallVector<unsigned, 2> V;
516
9.73k
    V.push_back(BlockID);
517
9.73k
    EmitRecord(bitc::BLOCKINFO_CODE_SETBID, V);
518
9.73k
    BlockInfoCurBID = BlockID;
519
9.73k
  }
520
521
51.8k
  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
522
51.8k
    if (BlockInfo *BI = getBlockInfo(BlockID))
523
42.0k
      return *BI;
524
51.8k
525
51.8k
    // Otherwise, add a new record.
526
9.73k
    BlockInfoRecords.emplace_back();
527
9.73k
    BlockInfoRecords.back().BlockID = BlockID;
528
9.73k
    return BlockInfoRecords.back();
529
51.8k
  }
530
531
public:
532
533
  /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified
534
  /// BlockID.
535
51.8k
  unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) {
536
51.8k
    SwitchToBlockID(BlockID);
537
51.8k
    EncodeAbbrev(*Abbv);
538
51.8k
539
51.8k
    // Add the abbrev to the specified block record.
540
51.8k
    BlockInfo &Info = getOrCreateBlockInfo(BlockID);
541
51.8k
    Info.Abbrevs.push_back(std::move(Abbv));
542
51.8k
543
51.8k
    return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV;
544
51.8k
  }
545
};
546
547
548
} // End llvm namespace
549
550
#endif