Coverage Report

Created: 2018-07-20 23:04

/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
217k
  size_t GetWordIndex() const {
79
217k
    size_t Offset = GetBufferOffset();
80
217k
    assert((Offset & 3) == 0 && "Not 32-bit aligned");
81
217k
    return Offset / 4;
82
217k
  }
83
84
public:
85
  explicit BitstreamWriter(SmallVectorImpl<char> &O)
86
10.0k
    : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
87
88
10.0k
  ~BitstreamWriter() {
89
10.0k
    assert(CurBit == 0 && "Unflushed data remaining");
90
10.0k
    assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance");
91
10.0k
  }
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
113k
  void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
106
113k
    using namespace llvm::support;
107
113k
    unsigned ByteNo = BitNo / 8;
108
113k
    assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
109
113k
               &Out[ByteNo], BitNo & 7)) &&
110
113k
           "Expected to be patching over 0-value placeholders");
111
113k
    endian::writeAtBitAlignment<uint32_t, little, unaligned>(
112
113k
        &Out[ByteNo], NewWord, BitNo & 7);
113
113k
  }
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
128M
      CurBit += NumBits;
126
128M
      return;
127
128M
    }
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
106k
    else
135
106k
      CurValue = 0;
136
27.6M
    CurBit = (CurBit+NumBits) & 31;
137
27.6M
  }
138
139
382k
  void FlushToWord() {
140
382k
    if (CurBit) {
141
367k
      WriteWord(CurValue);
142
367k
      CurBit = 0;
143
367k
      CurValue = 0;
144
367k
    }
145
382k
  }
146
147
81.9M
  void EmitVBR(uint32_t Val, unsigned NumBits) {
148
81.9M
    assert(NumBits <= 32 && "Too many bits to emit!");
149
81.9M
    uint32_t Threshold = 1U << (NumBits-1);
150
81.9M
151
81.9M
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
152
139M
    while (Val >= Threshold) {
153
57.1M
      Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
154
57.1M
      Val >>= NumBits-1;
155
57.1M
    }
156
81.9M
157
81.9M
    Emit(Val, NumBits);
158
81.9M
  }
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
2.01k
165
2.01k
    uint32_t Threshold = 1U << (NumBits-1);
166
2.01k
167
2.01k
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
168
26.5k
    while (Val >= Threshold) {
169
24.5k
      Emit(((uint32_t)Val & ((1 << (NumBits-1))-1)) |
170
24.5k
           (1 << (NumBits-1)), NumBits);
171
24.5k
      Val >>= NumBits-1;
172
24.5k
    }
173
2.01k
174
2.01k
    Emit((uint32_t)Val, NumBits);
175
2.01k
  }
176
177
  /// EmitCode - Emit the specified code.
178
7.28M
  void EmitCode(unsigned Val) {
179
7.28M
    Emit(Val, CurCodeSize);
180
7.28M
  }
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
173k
  BlockInfo *getBlockInfo(unsigned BlockID) {
189
173k
    // Common case, the most recent entry matches BlockID.
190
173k
    if (!BlockInfoRecords.empty() && 
BlockInfoRecords.back().BlockID == BlockID119k
)
191
62.9k
      return &BlockInfoRecords.back();
192
110k
193
110k
    for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
194
215k
         i != e; 
++i105k
)
195
124k
      if (BlockInfoRecords[i].BlockID == BlockID)
196
19.4k
        return &BlockInfoRecords[i];
197
110k
    
return nullptr90.7k
;
198
110k
  }
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.2k
      CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
225
30.2k
                        Info->Abbrevs.end());
226
30.2k
    }
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
851k
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
851k
    assert(Op.isLiteral() && "Not a literal");
261
851k
    // If the abbrev specifies the literal value to use, don't emit
262
851k
    // anything.
263
851k
    assert(V == Op.getLiteralValue() &&
264
851k
           "Invalid abbrev for record!");
265
851k
  }
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.18M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
9.18M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
9.18M
273
9.18M
    // Encode the value as we are commanded.
274
9.18M
    switch (Op.getEncoding()) {
275
9.18M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
9.18M
    case BitCodeAbbrevOp::Fixed:
277
5.26M
      if (Op.getEncodingData())
278
5.26M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
5.26M
      break;
280
9.18M
    case BitCodeAbbrevOp::VBR:
281
3.14M
      if (Op.getEncodingData())
282
3.14M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.14M
      break;
284
9.18M
    case BitCodeAbbrevOp::Char6:
285
769k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
769k
      break;
287
9.18M
    }
288
9.18M
  }
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
270
652k
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
652k
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
652k
273
652k
    // Encode the value as we are commanded.
274
652k
    switch (Op.getEncoding()) {
275
652k
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
652k
    case BitCodeAbbrevOp::Fixed:
277
424k
      if (Op.getEncodingData())
278
424k
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
424k
      break;
280
652k
    case BitCodeAbbrevOp::VBR:
281
135k
      if (Op.getEncodingData())
282
135k
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
135k
      break;
284
652k
    case BitCodeAbbrevOp::Char6:
285
92.5k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
92.5k
      break;
287
652k
    }
288
652k
  }
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
676k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
676k
      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
847k
      assert(e && "Expected non-empty abbreviation");
310
847k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
847k
312
847k
      if (Op.isLiteral())
313
847k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
26
      else {
315
26
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
26
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
26
               "Expected literal or scalar");
318
26
        EmitAbbreviatedField(Op, Code.getValue());
319
26
      }
320
847k
    }
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.97M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
2.97M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
2.97M
        ++RecordIdx;
329
8.15M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
221k
        // Array case.
331
221k
        assert(i + 2 == e && "array op not second to last?");
332
221k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
221k
334
221k
        // If this record has blob data, emit it, otherwise we must have record
335
221k
        // entries to encode this way.
336
221k
        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
221k
        } else {
349
221k
          // Emit a vbr6 to indicate the number of elements present.
350
221k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
221k
352
221k
          // Emit each field.
353
1.62M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.40M
)
354
1.40M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
221k
        }
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
158k
          assert(RecordIdx == Vals.size() &&
362
158k
                 "Blob data and record entries specified for blob operand!");
363
158k
364
158k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
158k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
158k
          emitBlob(Blob);
367
158k
          BlobData = nullptr;
368
158k
        } 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.08M
                                StringRef Blob, Optional<unsigned> Code) {
299
1.08M
    const char *BlobData = Blob.data();
300
1.08M
    unsigned BlobLen = (unsigned) Blob.size();
301
1.08M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
1.08M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
1.08M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
1.08M
305
1.08M
    EmitCode(Abbrev);
306
1.08M
307
1.08M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
1.08M
    if (Code) {
309
762k
      assert(e && "Expected non-empty abbreviation");
310
762k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
762k
312
762k
      if (Op.isLiteral())
313
762k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
28
      else {
315
28
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
28
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
28
               "Expected literal or scalar");
318
28
        EmitAbbreviatedField(Op, Code.getValue());
319
28
      }
320
762k
    }
321
1.08M
322
1.08M
    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.18M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx981k
)
354
981k
            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.08M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
1.08M
    assert(BlobData == nullptr &&
379
1.08M
           "Blob data specified for record that doesn't use it!");
380
1.08M
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned int>(unsigned int, llvm::ArrayRef<unsigned int>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
298
85.0k
                                StringRef Blob, Optional<unsigned> Code) {
299
85.0k
    const char *BlobData = Blob.data();
300
85.0k
    unsigned BlobLen = (unsigned) Blob.size();
301
85.0k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
85.0k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
85.0k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
85.0k
305
85.0k
    EmitCode(Abbrev);
306
85.0k
307
85.0k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
85.0k
    if (Code) {
309
85.0k
      assert(e && "Expected non-empty abbreviation");
310
85.0k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
85.0k
312
85.0k
      if (Op.isLiteral())
313
85.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
85.0k
    }
321
85.0k
322
85.0k
    unsigned RecordIdx = 0;
323
337k
    for (; i != e; 
++i252k
) {
324
252k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
252k
      if (Op.isLiteral()) {
326
3.46k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.46k
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.46k
        ++RecordIdx;
329
249k
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
21.3k
        // Array case.
331
21.3k
        assert(i + 2 == e && "array op not second to last?");
332
21.3k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
21.3k
334
21.3k
        // If this record has blob data, emit it, otherwise we must have record
335
21.3k
        // entries to encode this way.
336
21.3k
        if (BlobData) {
337
0
          assert(RecordIdx == Vals.size() &&
338
0
                 "Blob data and record entries specified for array!");
339
0
          // Emit a vbr6 to indicate the number of elements present.
340
0
          EmitVBR(static_cast<uint32_t>(BlobLen), 6);
341
0
342
0
          // Emit each field.
343
0
          for (unsigned i = 0; i != BlobLen; ++i)
344
0
            EmitAbbreviatedField(EltEnc, (unsigned char)BlobData[i]);
345
0
346
0
          // Know that blob data is consumed for assertion below.
347
0
          BlobData = nullptr;
348
21.3k
        } else {
349
21.3k
          // Emit a vbr6 to indicate the number of elements present.
350
21.3k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
21.3k
352
21.3k
          // Emit each field.
353
446k
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx424k
)
354
424k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
21.3k
        }
356
227k
      } 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
227k
      } else {  // Single scalar field.
372
227k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
227k
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
227k
        ++RecordIdx;
375
227k
      }
376
252k
    }
377
85.0k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
85.0k
    assert(BlobData == nullptr &&
379
85.0k
           "Blob data specified for record that doesn't use it!");
380
85.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
224k
    while (GetBufferOffset() & 3)
401
64.8k
      WriteByte(0);
402
159k
  }
void llvm::BitstreamWriter::emitBlob<unsigned char>(llvm::ArrayRef<unsigned char>, bool)
Line
Count
Source
385
158k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
158k
    // Emit a vbr6 to indicate the number of elements present.
387
158k
    if (ShouldEmitSize)
388
158k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
158k
390
158k
    // Flush to a 32-bit alignment boundary.
391
158k
    FlushToWord();
392
158k
393
158k
    // 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
158k
399
158k
    // Align end to 32-bits.
400
222k
    while (GetBufferOffset() & 3)
401
64.8k
      WriteByte(0);
402
158k
  }
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
158k
  void emitBlob(StringRef Bytes, bool ShouldEmitSize = true) {
404
158k
    emitBlob(makeArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
405
158k
             ShouldEmitSize);
406
158k
  }
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.46M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
6.46M
    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
847k
424
847k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
847k
  }
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
12.0k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
12.0k
    if (!Abbrev) {
413
12.0k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
12.0k
      // form.
415
12.0k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
12.0k
      EmitCode(bitc::UNABBREV_RECORD);
417
12.0k
      EmitVBR(Code, 6);
418
12.0k
      EmitVBR(Count, 6);
419
24.1k
      for (unsigned i = 0, e = Count; i != e; 
++i12.0k
)
420
12.0k
        EmitVBR64(Vals[i], 6);
421
12.0k
      return;
422
12.0k
    }
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.30M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.30M
    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
153k
424
153k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
153k
  }
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.1k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
12.1k
    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.47k
      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.7k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
54.7k
    if (!Abbrev) {
413
38.8k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
38.8k
      // form.
415
38.8k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
38.8k
      EmitCode(bitc::UNABBREV_RECORD);
417
38.8k
      EmitVBR(Code, 6);
418
38.8k
      EmitVBR(Count, 6);
419
543k
      for (unsigned i = 0, e = Count; i != e; 
++i505k
)
420
505k
        EmitVBR64(Vals[i], 6);
421
38.8k
      return;
422
38.8k
    }
423
15.9k
424
15.9k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
15.9k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 1u> >(unsigned int, llvm::SmallVector<unsigned int, 1u> const&, unsigned int)
Line
Count
Source
411
4.00k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
4.00k
    if (!Abbrev) {
413
0
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
0
      // form.
415
0
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
0
      EmitCode(bitc::UNABBREV_RECORD);
417
0
      EmitVBR(Code, 6);
418
0
      EmitVBR(Count, 6);
419
0
      for (unsigned i = 0, e = Count; i != e; ++i)
420
0
        EmitVBR64(Vals[i], 6);
421
0
      return;
422
0
    }
423
4.00k
424
4.00k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
4.00k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, unsigned int)
Line
Count
Source
411
5.53k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
5.53k
    if (!Abbrev) {
413
5.52k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
5.52k
      // form.
415
5.52k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
5.52k
      EmitCode(bitc::UNABBREV_RECORD);
417
5.52k
      EmitVBR(Code, 6);
418
5.52k
      EmitVBR(Count, 6);
419
11.6k
      for (unsigned i = 0, e = Count; i != e; 
++i6.15k
)
420
6.15k
        EmitVBR64(Vals[i], 6);
421
5.52k
      return;
422
5.52k
    }
423
2
424
2
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
2
  }
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
117
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
117
    if (!Abbrev) {
413
117
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
117
      // form.
415
117
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
117
      EmitCode(bitc::UNABBREV_RECORD);
417
117
      EmitVBR(Code, 6);
418
117
      EmitVBR(Count, 6);
419
530
      for (unsigned i = 0, e = Count; i != e; 
++i413
)
420
413
        EmitVBR64(Vals[i], 6);
421
117
      return;
422
117
    }
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
149k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
149k
    if (!Abbrev) {
413
84.1k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
84.1k
      // form.
415
84.1k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
84.1k
      EmitCode(bitc::UNABBREV_RECORD);
417
84.1k
      EmitVBR(Code, 6);
418
84.1k
      EmitVBR(Count, 6);
419
416k
      for (unsigned i = 0, e = Count; i != e; 
++i332k
)
420
332k
        EmitVBR64(Vals[i], 6);
421
84.1k
      return;
422
84.1k
    }
423
65.1k
424
65.1k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
65.1k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned int [5]>(unsigned int, unsigned int const (&) [5], unsigned int)
Line
Count
Source
411
89
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
89
    if (!Abbrev) {
413
89
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
89
      // form.
415
89
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
89
      EmitCode(bitc::UNABBREV_RECORD);
417
89
      EmitVBR(Code, 6);
418
89
      EmitVBR(Count, 6);
419
534
      for (unsigned i = 0, e = Count; i != e; 
++i445
)
420
445
        EmitVBR64(Vals[i], 6);
421
89
      return;
422
89
    }
423
0
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
426
427
  /// EmitRecordWithAbbrev - Emit a record with the specified abbreviation.
428
  /// Unlike EmitRecord, the code for the record should be included in Vals as
429
  /// the first entry.
430
  template <typename Container>
431
158k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
158k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
158k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrev<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2])
Line
Count
Source
431
4.03k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
4.03k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
4.03k
  }
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.24k
                          StringRef Blob) {
443
5.24k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
5.24k
  }
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.7k
                          StringRef Blob) {
443
14.7k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
14.7k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
1.67k
                          StringRef Blob) {
443
1.67k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
1.67k
  }
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
284k
  void EncodeAbbrev(const BitCodeAbbrev &Abbv) {
473
284k
    EmitCode(bitc::DEFINE_ABBREV);
474
284k
    EmitVBR(Abbv.getNumOperandInfos(), 5);
475
284k
    for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos());
476
2.27M
         i != e; 
++i1.99M
) {
477
1.99M
      const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i);
478
1.99M
      Emit(Op.isLiteral(), 1);
479
1.99M
      if (Op.isLiteral()) {
480
714k
        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.99M
    }
487
284k
  }
488
public:
489
490
  /// EmitAbbrev - This emits an abbreviation to the stream.  Note that this
491
  /// method takes ownership of the specified abbrev.
492
220k
  unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) {
493
220k
    // Emit the abbreviation as a record.
494
220k
    EncodeAbbrev(*Abbv);
495
220k
    CurAbbrevs.push_back(std::move(Abbv));
496
220k
    return static_cast<unsigned>(CurAbbrevs.size())-1 +
497
220k
      bitc::FIRST_APPLICATION_ABBREV;
498
220k
  }
499
500
  //===--------------------------------------------------------------------===//
501
  // BlockInfo Block Emission
502
  //===--------------------------------------------------------------------===//
503
504
  /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
505
8.07k
  void EnterBlockInfoBlock() {
506
8.07k
    EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2);
507
8.07k
    BlockInfoCurBID = ~0U;
508
8.07k
    BlockInfoRecords.clear();
509
8.07k
  }
510
private:
511
  /// SwitchToBlockID - If we aren't already talking about the specified block
512
  /// ID, emit a BLOCKINFO_CODE_SETBID record.
513
64.2k
  void SwitchToBlockID(unsigned BlockID) {
514
64.2k
    if (BlockInfoCurBID == BlockID) 
return52.1k
;
515
12.0k
    SmallVector<unsigned, 2> V;
516
12.0k
    V.push_back(BlockID);
517
12.0k
    EmitRecord(bitc::BLOCKINFO_CODE_SETBID, V);
518
12.0k
    BlockInfoCurBID = BlockID;
519
12.0k
  }
520
521
64.2k
  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
522
64.2k
    if (BlockInfo *BI = getBlockInfo(BlockID))
523
52.1k
      return *BI;
524
12.0k
525
12.0k
    // Otherwise, add a new record.
526
12.0k
    BlockInfoRecords.emplace_back();
527
12.0k
    BlockInfoRecords.back().BlockID = BlockID;
528
12.0k
    return BlockInfoRecords.back();
529
12.0k
  }
530
531
public:
532
533
  /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified
534
  /// BlockID.
535
64.2k
  unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) {
536
64.2k
    SwitchToBlockID(BlockID);
537
64.2k
    EncodeAbbrev(*Abbv);
538
64.2k
539
64.2k
    // Add the abbrev to the specified block record.
540
64.2k
    BlockInfo &Info = getOrCreateBlockInfo(BlockID);
541
64.2k
    Info.Abbrevs.push_back(std::move(Abbv));
542
64.2k
543
64.2k
    return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV;
544
64.2k
  }
545
};
546
547
548
} // End llvm namespace
549
550
#endif