Coverage Report

Created: 2018-07-19 03:59

/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
108k
    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
306M
  void WriteByte(unsigned char Value) {
67
306M
    Out.push_back(Value);
68
306M
  }
69
70
28.0M
  void WriteWord(unsigned Value) {
71
28.0M
    Value = support::endian::byte_swap<uint32_t, support::little>(Value);
72
28.0M
    Out.append(reinterpret_cast<const char *>(&Value),
73
28.0M
               reinterpret_cast<const char *>(&Value + 1));
74
28.0M
  }
75
76
5.28M
  size_t GetBufferOffset() const { return Out.size(); }
77
78
216k
  size_t GetWordIndex() const {
79
216k
    size_t Offset = GetBufferOffset();
80
216k
    assert((Offset & 3) == 0 && "Not 32-bit aligned");
81
216k
    return Offset / 4;
82
216k
  }
83
84
public:
85
  explicit BitstreamWriter(SmallVectorImpl<char> &O)
86
9.92k
    : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
87
88
9.91k
  ~BitstreamWriter() {
89
9.91k
    assert(CurBit == 0 && "Unflushed data remaining");
90
9.91k
    assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance");
91
9.91k
  }
92
93
  /// Retrieve the current position in the stream, in bits.
94
4.84M
  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
112k
  void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
106
112k
    using namespace llvm::support;
107
112k
    unsigned ByteNo = BitNo / 8;
108
112k
    assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
109
112k
               &Out[ByteNo], BitNo & 7)) &&
110
112k
           "Expected to be patching over 0-value placeholders");
111
112k
    endian::writeAtBitAlignment<uint32_t, little, unaligned>(
112
112k
        &Out[ByteNo], NewWord, BitNo & 7);
113
112k
  }
114
115
122
  void BackpatchWord64(uint64_t BitNo, uint64_t Val) {
116
122
    BackpatchWord(BitNo, (uint32_t)Val);
117
122
    BackpatchWord(BitNo + 32, (uint32_t)(Val >> 32));
118
122
  }
119
120
155M
  void Emit(uint32_t Val, unsigned NumBits) {
121
155M
    assert(NumBits && NumBits <= 32 && "Invalid value size!");
122
155M
    assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!");
123
155M
    CurValue |= Val << CurBit;
124
155M
    if (CurBit + NumBits < 32) {
125
127M
      CurBit += NumBits;
126
127M
      return;
127
127M
    }
128
27.6M
129
27.6M
    // Add the current word.
130
27.6M
    WriteWord(CurValue);
131
27.6M
132
27.6M
    if (CurBit)
133
27.5M
      CurValue = Val >> (32-CurBit);
134
105k
    else
135
105k
      CurValue = 0;
136
27.6M
    CurBit = (CurBit+NumBits) & 31;
137
27.6M
  }
138
139
380k
  void FlushToWord() {
140
380k
    if (CurBit) {
141
365k
      WriteWord(CurValue);
142
365k
      CurBit = 0;
143
365k
      CurValue = 0;
144
365k
    }
145
380k
  }
146
147
81.8M
  void EmitVBR(uint32_t Val, unsigned NumBits) {
148
81.8M
    assert(NumBits <= 32 && "Too many bits to emit!");
149
81.8M
    uint32_t Threshold = 1U << (NumBits-1);
150
81.8M
151
81.8M
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
152
138M
    while (Val >= Threshold) {
153
57.0M
      Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
154
57.0M
      Val >>= NumBits-1;
155
57.0M
    }
156
81.8M
157
81.8M
    Emit(Val, NumBits);
158
81.8M
  }
159
160
69.7M
  void EmitVBR64(uint64_t Val, unsigned NumBits) {
161
69.7M
    assert(NumBits <= 32 && "Too many bits to emit!");
162
69.7M
    if ((uint32_t)Val == Val)
163
69.7M
      return EmitVBR((uint32_t)Val, NumBits);
164
1.95k
165
1.95k
    uint32_t Threshold = 1U << (NumBits-1);
166
1.95k
167
1.95k
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
168
25.7k
    while (Val >= Threshold) {
169
23.7k
      Emit(((uint32_t)Val & ((1 << (NumBits-1))-1)) |
170
23.7k
           (1 << (NumBits-1)), NumBits);
171
23.7k
      Val >>= NumBits-1;
172
23.7k
    }
173
1.95k
174
1.95k
    Emit((uint32_t)Val, NumBits);
175
1.95k
  }
176
177
  /// EmitCode - Emit the specified code.
178
7.27M
  void EmitCode(unsigned Val) {
179
7.27M
    Emit(Val, CurCodeSize);
180
7.27M
  }
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
171k
  BlockInfo *getBlockInfo(unsigned BlockID) {
189
171k
    // Common case, the most recent entry matches BlockID.
190
171k
    if (!BlockInfoRecords.empty() && 
BlockInfoRecords.back().BlockID == BlockID117k
)
191
62.2k
      return &BlockInfoRecords.back();
192
109k
193
109k
    for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
194
213k
         i != e; 
++i103k
)
195
123k
      if (BlockInfoRecords[i].BlockID == BlockID)
196
19.3k
        return &BlockInfoRecords[i];
197
109k
    
return nullptr89.9k
;
198
109k
  }
199
200
108k
  void EnterSubblock(unsigned BlockID, unsigned CodeLen) {
201
108k
    // Block header:
202
108k
    //    [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
203
108k
    EmitCode(bitc::ENTER_SUBBLOCK);
204
108k
    EmitVBR(BlockID, bitc::BlockIDWidth);
205
108k
    EmitVBR(CodeLen, bitc::CodeLenWidth);
206
108k
    FlushToWord();
207
108k
208
108k
    size_t BlockSizeWordIndex = GetWordIndex();
209
108k
    unsigned OldCodeSize = CurCodeSize;
210
108k
211
108k
    // Emit a placeholder, which will be replaced when the block is popped.
212
108k
    Emit(0, bitc::BlockSizeWidth);
213
108k
214
108k
    CurCodeSize = CodeLen;
215
108k
216
108k
    // Push the outer block's abbrev set onto the stack, start out with an
217
108k
    // empty abbrev set.
218
108k
    BlockScope.emplace_back(OldCodeSize, BlockSizeWordIndex);
219
108k
    BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
220
108k
221
108k
    // If there is a blockinfo for this BlockID, add all the predefined abbrevs
222
108k
    // to the abbrev list.
223
108k
    if (BlockInfo *Info = getBlockInfo(BlockID)) {
224
30.0k
      CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
225
30.0k
                        Info->Abbrevs.end());
226
30.0k
    }
227
108k
  }
228
229
108k
  void ExitBlock() {
230
108k
    assert(!BlockScope.empty() && "Block scope imbalance!");
231
108k
    const Block &B = BlockScope.back();
232
108k
233
108k
    // Block tail:
234
108k
    //    [END_BLOCK, <align4bytes>]
235
108k
    EmitCode(bitc::END_BLOCK);
236
108k
    FlushToWord();
237
108k
238
108k
    // Compute the size of the block, in words, not counting the size field.
239
108k
    size_t SizeInWords = GetWordIndex() - B.StartSizeWord - 1;
240
108k
    uint64_t BitNo = uint64_t(B.StartSizeWord) * 32;
241
108k
242
108k
    // Update the block size field in the header of this sub-block.
243
108k
    BackpatchWord(BitNo, SizeInWords);
244
108k
245
108k
    // Restore the inner block's code size and abbrev table.
246
108k
    CurCodeSize = B.PrevCodeSize;
247
108k
    CurAbbrevs = std::move(B.PrevAbbrevs);
248
108k
    BlockScope.pop_back();
249
108k
  }
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.81M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
3.81M
    assert(Op.isLiteral() && "Not a literal");
261
3.81M
    // If the abbrev specifies the literal value to use, don't emit
262
3.81M
    // anything.
263
3.81M
    assert(V == Op.getLiteralValue() &&
264
3.81M
           "Invalid abbrev for record!");
265
3.81M
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
259
848k
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
848k
    assert(Op.isLiteral() && "Not a literal");
261
848k
    // If the abbrev specifies the literal value to use, don't emit
262
848k
    // anything.
263
848k
    assert(V == Op.getLiteralValue() &&
264
848k
           "Invalid abbrev for record!");
265
848k
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned long long>(llvm::BitCodeAbbrevOp const&, unsigned long long)
Line
Count
Source
259
2.96M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
2.96M
    assert(Op.isLiteral() && "Not a literal");
261
2.96M
    // If the abbrev specifies the literal value to use, don't emit
262
2.96M
    // anything.
263
2.96M
    assert(V == Op.getLiteralValue() &&
264
2.96M
           "Invalid abbrev for record!");
265
2.96M
  }
266
267
  /// EmitAbbreviatedField - Emit a single scalar field value with the specified
268
  /// encoding.
269
  template<typename uintty>
270
9.17M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
9.17M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
9.17M
273
9.17M
    // Encode the value as we are commanded.
274
9.17M
    switch (Op.getEncoding()) {
275
9.17M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
9.17M
    case BitCodeAbbrevOp::Fixed:
277
5.25M
      if (Op.getEncodingData())
278
5.25M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
5.25M
      break;
280
9.17M
    case BitCodeAbbrevOp::VBR:
281
3.14M
      if (Op.getEncodingData())
282
3.14M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.14M
      break;
284
9.17M
    case BitCodeAbbrevOp::Char6:
285
766k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
766k
      break;
287
9.17M
    }
288
9.17M
  }
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
270
644k
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
644k
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
644k
273
644k
    // Encode the value as we are commanded.
274
644k
    switch (Op.getEncoding()) {
275
644k
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
644k
    case BitCodeAbbrevOp::Fixed:
277
419k
      if (Op.getEncodingData())
278
419k
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
419k
      break;
280
644k
    case BitCodeAbbrevOp::VBR:
281
133k
      if (Op.getEncodingData())
282
133k
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
133k
      break;
284
644k
    case BitCodeAbbrevOp::Char6:
285
91.5k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
91.5k
      break;
287
644k
    }
288
644k
  }
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.52M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
8.52M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
8.52M
273
8.52M
    // Encode the value as we are commanded.
274
8.52M
    switch (Op.getEncoding()) {
275
8.52M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
8.52M
    case BitCodeAbbrevOp::Fixed:
277
4.83M
      if (Op.getEncodingData())
278
4.83M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
4.83M
      break;
280
8.52M
    case BitCodeAbbrevOp::VBR:
281
3.01M
      if (Op.getEncodingData())
282
3.01M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.01M
      break;
284
8.52M
    case BitCodeAbbrevOp::Char6:
285
675k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
675k
      break;
287
8.52M
    }
288
8.52M
  }
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.16M
                                StringRef Blob, Optional<unsigned> Code) {
299
1.16M
    const char *BlobData = Blob.data();
300
1.16M
    unsigned BlobLen = (unsigned) Blob.size();
301
1.16M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
1.16M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
1.16M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
1.16M
305
1.16M
    EmitCode(Abbrev);
306
1.16M
307
1.16M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
1.16M
    if (Code) {
309
845k
      assert(e && "Expected non-empty abbreviation");
310
845k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
845k
312
845k
      if (Op.isLiteral())
313
845k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
29
      else {
315
29
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
29
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
29
               "Expected literal or scalar");
318
29
        EmitAbbreviatedField(Op, Code.getValue());
319
29
      }
320
845k
    }
321
1.16M
322
1.16M
    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.96M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
2.96M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
2.96M
        ++RecordIdx;
329
8.15M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
220k
        // Array case.
331
220k
        assert(i + 2 == e && "array op not second to last?");
332
220k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
220k
334
220k
        // If this record has blob data, emit it, otherwise we must have record
335
220k
        // entries to encode this way.
336
220k
        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
220k
        } else {
349
220k
          // Emit a vbr6 to indicate the number of elements present.
350
220k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
220k
352
220k
          // Emit each field.
353
1.61M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.39M
)
354
1.39M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
220k
        }
356
7.93M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
357
159k
        // If this record has blob data, emit it, otherwise we must have record
358
159k
        // entries to encode this way.
359
159k
360
159k
        if (BlobData) {
361
157k
          assert(RecordIdx == Vals.size() &&
362
157k
                 "Blob data and record entries specified for blob operand!");
363
157k
364
157k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
157k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
157k
          emitBlob(Blob);
367
157k
          BlobData = nullptr;
368
157k
        } else {
369
1.41k
          emitBlob(Vals.slice(RecordIdx));
370
1.41k
        }
371
7.77M
      } else {  // Single scalar field.
372
7.77M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
7.77M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
7.77M
        ++RecordIdx;
375
7.77M
      }
376
11.1M
    }
377
1.16M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
1.16M
    assert(BlobData == nullptr &&
379
1.16M
           "Blob data specified for record that doesn't use it!");
380
1.16M
  }
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.07M
                                StringRef Blob, Optional<unsigned> Code) {
299
1.07M
    const char *BlobData = Blob.data();
300
1.07M
    unsigned BlobLen = (unsigned) Blob.size();
301
1.07M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
1.07M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
1.07M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
1.07M
305
1.07M
    EmitCode(Abbrev);
306
1.07M
307
1.07M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
1.07M
    if (Code) {
309
761k
      assert(e && "Expected non-empty abbreviation");
310
761k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
761k
312
761k
      if (Op.isLiteral())
313
761k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
30
      else {
315
30
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
30
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
30
               "Expected literal or scalar");
318
30
        EmitAbbreviatedField(Op, Code.getValue());
319
30
      }
320
761k
    }
321
1.07M
322
1.07M
    unsigned RecordIdx = 0;
323
11.9M
    for (; i != e; 
++i10.8M
) {
324
10.8M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
10.8M
      if (Op.isLiteral()) {
326
2.96M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
2.96M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
2.96M
        ++RecordIdx;
329
7.90M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
199k
        // Array case.
331
199k
        assert(i + 2 == e && "array op not second to last?");
332
199k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
199k
334
199k
        // If this record has blob data, emit it, otherwise we must have record
335
199k
        // entries to encode this way.
336
199k
        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
199k
        } else {
349
199k
          // Emit a vbr6 to indicate the number of elements present.
350
199k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
199k
352
199k
          // Emit each field.
353
1.17M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx979k
)
354
979k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
199k
        }
356
7.70M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
357
159k
        // If this record has blob data, emit it, otherwise we must have record
358
159k
        // entries to encode this way.
359
159k
360
159k
        if (BlobData) {
361
157k
          assert(RecordIdx == Vals.size() &&
362
157k
                 "Blob data and record entries specified for blob operand!");
363
157k
364
157k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
157k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
157k
          emitBlob(Blob);
367
157k
          BlobData = nullptr;
368
157k
        } else {
369
1.41k
          emitBlob(Vals.slice(RecordIdx));
370
1.41k
        }
371
7.54M
      } else {  // Single scalar field.
372
7.54M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
7.54M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
7.54M
        ++RecordIdx;
375
7.54M
      }
376
10.8M
    }
377
1.07M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
1.07M
    assert(BlobData == nullptr &&
379
1.07M
           "Blob data specified for record that doesn't use it!");
380
1.07M
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned int>(unsigned int, llvm::ArrayRef<unsigned int>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
298
84.0k
                                StringRef Blob, Optional<unsigned> Code) {
299
84.0k
    const char *BlobData = Blob.data();
300
84.0k
    unsigned BlobLen = (unsigned) Blob.size();
301
84.0k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
84.0k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
84.0k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
84.0k
305
84.0k
    EmitCode(Abbrev);
306
84.0k
307
84.0k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
84.0k
    if (Code) {
309
84.0k
      assert(e && "Expected non-empty abbreviation");
310
84.0k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
84.0k
312
84.0k
      if (Op.isLiteral())
313
84.0k
        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
84.0k
    }
321
84.0k
322
84.0k
    unsigned RecordIdx = 0;
323
333k
    for (; i != e; 
++i249k
) {
324
249k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
249k
      if (Op.isLiteral()) {
326
3.37k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.37k
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.37k
        ++RecordIdx;
329
246k
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
20.9k
        // Array case.
331
20.9k
        assert(i + 2 == e && "array op not second to last?");
332
20.9k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
20.9k
334
20.9k
        // If this record has blob data, emit it, otherwise we must have record
335
20.9k
        // entries to encode this way.
336
20.9k
        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
20.9k
        } else {
349
20.9k
          // Emit a vbr6 to indicate the number of elements present.
350
20.9k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
20.9k
352
20.9k
          // Emit each field.
353
440k
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx419k
)
354
419k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
20.9k
        }
356
225k
      } 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
225k
      } else {  // Single scalar field.
372
225k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
225k
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
225k
        ++RecordIdx;
375
225k
      }
376
249k
    }
377
84.0k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
84.0k
    assert(BlobData == nullptr &&
379
84.0k
           "Blob data specified for record that doesn't use it!");
380
84.0k
  }
381
382
public:
383
  /// Emit a blob, including flushing before and tail-padding.
384
  template <class UIntTy>
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
306M
    for (const auto &B : Bytes) {
395
306M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
306M
      WriteByte((unsigned char)B);
397
306M
    }
398
159k
399
159k
    // Align end to 32-bits.
400
223k
    while (GetBufferOffset() & 3)
401
64.2k
      WriteByte(0);
402
159k
  }
void llvm::BitstreamWriter::emitBlob<unsigned char>(llvm::ArrayRef<unsigned char>, bool)
Line
Count
Source
385
157k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
157k
    // Emit a vbr6 to indicate the number of elements present.
387
157k
    if (ShouldEmitSize)
388
157k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
157k
390
157k
    // Flush to a 32-bit alignment boundary.
391
157k
    FlushToWord();
392
157k
393
157k
    // Emit literal bytes.
394
306M
    for (const auto &B : Bytes) {
395
306M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
306M
      WriteByte((unsigned char)B);
397
306M
    }
398
157k
399
157k
    // Align end to 32-bits.
400
222k
    while (GetBufferOffset() & 3)
401
64.2k
      WriteByte(0);
402
157k
  }
void llvm::BitstreamWriter::emitBlob<unsigned long long>(llvm::ArrayRef<unsigned long long>, bool)
Line
Count
Source
385
1.41k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
1.41k
    // Emit a vbr6 to indicate the number of elements present.
387
1.41k
    if (ShouldEmitSize)
388
1.41k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
1.41k
390
1.41k
    // Flush to a 32-bit alignment boundary.
391
1.41k
    FlushToWord();
392
1.41k
393
1.41k
    // Emit literal bytes.
394
1.41k
    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.41k
399
1.41k
    // Align end to 32-bits.
400
1.41k
    while (GetBufferOffset() & 3)
401
0
      WriteByte(0);
402
1.41k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::emitBlob<unsigned int>(llvm::ArrayRef<unsigned int>, bool)
403
157k
  void emitBlob(StringRef Bytes, bool ShouldEmitSize = true) {
404
157k
    emitBlob(makeArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
405
157k
             ShouldEmitSize);
406
157k
  }
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.45M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
6.45M
    if (!Abbrev) {
413
5.61M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
5.61M
      // form.
415
5.61M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
5.61M
      EmitCode(bitc::UNABBREV_RECORD);
417
5.61M
      EmitVBR(Code, 6);
418
5.61M
      EmitVBR(Count, 6);
419
70.4M
      for (unsigned i = 0, e = Count; i != e; 
++i64.8M
)
420
64.8M
        EmitVBR64(Vals[i], 6);
421
5.61M
      return;
422
5.61M
    }
423
845k
424
845k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
845k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, unsigned int)
Line
Count
Source
411
2.79M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
2.79M
    if (!Abbrev) {
413
2.19M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
2.19M
      // form.
415
2.19M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
2.19M
      EmitCode(bitc::UNABBREV_RECORD);
417
2.19M
      EmitVBR(Code, 6);
418
2.19M
      EmitVBR(Count, 6);
419
48.7M
      for (unsigned i = 0, e = Count; i != e; 
++i46.5M
)
420
46.5M
        EmitVBR64(Vals[i], 6);
421
2.19M
      return;
422
2.19M
    }
423
599k
424
599k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
599k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 2u> >(unsigned int, llvm::SmallVector<unsigned int, 2u> const&, unsigned int)
Line
Count
Source
411
11.9k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
11.9k
    if (!Abbrev) {
413
11.9k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
11.9k
      // form.
415
11.9k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
11.9k
      EmitCode(bitc::UNABBREV_RECORD);
417
11.9k
      EmitVBR(Code, 6);
418
11.9k
      EmitVBR(Count, 6);
419
23.8k
      for (unsigned i = 0, e = Count; i != e; 
++i11.9k
)
420
11.9k
        EmitVBR64(Vals[i], 6);
421
11.9k
      return;
422
11.9k
    }
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.29M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.29M
    if (!Abbrev) {
413
3.14M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.14M
      // form.
415
3.14M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.14M
      EmitCode(bitc::UNABBREV_RECORD);
417
3.14M
      EmitVBR(Code, 6);
418
3.14M
      EmitVBR(Count, 6);
419
20.3M
      for (unsigned i = 0, e = Count; i != e; 
++i17.2M
)
420
17.2M
        EmitVBR64(Vals[i], 6);
421
3.14M
      return;
422
3.14M
    }
423
151k
424
151k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
151k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], unsigned int)
Line
Count
Source
411
3.45k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.45k
    if (!Abbrev) {
413
3.45k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.45k
      // form.
415
3.45k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.45k
      EmitCode(bitc::UNABBREV_RECORD);
417
3.45k
      EmitVBR(Code, 6);
418
3.45k
      EmitVBR(Count, 6);
419
6.91k
      for (unsigned i = 0, e = Count; i != e; 
++i3.45k
)
420
3.45k
        EmitVBR64(Vals[i], 6);
421
3.45k
      return;
422
3.45k
    }
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.0k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
12.0k
    if (!Abbrev) {
413
1.38k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.38k
      // form.
415
1.38k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.38k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.38k
      EmitVBR(Code, 6);
418
1.38k
      EmitVBR(Count, 6);
419
4.16k
      for (unsigned i = 0, e = Count; i != e; 
++i2.77k
)
420
2.77k
        EmitVBR64(Vals[i], 6);
421
1.38k
      return;
422
1.38k
    }
423
10.7k
424
10.7k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
10.7k
  }
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.84k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.84k
    if (!Abbrev) {
413
1.84k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.84k
      // form.
415
1.84k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.84k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.84k
      EmitVBR(Code, 6);
418
1.84k
      EmitVBR(Count, 6);
419
7.46k
      for (unsigned i = 0, e = Count; i != e; 
++i5.62k
)
420
5.62k
        EmitVBR64(Vals[i], 6);
421
1.84k
      return;
422
1.84k
    }
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.45k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.45k
    if (!Abbrev) {
413
3.45k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.45k
      // form.
415
3.45k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.45k
      EmitCode(bitc::UNABBREV_RECORD);
417
3.45k
      EmitVBR(Code, 6);
418
3.45k
      EmitVBR(Count, 6);
419
17.2k
      for (unsigned i = 0, e = Count; i != e; 
++i13.8k
)
420
13.8k
        EmitVBR64(Vals[i], 6);
421
3.45k
      return;
422
3.45k
    }
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
121k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
121k
    if (!Abbrev) {
413
121k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
121k
      // form.
415
121k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
121k
      EmitCode(bitc::UNABBREV_RECORD);
417
121k
      EmitVBR(Code, 6);
418
121k
      EmitVBR(Count, 6);
419
121k
      for (unsigned i = 0, e = Count; i != e; 
++i40
)
420
40
        EmitVBR64(Vals[i], 6);
421
121k
      return;
422
121k
    }
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.79k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.79k
    if (!Abbrev) {
413
1.79k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.79k
      // form.
415
1.79k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.79k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.79k
      EmitVBR(Code, 6);
418
1.79k
      EmitVBR(Count, 6);
419
208k
      for (unsigned i = 0, e = Count; i != e; 
++i206k
)
420
206k
        EmitVBR64(Vals[i], 6);
421
1.79k
      return;
422
1.79k
    }
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
54.2k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
54.2k
    if (!Abbrev) {
413
38.5k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
38.5k
      // form.
415
38.5k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
38.5k
      EmitCode(bitc::UNABBREV_RECORD);
417
38.5k
      EmitVBR(Code, 6);
418
38.5k
      EmitVBR(Count, 6);
419
537k
      for (unsigned i = 0, e = Count; i != e; 
++i499k
)
420
499k
        EmitVBR64(Vals[i], 6);
421
38.5k
      return;
422
38.5k
    }
423
15.7k
424
15.7k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
15.7k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 1u> >(unsigned int, llvm::SmallVector<unsigned int, 1u> const&, unsigned int)
Line
Count
Source
411
3.95k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.95k
    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
3.95k
424
3.95k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
3.95k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, unsigned int)
Line
Count
Source
411
5.43k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
5.43k
    if (!Abbrev) {
413
5.43k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
5.43k
      // form.
415
5.43k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
5.43k
      EmitCode(bitc::UNABBREV_RECORD);
417
5.43k
      EmitVBR(Code, 6);
418
5.43k
      EmitVBR(Count, 6);
419
11.4k
      for (unsigned i = 0, e = Count; i != e; 
++i6.04k
)
420
6.04k
        EmitVBR64(Vals[i], 6);
421
5.43k
      return;
422
5.43k
    }
423
1
424
1
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
1
  }
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
122
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
122
    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
122
424
122
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
122
  }
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
92
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
92
    if (!Abbrev) {
413
92
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
92
      // form.
415
92
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
92
      EmitCode(bitc::UNABBREV_RECORD);
417
92
      EmitVBR(Code, 6);
418
92
      EmitVBR(Count, 6);
419
410
      for (unsigned i = 0, e = Count; i != e; 
++i318
)
420
318
        EmitVBR64(Vals[i], 6);
421
92
      return;
422
92
    }
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.45k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.45k
    if (!Abbrev) {
413
1.45k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.45k
      // form.
415
1.45k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.45k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.45k
      EmitVBR(Code, 6);
418
1.45k
      EmitVBR(Count, 6);
419
8.61k
      for (unsigned i = 0, e = Count; i != e; 
++i7.15k
)
420
7.15k
        EmitVBR64(Vals[i], 6);
421
1.45k
      return;
422
1.45k
    }
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
148k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
148k
    if (!Abbrev) {
413
83.8k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
83.8k
      // form.
415
83.8k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
83.8k
      EmitCode(bitc::UNABBREV_RECORD);
417
83.8k
      EmitVBR(Code, 6);
418
83.8k
      EmitVBR(Count, 6);
419
414k
      for (unsigned i = 0, e = Count; i != e; 
++i330k
)
420
330k
        EmitVBR64(Vals[i], 6);
421
83.8k
      return;
422
83.8k
    }
423
64.3k
424
64.3k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
64.3k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned int [5]>(unsigned int, unsigned int const (&) [5], unsigned int)
Line
Count
Source
411
85
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
85
    if (!Abbrev) {
413
85
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
85
      // form.
415
85
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
85
      EmitCode(bitc::UNABBREV_RECORD);
417
85
      EmitVBR(Code, 6);
418
85
      EmitVBR(Count, 6);
419
510
      for (unsigned i = 0, e = Count; i != e; 
++i425
)
420
425
        EmitVBR64(Vals[i], 6);
421
85
      return;
422
85
    }
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
3.98k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
3.98k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
3.98k
  }
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
154k
                          StringRef Blob) {
443
154k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
154k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [3]>(unsigned int, unsigned long long const (&) [3], llvm::StringRef)
Line
Count
Source
442
21.1k
                          StringRef Blob) {
443
21.1k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
21.1k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [9]>(unsigned int, unsigned long long const (&) [9], llvm::StringRef)
Line
Count
Source
442
3.45k
                          StringRef Blob) {
443
3.45k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.45k
  }
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.23k
                          StringRef Blob) {
443
5.23k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
5.23k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], llvm::StringRef)
Line
Count
Source
442
15.8k
                          StringRef Blob) {
443
15.8k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
15.8k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], llvm::StringRef)
Line
Count
Source
442
85.6k
                          StringRef Blob) {
443
85.6k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
85.6k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [4]>(unsigned int, unsigned long long const (&) [4], llvm::StringRef)
Line
Count
Source
442
3.45k
                          StringRef Blob) {
443
3.45k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.45k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [13]>(unsigned int, unsigned long long const (&) [13], llvm::StringRef)
Line
Count
Source
442
3.21k
                          StringRef Blob) {
443
3.21k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.21k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
14.6k
                          StringRef Blob) {
443
14.6k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
14.6k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
1.63k
                          StringRef Blob) {
443
1.63k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
1.63k
  }
445
  template <typename Container>
446
  void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
447
4.96k
                          const char *BlobData, unsigned BlobLen) {
448
4.96k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
4.96k
                                    StringRef(BlobData, BlobLen), None);
450
4.96k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], char const*, unsigned int)
Line
Count
Source
447
3.45k
                          const char *BlobData, unsigned BlobLen) {
448
3.45k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
3.45k
                                    StringRef(BlobData, BlobLen), None);
450
3.45k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], char const*, unsigned int)
Line
Count
Source
447
1.51k
                          const char *BlobData, unsigned BlobLen) {
448
1.51k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
1.51k
                                    StringRef(BlobData, BlobLen), None);
450
1.51k
  }
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
282k
  void EncodeAbbrev(const BitCodeAbbrev &Abbv) {
473
282k
    EmitCode(bitc::DEFINE_ABBREV);
474
282k
    EmitVBR(Abbv.getNumOperandInfos(), 5);
475
282k
    for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos());
476
2.26M
         i != e; 
++i1.98M
) {
477
1.98M
      const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i);
478
1.98M
      Emit(Op.isLiteral(), 1);
479
1.98M
      if (Op.isLiteral()) {
480
712k
        EmitVBR64(Op.getLiteralValue(), 8);
481
1.27M
      } else {
482
1.27M
        Emit(Op.getEncoding(), 3);
483
1.27M
        if (Op.hasEncodingData())
484
1.07M
          EmitVBR64(Op.getEncodingData(), 5);
485
1.27M
      }
486
1.98M
    }
487
282k
  }
488
public:
489
490
  /// EmitAbbrev - This emits an abbreviation to the stream.  Note that this
491
  /// method takes ownership of the specified abbrev.
492
219k
  unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) {
493
219k
    // Emit the abbreviation as a record.
494
219k
    EncodeAbbrev(*Abbv);
495
219k
    CurAbbrevs.push_back(std::move(Abbv));
496
219k
    return static_cast<unsigned>(CurAbbrevs.size())-1 +
497
219k
      bitc::FIRST_APPLICATION_ABBREV;
498
219k
  }
499
500
  //===--------------------------------------------------------------------===//
501
  // BlockInfo Block Emission
502
  //===--------------------------------------------------------------------===//
503
504
  /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
505
8.02k
  void EnterBlockInfoBlock() {
506
8.02k
    EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2);
507
8.02k
    BlockInfoCurBID = ~0U;
508
8.02k
    BlockInfoRecords.clear();
509
8.02k
  }
510
private:
511
  /// SwitchToBlockID - If we aren't already talking about the specified block
512
  /// ID, emit a BLOCKINFO_CODE_SETBID record.
513
63.4k
  void SwitchToBlockID(unsigned BlockID) {
514
63.4k
    if (BlockInfoCurBID == BlockID) 
return51.5k
;
515
11.9k
    SmallVector<unsigned, 2> V;
516
11.9k
    V.push_back(BlockID);
517
11.9k
    EmitRecord(bitc::BLOCKINFO_CODE_SETBID, V);
518
11.9k
    BlockInfoCurBID = BlockID;
519
11.9k
  }
520
521
63.4k
  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
522
63.4k
    if (BlockInfo *BI = getBlockInfo(BlockID))
523
51.5k
      return *BI;
524
11.9k
525
11.9k
    // Otherwise, add a new record.
526
11.9k
    BlockInfoRecords.emplace_back();
527
11.9k
    BlockInfoRecords.back().BlockID = BlockID;
528
11.9k
    return BlockInfoRecords.back();
529
11.9k
  }
530
531
public:
532
533
  /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified
534
  /// BlockID.
535
63.4k
  unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) {
536
63.4k
    SwitchToBlockID(BlockID);
537
63.4k
    EncodeAbbrev(*Abbv);
538
63.4k
539
63.4k
    // Add the abbrev to the specified block record.
540
63.4k
    BlockInfo &Info = getOrCreateBlockInfo(BlockID);
541
63.4k
    Info.Abbrevs.push_back(std::move(Abbv));
542
63.4k
543
63.4k
    return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV;
544
63.4k
  }
545
};
546
547
548
} // End llvm namespace
549
550
#endif