Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Bitstream/BitstreamWriter.h
Line
Count
Source (jump to first uncovered line)
1
//===- BitstreamWriter.h - Low-level bitstream writer interface -*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This header defines the BitstreamWriter class.  This class can be used to
10
// write an arbitrary bitstream, regardless of its contents.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_BITSTREAM_BITSTREAMWRITER_H
15
#define LLVM_BITSTREAM_BITSTREAMWRITER_H
16
17
#include "llvm/ADT/ArrayRef.h"
18
#include "llvm/ADT/Optional.h"
19
#include "llvm/ADT/SmallVector.h"
20
#include "llvm/ADT/StringRef.h"
21
#include "llvm/Bitstream/BitCodes.h"
22
#include "llvm/Support/Endian.h"
23
#include <vector>
24
25
namespace llvm {
26
27
class BitstreamWriter {
28
  SmallVectorImpl<char> &Out;
29
30
  /// CurBit - Always between 0 and 31 inclusive, specifies the next bit to use.
31
  unsigned CurBit;
32
33
  /// CurValue - The current value.  Only bits < CurBit are valid.
34
  uint32_t CurValue;
35
36
  /// CurCodeSize - This is the declared size of code values used for the
37
  /// current block, in bits.
38
  unsigned CurCodeSize;
39
40
  /// BlockInfoCurBID - When emitting a BLOCKINFO_BLOCK, this is the currently
41
  /// selected BLOCK ID.
42
  unsigned BlockInfoCurBID;
43
44
  /// CurAbbrevs - Abbrevs installed at in this block.
45
  std::vector<std::shared_ptr<BitCodeAbbrev>> CurAbbrevs;
46
47
  struct Block {
48
    unsigned PrevCodeSize;
49
    size_t StartSizeWord;
50
    std::vector<std::shared_ptr<BitCodeAbbrev>> PrevAbbrevs;
51
127k
    Block(unsigned PCS, size_t SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {}
52
  };
53
54
  /// BlockScope - This tracks the current blocks that we have entered.
55
  std::vector<Block> BlockScope;
56
57
  /// BlockInfo - This contains information emitted to BLOCKINFO_BLOCK blocks.
58
  /// These describe abbreviations that all blocks of the specified ID inherit.
59
  struct BlockInfo {
60
    unsigned BlockID;
61
    std::vector<std::shared_ptr<BitCodeAbbrev>> Abbrevs;
62
  };
63
  std::vector<BlockInfo> BlockInfoRecords;
64
65
334M
  void WriteByte(unsigned char Value) {
66
334M
    Out.push_back(Value);
67
334M
  }
68
69
31.2M
  void WriteWord(unsigned Value) {
70
31.2M
    Value = support::endian::byte_swap<uint32_t, support::little>(Value);
71
31.2M
    Out.append(reinterpret_cast<const char *>(&Value),
72
31.2M
               reinterpret_cast<const char *>(&Value + 1));
73
31.2M
  }
74
75
5.87M
  size_t GetBufferOffset() const { return Out.size(); }
76
77
255k
  size_t GetWordIndex() const {
78
255k
    size_t Offset = GetBufferOffset();
79
255k
    assert((Offset & 3) == 0 && "Not 32-bit aligned");
80
255k
    return Offset / 4;
81
255k
  }
82
83
public:
84
  explicit BitstreamWriter(SmallVectorImpl<char> &O)
85
11.8k
    : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
86
87
11.8k
  ~BitstreamWriter() {
88
11.8k
    assert(CurBit == 0 && "Unflushed data remaining");
89
11.8k
    assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance");
90
11.8k
  }
91
92
  /// Retrieve the current position in the stream, in bits.
93
5.37M
  uint64_t GetCurrentBitNo() const { return GetBufferOffset() * 8 + CurBit; }
94
95
  /// Retrieve the number of bits currently used to encode an abbrev ID.
96
0
  unsigned GetAbbrevIDWidth() const { return CurCodeSize; }
97
98
  //===--------------------------------------------------------------------===//
99
  // Basic Primitives for emitting bits to the stream.
100
  //===--------------------------------------------------------------------===//
101
102
  /// Backpatch a 32-bit word in the output at the given bit offset
103
  /// with the specified value.
104
133k
  void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
105
133k
    using namespace llvm::support;
106
133k
    unsigned ByteNo = BitNo / 8;
107
133k
    assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
108
133k
               &Out[ByteNo], BitNo & 7)) &&
109
133k
           "Expected to be patching over 0-value placeholders");
110
133k
    endian::writeAtBitAlignment<uint32_t, little, unaligned>(
111
133k
        &Out[ByteNo], NewWord, BitNo & 7);
112
133k
  }
113
114
213
  void BackpatchWord64(uint64_t BitNo, uint64_t Val) {
115
213
    BackpatchWord(BitNo, (uint32_t)Val);
116
213
    BackpatchWord(BitNo + 32, (uint32_t)(Val >> 32));
117
213
  }
118
119
173M
  void Emit(uint32_t Val, unsigned NumBits) {
120
173M
    assert(NumBits && NumBits <= 32 && "Invalid value size!");
121
173M
    assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!");
122
173M
    CurValue |= Val << CurBit;
123
173M
    if (CurBit + NumBits < 32) {
124
143M
      CurBit += NumBits;
125
143M
      return;
126
143M
    }
127
30.8M
128
30.8M
    // Add the current word.
129
30.8M
    WriteWord(CurValue);
130
30.8M
131
30.8M
    if (CurBit)
132
30.7M
      CurValue = Val >> (32-CurBit);
133
121k
    else
134
121k
      CurValue = 0;
135
30.8M
    CurBit = (CurBit+NumBits) & 31;
136
30.8M
  }
137
138
438k
  void FlushToWord() {
139
438k
    if (CurBit) {
140
420k
      WriteWord(CurValue);
141
420k
      CurBit = 0;
142
420k
      CurValue = 0;
143
420k
    }
144
438k
  }
145
146
91.4M
  void EmitVBR(uint32_t Val, unsigned NumBits) {
147
91.4M
    assert(NumBits <= 32 && "Too many bits to emit!");
148
91.4M
    uint32_t Threshold = 1U << (NumBits-1);
149
91.4M
150
91.4M
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
151
154M
    while (Val >= Threshold) {
152
63.1M
      Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
153
63.1M
      Val >>= NumBits-1;
154
63.1M
    }
155
91.4M
156
91.4M
    Emit(Val, NumBits);
157
91.4M
  }
158
159
78.1M
  void EmitVBR64(uint64_t Val, unsigned NumBits) {
160
78.1M
    assert(NumBits <= 32 && "Too many bits to emit!");
161
78.1M
    if ((uint32_t)Val == Val)
162
78.1M
      return EmitVBR((uint32_t)Val, NumBits);
163
2.26k
164
2.26k
    uint32_t Threshold = 1U << (NumBits-1);
165
2.26k
166
2.26k
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
167
30.9k
    while (Val >= Threshold) {
168
28.6k
      Emit(((uint32_t)Val & ((1 << (NumBits-1))-1)) |
169
28.6k
           (1 << (NumBits-1)), NumBits);
170
28.6k
      Val >>= NumBits-1;
171
28.6k
    }
172
2.26k
173
2.26k
    Emit((uint32_t)Val, NumBits);
174
2.26k
  }
175
176
  /// EmitCode - Emit the specified code.
177
8.05M
  void EmitCode(unsigned Val) {
178
8.05M
    Emit(Val, CurCodeSize);
179
8.05M
  }
180
181
  //===--------------------------------------------------------------------===//
182
  // Block Manipulation
183
  //===--------------------------------------------------------------------===//
184
185
  /// getBlockInfo - If there is block info for the specified ID, return it,
186
  /// otherwise return null.
187
217k
  BlockInfo *getBlockInfo(unsigned BlockID) {
188
217k
    // Common case, the most recent entry matches BlockID.
189
217k
    if (!BlockInfoRecords.empty() && 
BlockInfoRecords.back().BlockID == BlockID157k
)
190
87.5k
      return &BlockInfoRecords.back();
191
129k
192
129k
    for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
193
262k
         i != e; 
++i132k
)
194
156k
      if (BlockInfoRecords[i].BlockID == BlockID)
195
23.5k
        return &BlockInfoRecords[i];
196
129k
    
return nullptr106k
;
197
129k
  }
198
199
127k
  void EnterSubblock(unsigned BlockID, unsigned CodeLen) {
200
127k
    // Block header:
201
127k
    //    [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
202
127k
    EmitCode(bitc::ENTER_SUBBLOCK);
203
127k
    EmitVBR(BlockID, bitc::BlockIDWidth);
204
127k
    EmitVBR(CodeLen, bitc::CodeLenWidth);
205
127k
    FlushToWord();
206
127k
207
127k
    size_t BlockSizeWordIndex = GetWordIndex();
208
127k
    unsigned OldCodeSize = CurCodeSize;
209
127k
210
127k
    // Emit a placeholder, which will be replaced when the block is popped.
211
127k
    Emit(0, bitc::BlockSizeWidth);
212
127k
213
127k
    CurCodeSize = CodeLen;
214
127k
215
127k
    // Push the outer block's abbrev set onto the stack, start out with an
216
127k
    // empty abbrev set.
217
127k
    BlockScope.emplace_back(OldCodeSize, BlockSizeWordIndex);
218
127k
    BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
219
127k
220
127k
    // If there is a blockinfo for this BlockID, add all the predefined abbrevs
221
127k
    // to the abbrev list.
222
127k
    if (BlockInfo *Info = getBlockInfo(BlockID)) {
223
36.3k
      CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
224
36.3k
                        Info->Abbrevs.end());
225
36.3k
    }
226
127k
  }
227
228
127k
  void ExitBlock() {
229
127k
    assert(!BlockScope.empty() && "Block scope imbalance!");
230
127k
    const Block &B = BlockScope.back();
231
127k
232
127k
    // Block tail:
233
127k
    //    [END_BLOCK, <align4bytes>]
234
127k
    EmitCode(bitc::END_BLOCK);
235
127k
    FlushToWord();
236
127k
237
127k
    // Compute the size of the block, in words, not counting the size field.
238
127k
    size_t SizeInWords = GetWordIndex() - B.StartSizeWord - 1;
239
127k
    uint64_t BitNo = uint64_t(B.StartSizeWord) * 32;
240
127k
241
127k
    // Update the block size field in the header of this sub-block.
242
127k
    BackpatchWord(BitNo, SizeInWords);
243
127k
244
127k
    // Restore the inner block's code size and abbrev table.
245
127k
    CurCodeSize = B.PrevCodeSize;
246
127k
    CurAbbrevs = std::move(B.PrevAbbrevs);
247
127k
    BlockScope.pop_back();
248
127k
  }
249
250
  //===--------------------------------------------------------------------===//
251
  // Record Emission
252
  //===--------------------------------------------------------------------===//
253
254
private:
255
  /// EmitAbbreviatedLiteral - Emit a literal value according to its abbrev
256
  /// record.  This is a no-op, since the abbrev specifies the literal to use.
257
  template<typename uintty>
258
4.72M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
259
4.72M
    assert(Op.isLiteral() && "Not a literal");
260
4.72M
    // If the abbrev specifies the literal value to use, don't emit
261
4.72M
    // anything.
262
4.72M
    assert(V == Op.getLiteralValue() &&
263
4.72M
           "Invalid abbrev for record!");
264
4.72M
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
258
964k
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
259
964k
    assert(Op.isLiteral() && "Not a literal");
260
964k
    // If the abbrev specifies the literal value to use, don't emit
261
964k
    // anything.
262
964k
    assert(V == Op.getLiteralValue() &&
263
964k
           "Invalid abbrev for record!");
264
964k
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned long long>(llvm::BitCodeAbbrevOp const&, unsigned long long)
Line
Count
Source
258
3.76M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
259
3.76M
    assert(Op.isLiteral() && "Not a literal");
260
3.76M
    // If the abbrev specifies the literal value to use, don't emit
261
3.76M
    // anything.
262
3.76M
    assert(V == Op.getLiteralValue() &&
263
3.76M
           "Invalid abbrev for record!");
264
3.76M
  }
265
266
  /// EmitAbbreviatedField - Emit a single scalar field value with the specified
267
  /// encoding.
268
  template<typename uintty>
269
10.7M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
270
10.7M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
271
10.7M
272
10.7M
    // Encode the value as we are commanded.
273
10.7M
    switch (Op.getEncoding()) {
274
10.7M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
275
10.7M
    case BitCodeAbbrevOp::Fixed:
276
6.40M
      if (Op.getEncodingData())
277
6.40M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
278
6.40M
      break;
279
10.7M
    case BitCodeAbbrevOp::VBR:
280
3.41M
      if (Op.getEncodingData())
281
3.41M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
282
3.41M
      break;
283
10.7M
    case BitCodeAbbrevOp::Char6:
284
958k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
285
958k
      break;
286
10.7M
    }
287
10.7M
  }
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
269
801k
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
270
801k
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
271
801k
272
801k
    // Encode the value as we are commanded.
273
801k
    switch (Op.getEncoding()) {
274
801k
    
default: 0
llvm_unreachable0
("Unknown encoding!");
275
801k
    case BitCodeAbbrevOp::Fixed:
276
532k
      if (Op.getEncodingData())
277
531k
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
278
532k
      break;
279
801k
    case BitCodeAbbrevOp::VBR:
280
157k
      if (Op.getEncodingData())
281
157k
        EmitVBR64(V, (unsigned)Op.getEncodingData());
282
157k
      break;
283
801k
    case BitCodeAbbrevOp::Char6:
284
112k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
285
112k
      break;
286
801k
    }
287
801k
  }
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
269
9.98M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
270
9.98M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
271
9.98M
272
9.98M
    // Encode the value as we are commanded.
273
9.98M
    switch (Op.getEncoding()) {
274
9.98M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
275
9.98M
    case BitCodeAbbrevOp::Fixed:
276
5.87M
      if (Op.getEncodingData())
277
5.87M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
278
5.87M
      break;
279
9.98M
    case BitCodeAbbrevOp::VBR:
280
3.25M
      if (Op.getEncodingData())
281
3.25M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
282
3.25M
      break;
283
9.98M
    case BitCodeAbbrevOp::Char6:
284
845k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
285
845k
      break;
286
9.98M
    }
287
9.98M
  }
288
289
  /// EmitRecordWithAbbrevImpl - This is the core implementation of the record
290
  /// emission code.  If BlobData is non-null, then it specifies an array of
291
  /// data that should be emitted as part of the Blob or Array operand that is
292
  /// known to exist at the end of the record. If Code is specified, then
293
  /// it is the record code to emit before the Vals, which must not contain
294
  /// the code.
295
  template <typename uintty>
296
  void EmitRecordWithAbbrevImpl(unsigned Abbrev, ArrayRef<uintty> Vals,
297
1.30M
                                StringRef Blob, Optional<unsigned> Code) {
298
1.30M
    const char *BlobData = Blob.data();
299
1.30M
    unsigned BlobLen = (unsigned) Blob.size();
300
1.30M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
301
1.30M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
302
1.30M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
303
1.30M
304
1.30M
    EmitCode(Abbrev);
305
1.30M
306
1.30M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
307
1.30M
    if (Code) {
308
960k
      assert(e && "Expected non-empty abbreviation");
309
960k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
310
960k
311
960k
      if (Op.isLiteral())
312
960k
        EmitAbbreviatedLiteral(Op, Code.getValue());
313
49
      else {
314
49
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
315
49
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
316
49
               "Expected literal or scalar");
317
49
        EmitAbbreviatedField(Op, Code.getValue());
318
49
      }
319
960k
    }
320
1.30M
321
1.30M
    unsigned RecordIdx = 0;
322
14.5M
    for (; i != e; 
++i13.2M
) {
323
13.2M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
324
13.2M
      if (Op.isLiteral()) {
325
3.76M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
326
3.76M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
327
3.76M
        ++RecordIdx;
328
9.50M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
329
251k
        // Array case.
330
251k
        assert(i + 2 == e && "array op not second to last?");
331
251k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
332
251k
333
251k
        // If this record has blob data, emit it, otherwise we must have record
334
251k
        // entries to encode this way.
335
251k
        if (BlobData) {
336
0
          assert(RecordIdx == Vals.size() &&
337
0
                 "Blob data and record entries specified for array!");
338
0
          // Emit a vbr6 to indicate the number of elements present.
339
0
          EmitVBR(static_cast<uint32_t>(BlobLen), 6);
340
0
341
0
          // Emit each field.
342
0
          for (unsigned i = 0; i != BlobLen; ++i)
343
0
            EmitAbbreviatedField(EltEnc, (unsigned char)BlobData[i]);
344
0
345
0
          // Know that blob data is consumed for assertion below.
346
0
          BlobData = nullptr;
347
251k
        } else {
348
251k
          // Emit a vbr6 to indicate the number of elements present.
349
251k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
350
251k
351
251k
          // Emit each field.
352
1.96M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.70M
)
353
1.70M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
354
251k
        }
355
9.24M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
356
176k
        // If this record has blob data, emit it, otherwise we must have record
357
176k
        // entries to encode this way.
358
176k
359
176k
        if (BlobData) {
360
175k
          assert(RecordIdx == Vals.size() &&
361
175k
                 "Blob data and record entries specified for blob operand!");
362
175k
363
175k
          assert(Blob.data() == BlobData && "BlobData got moved");
364
175k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
365
175k
          emitBlob(Blob);
366
175k
          BlobData = nullptr;
367
175k
        } else {
368
1.61k
          emitBlob(Vals.slice(RecordIdx));
369
1.61k
        }
370
9.07M
      } else {  // Single scalar field.
371
9.07M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
372
9.07M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
373
9.07M
        ++RecordIdx;
374
9.07M
      }
375
13.2M
    }
376
1.30M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
377
1.30M
    assert(BlobData == nullptr &&
378
1.30M
           "Blob data specified for record that doesn't use it!");
379
1.30M
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned int>(unsigned int, llvm::ArrayRef<unsigned int>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
297
99.9k
                                StringRef Blob, Optional<unsigned> Code) {
298
99.9k
    const char *BlobData = Blob.data();
299
99.9k
    unsigned BlobLen = (unsigned) Blob.size();
300
99.9k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
301
99.9k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
302
99.9k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
303
99.9k
304
99.9k
    EmitCode(Abbrev);
305
99.9k
306
99.9k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
307
99.9k
    if (Code) {
308
99.9k
      assert(e && "Expected non-empty abbreviation");
309
99.9k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
310
99.9k
311
99.9k
      if (Op.isLiteral())
312
99.9k
        EmitAbbreviatedLiteral(Op, Code.getValue());
313
0
      else {
314
0
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
315
0
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
316
0
               "Expected literal or scalar");
317
0
        EmitAbbreviatedField(Op, Code.getValue());
318
0
      }
319
99.9k
    }
320
99.9k
321
99.9k
    unsigned RecordIdx = 0;
322
397k
    for (; i != e; 
++i297k
) {
323
297k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
324
297k
      if (Op.isLiteral()) {
325
3.73k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
326
3.73k
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
327
3.73k
        ++RecordIdx;
328
293k
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
329
24.0k
        // Array case.
330
24.0k
        assert(i + 2 == e && "array op not second to last?");
331
24.0k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
332
24.0k
333
24.0k
        // If this record has blob data, emit it, otherwise we must have record
334
24.0k
        // entries to encode this way.
335
24.0k
        if (BlobData) {
336
0
          assert(RecordIdx == Vals.size() &&
337
0
                 "Blob data and record entries specified for array!");
338
0
          // Emit a vbr6 to indicate the number of elements present.
339
0
          EmitVBR(static_cast<uint32_t>(BlobLen), 6);
340
0
341
0
          // Emit each field.
342
0
          for (unsigned i = 0; i != BlobLen; ++i)
343
0
            EmitAbbreviatedField(EltEnc, (unsigned char)BlobData[i]);
344
0
345
0
          // Know that blob data is consumed for assertion below.
346
0
          BlobData = nullptr;
347
24.0k
        } else {
348
24.0k
          // Emit a vbr6 to indicate the number of elements present.
349
24.0k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
350
24.0k
351
24.0k
          // Emit each field.
352
556k
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx532k
)
353
532k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
354
24.0k
        }
355
269k
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
356
45
        // If this record has blob data, emit it, otherwise we must have record
357
45
        // entries to encode this way.
358
45
359
45
        if (BlobData) {
360
45
          assert(RecordIdx == Vals.size() &&
361
45
                 "Blob data and record entries specified for blob operand!");
362
45
363
45
          assert(Blob.data() == BlobData && "BlobData got moved");
364
45
          assert(Blob.size() == BlobLen && "BlobLen got changed");
365
45
          emitBlob(Blob);
366
45
          BlobData = nullptr;
367
45
        } else {
368
0
          emitBlob(Vals.slice(RecordIdx));
369
0
        }
370
269k
      } else {  // Single scalar field.
371
269k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
372
269k
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
373
269k
        ++RecordIdx;
374
269k
      }
375
297k
    }
376
99.9k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
377
99.9k
    assert(BlobData == nullptr &&
378
99.9k
           "Blob data specified for record that doesn't use it!");
379
99.9k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned long long>(unsigned int, llvm::ArrayRef<unsigned long long>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
297
1.20M
                                StringRef Blob, Optional<unsigned> Code) {
298
1.20M
    const char *BlobData = Blob.data();
299
1.20M
    unsigned BlobLen = (unsigned) Blob.size();
300
1.20M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
301
1.20M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
302
1.20M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
303
1.20M
304
1.20M
    EmitCode(Abbrev);
305
1.20M
306
1.20M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
307
1.20M
    if (Code) {
308
860k
      assert(e && "Expected non-empty abbreviation");
309
860k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
310
860k
311
860k
      if (Op.isLiteral())
312
860k
        EmitAbbreviatedLiteral(Op, Code.getValue());
313
49
      else {
314
49
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
315
49
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
316
49
               "Expected literal or scalar");
317
49
        EmitAbbreviatedField(Op, Code.getValue());
318
49
      }
319
860k
    }
320
1.20M
321
1.20M
    unsigned RecordIdx = 0;
322
14.1M
    for (; i != e; 
++i12.9M
) {
323
12.9M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
324
12.9M
      if (Op.isLiteral()) {
325
3.76M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
326
3.76M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
327
3.76M
        ++RecordIdx;
328
9.20M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
329
227k
        // Array case.
330
227k
        assert(i + 2 == e && "array op not second to last?");
331
227k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
332
227k
333
227k
        // If this record has blob data, emit it, otherwise we must have record
334
227k
        // entries to encode this way.
335
227k
        if (BlobData) {
336
0
          assert(RecordIdx == Vals.size() &&
337
0
                 "Blob data and record entries specified for array!");
338
0
          // Emit a vbr6 to indicate the number of elements present.
339
0
          EmitVBR(static_cast<uint32_t>(BlobLen), 6);
340
0
341
0
          // Emit each field.
342
0
          for (unsigned i = 0; i != BlobLen; ++i)
343
0
            EmitAbbreviatedField(EltEnc, (unsigned char)BlobData[i]);
344
0
345
0
          // Know that blob data is consumed for assertion below.
346
0
          BlobData = nullptr;
347
227k
        } else {
348
227k
          // Emit a vbr6 to indicate the number of elements present.
349
227k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
350
227k
351
227k
          // Emit each field.
352
1.40M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.17M
)
353
1.17M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
354
227k
        }
355
8.98M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
356
176k
        // If this record has blob data, emit it, otherwise we must have record
357
176k
        // entries to encode this way.
358
176k
359
176k
        if (BlobData) {
360
175k
          assert(RecordIdx == Vals.size() &&
361
175k
                 "Blob data and record entries specified for blob operand!");
362
175k
363
175k
          assert(Blob.data() == BlobData && "BlobData got moved");
364
175k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
365
175k
          emitBlob(Blob);
366
175k
          BlobData = nullptr;
367
175k
        } else {
368
1.61k
          emitBlob(Vals.slice(RecordIdx));
369
1.61k
        }
370
8.80M
      } else {  // Single scalar field.
371
8.80M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
372
8.80M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
373
8.80M
        ++RecordIdx;
374
8.80M
      }
375
12.9M
    }
376
1.20M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
377
1.20M
    assert(BlobData == nullptr &&
378
1.20M
           "Blob data specified for record that doesn't use it!");
379
1.20M
  }
380
381
public:
382
  /// Emit a blob, including flushing before and tail-padding.
383
  template <class UIntTy>
384
176k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
385
176k
    // Emit a vbr6 to indicate the number of elements present.
386
176k
    if (ShouldEmitSize)
387
176k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
388
176k
389
176k
    // Flush to a 32-bit alignment boundary.
390
176k
    FlushToWord();
391
176k
392
176k
    // Emit literal bytes.
393
334M
    for (const auto &B : Bytes) {
394
334M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
395
334M
      WriteByte((unsigned char)B);
396
334M
    }
397
176k
398
176k
    // Align end to 32-bits.
399
243k
    while (GetBufferOffset() & 3)
400
67.0k
      WriteByte(0);
401
176k
  }
void llvm::BitstreamWriter::emitBlob<unsigned char>(llvm::ArrayRef<unsigned char>, bool)
Line
Count
Source
384
175k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
385
175k
    // Emit a vbr6 to indicate the number of elements present.
386
175k
    if (ShouldEmitSize)
387
175k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
388
175k
389
175k
    // Flush to a 32-bit alignment boundary.
390
175k
    FlushToWord();
391
175k
392
175k
    // Emit literal bytes.
393
334M
    for (const auto &B : Bytes) {
394
334M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
395
334M
      WriteByte((unsigned char)B);
396
334M
    }
397
175k
398
175k
    // Align end to 32-bits.
399
242k
    while (GetBufferOffset() & 3)
400
67.0k
      WriteByte(0);
401
175k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::emitBlob<unsigned int>(llvm::ArrayRef<unsigned int>, bool)
void llvm::BitstreamWriter::emitBlob<unsigned long long>(llvm::ArrayRef<unsigned long long>, bool)
Line
Count
Source
384
1.61k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
385
1.61k
    // Emit a vbr6 to indicate the number of elements present.
386
1.61k
    if (ShouldEmitSize)
387
1.61k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
388
1.61k
389
1.61k
    // Flush to a 32-bit alignment boundary.
390
1.61k
    FlushToWord();
391
1.61k
392
1.61k
    // Emit literal bytes.
393
1.61k
    for (const auto &B : Bytes) {
394
0
      assert(isUInt<8>(B) && "Value too large to emit as byte");
395
0
      WriteByte((unsigned char)B);
396
0
    }
397
1.61k
398
1.61k
    // Align end to 32-bits.
399
1.61k
    while (GetBufferOffset() & 3)
400
0
      WriteByte(0);
401
1.61k
  }
402
175k
  void emitBlob(StringRef Bytes, bool ShouldEmitSize = true) {
403
175k
    emitBlob(makeArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
404
175k
             ShouldEmitSize);
405
175k
  }
406
407
  /// EmitRecord - Emit the specified record to the stream, using an abbrev if
408
  /// we have one to compress the output.
409
  template <typename Container>
410
7.11M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
7.11M
    if (!Abbrev) {
412
6.15M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
6.15M
      // form.
414
6.15M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
6.15M
      EmitCode(bitc::UNABBREV_RECORD);
416
6.15M
      EmitVBR(Code, 6);
417
6.15M
      EmitVBR(Count, 6);
418
78.8M
      for (unsigned i = 0, e = Count; i != e; 
++i72.6M
)
419
72.6M
        EmitVBR64(Vals[i], 6);
420
6.15M
      return;
421
6.15M
    }
422
960k
423
960k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
960k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 2u> >(unsigned int, llvm::SmallVector<unsigned int, 2u> const&, unsigned int)
Line
Count
Source
410
14.9k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
14.9k
    if (!Abbrev) {
412
14.9k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
14.9k
      // form.
414
14.9k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
14.9k
      EmitCode(bitc::UNABBREV_RECORD);
416
14.9k
      EmitVBR(Code, 6);
417
14.9k
      EmitVBR(Count, 6);
418
29.9k
      for (unsigned i = 0, e = Count; i != e; 
++i14.9k
)
419
14.9k
        EmitVBR64(Vals[i], 6);
420
14.9k
      return;
421
14.9k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, unsigned int)
Line
Count
Source
410
3.11M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
3.11M
    if (!Abbrev) {
412
2.44M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
2.44M
      // form.
414
2.44M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
2.44M
      EmitCode(bitc::UNABBREV_RECORD);
416
2.44M
      EmitVBR(Code, 6);
417
2.44M
      EmitVBR(Count, 6);
418
54.7M
      for (unsigned i = 0, e = Count; i != e; 
++i52.2M
)
419
52.2M
        EmitVBR64(Vals[i], 6);
420
2.44M
      return;
421
2.44M
    }
422
664k
423
664k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
664k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned long long, 64u> >(unsigned int, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int)
Line
Count
Source
410
3.55M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
3.55M
    if (!Abbrev) {
412
3.37M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
3.37M
      // form.
414
3.37M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
3.37M
      EmitCode(bitc::UNABBREV_RECORD);
416
3.37M
      EmitVBR(Code, 6);
417
3.37M
      EmitVBR(Count, 6);
418
22.3M
      for (unsigned i = 0, e = Count; i != e; 
++i19.0M
)
419
19.0M
        EmitVBR64(Vals[i], 6);
420
3.37M
      return;
421
3.37M
    }
422
182k
423
182k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
182k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], unsigned int)
Line
Count
Source
410
3.62k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
3.62k
    if (!Abbrev) {
412
3.62k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
3.62k
      // form.
414
3.62k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
3.62k
      EmitCode(bitc::UNABBREV_RECORD);
416
3.62k
      EmitVBR(Code, 6);
417
3.62k
      EmitVBR(Count, 6);
418
7.24k
      for (unsigned i = 0, e = Count; i != e; 
++i3.62k
)
419
3.62k
        EmitVBR64(Vals[i], 6);
420
3.62k
      return;
421
3.62k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
0
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], unsigned int)
Line
Count
Source
410
14.4k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
14.4k
    if (!Abbrev) {
412
1.48k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
1.48k
      // form.
414
1.48k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
1.48k
      EmitCode(bitc::UNABBREV_RECORD);
416
1.48k
      EmitVBR(Code, 6);
417
1.48k
      EmitVBR(Count, 6);
418
4.44k
      for (unsigned i = 0, e = Count; i != e; 
++i2.96k
)
419
2.96k
        EmitVBR64(Vals[i], 6);
420
1.48k
      return;
421
1.48k
    }
422
12.9k
423
12.9k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
12.9k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned long long, 16u> >(unsigned int, llvm::SmallVector<unsigned long long, 16u> const&, unsigned int)
Line
Count
Source
410
1.91k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
1.91k
    if (!Abbrev) {
412
1.91k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
1.91k
      // form.
414
1.91k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
1.91k
      EmitCode(bitc::UNABBREV_RECORD);
416
1.91k
      EmitVBR(Code, 6);
417
1.91k
      EmitVBR(Count, 6);
418
7.99k
      for (unsigned i = 0, e = Count; i != e; 
++i6.08k
)
419
6.08k
        EmitVBR64(Vals[i], 6);
420
1.91k
      return;
421
1.91k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
0
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [4]>(unsigned int, unsigned long long const (&) [4], unsigned int)
Line
Count
Source
410
3.61k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
3.61k
    if (!Abbrev) {
412
3.61k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
3.61k
      // form.
414
3.61k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
3.61k
      EmitCode(bitc::UNABBREV_RECORD);
416
3.61k
      EmitVBR(Code, 6);
417
3.61k
      EmitVBR(Count, 6);
418
18.0k
      for (unsigned i = 0, e = Count; i != e; 
++i14.4k
)
419
14.4k
        EmitVBR64(Vals[i], 6);
420
3.61k
      return;
421
3.61k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned int> >(unsigned int, llvm::ArrayRef<unsigned int> const&, unsigned int)
Line
Count
Source
410
138k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
138k
    if (!Abbrev) {
412
138k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
138k
      // form.
414
138k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
138k
      EmitCode(bitc::UNABBREV_RECORD);
416
138k
      EmitVBR(Code, 6);
417
138k
      EmitVBR(Count, 6);
418
138k
      for (unsigned i = 0, e = Count; i != e; 
++i55
)
419
55
        EmitVBR64(Vals[i], 6);
420
138k
      return;
421
138k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
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
410
1.88k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
1.88k
    if (!Abbrev) {
412
1.88k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
1.88k
      // form.
414
1.88k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
1.88k
      EmitCode(bitc::UNABBREV_RECORD);
416
1.88k
      EmitVBR(Code, 6);
417
1.88k
      EmitVBR(Count, 6);
418
219k
      for (unsigned i = 0, e = Count; i != e; 
++i217k
)
419
217k
        EmitVBR64(Vals[i], 6);
420
1.88k
      return;
421
1.88k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 64u> >(unsigned int, llvm::SmallVector<unsigned int, 64u> const&, unsigned int)
Line
Count
Source
410
66.4k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
66.4k
    if (!Abbrev) {
412
47.1k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
47.1k
      // form.
414
47.1k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
47.1k
      EmitCode(bitc::UNABBREV_RECORD);
416
47.1k
      EmitVBR(Code, 6);
417
47.1k
      EmitVBR(Count, 6);
418
743k
      for (unsigned i = 0, e = Count; i != e; 
++i696k
)
419
696k
        EmitVBR64(Vals[i], 6);
420
47.1k
      return;
421
47.1k
    }
422
19.2k
423
19.2k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
19.2k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 1u> >(unsigned int, llvm::SmallVector<unsigned int, 1u> const&, unsigned int)
Line
Count
Source
410
4.97k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
4.97k
    if (!Abbrev) {
412
0
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
0
      // form.
414
0
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
0
      EmitCode(bitc::UNABBREV_RECORD);
416
0
      EmitVBR(Code, 6);
417
0
      EmitVBR(Count, 6);
418
0
      for (unsigned i = 0, e = Count; i != e; ++i)
419
0
        EmitVBR64(Vals[i], 6);
420
0
      return;
421
0
    }
422
4.97k
423
4.97k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
4.97k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, unsigned int)
Line
Count
Source
410
7.46k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
7.46k
    if (!Abbrev) {
412
7.46k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
7.46k
      // form.
414
7.46k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
7.46k
      EmitCode(bitc::UNABBREV_RECORD);
416
7.46k
      EmitVBR(Code, 6);
417
7.46k
      EmitVBR(Count, 6);
418
15.7k
      for (unsigned i = 0, e = Count; i != e; 
++i8.28k
)
419
8.28k
        EmitVBR64(Vals[i], 6);
420
7.46k
      return;
421
7.46k
    }
422
1
423
1
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
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
410
213
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
213
    if (!Abbrev) {
412
0
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
0
      // form.
414
0
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
0
      EmitCode(bitc::UNABBREV_RECORD);
416
0
      EmitVBR(Code, 6);
417
0
      EmitVBR(Count, 6);
418
0
      for (unsigned i = 0, e = Count; i != e; ++i)
419
0
        EmitVBR64(Vals[i], 6);
420
0
      return;
421
0
    }
422
213
423
213
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
213
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned long long, 4u> >(unsigned int, llvm::SmallVector<unsigned long long, 4u> const&, unsigned int)
Line
Count
Source
410
401
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
401
    if (!Abbrev) {
412
401
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
401
      // form.
414
401
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
401
      EmitCode(bitc::UNABBREV_RECORD);
416
401
      EmitVBR(Code, 6);
417
401
      EmitVBR(Count, 6);
418
1.70k
      for (unsigned i = 0, e = Count; i != e; 
++i1.30k
)
419
1.30k
        EmitVBR64(Vals[i], 6);
420
401
      return;
421
401
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
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
410
1.73k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
1.73k
    if (!Abbrev) {
412
1.73k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
1.73k
      // form.
414
1.73k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
1.73k
      EmitCode(bitc::UNABBREV_RECORD);
416
1.73k
      EmitVBR(Code, 6);
417
1.73k
      EmitVBR(Count, 6);
418
10.2k
      for (unsigned i = 0, e = Count; i != e; 
++i8.55k
)
419
8.55k
        EmitVBR64(Vals[i], 6);
420
1.73k
      return;
421
1.73k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
0
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned int> >(unsigned int, llvm::SmallVectorImpl<unsigned int> const&, unsigned int)
Line
Count
Source
410
179k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
179k
    if (!Abbrev) {
412
104k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
104k
      // form.
414
104k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
104k
      EmitCode(bitc::UNABBREV_RECORD);
416
104k
      EmitVBR(Code, 6);
417
104k
      EmitVBR(Count, 6);
418
514k
      for (unsigned i = 0, e = Count; i != e; 
++i410k
)
419
410k
        EmitVBR64(Vals[i], 6);
420
104k
      return;
421
104k
    }
422
75.7k
423
75.7k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
75.7k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned int [5]>(unsigned int, unsigned int const (&) [5], unsigned int)
Line
Count
Source
410
136
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
136
    if (!Abbrev) {
412
136
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
136
      // form.
414
136
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
136
      EmitCode(bitc::UNABBREV_RECORD);
416
136
      EmitVBR(Code, 6);
417
136
      EmitVBR(Count, 6);
418
816
      for (unsigned i = 0, e = Count; i != e; 
++i680
)
419
680
        EmitVBR64(Vals[i], 6);
420
136
      return;
421
136
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
0
  }
425
426
  /// EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
427
  /// Unlike EmitRecord, the code for the record should be included in Vals as
428
  /// the first entry.
429
  template <typename Container>
430
172k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
431
172k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
432
172k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrev<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2])
Line
Count
Source
430
5.00k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
431
5.00k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
432
5.00k
  }
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
430
167k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
431
167k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
432
167k
  }
433
434
  /// EmitRecordWithBlob - Emit the specified record to the stream, using an
435
  /// abbrev that includes a blob at the end.  The blob data to emit is
436
  /// specified by the pointer and length specified at the end.  In contrast to
437
  /// EmitRecord, this routine expects that the first entry in Vals is the code
438
  /// of the record.
439
  template <typename Container>
440
  void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
441
171k
                          StringRef Blob) {
442
171k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
171k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [3]>(unsigned int, unsigned long long const (&) [3], llvm::StringRef)
Line
Count
Source
441
22.1k
                          StringRef Blob) {
442
22.1k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
22.1k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [9]>(unsigned int, unsigned long long const (&) [9], llvm::StringRef)
Line
Count
Source
441
3.61k
                          StringRef Blob) {
442
3.61k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
3.61k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [5]>(unsigned int, unsigned long long const (&) [5], llvm::StringRef)
Line
Count
Source
441
46
                          StringRef Blob) {
442
46
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
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
441
5.47k
                          StringRef Blob) {
442
5.47k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
5.47k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], llvm::StringRef)
Line
Count
Source
441
16.6k
                          StringRef Blob) {
442
16.6k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
16.6k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], llvm::StringRef)
Line
Count
Source
441
97.3k
                          StringRef Blob) {
442
97.3k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
97.3k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [4]>(unsigned int, unsigned long long const (&) [4], llvm::StringRef)
Line
Count
Source
441
3.61k
                          StringRef Blob) {
442
3.61k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
3.61k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [13]>(unsigned int, unsigned long long const (&) [13], llvm::StringRef)
Line
Count
Source
441
3.45k
                          StringRef Blob) {
442
3.45k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
3.45k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
441
17.0k
                          StringRef Blob) {
442
17.0k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
17.0k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
441
2.27k
                          StringRef Blob) {
442
2.27k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
2.27k
  }
444
  template <typename Container>
445
  void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
446
5.23k
                          const char *BlobData, unsigned BlobLen) {
447
5.23k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
448
5.23k
                                    StringRef(BlobData, BlobLen), None);
449
5.23k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], char const*, unsigned int)
Line
Count
Source
446
3.61k
                          const char *BlobData, unsigned BlobLen) {
447
3.61k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
448
3.61k
                                    StringRef(BlobData, BlobLen), None);
449
3.61k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], char const*, unsigned int)
Line
Count
Source
446
1.61k
                          const char *BlobData, unsigned BlobLen) {
447
1.61k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
448
1.61k
                                    StringRef(BlobData, BlobLen), None);
449
1.61k
  }
450
451
  /// EmitRecordWithArray - Just like EmitRecordWithBlob, works with records
452
  /// that end with an array.
453
  template <typename Container>
454
  void EmitRecordWithArray(unsigned Abbrev, const Container &Vals,
455
                           StringRef Array) {
456
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Array, None);
457
  }
458
  template <typename Container>
459
  void EmitRecordWithArray(unsigned Abbrev, const Container &Vals,
460
                           const char *ArrayData, unsigned ArrayLen) {
461
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
462
                                    StringRef(ArrayData, ArrayLen), None);
463
  }
464
465
  //===--------------------------------------------------------------------===//
466
  // Abbrev Emission
467
  //===--------------------------------------------------------------------===//
468
469
private:
470
  // Emit the abbreviation as a DEFINE_ABBREV record.
471
337k
  void EncodeAbbrev(const BitCodeAbbrev &Abbv) {
472
337k
    EmitCode(bitc::DEFINE_ABBREV);
473
337k
    EmitVBR(Abbv.getNumOperandInfos(), 5);
474
337k
    for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos());
475
2.60M
         i != e; 
++i2.26M
) {
476
2.26M
      const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i);
477
2.26M
      Emit(Op.isLiteral(), 1);
478
2.26M
      if (Op.isLiteral()) {
479
802k
        EmitVBR64(Op.getLiteralValue(), 8);
480
1.46M
      } else {
481
1.46M
        Emit(Op.getEncoding(), 3);
482
1.46M
        if (Op.hasEncodingData())
483
1.22M
          EmitVBR64(Op.getEncodingData(), 5);
484
1.46M
      }
485
2.26M
    }
486
337k
  }
487
public:
488
489
  /// Emits the abbreviation \p Abbv to the stream.
490
247k
  unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) {
491
247k
    EncodeAbbrev(*Abbv);
492
247k
    CurAbbrevs.push_back(std::move(Abbv));
493
247k
    return static_cast<unsigned>(CurAbbrevs.size())-1 +
494
247k
      bitc::FIRST_APPLICATION_ABBREV;
495
247k
  }
496
497
  //===--------------------------------------------------------------------===//
498
  // BlockInfo Block Emission
499
  //===--------------------------------------------------------------------===//
500
501
  /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
502
9.23k
  void EnterBlockInfoBlock() {
503
9.23k
    EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2);
504
9.23k
    BlockInfoCurBID = ~0U;
505
9.23k
    BlockInfoRecords.clear();
506
9.23k
  }
507
private:
508
  /// SwitchToBlockID - If we aren't already talking about the specified block
509
  /// ID, emit a BLOCKINFO_CODE_SETBID record.
510
89.6k
  void SwitchToBlockID(unsigned BlockID) {
511
89.6k
    if (BlockInfoCurBID == BlockID) 
return74.7k
;
512
14.9k
    SmallVector<unsigned, 2> V;
513
14.9k
    V.push_back(BlockID);
514
14.9k
    EmitRecord(bitc::BLOCKINFO_CODE_SETBID, V);
515
14.9k
    BlockInfoCurBID = BlockID;
516
14.9k
  }
517
518
89.6k
  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
519
89.6k
    if (BlockInfo *BI = getBlockInfo(BlockID))
520
74.7k
      return *BI;
521
14.9k
522
14.9k
    // Otherwise, add a new record.
523
14.9k
    BlockInfoRecords.emplace_back();
524
14.9k
    BlockInfoRecords.back().BlockID = BlockID;
525
14.9k
    return BlockInfoRecords.back();
526
14.9k
  }
527
528
public:
529
530
  /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified
531
  /// BlockID.
532
89.6k
  unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) {
533
89.6k
    SwitchToBlockID(BlockID);
534
89.6k
    EncodeAbbrev(*Abbv);
535
89.6k
536
89.6k
    // Add the abbrev to the specified block record.
537
89.6k
    BlockInfo &Info = getOrCreateBlockInfo(BlockID);
538
89.6k
    Info.Abbrevs.push_back(std::move(Abbv));
539
89.6k
540
89.6k
    return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV;
541
89.6k
  }
542
};
543
544
545
} // End llvm namespace
546
547
#endif