Coverage Report

Created: 2018-11-16 02:38

/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
115k
    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
323M
  void WriteByte(unsigned char Value) {
67
323M
    Out.push_back(Value);
68
323M
  }
69
70
28.7M
  void WriteWord(unsigned Value) {
71
28.7M
    Value = support::endian::byte_swap<uint32_t, support::little>(Value);
72
28.7M
    Out.append(reinterpret_cast<const char *>(&Value),
73
28.7M
               reinterpret_cast<const char *>(&Value + 1));
74
28.7M
  }
75
76
5.41M
  size_t GetBufferOffset() const { return Out.size(); }
77
78
230k
  size_t GetWordIndex() const {
79
230k
    size_t Offset = GetBufferOffset();
80
230k
    assert((Offset & 3) == 0 && "Not 32-bit aligned");
81
230k
    return Offset / 4;
82
230k
  }
83
84
public:
85
  explicit BitstreamWriter(SmallVectorImpl<char> &O)
86
10.4k
    : Out(O), CurBit(0), CurValue(0), CurCodeSize(2) {}
87
88
10.4k
  ~BitstreamWriter() {
89
10.4k
    assert(CurBit == 0 && "Unflushed data remaining");
90
10.4k
    assert(BlockScope.empty() && CurAbbrevs.empty() && "Block imbalance");
91
10.4k
  }
92
93
  /// Retrieve the current position in the stream, in bits.
94
4.95M
  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
120k
  void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
106
120k
    using namespace llvm::support;
107
120k
    unsigned ByteNo = BitNo / 8;
108
120k
    assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
109
120k
               &Out[ByteNo], BitNo & 7)) &&
110
120k
           "Expected to be patching over 0-value placeholders");
111
120k
    endian::writeAtBitAlignment<uint32_t, little, unaligned>(
112
120k
        &Out[ByteNo], NewWord, BitNo & 7);
113
120k
  }
114
115
141
  void BackpatchWord64(uint64_t BitNo, uint64_t Val) {
116
141
    BackpatchWord(BitNo, (uint32_t)Val);
117
141
    BackpatchWord(BitNo + 32, (uint32_t)(Val >> 32));
118
141
  }
119
120
159M
  void Emit(uint32_t Val, unsigned NumBits) {
121
159M
    assert(NumBits && NumBits <= 32 && "Invalid value size!");
122
159M
    assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!");
123
159M
    CurValue |= Val << CurBit;
124
159M
    if (CurBit + NumBits < 32) {
125
131M
      CurBit += NumBits;
126
131M
      return;
127
131M
    }
128
28.3M
129
28.3M
    // Add the current word.
130
28.3M
    WriteWord(CurValue);
131
28.3M
132
28.3M
    if (CurBit)
133
28.2M
      CurValue = Val >> (32-CurBit);
134
113k
    else
135
113k
      CurValue = 0;
136
28.3M
    CurBit = (CurBit+NumBits) & 31;
137
28.3M
  }
138
139
398k
  void FlushToWord() {
140
398k
    if (CurBit) {
141
385k
      WriteWord(CurValue);
142
385k
      CurBit = 0;
143
385k
      CurValue = 0;
144
385k
    }
145
398k
  }
146
147
83.8M
  void EmitVBR(uint32_t Val, unsigned NumBits) {
148
83.8M
    assert(NumBits <= 32 && "Too many bits to emit!");
149
83.8M
    uint32_t Threshold = 1U << (NumBits-1);
150
83.8M
151
83.8M
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
152
142M
    while (Val >= Threshold) {
153
58.2M
      Emit((Val & ((1 << (NumBits-1))-1)) | (1 << (NumBits-1)), NumBits);
154
58.2M
      Val >>= NumBits-1;
155
58.2M
    }
156
83.8M
157
83.8M
    Emit(Val, NumBits);
158
83.8M
  }
159
160
71.4M
  void EmitVBR64(uint64_t Val, unsigned NumBits) {
161
71.4M
    assert(NumBits <= 32 && "Too many bits to emit!");
162
71.4M
    if ((uint32_t)Val == Val)
163
71.4M
      return EmitVBR((uint32_t)Val, NumBits);
164
2.11k
165
2.11k
    uint32_t Threshold = 1U << (NumBits-1);
166
2.11k
167
2.11k
    // Emit the bits with VBR encoding, NumBits-1 bits at a time.
168
27.4k
    while (Val >= Threshold) {
169
25.2k
      Emit(((uint32_t)Val & ((1 << (NumBits-1))-1)) |
170
25.2k
           (1 << (NumBits-1)), NumBits);
171
25.2k
      Val >>= NumBits-1;
172
25.2k
    }
173
2.11k
174
2.11k
    Emit((uint32_t)Val, NumBits);
175
2.11k
  }
176
177
  /// EmitCode - Emit the specified code.
178
7.48M
  void EmitCode(unsigned Val) {
179
7.48M
    Emit(Val, CurCodeSize);
180
7.48M
  }
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
192k
  BlockInfo *getBlockInfo(unsigned BlockID) {
189
192k
    // Common case, the most recent entry matches BlockID.
190
192k
    if (!BlockInfoRecords.empty() && 
BlockInfoRecords.back().BlockID == BlockID136k
)
191
76.0k
      return &BlockInfoRecords.back();
192
116k
193
116k
    for (unsigned i = 0, e = static_cast<unsigned>(BlockInfoRecords.size());
194
230k
         i != e; 
++i113k
)
195
135k
      if (BlockInfoRecords[i].BlockID == BlockID)
196
21.1k
        return &BlockInfoRecords[i];
197
116k
    
return nullptr95.4k
;
198
116k
  }
199
200
115k
  void EnterSubblock(unsigned BlockID, unsigned CodeLen) {
201
115k
    // Block header:
202
115k
    //    [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen]
203
115k
    EmitCode(bitc::ENTER_SUBBLOCK);
204
115k
    EmitVBR(BlockID, bitc::BlockIDWidth);
205
115k
    EmitVBR(CodeLen, bitc::CodeLenWidth);
206
115k
    FlushToWord();
207
115k
208
115k
    size_t BlockSizeWordIndex = GetWordIndex();
209
115k
    unsigned OldCodeSize = CurCodeSize;
210
115k
211
115k
    // Emit a placeholder, which will be replaced when the block is popped.
212
115k
    Emit(0, bitc::BlockSizeWidth);
213
115k
214
115k
    CurCodeSize = CodeLen;
215
115k
216
115k
    // Push the outer block's abbrev set onto the stack, start out with an
217
115k
    // empty abbrev set.
218
115k
    BlockScope.emplace_back(OldCodeSize, BlockSizeWordIndex);
219
115k
    BlockScope.back().PrevAbbrevs.swap(CurAbbrevs);
220
115k
221
115k
    // If there is a blockinfo for this BlockID, add all the predefined abbrevs
222
115k
    // to the abbrev list.
223
115k
    if (BlockInfo *Info = getBlockInfo(BlockID)) {
224
32.9k
      CurAbbrevs.insert(CurAbbrevs.end(), Info->Abbrevs.begin(),
225
32.9k
                        Info->Abbrevs.end());
226
32.9k
    }
227
115k
  }
228
229
115k
  void ExitBlock() {
230
115k
    assert(!BlockScope.empty() && "Block scope imbalance!");
231
115k
    const Block &B = BlockScope.back();
232
115k
233
115k
    // Block tail:
234
115k
    //    [END_BLOCK, <align4bytes>]
235
115k
    EmitCode(bitc::END_BLOCK);
236
115k
    FlushToWord();
237
115k
238
115k
    // Compute the size of the block, in words, not counting the size field.
239
115k
    size_t SizeInWords = GetWordIndex() - B.StartSizeWord - 1;
240
115k
    uint64_t BitNo = uint64_t(B.StartSizeWord) * 32;
241
115k
242
115k
    // Update the block size field in the header of this sub-block.
243
115k
    BackpatchWord(BitNo, SizeInWords);
244
115k
245
115k
    // Restore the inner block's code size and abbrev table.
246
115k
    CurCodeSize = B.PrevCodeSize;
247
115k
    CurAbbrevs = std::move(B.PrevAbbrevs);
248
115k
    BlockScope.pop_back();
249
115k
  }
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.90M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
3.90M
    assert(Op.isLiteral() && "Not a literal");
261
3.90M
    // If the abbrev specifies the literal value to use, don't emit
262
3.90M
    // anything.
263
3.90M
    assert(V == Op.getLiteralValue() &&
264
3.90M
           "Invalid abbrev for record!");
265
3.90M
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
259
894k
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
894k
    assert(Op.isLiteral() && "Not a literal");
261
894k
    // If the abbrev specifies the literal value to use, don't emit
262
894k
    // anything.
263
894k
    assert(V == Op.getLiteralValue() &&
264
894k
           "Invalid abbrev for record!");
265
894k
  }
void llvm::BitstreamWriter::EmitAbbreviatedLiteral<unsigned long long>(llvm::BitCodeAbbrevOp const&, unsigned long long)
Line
Count
Source
259
3.00M
  void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) {
260
3.00M
    assert(Op.isLiteral() && "Not a literal");
261
3.00M
    // If the abbrev specifies the literal value to use, don't emit
262
3.00M
    // anything.
263
3.00M
    assert(V == Op.getLiteralValue() &&
264
3.00M
           "Invalid abbrev for record!");
265
3.00M
  }
266
267
  /// EmitAbbreviatedField - Emit a single scalar field value with the specified
268
  /// encoding.
269
  template<typename uintty>
270
9.79M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
9.79M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
9.79M
273
9.79M
    // Encode the value as we are commanded.
274
9.79M
    switch (Op.getEncoding()) {
275
9.79M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
9.79M
    case BitCodeAbbrevOp::Fixed:
277
5.64M
      if (Op.getEncodingData())
278
5.64M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
5.64M
      break;
280
9.79M
    case BitCodeAbbrevOp::VBR:
281
3.23M
      if (Op.getEncodingData())
282
3.23M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.23M
      break;
284
9.79M
    case BitCodeAbbrevOp::Char6:
285
917k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
917k
      break;
287
9.79M
    }
288
9.79M
  }
void llvm::BitstreamWriter::EmitAbbreviatedField<unsigned int>(llvm::BitCodeAbbrevOp const&, unsigned int)
Line
Count
Source
270
706k
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
706k
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
706k
273
706k
    // Encode the value as we are commanded.
274
706k
    switch (Op.getEncoding()) {
275
706k
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
706k
    case BitCodeAbbrevOp::Fixed:
277
460k
      if (Op.getEncodingData())
278
460k
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
460k
      break;
280
706k
    case BitCodeAbbrevOp::VBR:
281
149k
      if (Op.getEncodingData())
282
149k
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
149k
      break;
284
706k
    case BitCodeAbbrevOp::Char6:
285
96.6k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
96.6k
      break;
287
706k
    }
288
706k
  }
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
9.08M
  void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) {
271
9.08M
    assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!");
272
9.08M
273
9.08M
    // Encode the value as we are commanded.
274
9.08M
    switch (Op.getEncoding()) {
275
9.08M
    
default: 0
llvm_unreachable0
("Unknown encoding!");
276
9.08M
    case BitCodeAbbrevOp::Fixed:
277
5.18M
      if (Op.getEncodingData())
278
5.18M
        Emit((unsigned)V, (unsigned)Op.getEncodingData());
279
5.18M
      break;
280
9.08M
    case BitCodeAbbrevOp::VBR:
281
3.08M
      if (Op.getEncodingData())
282
3.08M
        EmitVBR64(V, (unsigned)Op.getEncodingData());
283
3.08M
      break;
284
9.08M
    case BitCodeAbbrevOp::Char6:
285
820k
      Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6);
286
820k
      break;
287
9.08M
    }
288
9.08M
  }
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.21M
                                StringRef Blob, Optional<unsigned> Code) {
299
1.21M
    const char *BlobData = Blob.data();
300
1.21M
    unsigned BlobLen = (unsigned) Blob.size();
301
1.21M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
1.21M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
1.21M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
1.21M
305
1.21M
    EmitCode(Abbrev);
306
1.21M
307
1.21M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
1.21M
    if (Code) {
309
891k
      assert(e && "Expected non-empty abbreviation");
310
891k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
891k
312
891k
      if (Op.isLiteral())
313
891k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
30
      else {
315
30
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
30
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
30
               "Expected literal or scalar");
318
30
        EmitAbbreviatedField(Op, Code.getValue());
319
30
      }
320
891k
    }
321
1.21M
322
1.21M
    unsigned RecordIdx = 0;
323
12.8M
    for (; i != e; 
++i11.6M
) {
324
11.6M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
11.6M
      if (Op.isLiteral()) {
326
3.00M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.00M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.00M
        ++RecordIdx;
329
8.61M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
236k
        // Array case.
331
236k
        assert(i + 2 == e && "array op not second to last?");
332
236k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
236k
334
236k
        // If this record has blob data, emit it, otherwise we must have record
335
236k
        // entries to encode this way.
336
236k
        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
236k
        } else {
349
236k
          // Emit a vbr6 to indicate the number of elements present.
350
236k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
236k
352
236k
          // Emit each field.
353
1.82M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.58M
)
354
1.58M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
236k
        }
356
8.37M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
357
162k
        // If this record has blob data, emit it, otherwise we must have record
358
162k
        // entries to encode this way.
359
162k
360
162k
        if (BlobData) {
361
161k
          assert(RecordIdx == Vals.size() &&
362
161k
                 "Blob data and record entries specified for blob operand!");
363
161k
364
161k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
161k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
161k
          emitBlob(Blob);
367
161k
          BlobData = nullptr;
368
161k
        } else {
369
1.48k
          emitBlob(Vals.slice(RecordIdx));
370
1.48k
        }
371
8.21M
      } else {  // Single scalar field.
372
8.21M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
8.21M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
8.21M
        ++RecordIdx;
375
8.21M
      }
376
11.6M
    }
377
1.21M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
1.21M
    assert(BlobData == nullptr &&
379
1.21M
           "Blob data specified for record that doesn't use it!");
380
1.21M
  }
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.11M
                                StringRef Blob, Optional<unsigned> Code) {
299
1.11M
    const char *BlobData = Blob.data();
300
1.11M
    unsigned BlobLen = (unsigned) Blob.size();
301
1.11M
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
1.11M
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
1.11M
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
1.11M
305
1.11M
    EmitCode(Abbrev);
306
1.11M
307
1.11M
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
1.11M
    if (Code) {
309
797k
      assert(e && "Expected non-empty abbreviation");
310
797k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
797k
312
797k
      if (Op.isLiteral())
313
797k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
30
      else {
315
30
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
30
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
30
               "Expected literal or scalar");
318
30
        EmitAbbreviatedField(Op, Code.getValue());
319
30
      }
320
797k
    }
321
1.11M
322
1.11M
    unsigned RecordIdx = 0;
323
12.4M
    for (; i != e; 
++i11.3M
) {
324
11.3M
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
11.3M
      if (Op.isLiteral()) {
326
3.00M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.00M
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.00M
        ++RecordIdx;
329
8.33M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
214k
        // Array case.
331
214k
        assert(i + 2 == e && "array op not second to last?");
332
214k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
214k
334
214k
        // If this record has blob data, emit it, otherwise we must have record
335
214k
        // entries to encode this way.
336
214k
        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
214k
        } else {
349
214k
          // Emit a vbr6 to indicate the number of elements present.
350
214k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
214k
352
214k
          // Emit each field.
353
1.34M
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx1.13M
)
354
1.13M
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
214k
        }
356
8.11M
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) {
357
162k
        // If this record has blob data, emit it, otherwise we must have record
358
162k
        // entries to encode this way.
359
162k
360
162k
        if (BlobData) {
361
161k
          assert(RecordIdx == Vals.size() &&
362
161k
                 "Blob data and record entries specified for blob operand!");
363
161k
364
161k
          assert(Blob.data() == BlobData && "BlobData got moved");
365
161k
          assert(Blob.size() == BlobLen && "BlobLen got changed");
366
161k
          emitBlob(Blob);
367
161k
          BlobData = nullptr;
368
161k
        } else {
369
1.48k
          emitBlob(Vals.slice(RecordIdx));
370
1.48k
        }
371
7.95M
      } else {  // Single scalar field.
372
7.95M
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
7.95M
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
7.95M
        ++RecordIdx;
375
7.95M
      }
376
11.3M
    }
377
1.11M
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
1.11M
    assert(BlobData == nullptr &&
379
1.11M
           "Blob data specified for record that doesn't use it!");
380
1.11M
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrevImpl<unsigned int>(unsigned int, llvm::ArrayRef<unsigned int>, llvm::StringRef, llvm::Optional<unsigned int>)
Line
Count
Source
298
93.6k
                                StringRef Blob, Optional<unsigned> Code) {
299
93.6k
    const char *BlobData = Blob.data();
300
93.6k
    unsigned BlobLen = (unsigned) Blob.size();
301
93.6k
    unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
302
93.6k
    assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
303
93.6k
    const BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo].get();
304
93.6k
305
93.6k
    EmitCode(Abbrev);
306
93.6k
307
93.6k
    unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos());
308
93.6k
    if (Code) {
309
93.5k
      assert(e && "Expected non-empty abbreviation");
310
93.5k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i++);
311
93.5k
312
93.5k
      if (Op.isLiteral())
313
93.5k
        EmitAbbreviatedLiteral(Op, Code.getValue());
314
0
      else {
315
0
        assert(Op.getEncoding() != BitCodeAbbrevOp::Array &&
316
0
               Op.getEncoding() != BitCodeAbbrevOp::Blob &&
317
0
               "Expected literal or scalar");
318
0
        EmitAbbreviatedField(Op, Code.getValue());
319
0
      }
320
93.5k
    }
321
93.6k
322
93.6k
    unsigned RecordIdx = 0;
323
375k
    for (; i != e; 
++i282k
) {
324
282k
      const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
325
282k
      if (Op.isLiteral()) {
326
3.49k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
327
3.49k
        EmitAbbreviatedLiteral(Op, Vals[RecordIdx]);
328
3.49k
        ++RecordIdx;
329
278k
      } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) {
330
22.1k
        // Array case.
331
22.1k
        assert(i + 2 == e && "array op not second to last?");
332
22.1k
        const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i);
333
22.1k
334
22.1k
        // If this record has blob data, emit it, otherwise we must have record
335
22.1k
        // entries to encode this way.
336
22.1k
        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
22.1k
        } else {
349
22.1k
          // Emit a vbr6 to indicate the number of elements present.
350
22.1k
          EmitVBR(static_cast<uint32_t>(Vals.size()-RecordIdx), 6);
351
22.1k
352
22.1k
          // Emit each field.
353
472k
          for (unsigned e = Vals.size(); RecordIdx != e; 
++RecordIdx450k
)
354
450k
            EmitAbbreviatedField(EltEnc, Vals[RecordIdx]);
355
22.1k
        }
356
256k
      } 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
256k
      } else {  // Single scalar field.
372
256k
        assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
373
256k
        EmitAbbreviatedField(Op, Vals[RecordIdx]);
374
256k
        ++RecordIdx;
375
256k
      }
376
282k
    }
377
93.6k
    assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
378
93.6k
    assert(BlobData == nullptr &&
379
93.6k
           "Blob data specified for record that doesn't use it!");
380
93.6k
  }
381
382
public:
383
  /// Emit a blob, including flushing before and tail-padding.
384
  template <class UIntTy>
385
162k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
162k
    // Emit a vbr6 to indicate the number of elements present.
387
162k
    if (ShouldEmitSize)
388
162k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
162k
390
162k
    // Flush to a 32-bit alignment boundary.
391
162k
    FlushToWord();
392
162k
393
162k
    // Emit literal bytes.
394
322M
    for (const auto &B : Bytes) {
395
322M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
322M
      WriteByte((unsigned char)B);
397
322M
    }
398
162k
399
162k
    // Align end to 32-bits.
400
230k
    while (GetBufferOffset() & 3)
401
67.4k
      WriteByte(0);
402
162k
  }
void llvm::BitstreamWriter::emitBlob<unsigned char>(llvm::ArrayRef<unsigned char>, bool)
Line
Count
Source
385
161k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
161k
    // Emit a vbr6 to indicate the number of elements present.
387
161k
    if (ShouldEmitSize)
388
161k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
161k
390
161k
    // Flush to a 32-bit alignment boundary.
391
161k
    FlushToWord();
392
161k
393
161k
    // Emit literal bytes.
394
322M
    for (const auto &B : Bytes) {
395
322M
      assert(isUInt<8>(B) && "Value too large to emit as byte");
396
322M
      WriteByte((unsigned char)B);
397
322M
    }
398
161k
399
161k
    // Align end to 32-bits.
400
228k
    while (GetBufferOffset() & 3)
401
67.4k
      WriteByte(0);
402
161k
  }
void llvm::BitstreamWriter::emitBlob<unsigned long long>(llvm::ArrayRef<unsigned long long>, bool)
Line
Count
Source
385
1.48k
  void emitBlob(ArrayRef<UIntTy> Bytes, bool ShouldEmitSize = true) {
386
1.48k
    // Emit a vbr6 to indicate the number of elements present.
387
1.48k
    if (ShouldEmitSize)
388
1.48k
      EmitVBR(static_cast<uint32_t>(Bytes.size()), 6);
389
1.48k
390
1.48k
    // Flush to a 32-bit alignment boundary.
391
1.48k
    FlushToWord();
392
1.48k
393
1.48k
    // Emit literal bytes.
394
1.48k
    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.48k
399
1.48k
    // Align end to 32-bits.
400
1.48k
    while (GetBufferOffset() & 3)
401
0
      WriteByte(0);
402
1.48k
  }
Unexecuted instantiation: void llvm::BitstreamWriter::emitBlob<unsigned int>(llvm::ArrayRef<unsigned int>, bool)
403
161k
  void emitBlob(StringRef Bytes, bool ShouldEmitSize = true) {
404
161k
    emitBlob(makeArrayRef((const uint8_t *)Bytes.data(), Bytes.size()),
405
161k
             ShouldEmitSize);
406
161k
  }
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.62M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
6.62M
    if (!Abbrev) {
413
5.73M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
5.73M
      // form.
415
5.73M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
5.73M
      EmitCode(bitc::UNABBREV_RECORD);
417
5.73M
      EmitVBR(Code, 6);
418
5.73M
      EmitVBR(Count, 6);
419
72.0M
      for (unsigned i = 0, e = Count; i != e; 
++i66.3M
)
420
66.3M
        EmitVBR64(Vals[i], 6);
421
5.73M
      return;
422
5.73M
    }
423
891k
424
891k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
891k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, unsigned int)
Line
Count
Source
411
2.85M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
2.85M
    if (!Abbrev) {
413
2.23M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
2.23M
      // form.
415
2.23M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
2.23M
      EmitCode(bitc::UNABBREV_RECORD);
417
2.23M
      EmitVBR(Code, 6);
418
2.23M
      EmitVBR(Count, 6);
419
49.7M
      for (unsigned i = 0, e = Count; i != e; 
++i47.5M
)
420
47.5M
        EmitVBR64(Vals[i], 6);
421
2.23M
      return;
422
2.23M
    }
423
615k
424
615k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
615k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 2u> >(unsigned int, llvm::SmallVector<unsigned int, 2u> const&, unsigned int)
Line
Count
Source
411
12.8k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
12.8k
    if (!Abbrev) {
413
12.8k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
12.8k
      // form.
415
12.8k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
12.8k
      EmitCode(bitc::UNABBREV_RECORD);
417
12.8k
      EmitVBR(Code, 6);
418
12.8k
      EmitVBR(Count, 6);
419
25.7k
      for (unsigned i = 0, e = Count; i != e; 
++i12.8k
)
420
12.8k
        EmitVBR64(Vals[i], 6);
421
12.8k
      return;
422
12.8k
    }
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.36M
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.36M
    if (!Abbrev) {
413
3.19M
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.19M
      // form.
415
3.19M
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.19M
      EmitCode(bitc::UNABBREV_RECORD);
417
3.19M
      EmitVBR(Code, 6);
418
3.19M
      EmitVBR(Count, 6);
419
20.7M
      for (unsigned i = 0, e = Count; i != e; 
++i17.5M
)
420
17.5M
        EmitVBR64(Vals[i], 6);
421
3.19M
      return;
422
3.19M
    }
423
170k
424
170k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
170k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], unsigned int)
Line
Count
Source
411
3.51k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.51k
    if (!Abbrev) {
413
3.51k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.51k
      // form.
415
3.51k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.51k
      EmitCode(bitc::UNABBREV_RECORD);
417
3.51k
      EmitVBR(Code, 6);
418
3.51k
      EmitVBR(Count, 6);
419
7.03k
      for (unsigned i = 0, e = Count; i != e; 
++i3.51k
)
420
3.51k
        EmitVBR64(Vals[i], 6);
421
3.51k
      return;
422
3.51k
    }
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
13.1k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
13.1k
    if (!Abbrev) {
413
1.42k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.42k
      // form.
415
1.42k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.42k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.42k
      EmitVBR(Code, 6);
418
1.42k
      EmitVBR(Count, 6);
419
4.27k
      for (unsigned i = 0, e = Count; i != e; 
++i2.85k
)
420
2.85k
        EmitVBR64(Vals[i], 6);
421
1.42k
      return;
422
1.42k
    }
423
11.7k
424
11.7k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
11.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.86k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.86k
    if (!Abbrev) {
413
1.86k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.86k
      // form.
415
1.86k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.86k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.86k
      EmitVBR(Code, 6);
418
1.86k
      EmitVBR(Count, 6);
419
7.58k
      for (unsigned i = 0, e = Count; i != e; 
++i5.72k
)
420
5.72k
        EmitVBR64(Vals[i], 6);
421
1.86k
      return;
422
1.86k
    }
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.51k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
3.51k
    if (!Abbrev) {
413
3.51k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
3.51k
      // form.
415
3.51k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
3.51k
      EmitCode(bitc::UNABBREV_RECORD);
417
3.51k
      EmitVBR(Code, 6);
418
3.51k
      EmitVBR(Count, 6);
419
17.5k
      for (unsigned i = 0, e = Count; i != e; 
++i14.0k
)
420
14.0k
        EmitVBR64(Vals[i], 6);
421
3.51k
      return;
422
3.51k
    }
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
125k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
125k
    if (!Abbrev) {
413
125k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
125k
      // form.
415
125k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
125k
      EmitCode(bitc::UNABBREV_RECORD);
417
125k
      EmitVBR(Code, 6);
418
125k
      EmitVBR(Count, 6);
419
125k
      for (unsigned i = 0, e = Count; i != e; 
++i40
)
420
40
        EmitVBR64(Vals[i], 6);
421
125k
      return;
422
125k
    }
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.83k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.83k
    if (!Abbrev) {
413
1.83k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.83k
      // form.
415
1.83k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.83k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.83k
      EmitVBR(Code, 6);
418
1.83k
      EmitVBR(Count, 6);
419
213k
      for (unsigned i = 0, e = Count; i != e; 
++i211k
)
420
211k
        EmitVBR64(Vals[i], 6);
421
1.83k
      return;
422
1.83k
    }
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
59.2k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
59.2k
    if (!Abbrev) {
413
42.1k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
42.1k
      // form.
415
42.1k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
42.1k
      EmitCode(bitc::UNABBREV_RECORD);
417
42.1k
      EmitVBR(Code, 6);
418
42.1k
      EmitVBR(Count, 6);
419
609k
      for (unsigned i = 0, e = Count; i != e; 
++i566k
)
420
566k
        EmitVBR64(Vals[i], 6);
421
42.1k
      return;
422
42.1k
    }
423
17.1k
424
17.1k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
17.1k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::SmallVector<unsigned int, 1u> >(unsigned int, llvm::SmallVector<unsigned int, 1u> const&, unsigned int)
Line
Count
Source
411
4.27k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
4.27k
    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.27k
424
4.27k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
4.27k
  }
void llvm::BitstreamWriter::EmitRecord<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, unsigned int)
Line
Count
Source
411
5.89k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
5.89k
    if (!Abbrev) {
413
5.89k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
5.89k
      // form.
415
5.89k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
5.89k
      EmitCode(bitc::UNABBREV_RECORD);
417
5.89k
      EmitVBR(Code, 6);
418
5.89k
      EmitVBR(Count, 6);
419
12.4k
      for (unsigned i = 0, e = Count; i != e; 
++i6.55k
)
420
6.55k
        EmitVBR64(Vals[i], 6);
421
5.89k
      return;
422
5.89k
    }
423
0
424
0
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
0
  }
void llvm::BitstreamWriter::EmitRecord<std::__1::vector<unsigned long long, std::__1::allocator<unsigned long long> > >(unsigned int, std::__1::vector<unsigned long long, std::__1::allocator<unsigned long long> > const&, unsigned int)
Line
Count
Source
411
141
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
141
    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
141
424
141
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
141
  }
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
130
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
130
    if (!Abbrev) {
413
130
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
130
      // form.
415
130
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
130
      EmitCode(bitc::UNABBREV_RECORD);
417
130
      EmitVBR(Code, 6);
418
130
      EmitVBR(Count, 6);
419
592
      for (unsigned i = 0, e = Count; i != e; 
++i462
)
420
462
        EmitVBR64(Vals[i], 6);
421
130
      return;
422
130
    }
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.69k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
1.69k
    if (!Abbrev) {
413
1.69k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
1.69k
      // form.
415
1.69k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
1.69k
      EmitCode(bitc::UNABBREV_RECORD);
417
1.69k
      EmitVBR(Code, 6);
418
1.69k
      EmitVBR(Count, 6);
419
10.0k
      for (unsigned i = 0, e = Count; i != e; 
++i8.34k
)
420
8.34k
        EmitVBR64(Vals[i], 6);
421
1.69k
      return;
422
1.69k
    }
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
172k
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
172k
    if (!Abbrev) {
413
100k
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
100k
      // form.
415
100k
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
100k
      EmitCode(bitc::UNABBREV_RECORD);
417
100k
      EmitVBR(Code, 6);
418
100k
      EmitVBR(Count, 6);
419
493k
      for (unsigned i = 0, e = Count; i != e; 
++i393k
)
420
393k
        EmitVBR64(Vals[i], 6);
421
100k
      return;
422
100k
    }
423
72.1k
424
72.1k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), Code);
425
72.1k
  }
void llvm::BitstreamWriter::EmitRecord<unsigned int [5]>(unsigned int, unsigned int const (&) [5], unsigned int)
Line
Count
Source
411
93
  void EmitRecord(unsigned Code, const Container &Vals, unsigned Abbrev = 0) {
412
93
    if (!Abbrev) {
413
93
      // If we don't have an abbrev to use, emit this in its fully unabbreviated
414
93
      // form.
415
93
      auto Count = static_cast<uint32_t>(makeArrayRef(Vals).size());
416
93
      EmitCode(bitc::UNABBREV_RECORD);
417
93
      EmitVBR(Code, 6);
418
93
      EmitVBR(Count, 6);
419
558
      for (unsigned i = 0, e = Count; i != e; 
++i465
)
420
465
        EmitVBR64(Vals[i], 6);
421
93
      return;
422
93
    }
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
159k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
159k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
159k
  }
void llvm::BitstreamWriter::EmitRecordWithAbbrev<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2])
Line
Count
Source
431
4.30k
  void EmitRecordWithAbbrev(unsigned Abbrev, const Container &Vals) {
432
4.30k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), StringRef(), None);
433
4.30k
  }
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
157k
                          StringRef Blob) {
443
157k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
157k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [3]>(unsigned int, unsigned long long const (&) [3], llvm::StringRef)
Line
Count
Source
442
21.4k
                          StringRef Blob) {
443
21.4k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
21.4k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [9]>(unsigned int, unsigned long long const (&) [9], llvm::StringRef)
Line
Count
Source
442
3.51k
                          StringRef Blob) {
443
3.51k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.51k
  }
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.32k
                          StringRef Blob) {
443
5.32k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
5.32k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], llvm::StringRef)
Line
Count
Source
442
16.0k
                          StringRef Blob) {
443
16.0k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
16.0k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], llvm::StringRef)
Line
Count
Source
442
87.2k
                          StringRef Blob) {
443
87.2k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
87.2k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [4]>(unsigned int, unsigned long long const (&) [4], llvm::StringRef)
Line
Count
Source
442
3.51k
                          StringRef Blob) {
443
3.51k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.51k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [13]>(unsigned int, unsigned long long const (&) [13], llvm::StringRef)
Line
Count
Source
442
3.26k
                          StringRef Blob) {
443
3.26k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
3.26k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::ArrayRef<unsigned long long> >(unsigned int, llvm::ArrayRef<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
15.3k
                          StringRef Blob) {
443
15.3k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
15.3k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<llvm::SmallVectorImpl<unsigned long long> >(unsigned int, llvm::SmallVectorImpl<unsigned long long> const&, llvm::StringRef)
Line
Count
Source
442
1.77k
                          StringRef Blob) {
443
1.77k
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Blob, None);
444
1.77k
  }
445
  template <typename Container>
446
  void EmitRecordWithBlob(unsigned Abbrev, const Container &Vals,
447
5.06k
                          const char *BlobData, unsigned BlobLen) {
448
5.06k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
5.06k
                                    StringRef(BlobData, BlobLen), None);
450
5.06k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [2]>(unsigned int, unsigned long long const (&) [2], char const*, unsigned int)
Line
Count
Source
447
3.51k
                          const char *BlobData, unsigned BlobLen) {
448
3.51k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
3.51k
                                    StringRef(BlobData, BlobLen), None);
450
3.51k
  }
void llvm::BitstreamWriter::EmitRecordWithBlob<unsigned long long [1]>(unsigned int, unsigned long long const (&) [1], char const*, unsigned int)
Line
Count
Source
447
1.54k
                          const char *BlobData, unsigned BlobLen) {
448
1.54k
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
449
1.54k
                                    StringRef(BlobData, BlobLen), None);
450
1.54k
  }
451
452
  /// EmitRecordWithArray - Just like EmitRecordWithBlob, works with records
453
  /// that end with an array.
454
  template <typename Container>
455
  void EmitRecordWithArray(unsigned Abbrev, const Container &Vals,
456
                           StringRef Array) {
457
    EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals), Array, None);
458
  }
459
  template <typename Container>
460
  void EmitRecordWithArray(unsigned Abbrev, const Container &Vals,
461
                           const char *ArrayData, unsigned ArrayLen) {
462
    return EmitRecordWithAbbrevImpl(Abbrev, makeArrayRef(Vals),
463
                                    StringRef(ArrayData, ArrayLen), None);
464
  }
465
466
  //===--------------------------------------------------------------------===//
467
  // Abbrev Emission
468
  //===--------------------------------------------------------------------===//
469
470
private:
471
  // Emit the abbreviation as a DEFINE_ABBREV record.
472
304k
  void EncodeAbbrev(const BitCodeAbbrev &Abbv) {
473
304k
    EmitCode(bitc::DEFINE_ABBREV);
474
304k
    EmitVBR(Abbv.getNumOperandInfos(), 5);
475
304k
    for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos());
476
2.39M
         i != e; 
++i2.08M
) {
477
2.08M
      const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i);
478
2.08M
      Emit(Op.isLiteral(), 1);
479
2.08M
      if (Op.isLiteral()) {
480
745k
        EmitVBR64(Op.getLiteralValue(), 8);
481
1.34M
      } else {
482
1.34M
        Emit(Op.getEncoding(), 3);
483
1.34M
        if (Op.hasEncodingData())
484
1.13M
          EmitVBR64(Op.getEncodingData(), 5);
485
1.34M
      }
486
2.08M
    }
487
304k
  }
488
public:
489
490
  /// EmitAbbrev - This emits an abbreviation to the stream.  Note that this
491
  /// method takes ownership of the specified abbrev.
492
227k
  unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) {
493
227k
    // Emit the abbreviation as a record.
494
227k
    EncodeAbbrev(*Abbv);
495
227k
    CurAbbrevs.push_back(std::move(Abbv));
496
227k
    return static_cast<unsigned>(CurAbbrevs.size())-1 +
497
227k
      bitc::FIRST_APPLICATION_ABBREV;
498
227k
  }
499
500
  //===--------------------------------------------------------------------===//
501
  // BlockInfo Block Emission
502
  //===--------------------------------------------------------------------===//
503
504
  /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK.
505
8.42k
  void EnterBlockInfoBlock() {
506
8.42k
    EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2);
507
8.42k
    BlockInfoCurBID = ~0U;
508
8.42k
    BlockInfoRecords.clear();
509
8.42k
  }
510
private:
511
  /// SwitchToBlockID - If we aren't already talking about the specified block
512
  /// ID, emit a BLOCKINFO_CODE_SETBID record.
513
77.2k
  void SwitchToBlockID(unsigned BlockID) {
514
77.2k
    if (BlockInfoCurBID == BlockID) 
return64.3k
;
515
12.8k
    SmallVector<unsigned, 2> V;
516
12.8k
    V.push_back(BlockID);
517
12.8k
    EmitRecord(bitc::BLOCKINFO_CODE_SETBID, V);
518
12.8k
    BlockInfoCurBID = BlockID;
519
12.8k
  }
520
521
77.2k
  BlockInfo &getOrCreateBlockInfo(unsigned BlockID) {
522
77.2k
    if (BlockInfo *BI = getBlockInfo(BlockID))
523
64.3k
      return *BI;
524
12.8k
525
12.8k
    // Otherwise, add a new record.
526
12.8k
    BlockInfoRecords.emplace_back();
527
12.8k
    BlockInfoRecords.back().BlockID = BlockID;
528
12.8k
    return BlockInfoRecords.back();
529
12.8k
  }
530
531
public:
532
533
  /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified
534
  /// BlockID.
535
77.2k
  unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) {
536
77.2k
    SwitchToBlockID(BlockID);
537
77.2k
    EncodeAbbrev(*Abbv);
538
77.2k
539
77.2k
    // Add the abbrev to the specified block record.
540
77.2k
    BlockInfo &Info = getOrCreateBlockInfo(BlockID);
541
77.2k
    Info.Abbrevs.push_back(std::move(Abbv));
542
77.2k
543
77.2k
    return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV;
544
77.2k
  }
545
};
546
547
548
} // End llvm namespace
549
550
#endif