summaryrefslogtreecommitdiffstats
path: root/include/llvm/Bitcode
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Bitcode')
-rw-r--r--include/llvm/Bitcode/Archive.h1
-rw-r--r--include/llvm/Bitcode/BitstreamReader.h14
-rw-r--r--include/llvm/Bitcode/BitstreamWriter.h22
-rw-r--r--include/llvm/Bitcode/LLVMBitCodes.h33
-rw-r--r--include/llvm/Bitcode/ReaderWriter.h52
5 files changed, 91 insertions, 31 deletions
diff --git a/include/llvm/Bitcode/Archive.h b/include/llvm/Bitcode/Archive.h
index 13583c0..e19e4c0 100644
--- a/include/llvm/Bitcode/Archive.h
+++ b/include/llvm/Bitcode/Archive.h
@@ -22,7 +22,6 @@
#include "llvm/System/Path.h"
#include <map>
#include <set>
-#include <fstream>
namespace llvm {
class MemoryBuffer;
diff --git a/include/llvm/Bitcode/BitstreamReader.h b/include/llvm/Bitcode/BitstreamReader.h
index 28249ee..779ef5f 100644
--- a/include/llvm/Bitcode/BitstreamReader.h
+++ b/include/llvm/Bitcode/BitstreamReader.h
@@ -17,6 +17,7 @@
#include "llvm/Bitcode/BitCodes.h"
#include <climits>
+#include <string>
#include <vector>
namespace llvm {
@@ -260,6 +261,7 @@ public:
uint32_t Read(unsigned NumBits) {
+ assert(NumBits <= 32 && "Cannot return more than 32 bits!");
// If the field is fully contained by CurWord, return it quickly.
if (BitsInCurWord >= NumBits) {
uint32_t R = CurWord & ((1U << NumBits)-1);
@@ -322,17 +324,19 @@ public:
}
}
+ // ReadVBR64 - Read a VBR that may have a value up to 64-bits in size. The
+ // chunk size of the VBR must still be <= 32 bits though.
uint64_t ReadVBR64(unsigned NumBits) {
- uint64_t Piece = Read(NumBits);
- if ((Piece & (uint64_t(1) << (NumBits-1))) == 0)
- return Piece;
+ uint32_t Piece = Read(NumBits);
+ if ((Piece & (1U << (NumBits-1))) == 0)
+ return uint64_t(Piece);
uint64_t Result = 0;
unsigned NextBit = 0;
while (1) {
- Result |= (Piece & ((1U << (NumBits-1))-1)) << NextBit;
+ Result |= uint64_t(Piece & ((1U << (NumBits-1))-1)) << NextBit;
- if ((Piece & (uint64_t(1) << (NumBits-1))) == 0)
+ if ((Piece & (1U << (NumBits-1))) == 0)
return Result;
NextBit += NumBits-1;
diff --git a/include/llvm/Bitcode/BitstreamWriter.h b/include/llvm/Bitcode/BitstreamWriter.h
index 55dd4dd..e48a190 100644
--- a/include/llvm/Bitcode/BitstreamWriter.h
+++ b/include/llvm/Bitcode/BitstreamWriter.h
@@ -15,6 +15,7 @@
#ifndef BITSTREAM_WRITER_H
#define BITSTREAM_WRITER_H
+#include "llvm/ADT/StringRef.h"
#include "llvm/Bitcode/BitCodes.h"
#include <vector>
@@ -293,7 +294,9 @@ private:
/// known to exist at the end of the the record.
template<typename uintty>
void EmitRecordWithAbbrevImpl(unsigned Abbrev, SmallVectorImpl<uintty> &Vals,
- const char *BlobData, unsigned BlobLen) {
+ const StringRef &Blob) {
+ const char *BlobData = Blob.data();
+ unsigned BlobLen = (unsigned) Blob.size();
unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV;
assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!");
BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo];
@@ -409,7 +412,7 @@ public:
/// the first entry.
template<typename uintty>
void EmitRecordWithAbbrev(unsigned Abbrev, SmallVectorImpl<uintty> &Vals) {
- EmitRecordWithAbbrevImpl(Abbrev, Vals, 0, 0);
+ EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef());
}
/// EmitRecordWithBlob - Emit the specified record to the stream, using an
@@ -419,16 +422,27 @@ public:
/// of the record.
template<typename uintty>
void EmitRecordWithBlob(unsigned Abbrev, SmallVectorImpl<uintty> &Vals,
+ const StringRef &Blob) {
+ EmitRecordWithAbbrevImpl(Abbrev, Vals, Blob);
+ }
+ template<typename uintty>
+ void EmitRecordWithBlob(unsigned Abbrev, SmallVectorImpl<uintty> &Vals,
const char *BlobData, unsigned BlobLen) {
- EmitRecordWithAbbrevImpl(Abbrev, Vals, BlobData, BlobLen);
+ return EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef(BlobData, BlobLen));
}
/// EmitRecordWithArray - Just like EmitRecordWithBlob, works with records
/// that end with an array.
template<typename uintty>
void EmitRecordWithArray(unsigned Abbrev, SmallVectorImpl<uintty> &Vals,
+ const StringRef &Array) {
+ EmitRecordWithAbbrevImpl(Abbrev, Vals, Array);
+ }
+ template<typename uintty>
+ void EmitRecordWithArray(unsigned Abbrev, SmallVectorImpl<uintty> &Vals,
const char *ArrayData, unsigned ArrayLen) {
- EmitRecordWithAbbrevImpl(Abbrev, Vals, ArrayData, ArrayLen);
+ return EmitRecordWithAbbrevImpl(Abbrev, Vals, StringRef(ArrayData,
+ ArrayLen));
}
//===--------------------------------------------------------------------===//
diff --git a/include/llvm/Bitcode/LLVMBitCodes.h b/include/llvm/Bitcode/LLVMBitCodes.h
index 1ede69d..dccd8e0 100644
--- a/include/llvm/Bitcode/LLVMBitCodes.h
+++ b/include/llvm/Bitcode/LLVMBitCodes.h
@@ -33,7 +33,9 @@ namespace bitc {
CONSTANTS_BLOCK_ID,
FUNCTION_BLOCK_ID,
TYPE_SYMTAB_BLOCK_ID,
- VALUE_SYMTAB_BLOCK_ID
+ VALUE_SYMTAB_BLOCK_ID,
+ METADATA_BLOCK_ID,
+ METADATA_ATTACHMENT_ID
};
@@ -106,6 +108,14 @@ namespace bitc {
VST_CODE_BBENTRY = 2 // VST_BBENTRY: [bbid, namechar x N]
};
+ enum MetadataCodes {
+ METADATA_STRING = 1, // MDSTRING: [values]
+ METADATA_NODE = 2, // MDNODE: [n x (type num, value num)]
+ METADATA_NAME = 3, // STRING: [values]
+ METADATA_NAMED_NODE = 4, // NAMEDMDNODE: [n x mdnodes]
+ METADATA_KIND = 5, // [n x [id, name]]
+ METADATA_ATTACHMENT = 6 // [m x [value, [n x [id, mdnode]]]
+ };
// The constants block (CONSTANTS_BLOCK_ID) describes emission for each
// constant and maintains an implicit current type value.
enum ConstantsCodes {
@@ -128,8 +138,7 @@ namespace bitc {
CST_CODE_CE_CMP = 17, // CE_CMP: [opty, opval, opval, pred]
CST_CODE_INLINEASM = 18, // INLINEASM: [sideeffect,asmstr,conststr]
CST_CODE_CE_SHUFVEC_EX = 19, // SHUFVEC_EX: [opty, opval, opval, opval]
- CST_CODE_MDSTRING = 20, // MDSTRING: [values]
- CST_CODE_MDNODE = 21 // MDNODE: [n x (type num, value num)]
+ CST_CODE_CE_INBOUNDS_GEP = 20 // INBOUNDS_GEP: [n x operands]
};
/// CastOpcodes - These are values used in the bitcode files to encode which
@@ -171,6 +180,18 @@ namespace bitc {
BINOP_XOR = 12
};
+ /// OverflowingBinaryOperatorOptionalFlags - Flags for serializing
+ /// OverflowingBinaryOperator's SubclassOptionalData contents.
+ enum OverflowingBinaryOperatorOptionalFlags {
+ OBO_NO_UNSIGNED_WRAP = 0,
+ OBO_NO_SIGNED_WRAP = 1
+ };
+
+ /// SDivOperatorOptionalFlags - Flags for serializing SDivOperator's
+ /// SubclassOptionalData contents.
+ enum SDivOperatorOptionalFlags {
+ SDIV_EXACT = 0
+ };
// The function body block (FUNCTION_BLOCK_ID) describes function bodies. It
// can contain a constant block (CONSTANTS_BLOCK_ID).
@@ -210,10 +231,12 @@ namespace bitc {
FUNC_CODE_INST_GETRESULT = 25, // GETRESULT: [ty, opval, n]
FUNC_CODE_INST_EXTRACTVAL = 26, // EXTRACTVAL: [n x operands]
FUNC_CODE_INST_INSERTVAL = 27, // INSERTVAL: [n x operands]
- // fcmp/icmp returning Int1TY or vector of Int1Ty, NOT for vicmp/vfcmp
+ // fcmp/icmp returning Int1TY or vector of Int1Ty. Same as CMP, exists to
+ // support legacy vicmp/vfcmp instructions.
FUNC_CODE_INST_CMP2 = 28, // CMP2: [opty, opval, opval, pred]
// new select on i1 or [N x i1]
- FUNC_CODE_INST_VSELECT = 29 // VSELECT: [ty,opval,opval,predty,pred]
+ FUNC_CODE_INST_VSELECT = 29, // VSELECT: [ty,opval,opval,predty,pred]
+ FUNC_CODE_INST_INBOUNDS_GEP = 30 // INBOUNDS_GEP: [n x operands]
};
} // End bitc namespace
} // End llvm namespace
diff --git a/include/llvm/Bitcode/ReaderWriter.h b/include/llvm/Bitcode/ReaderWriter.h
index 3d33d75..7b74bdf 100644
--- a/include/llvm/Bitcode/ReaderWriter.h
+++ b/include/llvm/Bitcode/ReaderWriter.h
@@ -14,7 +14,6 @@
#ifndef LLVM_BITCODE_H
#define LLVM_BITCODE_H
-#include <iosfwd>
#include <string>
namespace llvm {
@@ -41,10 +40,6 @@ namespace llvm {
Module *ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
std::string *ErrMsg = 0);
- /// WriteBitcodeToFile - Write the specified module to the specified output
- /// stream.
- void WriteBitcodeToFile(const Module *M, std::ostream &Out);
-
/// WriteBitcodeToFile - Write the specified module to the specified
/// raw output stream.
void WriteBitcodeToFile(const Module *M, raw_ostream &Out);
@@ -53,23 +48,48 @@ namespace llvm {
/// raw output stream.
void WriteBitcodeToStream(const Module *M, BitstreamWriter &Stream);
- /// CreateBitcodeWriterPass - Create and return a pass that writes the module
- /// to the specified ostream.
- ModulePass *CreateBitcodeWriterPass(std::ostream &Str);
-
/// createBitcodeWriterPass - Create and return a pass that writes the module
/// to the specified ostream.
ModulePass *createBitcodeWriterPass(raw_ostream &Str);
- /// isBitcodeWrapper - Return true fi this is a wrapper for LLVM IR bitcode
- /// files.
- static bool inline isBitcodeWrapper(unsigned char *BufPtr,
- unsigned char *BufEnd) {
- return (BufPtr != BufEnd && BufPtr[0] == 0xDE && BufPtr[1] == 0xC0 &&
- BufPtr[2] == 0x17 && BufPtr[3] == 0x0B);
+ /// isBitcodeWrapper - Return true if the given bytes are the magic bytes
+ /// for an LLVM IR bitcode wrapper.
+ ///
+ static inline bool isBitcodeWrapper(const unsigned char *BufPtr,
+ const unsigned char *BufEnd) {
+ // See if you can find the hidden message in the magic bytes :-).
+ // (Hint: it's a little-endian encoding.)
+ return BufPtr != BufEnd &&
+ BufPtr[0] == 0xDE &&
+ BufPtr[1] == 0xC0 &&
+ BufPtr[2] == 0x17 &&
+ BufPtr[3] == 0x0B;
}
-
+
+ /// isRawBitcode - Return true if the given bytes are the magic bytes for
+ /// raw LLVM IR bitcode (without a wrapper).
+ ///
+ static inline bool isRawBitcode(const unsigned char *BufPtr,
+ const unsigned char *BufEnd) {
+ // These bytes sort of have a hidden message, but it's not in
+ // little-endian this time, and it's a little redundant.
+ return BufPtr != BufEnd &&
+ BufPtr[0] == 'B' &&
+ BufPtr[1] == 'C' &&
+ BufPtr[2] == 0xc0 &&
+ BufPtr[3] == 0xde;
+ }
+
+ /// isBitcode - Return true if the given bytes are the magic bytes for
+ /// LLVM IR bitcode, either with or without a wrapper.
+ ///
+ static bool inline isBitcode(const unsigned char *BufPtr,
+ const unsigned char *BufEnd) {
+ return isBitcodeWrapper(BufPtr, BufEnd) ||
+ isRawBitcode(BufPtr, BufEnd);
+ }
+
/// SkipBitcodeWrapperHeader - Some systems wrap bc files with a special
/// header for padding or other reasons. The format of this header is:
///
OpenPOWER on IntegriCloud