Coverage Report

Created: 2018-09-23 22:08

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/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
112k
    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
319M
  void WriteByte(unsigned char Value) {
67
319M
    Out.push_back(Value);
68
319M
  }
69
70
28.4M
  void WriteWord(unsigned Value) {
71
28.4M
    Value = support::endian::byte_swap<uint32_t, support::little>(Value);
72
28.4M
    Out.append(reinterpret_cast<const char *>(&Value),
73
28.4M
               reinterpret_cast<const char *>(&Value + 1));
74
28.4M
  }
75
76
5.33M
  size_t GetBufferOffset() const { return Out.size(); }
77
78
225k
  size_t GetWordIndex() const {
79
225k
    size_t Offset = GetBufferOffset();
80
225k
    assert((Offset & 3) == 0 && "Not 32-bit aligned");
81
225k
    return Offset / 4;
82
225k
  }
83
84
public:
85
  explicit BitstreamWriter(SmallVectorImpl<char> &O)
86
10.1k
    : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
87
88
10.1k
  ~BitstreamWriter() {
89
10.1k
    assert(CurBit == 0 && "Unflushed data remaining");
90
10.1k
    assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance");
91
10.1k
  }
92
93
  /// Retrieve the current position in the stream, in bits.
94
4.88M
  uint64_t GetCurrentBitNo() const { return GetBufferOffset() * 8 + CurBit; }
95
96
  /// Retrieve the number of bits currently used to encode an abbrev ID.
97
  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
117k
  void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
106
117k
    using namespace llvm::support;
107
117k
    unsigned ByteNo = BitNo / 8;
108
117k
    assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
109
117k
               &Out[ByteNo], BitNo & 7)) &&
110
117k
           "Expected to be patching over 0-value placeholders");
111
117k
    endian::writeAtBitAlignment<uint32_t, little, unaligned>(
112
117k
        &Out[ByteNo], NewWord, BitNo & 7);
113
117k
  }
114
115
127
  void BackpatchWord64(uint64_t BitNo, uint64_t Val) {
116
127
    BackpatchWord(BitNo, (uint32_t)Val);
117
127
    BackpatchWord(BitNo + 32, (uint32_t)(Val >> 32));
118
127
  }
119
120
157M
  void Emit(uint32_t Val, unsigned NumBits) {
121
157M
    assert(NumBits && NumBits <= 32 && "Invalid value size!");
122
157M
    assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!");
123
157M
    CurValue |= Val << CurBit;
124
157M
    if (CurBit + NumBits < 32) {
125
129M
      CurBit += NumBits;
126
129M
      return;
127
129M
    }
128
28.0M
129
28.0M
    // Add the current word.
130
28.0M
    WriteWord(CurValue);
131
28.0M
132
28.0M
    if (CurBit)
133
27.9M
      CurValue = Val >> (32-CurBit);
134
108k
    else
135
108k
      CurValue = 0;
136
28.0M
    CurBit = (CurBit+NumBits) & 31;
137
28.0M
  }
138
139
392k
  void FlushToWord() {
140
392k
    if (CurBit) {
141
379k
      WriteWord(CurValue);
142
379k
      CurBit = 0;
143
379k
      CurValue = 0;
144
379k
    }
145
392k
  }
146
147
82.8M
  void EmitVBR(uint32_t Val, unsigned NumBits) {
148
82.8M
    assert(NumBits <= 32 && "Too many bits to emit!");
149
82.8M
    uint32_t Threshold = 1U << (NumBits-1);
150
82.8M
151
82.8M
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
152
140M
    while (Val >= Threshold) {
153
57.7M
      Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
154
57.7M
      Val >>= NumBits-1;
155
57.7M
    }
156
82.8M
157
82.8M
    Emit(Val, NumBits);
158
82.8M
  }
159
160
70.5M
  void EmitVBR64(uint64_t Val, unsigned NumBits) {
161
70.5M
    assert(NumBits <= 32 && "Too many bits to emit!");
162
70.5M
    if ((uint32_t)Val == Val)
163
70.5M
      return EmitVBR((uint32_t)Val, NumBits);
164
2.07k
165
2.07k
    uint32_t Threshold = 1U << (NumBits-1);
166
2.07k
167
2.07k
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
168
26.8k
    while (Val >= Threshold) {
169
24.7k
      Emit(((uint32_t)Val & ((1 << (NumBits-1))-1)) |
170
24.7k
           (1 << (NumBits-1)), NumBits);
171
24.7k
      Val >>= NumBits-1;
172
24.7k
    }
173
2.07k
174
2.07k
    Emit((uint32_t)Val, NumBits);
175
2.07k
  }
176
177
  /// EmitCode - Emit the specified code.
178
7.38M
  void EmitCode(unsigned Val) {
179
7.38M
    Emit(Val, CurCodeSize);
180
7.38M
  }
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
178k
  BlockInfo *getBlockInfo(unsigned BlockID) {
189
178k
    // Common case, the most recent entry matches BlockID.
190
178k
    if (!BlockInfoRecords.empty() && 
BlockInfoRecords.back().BlockID == BlockID123k
)
191
64.8k
      return &BlockInfoRecords.back();
192
113k
193
113k
    for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
194
222k
         i != e; 
++i109k
)
195
130k
      if (BlockInfoRecords[i].BlockID == BlockID)
196
20.7k
        return &BlockInfoRecords[i];
197
113k
    
return nullptr92.8k
;
198
113k
  }
199
200
112k
  void EnterSubblock(unsigned BlockID, unsigned CodeLen) {
201
112k
    // Block header:
202
112k
    //    [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
203
112k
    EmitCode(bitc::ENTER_SUBBLOCK);
204
112k
    EmitVBR(BlockID, bitc::BlockIDWidth);
205
112k
    EmitVBR(CodeLen, bitc::CodeLenWidth);
206
112k
    FlushToWord();
207
112k
208
112k
    size_t BlockSizeWordIndex = GetWordIndex();
209
112k
    unsigned OldCodeSize = CurCodeSize;
210
112k
211
112k
    // Emit a placeholder, which will be replaced when the block is popped.
212
112k
    Emit(0, bitc::BlockSizeWidth);
213
112k
214
112k
    CurCodeSize = CodeLen;
215
112k
216
112k
    // Push the outer block's abbrev set onto the stack, start out with an
217
112k
    // empty abbrev set.
218
112k
    BlockScope.emplace_back(OldCodeSize, BlockSizeWordIndex);
219
112k
    BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
220
112k
221
112k
    // If there is a blockinfo for this BlockID, add all the predefined abbrevs
222
112k
    // to the abbrev list.
223
112k
    if (BlockInfo *Info = getBlockInfo(BlockID)) {
224
32.2k
      CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
225
32.2k
                        Info->Abbrevs.end());
226
32.2k
    }
227
112k
  }
228
229
112k
  void ExitBlock() {
230
112k
    assert(!BlockScope.empty() && "Block scope imbalance!");
231
112k
    const Block &B = BlockScope.back();
232
112k
233
112k
    // Block tail:
234
112k
    //    [END_BLOCK, <align4bytes>]
235
112k
    EmitCode(bitc::END_BLOCK);
236
112k
    FlushToWord();
237
112k
238
112k
    // Compute the size of the block, in words, not counting the size field.
239
112k
    size_t SizeInWords = GetWordIndex() - B.StartSizeWord - 1;
240
112k
    uint64_t BitNo = uint64_t(B.StartSizeWord) * 32;
241
112k
242
112k
    // Update the block size field in the header of this sub-block.
243
112k
    BackpatchWord(BitNo, SizeInWords);
244
112k
245
112k
    // Restore the inner block's code size and abbrev table.
246
112k
    CurCodeSize = B.PrevCodeSize;
247
112k
    CurAbbrevs = std::move(B.PrevAbbrevs);
248
112k
    BlockScope.pop_back();
249
112k
  }
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
3.86M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
3.86M
    assert(Op.isLiteral() && "Not a literal");
261
3.86M
    // If the abbrev specifies the literal value to use, don't emit
262
3.86M
    // anything.
263
3.86M
    assert(V == Op.getLiteralValue() &&
264
3.86M
           "Invalid abbrev for record!");
265
3.86M
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
259
877k
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
877k
    assert(Op.isLiteral() && "Not a literal");
261
877k
    // If the abbrev specifies the literal value to use, don't emit
262
877k
    // anything.
263
877k
    assert(V == Op.getLiteralValue() &&
264
877k
           "Invalid abbrev for record!");
265
877k
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned long long>(llvm::BitCodeAbbrevOp const&, unsigned long long)
Line
Count
Source
259
2.98M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
2.98M
    assert(Op.isLiteral() && "Not a literal");
261
2.98M
    // If the abbrev specifies the literal value to use, don't emit
262
2.98M
    // anything.
263
2.98M
    assert(V == Op.getLiteralValue() &&
264
2.98M
           "Invalid abbrev for record!");
265
2.98M
  }
266
267
  /// EmitAbbreviatedField - Emit a single scalar field value with the specified
268
  /// encoding.
269
  template<typename uintty>
270
9.60M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
9.60M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
9.60M
273
9.60M
    // Encode the value as we are commanded.
274
9.60M
    switch (Op.getEncoding()) {
275
9.60M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
9.60M
    case BitCodeAbbrevOp::Fixed:
277
5.50M
      if (Op.getEncodingData())
278
5.50M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
5.50M
      break;
280
9.60M
    case BitCodeAbbrevOp::VBR:
281
3.19M
      if (Op.getEncodingData())
282
3.19M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.19M
      break;
284
9.60M
    case BitCodeAbbrevOp::Char6:
285
913k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
913k
      break;
287
9.60M
    }
288
9.60M
  }
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
270
688k
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
688k
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
688k
273
688k
    // Encode the value as we are commanded.
274
688k
    switch (Op.getEncoding()) {
275
688k
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
688k
    case BitCodeAbbrevOp::Fixed:
277
445k
      if (Op.getEncodingData())
278
445k
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
445k
      break;
280
688k
    case BitCodeAbbrevOp::VBR:
281
148k
      if (Op.getEncodingData())
282
148k
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
148k
      break;
284
688k
    case BitCodeAbbrevOp::Char6:
285
94.0k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
94.0k
      break;
287
688k
    }
288
688k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned char>(llvm::BitCodeAbbrevOp const&, unsigned char)
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned long long>(llvm::BitCodeAbbrevOp const&, unsigned long long)
Line
Count
Source
270
8.92M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
8.92M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
8.92M
273
8.92M
    // Encode the value as we are commanded.
274
8.92M
    switch (Op.getEncoding()) {
275
8.92M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
8.92M
    case BitCodeAbbrevOp::Fixed:
277
5.05M
      if (Op.getEncodingData())
278
5.05M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
5.05M
      break;
280
8.92M
    case BitCodeAbbrevOp::VBR:
281
3.04M
      if (Op.getEncodingData())
282
3.04M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.04M
      break;
284
8.92M
    case BitCodeAbbrevOp::Char6:
285
819k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
819k
      break;
287
8.92M
    }
288
8.92M
  }
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
1.19M
                                StringRef Blob, Optional<unsigned> Code) {
299
1.19M
    const char *BlobData = Blob.data();
300
1.19M
    unsigned BlobLen = (unsigned) Blob.size();
301
1.19M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
1.19M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
1.19M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
1.19M
305
1.19M
    EmitCode(Abbrev);
306
1.19M
307
1.19M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
1.19M
    if (Code) {
309
874k
      assert(e && "Expected non-empty abbreviation");
310
874k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
874k
312
874k
      if (Op.isLiteral())
313
874k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
32
      else {
315
32
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
32
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
32
               "Expected literal or scalar");
318
32
        EmitAbbreviatedField(Op, Code.getValue());
319
32
      }
320
874k
    }
321
1.19M
322
1.19M
    unsigned RecordIdx = 0;
323
12.6M
    for (; i != e; 
++i11.4M
) {
324
11.4M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
11.4M
      if (Op.isLiteral()) {
326
2.98M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
2.98M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
2.98M
        ++RecordIdx;
329
8.44M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
234k
        // Array case.
331
234k
        assert(i + 2 == e && "array op not second to last?");
332
234k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
234k
334
234k
        // If this record has blob data, emit it, otherwise we must have record
335
234k
        // entries to encode this way.
336
234k
        if (BlobData) {
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 != BlobLen; ++i)
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
234k
        } else {
349
234k
          // Emit a vbr6 to indicate the number of elements present.
350
234k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
234k
352
234k
          // Emit each field.
353
1.79M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.56M
)
354
1.56M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
234k
        }
356
8.20M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
357
161k
        // If this record has blob data, emit it, otherwise we must have record
358
161k
        // entries to encode this way.
359
161k
360
161k
        if (BlobData) {
361
159k
          assert(RecordIdx == Vals.size() &&
362
159k
                 "Blob data and record entries specified for blob operand!");
363
159k
364
159k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
159k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
159k
          emitBlob(Blob);
367
159k
          BlobData = nullptr;
368
159k
        } else {
369
1.46k
          emitBlob(Vals.slice(RecordIdx));
370
1.46k
        }
371
8.04M
      } else {  // Single scalar field.
372
8.04M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
8.04M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
8.04M
        ++RecordIdx;
375
8.04M
      }
376
11.4M
    }
377
1.19M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
1.19M
    assert(BlobData == nullptr &&
379
1.19M
           "Blob data specified for record that doesn't use it!");
380
1.19M
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned long long>(unsigned int, llvm::ArrayRef<unsigned long long>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
298
1.10M
                                StringRef Blob, Optional<unsigned> Code) {
299
1.10M
    const char *BlobData = Blob.data();
300
1.10M
    unsigned BlobLen = (unsigned) Blob.size();
301
1.10M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
1.10M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
1.10M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
1.10M
305
1.10M
    EmitCode(Abbrev);
306
1.10M
307
1.10M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
1.10M
    if (Code) {
309
782k
      assert(e && "Expected non-empty abbreviation");
310
782k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
782k
312
782k
      if (Op.isLiteral())
313
782k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
31
      else {
315
31
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
31
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
31
               "Expected literal or scalar");
318
31
        EmitAbbreviatedField(Op, Code.getValue());
319
31
      }
320
782k
    }
321
1.10M
322
1.10M
    unsigned RecordIdx = 0;
323
12.2M
    for (; i != e; 
++i11.1M
) {
324
11.1M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
11.1M
      if (Op.isLiteral()) {
326
2.98M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
2.98M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
2.98M
        ++RecordIdx;
329
8.16M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
213k
        // Array case.
331
213k
        assert(i + 2 == e && "array op not second to last?");
332
213k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
213k
334
213k
        // If this record has blob data, emit it, otherwise we must have record
335
213k
        // entries to encode this way.
336
213k
        if (BlobData) {
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 != BlobLen; ++i)
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
213k
        } else {
349
213k
          // Emit a vbr6 to indicate the number of elements present.
350
213k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
213k
352
213k
          // Emit each field.
353
1.34M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.12M
)
354
1.12M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
213k
        }
356
7.95M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
357
161k
        // If this record has blob data, emit it, otherwise we must have record
358
161k
        // entries to encode this way.
359
161k
360
161k
        if (BlobData) {
361
159k
          assert(RecordIdx == Vals.size() &&
362
159k
                 "Blob data and record entries specified for blob operand!");
363
159k
364
159k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
159k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
159k
          emitBlob(Blob);
367
159k
          BlobData = nullptr;
368
159k
        } else {
369
1.46k
          emitBlob(Vals.slice(RecordIdx));
370
1.46k
        }
371
7.79M
      } else {  // Single scalar field.
372
7.79M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
7.79M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
7.79M
        ++RecordIdx;
375
7.79M
      }
376
11.1M
    }
377
1.10M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
1.10M
    assert(BlobData == nullptr &&
379
1.10M
           "Blob data specified for record that doesn't use it!");
380
1.10M
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned int>(unsigned int, llvm::ArrayRef<unsigned int>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
298
92.5k
                                StringRef Blob, Optional<unsigned> Code) {
299
92.5k
    const char *BlobData = Blob.data();
300
92.5k
    unsigned BlobLen = (unsigned) Blob.size();
301
92.5k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
92.5k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
92.5k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
92.5k
305
92.5k
    EmitCode(Abbrev);
306
92.5k
307
92.5k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
92.5k
    if (Code) {
309
92.4k
      assert(e && "Expected non-empty abbreviation");
310
92.4k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
92.4k
312
92.4k
      if (Op.isLiteral())
313
92.4k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
1
      else {
315
1
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
1
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
1
               "Expected literal or scalar");
318
1
        EmitAbbreviatedField(Op, Code.getValue());
319
1
      }
320
92.4k
    }
321
92.5k
322
92.5k
    unsigned RecordIdx = 0;
323
372k
    for (; i != e; 
++i280k
) {
324
280k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
280k
      if (Op.isLiteral()) {
326
3.49k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.49k
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.49k
        ++RecordIdx;
329
276k
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
21.5k
        // Array case.
331
21.5k
        assert(i + 2 == e && "array op not second to last?");
332
21.5k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
21.5k
334
21.5k
        // If this record has blob data, emit it, otherwise we must have record
335
21.5k
        // entries to encode this way.
336
21.5k
        if (BlobData) {
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 != BlobLen; ++i)
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
21.5k
        } else {
349
21.5k
          // Emit a vbr6 to indicate the number of elements present.
350
21.5k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
21.5k
352
21.5k
          // Emit each field.
353
455k
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx433k
)
354
433k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
21.5k
        }
356
255k
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
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 (BlobData) {
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
255k
      } else {  // Single scalar field.
372
255k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
255k
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
255k
        ++RecordIdx;
375
255k
      }
376
280k
    }
377
92.5k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
92.5k
    assert(BlobData == nullptr &&
379
92.5k
           "Blob data specified for record that doesn't use it!");
380
92.5k
  }
381
382
public:
383
  /// Emit a blob, including flushing before and tail-padding.
384
  template <class UIntTy>
385
161k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
161k
    // Emit a vbr6 to indicate the number of elements present.
387
161k
    if (ShouldEmitSize)
388
161k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
161k
390
161k
    // Flush to a 32-bit alignment boundary.
391
161k
    FlushToWord();
392
161k
393
161k
    // Emit literal bytes.
394
319M
    for (const auto &B : Bytes) {
395
319M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
319M
      WriteByte((unsigned char)B);
397
319M
    }
398
161k
399
161k
    // Align end to 32-bits.
400
227k
    while (GetBufferOffset() & 3)
401
66.1k
      WriteByte(0);
402
161k
  }
void llvm::BitstreamWriter::emitBlob<unsigned char>(llvm::ArrayRef<unsigned char>, bool)
Line
Count
Source
385
159k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
159k
    // Emit a vbr6 to indicate the number of elements present.
387
159k
    if (ShouldEmitSize)
388
159k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
159k
390
159k
    // Flush to a 32-bit alignment boundary.
391
159k
    FlushToWord();
392
159k
393
159k
    // Emit literal bytes.
394
319M
    for (const auto &B : Bytes) {
395
319M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
319M
      WriteByte((unsigned char)B);
397
319M
    }
398
159k
399
159k
    // Align end to 32-bits.
400
226k
    while (GetBufferOffset() & 3)
401
66.1k
      WriteByte(0);
402
159k
  }
void llvm::BitstreamWriter::emitBlob<unsigned long long>(llvm::ArrayRef<unsigned long long>, bool)
Line
Count
Source
385
1.46k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
1.46k
    // Emit a vbr6 to indicate the number of elements present.
387
1.46k
    if (ShouldEmitSize)
388
1.46k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
1.46k
390
1.46k
    // Flush to a 32-bit alignment boundary.
391
1.46k
    FlushToWord();
392
1.46k
393
1.46k
    // Emit literal bytes.
394
1.46k
    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.46k
399
1.46k
    // Align end to 32-bits.
400
1.46k
    while (GetBufferOffset() & 3)
401
0
      WriteByte(0);
402
1.46k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::emitBlob<unsigned int>(llvm::ArrayRef<unsigned int>, bool)
403
159k
  void emitBlob(StringRef Bytes, bool ShouldEmitSize = true) {
404
159k
    emitBlob(makeArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
405
159k
             ShouldEmitSize);
406
159k
  }
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
6.55M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
6.55M
    if (!Abbrev) {
413
5.67M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
5.67M
      // form.
415
5.67M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
5.67M
      EmitCode(bitc::UNABBREV_RECORD);
417
5.67M
      EmitVBR(Code, 6);
418
5.67M
      EmitVBR(Count, 6);
419
71.2M
      for (unsigned i = 0, e = Count; i != e; 
++i65.5M
)
420
65.5M
        EmitVBR64(Vals[i], 6);
421
5.67M
      return;
422
5.67M
    }
423
874k
424
874k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
874k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, unsigned int)
Line
Count
Source
411
2.81M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
2.81M
    if (!Abbrev) {
413
2.21M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
2.21M
      // form.
415
2.21M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
2.21M
      EmitCode(bitc::UNABBREV_RECORD);
417
2.21M
      EmitVBR(Code, 6);
418
2.21M
      EmitVBR(Count, 6);
419
49.1M
      for (unsigned i = 0, e = Count; i != e; 
++i46.9M
)
420
46.9M
        EmitVBR64(Vals[i], 6);
421
2.21M
      return;
422
2.21M
    }
423
602k
424
602k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
602k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 2u> >(unsigned int, llvm::SmallVector<unsigned int, 2u> const&, unsigned int)
Line
Count
Source
411
12.3k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
12.3k
    if (!Abbrev) {
413
12.3k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
12.3k
      // form.
415
12.3k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
12.3k
      EmitCode(bitc::UNABBREV_RECORD);
417
12.3k
      EmitVBR(Code, 6);
418
12.3k
      EmitVBR(Count, 6);
419
24.6k
      for (unsigned i = 0, e = Count; i != e; 
++i12.3k
)
420
12.3k
        EmitVBR64(Vals[i], 6);
421
12.3k
      return;
422
12.3k
    }
423
0
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
3.33M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.33M
    if (!Abbrev) {
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
20.5M
      for (unsigned i = 0, e = Count; i != e; 
++i17.3M
)
420
17.3M
        EmitVBR64(Vals[i], 6);
421
3.16M
      return;
422
3.16M
    }
423
168k
424
168k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
168k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], unsigned int)
Line
Count
Source
411
3.50k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.50k
    if (!Abbrev) {
413
3.50k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.50k
      // form.
415
3.50k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.50k
      EmitCode(bitc::UNABBREV_RECORD);
417
3.50k
      EmitVBR(Code, 6);
418
3.50k
      EmitVBR(Count, 6);
419
7.00k
      for (unsigned i = 0, e = Count; i != e; 
++i3.50k
)
420
3.50k
        EmitVBR64(Vals[i], 6);
421
3.50k
      return;
422
3.50k
    }
423
0
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
12.9k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
12.9k
    if (!Abbrev) {
413
1.41k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.41k
      // form.
415
1.41k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.41k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.41k
      EmitVBR(Code, 6);
418
1.41k
      EmitVBR(Count, 6);
419
4.25k
      for (unsigned i = 0, e = Count; i != e; 
++i2.83k
)
420
2.83k
        EmitVBR64(Vals[i], 6);
421
1.41k
      return;
422
1.41k
    }
423
11.5k
424
11.5k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
11.5k
  }
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
1.85k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.85k
    if (!Abbrev) {
413
1.85k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.85k
      // form.
415
1.85k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.85k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.85k
      EmitVBR(Code, 6);
418
1.85k
      EmitVBR(Count, 6);
419
7.56k
      for (unsigned i = 0, e = Count; i != e; 
++i5.71k
)
420
5.71k
        EmitVBR64(Vals[i], 6);
421
1.85k
      return;
422
1.85k
    }
423
0
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
3.49k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.49k
    if (!Abbrev) {
413
3.49k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.49k
      // form.
415
3.49k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.49k
      EmitCode(bitc::UNABBREV_RECORD);
417
3.49k
      EmitVBR(Code, 6);
418
3.49k
      EmitVBR(Count, 6);
419
17.4k
      for (unsigned i = 0, e = Count; i != e; 
++i13.9k
)
420
13.9k
        EmitVBR64(Vals[i], 6);
421
3.49k
      return;
422
3.49k
    }
423
0
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
122k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
122k
    if (!Abbrev) {
413
122k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
122k
      // form.
415
122k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
122k
      EmitCode(bitc::UNABBREV_RECORD);
417
122k
      EmitVBR(Code, 6);
418
122k
      EmitVBR(Count, 6);
419
122k
      for (unsigned i = 0, e = Count; i != e; 
++i40
)
420
40
        EmitVBR64(Vals[i], 6);
421
122k
      return;
422
122k
    }
423
0
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
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.82k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.82k
    if (!Abbrev) {
413
1.82k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.82k
      // form.
415
1.82k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.82k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.82k
      EmitVBR(Code, 6);
418
1.82k
      EmitVBR(Count, 6);
419
212k
      for (unsigned i = 0, e = Count; i != e; 
++i210k
)
420
210k
        EmitVBR64(Vals[i], 6);
421
1.82k
      return;
422
1.82k
    }
423
0
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 64u> >(unsigned int, llvm::SmallVector<unsigned int, 64u> const&, unsigned int)
Line
Count
Source
411
57.6k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
57.6k
    if (!Abbrev) {
413
40.9k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
40.9k
      // form.
415
40.9k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
40.9k
      EmitCode(bitc::UNABBREV_RECORD);
417
40.9k
      EmitVBR(Code, 6);
418
40.9k
      EmitVBR(Count, 6);
419
588k
      for (unsigned i = 0, e = Count; i != e; 
++i547k
)
420
547k
        EmitVBR64(Vals[i], 6);
421
40.9k
      return;
422
40.9k
    }
423
16.7k
424
16.7k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
16.7k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 1u> >(unsigned int, llvm::SmallVector<unsigned int, 1u> const&, unsigned int)
Line
Count
Source
411
4.09k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
4.09k
    if (!Abbrev) {
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 != e; ++i)
420
0
        EmitVBR64(Vals[i], 6);
421
0
      return;
422
0
    }
423
4.09k
424
4.09k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
4.09k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, unsigned int)
Line
Count
Source
411
5.64k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
5.64k
    if (!Abbrev) {
413
5.64k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
5.64k
      // form.
415
5.64k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
5.64k
      EmitCode(bitc::UNABBREV_RECORD);
417
5.64k
      EmitVBR(Code, 6);
418
5.64k
      EmitVBR(Count, 6);
419
11.9k
      for (unsigned i = 0, e = Count; i != e; 
++i6.28k
)
420
6.28k
        EmitVBR64(Vals[i], 6);
421
5.64k
      return;
422
5.64k
    }
423
0
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
127
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
127
    if (!Abbrev) {
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 != e; ++i)
420
0
        EmitVBR64(Vals[i], 6);
421
0
      return;
422
0
    }
423
127
424
127
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
127
  }
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
118
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
118
    if (!Abbrev) {
413
118
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
118
      // form.
415
118
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
118
      EmitCode(bitc::UNABBREV_RECORD);
417
118
      EmitVBR(Code, 6);
418
118
      EmitVBR(Count, 6);
419
534
      for (unsigned i = 0, e = Count; i != e; 
++i416
)
420
416
        EmitVBR64(Vals[i], 6);
421
118
      return;
422
118
    }
423
0
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
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
1.70k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.70k
    if (!Abbrev) {
413
1.70k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.70k
      // form.
415
1.70k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.70k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.70k
      EmitVBR(Code, 6);
418
1.70k
      EmitVBR(Count, 6);
419
10.1k
      for (unsigned i = 0, e = Count; i != e; 
++i8.42k
)
420
8.42k
        EmitVBR64(Vals[i], 6);
421
1.70k
      return;
422
1.70k
    }
423
0
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned int> >(unsigned int, llvm::SmallVectorImpl<unsigned int> const&, unsigned int)
Line
Count
Source
411
171k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
171k
    if (!Abbrev) {
413
99.9k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
99.9k
      // form.
415
99.9k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
99.9k
      EmitCode(bitc::UNABBREV_RECORD);
417
99.9k
      EmitVBR(Code, 6);
418
99.9k
      EmitVBR(Count, 6);
419
491k
      for (unsigned i = 0, e = Count; i != e; 
++i391k
)
420
391k
        EmitVBR64(Vals[i], 6);
421
99.9k
      return;
422
99.9k
    }
423
71.6k
424
71.6k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
71.6k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned int [5]>(unsigned int, unsigned int const (&) [5], unsigned int)
Line
Count
Source
411
88
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
88
    if (!Abbrev) {
413
88
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
88
      // form.
415
88
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
88
      EmitCode(bitc::UNABBREV_RECORD);
417
88
      EmitVBR(Code, 6);
418
88
      EmitVBR(Count, 6);
419
528
      for (unsigned i = 0, e = Count; i != e; 
++i440
)
420
440
        EmitVBR64(Vals[i], 6);
421
88
      return;
422
88
    }
423
0
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
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
158k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
158k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
158k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrev<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2])
Line
Count
Source
431
4.12k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
4.12k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
4.12k
  }
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
154k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
154k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
154k
  }
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
156k
                          StringRef Blob) {
443
156k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
156k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [3]>(unsigned int, unsigned long long const (&) [3], llvm::StringRef)
Line
Count
Source
442
21.3k
                          StringRef Blob) {
443
21.3k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
21.3k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [9]>(unsigned int, unsigned long long const (&) [9], llvm::StringRef)
Line
Count
Source
442
3.49k
                          StringRef Blob) {
443
3.49k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.49k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [5]>(unsigned int, unsigned long long const (&) [5], llvm::StringRef)
Line
Count
Source
442
46
                          StringRef Blob) {
443
46
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
46
  }
Unexecuted instantiation: void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [10]>(unsigned int, unsigned long long const (&) [10], llvm::StringRef)
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
5.30k
                          StringRef Blob) {
443
5.30k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
5.30k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], llvm::StringRef)
Line
Count
Source
442
16.0k
                          StringRef Blob) {
443
16.0k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
16.0k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], llvm::StringRef)
Line
Count
Source
442
86.6k
                          StringRef Blob) {
443
86.6k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
86.6k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [4]>(unsigned int, unsigned long long const (&) [4], llvm::StringRef)
Line
Count
Source
442
3.49k
                          StringRef Blob) {
443
3.49k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.49k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [13]>(unsigned int, unsigned long long const (&) [13], llvm::StringRef)
Line
Count
Source
442
3.25k
                          StringRef Blob) {
443
3.25k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.25k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
14.9k
                          StringRef Blob) {
443
14.9k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
14.9k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
1.70k
                          StringRef Blob) {
443
1.70k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
1.70k
  }
445
  template <typename Container>
446
  void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
447
5.03k
                          const char *BlobData, unsigned BlobLen) {
448
5.03k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
5.03k
                                    StringRef(BlobData, BlobLen), None);
450
5.03k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], char const*, unsigned int)
Line
Count
Source
447
3.49k
                          const char *BlobData, unsigned BlobLen) {
448
3.49k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
3.49k
                                    StringRef(BlobData, BlobLen), None);
450
3.49k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], char const*, unsigned int)
Line
Count
Source
447
1.54k
                          const char *BlobData, unsigned BlobLen) {
448
1.54k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
1.54k
                                    StringRef(BlobData, BlobLen), None);
450
1.54k
  }
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
289k
  void EncodeAbbrev(const BitCodeAbbrev &Abbv) {
473
289k
    EmitCode(bitc::DEFINE_ABBREV);
474
289k
    EmitVBR(Abbv.getNumOperandInfos(), 5);
475
289k
    for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos());
476
2.31M
         i != e; 
++i2.02M
) {
477
2.02M
      const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i);
478
2.02M
      Emit(Op.isLiteral(), 1);
479
2.02M
      if (Op.isLiteral()) {
480
725k
        EmitVBR64(Op.getLiteralValue(), 8);
481
1.30M
      } else {
482
1.30M
        Emit(Op.getEncoding(), 3);
483
1.30M
        if (Op.hasEncodingData())
484
1.09M
          EmitVBR64(Op.getEncodingData(), 5);
485
1.30M
      }
486
2.02M
    }
487
289k
  }
488
public:
489
490
  /// EmitAbbrev - This emits an abbreviation to the stream.  Note that this
491
  /// method takes ownership of the specified abbrev.
492
223k
  unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) {
493
223k
    // Emit the abbreviation as a record.
494
223k
    EncodeAbbrev(*Abbv);
495
223k
    CurAbbrevs.push_back(std::move(Abbv));
496
223k
    return static_cast<unsigned>(CurAbbrevs.size())-1 +
497
223k
      bitc::FIRST_APPLICATION_ABBREV;
498
223k
  }
499
500
  //===--------------------------------------------------------------------===//
501
  // BlockInfo Block Emission
502
  //===--------------------------------------------------------------------===//
503
504
  /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
505
8.22k
  void EnterBlockInfoBlock() {
506
8.22k
    EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2);
507
8.22k
    BlockInfoCurBID = ~0U;
508
8.22k
    BlockInfoRecords.clear();
509
8.22k
  }
510
private:
511
  /// SwitchToBlockID - If we aren't already talking about the specified block
512
  /// ID, emit a BLOCKINFO_CODE_SETBID record.
513
65.6k
  void SwitchToBlockID(unsigned BlockID) {
514
65.6k
    if (BlockInfoCurBID == BlockID) 
return53.3k
;
515
12.3k
    SmallVector<unsigned, 2> V;
516
12.3k
    V.push_back(BlockID);
517
12.3k
    EmitRecord(bitc::BLOCKINFO_CODE_SETBID, V);
518
12.3k
    BlockInfoCurBID = BlockID;
519
12.3k
  }
520
521
65.6k
  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
522
65.6k
    if (BlockInfo *BI = getBlockInfo(BlockID))
523
53.3k
      return *BI;
524
12.3k
525
12.3k
    // Otherwise, add a new record.
526
12.3k
    BlockInfoRecords.emplace_back();
527
12.3k
    BlockInfoRecords.back().BlockID = BlockID;
528
12.3k
    return BlockInfoRecords.back();
529
12.3k
  }
530
531
public:
532
533
  /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified
534
  /// BlockID.
535
65.6k
  unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) {
536
65.6k
    SwitchToBlockID(BlockID);
537
65.6k
    EncodeAbbrev(*Abbv);
538
65.6k
539
65.6k
    // Add the abbrev to the specified block record.
540
65.6k
    BlockInfo &Info = getOrCreateBlockInfo(BlockID);
541
65.6k
    Info.Abbrevs.push_back(std::move(Abbv));
542
65.6k
543
65.6k
    return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV;
544
65.6k
  }
545
};
546
547
548
} // End llvm namespace
549
550
#endif