Coverage Report

Created: 2019-02-15 18:59

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Bitcode/BitstreamWriter.h
Line
Count
Source (jump to first uncovered line)
1
//===- BitstreamWriter.h - Low-level bitstream writer interface -*- C++ -*-===//
2
//
3
// 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_BITCODE_BITSTREAMWRITER_H
15
#define LLVM_BITCODE_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/Bitcode/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
121k
    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
318M
  void WriteByte(unsigned char Value) {
66
318M
    Out.push_back(Value);
67
318M
  }
68
69
29.0M
  void WriteWord(unsigned Value) {
70
29.0M
    Value = support::endian::byte_swap<uint32_t, support::little>(Value);
71
29.0M
    Out.append(reinterpret_cast<const char *>(&Value),
72
29.0M
               reinterpret_cast<const char *>(&Value + 1));
73
29.0M
  }
74
75
5.46M
  size_t GetBufferOffset() const { return Out.size(); }
76
77
242k
  size_t GetWordIndex() const {
78
242k
    size_t Offset = GetBufferOffset();
79
242k
    assert((Offset & 3) == 0 && "Not 32-bit aligned");
80
242k
    return Offset / 4;
81
242k
  }
82
83
public:
84
  explicit BitstreamWriter(SmallVectorImpl<char> &O)
85
11.1k
    : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
86
87
11.1k
  ~BitstreamWriter() {
88
11.1k
    assert(CurBit == 0 && "Unflushed data remaining");
89
11.1k
    assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance");
90
11.1k
  }
91
92
  /// Retrieve the current position in the stream, in bits.
93
4.98M
  uint64_t GetCurrentBitNo() const { return GetBufferOffset() * 8 + CurBit; }
94
95
  /// Retrieve the number of bits currently used to encode an abbrev ID.
96
  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
126k
  void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
105
126k
    using namespace llvm::support;
106
126k
    unsigned ByteNo = BitNo / 8;
107
126k
    assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
108
126k
               &Out[ByteNo], BitNo & 7)) &&
109
126k
           "Expected to be patching over 0-value placeholders");
110
126k
    endian::writeAtBitAlignment<uint32_t, little, unaligned>(
111
126k
        &Out[ByteNo], NewWord, BitNo & 7);
112
126k
  }
113
114
160
  void BackpatchWord64(uint64_t BitNo, uint64_t Val) {
115
160
    BackpatchWord(BitNo, (uint32_t)Val);
116
160
    BackpatchWord(BitNo + 32, (uint32_t)(Val >> 32));
117
160
  }
118
119
161M
  void Emit(uint32_t Val, unsigned NumBits) {
120
161M
    assert(NumBits && NumBits <= 32 && "Invalid value size!");
121
161M
    assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!");
122
161M
    CurValue |= Val << CurBit;
123
161M
    if (CurBit + NumBits < 32) {
124
132M
      CurBit += NumBits;
125
132M
      return;
126
132M
    }
127
28.6M
128
28.6M
    // Add the current word.
129
28.6M
    WriteWord(CurValue);
130
28.6M
131
28.6M
    if (CurBit)
132
28.5M
      CurValue = Val >> (32-CurBit);
133
115k
    else
134
115k
      CurValue = 0;
135
28.6M
    CurBit = (CurBit+NumBits) & 31;
136
28.6M
  }
137
138
412k
  void FlushToWord() {
139
412k
    if (CurBit) {
140
400k
      WriteWord(CurValue);
141
400k
      CurBit = 0;
142
400k
      CurValue = 0;
143
400k
    }
144
412k
  }
145
146
84.7M
  void EmitVBR(uint32_t Val, unsigned NumBits) {
147
84.7M
    assert(NumBits <= 32 && "Too many bits to emit!");
148
84.7M
    uint32_t Threshold = 1U << (NumBits-1);
149
84.7M
150
84.7M
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
151
143M
    while (Val >= Threshold) {
152
58.7M
      Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
153
58.7M
      Val >>= NumBits-1;
154
58.7M
    }
155
84.7M
156
84.7M
    Emit(Val, NumBits);
157
84.7M
  }
158
159
72.2M
  void EmitVBR64(uint64_t Val, unsigned NumBits) {
160
72.2M
    assert(NumBits <= 32 && "Too many bits to emit!");
161
72.2M
    if ((uint32_t)Val == Val)
162
72.2M
      return EmitVBR((uint32_t)Val, NumBits);
163
2.14k
164
2.14k
    uint32_t Threshold = 1U << (NumBits-1);
165
2.14k
166
2.14k
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
167
28.4k
    while (Val >= Threshold) {
168
26.3k
      Emit(((uint32_t)Val & ((1 << (NumBits-1))-1)) |
169
26.3k
           (1 << (NumBits-1)), NumBits);
170
26.3k
      Val >>= NumBits-1;
171
26.3k
    }
172
2.14k
173
2.14k
    Emit((uint32_t)Val, NumBits);
174
2.14k
  }
175
176
  /// EmitCode - Emit the specified code.
177
7.58M
  void EmitCode(unsigned Val) {
178
7.58M
    Emit(Val, CurCodeSize);
179
7.58M
  }
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
205k
  BlockInfo *getBlockInfo(unsigned BlockID) {
188
205k
    // Common case, the most recent entry matches BlockID.
189
205k
    if (!BlockInfoRecords.empty() && 
BlockInfoRecords.back().BlockID == BlockID147k
)
190
82.2k
      return &BlockInfoRecords.back();
191
123k
192
123k
    for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
193
246k
         i != e; 
++i123k
)
194
146k
      if (BlockInfoRecords[i].BlockID == BlockID)
195
22.2k
        return &BlockInfoRecords[i];
196
123k
    
return nullptr100k
;
197
123k
  }
198
199
121k
  void EnterSubblock(unsigned BlockID, unsigned CodeLen) {
200
121k
    // Block header:
201
121k
    //    [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
202
121k
    EmitCode(bitc::ENTER_SUBBLOCK);
203
121k
    EmitVBR(BlockID, bitc::BlockIDWidth);
204
121k
    EmitVBR(CodeLen, bitc::CodeLenWidth);
205
121k
    FlushToWord();
206
121k
207
121k
    size_t BlockSizeWordIndex = GetWordIndex();
208
121k
    unsigned OldCodeSize = CurCodeSize;
209
121k
210
121k
    // Emit a placeholder, which will be replaced when the block is popped.
211
121k
    Emit(0, bitc::BlockSizeWidth);
212
121k
213
121k
    CurCodeSize = CodeLen;
214
121k
215
121k
    // Push the outer block's abbrev set onto the stack, start out with an
216
121k
    // empty abbrev set.
217
121k
    BlockScope.emplace_back(OldCodeSize, BlockSizeWordIndex);
218
121k
    BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
219
121k
220
121k
    // If there is a blockinfo for this BlockID, add all the predefined abbrevs
221
121k
    // to the abbrev list.
222
121k
    if (BlockInfo *Info = getBlockInfo(BlockID)) {
223
34.4k
      CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
224
34.4k
                        Info->Abbrevs.end());
225
34.4k
    }
226
121k
  }
227
228
121k
  void ExitBlock() {
229
121k
    assert(!BlockScope.empty() && "Block scope imbalance!");
230
121k
    const Block &B = BlockScope.back();
231
121k
232
121k
    // Block tail:
233
121k
    //    [END_BLOCK, <align4bytes>]
234
121k
    EmitCode(bitc::END_BLOCK);
235
121k
    FlushToWord();
236
121k
237
121k
    // Compute the size of the block, in words, not counting the size field.
238
121k
    size_t SizeInWords = GetWordIndex() - B.StartSizeWord - 1;
239
121k
    uint64_t BitNo = uint64_t(B.StartSizeWord) * 32;
240
121k
241
121k
    // Update the block size field in the header of this sub-block.
242
121k
    BackpatchWord(BitNo, SizeInWords);
243
121k
244
121k
    // Restore the inner block's code size and abbrev table.
245
121k
    CurCodeSize = B.PrevCodeSize;
246
121k
    CurAbbrevs = std::move(B.PrevAbbrevs);
247
121k
    BlockScope.pop_back();
248
121k
  }
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
3.99M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
259
3.99M
    assert(Op.isLiteral() && "Not a literal");
260
3.99M
    // If the abbrev specifies the literal value to use, don't emit
261
3.99M
    // anything.
262
3.99M
    assert(V == Op.getLiteralValue() &&
263
3.99M
           "Invalid abbrev for record!");
264
3.99M
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
258
904k
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
259
904k
    assert(Op.isLiteral() && "Not a literal");
260
904k
    // If the abbrev specifies the literal value to use, don't emit
261
904k
    // anything.
262
904k
    assert(V == Op.getLiteralValue() &&
263
904k
           "Invalid abbrev for record!");
264
904k
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned long long>(llvm::BitCodeAbbrevOp const&, unsigned long long)
Line
Count
Source
258
3.09M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
259
3.09M
    assert(Op.isLiteral() && "Not a literal");
260
3.09M
    // If the abbrev specifies the literal value to use, don't emit
261
3.09M
    // anything.
262
3.09M
    assert(V == Op.getLiteralValue() &&
263
3.09M
           "Invalid abbrev for record!");
264
3.09M
  }
265
266
  /// EmitAbbreviatedField - Emit a single scalar field value with the specified
267
  /// encoding.
268
  template<typename uintty>
269
9.88M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
270
9.88M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
271
9.88M
272
9.88M
    // Encode the value as we are commanded.
273
9.88M
    switch (Op.getEncoding()) {
274
9.88M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
275
9.88M
    case BitCodeAbbrevOp::Fixed:
276
5.70M
      if (Op.getEncodingData())
277
5.70M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
278
5.70M
      break;
279
9.88M
    case BitCodeAbbrevOp::VBR:
280
3.24M
      if (Op.getEncodingData())
281
3.24M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
282
3.24M
      break;
283
9.88M
    case BitCodeAbbrevOp::Char6:
284
935k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
285
935k
      break;
286
9.88M
    }
287
9.88M
  }
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
269
756k
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
270
756k
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
271
756k
272
756k
    // Encode the value as we are commanded.
273
756k
    switch (Op.getEncoding()) {
274
756k
    
default: 0
llvm_unreachable0
("Unknown encoding!");
275
756k
    case BitCodeAbbrevOp::Fixed:
276
500k
      if (Op.getEncodingData())
277
500k
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
278
500k
      break;
279
756k
    case BitCodeAbbrevOp::VBR:
280
153k
      if (Op.getEncodingData())
281
153k
        EmitVBR64(V, (unsigned)Op.getEncodingData());
282
153k
      break;
283
756k
    case BitCodeAbbrevOp::Char6:
284
101k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
285
101k
      break;
286
756k
    }
287
756k
  }
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.12M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
270
9.12M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
271
9.12M
272
9.12M
    // Encode the value as we are commanded.
273
9.12M
    switch (Op.getEncoding()) {
274
9.12M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
275
9.12M
    case BitCodeAbbrevOp::Fixed:
276
5.20M
      if (Op.getEncodingData())
277
5.20M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
278
5.20M
      break;
279
9.12M
    case BitCodeAbbrevOp::VBR:
280
3.09M
      if (Op.getEncodingData())
281
3.09M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
282
3.09M
      break;
283
9.12M
    case BitCodeAbbrevOp::Char6:
284
834k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
285
834k
      break;
286
9.12M
    }
287
9.12M
  }
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.22M
                                StringRef Blob, Optional<unsigned> Code) {
298
1.22M
    const char *BlobData = Blob.data();
299
1.22M
    unsigned BlobLen = (unsigned) Blob.size();
300
1.22M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
301
1.22M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
302
1.22M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
303
1.22M
304
1.22M
    EmitCode(Abbrev);
305
1.22M
306
1.22M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
307
1.22M
    if (Code) {
308
900k
      assert(e && "Expected non-empty abbreviation");
309
900k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
310
900k
311
900k
      if (Op.isLiteral())
312
900k
        EmitAbbreviatedLiteral(Op, Code.getValue());
313
28
      else {
314
28
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
315
28
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
316
28
               "Expected literal or scalar");
317
28
        EmitAbbreviatedField(Op, Code.getValue());
318
28
      }
319
900k
    }
320
1.22M
321
1.22M
    unsigned RecordIdx = 0;
322
12.9M
    for (; i != e; 
++i11.7M
) {
323
11.7M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
324
11.7M
      if (Op.isLiteral()) {
325
3.09M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
326
3.09M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
327
3.09M
        ++RecordIdx;
328
8.64M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
329
240k
        // Array case.
330
240k
        assert(i + 2 == e && "array op not second to last?");
331
240k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
332
240k
333
240k
        // If this record has blob data, emit it, otherwise we must have record
334
240k
        // entries to encode this way.
335
240k
        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
240k
        } else {
348
240k
          // Emit a vbr6 to indicate the number of elements present.
349
240k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
350
240k
351
240k
          // Emit each field.
352
1.88M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.64M
)
353
1.64M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
354
240k
        }
355
8.40M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
356
164k
        // If this record has blob data, emit it, otherwise we must have record
357
164k
        // entries to encode this way.
358
164k
359
164k
        if (BlobData) {
360
163k
          assert(RecordIdx == Vals.size() &&
361
163k
                 "Blob data and record entries specified for blob operand!");
362
163k
363
163k
          assert(Blob.data() == BlobData && "BlobData got moved");
364
163k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
365
163k
          emitBlob(Blob);
366
163k
          BlobData = nullptr;
367
163k
        } else {
368
1.50k
          emitBlob(Vals.slice(RecordIdx));
369
1.50k
        }
370
8.23M
      } else {  // Single scalar field.
371
8.23M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
372
8.23M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
373
8.23M
        ++RecordIdx;
374
8.23M
      }
375
11.7M
    }
376
1.22M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
377
1.22M
    assert(BlobData == nullptr &&
378
1.22M
           "Blob data specified for record that doesn't use it!");
379
1.22M
  }
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.12M
                                StringRef Blob, Optional<unsigned> Code) {
298
1.12M
    const char *BlobData = Blob.data();
299
1.12M
    unsigned BlobLen = (unsigned) Blob.size();
300
1.12M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
301
1.12M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
302
1.12M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
303
1.12M
304
1.12M
    EmitCode(Abbrev);
305
1.12M
306
1.12M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
307
1.12M
    if (Code) {
308
803k
      assert(e && "Expected non-empty abbreviation");
309
803k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
310
803k
311
803k
      if (Op.isLiteral())
312
803k
        EmitAbbreviatedLiteral(Op, Code.getValue());
313
29
      else {
314
29
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
315
29
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
316
29
               "Expected literal or scalar");
317
29
        EmitAbbreviatedField(Op, Code.getValue());
318
29
      }
319
803k
    }
320
1.12M
321
1.12M
    unsigned RecordIdx = 0;
322
12.5M
    for (; i != e; 
++i11.4M
) {
323
11.4M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
324
11.4M
      if (Op.isLiteral()) {
325
3.09M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
326
3.09M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
327
3.09M
        ++RecordIdx;
328
8.35M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
329
217k
        // Array case.
330
217k
        assert(i + 2 == e && "array op not second to last?");
331
217k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
332
217k
333
217k
        // If this record has blob data, emit it, otherwise we must have record
334
217k
        // entries to encode this way.
335
217k
        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
217k
        } else {
348
217k
          // Emit a vbr6 to indicate the number of elements present.
349
217k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
350
217k
351
217k
          // Emit each field.
352
1.37M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.15M
)
353
1.15M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
354
217k
        }
355
8.13M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
356
164k
        // If this record has blob data, emit it, otherwise we must have record
357
164k
        // entries to encode this way.
358
164k
359
164k
        if (BlobData) {
360
162k
          assert(RecordIdx == Vals.size() &&
361
162k
                 "Blob data and record entries specified for blob operand!");
362
162k
363
162k
          assert(Blob.data() == BlobData && "BlobData got moved");
364
162k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
365
162k
          emitBlob(Blob);
366
162k
          BlobData = nullptr;
367
162k
        } else {
368
1.50k
          emitBlob(Vals.slice(RecordIdx));
369
1.50k
        }
370
7.97M
      } else {  // Single scalar field.
371
7.97M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
372
7.97M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
373
7.97M
        ++RecordIdx;
374
7.97M
      }
375
11.4M
    }
376
1.12M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
377
1.12M
    assert(BlobData == nullptr &&
378
1.12M
           "Blob data specified for record that doesn't use it!");
379
1.12M
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned int>(unsigned int, llvm::ArrayRef<unsigned int>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
297
96.9k
                                StringRef Blob, Optional<unsigned> Code) {
298
96.9k
    const char *BlobData = Blob.data();
299
96.9k
    unsigned BlobLen = (unsigned) Blob.size();
300
96.9k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
301
96.9k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
302
96.9k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
303
96.9k
304
96.9k
    EmitCode(Abbrev);
305
96.9k
306
96.9k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
307
96.9k
    if (Code) {
308
96.8k
      assert(e && "Expected non-empty abbreviation");
309
96.8k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
310
96.8k
311
96.8k
      if (Op.isLiteral())
312
96.8k
        EmitAbbreviatedLiteral(Op, Code.getValue());
313
18.4E
      else {
314
18.4E
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
315
18.4E
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
316
18.4E
               "Expected literal or scalar");
317
18.4E
        EmitAbbreviatedField(Op, Code.getValue());
318
18.4E
      }
319
96.8k
    }
320
96.9k
321
96.9k
    unsigned RecordIdx = 0;
322
386k
    for (; i != e; 
++i289k
) {
323
289k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
324
289k
      if (Op.isLiteral()) {
325
3.60k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
326
3.60k
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
327
3.60k
        ++RecordIdx;
328
286k
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
329
23.0k
        // Array case.
330
23.0k
        assert(i + 2 == e && "array op not second to last?");
331
23.0k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
332
23.0k
333
23.0k
        // If this record has blob data, emit it, otherwise we must have record
334
23.0k
        // entries to encode this way.
335
23.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
23.0k
        } else {
348
23.0k
          // Emit a vbr6 to indicate the number of elements present.
349
23.0k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
350
23.0k
351
23.0k
          // Emit each field.
352
516k
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx493k
)
353
493k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
354
23.0k
        }
355
263k
      } 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
263k
      } else {  // Single scalar field.
371
263k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
372
263k
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
373
263k
        ++RecordIdx;
374
263k
      }
375
289k
    }
376
96.9k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
377
96.9k
    assert(BlobData == nullptr &&
378
96.9k
           "Blob data specified for record that doesn't use it!");
379
96.9k
  }
380
381
public:
382
  /// Emit a blob, including flushing before and tail-padding.
383
  template <class UIntTy>
384
164k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
385
164k
    // Emit a vbr6 to indicate the number of elements present.
386
164k
    if (ShouldEmitSize)
387
164k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
388
164k
389
164k
    // Flush to a 32-bit alignment boundary.
390
164k
    FlushToWord();
391
164k
392
164k
    // Emit literal bytes.
393
317M
    for (const auto &B : Bytes) {
394
317M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
395
317M
      WriteByte((unsigned char)B);
396
317M
    }
397
164k
398
164k
    // Align end to 32-bits.
399
229k
    while (GetBufferOffset() & 3)
400
64.8k
      WriteByte(0);
401
164k
  }
void llvm::BitstreamWriter::emitBlob<unsigned char>(llvm::ArrayRef<unsigned char>, bool)
Line
Count
Source
384
163k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
385
163k
    // Emit a vbr6 to indicate the number of elements present.
386
163k
    if (ShouldEmitSize)
387
163k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
388
163k
389
163k
    // Flush to a 32-bit alignment boundary.
390
163k
    FlushToWord();
391
163k
392
163k
    // Emit literal bytes.
393
317M
    for (const auto &B : Bytes) {
394
317M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
395
317M
      WriteByte((unsigned char)B);
396
317M
    }
397
163k
398
163k
    // Align end to 32-bits.
399
227k
    while (GetBufferOffset() & 3)
400
64.8k
      WriteByte(0);
401
163k
  }
void llvm::BitstreamWriter::emitBlob<unsigned long long>(llvm::ArrayRef<unsigned long long>, bool)
Line
Count
Source
384
1.50k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
385
1.50k
    // Emit a vbr6 to indicate the number of elements present.
386
1.50k
    if (ShouldEmitSize)
387
1.50k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
388
1.50k
389
1.50k
    // Flush to a 32-bit alignment boundary.
390
1.50k
    FlushToWord();
391
1.50k
392
1.50k
    // Emit literal bytes.
393
1.50k
    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.50k
398
1.50k
    // Align end to 32-bits.
399
1.50k
    while (GetBufferOffset() & 3)
400
0
      WriteByte(0);
401
1.50k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::emitBlob<unsigned int>(llvm::ArrayRef<unsigned int>, bool)
402
163k
  void emitBlob(StringRef Bytes, bool ShouldEmitSize = true) {
403
163k
    emitBlob(makeArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
404
163k
             ShouldEmitSize);
405
163k
  }
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
6.70M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
6.70M
    if (!Abbrev) {
412
5.80M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
5.80M
      // form.
414
5.80M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
5.80M
      EmitCode(bitc::UNABBREV_RECORD);
416
5.80M
      EmitVBR(Code, 6);
417
5.80M
      EmitVBR(Count, 6);
418
72.8M
      for (unsigned i = 0, e = Count; i != e; 
++i67.0M
)
419
67.0M
        EmitVBR64(Vals[i], 6);
420
5.80M
      return;
421
5.80M
    }
422
900k
423
900k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
900k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, unsigned int)
Line
Count
Source
410
2.87M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
2.87M
    if (!Abbrev) {
412
2.25M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
2.25M
      // form.
414
2.25M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
2.25M
      EmitCode(bitc::UNABBREV_RECORD);
416
2.25M
      EmitVBR(Code, 6);
417
2.25M
      EmitVBR(Count, 6);
418
50.0M
      for (unsigned i = 0, e = Count; i != e; 
++i47.8M
)
419
47.8M
        EmitVBR64(Vals[i], 6);
420
2.25M
      return;
421
2.25M
    }
422
616k
423
616k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
616k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 2u> >(unsigned int, llvm::SmallVector<unsigned int, 2u> const&, unsigned int)
Line
Count
Source
410
14.0k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
14.0k
    if (!Abbrev) {
412
14.0k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
14.0k
      // form.
414
14.0k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
14.0k
      EmitCode(bitc::UNABBREV_RECORD);
416
14.0k
      EmitVBR(Code, 6);
417
14.0k
      EmitVBR(Count, 6);
418
28.0k
      for (unsigned i = 0, e = Count; i != e; 
++i14.0k
)
419
14.0k
        EmitVBR64(Vals[i], 6);
420
14.0k
      return;
421
14.0k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
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
410
3.41M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
3.41M
    if (!Abbrev) {
412
3.23M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
3.23M
      // form.
414
3.23M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
3.23M
      EmitCode(bitc::UNABBREV_RECORD);
416
3.23M
      EmitVBR(Code, 6);
417
3.23M
      EmitVBR(Count, 6);
418
21.1M
      for (unsigned i = 0, e = Count; i != e; 
++i17.9M
)
419
17.9M
        EmitVBR64(Vals[i], 6);
420
3.23M
      return;
421
3.23M
    }
422
175k
423
175k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
175k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], unsigned int)
Line
Count
Source
410
3.52k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
3.52k
    if (!Abbrev) {
412
3.52k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
3.52k
      // form.
414
3.52k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
3.52k
      EmitCode(bitc::UNABBREV_RECORD);
416
3.52k
      EmitVBR(Code, 6);
417
3.52k
      EmitVBR(Count, 6);
418
7.05k
      for (unsigned i = 0, e = Count; i != e; 
++i3.52k
)
419
3.52k
        EmitVBR64(Vals[i], 6);
420
3.52k
      return;
421
3.52k
    }
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
13.7k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
13.7k
    if (!Abbrev) {
412
1.43k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
1.43k
      // form.
414
1.43k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
1.43k
      EmitCode(bitc::UNABBREV_RECORD);
416
1.43k
      EmitVBR(Code, 6);
417
1.43k
      EmitVBR(Count, 6);
418
4.29k
      for (unsigned i = 0, e = Count; i != e; 
++i2.86k
)
419
2.86k
        EmitVBR64(Vals[i], 6);
420
1.43k
      return;
421
1.43k
    }
422
12.2k
423
12.2k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
12.2k
  }
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.87k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
1.87k
    if (!Abbrev) {
412
1.87k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
1.87k
      // form.
414
1.87k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
1.87k
      EmitCode(bitc::UNABBREV_RECORD);
416
1.87k
      EmitVBR(Code, 6);
417
1.87k
      EmitVBR(Count, 6);
418
7.73k
      for (unsigned i = 0, e = Count; i != e; 
++i5.86k
)
419
5.86k
        EmitVBR64(Vals[i], 6);
420
1.87k
      return;
421
1.87k
    }
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.52k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
3.52k
    if (!Abbrev) {
412
3.52k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
3.52k
      // form.
414
3.52k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
3.52k
      EmitCode(bitc::UNABBREV_RECORD);
416
3.52k
      EmitVBR(Code, 6);
417
3.52k
      EmitVBR(Count, 6);
418
17.6k
      for (unsigned i = 0, e = Count; i != e; 
++i14.1k
)
419
14.1k
        EmitVBR64(Vals[i], 6);
420
3.52k
      return;
421
3.52k
    }
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
126k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
126k
    if (!Abbrev) {
412
126k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
126k
      // form.
414
126k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
126k
      EmitCode(bitc::UNABBREV_RECORD);
416
126k
      EmitVBR(Code, 6);
417
126k
      EmitVBR(Count, 6);
418
126k
      for (unsigned i = 0, e = Count; i != e; 
++i50
)
419
50
        EmitVBR64(Vals[i], 6);
420
126k
      return;
421
126k
    }
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.83k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
1.83k
    if (!Abbrev) {
412
1.83k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
1.83k
      // form.
414
1.83k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
1.83k
      EmitCode(bitc::UNABBREV_RECORD);
416
1.83k
      EmitVBR(Code, 6);
417
1.83k
      EmitVBR(Count, 6);
418
213k
      for (unsigned i = 0, e = Count; i != e; 
++i211k
)
419
211k
        EmitVBR64(Vals[i], 6);
420
1.83k
      return;
421
1.83k
    }
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
62.4k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
62.4k
    if (!Abbrev) {
412
44.3k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
44.3k
      // form.
414
44.3k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
44.3k
      EmitCode(bitc::UNABBREV_RECORD);
416
44.3k
      EmitVBR(Code, 6);
417
44.3k
      EmitVBR(Count, 6);
418
647k
      for (unsigned i = 0, e = Count; i != e; 
++i603k
)
419
603k
        EmitVBR64(Vals[i], 6);
420
44.3k
      return;
421
44.3k
    }
422
18.1k
423
18.1k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
18.1k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 1u> >(unsigned int, llvm::SmallVector<unsigned int, 1u> const&, unsigned int)
Line
Count
Source
410
4.65k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
4.65k
    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.65k
423
4.65k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
4.65k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, unsigned int)
Line
Count
Source
410
6.88k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
6.88k
    if (!Abbrev) {
412
6.88k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
6.88k
      // form.
414
6.88k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
6.88k
      EmitCode(bitc::UNABBREV_RECORD);
416
6.88k
      EmitVBR(Code, 6);
417
6.88k
      EmitVBR(Count, 6);
418
14.5k
      for (unsigned i = 0, e = Count; i != e; 
++i7.61k
)
419
7.61k
        EmitVBR64(Vals[i], 6);
420
6.88k
      return;
421
6.88k
    }
422
0
423
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
0
  }
void llvm::BitstreamWriter::EmitRecord<std::__1::vector<unsigned long long, std::__1::allocator<unsigned long long> > >(unsigned int, std::__1::vector<unsigned long long, std::__1::allocator<unsigned long long> > const&, unsigned int)
Line
Count
Source
410
160
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
160
    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
160
423
160
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
160
  }
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
347
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
347
    if (!Abbrev) {
412
347
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
347
      // form.
414
347
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
347
      EmitCode(bitc::UNABBREV_RECORD);
416
347
      EmitVBR(Code, 6);
417
347
      EmitVBR(Count, 6);
418
1.46k
      for (unsigned i = 0, e = Count; i != e; 
++i1.11k
)
419
1.11k
        EmitVBR64(Vals[i], 6);
420
347
      return;
421
347
    }
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.70k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
1.70k
    if (!Abbrev) {
412
1.70k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
1.70k
      // form.
414
1.70k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
1.70k
      EmitCode(bitc::UNABBREV_RECORD);
416
1.70k
      EmitVBR(Code, 6);
417
1.70k
      EmitVBR(Count, 6);
418
10.1k
      for (unsigned i = 0, e = Count; i != e; 
++i8.43k
)
419
8.43k
        EmitVBR64(Vals[i], 6);
420
1.70k
      return;
421
1.70k
    }
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
176k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
176k
    if (!Abbrev) {
412
102k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
102k
      // form.
414
102k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
102k
      EmitCode(bitc::UNABBREV_RECORD);
416
102k
      EmitVBR(Code, 6);
417
102k
      EmitVBR(Count, 6);
418
505k
      for (unsigned i = 0, e = Count; i != e; 
++i402k
)
419
402k
        EmitVBR64(Vals[i], 6);
420
102k
      return;
421
102k
    }
422
74.1k
423
74.1k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
424
74.1k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned int [5]>(unsigned int, unsigned int const (&) [5], unsigned int)
Line
Count
Source
410
118
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
411
118
    if (!Abbrev) {
412
118
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
413
118
      // form.
414
118
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
415
118
      EmitCode(bitc::UNABBREV_RECORD);
416
118
      EmitVBR(Code, 6);
417
118
      EmitVBR(Count, 6);
418
708
      for (unsigned i = 0, e = Count; i != e; 
++i590
)
419
590
        EmitVBR64(Vals[i], 6);
420
118
      return;
421
118
    }
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
159k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
431
159k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
432
159k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrev<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2])
Line
Count
Source
430
4.68k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
431
4.68k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
432
4.68k
  }
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
154k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
431
154k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
432
154k
  }
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
159k
                          StringRef Blob) {
442
159k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
159k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [3]>(unsigned int, unsigned long long const (&) [3], llvm::StringRef)
Line
Count
Source
441
21.5k
                          StringRef Blob) {
442
21.5k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
21.5k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [9]>(unsigned int, unsigned long long const (&) [9], llvm::StringRef)
Line
Count
Source
441
3.52k
                          StringRef Blob) {
442
3.52k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
3.52k
  }
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.34k
                          StringRef Blob) {
442
5.34k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
5.34k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], llvm::StringRef)
Line
Count
Source
441
16.1k
                          StringRef Blob) {
442
16.1k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
16.1k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], llvm::StringRef)
Line
Count
Source
441
87.8k
                          StringRef Blob) {
442
87.8k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
87.8k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [4]>(unsigned int, unsigned long long const (&) [4], llvm::StringRef)
Line
Count
Source
441
3.52k
                          StringRef Blob) {
442
3.52k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
3.52k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [13]>(unsigned int, unsigned long long const (&) [13], llvm::StringRef)
Line
Count
Source
441
3.28k
                          StringRef Blob) {
442
3.28k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
3.28k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
441
16.0k
                          StringRef Blob) {
442
16.0k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
16.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.04k
                          StringRef Blob) {
442
2.04k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
443
2.04k
  }
444
  template <typename Container>
445
  void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
446
5.08k
                          const char *BlobData, unsigned BlobLen) {
447
5.08k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
448
5.08k
                                    StringRef(BlobData, BlobLen), None);
449
5.08k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], char const*, unsigned int)
Line
Count
Source
446
3.52k
                          const char *BlobData, unsigned BlobLen) {
447
3.52k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
448
3.52k
                                    StringRef(BlobData, BlobLen), None);
449
3.52k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], char const*, unsigned int)
Line
Count
Source
446
1.55k
                          const char *BlobData, unsigned BlobLen) {
447
1.55k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
448
1.55k
                                    StringRef(BlobData, BlobLen), None);
449
1.55k
  }
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
319k
  void EncodeAbbrev(const BitCodeAbbrev &Abbv) {
472
319k
    EmitCode(bitc::DEFINE_ABBREV);
473
319k
    EmitVBR(Abbv.getNumOperandInfos(), 5);
474
319k
    for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos());
475
2.46M
         i != e; 
++i2.14M
) {
476
2.14M
      const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i);
477
2.14M
      Emit(Op.isLiteral(), 1);
478
2.14M
      if (Op.isLiteral()) {
479
766k
        EmitVBR64(Op.getLiteralValue(), 8);
480
1.38M
      } else {
481
1.38M
        Emit(Op.getEncoding(), 3);
482
1.38M
        if (Op.hasEncodingData())
483
1.16M
          EmitVBR64(Op.getEncodingData(), 5);
484
1.38M
      }
485
2.14M
    }
486
319k
  }
487
public:
488
489
  /// EmitAbbrev - This emits an abbreviation to the stream.  Note that this
490
  /// method takes ownership of the specified abbrev.
491
235k
  unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) {
492
235k
    // Emit the abbreviation as a record.
493
235k
    EncodeAbbrev(*Abbv);
494
235k
    CurAbbrevs.push_back(std::move(Abbv));
495
235k
    return static_cast<unsigned>(CurAbbrevs.size())-1 +
496
235k
      bitc::FIRST_APPLICATION_ABBREV;
497
235k
  }
498
499
  //===--------------------------------------------------------------------===//
500
  // BlockInfo Block Emission
501
  //===--------------------------------------------------------------------===//
502
503
  /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
504
8.81k
  void EnterBlockInfoBlock() {
505
8.81k
    EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2);
506
8.81k
    BlockInfoCurBID = ~0U;
507
8.81k
    BlockInfoRecords.clear();
508
8.81k
  }
509
private:
510
  /// SwitchToBlockID - If we aren't already talking about the specified block
511
  /// ID, emit a BLOCKINFO_CODE_SETBID record.
512
84.0k
  void SwitchToBlockID(unsigned BlockID) {
513
84.0k
    if (BlockInfoCurBID == BlockID) 
return70.0k
;
514
14.0k
    SmallVector<unsigned, 2> V;
515
14.0k
    V.push_back(BlockID);
516
14.0k
    EmitRecord(bitc::BLOCKINFO_CODE_SETBID, V);
517
14.0k
    BlockInfoCurBID = BlockID;
518
14.0k
  }
519
520
84.0k
  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
521
84.0k
    if (BlockInfo *BI = getBlockInfo(BlockID))
522
70.0k
      return *BI;
523
14.0k
524
14.0k
    // Otherwise, add a new record.
525
14.0k
    BlockInfoRecords.emplace_back();
526
14.0k
    BlockInfoRecords.back().BlockID = BlockID;
527
14.0k
    return BlockInfoRecords.back();
528
14.0k
  }
529
530
public:
531
532
  /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified
533
  /// BlockID.
534
84.0k
  unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) {
535
84.0k
    SwitchToBlockID(BlockID);
536
84.0k
    EncodeAbbrev(*Abbv);
537
84.0k
538
84.0k
    // Add the abbrev to the specified block record.
539
84.0k
    BlockInfo &Info = getOrCreateBlockInfo(BlockID);
540
84.0k
    Info.Abbrevs.push_back(std::move(Abbv));
541
84.0k
542
84.0k
    return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV;
543
84.0k
  }
544
};
545
546
547
} // End llvm namespace
548
549
#endif